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:

/usr/bin/pkgbuild
/usr/bin/productbuild

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/Firefox.app /tmp/Firefox.pkg

I get a package for Firefox that requires a restart.

See http://s.sudre.free.fr/Stuff/Ivanhoe/FLAT.html 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…

Explore posts in the same categories: Deployment, Lion, OS X, Packaging

One Comment on “Stupid tricks with pkgbuild”

  1. Don Montalvo Says:

    radar.apple.com > 11705215


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 177 other followers

%d bloggers like this: