#!/bin/sh # usage mkdmgfromapp appname [extrafile] [extrafile] # if [ ! -d "$1" ] || [ `basename "$1" .app` == `basename "$1"` ] then echo "Cannot find $1 or not an .app. Bailing out..." exit 1 fi NAME=`basename "$1" .app` VERSION=`plist -Key CFBundleVersion -Path "$1"/Contents/Info.plist` DMG=${NAME}-"${VERSION}".dmg VOLNAME="${NAME}-${VERSION}-Volume" rm -f "${DMG}" "${DMG}".gz hdiutil create -megabytes 4 "${DMG}" -layout NONE AppDisk=`hdid -nomount "${DMG}"|sed 's/ .*//'` echo "Disk: ${AppDisk}" newfs_hfs -v "${VOLNAME}" "${AppDisk}" hdiutil eject "${AppDisk}" echo Step HDID=`hdid "${DMG}"` # Warning: hidden behaviour # Both patterns below contain a space and a tab. Do not edit with an editor # that translates tab to space or space to tab AppDisk=`echo -n "${HDID}"|sed 's/[ ].*//'` AppVolume=`echo -n "${HDID}"|sed 's/^[^ ]*[ ]*//'` echo "Disk: ${AppDisk} Vol: ${AppVolume}" if [ ! -d "${AppVolume}" ] then echo "Cannot locate ${AppVolume} volume. Baling out..." exit 1 else while [ $# -gt 0 ] do cp -pr "$1" "${AppVolume}" shift done fi hdiutil eject "${AppDisk}" gzip -9 "${DMG}" exit 0