OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
3 # for details. All rights reserved. Use of this source code is governed by | 3 # for details. All rights reserved. Use of this source code is governed by |
4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 # This is partly based on | 6 # This is partly based on |
7 # https://bitbucket.org/rmacnak/nsvm/src/ | 7 # https://bitbucket.org/rmacnak/nsvm/src/ |
8 # b2de52432a2baff9c4ada099430fb16a771d34ef/vm/onebuild/installer-Darwin.gmk | 8 # b2de52432a2baff9c4ada099430fb16a771d34ef/vm/onebuild/installer-Darwin.gmk |
9 | 9 |
10 # Fail if a command failed | 10 # Fail if a command failed |
11 set -e | 11 set -e |
| 12 set -o errexit |
| 13 set -o nounset |
12 | 14 |
13 if [ $# -ne 4 ]; then | 15 if [ $# -ne 4 ]; then |
14 echo "Usage $0 <output.dmg> <app-folder> <icon.icns> <volume-name>" | 16 echo "Usage $0 <output.dmg> <raw-editor-bundle> <folder-icon> <volume-name>" |
15 exit 1 | 17 exit 1 |
16 fi | 18 fi |
17 | 19 |
18 OUTPUT_DMG_FILE=$1 | 20 OUTPUT_DMG_FILE=$1 |
19 INPUT_APP_FOLDER_PATH=$2 | 21 INPUT_FOLDER_PATH=$2 |
20 INPUT_ICON=$3 | 22 FOLDER_ICON=$3 |
21 INPUT_VOLUME_NAME=$4 | 23 INPUT_VOLUME_NAME=$4 |
22 | 24 |
23 APP_FOLDER_NAME=$(basename "$INPUT_APP_FOLDER_PATH") | 25 FOLDER_NAME="Dart" |
24 VOLUME_MOUNTPOINT="/Volumes/$INPUT_VOLUME_NAME" | 26 VOLUME_MOUNTPOINT="/Volumes/$INPUT_VOLUME_NAME" |
25 SPARSEIMAGE="$OUTPUT_DMG_FILE.sparseimage" | 27 SPARSEIMAGE="$OUTPUT_DMG_FILE.sparseimage" |
26 | 28 |
27 # Input validations | 29 # Input validations |
28 if [ "${INPUT_APP_FOLDER_PATH##*.}" != "app" ]; then | 30 if [ ! -d "$INPUT_FOLDER_PATH" ]; then |
29 echo "Application folder has to end in '.app' " \ | 31 echo "Editor bundle folder does not exist ($INPUT_FOLDER_PATH)" |
30 "(but was $INPUT_APP_FOLDER_PATH)." | |
31 exit 1 | |
32 fi | |
33 if [ "${INPUT_ICON##*.}" != "icns" ]; then | |
34 echo "Volume icon has to end in '.icns'." | |
35 exit 1 | 32 exit 1 |
36 fi | 33 fi |
37 | 34 |
38 # If an old image is still mounted, umount it | 35 # If an old image is still mounted, umount it |
39 if [ -e "$VOLUME_MOUNTPOINT" ]; then | 36 if [ -e "$VOLUME_MOUNTPOINT" ]; then |
40 hdiutil eject "$VOLUME_MOUNTPOINT" | 37 hdiutil eject "$VOLUME_MOUNTPOINT" |
41 fi | 38 fi |
42 | 39 |
43 # Remove old output files | 40 # Remove old output files |
44 if [ -f "$SPARSEIMAGE" ]; then | 41 if [ -f "$SPARSEIMAGE" ]; then |
45 rm "$SPARSEIMAGE" | 42 rm "$SPARSEIMAGE" |
46 fi | 43 fi |
47 if [ -f "$OUTPUT_DMG_FILE" ]; then | 44 if [ -f "$OUTPUT_DMG_FILE" ]; then |
48 rm "$OUTPUT_DMG_FILE" | 45 rm "$OUTPUT_DMG_FILE" |
49 fi | 46 fi |
50 | 47 |
| 48 # This function will set (or replace) the icon of a folder. |
| 49 # Finder displays a default folder icon. Since the installer |
| 50 # will consist of a folder and a link to "/Applications", we want |
| 51 # the folder to have a nice icon. |
| 52 # In order to make Finder display a custom icon, we need to |
| 53 # - Have a "FOLDER/Icon\r" file which contains the icon resource |
| 54 # (i.e. the metadata of this file will contain an icon) |
| 55 # - Have the 'custom icon' attribute set on "FOLDER" |
| 56 # Additionally we mark the "FOLDER/Icon\r" file as invisible, so it |
| 57 # is not shown in Finder (although it's visible on the commandline). |
| 58 replace_folder_icon() { |
| 59 FOLDER="$1" |
| 60 ICON="$2" |
| 61 TEMP_ICON_RESOURCE='/tmp/icns.rsrc' |
| 62 ICON_RESOURCE="$FOLDER"/$'Icon\r' |
| 63 |
| 64 # Add finder icon to the image file |
| 65 sips -i "$ICON" > /dev/null |
| 66 |
| 67 # Extract the finder icon resource |
| 68 DeRez -only icns "$ICON" > "$TEMP_ICON_RESOURCE" |
| 69 |
| 70 # Create the icon resource |
| 71 rm -f "$ICON_RESOURCE" |
| 72 Rez -append "$TEMP_ICON_RESOURCE" -o "$ICON_RESOURCE" |
| 73 rm "$TEMP_ICON_RESOURCE" |
| 74 |
| 75 # Set the 'custom icon' attribute on $FOLDER |
| 76 SetFile -a C "$FOLDER" |
| 77 |
| 78 # Make the $ICON_RESOURCE invisible for finder |
| 79 SetFile -a V "$ICON_RESOURCE" |
| 80 } |
| 81 |
| 82 |
51 # Create a new image and attach it | 83 # Create a new image and attach it |
52 hdiutil create -size 300m -type SPARSE -volname "$INPUT_VOLUME_NAME" -fs \ | 84 hdiutil create -size 400m -type SPARSE -volname "$INPUT_VOLUME_NAME" -fs \ |
53 'Journaled HFS+' "$SPARSEIMAGE" | 85 'Journaled HFS+' "$SPARSEIMAGE" |
54 hdiutil attach "$SPARSEIMAGE" | 86 hdiutil attach "$SPARSEIMAGE" |
55 | 87 |
56 # Add link to /Applications (so the user can drag-and-drop into it) | 88 # Add link to /Applications (so the user can drag-and-drop into it) |
57 ln -s /Applications "$VOLUME_MOUNTPOINT/" | 89 ln -s /Applications "$VOLUME_MOUNTPOINT/" |
58 # Copy our application | 90 # Copy our application |
59 ditto "$INPUT_APP_FOLDER_PATH" "$VOLUME_MOUNTPOINT/$APP_FOLDER_NAME" | 91 ditto "$INPUT_FOLDER_PATH" "$VOLUME_MOUNTPOINT/$FOLDER_NAME" |
60 # Make sure that the folder gets opened when mounting the image | 92 # Set custom icon on this folder |
| 93 replace_folder_icon "$VOLUME_MOUNTPOINT/$FOLDER_NAME" "$FOLDER_ICON" |
| 94 # Make sure that the dmg gets opened when mounting the image |
61 bless --folder "$VOLUME_MOUNTPOINT" --openfolder "$VOLUME_MOUNTPOINT" | 95 bless --folder "$VOLUME_MOUNTPOINT" --openfolder "$VOLUME_MOUNTPOINT" |
62 # Copy the volume icon | |
63 cp "$INPUT_ICON" "$VOLUME_MOUNTPOINT/.VolumeIcon.icns" | |
64 | |
65 # Set the 'custom-icon' attribute on the volume | |
66 SetFile -a C "$VOLUME_MOUNTPOINT" | |
67 | 96 |
68 # Use an applescript to setup the layout of the folder. | 97 # Use an applescript to setup the layout of the folder. |
69 osascript << EOF | 98 osascript << EOF |
70 tell application "Finder" | 99 tell application "Finder" |
71 » tell disk "$INPUT_VOLUME_NAME" | 100 tell disk "$INPUT_VOLUME_NAME" |
72 » » open | 101 open |
73 » » tell container window | 102 tell container window |
74 » » » set current view to icon view | 103 set current view to icon view |
75 » » » set toolbar visible to false | 104 set toolbar visible to false |
76 » » » set statusbar visible to false | 105 set statusbar visible to false |
77 » » » set position to {100, 100} | 106 set position to {100, 100} |
78 » » » set bounds to {100, 100, 512, 256} | 107 set bounds to {100, 100, 512, 256} |
79 » » end tell | 108 end tell |
80 » » tell icon view options of container window | 109 tell icon view options of container window |
81 » » » set arrangement to not arranged | 110 set arrangement to not arranged |
82 » » » set icon size to 128 | 111 set icon size to 128 |
83 » » end tell | 112 end tell |
84 » » set position of item "$APP_FOLDER_NAME" to {64, 64} | 113 set position of item "$FOLDER_NAME" to {64, 64} |
85 » » set position of item "Applications" to {320, 64} | 114 set position of item "Applications" to {320, 64} |
86 eject | 115 eject |
87 » end tell | 116 end tell |
88 end tell | 117 end tell |
89 EOF | 118 EOF |
90 | 119 |
91 # Wait until the script above has umounted the image | 120 # Wait until the script above has umounted the image |
92 while [ -e "$VOLUME_MOUNTPOINT" ]; do | 121 while [ -e "$VOLUME_MOUNTPOINT" ]; do |
93 echo "Waiting for Finder to eject $VOLUME_MOUNTPOINT" | 122 echo "Waiting for Finder to eject $VOLUME_MOUNTPOINT" |
94 sleep 2 | 123 sleep 2 |
95 done | 124 done |
96 | 125 |
97 # Compress the sparse image | 126 # Compress the sparse image |
98 hdiutil convert "$SPARSEIMAGE" -format UDBZ -o "$OUTPUT_DMG_FILE" | 127 hdiutil convert "$SPARSEIMAGE" -format UDBZ -o "$OUTPUT_DMG_FILE" |
99 | 128 |
100 # Remove sparse image | 129 # Remove sparse image |
101 rm "$SPARSEIMAGE" | 130 rm "$SPARSEIMAGE" |
102 | 131 |
OLD | NEW |