source: launchers/macosx/osx_create_dmg.sh @ 51cbd8e

Last change on this file since 51cbd8e was ae0d420, checked in by meeh <meeh@…>, 23 months ago

Mac OSX Launcher:

  • Added script to check for latest java via xcode
  • Updated xcode project metadata files
  • Update dmg create script
  • Make xcode write version.h under build
  • Added template for version.h
  • Property mode set to 100755
File size: 3.7 KB
Line 
1#!/usr/bin/env bash
2DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3
4. .sign-secrets
5
6APP_NAME="I2PLauncher"
7VERSION="0.9.36"
8DMG_BACKGROUND_IMG="${DIR}/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 ${DMG_BACKGROUND_IMG} --out ${_DMG_BACKGROUND_TMP}
27
28   DMG_BACKGROUND_IMG="${_DMG_BACKGROUND_TMP}"
29fi
30
31# clear out any old data
32rm -rf "${STAGING_DIR}" "${DMG_TMP}" "${DMG_FINAL}"
33
34# copy over the stuff we want in the final disk image to our staging dir
35mkdir -p "${STAGING_DIR}"
36cp -rpf "${APP_NAME}.app" "${STAGING_DIR}"
37# ... cp anything else you want in the DMG - documentation, etc.
38
39# figure out how big our DMG needs to be
40#  assumes our contents are at least 1M!
41SIZE=`du -sh "${STAGING_DIR}" | sed 's/\([0-9\.]*\)M\(.*\)/\1/'`
42SIZE=`echo "${SIZE} + 1.0" | bc | awk '{print int($1+0.5)}'`
43
44if [ $? -ne 0 ]; then
45   echo "Error: Cannot compute size of staging dir"
46   exit
47fi
48
49# create the temp DMG file
50hdiutil create -srcfolder "${STAGING_DIR}" -volname "${VOL_NAME}" -fs HFS+ \
51      -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}M "${DMG_TMP}"
52
53echo "Created DMG: ${DMG_TMP}"
54
55# mount it and save the device
56DEVICE=$(hdiutil attach -readwrite -noverify "${DMG_TMP}" | \
57         egrep '^/dev/' | sed 1q | awk '{print $1}')
58
59sleep 2
60
61# add a link to the Applications dir
62echo "Add link to /Applications"
63pushd /Volumes/"${VOL_NAME}"
64ln -s /Applications
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.