Archives

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

Script of the week: bzdmg

| No Comments | 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

Leave a comment

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

  • yoman: “Barfin”? “Slurping”? “Slime” “Hunchentoot” ??? What in the T.F. world read more
  • Bjorn Tipling: Why would you add instructions for installing an editor when read more
  • Mark Aufflick: sudo port install sbcl +threads If you previously installed sbcl read more
  • Alexander Lehmann: Thank. You. So. Much. – Clisp caused a lot of read more
  • Vetle: Btw, to get support for threading in SBCL, you have read more
  • ifade: I tried the same and get the same answer, but read more
  • Martial Boniou: Hi, I tried to install slime with MacPorts and I read more
OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.261