+ DMGWINBOTTOM=580
+ YPOS=$[ $DMGWINBOTTOM - 300 ]
+ XJADEOPOS="set position of item \"Jadeo.app\" of container window to {310, ${YPOS}}"
+
+ DMGBACKGROUND=dmgbgxj.png
+fi
+
+echo "Building DMG ..."
+
+# UC_DMG=$APPNAME-${release_version}-UC.dmg
+# FINAL_DMG=$APPNAME-${release_version}.dmg
+UC_DMG=$APPNAME-$release_version.dmg
+VOLNAME=$APPNAME-$release_version
+
+# TODO use mktemp
+export TMPDIR=`pwd`
+MNTPATH=`mktemp -d -t /ardourimg`
+TMPDMG=`mktemp -t ardour`
+ICNSTMP=`mktemp -t ardouricon`
+EXTRA_SPACE_MB=30
+DMGMEGABYTES=$[ `du -sk "$PRODUCT_PKG_DIR" | cut -f 1` * 1024 / 1048576 + $EXTRA_SPACE_MB ]
+
+echo "DMG MB = " $DMGMEGABYTES
+
+rm -f $UC_DMG "$TMPDMG" "${TMPDMG}.dmg" "$ICNSTMP"
+rm -rf "$MNTPATH"
+mkdir -p "$MNTPATH"
+
+TMPDMG="${TMPDMG}.dmg"
+
+hdiutil create -megabytes $DMGMEGABYTES "$TMPDMG"
+DiskDevice=$(hdid -nomount "$TMPDMG" | grep Apple_HFS | cut -f 1 -d ' ')
+newfs_hfs -v "${VOLNAME}" "${DiskDevice}"
+mount -t hfs "${DiskDevice}" "${MNTPATH}"
+
+cp -r ${PRODUCT_PKG_DIR}/* "${MNTPATH}" || exit
+mkdir "${MNTPATH}/.background"
+cp -vi ${DMGBACKGROUND} "${MNTPATH}/.background/dmgbg.png"
+
+echo "setting DMG background ..."
+
+echo '
+ tell application "Finder"
+ tell disk "'${VOLNAME}'"
+ open
+ set current view of container window to icon view
+ set toolbar visible of container window to false
+ set statusbar visible of container window to false
+ set the bounds of container window to {400, 200, 800, '${DMGWINBOTTOM}'}
+ set theViewOptions to the icon view options of container window
+ set arrangement of theViewOptions to not arranged
+ set icon size of theViewOptions to 64
+ set background picture of theViewOptions to file ".background:dmgbg.png"
+ make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
+ set position of item "'${APPDIR}'" of container window to {90, 100}
+ set position of item "Applications" of container window to {310, 100}
+ '${MIXBUSPOS}'
+ '${HARVIDPOS}'
+ '${XJADEOPOS}'
+ close
+ open
+ update without registering applications
+ delay 5
+ eject
+ end tell
+ end tell
+' | osascript
+
+chmod -Rf go-w "${MNTPATH}"
+sync
+
+echo "compressing Image ..."
+
+# Umount the image
+umount "${DiskDevice}"
+hdiutil eject "${DiskDevice}"
+# Create a read-only version, use zlib compression
+hdiutil convert -format UDZO "${TMPDMG}" -imagekey zlib-level=9 -o "${UC_DMG}"
+# Delete the temporary files
+rm "$TMPDMG"
+rm -rf "$MNTPATH"
+
+echo "setting file icon ..."
+
+cp ${PRODUCT_PKG_DIR}/$Resources/appIcon.icns ${ICNSTMP}.icns
+/usr/bin/sips -i ${ICNSTMP}.icns
+/Developer/Tools/DeRez -only icns ${ICNSTMP}.icns > ${ICNSTMP}.rsrc
+/Developer/Tools/Rez -append ${ICNSTMP}.rsrc -o "$UC_DMG"
+/Developer/Tools/SetFile -a C "$UC_DMG"
+
+rm ${ICNSTMP}.icns ${ICNSTMP}.rsrc
+
+echo
+echo "packaging suceeded."
+ls -l "$UC_DMG"
+
+echo "Done."
+exit