1
+ #! /bin/bash
2
+
3
+ # by Andy Maloney
4
+ # http://asmaloney.com/2013/07/howto/packaging-a-mac-os-x-application-using-a-dmg/
5
+
6
+ dir=${0%/* }
7
+ if [ -d " $dir " ]; then
8
+ pushd " $dir "
9
+ fi
10
+
11
+ pushd ../../../cp-build-osx
12
+
13
+ # ./contrib/scripts/create_dmg.sh caveexpress 2.4
14
+
15
+ # set up your app name, version number, and background image file name
16
+ APP_NAME=" $1 "
17
+ VERSION=" $2 "
18
+ DMG_BACKGROUND_IMG=" Background.png"
19
+ cp " ../caveexpress/contrib/installer/osx/background.png" ${DMG_BACKGROUND_IMG}
20
+
21
+ # you should not need to change these
22
+ APP_EXE=" ${APP_NAME} .app/Contents/MacOS/${APP_NAME} "
23
+
24
+ VOL_NAME=" ${APP_NAME} ${VERSION} " # volume name will be "SuperCoolApp 1.0.0"
25
+ DMG_TMP=" ${VOL_NAME} -temp.dmg"
26
+ DMG_FINAL=" ${VOL_NAME} .dmg" # final DMG name will be "SuperCoolApp 1.0.0.dmg"
27
+ STAGING_DIR=" ./Install" # we copy all our stuff into this dir
28
+
29
+ # clear out any old data
30
+ rm -rf " ${STAGING_DIR} " " ${DMG_TMP} " " ${DMG_FINAL} "
31
+
32
+ # copy over the stuff we want in the final disk image to our staging dir
33
+ mkdir -p " ${STAGING_DIR} "
34
+ cp -rpf " ${APP_NAME} .app" " ${STAGING_DIR} "
35
+ # ... cp anything else you want in the DMG - documentation, etc.
36
+
37
+ pushd " ${STAGING_DIR} "
38
+
39
+ # strip the executable
40
+ echo " Stripping ${APP_EXE} ..."
41
+ strip -u -r " ${APP_EXE} "
42
+
43
+ # compress the executable if we have upx in PATH
44
+ # UPX: http://upx.sourceforge.net/
45
+ if hash upx 2> /dev/null; then
46
+ echo " Compressing (UPX) ${APP_EXE} ..."
47
+ upx -9 " ${APP_EXE} "
48
+ fi
49
+
50
+ # ... perform any other stripping/compressing of libs and executables
51
+
52
+ popd
53
+
54
+ # figure out how big our DMG needs to be
55
+ # assumes our contents are at least 1M!
56
+ SIZE=` du -sh " ${STAGING_DIR} " | sed ' s/\([0-9\.]*\)M\(.*\)/\1/' `
57
+ SIZE=` echo " ${SIZE} + 1.0" | bc | awk ' {print int($1+0.5)}' `
58
+
59
+ if [ $? -ne 0 ]; then
60
+ echo " Error: Cannot compute size of staging dir"
61
+ exit
62
+ fi
63
+
64
+ # create the temp DMG file
65
+ hdiutil create -srcfolder " ${STAGING_DIR} " -volname " ${VOL_NAME} " -fs HFS+ \
66
+ -fsargs " -c c=64,a=16,e=16" -format UDRW -size ${SIZE} M " ${DMG_TMP} "
67
+
68
+ echo " Created DMG: ${DMG_TMP} with size ${SIZE} "
69
+
70
+ # mount it and save the device
71
+ DEVICE=$( hdiutil attach -readwrite -noverify " ${DMG_TMP} " | \
72
+ egrep ' ^/dev/' | sed 1q | awk ' {print $1}' )
73
+
74
+ sleep 2
75
+
76
+ # add a link to the Applications dir
77
+ echo " Add link to /Applications"
78
+ pushd /Volumes/" ${VOL_NAME} "
79
+ ln -s /Applications
80
+ popd
81
+
82
+ # add a background image
83
+ mkdir /Volumes/" ${VOL_NAME} " /.background
84
+ cp " ${DMG_BACKGROUND_IMG} " /Volumes/" ${VOL_NAME} " /.background/
85
+
86
+ # tell the Finder to resize the window, set the background,
87
+ # change the icon size, place the icons in the right position, etc.
88
+ echo '
89
+ tell application "Finder"
90
+ tell disk "' ${VOL_NAME} ' "
91
+ open
92
+ set current view of container window to icon view
93
+ set toolbar visible of container window to false
94
+ set statusbar visible of container window to false
95
+ set the bounds of container window to {400, 100, 920, 440}
96
+ set viewOptions to the icon view options of container window
97
+ set arrangement of viewOptions to not arranged
98
+ set icon size of viewOptions to 72
99
+ set background picture of viewOptions to file ".background:' ${DMG_BACKGROUND_IMG} ' "
100
+ set position of item "' ${APP_NAME} ' .app" of container window to {160, 205}
101
+ set position of item "Applications" of container window to {360, 205}
102
+ close
103
+ open
104
+ update without registering applications
105
+ delay 2
106
+ end tell
107
+ end tell
108
+ ' | osascript
109
+
110
+ sync
111
+
112
+ # unmount it
113
+ hdiutil detach " ${DEVICE} "
114
+
115
+ # now make the final image a compressed disk image
116
+ echo " Creating compressed image"
117
+ hdiutil convert " ${DMG_TMP} " -format UDZO -imagekey zlib-level=9 -o " ${DMG_FINAL} "
118
+
119
+ # clean up
120
+ rm -rf " ${DMG_TMP} "
121
+ rm -rf " ${STAGING_DIR} "
122
+
123
+ echo ' Done.'
124
+
125
+ exit
0 commit comments