Stupid tricks with pkgbuild

Starting with Xcode 3.2 on Snow Leopard, and installed by default on Mac OS X Lion are two new-ish packaging tools:


These tools are ideal for use in scripted package building, and can replace much of the use of the packagemaker binary inside Apple’s PackageMaker application.

pkgbuild can be used to create simple flat packages. productbuild can create more complex distribution packages, which may contain one or more flat packaged generated using pkgbuild.

Check out the man pages for pkgbuild and productbuild for more info.

pkgbuild is very easy to use, compared to packagemaker. There are two chief limitations that I found in attempting to use it as a replacement for packagemaker:

  1. pkgbuild creates only flat packages. These are supported only on 10.5 Leopard and newer.
  2. There didn’t appear to be a way to specify that a package required a restart or logout.

The first is not really a problem if you don’t have to manage any pre-Leopard machines.

The second can be worked around by using productbuild — the Distribution file can specify the need to restart. That’s the officially supported solution, but is a bit of a pain.

It turns out that pkgbuild has an undocumented --info option. This allows you to specify a PackageInfo template that can be used to specify some additional info that can’t be specified through other pkgbuild flags.

If I create /tmp/PackageInfo with these contents:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<pkg-info postinstall-action="restart"/>

Then do this:

pkgbuild --info /tmp/PackageInfo --component /Applications/ /tmp/Firefox.pkg

I get a package for Firefox that requires a restart.

See for more info on flat package PackageInfo files, which are not the same as bundle package Info.plist files.

There is some concern that this relies on an undocumented option, which Apple could change or take away at any time — but they could do that with documented options as well…

Stupid tricks with pkgbuild

One thought on “Stupid tricks with pkgbuild

Comments are closed.