tools/create-dmg.sh
author koda
Tue, 09 Jul 2013 04:23:48 +0200
changeset 9345 bb9bf1efd0d2
parent 9343 67552b2e20ca
child 9350 59408b4515dd
permissions -rwxr-xr-x
use the modern install(SCRIPT ...) command instead of legacy POST_BUILD_SCRIPT
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9343
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     1
#! /bin/bash
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     2
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     3
# Create a read-only disk image of the contents of a folder
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     4
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     5
set -e;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     6
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     7
function pure_version() {
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     8
  echo '1.0.0.2'
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
     9
}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    10
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    11
function version() {
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    12
  echo "create-dmg $(pure_version)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    13
}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    14
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    15
function usage() {
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    16
  version
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    17
  echo "Creates a fancy DMG file."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    18
  echo "Usage:  $(basename $0) options... image.dmg source_folder"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    19
  echo "All contents of source_folder will be copied into the disk image."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    20
  echo "Options:"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    21
  echo "  --volname name"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    22
  echo "      set volume name (displayed in the Finder sidebar and window title)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    23
  echo "  --volicon icon.icns"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    24
  echo "      set volume icon"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    25
  echo "  --background pic.png"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    26
  echo "      set folder background image (provide png, gif, jpg)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    27
  echo "  --window-pos x y"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    28
  echo "      set position the folder window"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    29
  echo "  --window-size width height"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    30
  echo "      set size of the folder window"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    31
  echo "  --icon-size icon_size"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    32
  echo "      set window icons size (up to 128)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    33
  echo "  --icon file_name x y"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    34
  echo "      set position of the file's icon"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    35
  echo "  --hide-extension file_name"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    36
  echo "      hide the extension of file"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    37
  echo "  --custom-icon file_name custom_icon_or_sample_file x y"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    38
  echo "      set position and custom icon"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    39
  echo "  --app-drop-link x y"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    40
  echo "      make a drop link to Applications, at location x,y"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    41
  echo "  --eula eula_file"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    42
  echo "      attach a license file to the dmg"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    43
  echo "  --version         show tool version number"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    44
  echo "  -h, --help        display this help"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    45
  exit 0
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    46
}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    47
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    48
WINX=10
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    49
WINY=60
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    50
WINW=500
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    51
WINH=350
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    52
ICON_SIZE=128
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    53
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    54
while test "${1:0:1}" = "-"; do
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    55
  case $1 in
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    56
    --volname)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    57
      VOLUME_NAME="$2"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    58
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    59
    --volicon)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    60
      VOLUME_ICON_FILE="$2"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    61
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    62
    --background)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    63
      BACKGROUND_FILE="$2"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    64
      BACKGROUND_FILE_NAME="$(basename $BACKGROUND_FILE)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    65
      BACKGROUND_CLAUSE="set background picture of opts to file \".background:$BACKGROUND_FILE_NAME\""
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    66
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    67
    --icon-size)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    68
      ICON_SIZE="$2"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    69
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    70
    --window-pos)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    71
      WINX=$2; WINY=$3
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    72
      shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    73
    --window-size)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    74
      WINW=$2; WINH=$3
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    75
      shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    76
    --icon)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    77
      POSITION_CLAUSE="${POSITION_CLAUSE}set position of item \"$2\" to {$3, $4}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    78
"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    79
      shift; shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    80
    --hide-extension)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    81
      HIDING_CLAUSE="${HIDING_CLAUSE}set the extension hidden of item \"$2\" to true"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    82
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    83
    --custom-icon)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    84
      shift; shift; shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    85
    -h | --help)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    86
      usage;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    87
    --version)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    88
      version; exit 0;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    89
    --pure-version)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    90
      pure_version; exit 0;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    91
    --app-drop-link)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    92
      APPLICATION_LINK=$2
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    93
      APPLICATION_CLAUSE="set position of item \"Applications\" to {$2, $3}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    94
