1 #!/bin/sh
2 #
3 # Inkscape packaging script for Mac OS X
4 #
5 # The script creates a read-write disk image,
6 # copies Inkscape in it, copies additional python packages
7 # if needed, customizes its appearance using a
8 # previously created .DS_Store file (inkscape*.ds_store),
9 # and then compresses the disk image for distribution.
10 #
11 # Authors:
12 # Jean-Olivier Irisson <jo.irisson@gmail.com>
13 # Michael Wybrow <mjwybrow@users.sourceforge.net>
14 #
15 # Copyright 2006
16 # Licensed under GNU General Public License
17 #
18 #
19 # How to update the disk image layout:
20 # ------------------------------------
21 #
22 # Modify the 'dmg_background.svg' file and generate a new
23 # 'dmg_background.png' file.
24 #
25 # Update the AppleScript file 'dmg_set_style.scpt'.
26 #
27 # Run this script with the '-s' option. It will apply the
28 # 'dmg_set_style.scpt' AppleScript file, and then prompt the
29 # user to check the window size and position before writing
30 # a new 'inkscape.ds_store' file to work around a bug in Finder
31 # and AppleScript. The updated 'inkscape.ds_store' will need
32 # to be commited to the repository when this is done.
33 #
35 # Defaults
36 set_ds_store=false
37 add_python=false
38 ds_store_file="inkscape.ds_store"
39 package="Inkscape.app"
40 RWNAME="RWinkscape.dmg"
41 VOLNAME="Inkscape"
42 TMPDIR="/tmp/dmg-$$"
43 AUTOOPENOPT=
45 # Parse command line arguments
46 while [ "$1" != "" ]
47 do
48 case $1 in
49 -s)
50 set_ds_store=true ;;
51 -py|--with-python)
52 add_python=true
53 python_dir="$2"
54 ds_store_file="inkscape_python.ds_store"
55 shift 1 ;;
56 esac
57 shift 1
58 done
59 # some checks
60 if [ ! -e "$package" ]; then
61 echo "Cannot find $package"
62 exit 1
63 fi
64 if [ ${add_python} = "true" ]; then
65 if [ ! -e "$python_dir" ]; then
66 echo "Cannot find your python packages directory"
67 exit 1
68 fi
69 fi
71 # Create temp directory with desired contents of the release volume.
72 rm -rf "$TMPDIR"
73 mkdir "$TMPDIR"
75 echo "Copying files to temp directory..."
76 # Inkscape itself
77 # copy Inkscape.app
78 cp -rf "$package" "$TMPDIR"/
79 # link to Applications in order to drag and drop inkscape onto it.
80 ln -sf /Applications "$TMPDIR"/
82 # Python
83 if [ ${add_python} = "true" ]; then
84 # copy python libraries
85 cp -rf "$python_dir"/* "$TMPDIR"/
86 # link python environment in order to drag and drop inkscape onto it
87 ln -sf /Library/Python/2.3/site-packages "$TMPDIR"/Python\ site-packages
88 fi
90 # Copy a background image inside a hidden directory so the image
91 # file itself won't be shown.
92 mkdir "$TMPDIR/.background"
93 cp dmg_background.png "$TMPDIR/.background/background.png"
95 # If the appearance settings are not to be modified we just copy them
96 if [ ${set_ds_store} = "false" ]; then
97 # Copy the .DS_Store file which contains information about
98 # window size, appearance, etc. Most of this can be set
99 # with Apple script but involves user intervention so we
100 # just keep a copy of the correct settings and use that instead.
101 cp $ds_store_file "$TMPDIR/.DS_Store"
102 AUTOOPENOPT=-noautoopen
103 fi
105 # Create a new RW image from the temp directory.
106 echo "Creating a new RW disk image..."
107 rm -f "$RWNAME"
108 /usr/bin/hdiutil create -srcfolder "$TMPDIR" -volname "$VOLNAME" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$RWNAME"
110 # We're finished with the temp directory, remove it.
111 rm -rf "$TMPDIR"
113 # Mount the created image.
114 echo "Mounting the disk image..."
115 MOUNT_DIR="/Volumes/$VOLNAME"
116 DEV_NAME=`/usr/bin/hdiutil attach -readwrite -noverify $AUTOOPENOPT "$RWNAME" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
118 # Have the disk image window open automatically when mounted.
119 bless -openfolder /Volumes/$VOLNAME
121 # In case the apperance has to be modified, mount the image and apply the base settings to it via Applescript
122 if [ ${set_ds_store} = "true" ]; then
123 /usr/bin/osascript dmg_set_style.scpt
125 open "/Volumes/$VOLNAME"
126 # BUG: one needs to move and close the window manually for the
127 # changes in appearance to be retained...
128 echo "
129 **************************************
130 * Please move the disk image window *
131 * to the center of the screen *
132 * then close it and press enter *
133 **************************************
134 "
135 read -e DUMB
137 # .DS_Store files aren't written till the disk is unmounted,
138 # or finder is restarted.
139 hdiutil detach "$DEV_NAME"
140 AUTOOPENOPT=-noautoopen
141 DEV_NAME=`/usr/bin/hdiutil attach -readwrite -noverify $AUTOOPENOPT "$RWNAME" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
142 echo
143 echo "New $ds_store_file file written. Re-run $0 without the -s option to use it"
144 cp /Volumes/$VOLNAME/.DS_Store ./$ds_store_file
145 SetFile -a v ./$ds_store_file
147 # Unmount the disk image.
148 hdiutil detach "$DEV_NAME"
149 rm -f "$RWNAME"
151 exit 0
152 fi
154 # Unmount the disk image.
155 hdiutil detach "$DEV_NAME"
157 # Create the offical release image by compressing the RW one.
158 /usr/bin/hdiutil convert "$RWNAME" -format UDZO -imagekey zlib-level=9 -o "Inkscape.dmg"
159 rm -f "$RWNAME"
161 exit 0