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