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"
40 # Parse command line arguments
41 while [ "$1" != "" ]
42 do
43 case $1 in
44 -s)
45 set_ds_store=true ;;
46 -py|--with-python)
47 add_python=true
48 python_dir=$2
49 ds_store_file="inkscape_python.ds_store"
50 shift 1 ;;
51 esac
52 shift 1
53 done
54 # some checks
55 if [ ! -e $python_dir ]; then
56 echo "Cannot find your python packages directory"
57 exit 1
58 fi
60 RWNAME="RWinkscape.dmg"
61 VOLNAME="Inkscape"
62 FIRSTTIME="false"
63 TMPDIR="/tmp/dmg-$$"
65 # Create temp directory with desired contents of the release volume.
66 rm -rf "$TMPDIR"
67 mkdir "$TMPDIR"
69 echo "Copying files to temp directory..."
70 # Copy Inkscape.app folder.
71 cp -rf Inkscape.app "$TMPDIR"/
73 # link to Applications in order to drag and drop inkscape onto it.
74 ln -sf /Applications "$TMPDIR"/
76 if [ ${add_python} = "true" ]; then
77 # Copy python libraries
78 cp -rf $python_dir/* "$TMPDIR"/
79 # link python environment in order to drag and drop inkscape onto it
80 ln -sf /Library/Python/2.3/site-packages "$TMPDIR"/Python\ site-packages
81 fi
83 # Copy a background image inside a hidden directory so the image
84 # file itself won't be shown.
85 mkdir "$TMPDIR/.background"
86 cp dmg_background.png "$TMPDIR/.background/background.png"
88 AUTOOPENOPT=
89 if [ ${set_ds_store} = "false" ]; then
90 # Copy the .DS_Store file which contains information about
91 # window size, appearance, etc. Most of this can be set
92 # with Apple script but involves user intervention so we
93 # just keep a copy of the correct settings and use that instead.
94 cp $ds_store_file "$TMPDIR/.DS_Store"
95 AUTOOPENOPT=-noautoopen
96 fi
98 # Create a new RW image from the temp directory.
99 echo "Creating a new RW disk image..."
100 rm -f "$RWNAME"
101 /usr/bin/hdiutil create -srcfolder "$TMPDIR" -volname "$VOLNAME" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$RWNAME"
103 # We're finished with the temp directory, remove it.
104 rm -rf "$TMPDIR"
106 # Mount the created image.
107 echo "Mounting the disk image..."
108 MOUNT_DIR="/Volumes/$VOLNAME"
109 DEV_NAME=`/usr/bin/hdiutil attach -readwrite -noverify $AUTOOPENOPT "$RWNAME" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
111 # Have the disk image window open automatically when mounted.
112 bless -openfolder /Volumes/$VOLNAME
114 if [ ${set_ds_store} = "true" ]; then
115 /usr/bin/osascript dmg_set_style.scpt
117 open "/Volumes/$VOLNAME"
118 # BUG: one needs to move and close the window manually for the
119 # changes in appearance to be retained...
120 echo "
121 **************************************
122 * Please move the disk image window *
123 * to the center of the screen *
124 * then close it and press enter *
125 **************************************
126 "
127 read -e DUMB
129 # .DS_Store files aren't written till the disk is unmounted,
130 # or finder is restarted.
131 hdiutil detach "$DEV_NAME"
132 AUTOOPENOPT=-noautoopen
133 DEV_NAME=`/usr/bin/hdiutil attach -readwrite -noverify $AUTOOPENOPT "$RWNAME" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
134 echo
135 echo "New $ds_store_file file written."
136 cp /Volumes/$VOLNAME/.DS_Store ./$ds_store_file
137 SetFile -a v ./$ds_store_file
139 # Unmount the disk image.
140 hdiutil detach "$DEV_NAME"
141 rm -f "$RWNAME"
143 exit 0
144 fi
146 # Unmount the disk image.
147 hdiutil detach "$DEV_NAME"
149 # Create the offical release image by compressing the RW one.
150 /usr/bin/hdiutil convert "$RWNAME" -format UDZO -imagekey zlib-level=9 -o "Inkscape.dmg"
151 rm -f "$RWNAME"
153 exit 0