#!/bin/bash
#
# create a compressed dmg from the selection.
# started using this instead of tar-gzip, cuz tar doesn't keep resource
# or finder info.
#
# And I really did try to do this one in applescript.  Just could not 
# figure out how to script Disk Copy.
#
# NOTE: name of first item used to name the dmg.
#
# michael conrad tilstra (tadpol@tadpol.org) Sun Feb 23 15:10:18 CST 2003

# uncomment the set, and comment the exec to debug.
#set -vxe
exec &>/dev/null

name=`basename "$1"`
workdir=`dirname "$1"`
spimg="/tmp/${name}.sparseimage"
dmg="${name}.dmg"

cd "$workdir"

# anything smaller than 5M, and you cannot make HFS+ good thing the compressed
# forms drop down to right about the size of the data you put in.
hdiutil create "$spimg" -megabytes 5 -type SPARSE -fs 'HFS+' -volname "$name"
devdev=`hdiutil attach "$spimg" | head -1 | cut -f1`

for i in "$@"
do
    ditto -rsrcFork "$i" "/Volumes/${name}/"
done

hdiutil detach $devdev
hdiutil convert "$spimg" -format 'UDZO' -o "$dmg" -tgtimagekey zlib-level=9

rm "$spimg"
