Building an Installer — Part 3

Running installers with installers

C4
The C4 Dev

--

We previously looked at running a script that builds an installer package. But, the script we were running only creates an installer for a specific folder full of files (i.e. the C4 Single View Application.xctemplate). What we want to do is make an installer that builds 3 installers and runs them all at the same time.

Why?!

Because, it’s easier to understand.

What?!

We already saw that building an installer that targets 1 folder is really easy. So, that means that building 3 installers that each target a separate folder is also really easy. So, if we can build an installer that runs installers then we’re gold.

And, it’s possible.

Using productbuild(1)

Apple’s Man Pages specify a command called productbuild which doesn’t sound like much, but does exactly what we want. The description is:

4. Create a product archive using a distribution file. If you have a distribution file, use the --distribution option to specify the path to it, and the --package-path option to specify the directory where the component packages are found (if they are not in the current working directory). All packages referenced by the distribution will be incorporated into the resulting product archive.

5. Synthesize a distribution for one or more component packages. This also synthesizes a distribution, but writes out the resulting distribution instead of incorporating it into a product archive. This can serve as a starting point if a more sophisticated distribution is required.

In English, this reads as:

4. You can use a special distribution.xml file that allows you to create an installer that can incorporate other .pkg files.

5. Create a distribution file that can be used to build a complex installer.

Naturally, we want to do number five first, then use that file to do four.

Create a Distribution File

Shane Kirk shows us how to use product build to create a distribution file:

productbuild —synthesize —package ./mypackage.pkg distribution.xml

His description, combined with Apple’s Man Pages, gives the impression that if we build this distribution file first then we’ll be able to create a super package that installs other packages.

So, we rewrite the command to suit our test case.

We’ve already got a test package to work with, we so we’re going to rewite the above like so:

productbuild --synthesize --package test.pkg distribution.xml

To run it do the following:

  1. Open terminal
  2. cd Desktop
  3. Paste the line of code in to terminal and hit enter

A new file called distribution.xml appears on the desktop. But doesn’t do much else until we use productbuild again, but in a different way.

Create an Installer from distribution.xml

Shane Kirk shows us how to use the distribution command like so:

productbuild --distribution distribution.xml --resources ./myimages --package-path ./mypackage.pkg myimprovedpackage.pkg

Again, we need to tailor this to our case. We’re not working with resources yet, so we’re going to eliminate that and build a package with a package. Our code looks like:

productbuild --distribution distribution.xml --package-path test.pkg superPackage.pkg
  1. Run the previous command from terminal and a new file called superPackage.pkg pops up on the desktop.
  2. Delete the current folder newFiles that we previous created.
  3. Run it and a new folder called newFiles appears with the same 4 files that we got when we ran our script in Part 2.

Badass.

We just created a new package from a distribution file that points to a smaller package. And, from reading the Man Pages, it seems like we can add a couple of packages to the distribution.xml so that they all run.

We’ve just run an installer with an installer. Next, we’re going to make more installers so we can install while we install.

--

--

C4
The C4 Dev

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