Archives

Creative Commons License
This blog is licensed under a Creative Commons License.

Script of the week: bzdmg

| No TrackBacks

I haven’t written much this past week because I’ve been upgrading all the home’s machines to Leopard. So far it’s gone very smoothly, and I like the new OS!

The script for this week is about disk images. Since version 10.4 of the operating system, OS X has had the ability to internally (and transparently) compress disk images using bzip2. Probably because of compatibility issues with 10.3, I rarely ever see vendors compressing their disk images this way (I even see them using gzip on the image after it’s made, which makes no sense at all since internal gzip compression has been supported for a long time!). And so I wrote this script, which re-compresses disk image files using internal bzip2 compression. This can result in significant space savings over many images. And if it’s already been compressed with bzip2, the script reports this and changes nothing.

Here it is, which I call bzdmg:

#!/bin/bash

if (( $# == 0 )); then
    echo "usage: bzdmg <DISK IMAGES...>"
    exit 1
fi

for file in "$@"; do
    FORMAT=$(hdiutil imageinfo "$file" | grep ^Format:)
    if [[ "$FORMAT" == "Format: UDBZ" ]]; then
        echo $file is already compressed with bzip.
    else
        TEMP=/tmp/image-$$.dmg
        if hdiutil convert -format UDBZ -o $TEMP "$file"; then
            mv -f $TEMP "$file" 2> /dev/null
            if [[ -f $TEMP ]]; then
                echo Error converting disk image file '$file'
                rm -f $TEMP
            fi
        fi
    fi
done

No TrackBacks

TrackBack URL: http://www.newartisans.com/mt/mt-tb.cgi/30

About this Entry

This page contains a single entry by John Wiegley published on November 4, 2007 10:04 PM.

A regular expression IDE for Emacs was the previous entry in this blog.

Running Common Lisp behind Apache is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Recent Comments

  • Curt Sampson: That there’s “no state” in Haskell is quite wrong; in read more
  • rv: Hi. I wanted to drop you a quick note to read more
  • John Wiegley: It’s here: http://ftp.newartisans.com/pub/python/modpython_gateway.py read more
  • Leon: The file “modpython_gateway.py” Is no longer available in the downloads read more
  • Kathy: Well, the article is really the sweetest on this laudable read more
  • mr.design: Hi John, I just started to read your GFTBU, it’s read more
  • yoman: “Barfin”? “Slurping”? “Slime” “Hunchentoot” ??? What in the T.F. world read more
  • John Wiegley: Something like this is slated for the next release of read more
  • womens health: According to me, Apple has implemented something called blocks, which read more
  • Bjorn Tipling: Why would you add instructions for installing an editor when read more
OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.261