Fetching contributors…
Cannot retrieve contributors at this time
54 lines (35 sloc) 1.32 KB
#!/bin/csh -ef
# Make a disk image from a directory.
# input 'name', 'size' (in MB), 'files/directories'
set prog = `/usr/bin/basename $0`
set usage="$prog <directory>"
set directory = `cd -l "$1"`
set name = `basename "$directory"`
if ( "$directory" == "" ) then
echo "$usage" ; exit
set outdir="$2"
if ( "$outdir" == "") then
set scratch=/tmp/"$name"-scratch
set kBytes = `du -ks "$directory" | sed -e "s/\([0-9]*\).*/\1/"`
rm -f "$scratch.dmg"
# make image 5MB larger than needed. Prevents problems with too small images
set kBytes = `echo "$kBytes + 5120" | bc `
# create an empty disk image of $kBytes kB
hdiutil create -size "$kBytes"k -fs HFS+ -volname "$name" "$scratch"
# mount/attach the disk image (returns sth. like /dev/disk1)
set info = `hdid "$scratch.dmg"`
set device = `echo "$info" | sed "s|\(/dev/[A-Za-z0-9]*\).*|\1|1"`
set volume = `echo "$info" | sed "s|.*\(/Volumes/.*\)|\1|1"`
# copy stuff into the disk image manually
cp -R "$directory/" "$volume/"
# eject/detach the disk image again
hdiutil eject "$device"
rm -f "$outdir/$name.dmg"
# finalize disk image with some format and name
hdiutil convert "$scratch.dmg" -format UDCO -o "$outdir/$name"
# clean up tmp files
rm -f "$scratch.dmg"