--- /dev/null
+#!/bin/sh
+#
+# make-osxdmg.sh
+#
+# Create a MacOSX dmg (disk image) for a given directory.
+#
+
+DMG_NAME="$1"
+BIN_DIR="$2"
+VOLUME_NAME="$3"
+
+ORG_DIR="$PWD"
+
+EXTRA_SIZE=4096
+
+
+# ****************************** usage ********************************
+
+function usage() {
+ cat <<_ACEOF
+make-osxdmg.sh <dmgname> [dirname] [volumename]
+_ACEOF
+}
+
+
+# ****************************** validate cmdline args ****************
+
+function defaultArgs() {
+ if test "x${BIN_DIR}" = "x"; then
+ BIN_DIR="$PWD"
+ fi
+ if test "x${VOLUME_NAME}" = "x"; then
+ VOLUME_NAME="$DMG_NAME"
+ fi
+}
+
+function validateArgs() {
+ if test "x$DMG_NAME" = "x"; then
+ usage;
+ exit 1
+ fi
+}
+
+
+# ****************************** sizing *******************************
+
+function calcSize() {
+ SIZE_KB=`du -sk ${BIN_DIR} | awk '{print $1}'`
+ SIZE_KB=`expr $SIZE_KB + ${EXTRA_SIZE}`
+}
+
+
+# ****************************** setup disk ***************************
+
+function setupDisk() {
+ DST_IMG="$1"
+
+ if test -e "${DST_IMG}"; then
+ echo " deleting old dmg ..."
+ rm "${DST_IMG}"
+ fi
+ hdiutil create -size ${SIZE_KB}k ${DST_IMG} -layout NONE
+
+ DISK=`hdid -nomount ${DST_IMG} | awk '{print $1}'`
+ echo " disk (no mount): $DISK"
+
+ newfs_hfs -v "${VOLUME_NAME}" "${DISK}"
+ ejectDisk;
+
+ DISK=`hdid ${DST_IMG} | awk '{print $1}'`
+ echo " disk: $DISK"
+}
+
+function ejectDisk() {
+ hdiutil eject "${DISK}"
+}
+
+function convertToReadOnlyCompressedImage() {
+ SRC_DMG="$1"
+ DST_DMG="$2"
+ # convert .dmg into read-only zlib (-9) compressed release version
+ hdiutil convert -format UDZO ${SRC_DMG} -o ${DST_DMG} -imagekey zlib-level=9
+}
+
+function internetEnableDiskImage() {
+ # internet-enable the release .dmg. for details see
+ # http://developer.apple.com/ue/files/iedi.html
+ hdiutil internet-enable -yes "$1"
+}
+
+
+# ****************************** running ******************************
+
+defaultArgs;
+validateArgs;
+
+echo "Building MacOSX DMG ${DMG_NAME}.dmg for $BIN_DIR .."
+
+calcSize;
+echo " size: ${SIZE_KB}K"
+
+setupDisk "${DMG_NAME}.dmg"
+
+echo -n " coping content to disk .."
+cd $BIN_DIR
+gnutar cf - . | ( cd "/Volumes/${VOLUME_NAME}" ; gnutar xf - )
+cd $ORG_DIR
+echo ".. done."
+
+# once again eject, to synchronize
+ejectDisk;
+
+REL_DMG="${DMG_NAME}-release.dmg"
+convertToReadOnlyCompressedImage "${DMG_NAME}.dmg" "${REL_DMG}"
+internetEnableDiskImage "${REL_DMG}"