"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    95
      shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    96
    --eula)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    97
      EULA_RSRC=$2
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    98
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    99
    -*)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   100
      echo "Unknown option $1. Run with --help for help."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   101
      exit 1;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   102
  esac
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   103
done
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   104
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   105
test -z "$2" && {
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   106
  echo "Not enough arguments. Invoke with --help for help."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   107
  exit 1
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   108
}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   109
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   110
DMG_PATH="$1"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   111
DMG_DIRNAME="$(dirname "$DMG_PATH")"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   112
DMG_DIR="$(cd $DMG_DIRNAME > /dev/null; pwd)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   113
DMG_NAME="$(basename "$DMG_PATH")"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   114
DMG_TEMP_NAME="$DMG_DIR/rw.${DMG_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   115
SRC_FOLDER="$(cd "$2" > /dev/null; pwd)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   116
test -z "$VOLUME_NAME" && VOLUME_NAME="$(basename "$DMG_PATH" .dmg)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   117
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   118
AUX_PATH="$(dirname $0)/support"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   119
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   120
test -d "$AUX_PATH" || {
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   121
  echo "Cannot find support directory: $AUX_PATH"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   122
  exit 1
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   123
}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   124
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   125
if [ -f "$SRC_FOLDER/.DS_Store" ]; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   126
    echo "Deleting any .DS_Store in source folder"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   127
    rm "$SRC_FOLDER/.DS_Store"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   128
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   129
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   130
# Create the image
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   131
echo "Creating disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   132
test -f "${DMG_TEMP_NAME}" && rm -f "${DMG_TEMP_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   133
ACTUAL_SIZE=`du -sm "$SRC_FOLDER" | sed -e 's/	.*//g'`
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   134
DISK_IMAGE_SIZE=$(expr $ACTUAL_SIZE + 20)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   135
hdiutil create -srcfolder "$SRC_FOLDER" -volname "${VOLUME_NAME}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size ${DISK_IMAGE_SIZE}m "${DMG_TEMP_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   136
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   137
# mount it
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   138
echo "Mounting disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   139
MOUNT_DIR="/Volumes/${VOLUME_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   140
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   141
# try unmount dmg if it was mounted previously (e.g. developer mounted dmg, installed app and forgot to unmount it)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   142
echo "Unmounting disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   143
DEV_NAME=$(hdiutil info | egrep '^/dev/' | sed 1q | awk '{print $1}')
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   144
test -d "${MOUNT_DIR}" && hdiutil detach "${DEV_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   145
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   146
echo "Mount directory: $MOUNT_DIR"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   147
DEV_NAME=$(hdiutil attach -readwrite -noverify -noautoopen "${DMG_TEMP_NAME}" | egrep '^/dev/' | sed 1q | awk '{print $1}')
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   148
echo "Device name:     $DEV_NAME"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   149
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   150
if ! test -z "$BACKGROUND_FILE"; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   151
  echo "Copying background file..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   152
  test -d "$MOUNT_DIR/.background" || mkdir "$MOUNT_DIR/.background"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   153
  cp "$BACKGROUND_FILE" "$MOUNT_DIR/.background/$BACKGROUND_FILE_NAME"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   154
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   155
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   156
if ! test -z "$APPLICATION_LINK"; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   157
  echo "making link to Applications dir"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   158
  echo $MOUNT_DIR
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   159
  ln -s /Applications "$MOUNT_DIR/Applications"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   160
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   161
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   162
if ! test -z "$VOLUME_ICON_FILE"; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   163
  echo "Copying volume icon file '$VOLUME_ICON_FILE'..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   164
  cp "$VOLUME_ICON_FILE" "$MOUNT_DIR/.VolumeIcon.icns"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   165
  SetFile -c icnC "$MOUNT_DIR/.VolumeIcon.icns"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   166
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   167
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   168
# run applescript
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   169
APPLESCRIPT=$(mktemp -t createdmg)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   170
cat "$AUX_PATH/template.applescript" | sed -e "s/WINX/$WINX/g" -e "s/WINY/$WINY/g" -e "s/WINW/$WINW/g" -e "s/WINH/$WINH/g" -e "s/BACKGROUND_CLAUSE/$BACKGROUND_CLAUSE/g" -e "s/ICON_SIZE/$ICON_SIZE/g" | perl -pe  "s/POSITION_CLAUSE/$POSITION_CLAUSE/g" | perl -pe "s/APPLICATION_CLAUSE/$APPLICATION_CLAUSE/g" | perl -pe "s/HIDING_CLAUSE/$HIDING_CLAUSE/" >"$APPLESCRIPT"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   171
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   172
echo "Running Applescript: /usr/bin/osascript \"${APPLESCRIPT}\" \"${VOLUME_NAME}\""
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   173
"/usr/bin/osascript" "${APPLESCRIPT}" "${VOLUME_NAME}" || true
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   174
echo "Done running the applescript..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   175
sleep 4
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   176
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   177
rm "$APPLESCRIPT"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   178
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   179
# make sure it's not world writeable
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   180
echo "Fixing permissions..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   181
chmod -Rf go-w "${MOUNT_DIR}" &> /dev/null || true
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   182
echo "Done fixing permissions."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   183
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   184
# make the top window open itself on mount:
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   185
echo "Blessing started"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   186
bless --folder "${MOUNT_DIR}" --openfolder "${MOUNT_DIR}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   187
echo "Blessing finished"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   188
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   189
if ! test -z "$VOLUME_ICON_FILE"; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   190
   # tell the volume that it has a special file attribute
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   191
   SetFile -a C "$MOUNT_DIR"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   192
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   193
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   194
# unmount
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   195
echo "Unmounting disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   196
hdiutil detach "${DEV_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   197
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   198
# compress image
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   199
echo "Compressing disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   200
hdiutil convert "${DMG_TEMP_NAME}" -format UDZO -imagekey zlib-level=9 -o "${DMG_DIR}/${DMG_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   201
rm -f "${DMG_TEMP_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   202
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   203
# adding EULA resources
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   204
if [ ! -z "${EULA_RSRC}" -a "${EULA_RSRC}" != "-null-" ]; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   205
        echo "adding EULA resources"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   206
        "${AUX_PATH}/dmg-license.py" "${DMG_DIR}/${DMG_NAME}" "${EULA_RSRC}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   207
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   208
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   209
echo "Disk image done"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   210
exit 0