d9b6099cd317f981de1e7c8556a75a1e7a083fba
[ardour.git] / tools / osx_packaging / osx_build
1 #!/bin/bash
2
3 # script for pulling together a MacOSX app bundle.
4
5 GTKSTACK_ROOT=$HOME/gtk/inst
6 ARDOURSTACK_ROOT=$HOME/a3/inst
7 BUILD_ROOT=../../build
8
9 SAE=
10 MIXBUS=
11 WITH_HARVID=
12 WITH_LADSPA=1
13 STRIP=1
14 PRINT_SYSDEPS=
15 WITH_NLS=
16
17 while [ $# -gt 0 ] ; do
18     echo "arg = $1"
19     case $1 in
20
21         #
22         # top level build targets
23         #
24
25         --sae) WITH_NLS= ; 
26                SAE=1 ; 
27                WITH_LADSPA=1; 
28                STRIP= ; 
29                PRODUCT_PKG_DIR=ArdourSAE ; 
30                APPNAME=Ardour ;
31                shift ;;
32         --mixbus) MIXBUS=1; 
33                   WITH_NLS=1 ; 
34                   SAE= ; 
35                   WITH_LADSPA=; 
36                   STRIP= ; 
37                   PRODUCT_PKG_DIR=MixBus;
38                   APPNAME=Mixbus ;
39                   shift ;;
40         --public) WITH_NLS= ; 
41                   SAE= ; 
42                   WITH_LADSPA=1; 
43                   STRIP= ; 
44                   PRODUCT_PKG_DIR=Ardour;
45                   APPNAME=Ardour ;
46                   shift ;;
47         --allinone) SAE= ; 
48                     WITH_NLS= ; 
49                     WITH_LADSPA=1; 
50                     STRIP= ; 
51                     PRODUCT_PKG_DIR=Ardour ;
52                     shift ;;
53         --test) SAE= ; WITH_LADSPA=; STRIP= ; shift ;;
54
55         #
56         # specific build flags
57         #
58
59         --harvid) WITH_HARVID=1 ; shift ;;
60         --noladspa) WITH_LADSPA= ; shift ;;
61         --nostrip) STRIP= ; shift ;;
62         --sysdeps) PRINT_SYSDEPS=1; shift ;;
63         --nls) WITH_NLS=1 ; shift ;;
64     esac
65 done
66
67 if test -z "$PRODUCT_PKG_DIR" -o -z "$APPNAME"; then
68         echo "application or product-name was not specified"
69         exit 1
70 fi
71
72 . ../define_versions.sh
73 echo "Version is $release_version / $revision"
74 info_string="$version built on `hostname` by `whoami` on `date`"
75 echo "Info string is $info_string"
76
77 # setup directory structure
78
79 APPDIR=${APPNAME}.app
80 APPROOT=$APPDIR/Contents
81 Frameworks=$APPROOT/lib
82 Resources=$APPROOT/Resources
83 #
84 # Since this is OS X, don't try to distinguish between etc and shared
85 # (machine dependent and independent data) - just put everything
86 # into Resources.
87
88 Shared=$Resources
89 Etc=$Resources
90 Locale=$Resources/locale
91 #
92 # Bundled Plugins live in a top level folder
93
94 Plugins=$APPROOT/Plugins
95 Surfaces=$Frameworks/surfaces
96 Panners=$Frameworks/panners
97 MidiMaps=$Shared/midi_maps
98 ExportFormats=$Shared/export
99 Templates=$Shared/templates
100 PatchFiles=$Shared/patchfiles
101 MackieControl=$Shared/mcp
102
103 if [ x$PRINT_SYSDEPS != x ] ; then
104 #
105 # print system dependencies
106 #
107
108     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Plugins/*.so ; do 
109         if ! file $file | grep -qs Mach-O ; then
110             continue
111         fi
112         otool -L $file | awk '{print $1}' | egrep -v "(^@executable_path|^Ardour[0-9][.0-9]*.app)" 
113     done | sort | uniq
114     exit 0
115 fi
116
117 echo "Removing old $APPDIR tree ..."
118
119 rm -rf $APPDIR
120
121 echo "Building new app directory structure ..."
122
123 # only bother to make the longest paths
124
125 mkdir -p $APPROOT/MacOS
126 mkdir -p $APPROOT/Resources
127 mkdir -p $Plugins
128 mkdir -p $Surfaces
129 mkdir -p $Panners
130 mkdir -p $MidiMaps
131 mkdir -p $ExportFormats
132 mkdir -p $Templates
133 mkdir -p $Frameworks/modules
134 mkdir -p $Etc
135 mkdir -p $MackieControl
136
137 # maybe set variables
138 env=""
139 if test x$SAE != x ; then
140     appname="Ardour3/SAE"
141     env="$env<key>ARDOUR_SAE</key><string>true</string>"
142     #
143     # current default for SAE version is German keyboard layout without a keypad
144     #
145     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>de-nokeypad</string>"
146     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui_sae.conf</string>"
147     env="$env<key>ARDOUR3_UI_RC</key><string>ardour3_ui_dark_sae.rc</string>"
148 elif test x$MIXBUS != x ; then
149     appname="Ardour3/Mixbus"
150     env="$env<key>ARDOUR_MIXBUS</key><string>true</string>"
151     #
152     # current default for MIXBUS version is US keyboard layout without a keypad
153     #
154     env="$env<key>ARDOUR_KEYBOARD_LAYOUT</key><string>us-nokeypad</string>"
155     env="$env<key>ARDOUR_UI_CONF</key><string>ardour3_ui.conf</string>"
156     env="$env<key>ARDOUR3_UI_RC</key><string>ardour3_ui_dark.rc</string>"
157 else
158     appname="Ardour3"
159 fi
160
161 #
162 # if we're not going to bundle JACK, make sure we can find
163 # jack in the places where it might be
164 #
165
166 env="$env<key>PATH</key><string>/usr/local/bin:/opt/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>"
167 env="$env<key>DYLIB_FALLBACK_LIBRARY_PATH</key><string>/usr/local/lib:/opt/lib</string>"
168
169 env="<key>LSEnvironment</key><dict>$env<key>ARDOUR_BUNDLED</key><string>true</string></dict>"
170
171 # edit plist
172 sed -e "s?@ENV@?$env?g" \
173     -e "s?@VERSION@?$release_version/$revision?g" \
174     -e "s?@INFOSTRING@?$info_string?g" < Info.plist.in > Info.plist
175 # and plist strings
176 sed -e "s?@APPNAME@?$appname?" \
177     -e "s?@ENV@?$env?g" \
178     -e "s?@VERSION@?$release_version/$revision?g" \
179     -e "s?@INFOSTRING@?$info_string?g" < InfoPlist.strings.in > Resources/InfoPlist.strings || exit 1
180
181 # copy static files
182
183 cp Info.plist $APPROOT
184 cp -R Resources $APPROOT
185
186 #
187 # if we build a bundle without jack, then
188 # make the Ardour3 executable a helper
189 # script that checks to see if JACK is
190 # installed.
191 #
192
193 cp startup_script $APPROOT/MacOS/Ardour3
194 chmod 775 $APPROOT/MacOS/Ardour3
195 MAIN_EXECUTABLE=Ardour3.bin
196
197 echo "Copying ardour executable ...."
198 cp $BUILD_ROOT/gtk2_ardour/ardour-$release_version $APPROOT/MacOS/$MAIN_EXECUTABLE
199 if test x$SAE != x ; then
200     # cp $BUILD_ROOT/gtk2_ardour/evtest $APPROOT/MacOS/gtkevents
201     cp  Ardour3-SAE.icns $Resources/appIcon.icns
202 elif test x$MIXBUS != x ; then
203     cp  Mixbus.icns $Resources/appIcon.icns
204 else
205     cp  Ardour3.icns $Resources/appIcon.icns
206 fi
207 cp  typeArdour.icns $Resources/
208 if test x$STRIP != x ; then
209     strip $APPROOT/MacOS/Ardour3
210 fi
211
212 # copy locale files
213 if test x$WITH_NLS != x ; then
214     echo "NLS support ..."
215     echo "I hope you remembered to run scons msgupdate!"
216     LINGUAS=
217     for file in $BUILD_ROOT/gtk2_ardour/*.mo 
218     do
219         lang=`basename $file | sed 's/\.mo//'`
220         mkdir -p $Locale/$lang/LC_MESSAGES
221         cp $file $Locale/$lang/LC_MESSAGES/gtk2_ardour.mo
222         LINGUAS="$LINGUAS $lang"
223     done
224     for file in $BUILD_ROOT/libs/ardour/*.mo 
225     do
226         lang=`basename $file | sed 's/\.mo//'`
227         mkdir -p $Locale/$lang/LC_MESSAGES
228         cp $file $Locale/$lang/LC_MESSAGES/libardour.mo
229     done
230     for l in $LINGUAS
231     do
232       if [ -d $GTKSTACK_ROOT/share/locale/$l ] ; then
233           echo "Copying GTK i18n files for $l..."
234           cp -r $GTKSTACK_ROOT/share/locale/$l $Locale
235       else
236           # try with just the language spec
237           just_lang=`echo $l | sed 's/_[A-Z][A-Z]$//'`
238           if [ -d $GTKSTACK_ROOT/share/locale/$just_lang ] ; then
239               echo "Copying GTK i18n files for $l..."
240               cp -r $GTKSTACK_ROOT/share/locale/$just_lang $Locale
241           fi
242       fi
243     done
244 else
245     echo "Skipping NLS support"
246 fi
247
248 #
249 # Copy stuff that may be dynamically loaded
250
251
252 cp -R $GTKSTACK_ROOT/etc/* $Etc
253 echo "Copying all Pango modules ..."
254 cp -R $GTKSTACK_ROOT/lib/pango/1.6.0/modules/*.so $Frameworks/modules
255 echo "Copying all GDK Pixbuf loaders ..."
256 cp -R $GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders/*.so $Frameworks/modules
257 # charset alias file
258 cp -R $GTKSTACK_ROOT/lib/charset.alias $Resources
259
260 # generate new Pango module file
261 cat > pangorc <<EOF 
262 [Pango]
263 ModulesPath=$GTKSTACK_ROOT/lib/pango/1.6.0/modules
264 EOF
265 env PANGO_RC_FILE=pangorc $GTKSTACK_ROOT/bin/pango-querymodules | sed "s?$GTKSTACK_ROOT/lib/pango/1.6.0/modules/?@executable_path/../lib/modules/?" > $Resources/pango.modules
266 rm pangorc
267
268 # generate a new GDK pixbufs loaders file
269 gdk-pixbuf-query-loaders | sed "s?$GTKSTACK_ROOT/lib/gdk-pixbuf-2.0/2.10.0/loaders/?@executable_path/../lib/modules/?" > $Resources/gdk-pixbuf.loaders
270
271 # We rely on clearlooks, so include a version from our own build tree
272 # this one is special - we will set GTK_PATH to $Frameworks/gtkengines
273
274 GTK_ENGINE_DIR=$Frameworks/gtkengines/engines
275 mkdir -p $GTK_ENGINE_DIR
276
277 echo "Copying GTK engines ..."
278 cp $BUILD_ROOT/libs/clearlooks-newer/libclearlooks.dylib $Frameworks
279 (cd $GTK_ENGINE_DIR && ln -s ../../libclearlooks.dylib . && ln -s ../../libclearlooks.dylib libclearlooks.so)
280
281 cp $GTKSTACK_ROOT/lib/gtk-2.0/2.10.0/engines/libpixmap.so $Frameworks
282 (cd $GTK_ENGINE_DIR && ln -s ../../libpixmap.so)
283
284
285 if test x$WITH_LADSPA != x ; then
286     if test x$SAE != x ; then
287         plugdir=sae_ladspa
288     elif test x$MIXBUS != x ; then
289         plugdir=mixbus_ladspa
290     else
291         plugdir=ladspa
292     fi
293     if [ -d $plugdir -a "x$(ls $plugdir)" != x ] ; then 
294         echo "Copying `ls $plugdir | wc -l` plugins ..."
295         cp -r $plugdir/* $Plugins
296     fi
297 fi
298
299 # Control Surface shared libraries
300 cp $BUILD_ROOT/libs/surfaces/*/libardour_*.dylib $Surfaces
301 cp $BUILD_ROOT/libs/surfaces/control_protocol/libardourcp*.dylib $Frameworks
302
303 # Panners
304 cp $BUILD_ROOT/libs/panners/*/lib*.dylib $Panners
305
306
307 # Export Formats/Presets
308 for f in $BUILD_ROOT/../export/*.preset $BUILD_ROOT/../export/*.format ; do 
309     cp "$f" $ExportFormats ; 
310 done
311
312 # Session and Route templates
313 #for f in $BUILD_ROOT/../templates/* ; do 
314 #    if [ -d "$f" ] ; then
315 #        cp -r "$f" $Templates ; 
316 #    fi
317 #done
318
319 # MidiMaps
320 # got to be careful with names here
321 for x in $BUILD_ROOT/../midi_maps/*.map ; do
322     cp "$x" $MidiMaps
323 done
324
325 # MIDNAM Patch Files
326 # got to be careful with names here
327 for x in $BUILD_ROOT/../patchfiles/*.midnam ; do
328     cp "$x" $PatchFiles
329 done
330
331 # MackieControl data
332 # got to be careful with names here
333 for x in $BUILD_ROOT/../mcp/*.device $BUILD_ROOT/../mcp/*.profile ; do
334     cp "$x" $MackieControl
335 done
336
337 # VAMP plugins that we use
338 cp $BUILD_ROOT/libs/vamp-plugins/libardourvampplugins.dylib $Frameworks
339
340 # Suil modules
341 cp $ARDOURSTACK_ROOT/lib/suil-0/lib* $Frameworks
342
343 while [ true ] ; do 
344     missing=false
345     for file in $APPROOT/MacOS/* $Frameworks/* $Frameworks/modules/* $Panners/*.dylib $Surfaces/*.dylib $Plugins/*.so ; do 
346         if ! file $file | grep -qs Mach-O ; then
347             continue
348         fi
349         deps=`otool -L $file | awk '{print $1}' | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | grep -v 'libjack\.'`
350         # echo -n "."
351         for dep in $deps ; do
352             base=`basename $dep`
353             if ! test -f $Frameworks/$base; then
354                 if echo $dep | grep -sq '^libs' ; then
355                     cp $BUILD_ROOT/$dep $Frameworks
356                 else
357                     cp $dep $Frameworks
358                 fi
359                 missing=true
360             fi
361         done
362     done
363     if test x$missing = xfalse ; then
364         # everything has been found
365         break
366     fi
367 done
368 echo
369
370 echo "Copying other stuff to $APPDIR  ..."
371
372 #cp $BUILD_ROOT/gtk2_ardour/ergonomic-us.bindings  $Resources
373
374 cp $BUILD_ROOT/gtk2_ardour/mnemonic-us.bindings  $Resources
375 cp ../../gtk2_ardour/mixer.bindings $Resources
376 cp ../../gtk2_ardour/step_editing.bindings $Resources
377 cp $BUILD_ROOT/gtk2_ardour/ardour.menus $Resources
378
379 if test x$SAE != x ; then
380     cp $BUILD_ROOT/gtk2_ardour/SAE-de-keypad.bindings  $Resources
381     cp $BUILD_ROOT/gtk2_ardour/SAE-de-nokeypad.bindings  $Resources
382     cp $BUILD_ROOT/gtk2_ardour/SAE-us-keypad.bindings  $Resources
383     cp $BUILD_ROOT/gtk2_ardour/SAE-us-nokeypad.bindings  $Resources
384     cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
385     echo cp $BUILD_ROOT/ardour_system_sae.rc $Resources/ardour_system.rc
386     cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
387     echo cp $BUILD_ROOT/instant.xml.sae $Resources/instant.xml
388 else
389     cp ../../ardour_system.rc $Resources/ardour_system.rc
390     cp ../../instant.xml $Resources/instant.xml
391     echo cp ../../instant.xml $Resources/instant.xml
392 fi
393 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources
394 cp ../../gtk2_ardour/ardour3_ui_default.conf $Resources/ardour3_ui.conf
395 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_light.rc $Resources
396 cp $BUILD_ROOT/gtk2_ardour/ardour3_ui_dark.rc $Resources
397
398 cp -r ../../gtk2_ardour/icons $Resources
399 cp -r ../../gtk2_ardour/pixmaps $Resources
400
401 # shared stuff
402 cp -R ../../gtk2_ardour/splash.png $Shared
403 cp -R ../../gtk2_ardour/ArdourMono.ttf $Shared
404
405 # go through and recursively remove any .svn dirs in the bundle
406 for svndir in `find $APPDIR -name .svn -type dir`; do
407     rm -rf $svndir
408 done
409
410 # now fix up the executables
411 echo "Fixing up executable dependency names ..."
412 executables=$MAIN_EXECUTABLE
413 if test x$SAE != x ; then
414     executables="$executables"
415 fi
416
417 for exe in $executables; do
418     EXE=$APPROOT/MacOS/$exe
419     changes=""
420     for lib in `otool -L $EXE | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
421       base=`basename $lib`
422       changes="$changes -change $lib @executable_path/../lib/$base"
423     done
424     if test "x$changes" != "x" ; then
425         install_name_tool $changes $EXE
426     fi
427 done
428
429 echo "Fixing up library names ..."
430 # now do the same for all the libraries we include
431 for libdir in $Frameworks $Frameworks/modules $Surfaces $Panners ; do
432
433     libbase=`basename $libdir`
434     
435     for dylib in $libdir/*.dylib $libdir/*.so ; do
436         
437        # skip symlinks
438         
439         if test -L $dylib ; then
440             continue
441         fi
442         
443         # change all the dependencies
444         
445         changes=""
446         for lib in `otool -L $dylib | egrep "($GTKSTACK_ROOT|$ARDOURSTACK_ROOT|/opt/|/local/|libs/)" | awk '{print $1}' | grep -v 'libjack\.'` ; do
447             base=`basename $lib`
448             if echo $lib | grep -s libbase; then
449                 changes="$changes -change $lib @executable_path/../$libbase/$base"
450             else
451                 changes="$changes -change $lib @executable_path/../lib/$base"
452             fi
453         done
454         
455         if test "x$changes" != x ; then
456             if  install_name_tool $changes $dylib ; then
457                 :
458             else
459                 exit 1
460             fi
461         fi
462         
463         # now the change what the library thinks its own name is
464         
465         base=`basename $dylib`
466         install_name_tool -id @executable_path/../$libbase/$base $dylib
467     done
468 done
469
470 #
471 # and now ... the DMG
472
473
474 rm -rf $PRODUCT_PKG_DIR
475 mkdir $PRODUCT_PKG_DIR
476
477 DMGWINBOTTOM=440
478
479 if [ x$SAE != x ] ; then
480         
481     # SAE packaging
482     
483     echo "Creating SAE packaging directory"
484     mv $APPDIR $PRODUCT_PKG_DIR/Ardour3-SAE.app
485     cp HowToInstallArdourSAE.pdf "$PRODUCT_PKG_DIR/How To Install Ardour SAE.pdf"
486     cp SAE-de-keypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts (keypad).pdf"
487     cp SAE-de-nokeypad.pdf "$PRODUCT_PKG_DIR/Ardour SAE Shortcuts.pdf"
488     
489 elif [ x$MIXBUS != x ] ; then
490
491      # Mixbus packaging
492
493     echo "Creating Mixbus packaging directory"
494     mv $APPDIR $PRODUCT_PKG_DIR/
495     cp MixBus_Install_QuickStart.pdf "$PRODUCT_PKG_DIR/Mixbus Install & Quick Start Guide.pdf"
496                 DMGWINBOTTOM=$[ $DMGWINBOTTOM + 100 ]
497                 MIXBUSPOS="set position of item \"MixBus_Install_QuickStart.pdf\" of container window to {90, 180}"
498 else 
499
500     echo "Creating $APPNAME packaging directory"
501     mv $APPDIR $PRODUCT_PKG_DIR/
502
503 fi
504
505 if test x$WITH_HARVID != x ; then
506         echo "installing video tools.."
507         # TODO move files to http://ardour.org/files/ - symlink 'latest'
508         HARVID_VERSION=$(curl http://ardour.org/files/video-tools/harvid_version.txt)
509         XJADEO_VERSION=$(curl http://ardour.org/files/video-tools/xjadeo_version.txt)
510         echo "copying harvid and xjadeo ..."
511   curl -L -o "$PRODUCT_PKG_DIR/harvid-${HARVID_VERSION}.pkg" "http://x42.github.io/harvid/releases/harvid-${HARVID_VERSION}.pkg"
512   curl -L -o "$PRODUCT_PKG_DIR/xjadeo-${XJADEO_VERSION:1}.dmg" "http://sourceforge.net/projects/xjadeo/files/xjadeo/${XJADEO_VERSION}/jadeo-${XJADEO_VERSION:1}.dmg/download"
513         DMGWINBOTTOM=$[ $DMGWINBOTTOM + 140 ]
514         YPOS=$[ $DMGWINBOTTOM - 300 ]
515         HARVIDPOS="set position of item \"harvid-${HARVID_VERSION}.pkg\" of container window to {90, ${YPOS}}"
516         XJADEOPOS="set position of item \"xjadeo-${XJADEO_VERSION:1}.dmg\" of container window to {310, ${YPOS}}"
517 fi
518
519 echo "Building DMG ..."
520
521 # UC_DMG=$APPNAME-${release_version}-${revision}-UC.dmg
522 # FINAL_DMG=$APPNAME-${release_version}-${revision}.dmg
523 UC_DMG=$APPNAME-$version.dmg
524 VOLNAME=$APPNAME-$version
525
526 # TODO use mktemp
527 export TMPDIR=`pwd`
528 MNTPATH=`mktemp -d -t /ardourimg`
529 TMPDMG=`mktemp -t ardour`
530 ICNSTMP=`mktemp -t ardouricon`
531 EXTRA_SPACE_MB=30
532 DMGMEGABYTES=$[ `du -sk "$PRODUCT_PKG_DIR" | cut -f 1` * 1024 / 1048576 + $EXTRA_SPACE_MB ]
533
534 echo "DMG MB = " $DMGMEGABYTES
535
536 rm -f $UC_DMG "$TMPDMG" "${TMPDMG}.dmg" "$ICNSTMP"
537 rm -rf "$MNTPATH"
538 mkdir -p "$MNTPATH"
539
540 TMPDMG="${TMPDMG}.dmg"
541
542 hdiutil create -megabytes $DMGMEGABYTES "$TMPDMG"
543 DiskDevice=$(hdid -nomount "$TMPDMG" | grep Apple_HFS | cut -f 1 -d ' ')
544 newfs_hfs -v "${VOLNAME}" "${DiskDevice}"
545 mount -t hfs "${DiskDevice}" "${MNTPATH}"
546
547 cp -r ${PRODUCT_PKG_DIR}/* "${MNTPATH}" || exit
548 mkdir "${MNTPATH}/.background"
549 cp -vi dmgbg.png "${MNTPATH}/.background/dmgbg.png"
550
551 echo "setting DMG background ..."
552
553 echo '
554    tell application "Finder"
555      tell disk "'${VOLNAME}'"
556            open
557            set current view of container window to icon view
558            set toolbar visible of container window to false
559            set statusbar visible of container window to false
560            set the bounds of container window to {400, 200, 800, '${DMGWINBOTTOM}'}
561            set theViewOptions to the icon view options of container window
562            set arrangement of theViewOptions to not arranged
563            set icon size of theViewOptions to 64
564            set background picture of theViewOptions to file ".background:dmgbg.png"
565            make new alias file at container window to POSIX file "/Applications" with properties {name:"Applications"}
566            set position of item "'${APPDIR}'" of container window to {90, 100}
567            set position of item "Applications" of container window to {310, 100}
568            '${MIXBUSPOS}'
569            '${HARVIDPOS}'
570            '${XJADEOPOS}'
571            close
572            open
573            update without registering applications
574            delay 5
575            eject
576      end tell
577    end tell
578 ' | osascript
579
580 chmod -Rf go-w "${MNTPATH}"
581 sync
582
583 echo "compressing Image ..."
584
585 # Umount the image
586 umount "${DiskDevice}"
587 hdiutil eject "${DiskDevice}"
588 # Create a read-only version, use zlib compression
589 hdiutil convert -format UDZO "${TMPDMG}" -imagekey zlib-level=9 -o "${UC_DMG}"
590 # Delete the temporary files
591 rm "$TMPDMG"
592 rmdir "$MNTPATH"
593
594 echo "setting file icon ..."
595
596 cp ${PRODUCT_PKG_DIR}/$Resources/appIcon.icns ${ICNSTMP}.icns
597 /usr/bin/sips -i ${ICNSTMP}.icns
598 /Developer/Tools/DeRez -only icns ${ICNSTMP}.icns > ${ICNSTMP}.rsrc
599 /Developer/Tools/Rez -append ${ICNSTMP}.rsrc -o "$UC_DMG"
600 /Developer/Tools/SetFile -a C "$UC_DMG"
601
602 rm ${ICNSTMP}.icns ${ICNSTMP}.rsrc
603
604 echo
605 echo "packaging suceeded."
606 ls -l "$UC_DMG"
607
608 echo "Done."
609 exit