Mac – Bash – Package-Repackage

email me

This is how you would repackage a PKG or APP, creating a custom, thinner installation GUI. Using this method, you can take an existing PKG, add a script, and compile a new package—this wrapper package can have company branding, contain logging and telemetry functions, and apply customized settings.

Upon execution, a pre script will run (if you have one), then the contents of the package will extract, and a post script will carryout custom command sequences.

You can also lockdown certain areas of the package installation, like the ability to change the setup location, and the option of enabling or disabling the embedded package. Very powerful.

Using Packages, I was able to create a new, custom package. Here are the screenshots.

Initial Project screen

Add a custom Title

Select Custom Background and add a custom Image

Change the Package Name to use an alias name. Select Required to disable deselect. Make sure User sees says Custom Install Only

What the Summary screen will look like…

To disable the ability to change the setup location, select Install on startup disk only.

Initial Package screen starts on Settings tab. Select Require admin password for installation, if needed.

Under the Payload tab, add location where source files will be extracted to. I normally use Users > Shared > foldername, but a common location is Applications, especially for .APP files.

Under Scripts, add a script for automation sequencing (pre, post, or both)

Select Build, and a Customized Package will be created

 

Installer.sh script

#!/bin/bash

# App: Pulse Secure
# Ver: 9.0.3.1599
# Size: 18.6 MB
# Author: Eddie Jackson
# Date: 8/5/2019
# Log: /Users/Shared/pulse/log.txt
# Resources: installer.sh, PulseSecure.pkg, image.png

clear && printf '\e[3J'

cd /Volumes
cd Mac*/Users/Shared/pulse
echo Current Directory: /Users/Shared/pulse
echo Package File: PulseSecure.pkg
echo ""

echo Installing Pulse Secure...

# install with verbose output for log
sudo installer -pkg "PulseSecure.pkg" -target / -verbose > log.txt
rm "PulseSecure.pkg" >> log.txt
echo -e "\nCompleted!\n"
echo -e "exiting...\n"
sleep 5

exit 0

 

If you have any issues, check where the internal PKG or APP is being copied to. If the target in the installer string is failing, try changing that. If it still fails, add the .APP file (or other resource content) to the Applications folder under the Payload tab. I have seen permission issues on the Users > Shared folder sometimes cause problems; you may also just fix any permission issues using chmod.

Deny execute permission to everyone:
$ chmod a-x YourFile

Allow read permission to everyone:
$ chmod a+r YourFile

Make a file readable and writable by the group and others:
$ chmod go+rw YourFile

Make a shell script executable by the user/owner
$ chmod u+x YourScript.sh

Allow everyone to read, write, and execute the file and turn on the set group-ID:
$ chmod =rwx,g+s YourFile

 

What I Disabled

The install skips the Destination Select and does not allow us to change the Installation Location. Only Install is presented.

The Package Name cannot be deselected and the Path cannot be changed.

Notice my custom Title, Package Name, and Image Branding are all working.

 

Notes

SCCM Packaging into CMMAC


Uninstall Pulse

Library > Application Support > Pulse Secure > Pulse > Uninstall

Installer with an untrusted PKG
sudo installer -dumplog -verbose -allowUntrusted -pkg “path/YourPackage.pkg” -target “/”

Create simple logging in your script
echo [$(date)] Installed Pulse Client 9.0.3.1599 >> log.txt

Test whether or not folder/app exists
if [ -d “/Pulse Secure.app” ]; then echo “YES”; fi

Test whether or not file exists
if [ -f “/log.txt” ]; then echo “YES”; fi

cd /Volumes
cd Mac*/Users/Shared/pulse
cp -r “Pulse Secure.app” /Applications/
open “Pulse Secure.app”

 

tags: Mac Packaging, PKG, APP, SCCM CCMAC, Mac CMMAC, MrNetTek