Lab Notebook: Packaging UNIX Programs and Directories

Author: Geoff Hutchison
Website: http://geoffhutchison.net/

This week's installment of my irregular "lab notebook" articles on setting up a Mac-only lab centers around creating installation packages.

If you use Apple Remote Desktop to manage a cluster like I do, you can use Installer packages to distribute software across the entire cluster at once. This makes it extremely easy to be sure UNIX programs in /usr/local/bin or elsewhere on the filesystem are all properly installed on the cluster.

Packages are also a very effective way to maintain software across re-installation of Mac OS X. For example, if you're considering upgrading to Leopard, the typical "Archive and Install" or "Erase and Install" options will not preserve your UNIX files in /usr/local or other paths.

Using PackageMaker

I'm going to demonstrate creating a package of all my MacPorts and other UNIX packages in the /opt directory structure. I did the same thing for /usr/local.

If you've installed the Developer Tools, you can find PackageMaker.app in /Developer/Applications/Utilities as shown below:

PackageMaker.app

Once you launch PackageMaker, you're promptd to create a new package. Stick with a Single Package Project for now.

The first tab you'll see with the new PackageMaker project you created is an installer interface. Since I'm installing these packages remotely, I don't care too much about the interface. I usually give a quick title and description to remind myself (or others) what the package does and that it's intended for remote installation.

Click the next tab "Contents," where we really get to work. This is where we specify which files are included in the package. In this case, we want to bundle up everything in /opt:

Package Contents

The Root: path specifies where the files are to install. In many cases (e.g., if you're developing an application), you will probably pick a temporary directory. Here we're just packaging up a live path, so you can just type in /opt

The next tab "Configuration" sets where the files will be installed and how the installation will occur. Since the packaging will strip the Root: directory path off of filenames, you will want to specify /opt again as the Default Location: for this package.

Package Configuration

Note that we want the package to be installed by Root, and we don't want anyone to try to move the package to another path or volume.

The "Scripts" tab can be used to set a variety of scripts to run before installation (e.g., to determine if this package should be installed on this computer) or afterwards. For this particular tutorial, we're going to skip that.

Move now to the "Package Version" tab, since you will need to specify some information here as well:

Package Version

You must give this package an identifier, or it will not build. The convention is to use a reverse domain name (e.g., com.apple.xcode), but any unique name for the package will work. I use a scheme like edu.pitt.chem.hutchison.opt since my computers are in the chem.pitt.edu domain and I can then give unique package names in the other parts of the identifier.

You should give a version number for this package, since it will allow you to track as you create new versions over time.

Summary

That's it. Once you have everything set up, go to the File menu and save your package "project." Then go to the Build menu and choose "Build" to create the actual Opt.pkg file. You can then install this using the command-line installer, the default Installer.app graphical interface, or Apple Remote Desktop.

As I said, I've done this not just to distribute packages across my cluster, but also to have backups of my UNIX binaries when I upgrade to Leopard.

Any questions?

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Is this the only way to preserve /opt etc. for Leopard?

Is this the only way to preserve /opt, /usr/local, etc., when upgrading (or re-installing) the OS? Does Apple not provide direct support for doing this?

Jerry

As I said...

If you choose an "Archive and Install" or "Erase and Install" when upgrading the OS or re-installing, then by definition, those directories will be archived or erased. Keep in mind that these are not Apple system files, so there's not necessarily a reason for them to remain in-place.

So if you upgrade or re-install and you intend to choose those options, you should either:

  • Create an archive of those directories (.zip, .tar.gz, whatever) and uncompress later
  • or create a package as I described (which also compresses like a .tar.gz

Now if you choose "Archive and Install," all your directories will be preserved -- they go into the "/Previous System" directory. You can also find them there.

But I did mention creating packages for this reason -- new Mac users may be surprised if their files in /opt or /usr/local are initially "missing," when installing Leopard.