source: launchers/macosx/osx_create_dmg.sh @ 22a0f39

Last change on this file since 22a0f39 was 22a0f39, checked in by meeh <meeh@…>, 2 years ago

Mac OS X Launcher:

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