Annotation of imach/distributions/osx/createdmg3.sh, revision 1.1
1.1 ! brouard 1: #!/bin/bash
! 2: set -x
! 3: LANG=C # Otherwise du gives french comma and can't sum!
! 4: # borrowed to Andy Maloney
! 5: # http://asmaloney.com/2013/07/howto/packaging-a-mac-os-x-application-using-a-dmg/
! 6:
! 7: # make sure we are in the correct dir when we double-click a .command file
! 8: dir=${0%/*}
! 9: if [ -d "$dir" ]; then
! 10: cd "$dir"
! 11: fi
! 12:
! 13: # set up your app name, version number, and background image file name
! 14: #APP_NAME="imach"
! 15: APP_NAME=$4
! 16: VERSION=$5
! 17: #"0.98nT"
! 18: DMG_BACKGROUND_IMG="Background.png"
! 19:
! 20: # you should not need to change these
! 21: #APP_EXE="/Users/nbrouard/Documents/imachcvs/NetBeans/imach/src
! 22: #APP_EXE="${APP_NAME}.app/Contents/MacOS/${APP_NAME}"
! 23: APP_EXE="${APP_NAME}.app/Contents/MacOS/applet"
! 24:
! 25: #VOL_NAME="${APP_NAME} ${VERSION}" # volume name will be "SuperCoolApp 1.0.0"
! 26: VOL_NAME=$2 # volume name will be "SuperCoolApp 1.0.0"
! 27: #DMG_FINAL="${VOL_NAME}.dmg" # final DMG name will be "SuperCoolApp 1.0.0.dmg"
! 28: DMG_FINAL=$3 # final DMG name will be "SuperCoolApp 1.0.0.dmg"
! 29: DMG_TMP="${VOL_NAME}-temp.dmg"
! 30: STAGING_DIR="./Install" # we copy all our stuff into this dir
! 31:
! 32: # Check the background image DPI and convert it if it isn't 72x72
! 33: _BACKGROUND_IMAGE_DPI_H=`sips -g dpiHeight ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9]+\.[0-9]+'`
! 34: _BACKGROUND_IMAGE_DPI_W=`sips -g dpiWidth ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9]+\.[0-9]+'`
! 35:
! 36: if [ $(echo " $_BACKGROUND_IMAGE_DPI_H != 72.0 " | bc) -eq 1 -o $(echo " $_BACKGROUND_IMAGE_DPI_W != 72.0 " | bc) -eq 1 ]; then
! 37: echo "WARNING: The background image's DPI is not 72. This will result in distorted backgrounds on Mac OS X 10.7+."
! 38: echo " I will convert it to 72 DPI for you."
! 39:
! 40: _DMG_BACKGROUND_TMP="${DMG_BACKGROUND_IMG%.*}"_dpifix."${DMG_BACKGROUND_IMG##*.}"
! 41:
! 42: sips -s dpiWidth 72 -s dpiHeight 72 ${DMG_BACKGROUND_IMG} --out ${_DMG_BACKGROUND_TMP}
! 43:
! 44: DMG_BACKGROUND_IMG="${_DMG_BACKGROUND_TMP}"
! 45: fi
! 46:
! 47: # clear out any old data
! 48: rm -rf "${STAGING_DIR}" "${DMG_TMP}" "${DMG_FINAL}"
! 49:
! 50: # copy over the stuff we want in the final disk image to our staging dir
! 51: mkdir -p "${STAGING_DIR}"
! 52: cp -rpf "${APP_NAME}.app" "${STAGING_DIR}"
! 53: # ... cp anything else you want in the DMG - documentation, etc.
! 54:
! 55: pushd "${STAGING_DIR}"
! 56:
! 57: # strip the executable
! 58: echo "Stripping ${APP_EXE}..."
! 59: strip -u -r "${APP_EXE}"
! 60:
! 61: # compress the executable if we have upx in PATH
! 62: # UPX: http://upx.sourceforge.net/
! 63: if hash upx 2>/dev/null; then
! 64: echo "Compressing (UPX) ${APP_EXE}..."
! 65: upx -9 "${APP_EXE}"
! 66: fi
! 67:
! 68: # ... perform any other stripping/compressing of libs and executables
! 69:
! 70: popd
! 71:
! 72: # figure out how big our DMG needs to be
! 73: # assumes our contents are at least 1M!
! 74: SIZE=`du -sh "${STAGING_DIR}" | sed 's/\([0-9\.]*\)M\(.*\)/\1/'`
! 75: #SIZE=`du -sm "${STAGING_DIR}" | sed 's/\([0-9\.]*\)m\(.*\)/\1/'`
! 76: SIZE=`echo "${SIZE} + 1.0" | bc | awk '{print int($1+0.5)}'`
! 77: #SIZE=1
! 78:
! 79: if [ $? -ne 0 ]; then
! 80: echo "Error: Cannot compute size of staging dir"
! 81: exit
! 82: fi
! 83:
! 84: # create the temp DMG file
! 85: hdiutil create -srcfolder "${STAGING_DIR}" -volname "${VOL_NAME}" -fs HFS+ \
! 86: -format UDRW -size ${SIZE}M "${DMG_TMP}"
! 87: # -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}M "${DMG_TMP}"
! 88:
! 89: echo "Created DMG: ${DMG_TMP}"
! 90:
! 91: # mount it and save the device
! 92: # works and I verified that it keeps the hml subdirectory.
! 93: DEVICE=$(hdiutil attach -readwrite -noverify "${DMG_TMP}" | \
! 94: egrep '^/dev/' | sed 1q | awk '{print $1}')
! 95:
! 96: sleep 2
! 97:
! 98: # add a link to the Applications dir
! 99: echo "Add link to /Applications"
! 100: pushd /Volumes/"${VOL_NAME}"
! 101: ln -s /Applications
! 102: popd
! 103:
! 104: # add a background image
! 105: mkdir /Volumes/"${VOL_NAME}"/.background
! 106: cp "${DMG_BACKGROUND_IMG}" /Volumes/"${VOL_NAME}"/.background/
! 107:
! 108: # tell the Finder to resize the window, set the background,
! 109: # change the icon size, place the icons in the right position, etc.
! 110: echo '
! 111: tell application "Finder"
! 112: tell disk "'${VOL_NAME}'"
! 113: open
! 114: set current view of container window to icon view
! 115: set toolbar visible of container window to false
! 116: set statusbar visible of container window to false
! 117: set the bounds of container window to {400, 100, 920, 440}
! 118: set viewOptions to the icon view options of container window
! 119: set arrangement of viewOptions to not arranged
! 120: set icon size of viewOptions to 72
! 121: set background picture of viewOptions to file ".background:'${DMG_BACKGROUND_IMG}'"
! 122: set position of item "'${APP_NAME}'.app" of container window to {160, 205}
! 123: set position of item "Applications" of container window to {360, 205}
! 124: close
! 125: open
! 126: update without registering applications
! 127: delay 2
! 128: end tell
! 129: end tell
! 130: ' | osascript
! 131:
! 132: sync
! 133:
! 134: # unmount it
! 135: hdiutil detach "${DEVICE}"
! 136:
! 137: # now make the final image a compressed disk image
! 138: echo "Creating compressed image"
! 139: hdiutil convert "${DMG_TMP}" -format UDZO -imagekey zlib-level=9 -o "${DMG_FINAL}"
! 140:
! 141: # clean up
! 142: pwd
! 143: sleep 2
! 144: rm -rf "${DMG_TMP}"
! 145: rm -rf "${STAGING_DIR}"
! 146:
! 147: echo 'Done.'
! 148:
! 149: exit
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>