2 # $Id: dmg.sh,v 1.4 2005/08/28 13:08:50 petterik Exp $
7 # dmg.sh <project_name> <project_version>
9 # Shell script for wrapping up mountable Mac OS X disk image
10 # containing a native installation package.
20 if ([ "$NAM" = "" ] || [ "$VER" = "" ]) ; then
21 echo "usage: dmg.sh <project name> <project version>"
25 if [ "$REL" = "" ] ; then
31 DSKNAM=${NAM}-${VER}-${REL}
33 if [ ! -d $PRJ ] ; then
34 echo " Directory $PRJ does not exist"
38 for f in $TMPIMG ${DSKNAM}.dmg ${DSKNAM}.dmg.gz ; do
45 BLKS=`du -s $PRJ | awk '{print $1}'`
47 echo " $PRJ blocks $BLKS"
49 # man hdutil example adds 100 sectors, min size is 4MB
50 if [ $BLKS -lt 8192 ] ; then
53 BLKS=`expr $BLKS \+ 100`
56 echo " Using $BLKS sectors for raw image"
58 hdiutil create $TMPIMG -sectors $BLKS -layout NONE
60 # Create a /dev/disk device from the image
61 drive=`hdid -nomount $TMPIMG | awk '{print $1}'`
63 # Create a new filesystem on the disk device
64 newfs_hfs -v "${DSKNAM}" -b 4096 /dev/r${drive:t}
67 echo " Image formatted, ejecting ${drive}..."
68 hdiutil eject ${drive}
70 echo " Mounting $TMPIMG ..."
71 drive=`hdid $TMPIMG | awk '{print $1}'`
73 echo " Searching for ${drive}..."
74 while [ "$MOUNTPOINT" = "" ] ; do
75 MOUNTPOINT=`df -l | grep $drive | awk '{print $6}'`
77 echo " Found $drive at $MOUNTPOINT"
79 # Unpack the tarball into the mounted filesystem
80 echo " Copying application..."
82 tar cf - $PRJ | (cd $MOUNTPOINT; tar xf -)
86 hdiutil eject ${drive}
88 # Convert the image to a UDIF compressed image
89 echo " Compressing..."
90 hdiutil convert -format UDCO $TMPIMG -o ${DSKNAM}.dmg
93 # Remove the temporary image
94 echo " Removing scratch image"
97 ls -l ${DSKNAM}.dmg.gz