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

Fallout Shelter pulls in ten times its u...
When the Fallout TV series was announced I, like I assume many others, assumed it was going to be an utter pile of garbage. Well, as we now know that couldn't be further from the truth. It was a smash hit, and this success has of course given the... | Read more »
Recruit two powerful-sounding students t...
I am a fan of anime, and I hear about a lot that comes through, but one that escaped my attention until now is A Certain Scientific Railgun T, and that name is very enticing. If it's new to you too, then players of Blue Archive can get a hands-on... | Read more »
Top Hat Studios unveils a new gameplay t...
There are a lot of big games coming that you might be excited about, but one of those I am most interested in is Athenian Rhapsody because it looks delightfully silly. The developers behind this project, the rather fancy-sounding Top Hat Studios,... | Read more »
Bound through time on the hunt for sneak...
Have you ever sat down and wondered what would happen if Dr Who and Sherlock Holmes went on an adventure? Well, besides probably being the best mash-up of English fiction, you'd get the Hidden Through Time series, and now Rogueside has announced... | Read more »
The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
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 »

Price Scanner via MacPrices.net

Verizon has Apple AirPods on sale this weeken...
Verizon has Apple AirPods on sale for up to 31% off MSRP on their online store this weekend. Their prices are the lowest price available for AirPods from any Apple retailer. Verizon service is not... Read more
Apple has 15-inch M2 MacBook Airs available s...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs available starting at $1019 and ranging up to $300 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at Apple.... Read more
May 2024 Apple Education discounts on MacBook...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $300 off the purchase of a new MacBook... Read more
Clearance 16-inch M2 Pro MacBook Pros in stoc...
Apple has clearance 16″ M2 Pro MacBook Pros available in their Certified Refurbished store starting at $2049 and ranging up to $450 off original MSRP. Each model features a new outer case, shipping... Read more
Save $300 at Apple on 14-inch M3 MacBook Pros...
Apple has 14″ M3 MacBook Pros with 16GB of RAM, Certified Refurbished, available for $270-$300 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year warranty is... Read more
Apple continues to offer 14-inch M3 MacBook P...
Apple has 14″ M3 MacBook Pros, Certified Refurbished, available starting at only $1359 and ranging up to $270 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year... Read more
Apple AirPods Pro with USB-C return to all-ti...
Amazon has Apple’s AirPods Pro with USB-C in stock and on sale for $179.99 including free shipping. Their price is $70 (28%) off MSRP, and it’s currently the lowest price available for new AirPods... Read more
Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more
Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more

Jobs Board

Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
*Apple* App Developer - Datrose (United Stat...
…year experiencein programming and have computer knowledge with SWIFT. Job Responsibilites: Apple App Developer is expected to support essential tasks for the RxASL 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.