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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>