#!/bin/sh
#
# Creates a disk image (dmg) on Mac OS X from the command line.
# usage:
#    mkdmg <volname> <vers> <srcdir>
#
# Where <volname> is the name to use for the mounted image, <vers> is the version
# number of the volume and <srcdir> is where the contents to put on the dmg are.
#
# The result will be a file called <volname>-<vers>.dmg

set -xe

if [ $# != 3 ]; then
 echo "usage: mkdmg.sh volname vers srcdir"
 exit 0
fi

VOL="$1"
FILES="$2"
DEST="$3"

TMP_DMG="/tmp/tmp-$VOL.dmg"
rm -f "$TMP_DMG"

# create temporary disk image and format, ejecting when done
hdiutil create -ov -fs HFS+ -volname "$VOL" -srcfolder ${FILES} "$TMP_DMG" 

# convert to compressed image, delete temp image
rm -f $DEST
hdiutil convert "$TMP_DMG" -format UDZO -o $DEST
rm -f "$TMP_DMG"
