1#!/bin/bash
2
3if ! [[ $# -eq 3 ]]; then
4    echo "Usage: $0 [App name] [background.png] [Volume name]"
5    exit 1
6fi
7
8APP_NAME=$1
9DMG_BACKGROUND_IMG=$2
10VOL_NAME=$3
11
12if [[ ! -f ${DMG_BACKGROUND_IMG} ]]; then
13    echo "background not found"
14    exit 1
15fi
16
17echo "Adding link to '/Applications'..."
18pushd /Volumes/"${VOL_NAME}" || exit 1
19ln -s /Applications " " || exit 1
20popd || exit 1
21
22echo "Package background set up..."
23mkdir /Volumes/"${VOL_NAME}"/.background || exit 1
24
25cp "${DMG_BACKGROUND_IMG}" /Volumes/"${VOL_NAME}"/.background/ || exit 1
26
27DMG_BACKGROUND_IMG_BASENAME=$(basename "${DMG_BACKGROUND_IMG}")
28
29# tell the Finder to resize the window, set the background,
30#  change the icon size, place the icons in the right position, etc.
31echo '
32   tell application "Finder"
33     tell disk "'${VOL_NAME}'"
34           open
35           set current view of container window to icon view
36           set toolbar visible of container window to false
37           set statusbar visible of container window to false
38           set the bounds of container window to {400, 100, 925, 508}
39           set viewOptions to the icon view options of container window
40           set arrangement of viewOptions to not arranged
41           set icon size of viewOptions to 122
42           set background picture of viewOptions to file ".background:'${DMG_BACKGROUND_IMG_BASENAME}'"
43           set position of item "'${APP_NAME}'.app" of container window to {117, 193}
44           set position of item " " of container window to {411, 193}
45           set position of item ".background" of container window to {1000, 1000}
46           set position of item ".fseventsd" of container window to {1010, 1010}
47           close
48           open
49           update without registering applications
50           delay 20
51     end tell
52   end tell
53' | osascript || echo "WARNING: Script for .dmg background failed!!!"
54
55echo "Syncing..."
56sync || exit 1
57