| 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 |
# Modifié pour Collatinus_11.app le 26 avril 2017 par Philippe. |
| 7 |
# Suppose que Collatinus_11.app se trouve dans le |
| 8 |
# répertoire PARENT de celui où est cet exécutable. |
| 9 |
# Le numéro de version se change quelques lignes plus bas. |
| 10 |
# L’original prévoyait une compression de l’exécutable que j’ai commentée. |
| 11 |
|
| 12 |
# Attention ! TextEdit a tendance à remplacer les guillemets doubles " |
| 13 |
# par les équivalents typographiques “” qui ne sont pas compris. |
| 14 |
# Un cmd-Z au bon moment rétablit le ". |
| 15 |
|
| 16 |
# make sure we are in the correct dir when we double-click a .command file |
| 17 |
dir=${0%/*} |
| 18 |
if [ -d "$dir" ]; then |
| 19 |
cd "$dir" |
| 20 |
fi |
| 21 |
|
| 22 |
# set up your app name, version number, and background image file name |
| 23 |
APP_NAME="Collatinus_11" |
| 24 |
VERSION="11.beta" |
| 25 |
DMG_BACKGROUND_IMG="Fond_dmg.png" |
| 26 |
|
| 27 |
# you should not need to change these |
| 28 |
APP_EXE="${APP_NAME}.app/Contents/MacOS/${APP_NAME}" |
| 29 |
|
| 30 |
VOL_NAME="Collatinus ${VERSION}" # volume name will be "SuperCoolApp 1.0.0" |
| 31 |
DMG_TMP="${VOL_NAME}-temp.dmg" |
| 32 |
DMG_FINAL="${VOL_NAME}.dmg" # final DMG name will be "SuperCoolApp 1.0.0.dmg" |
| 33 |
STAGING_DIR="./Install" # we copy all our stuff into this dir |
| 34 |
|
| 35 |
# Check the background image DPI and convert it if it isn't 72x72 |
| 36 |
_BACKGROUND_IMAGE_DPI_H=`sips -g dpiHeight ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9]+\.[0-9]+'` |
| 37 |
_BACKGROUND_IMAGE_DPI_W=`sips -g dpiWidth ${DMG_BACKGROUND_IMG} | grep -Eo '[0-9]+\.[0-9]+'` |
| 38 |
|
| 39 |
if [ $(echo " $_BACKGROUND_IMAGE_DPI_H != 72.0 " | bc) -eq 1 -o $(echo " $_BACKGROUND_IMAGE_DPI_W != 72.0 " | bc) -eq 1 ]; then |
| 40 |
echo "WARNING: The background image's DPI is not 72. This will result in distorted backgrounds on Mac OS X 10.7+." |
| 41 |
echo " I will convert it to 72 DPI for you." |
| 42 |
|
| 43 |
_DMG_BACKGROUND_TMP="${DMG_BACKGROUND_IMG%.*}"_dpifix."${DMG_BACKGROUND_IMG##*.}" |
| 44 |
|
| 45 |
sips -s dpiWidth 72 -s dpiHeight 72 ${DMG_BACKGROUND_IMG} --out ${_DMG_BACKGROUND_TMP} |
| 46 |
|
| 47 |
DMG_BACKGROUND_IMG="${_DMG_BACKGROUND_TMP}" |
| 48 |
fi |
| 49 |
|
| 50 |
# clear out any old data |
| 51 |
rm -rf "${STAGING_DIR}" "${DMG_TMP}" "${DMG_FINAL}" |
| 52 |
|
| 53 |
# copy over the stuff we want in the final disk image to our staging dir |
| 54 |
mkdir -p "${STAGING_DIR}" |
| 55 |
cp -rpf "../${APP_NAME}.app" "${STAGING_DIR}" |
| 56 |
# Assumes that the application is in the parent folder |
| 57 |
# ... cp anything else you want in the DMG - documentation, etc. |
| 58 |
|
| 59 |
pushd "${STAGING_DIR}" |
| 60 |
|
| 61 |
# strip the executable |
| 62 |
#echo "Stripping ${APP_EXE}..." |
| 63 |
#strip -u -r "${APP_EXE}" |
| 64 |
|
| 65 |
# compress the executable if we have upx in PATH |
| 66 |
# UPX: http://upx.sourceforge.net/ |
| 67 |
#if hash upx 2>/dev/null; then |
| 68 |
# echo "Compressing (UPX) ${APP_EXE}..." |
| 69 |
# upx -9 "${APP_EXE}" |
| 70 |
#fi |
| 71 |
|
| 72 |
# ... perform any other stripping/compressing of libs and executables |
| 73 |
|
| 74 |
popd |
| 75 |
|
| 76 |
# figure out how big our DMG needs to be |
| 77 |
# assumes our contents are at least 1M! |
| 78 |
SIZE=`du -sh "${STAGING_DIR}" | sed 's/\([0-9\.]*\)M\(.*\)/\1/'` |
| 79 |
SIZE=`echo "${SIZE} + 1.0" | bc | awk '{print int($1+0.5)}'` |
| 80 |
|
| 81 |
if [ $? -ne 0 ]; then |
| 82 |
echo "Error: Cannot compute size of staging dir" |
| 83 |
exit |
| 84 |
fi |
| 85 |
|
| 86 |
# create the temp DMG file |
| 87 |
hdiutil create -srcfolder "${STAGING_DIR}" -volname "${VOL_NAME}" -fs HFS+ \ |
| 88 |
-fsargs "-c c=64,a=16,e=16" -format UDRW -size ${SIZE}M "${DMG_TMP}" |
| 89 |
|
| 90 |
echo "Created DMG: ${DMG_TMP}" |
| 91 |
|
| 92 |
# mount it and save the device |
| 93 |
DEVICE=$(hdiutil attach -readwrite -noverify "${DMG_TMP}" | \ |
| 94 |
egrep '^/dev/' | sed 1q | awk '{print $1}') |
| 95 |
|
| 96 |
sleep 2 |
| 97 |
|
| 98 |
# add a link to the Applications dir |
| 99 |
echo "Add link to /Applications" |
| 100 |
pushd /Volumes/"${VOL_NAME}" |
| 101 |
ln -s /Applications |
| 102 |
popd |
| 103 |
|
| 104 |
# add a background image |
| 105 |
mkdir /Volumes/"${VOL_NAME}"/.background |
| 106 |
cp "${DMG_BACKGROUND_IMG}" /Volumes/"${VOL_NAME}"/.background/ |
| 107 |
|
| 108 |
# tell the Finder to resize the window, set the background, |
| 109 |
# change the icon size, place the icons in the right position, etc. |
| 110 |
echo ' |
| 111 |
tell application "Finder" |
| 112 |
tell disk "'${VOL_NAME}'" |
| 113 |
open |
| 114 |
set current view of container window to icon view |
| 115 |
set toolbar visible of container window to false |
| 116 |
set statusbar visible of container window to false |
| 117 |
set the bounds of container window to {400, 100, 927, 490} |
| 118 |
set viewOptions to the icon view options of container window |
| 119 |
set arrangement of viewOptions to not arranged |
| 120 |
set icon size of viewOptions to 72 |
| 121 |
set background picture of viewOptions to file ".background:'${DMG_BACKGROUND_IMG}'" |
| 122 |
set position of item "'${APP_NAME}'.app" of container window to {60, 205} |
| 123 |
set position of item "Applications" of container window to {360, 305} |
| 124 |
close |
| 125 |
open |
| 126 |
update without registering applications |
| 127 |
delay 2 |
| 128 |
end tell |
| 129 |
end tell |
| 130 |
' | osascript |
| 131 |
|
| 132 |
sync |
| 133 |
|
| 134 |
# unmount it |
| 135 |
hdiutil detach "${DEVICE}" |
| 136 |
|
| 137 |
# now make the final image a compressed disk image |
| 138 |
echo "Creating compressed image" |
| 139 |
hdiutil convert "${DMG_TMP}" -format UDZO -imagekey zlib-level=9 -o "${DMG_FINAL}" |
| 140 |
|
| 141 |
# clean up |
| 142 |
rm -rf "${DMG_TMP}" |
| 143 |
rm -rf "${STAGING_DIR}" |
| 144 |
|
| 145 |
echo 'Done.' |
| 146 |
|
| 147 |
exit |