TweetFollow Us on Twitter

Mac in the Shell: Packaging and Installing

Volume Number: 24 (2008)
Issue Number: 06
Column Tag: Mac in the Shell

Mac in the Shell: Packaging and Installing

Simplify and scale your install methodology

by Edward Marczak

Introduction

While many systems contain a package manager, OS X's is unique, for better or worse. More and more people are now getting familiar with the graphical PackageMaker.app (and if you're not, see Jose Cruz's article in this issue). However, the GUI utility is only half the issue. Once an application is packaged, it needs to be deployed, sometimes at grand scale. Also, it's important to be able to automate updates to a package over time so new installs user the newer versions. This article talks about the command-line version of PackageMaker.app, packagemaker, and command-line installer – two tools to help get software to the masses easily and automatically.

Earth

Packaging refers to placing files into a package format (which acts like a single file) that is used to install said files (the payload) on a target system. The graphical Packager Maker.app that ships with 10.5 developer tools is vastly improved over earlier versions. All of those improvements are brought to the command line build version. This includes the wonderful snapshot package, too.

For the sake of simplicity, let's imagine that the payload that you wish to install is contained entirely in a single directory. This can be a directory full of files, or a single application (which is, in reality, a folder full of files). We'll use the former in this example: a single directory containing some utility programs for our command line pleasure. This will need to be installed on all systems in our organization. packagemaker makes this a snap to package up. The simplest way to package this directory is to do the following:

Create an empty directory for general use in which to create packages.

Create another directory for the specific package to bundle up.

Place all directories and files with the correct hierarchy, permissions and owner inside of the specific directory to be packaged.

Run packagemaker:

/Developer/usr/bin/packagemaker \
-r /Users/germ/pkgbuilds/binutils/ \
-v -i com.radiotope.binutils \
-o ./binutils.pkg

The switches used in the example direct packagemaker in the following manner:

-r The build root, or, the directory of files to be packaged.

-v be verbose about it.

-i specify the package ID

-o Output file.

Technically, to make command this even shorter, the -v and -o switches could be omitted. Output, by default, will be dropped in the current directory, and be named based on the root.

To watch the file system for changes, and create a package based on those changes, use the —watch flag. Start packagemaker with the —watch, -o and -i flags, at minimum:

$ /Developer/usr/bin/packagemaker —watch -v -i com.radiotope.binutils -o binutils.pkg
Watching filesystem as pid: 53917. Send SIGUSR1 to stop: kill -SIGUSR1 53917

Note that you're provided the kill command that will properly stop packagemaker, and allow it perform the actual packaging. Once packagemaker is watching, perform the install that you'd like to package, and then send the signal using kill. packagemaker will carry on and create a package based on any files that have changed on the filesystem between the time it was started, and the time that it received the SIGUSR1 signal. Unlike it's GUI brethren, command line packagemaker does not allow an opportunity to edit the list of files that it has noted as changed. If you choose to use the —watch flag, ensure that you're running it at a time when the filesystem is least active.

Fire

While packagemaker is effective at automating package builds, sometimes it's just plain easier to use the GUI-based PackageMaker.app to create the first revision. Package Maker.app grants greater flexibility in many cases. Gratefully, the two utilities can be combined: use PackageMaker.app to initially create a package, with the precise options necessary. This configuration can be saved as a .pmdoc file. The command line packagemaker can take a .pmdoc file and build a package based on the configuration options specified within. This can then be used as upgrades to the original package take place.

To allow packagemaker to take direction from a .pmdoc file, use the -d, or —doc switch to specify the .pmdoc file:

/Developer/usr/bin/packagemaker \
-d /Users/germ/pmdoc/Bin_Utils.pmdoc \
-v -i com.radiotope.binutils \
-o ./binutils.pkg

Any options specified on the command line override the equivalent option from the .pmdoc file.

Water

Once packages are created, the goal is to install them on target systems. They can be brought over to a target system in many ways, but once there, they will be installed using Apple's installer. Like PackageMaker, installer comes in both a GUI and command-line version. The command-line version is the gateway to automating installs.

The basic syntax is short and sweet:

installer -pkg [path to package] -target [path to destination volume/device]

To install the example binutils.pkg on the current system volume, the command would look like this:

installer -pkg /packages/binutils.pkg -target /

