Payload-Free Package Creator.app
I do a lot of work with payload-free packages and I’ve looked for a while for a tool that would let me easily create them from existing scripts. While I have a process for creating them as needed with pkgbuild, this approach still requires some setup work.
After thinking about it and taking a look at various approaches, I’ve developed Payload-Free Package Creator.app, an Automator application that will allow the selection of an existing script and create a payload-free package that runs the selected script. For more details, see below the jump.
Using Payload-Free Package Creator.app
1. If needed, download the Payload-Free_Package_Creator_Application.zip file from the application directory in my GitHub repo.
2. Once downloaded and unzipped, double-click on the Payload-Free Package Creator application.
3. You’ll be prompted to select the script that you want to create a payload-free package from.
4. Once you’ve selected the script, you’ll be prompted to name the payload-free package. By default, the name filled in will be Payload-Free Installer Package.
This name can be changed as desired.
5. Once you’ve entered a name for the installer package, you’ll be prompted for a package identifier. By default, the name filled in will be com.github.payload_free
This name should be changed to be something unique.
6. Once the package name and package identifier have been set, Payload-Free Package Creator.app will prompt for an administrator’s username and password.
7. Once the admin username and password are provided, Payload-Free Package Creator.app will create the payload-free package and prompt you when it’s finished.
8. Click OK at the prompt and a new Finder window will open to display the newly-created payload-free package.
9. Payload-Free Package Creator.app will automatically exit once finished.
How Payload-Free Package Creator.app works
Payload-Free Package Creator.app is an Automator application that uses AppleScript, shell scripting and pkgbuild behind the scenes to create payload-free packages. When a script is selected, the following process takes place:
1. The script is copied to /tmp and the file is renamed to postinstall, to match the name that pkgbuild is expecting for a post-installation script.
2. After the package name and package identifier are chosen, /tmp is checked to make sure that there is not an existing directory that is named the same as the chosen name. If a matching directory is found, it is removed.
3. A new directory is created in /tmp that matches the chosen name of the package.
4. Next, a scripts directory is created inside of /tmp/package_name_here.
5. The postinstall script is moved to /tmp/package_name_here/scripts.
6. The payload-free package is built by pkgbuild using the postinstall script stored in /tmp/package_name_here/scripts.
7. The finished payload-free package is stored in /tmp/package_name_here and the user is prompted that the process is finished.
8. Once the user is notified and clicks OK, a new Finder window opens for /tmp/package_name_here.
The total workflow looks like this:
The AppleScript used to create the payload-free package as part of the Automator work is below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run {input, parameters} | |
— this repeat loop prevents empty strings from being submitted for the package name value | |
set q to 0 | |
repeat while q is 0 | |
set result to text returned of (display dialog "Enter a Name For Your Payload-Free Installer Package:" default answer "Payload-Free Installer Package") | |
if result is not "" then | |
set pkgname to result | |
set q to 1 | |
end if | |
end repeat | |
— this repeat loop prevents empty strings from being submitted for the package identifier value | |
set q to 0 | |
repeat while q is 0 | |
set result to text returned of (display dialog "Enter a Package Identifier:" default answer "com.github.payload_free") | |
if result is not "" then | |
set pkgid to result | |
set q to 1 | |
end if | |
end repeat | |
— Set the postinstall script to be executable | |
do shell script "chmod a+x /tmp/postinstall" with administrator privileges | |
— Remove any existing build directories that have the same name as the new payload-free package | |
do shell script "rm -rf /tmp/" & quoted form of pkgname & "/" with administrator privileges | |
— Create the build directories for the payload-free package | |
do shell script "mkdir /tmp/" & quoted form of pkgname & "" with administrator privileges | |
do shell script "mkdir /tmp/" & quoted form of pkgname & "/scripts" with administrator privileges | |
— Move the postinstall script into the correct build directory | |
do shell script "mv /tmp/postinstall /tmp/" & quoted form of pkgname & "/scripts" with administrator privileges | |
— Build the payload-free package | |
do shell script "pkgbuild –identifier " & quoted form of pkgid & " –nopayload –scripts /tmp/" & quoted form of pkgname & "/scripts /tmp/" & quoted form of pkgname & "/" & quoted form of pkgname & ".pkg" with administrator privileges | |
— Display dialog that the payload-free package has been created | |
display alert ((pkgname) as string) & ".pkg has been created." | |
— Open a new Finder window that shows the new package | |
do shell script "open /tmp/" & quoted form of pkgname & "" | |
return input | |
end run |
All Payload-Free Package Creator components and scripts are available at my GitHub repo:
https://github.com/rtrouton/Payload-Free-Package-Creator
The Automator workflow files and the AppleScript are also available via the link above if you want to build a customized Payload-Free Package Creator for your own environment.
Wow, this looks to be exceptionally handy. Thanks!
Seconded. Good work!
This is great could you add a section for version number?
when I attempt to import a .pkg built with this tool using munkiimport (2.2.2.2414) I get the following error:
WARNING: No valid Distribution or PackageInfo found.
somePayloadFree.pkg doesn’t appear to be a valid installer item!
Getting package info failed.
Thoughts?
Was just coming in to say the same thing! Haven’t found a fix yet.
Payload-free packages generated with this tool should not be used with Munki. This is because it uses pkgbuild’s method of generating payload-free packages, which does not leave a recipt behind.
but how to install it in kali linux…?
Now that PPPC is here, how do we set it to allow writing to 10.15.4 space that is readonly?