tools/create-dmg.sh
author sheepluva
Sun, 15 May 2016 23:59:24 +0200
changeset 11824 3f1f8f79fcdb
parent 9351 09115096c7d6
permissions -rwxr-xr-x
implement Trim() in uUtils
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"
9350
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
    43
  echo "  --no-internet-enable"
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
    44
  echo "      disable automatic mount&copy"
9343
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    45
  echo "  --version         show tool version number"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    46
  echo "  -h, --help        display this help"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    47
  exit 0
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    48
}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    49
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    50
WINX=10
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    51
WINY=60
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    52
WINW=500
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    53
WINH=350
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    54
ICON_SIZE=128
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    55
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    56
while test "${1:0:1}" = "-"; do
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    57
  case $1 in
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    58
    --volname)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    59
      VOLUME_NAME="$2"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    60
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    61
    --volicon)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    62
      VOLUME_ICON_FILE="$2"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    63
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    64
    --background)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    65
      BACKGROUND_FILE="$2"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    66
      BACKGROUND_FILE_NAME="$(basename $BACKGROUND_FILE)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    67
      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
    68
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    69
    --icon-size)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    70
      ICON_SIZE="$2"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    71
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    72
    --window-pos)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    73
      WINX=$2; WINY=$3
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    74
      shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    75
    --window-size)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    76
      WINW=$2; WINH=$3
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    77
      shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    78
    --icon)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    79
      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
    80
"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    81
      shift; shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    82
    --hide-extension)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    83
      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
    84
      shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    85
    --custom-icon)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    86
      shift; shift; shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    87
    -h | --help)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    88
      usage;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    89
    --version)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    90
      version; exit 0;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    91
    --pure-version)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    92
      pure_version; exit 0;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    93
    --app-drop-link)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    94
      APPLICATION_LINK=$2
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    95
      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
    96
"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    97
      shift; shift; shift;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    98
    --eula)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
    99
      EULA_RSRC=$2
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   100
      shift; shift;;
9350
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
   101
    --no-internet-enable)
9351
09115096c7d6 typo in var name
koda
parents: 9350
diff changeset
   102
      NOINTERNET=1
9350
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
   103
      shift;;
9343
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
      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
   106
      exit 1;;
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   107
  esac
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   108
done
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
test -z "$2" && {
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   111
  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
   112
  exit 1
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   113
}
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   114
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   115
DMG_PATH="$1"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   116
DMG_DIRNAME="$(dirname "$DMG_PATH")"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   117
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
   118
DMG_NAME="$(basename "$DMG_PATH")"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   119
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
   120
SRC_FOLDER="$(cd "$2" > /dev/null; pwd)"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   121
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
   122
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   123
AUX_PATH="$(dirname $0)/support"
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
test -d "$AUX_PATH" || {
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   126
  echo "Cannot find support directory: $AUX_PATH"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   127
  exit 1
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   128
}
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
if [ -f "$SRC_FOLDER/.DS_Store" ]; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   131
    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
   132
    rm "$SRC_FOLDER/.DS_Store"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   133
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   134
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   135
# Create the image
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   136
echo "Creating disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   137
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
   138
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
   139
DISK_IMAGE_SIZE=$(expr $ACTUAL_SIZE + 20)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   140
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
   141
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   142
# mount it
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   143
echo "Mounting disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   144
MOUNT_DIR="/Volumes/${VOLUME_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
# 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
   147
echo "Unmounting disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   148
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
   149
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
   150
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   151
echo "Mount directory: $MOUNT_DIR"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   152
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
   153
echo "Device name:     $DEV_NAME"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   154
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   155
if ! test -z "$BACKGROUND_FILE"; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   156
  echo "Copying background file..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   157
  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
   158
  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
   159
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   160
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   161
if ! test -z "$APPLICATION_LINK"; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   162
  echo "making link to Applications dir"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   163
  echo $MOUNT_DIR
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   164
  ln -s /Applications "$MOUNT_DIR/Applications"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   165
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   166
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   167
if ! test -z "$VOLUME_ICON_FILE"; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   168
  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
   169
  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
   170
  SetFile -c icnC "$MOUNT_DIR/.VolumeIcon.icns"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   171
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   172
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   173
# run applescript
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   174
APPLESCRIPT=$(mktemp -t createdmg)
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   175
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
   176
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   177
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
   178
"/usr/bin/osascript" "${APPLESCRIPT}" "${VOLUME_NAME}" || true
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   179
echo "Done running the applescript..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   180
sleep 4
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   181
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   182
rm "$APPLESCRIPT"
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 sure it's not world writeable
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   185
echo "Fixing permissions..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   186
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
   187
echo "Done fixing permissions."
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
# 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
   190
echo "Blessing started"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   191
bless --folder "${MOUNT_DIR}" --openfolder "${MOUNT_DIR}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   192
echo "Blessing finished"
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
if ! test -z "$VOLUME_ICON_FILE"; then
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   195
   # 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
   196
   SetFile -a C "$MOUNT_DIR"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   197
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   198
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   199
# unmount
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   200
echo "Unmounting disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   201
hdiutil detach "${DEV_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
# compress image
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   204
echo "Compressing disk image..."
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   205
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
   206
rm -f "${DMG_TEMP_NAME}"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   207
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   208
# adding EULA resources
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   209
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
   210
        echo "adding EULA resources"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   211
        "${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
   212
fi
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   213
9351
09115096c7d6 typo in var name
koda
parents: 9350
diff changeset
   214
if [ ! -z "${NOINTERNET}" -a "${NOINTERNET}" == 1 ]; then
9350
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
   215
        echo "not setting 'internet-enable' on the dmg"
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
   216
else
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
   217
        hdiutil internet-enable -yes "${DMG_DIR}/${DMG_NAME}"
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
   218
fi
59408b4515dd always set internet-enabled on the dmg
koda
parents: 9343
diff changeset
   219
9343
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   220
echo "Disk image done"
67552b2e20ca import create-dmg script from https://github.com/andreyvit/yoursway-create-dmg
koda
parents:
diff changeset
   221
exit 0