Building an Installer — Part 4

Run a bunch of installers at the same time.

C4
The C4 Dev

--

We previously looked at building an installer that installs a separate installer. Now, we’re going to build 3 installers and run them at the same time.

Create Installer Folders

First, create 3 new folders called: folder1, folder2, folder3. In each one of them add a unique image — it doesn’t matter what they’re called. We’re going to make a script that builds separate installers for each one.

Create a Build Script

Next, we’re going to create a single script that builds all the installers.

1. create a new buildMultipleInstallers.sh script
2. Add 3 commands to create packages:

pkgbuild —root ./folder1 —identifier test.folder1 —install-location /Users/$USER/Desktop/folders folder1.pkgpkgbuild —root ./folder2 —identifier test.folder2 —install-location /Users/$USER/Desktop/folders folder2.pkgpkgbuild —root ./folder3 —identifier test.folder3 —install-location /Users/$USER/Desktop/folders folder3.pkg

3. run the script from the desktop, and we see:

All three pkgbuild commands get called from the multiple script file

Wham

Three new .pkg files pop up on the desktop and when we run them they take the contents of the three original folders (i.e. folder1, folder2, folder3) and place them inside a new directory on the desktop.

The original 3 folders, the packages we built, and the resulting folders directory that gets created after running each installer

Perfect. One script, three packages.

Run All The Things

Having built an run all those by double clicking on them was tedious. Let’s figure out how to pack them all into the same installer. To do so, we’re going to look at the last line we ran in Part 3.

productbuild —distribution distribution.xml —package-path test.pkg superPackage.pkg

This line creates a single distribution file that that automatically runs our test.pkg, but we want to run multiple packages at the same time. So, we do the following:

1. Create a new file called buildMultiplePackage.sh

2. Add the following lines to it:

productbuild --synthesize --package folder1.pkg -package folder2.pkg --package folder3.pkg distribution.xmlproductbuild --distribution distribution.xml multiplePackages.pkg

3. Run it from terminal

Running this script first synthesizes a new distribution file that contains references to three packages. Then, it builds a new installer called multiplePackages.pkg and saves it to the desktop

4. Delete the folders directory on the desktop.

5. Run the installer.

BADASS!

We just ran an installer that installs three other installers. After running multiplePackages.pkg we see that the folders directory reappears, but now with all the content that is installed from folder1, folder2, and folder3!

Oh, we’re getting sophisticated now.

--

--

C4
The C4 Dev

Code, Creatively. An open-source API for iOS.