Hack 62 Software Update on the Command Line

figs/beginner.giffigs/hack62.gif

Just like it's pretty GUI counterpart, the command-line softwareupdate checks for updates to OS X itself and other associated applications, installing them upon approval.

As Apple moves onward and upward in its efforts to synchronize what happens above and below the shiny Aqua desktop, some previously GUI-only bits have made their way to the Terminal command line. One such function is Software Update; just like its pretty GUI counterpart, softwareupdate (man softwareupdate) checks for updates to OS X itself and other associated applications, installing them upon approval.

Aside from simply appealing to Unix jocks, Software Update on the command line affords administrators (especially those with multiple Macs to keep in sync) the ability to log in remotely and perform updates without having to wander physically from machine to machine. A good admin can actually go so far as to automate the process.

62.1 Software Update CLI Walk-Through

Let's take a stroll through softwareupdate.

It's always advisable to close out of all applications except the Finder and Software Update or the Terminal in which you're doing a software update. This is the best preemptive medicine for avoiding complications and conflicts that might arise from updating the system beneath the feet of running applications.

The first step is to see if any updates are available. Launch the Terminal[Hack #48] application and type softwareupdate at the command-line prompt. Software Update calls home over your network or dial-up connection, returning shortly with a list of updates, if any.

Should your system be completely up-to-date, Software Update will simply tell you so:

% softwareupdate
Software Update Tool
Copyright 2002 Apple Computer, Inc.

Your software is up to date.

In this case, however, Software Update proffers a slew of updates, mostly having to do with language support:

% softwareupdate
Software Update Tool
Copyright 2002 Apple Computer, Inc.

Software Update found the following new or updated software:

- BrazilianPortugueseSU
Brazilian Portuguese Language Support (10.1.5), 5712K
- DanishSU
Danish Language Support (10.1.5), 6000K
- FinnishSU
Finnish Language Support (10.1.5), 5492K
- KoreanSU
Korean Language Support (10.1.5), 40640K
- NorwegianSU
Norwegian Language Support (10.1.5), 5592K
- SecurityUpd2002-08-02
Security Update 2002-08-02 (1.0), 5300K - restart required
- SimplifiedChineseSU
Simplified Chinese Language Support (10.1.5), 37580K
- TraditionalChineseSU
Traditional Chinese Language Support (10.1.5), 39060K


To install an update, run this tool with the item name as an argument.
e.g. 'softwareupdate <item> ...'

While installing any particular update is up to you and your particular system configuration, some, like the security update hidden among the others here, you'll want to install right away. To install a particular update, type softwareupdate, followed by the name ? or names, since softwareupdate, like its GUI counterpart, can install more than one at a time ? of the package you wish to install; you'll need to sudo [Hack #50], since software updates invariably involve changing global system files and settings:

% sudo softwareupdate SecurityUpd2002-08-02
Password:
Software Update Tool
Copyright 2002 Apple Computer, Inc.

Downloading "Security Update 2002-08-02"... 10% 20% 30% 40% 50%
2002-08-05 13:52:48.941 softwareupdate[13686] File to verify: 
/var/root/Library/Caches/a1028.g.akamai.net/5/1028/3093/1/
1a1a1a88ff63d249b72392f35785e656c63297c52897043397067
deb57c6278bfe2d82d504346a9bc8f8295a91c03867cb337bf347
8cf055960b71c5fd74a51258c53f99/SecurityUpd2002-08-02.tar
2002-08-05 13:52:52.207 softwareupdate[13686] File verification succeeded
2002-08-05 13:52:52.213 softwareupdate[13686] Verified file now to install: 
/tmp/SecurityUpd2002-08-02.pkg.tar
2002-08-05 13:52:52.215 softwareupdate[13686] Returning 1 from VerifyFile

Unarchiving "Security Update 2002-08-02"... 50%
Installing "Security Update 2002-08-02"... 67% 70% 80% 90% 100% done.

You have installed one or more updates that requires that you restart your
computer. Please restart immediately.

Software Update downloads, verifies, unpacks, and installs the update. Notice the admonishment to "Please restart immediately"; when Software Update advises an immediate restart, take the advice and restart your Macintosh before doing much of anything else. While the GUI-flavored Software Update won't let you out of Software Update without restarting when necessary, the command-line version leaves you, in true Unix style, to your own devices and peril.

What happens if you don't restart immediately? Bad things, no doubt. Perhaps you were editing the Apache configuration file, since updated beneath your feet by the software update. Or you've made some seemingly minor change via NetInfo that's incompatible with an updated system setting. While it's best to close down everything except the Finder before doing a software update, it's certainly strongly advised that you restart when told to do so.

62.2 Snooping About

Whether you're running Software Update from the GUI or command line, the mechanics are the same. While an understanding is in no way needed to use softwareupdate, the more inquisitive user might find the underpinnings well worth a quick gander.

There was some mention of verifying a file called SecurityUpd2002-08-02.tar. This is a compressed archive (often called a tarball [Hack #4]) containing all the files composing the update. The archive contains a signature for verifying that the archive wasn't damaged in transit and another tarball, the update package itself:

% tar tvf /var/root/Library/Caches/a1028.g.akamai.net/5/1028/3093/1/
1a1a1a88ff63d249b72392f35785e656c63297c52897043397067deb57c6278b
fe2d82d504346a9bc8f8295a91c03867cb337bf3478cf055960b71c5fd74a51258
c53f99/SecurityUpd2002-08-02.tar

-rw-r--r-- swupdate/wheel 543 2002-08-01 15:33:20 signature
-rw-r--r-- swupdate/unknown 5416960 2002-08-01 15:26:04 Security
Upd2002-08-02.pkg.tar

OS X keeps a record of installs and updates in /Library/Receipts, the remnants of which may be found in each package's Contents/Resources directory.

% ls /Library/Receipts/SecurityUpd2002-08-02.pkg/Contents/Resources/
BundleVersions.plist VolumeCheck
Dutch.lproj da.lproj
English.lproj fi.lproj
French.lproj ko.lproj
German.lproj no.lproj
InstallationCheck package_version
Italian.lproj pt.lproj
Japanese.lproj software_version
SecurityUpd2002-08-02.bom sv.lproj
SecurityUpd2002-08-02.loc zh_CN.lproj
SecurityUpd2002-08-02.sizes zh_TW.lproj
Spanish.lproj

Of course, the actual files themselves have been installed into the appropriate places all over the filesystem. However, for a glimpse of all that was installed and altered, we turn to the bom (man bom), or bill of materials, file, viewable with the lsbom command (type man lsbom on the command line for more information):

% lsbom /Library/Receipts/SecurityUpd2002-08-02.pkg/Contents/Resources/
SecurityUpd2002-08-02.bom | more

. 41775 0/80
./System 40755 0/0
./System/Library 40755 0/0
./System/Library/Frameworks 40755 0/0
./System/Library/Frameworks/System.framework 40755 0/0
./System/Library/Frameworks/System.framework/Resources 120755 0/0 26
3302263027 Versions/Current/Resources
./System/Library/Frameworks/System.framework/System 120755 0/0 23
285767527 Versions/Current/System
...
./usr/share/man/man8/rotatelogs.8 100644 0/0 4150 1165073178
./usr/share/man/man8/sftp-server.8 100644 0/0 2087 1556173402
./usr/share/man/man8/ssh-keysign.8 100644 0/0 2375 3700322105
./usr/share/man/man8/sshd.8 100644 0/0 26471 342712072