|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -set -e |
| 3 | +set -ex |
4 | 4 |
|
5 | 5 | # Original by Andy Maloney
|
6 | 6 | # http://asmaloney.com/2013/07/howto/packaging-a-mac-os-x-application-using-a-dmg/
|
@@ -29,11 +29,8 @@ _BACKGROUND_IMAGE_DPI_W=`sips -g dpiWidth ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9
|
29 | 29 | if [ $(echo " $_BACKGROUND_IMAGE_DPI_H != 72.0 " | bc) -eq 1 -o $(echo " $_BACKGROUND_IMAGE_DPI_W != 72.0 " | bc) -eq 1 ]; then
|
30 | 30 | echo "WARNING: The background image's DPI is not 72. This will result in distorted backgrounds on Mac OS X 10.7+."
|
31 | 31 | echo " I will convert it to 72 DPI for you."
|
32 |
| - |
33 | 32 | _DMG_BACKGROUND_TMP="${DMG_BACKGROUND_IMG%.*}"_dpifix."${DMG_BACKGROUND_IMG##*.}"
|
34 |
| - |
35 | 33 | sips -s dpiWidth 72 -s dpiHeight 72 ${DMG_BACKGROUND_IMG} --out ${_DMG_BACKGROUND_TMP}
|
36 |
| - |
37 | 34 | DMG_BACKGROUND_IMG="${_DMG_BACKGROUND_TMP}"
|
38 | 35 | fi
|
39 | 36 |
|
|
62 | 59 |
|
63 | 60 | popd
|
64 | 61 |
|
65 |
| -# figure out how big our DMG needs to be |
66 |
| -# assumes our contents are at least 1M! |
67 |
| -SIZE=`du -sh "${STAGING_DIR}" | sed 's/\([0-9\.]*\)M\(.*\)/\1/'` |
68 |
| -SIZE=`echo "${SIZE} + 1.0" | bc | awk '{print int($1+0.5)}'` |
69 |
| - |
70 |
| -if [ $? -ne 0 ]; then |
71 |
| - echo "Error: Cannot compute size of staging dir" |
72 |
| - exit |
73 |
| -fi |
74 |
| - |
75 |
| -# create the temp DMG file |
76 |
| -hdiutil create -srcfolder "${STAGING_DIR}" -volname "${VOL_NAME}" -fs HFS+ \ |
77 |
| - -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}M "${DMG_TMP}" |
78 |
| - |
79 |
| -echo "Created DMG: ${DMG_TMP}" |
80 |
| - |
81 |
| -# mount it and save the device |
82 |
| -DEVICE=$(hdiutil attach -readwrite -noverify "${DMG_TMP}" | \ |
83 |
| - egrep '^/dev/' | sed 1q | awk '{print $1}') |
84 |
| - |
85 |
| -sleep 2 |
86 |
| - |
87 |
| -# add a link to the Applications dir |
88 |
| -echo "Add link to /Applications" |
89 |
| -pushd /Volumes/"${VOL_NAME}" |
90 |
| -ln -s /Applications |
91 |
| -popd |
92 |
| - |
93 |
| -# add a background image |
94 |
| -mkdir /Volumes/"${VOL_NAME}"/.background |
95 |
| -cp "${DMG_BACKGROUND_IMG}" /Volumes/"${VOL_NAME}"/.background/ |
96 |
| -DMG_BACKGROUND_IMG_BASENAME=`basename ${DMG_BACKGROUND_IMG}` |
97 |
| - |
98 |
| -# add COPYING |
99 |
| -cp "@CMAKE_SOURCE_DIR@/COPYING" /Volumes/"${VOL_NAME}"/ |
100 |
| - |
101 |
| -# tell the Finder to resize the window, set the background, |
102 |
| -# change the icon size, place the icons in the right position, etc. |
103 |
| -echo ' |
104 |
| - tell application "Finder" |
105 |
| - tell disk "'${VOL_NAME}'" |
106 |
| - open |
107 |
| - set current view of container window to icon view |
108 |
| - set toolbar visible of container window to false |
109 |
| - set statusbar visible of container window to false |
110 |
| - set the bounds of container window to {400, 100, 927, 440} |
111 |
| - set viewOptions to the icon view options of container window |
112 |
| - set arrangement of viewOptions to not arranged |
113 |
| - set icon size of viewOptions to 72 |
114 |
| - set background picture of viewOptions to file ".background:'${DMG_BACKGROUND_IMG_BASENAME}'" |
115 |
| - set position of item "'${APP_NAME}'.app" of container window to {160, 225} |
116 |
| - set position of item "Applications" of container window to {360, 225} |
117 |
| - set position of item "COPYING" of container window to {460, 275} |
118 |
| - close |
119 |
| - open |
120 |
| - update without registering applications |
121 |
| - delay 2 |
122 |
| - end tell |
123 |
| - end tell |
124 |
| -' | osascript |
125 |
| - |
126 |
| -sync |
127 |
| - |
128 |
| -# unmount it |
129 |
| -hdiutil detach "${DEVICE}" |
130 |
| - |
131 |
| -# now make the final image a compressed disk image |
132 |
| -echo "Creating compressed image" |
133 |
| -hdiutil convert "${DMG_TMP}" -format UDZO -imagekey zlib-level=9 -o "${DMG_FINAL}" |
134 |
| - |
135 |
| -# clean up |
136 |
| -rm -rf "${DMG_TMP}" |
137 |
| -rm -rf "${STAGING_DIR}" |
| 62 | +#------------- Updated section to support creating a dmg in macOS 10.13+ -------------# |
| 63 | +# Changes made by Carlos Matos <[email protected] |
| 64 | +# Issues identified when trying to port CI from Travis to Github Actions. Using macOS 10.14+ |
| 65 | +# would cause the CI job to fail due to security enhancements made after High Sierra. This |
| 66 | +# was essentially causing the original applescript to timeout after it's default 2 minute waiting |
| 67 | +# period. After making several attempts to work around this issue - it became clear that this was |
| 68 | +# going to take too much effort - if it even would work at all. I began looking at alternative |
| 69 | +# solutions, which lead me to a couple of open source projects created by people who simply wanted |
| 70 | +# to make the process of creating a dmg easier. After testing dmgbuild and appdmg, I settled with |
| 71 | +# appdmg since it was easy to port our existing configuration to it. |
| 72 | +cat << EOF > scapwb.json |
| 73 | +{ |
| 74 | + "title": "SCAP Workbench", |
| 75 | + "background": "${DMG_BACKGROUND_IMG}", |
| 76 | + "format": "UDZO", |
| 77 | + "window": { "position": { "x": 300, "y": 300 } }, |
| 78 | + "contents": [ |
| 79 | + { "x": 360, "y": 225, "type": "link", "path": "/Applications" }, |
| 80 | + { "x": 160, "y": 225, "type": "file", "path": "${STAGING_DIR}/${APP_NAME}.app" } |
| 81 | + ] |
| 82 | +} |
| 83 | +EOF |
| 84 | + |
| 85 | +echo "Creating customized DMG image..." |
| 86 | +appdmg scapwb.json ${DMG_FINAL} |
138 | 87 |
|
139 | 88 | echo 'Done.'
|
140 | 89 |
|
|
0 commit comments