very first draft for dmg packaging - all set in script, no option
[sface.git] / macos / build-dmg.sh
1 #!/bin/sh
2
3 # PURPOSE
4 # package a combination of sfa+sface into a snow leopard dmg install disk
5
6 # NOTES
7 # we leverage the first similar packaging initially made by Baris Metin
8
9 # REQUIREMENTS
10 # sface-skel.dmg is the skeleton that has Qt and all the other third-party software
11 #   it is expected to be found in the local directory
12 #   should be made available on http://mirror.onelab.eu/third-party/ as well
13 # the script expects the taglevels for both sfa and sface, 
14 #   in order to retrieve the corresponding code and to label the resulting package properly
15 #
16
17 # the place to search for the  skeleton
18 SKEL_REPO=http://mirror.onelab.eu/third-party
19
20 sfa_GITPATH=git://git.onelab.eu/sfa.git@sfa-1.0-20
21 sface_GITPATH=git://git.onelab.eu/sface.git@sface-0.1-5
22 sface_GITPATH=git://git.onelab.eu/sface.git@master
23
24 # hard-wired for snow-leopard for now
25 arch=snow-leopard
26
27 # does not affect final dmg size as it's compressed
28 DISK_SIZE=100M
29
30 ########################################
31 COMMAND=$(basename $0)
32
33 # extract the tag part of a GITPATH
34 function git_url () { echo $1 | cut -d @ -f 1 ; }
35 function git_tag () { echo $1 | cut -d @ -f 2 ; }
36
37 # go in $dest and retrieve $path part of codebase based on gitpath, e.g.
38 # git_retrieve \
39 #     git://git.onelab.eu/sface.git@sface-0.1-5 
40 #     sface 
41 #     /Volumes/sface-skel-sn/sface.app/Contents/Resources/
42 function git_retrieve () {
43     gitpath=$1; shift
44     path=$1; shift
45     dest=$1; shift
46
47     giturl=$(git_url $gitpath)
48     gittag=$(git_tag $gitpath)
49     [ -d $dest ] || mkdir -p $dest
50     pushd $dest >& /dev/null
51     git archive --remote=${giturl} ${gittag} | tar -xf - ${path}
52     popd
53 }
54
55 function die () {
56     echo "$@" "- exiting" 
57     exit 1
58 }
59
60 function main () {
61     skel_name=sface-skel-${arch}
62     skel_dmg=./${skel_name}.dmg
63     skel_mnt=/Volumes/${skel_name}
64
65     sfa_release=sfa-$(git_tag $sfa_GITPATH | sed -e s,sfa-,,)
66     sface_release=sface-$(git_tag $sface_GITPATH | sed -e s,sface-,,)
67     release=$(git_tag $sfa_GITPATH)-$(git_tag $sface_GITPATH)
68
69     img_name=${sface_release}-${sfa_release}-${arch}
70     img_dmg=./${img_name}.dmg
71     img_raw_dmg=./${img_name}.raw.dmg
72     img_mnt=/Volumes/${img_name}
73
74     # check we're clear
75     [ -f $img_dmg ] && die "output dmg $img_dmg already exists"
76     [ -f $img_raw_dmg ] && die "please clean up tmp file $img_raw_dmg"
77
78     # mount the skeleton if not yet avail.
79     if [ ! -d $skel_mnt ] ; then
80         # locate skel dmg
81         if [ ! -f $skel_dmg ] ; then
82             echo "Retrieving $skel_dmg from $SKEL_REPO"
83             curl -O $SKEL_REPO/$skel_dmg
84         fi
85         # needless to check for existence as curl will have created on anyway
86         if ! hdiutil mount $skel_dmg ; then
87             die "Could not mount $skel_dmg
88 Please check it is published at $SKEL_REPO
89 Also make sure to trash the current one before retrying"
90         fi
91     fi
92     [ -d $skel_mnt ] || die "Could not mount skeleton $skel_dmg"
93
94     # if image already mounted, it's an old run
95     [ -d $img_mnt ] && die "Image already mounted on $img_mount"
96
97     hdiutil create -size $DISK_SIZE -fs HFS+J -volname ${img_name} $img_raw_dmg
98     hdiutil attach -readwrite -mount required $img_raw_dmg 
99
100     # copy skeleton as-is
101     tar -C $skel_mnt -cf - . | tar -C $img_mnt -xf -
102     # places relative to mount point
103     app=sface.app
104     resource_path=$app/Contents/Resources
105     bin_path=$app/Contents/MacOS
106     icon_path=$app/Contents/Resources/
107     background_path=background
108     # retrieve sfa/sfa and sface/sface in the image
109     git_retrieve $sfa_GITPATH sfa $img_mnt/$resource_path/
110     git_retrieve $sface_GITPATH sface $img_mnt/$resource_path/
111     # copy binaries from sface to the bin dir
112     for bin in sface.bin sface-run; do 
113         git_retrieve $sface_GITPATH $bin $img_mnt/$bin_path
114     done
115     # install background and app icons
116     git_retrieve $sface_GITPATH macos/background.png $img_mnt/$background_path
117     git_retrieve $sface_GITPATH macos/appIcon.icns $img_mnt/$icon_path
118
119     # this apparently requires xcode
120     /Developer/Tools/SetFile -a V $img_mnt/$background_path
121     # clean up just in case
122     find $img_mnt -name '*pyc' | xargs rm -f
123     find $img_mnt -name '*~' | xargs rm -f
124
125     echo "Please open $img_mnt under Finder ..."
126     read _
127
128     hdiutil detach $img_mnt
129     rm -f $img_dmg
130     hdiutil convert -format UDZO -imagekey zlib-level=9 -o $img_dmg $img_raw_dmg
131     # clean up the raw image
132     rm -f $img_raw_dmg
133     # unmount the skeleton
134     hdiutil unmount $skel_mnt
135 }
136
137 main "$@"