#!/bin/sh
## invoke this script like: create_dmg image_name "Volume Name"
## it will produce image_name.dmg
#
# mkdmg.sh imagename
# if a previous copy of the image exists, remove it
rm -f $1.dmg
# create the image. My software fits on a 5MB image
hdiutil create $1.dmg -size 05m -fs HFS+ -volname "$1"
# mount the image and store the device name into dev_handle
dev_handle=`hdid $1.dmg | grep Apple_HFS | perl -e '\$_=<>; /^\\/dev\\/(disk.)/; print \$1'`
# copy the software onto the disk
ditto -rsrcFork "build/Release/Transmission.app" "/Volumes/$1/Transmission.app" || exit 1
cp -p ../Changelog.txt /Volumes/$1
# unmount the volume
hdiutil detach $dev_handle
# compress the image
hdiutil convert $1.dmg -format UDZO -o $1.udzo.dmg
# remove the uncompressed image
rm -f $1.dmg
# move the compressed image to take its place
mv $1.udzo.dmg $1.dmg