Before installing, installer can determine which targets on the current system are valid. The -volinfo switch lists all valid volumes for a given package. Some packages have constraints on installation targets, such as "home" or "root volume only." To obtain a list of currently mounted volumes that are appropriate destinations, supply the package and volinfo switches:

installer -pkg /packages/binutils.pkg -volinfo 

This output can be parsed for a valid destination.

Finally, note that the -target switch can also accept other forms of listing the destination. Also acceptable are device node entries (/dev/disk3), a disk identifier (/dev/disk1s6) or a volume's UUID. It will also accept a domain as listed in the -dominfo switch, however, since very few packages contain domain information, this method has lesser value than methods shown earlier.

Air

The importance of the command line versions of these utilities lies in automation.

MacTech has run several articles that talk about AFP548's InstaDMG, a build tool to create a system image. The command line installer is at the heart of this program. An excerpt from the main script shows installer in action:

/bin/ls -A1 $UPDATE_FOLDER | /usr/bin/sed '/.DS_Store/d' | while read UPDATE_PKG
   do
      /usr/sbin/installer -verbose \
    -pkg "${UPDATE_FOLDER}/${UPDATE_PKG}/`/bin/ls ${UPDATE_FOLDER}/${UPDATE_PKG} | \
    /usr/bin/sed '/.DS_Store/d'`" \
    -target $CURRENT_IMAGE_MOUNT >> $LOG_FILE
      /bin/echo "Installed ${UPDATE_FOLDER}/${UPDATE_PKG}/`/bin/ls ${UPDATE_FOLDER}/${UPDATE_PKG} | \
    /usr/bin/sed '/.DS_Store/d'`" >> $PKG_LOG
   done

The idea behind this except is to list all packages in a hierarchy of folders and send that list in order to installer, which installs each package in turn.

Another approach to automating this type of install would be using the find command:

find ${UPDATE_FOLDER} -iname "*pkg" -type d -exec installer -pkg {} -target / \;

This command could also be redirected to a file (remember to specify -verbose in the installer command!) for logging purposes.

The installer command can also be individually distributed to OS X systems using dshell (see the January 2008 issue of MacTech), or via Apple Remote Desktop's "Send Unix" command. While ARD does have a method to directly install packages, it proves unreliable in many instances, including sending packages to machines over a WAN, and sending packages to too many machines. The number that consists of "too many" is inconsistent from run to run and environment to environment.

Rather than send one-liners, a larger, structured script can direct a machine to mount a remote disk image (using hdiutil), install a package on that volume, dismount the volume and reboot the remote machine if necessary and appropriate. It can do all of this while checking for errors and reporting on progress, too.

Conclusion

As OS X systems become more prevalent, better methods of configuration and installation need to appear in order to allow administrators the ability to serve users in a timely manner. The methods in this article can be used with or without a complete OS X infrastructure (e.g. Without OS X Server supporting directory services or more of the back-end). Automation means consistency. Possibly more important, though, is that it means timeliness and less work for administrators once set up.

Also, packaging allows an administrator to pretty much do anything to a target system. Since preferences and user accounts are stored as files, installer can overwrite them. Also, since packages can runs scripts, they can perform even more sophisticated functions. Your imagination is the only limit.

Media of the month: "The Design and Implementation of the FreeBSD Operating System" by Marshall Kirk McKusick and George V. Neville-Neil. While not a perfect fit, this may be the closest thing we have to an OS X internals book. The BSD file structures all match up, along with what happens at the Unix layer. Combine this with the Mac specific (but sadly dated) Mac OS X Internals by Amit Singh, and you have some incredibly deep knowledge of lower level structures and system activity.

Hopefully you're reading this while attending WWDC (yes, it's that time of the year again). Or, this is providing some travel reading for you. In any case, MacTech will be present, so feel free to find us and say hello!

Until next month, enjoy WWDC and all that encompasses it, and keep scripting.

References

PackageMaker Users Guide, Apple Computer. http://developer.apple.com/documentation/DeveloperTools/Conceptual/PackageMakerUserGuide/PackageMaker_UserGuide.pdf

packagemaker man page

installer man page


Ed Marczak is the Executive Editor for MacTech Magazine, and has been lucky enough to have ridden the computing and technology wave from early on. From teletype computing to MVS to Netware to modern OS X, his interest was piqued. He has also been fortunate enough to come into contact with some of the best minds in the business. Ed spends his non-compute time with his wife and two daughters.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.