source: launchers/macosx/osx_create_dmg.sh @ 609d594

Last change on this file since 609d594 was 609d594, checked in by meeh <meeh@…>, 15 months ago

Mac OSX Launcher: 0.1.3 Release commit.

  • Property mode set to 100755
File size: 3.8 KB
Line 
1#!/usr/bin/env bash
2DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3
4source $DIR/.sign-secrets
5
6APP_NAME="I2PLauncher"
7VERSION="`/usr/libexec/PlistBuddy -c 'Print I2PRouterVersion' Info.plist`"
8DMG_BACKGROUND_IMG=${BACKGROUND_IMG:-"Background.png"}
9
10APP_EXE="${APP_NAME}.app/Contents/MacOS/${APP_NAME}"
11VOL_NAME="${APP_NAME}-${VERSION}"
12DMG_TMP="${VOL_NAME}-temp.dmg"
13DMG_FINAL="${VOL_NAME}.dmg"
14STAGING_DIR="/tmp/mkdmg$$"
15
16# Check the background image DPI and convert it if it isn't 72x72
17_BACKGROUND_IMAGE_DPI_H=`sips -g dpiHeight ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9]+\.[0-9]+'`
18_BACKGROUND_IMAGE_DPI_W=`sips -g dpiWidth ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9]+\.[0-9]+'`
19
20if [ $(echo " $_BACKGROUND_IMAGE_DPI_H != 72.0 " | bc) -eq 1 -o $(echo " $_BACKGROUND_IMAGE_DPI_W != 72.0 " | bc) -eq 1 ]; then
21   echo "WARNING: The background image's DPI is not 72.  This will result in distorted backgrounds on Mac OS X 10.7+."
22   echo "         I will convert it to 72 DPI for you."
23
24   _DMG_BACKGROUND_TMP="${DMG_BACKGROUND_IMG%.*}"_dpifix."${DMG_BACKGROUND_IMG##*.}"
25
26   sips -s dpiWidth 72 -s dpiHeight 72 $DIR/${DMG_BACKGROUND_IMG} --out $DIR/${_DMG_BACKGROUND_TMP}
27
28
29  DMG_BACKGROUND_IMG="${_DMG_BACKGROUND_TMP}"
30fi
31
32# copy over the stuff we want in the final disk image to our staging dir
33mkdir -p "${STAGING_DIR}"
34cp -rpf "${APP_NAME}.app" "${STAGING_DIR}"
35# ... cp anything else you want in the DMG - documentation, etc.
36
37# figure out how big our DMG needs to be
38#  assumes our contents are at least 1M!
39SIZE=`du -sh "${STAGING_DIR}" | sed 's/\([0-9\.]*\)M\(.*\)/\1/'`
40SIZE=`echo "${SIZE} + 23.0" | bc | awk '{print int($1+0.5)}'`
41
42if [ $? -ne 0 ]; then
43   echo "Error: Cannot compute size of staging dir"
44   exit
45fi
46
47# create the temp DMG file
48hdiutil create -srcfolder "${STAGING_DIR}" -volname "${VOL_NAME}" -fs HFS+ \
49      -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}M "$RELEASE_DIR/${DMG_TMP}"
50
51echo "Created DMG: ${DMG_TMP}"
52
53# mount it and save the device
54DEVICE=$(hdiutil attach -readwrite -noverify "$RELEASE_DIR/${DMG_TMP}" | \
55         egrep '^/dev/' | sed 1q | awk '{print $1}')
56
57sleep 2
58
59
60
61# add a link to the Applications dir
62echo "Add link to /Applications"
63cd /Volumes/"${VOL_NAME}"
64ln -sf /Applications Applications
65
66# add a background image
67mkdir -p /Volumes/"${VOL_NAME}"/.background
68cp "$DIR/`basename ${DMG_BACKGROUND_IMG}`" /Volumes/"${VOL_NAME}"/.background/`basename ${DMG_BACKGROUND_IMG}`
69
70cd $RELEASE_DIR
71
72# tell the Finder to resize the window, set the background,
73#  change the icon size, place the icons in the right position, etc.
74echo '
75   tell application "Finder"
76     tell disk "'${VOL_NAME}'"
77           open
78           set current view of container window to icon view
79           set toolbar visible of container window to false
80           set statusbar visible of container window to false
81           set the bounds of container window to {400, 100, 920, 440}
82           set viewOptions to the icon view options of container window
83           set arrangement of viewOptions to not arranged
84           set icon size of viewOptions to 72
85           set background picture of viewOptions to file ".background:'${DMG_BACKGROUND_IMG}'"
86           set position of item "'${APP_NAME}'.app" of container window to {160, 205}
87           set position of item "Applications" of container window to {360, 205}
88           close
89           open
90           update without registering applications
91           delay 2
92     end tell
93   end tell
94' | osascript
95
96sync
97
98# unmount it
99hdiutil detach "${DEVICE}"
100
101# now make the final image a compressed disk image
102echo "Creating compressed image"
103hdiutil convert "$RELEASE_DIR/${DMG_TMP}" -format UDZO -imagekey zlib-level=9 -o "$RELEASE_DIR/${DMG_FINAL}"
104
105codesign --force --deep --sign "${APPLE_CODE_SIGNER_ID}" "$RELEASE_DIR/${DMG_FINAL}"
106
107# clean up
108rm -rf "$RELEASE_DIR/${DMG_TMP}"
109rm -rf "${STAGING_DIR}"
110
111
112echo 'Done.'
113
114exit
Note: See TracBrowser for help on using the repository browser.