Code

Unit test cleanup.
[inkscape.git] / packaging / macosx / osx-dmg.sh
1 #!/bin/sh
2 #
3 # USAGE
4 # osx-dmg [-s] -p /path/to/Inkscape.app
5 #
6 # The script creates a read-write disk image, 
7 # copies Inkscape in it, 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 (C) 2006-2007
16 # Released under GNU GPL, read the file 'COPYING' for more information
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 ds_store_file="inkscape.ds_store"
38 package=""
39 rw_name="RWinkscape.dmg"
40 volume_name="Inkscape"
41 tmp_dir="/tmp/dmg-$$"
42 auto_open_opt=
44 # Help message
45 #----------------------------------------------------------
46 help()
47 {
48 echo "
49 Create a custom dmg file to distribute Inkscape
51 \033[1mUSAGE\033[0m
52         $0 [-s] -p /path/to/Inkscape.app
54 \033[1mOPTIONS\033[0m
55         \033[1m-h,--help\033[0m 
56                 display this help message
57         \033[1m-s\033[0m
58                 set a new apperance (do not actually creates a bundle)
59         \033[1m-p,--package\033[0m
60                 set the path to the Inkscape.app that should be copie
61                 in the dmg
62 "
63 }
65 # Parse command line arguments
66 while [ "$1" != "" ]
67 do
68         case $1 in
69                 -h|--help)
70                         help
71                         exit 0 ;;
72                 -s)
73                         set_ds_store=true ;;
74                 -p|--package)
75                         package="$2"
76                         shift 1 ;;
77                 *)
78                         echo "Invalid command line option" 
79                         exit 2 ;;
80         esac
81         shift 1
82 done
84 # Safety checks
85 if [ ! -e "$package" ]; then
86         echo "Cannot find package: $package"
87         exit 1
88 fi
90 echo "\n\033[1mCREATE INKSCAPE DISK IMAGE\033[0m\n"
92 # Create temp directory with desired contents of the release volume.
93 rm -rf "$tmp_dir"
94 mkdir "$tmp_dir"
96 echo "\033[1mCopying files to temp directory\033[0m"
97 # Inkscape itself
98 # copy Inkscape.app
99 cp -rf "$package" "$tmp_dir"/
100 # link to Applications in order to drag and drop inkscape onto it
101 ln -sf /Applications "$tmp_dir"/
103 # Copy a background image inside a hidden directory so the image file itself won't be shown.
104 mkdir "$tmp_dir/.background"
105 cp dmg_background.png "$tmp_dir/.background/background.png"
107 # If the appearance settings are not to be modified we just copy them
108 if [ ${set_ds_store} = "false" ]; then
109         # Copy the .DS_Store file which contains information about
110         # window size, appearance, etc.  Most of this can be set
111         # with Apple script but involves user intervention so we
112         # just keep a copy of the correct settings and use that instead.
113         cp $ds_store_file "$tmp_dir/.DS_Store"
114         auto_open_opt=-noautoopen
115 fi
117 # Create a new RW image from the temp directory.
118 echo "\033[1mCreating a temporary disk image\033[0m"
119 rm -f "$rw_name"
120 /usr/bin/hdiutil create -srcfolder "$tmp_dir" -volname "$volume_name" -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$rw_name"
122 # We're finished with the temp directory, remove it.
123 rm -rf "$tmp_dir"
125 # Mount the created image.
126 MOUNT_DIR="/Volumes/$volume_name"
127 DEV_NAME=`/usr/bin/hdiutil attach -readwrite -noverify $auto_open_opt  "$rw_name" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
129 # Have the disk image window open automatically when mounted.
130 bless -openfolder /Volumes/$volume_name
132 # In case the apperance has to be modified, mount the image and apply the base settings to it via Applescript
133 if [ ${set_ds_store} = "true" ]; then
134         /usr/bin/osascript dmg_set_style.scpt
136         open "/Volumes/$volume_name"
137         # BUG: one needs to move and close the window manually for the
138         # changes in appearance to be retained... 
139         echo " 
140         ************************************** 
141         *  Please move the disk image window * 
142         *    to the center of the screen     *  
143         *   then close it and press enter    * 
144         ************************************** 
145         " 
146         read -e DUMB
148         # .DS_Store files aren't written till the disk is unmounted, or finder is restarted.
149         hdiutil detach "$DEV_NAME"
150         auto_open_opt=-noautoopen
151         DEV_NAME=`/usr/bin/hdiutil attach -readwrite -noverify $auto_open_opt  "$rw_name" | egrep '^/dev/' | sed 1q | awk '{print $1}'`
152         echo
153         echo "New $ds_store_file file written. Re-run $0 without the -s option to use it"
154         cp /Volumes/$volume_name/.DS_Store ./$ds_store_file
155         SetFile -a v ./$ds_store_file
157         # Unmount the disk image.
158         hdiutil detach "$DEV_NAME"
159         rm -f "$rw_name"
161         exit 0
162 fi
164 # Unmount the disk image.
165 hdiutil detach "$DEV_NAME"
167 # Create the offical release image by compressing the RW one.
168 echo "\033[1mCompressing the final disk image\033[0m"
169 img_name="Inkscape.dmg"
170 # TODO make this a command line option
171 if [ -e "$img_name" ]; then
172         echo "$img_name already exists."
173         rm -i "$img_name"
174 fi
175 /usr/bin/hdiutil convert "$rw_name" -format UDZO -imagekey zlib-level=9 -o "$img_name"
176 rm -f "$rw_name"
178 exit 0