summaryrefslogtreecommitdiff
path: root/tools/numpy-macosx-installer/new-create-dmg
blob: 581663a0266379e2ceb2e04b368f59c98f114676 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#! /bin/bash
SRC_FOLDER=content
VOLUME_NAME=numpy
DMG_TEMP_NAME=numpy.tmp.dmg
title="${VOLUME_NAME}"
applicationName=numpy-1.4.0.dev-py2.6.mpkg
finalDMGName=numpy.dmg
backgroundPictureName=dmgbackground.png

WINX=100
WINY=100
WINW=600
WINH=600
ICON_SIZE=128

BACKGROUND_FILE=art/dmgbackground.png
NUMPY_MPKG=""

while test "${1:0:1}" = "-"; do
  case $1 in
    --pkgname)
      NUMPY_MPKG="$2"
      shift; shift;;
    --volname)
      VOLUME_NAME="$2"
      shift; shift;;
    -h | --help)
      usage;;
    --version)
      version; exit 0;;
    --pure-version)
      pure_version; exit 0;;
    -*)
      echo "Unknown option $1. Run with --help for help."
      exit 1;;
  esac
done

test -z "$2" && {
  echo "Not enough arguments. Invoke with --help for help."
  exit 1
}

# Check for mandatory options
if [ -e $NUMPY_MPKG ]
then
	echo "--pkgname is mandatory"
fi

BACKGROUND_FILE_NAME="$(basename $BACKGROUND_FILE)"
BACKGROUND_CLAUSE="set background picture of opts to file \".background:$BACKGROUND_FILE_NAME\""

DOCUMENTATION_PATH="Documentation"

DMG_PATH="$1"
DMG_DIRNAME="$(dirname "$DMG_PATH")"
DMG_DIR="$(cd $DMG_DIRNAME > /dev/null; pwd)"
DMG_NAME="$(basename "$DMG_PATH")"
DMG_TEMP_NAME="$DMG_DIR/rw.${DMG_NAME}"
SRC_FOLDER="$(cd "$2" > /dev/null; pwd)"
DMG_SIZE=16m
test -z "$VOLUME_NAME" && VOLUME_NAME="$(basename "$DMG_PATH" .dmg)"

# AUX_PATH="$(cd "$(dirname $0)"; pwd)/support"
# 
# test -d "$AUX_PATH" || {
#   echo "Cannot find support directory: $AUX_PATH"
#   exit 1
# }

# Create the image
echo "Creating disk image..."
test -f "${DMG_TEMP_NAME}" && rm -f "${DMG_TEMP_NAME}"
hdiutil create -srcfolder "$SRC_FOLDER" -volname "${VOLUME_NAME}" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -size "${DMG_SIZE}" "${DMG_TEMP_NAME}"
device=$(hdiutil attach -readwrite -noverify -noautoopen "${DMG_TEMP_NAME}" | egrep '^/dev/' | sed 1q | awk '{print $1}')

# Copy background image
mkdir /Volumes/"${VOLUME_NAME}"/.background
cp $BACKGROUND_FILE /Volumes/"${VOLUME_NAME}"/.background/"${BACKGROUND_FILE_NAME}"

# Set background image + icon size + icon position
# XXX: the close/open after icon positioning is to circumvent a big in Snow
# Leopard. Without it, the icon position is not changed
echo '
   tell application "Finder"
       tell disk "'${VOLUME_NAME}'"
	       open
	       set current view of container window to icon view
	       set toolbar visible of container window to false
	       set statusbar visible of container window to false
	       set the bounds of container window to {100, 100, 600, 600}
	       set theViewOptions to the icon view options of container window
	       set arrangement of theViewOptions to not arranged
	       set icon size of theViewOptions to 128
	       set background picture of theViewOptions to file ".background:'${BACKGROUND_FILE_NAME}'"
	       set position of item "'${NUMPY_MPKG}'" of container window to {125, 320}
	       set position of item "'${DOCUMENTATION_PATH}'" of container window to {375, 320}
	       close
	       open
	       update without registering applications
	       delay 5
       end tell
   end tell
' | osascript

rm -f "${DMG_NAME}"
chmod -Rf go-w /Volumes/"${VOLUME_NAME}"
sync
sync
hdiutil detach ${device}
hdiutil convert "${DMG_TEMP_NAME}" -format UDZO -imagekey zlib-level=9 -o "${DMG_NAME}"
rm -f ${DMG_TEMP_NAME}