Chromium Code Reviews| 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 replace_folder_icon() { | |
|
ricow1
2013/10/18 11:18:08
could you give a little context here in a comment,
kustermann
2013/10/18 14:12:13
Done.
| |
| 49 FOLDER="$1" | |
| 50 ICON="$2" | |
| 51 TEMP_ICON_RESOURCE='/tmp/icns.rsrc' | |
| 52 ICON_RESOURCE="$FOLDER"/$'Icon\r' | |
| 53 | |
| 54 # Add finder icon to the image file | |
| 55 sips -i "$ICON" > /dev/null | |
| 56 | |
| 57 # Extract the finder icon resource | |
| 58 DeRez -only icns "$ICON" > "$TEMP_ICON_RESOURCE" | |
| 59 | |
| 60 # Create the icon resource | |
| 61 rm -f "$ICON_RESOURCE" | |
| 62 Rez -append "$TEMP_ICON_RESOURCE" -o "$ICON_RESOURCE" | |
| 63 rm "$TEMP_ICON_RESOURCE" | |
| 64 | |
| 65 # Set the 'custom icon' attribute on $FOLDER | |
| 66 SetFile -a C "$FOLDER" | |
| 67 | |
| 68 # Make the $ICON_RESOURCE invisible for finder | |
| 69 SetFile -a V "$ICON_RESOURCE" | |
| 70 } | |
| 71 | |
| 72 | |
| 51 # Create a new image and attach it | 73 # Create a new image and attach it |
| 52 hdiutil create -size 300m -type SPARSE -volname "$INPUT_VOLUME_NAME" -fs \ | 74 hdiutil create -size 400m -type SPARSE -volname "$INPUT_VOLUME_NAME" -fs \ |
| 53 'Journaled HFS+' "$SPARSEIMAGE" | 75 'Journaled HFS+' "$SPARSEIMAGE" |
| 54 hdiutil attach "$SPARSEIMAGE" | 76 hdiutil attach "$SPARSEIMAGE" |
| 55 | 77 |
| 56 # Add link to /Applications (so the user can drag-and-drop into it) | 78 # Add link to /Applications (so the user can drag-and-drop into it) |
| 57 ln -s /Applications "$VOLUME_MOUNTPOINT/" | 79 ln -s /Applications "$VOLUME_MOUNTPOINT/" |
| 58 # Copy our application | 80 # Copy our application |
| 59 ditto "$INPUT_APP_FOLDER_PATH" "$VOLUME_MOUNTPOINT/$APP_FOLDER_NAME" | 81 ditto "$INPUT_FOLDER_PATH" "$VOLUME_MOUNTPOINT/$FOLDER_NAME" |
| 60 # Make sure that the folder gets opened when mounting the image | 82 # Set custom icon on this folder |
| 83 replace_folder_icon "$VOLUME_MOUNTPOINT/$FOLDER_NAME" "$FOLDER_ICON" | |
| 84 # Make sure that the dmg gets opened when mounting the image | |
| 61 bless --folder "$VOLUME_MOUNTPOINT" --openfolder "$VOLUME_MOUNTPOINT" | 85 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 | 86 |
| 68 # Use an applescript to setup the layout of the folder. | 87 # Use an applescript to setup the layout of the folder. |
| 69 osascript << EOF | 88 osascript << EOF |
| 70 tell application "Finder" | 89 tell application "Finder" |
| 71 tell disk "$INPUT_VOLUME_NAME" | 90 tell disk "$INPUT_VOLUME_NAME" |
| 72 open | 91 open |
| 73 tell container window | 92 tell container window |
| 74 set current view to icon view | 93 set current view to icon view |
| 75 set toolbar visible to false | 94 set toolbar visible to false |
| 76 set statusbar visible to false | 95 set statusbar visible to false |
| 77 set position to {100, 100} | 96 set position to {100, 100} |
| 78 set bounds to {100, 100, 512, 256} | 97 set bounds to {100, 100, 512, 256} |
| 79 end tell | 98 end tell |
| 80 tell icon view options of container window | 99 tell icon view options of container window |
| 81 set arrangement to not arranged | 100 set arrangement to not arranged |
| 82 set icon size to 128 | 101 set icon size to 128 |
| 83 end tell | 102 end tell |
| 84 » » set position of item "$APP_FOLDER_NAME" to {64, 64} | 103 » » set position of item "$FOLDER_NAME" to {64, 64} |
|
ricow1
2013/10/18 11:18:08
consider removing tabs
kustermann
2013/10/18 14:12:13
Done.
| |
| 85 set position of item "Applications" to {320, 64} | 104 set position of item "Applications" to {320, 64} |
| 86 eject | 105 eject |
| 87 end tell | 106 end tell |
| 88 end tell | 107 end tell |
| 89 EOF | 108 EOF |
| 90 | 109 |
| 91 # Wait until the script above has umounted the image | 110 # Wait until the script above has umounted the image |
| 92 while [ -e "$VOLUME_MOUNTPOINT" ]; do | 111 while [ -e "$VOLUME_MOUNTPOINT" ]; do |
| 93 echo "Waiting for Finder to eject $VOLUME_MOUNTPOINT" | 112 echo "Waiting for Finder to eject $VOLUME_MOUNTPOINT" |
| 94 sleep 2 | 113 sleep 2 |
| 95 done | 114 done |
| 96 | 115 |
| 97 # Compress the sparse image | 116 # Compress the sparse image |
| 98 hdiutil convert "$SPARSEIMAGE" -format UDBZ -o "$OUTPUT_DMG_FILE" | 117 hdiutil convert "$SPARSEIMAGE" -format UDBZ -o "$OUTPUT_DMG_FILE" |
| 99 | 118 |
| 100 # Remove sparse image | 119 # Remove sparse image |
| 101 rm "$SPARSEIMAGE" | 120 rm "$SPARSEIMAGE" |
| 102 | 121 |
| OLD | NEW |