source: orange/install-scripts/mac/create-dmg-installer.sh @ 11636:310bc52a043b

Revision 11636:310bc52a043b, 3.2 KB checked in by Ales Erjavec <ales.erjavec@…>, 9 months ago (diff)

Added create-dmg-installer.sh script.

  • Property exe set to *
Line 
1#!/bin/bash -e
2#
3# Create an .dmg installer for Orange
4
5function print_usage() {
6    echo 'create-dmg-installer.sh --app BUILD_APP_PATH OUTPUT_BUNDLE.dmg
7
8Create an disk image installer (.dmg) for Orange OSX application.
9
10Options:
11
12    -a --app PATH      Path to a build Orange.app to include in the disk.
13                       (default dist/Orange.app)
14    -k --keep-temp     Keep the temporary files after creating the final image.
15    -h --help          Print this help
16'
17}
18
19DIRNAME=$(dirname "$0")
20
21# Path to dmg resources (volume icon, background, ...)
22RES=$DIRNAME/dmg-resources
23
24APP="dist/Orange.app"
25
26KEEP_TEMP=0
27
28while test ${1:0:1} = "-"; do
29    case $1 in
30        -a|--app)
31            APP=$2
32            shift 2
33            ;;
34        -k|--keep-temp)
35            KEEP_TEMP=1
36            shift 1
37            ;;
38        -h|--help)
39            print_usage
40            exit 0
41            ;;
42        -*)
43            echo "Unknown option $1"
44            print_usage
45            exit 1
46            ;;
47    esac
48done
49
50DMG=$1
51
52if [[ ! -d $APP ]]; then
53    echo "$APP path does not exits or is not a directory."
54    print_usage
55    exit 1
56fi
57
58TMP_DIR=$(mktemp -d -t orange-dmg)
59TMP_TEMPLATE=$TMP_DIR/template
60TMP_DMG=$TMP_DIR/orange.dmg
61
62echo "Preparing an image template in $TMP_TEMPLATE"
63echo "============================================="
64
65# Copy neccessary resources into the template
66mkdir -p "$TMP_TEMPLATE"/.background
67cp -a "$RES"/background.png "$TMP_TEMPLATE"/.background
68
69cp -a "$RES"/VolumeIcon.icns "$TMP_TEMPLATE"/.VolumeIcon.icns
70
71cp -a "$RES"/DS_Store "$TMP_TEMPLATE"/.DS_Store
72
73# Create a link to the Applications folder.
74ln -s /Applications/ "$TMP_TEMPLATE"/Applications
75
76# Copy the .app directory in place
77cp -a "$APP" "$TMP_TEMPLATE"/Orange.app
78
79# Remove unnecesary files.
80find "$TMP_TEMPLATE"/Orange.app/Contents/ \( -name '*~' -or -name '*.bak' -or -name '*.pyc' -or -name '*.pyo' \) -delete
81
82# Create a regular .fseventsd/no_log file
83# (see http://hostilefork.com/2009/12/02/trashes-fseventsd-and-spotlight-v100/ )
84
85mkdir "$TMP_TEMPLATE"/.fseventsd
86touch "$TMP_TEMPLATE"/.fseventsd/no_log
87
88echo "Creating a temporary disk image"
89hdiutil create -format UDRW -volname Orange -fs HFS+ \
90       -fsargs "-c c=64,a=16,e=16" \
91       -srcfolder "$TMP_TEMPLATE" \
92       "$TMP_DMG"
93
94# Force detatch an image it it is mounted
95hdiutil detach /Volumes/Orange -force || true
96
97# Mount in RW mode
98echo "Mounting temporary disk image"
99MOUNT_OUTPUT=$(hdiutil attach -readwrite -noverify -noautoopen "$TMP_DMG" | egrep '^/dev/')
100
101DEV_NAME=$(echo -n "$MOUNT_OUTPUT" | head -n 1 | awk '{print $1}')
102MOUNT_POINT=$(echo -n "$MOUNT_OUTPUT" | tail -n 1 | awk '{print $3}')
103
104# Makes the disk image window open automatically when mounted
105bless -openfolder "$MOUNT_POINT"
106
107# Hides background directory even more
108/Developer/Tools/SetFile -a V "$MOUNT_POINT/.background/"
109
110# Sets the custom icon volume flag so that volume has nice
111# Orange icon after mount (.VolumeIcon.icns)
112/Developer/Tools/SetFile -a C "$MOUNT_POINT"
113
114hdiutil detach "$DEV_NAME" -force
115
116echo "Converting temporary image to a compressed image."
117
118if [[ -e $DMG ]]; then
119    rm -f "$DMG"
120fi
121
122hdiutil convert "$TMP_DMG" -format UDZO -imagekey zlib-level=9 -o "$DMG"
123
124if [ ! $KEEP_TEMP ]; then
125    echo "Cleaning up."
126    rm -rf "$TMP_DIR"
127fi
128
Note: See TracBrowser for help on using the repository browser.