4 # package a combination of sfa+sface into a snow leopard dmg install disk
7 # we leverage the first similar packaging initially made by Baris Metin
10 # sface-skel-snow-leopard<arch>.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 # otherwise, or if -f is specified, it gets fetched
13 # from http://mirror.onelab.eu/third-party/
14 # the script expects the taglevels for both sfa and sface,
15 # in order to retrieve the corresponding code and to label the resulting package properly
16 # alternatively, a build-dir and tags file can be used instead
18 # the place to search for the skeleton
19 SKEL_REPO=http://mirror.onelab.eu/third-party
21 # default is snow-leopard
22 DEFAULT_ARCH=snow-leopard
23 ALL_ARCHS="leopard snow-leopard"
25 # does not affect final dmg size as it's compressed
28 ########################################
29 COMMAND=$(basename $0)
31 # extract the tag part of a GITPATH
32 function git_url () { echo $1 | cut -d @ -f 1 ; }
33 function git_tag () { echo $1 | cut -d @ -f 2 ; }
35 # go in $dest and retrieve $path part of codebase based on gitpath, e.g.
37 # git://git.onelab.eu/sface.git@sface-0.1-5
39 # /Volumes/sface-skel-sn/sface.app/Contents/Resources/
40 # or, with the -f (-file) option:
42 # git://git.onelab.eu/sface.git@sface-0.1-5
44 # /Volumes/sface-skel-sn/sface.app/appIcon.icns
45 function git_retrieve () {
47 case "$1" in -f|--file) filemode=true; shift;; esac
52 giturl=$(git_url $gitpath)
53 gittag=$(git_tag $gitpath)
54 if [ -z "$filemode" ] ; then
55 [ -d $dest ] || mkdir -p $dest
57 git archive --remote=${giturl} ${gittag} | tar -xf - ${path}
60 destdir=$(dirname $dest)
61 [ -d $destdir ] || mkdir -p $destdir
62 git archive --remote=${giturl} ${gittag} | tar -xOf - ${path} > ${dest}
73 sface_GITPATH=$1; shift
77 skel_name=sface-skel-${arch}
78 skel_dmg=./${skel_name}.dmg
79 skel_mnt="/Volumes/${skel_name}"
81 sfa_release=sfa-$(git_tag $sfa_GITPATH | sed -e s,sfa-,,)
82 sface_release=sface-$(git_tag $sface_GITPATH | sed -e s,sface-,,)
83 release=$(git_tag $sfa_GITPATH)-$(git_tag $sface_GITPATH)
85 img_name=${sface_release}-${sfa_release}-${arch}
86 img_dmg=./${img_name}.dmg
87 img_raw_dmg=./${img_name}.raw.dmg
88 img_mnt="/Volumes/${img_name}"
91 [ -f $img_dmg ] && die "output dmg $img_dmg already exists"
92 [ -f $img_raw_dmg ] && die "please clean up tmp file $img_raw_dmg"
94 if [ -n "$FORCE_DOWNLOAD" ] ; then
95 [ -d "$skel_mnt" ] && hdiutil unmount "$skel_mnt"
96 [ -f "$skel_dmg" ] && rm -f "$skel_dmg"
99 # mount the skeleton if not yet avail.
100 if [ ! -d "$skel_mnt" ] ; then
102 if [ ! -f $skel_dmg ] ; then
103 echo "Retrieving $skel_dmg from $SKEL_REPO"
104 curl -O $SKEL_REPO/$skel_dmg
106 # needless to check for existence as curl will have created on anyway
107 echo "Mounting skeleton"
108 if ! hdiutil mount -quiet -mountpoint $skel_mnt $skel_dmg ; then
109 die "Could not mount $skel_dmg
110 Please check it is published at $SKEL_REPO
111 Also make sure to trash the current one before retrying"
114 [ -d "$skel_mnt" ] || die "Could not mount skeleton $skel_dmg"
116 # if image already mounted, it's an old run
117 [ -d "$img_mnt" ] && die "Image already mounted on $img_mnt"
119 echo "Initializing image ..."
120 hdiutil create -quiet -size $DISK_SIZE -fs HFS -volname ${img_name} $img_raw_dmg
121 hdiutil attach -readwrite -mount required $img_raw_dmg
123 # copy skeleton as-is
124 tar -C "$skel_mnt" --exclude .Trashes -cf - . | tar -C "$img_mnt" -xf -
125 # places relative to mount point
128 skelapp_path=$(ls -d "$skel_mnt"/*.app)
129 skelapp=$(basename "$skelapp_path")
130 if [ "$skelapp" != "$app" ] ; then
131 mv "$img_mnt/$skelapp" "$img_mnt/$app"
134 resource_path=$app/Contents/Resources
135 bin_path=$app/Contents/MacOS
136 icon_path=$app/Contents/Resources/
137 background_path=background
138 # retrieve sfa/sfa and sface/sface in the image
139 git_retrieve $sfa_GITPATH sfa "$img_mnt"/$resource_path/
140 git_retrieve $sface_GITPATH sface "$img_mnt"/$resource_path/
141 # copy binaries from sface to the bin dir
142 for bin in sface.bin sface-run; do
143 # don't use the --file mode as this loses the executable bit
144 git_retrieve $sface_GITPATH $bin "$img_mnt"/$bin_path
146 # install background and app icons
147 # git_retrieve --file $sface_GITPATH macos/graphic-install-background.png "$img_mnt"/$background_path/background.png
148 git_retrieve --file $sface_GITPATH macos/graphic-install-background.png "$img_mnt"/.background.png
149 git_retrieve --file $sface_GITPATH macos/graphic-sfa.icns "$img_mnt"/$icon_path/appIcon.icns
151 git_retrieve --file $sface_GITPATH macos/graphic-vol-sface.icns "$img_mnt"/.VolumeIcon.icns
153 # instantiate version
154 sed -e "s,@VERSIONTAG@,$sfa_release,g" -e "s,@SCMURL@,${sfa_GITPATH},g" \
155 "$img_mnt"/$resource_path/sfa/util/version.py.in > "$img_mnt"/$resource_path/sfa/util/version.py
157 # this apparently requires xcode
158 /Developer/Tools/SetFile -a V "$img_mnt"/$background_path
160 # clean up just in case
161 find "$img_mnt" -name '*pyc' | xargs rm -f
162 find "$img_mnt" -name '*~' | xargs rm -f
164 if [ -n "$INTERACTIVE" ] ; then
165 echo "Please tweak icons layout in $img_mnt under Finder, and press enter when done ..."
169 hdiutil detach "$img_mnt"
171 echo "Compressing..."
172 hdiutil convert -quiet -format UDZO -imagekey zlib-level=9 -o $img_dmg $img_raw_dmg
173 # clean up the raw image
175 # unmount the skeleton
176 hdiutil unmount "$skel_mnt"
178 echo "=================================================="
179 echo "Install image ready in $img_dmg"
180 echo "You may publish it by running e.g."
181 echo "rsync -av $img_dmg root@build.onelab.eu:/build/sface"
182 echo "=================================================="
186 ########################################
187 # either provide a build dir and tags file
188 # or sface-GITPATH sfa-GITPATH
190 echo "$COMMAND -b <build-dir> -t <tags-file>"
192 echo "$COMMAND -c <sface-GITPATH> -s <sfa-GITPATH>"
194 echo "Common options"
195 echo " -i : interactive : let you align icons properly in the image before it gets wrapped"
196 echo " -f : force download of the skeleton package"
197 echo " -a leopard|snow-leopard"
198 echo " -A : run on all known archs"
201 echo " -h : this help"
204 DEFAULT_BUILD_DIR=$HOME/git/build
205 DEFAULT_TAGS_FILE=onelab-k32-tags.mk
208 while getopts "b:t:c:s:ifa:Anvh" opt ; do
210 b) BUILD_DIR=$OPTARG;;
211 t) TAGS_FILE=$OPTARG;;
212 c) sface_GITPATH=$OPTARG;;
213 s) sfa_GITPATH=$OPTARG;;
214 i) INTERACTIVE=true;;
215 f) FORCE_DOWNLOAD=true;;
216 a) ARCHS="$ARCHS $OPTARG";;
217 A) ARCHS="leopard snow-leopard";;
223 shift $(($OPTIND - 1))
225 [ -z "$BUILD_DIR" ] && BUILD_DIR=$DEFAULT_BUILD_DIR
226 [ -z "$TAGS_FILE" ] && TAGS_FILE=$DEFAULT_TAGS_FILE
227 [ -z "$ARCHS" ] && ARCHS=$DEFAULT_ARCH
228 [[ -n "$@" ]] && { usage ; exit 1; }
229 if [ -z "$sface_GITPATH" ] ; then
230 sface_GITPATH=$(make -C $BUILD_DIR stage1=true PLDISTROTAGS=$TAGS_FILE +sface-GITPATH 2> /dev/null)
231 echo "Retrieved from $BUILD_DIR/$TAGS_FILE.."
232 echo " sface_GITPATH=$sface_GITPATH"
234 if [ -z "$sfa_GITPATH" ] ; then
235 sfa_GITPATH=$(make -C $BUILD_DIR stage1=true PLDISTROTAGS=$TAGS_FILE +sfa-GITPATH 2> /dev/null)
236 echo "Retrieved from $BUILD_DIR/$TAGS_FILE.."
237 echo " sfa_GITPATH=$sfa_GITPATH"
239 for ARCH in $ARCHS; do
240 if [ -z "$dry_run" ] ; then
241 package $sface_GITPATH $sfa_GITPATH $ARCH
243 echo "Would run package $sface_GITPATH $sfa_GITPATH $ARCH"