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.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 it gets fetched at http://mirror.onelab.eu/third-party/
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
17 # the place to search for the skeleton
18 SKEL_REPO=http://mirror.onelab.eu/third-party
20 # hard-wired for snow-leopard for now
23 # does not affect final dmg size as it's compressed
26 ########################################
27 COMMAND=$(basename $0)
29 # extract the tag part of a GITPATH
30 function git_url () { echo $1 | cut -d @ -f 1 ; }
31 function git_tag () { echo $1 | cut -d @ -f 2 ; }
33 # go in $dest and retrieve $path part of codebase based on gitpath, e.g.
35 # git://git.onelab.eu/sface.git@sface-0.1-5
37 # /Volumes/sface-skel-sn/sface.app/Contents/Resources/
38 # or, with the -f (-file) option:
40 # git://git.onelab.eu/sface.git@sface-0.1-5
42 # /Volumes/sface-skel-sn/sface.app/appIcon.icns
43 function git_retrieve () {
45 case "$1" in -f|--file) filemode=true; shift;; esac
50 giturl=$(git_url $gitpath)
51 gittag=$(git_tag $gitpath)
52 if [ -z "$filemode" ] ; then
53 [ -d $dest ] || mkdir -p $dest
55 git archive --remote=${giturl} ${gittag} | tar -xf - ${path}
58 destdir=$(dirname $dest)
59 [ -d $destdir ] || mkdir -p $destdir
60 git archive --remote=${giturl} ${gittag} | tar -xOf - ${path} > ${dest}
71 sface_GITPATH=$1; shift
74 skel_name=sface-skel-${arch}
75 skel_dmg=./${skel_name}.dmg
76 skel_mnt=/Volumes/${skel_name}
78 sfa_release=sfa-$(git_tag $sfa_GITPATH | sed -e s,sfa-,,)
79 sface_release=sface-$(git_tag $sface_GITPATH | sed -e s,sface-,,)
80 release=$(git_tag $sfa_GITPATH)-$(git_tag $sface_GITPATH)
82 img_name=${sface_release}-${sfa_release}-${arch}
83 img_dmg=./${img_name}.dmg
84 img_raw_dmg=./${img_name}.raw.dmg
85 img_mnt=/Volumes/${img_name}
88 [ -f $img_dmg ] && die "output dmg $img_dmg already exists"
89 [ -f $img_raw_dmg ] && die "please clean up tmp file $img_raw_dmg"
91 # mount the skeleton if not yet avail.
92 if [ ! -d $skel_mnt ] ; then
94 if [ ! -f $skel_dmg ] ; then
95 echo "Retrieving $skel_dmg from $SKEL_REPO"
96 curl -O $SKEL_REPO/$skel_dmg
98 # needless to check for existence as curl will have created on anyway
99 if ! hdiutil mount $skel_dmg ; then
100 die "Could not mount $skel_dmg
101 Please check it is published at $SKEL_REPO
102 Also make sure to trash the current one before retrying"
105 [ -d $skel_mnt ] || die "Could not mount skeleton $skel_dmg"
107 # if image already mounted, it's an old run
108 [ -d $img_mnt ] && die "Image already mounted on $img_mount"
110 hdiutil create -size $DISK_SIZE -fs HFS+J -volname ${img_name} $img_raw_dmg
111 hdiutil attach -readwrite -mount required $img_raw_dmg
113 # copy skeleton as-is
114 tar -C $skel_mnt --exclude .Trashes -cf - . | tar -C $img_mnt -xf -
115 # places relative to mount point
117 resource_path=$app/Contents/Resources
118 bin_path=$app/Contents/MacOS
119 icon_path=$app/Contents/Resources/
120 background_path=background
121 # retrieve sfa/sfa and sface/sface in the image
122 git_retrieve $sfa_GITPATH sfa $img_mnt/$resource_path/
123 git_retrieve $sface_GITPATH sface $img_mnt/$resource_path/
124 # copy binaries from sface to the bin dir
125 for bin in sface.bin sface-run; do
126 git_retrieve --file $sface_GITPATH $bin $img_mnt/$bin_path/$bin
128 # install background and app icons
129 git_retrieve --file $sface_GITPATH macos/background.png $img_mnt/$background_path/background.png
130 git_retrieve --file $sface_GITPATH macos/appIcon.icns $img_mnt/$icon_path/appIcon.icns
132 git_retrieve --file $sface_GITPATH macos/appIcon.icns $img_mnt/.VolumeIcon.icns
134 # this apparently requires xcode
135 /Developer/Tools/SetFile -a V $img_mnt/$background_path
136 # clean up just in case
137 find $img_mnt -name '*pyc' | xargs rm -f
138 find $img_mnt -name '*~' | xargs rm -f
140 if [ -n "$INTERACTIVE" ] ; then
141 echo "Please open $img_mnt under Finder ..."
145 hdiutil detach $img_mnt
147 hdiutil convert -format UDZO -imagekey zlib-level=9 -o $img_dmg $img_raw_dmg
148 # clean up the raw image
150 # unmount the skeleton
151 hdiutil unmount $skel_mnt
155 ########################################
156 # either provide a build dir and tags file
157 # or sface-GITPATH sfa-GITPATH
159 echo "$COMMAND -b <build-dir> -t <tags-file>"
161 echo "$COMMAND -c <sface-GITPATH> -s <sfa-GITPATH>"
163 echo "Common options"
165 echo " -i : let you open the image before getting wrapped"
166 echo " -h : this help"
169 DEFAULT_BUILD_DIR=$HOME/git/build
170 DEFAULT_TAGS_FILE=onelab-k32-tags.mk
173 while getopts "b:t:c:s:hni" opt ; do
175 b) BUILD_DIR=$OPTARG;;
176 t) TAGS_FILE=$OPTARG;;
177 c) sface_GITPATH=$OPTARG;;
178 s) sfa_GITPATH=$OPTARG;;
180 i) INTERACTIVE=true;;
184 shift $(($OPTIND - 1))
186 [ -z "$BUILD_DIR" ] && BUILD_DIR=$DEFAULT_BUILD_DIR
187 [ -z "$TAGS_FILE" ] && TAGS_FILE=$DEFAULT_TAGS_FILE
188 if [ -z "$sface_GITPATH" ] ; then
189 sface_GITPATH=$(make -C $BUILD_DIR stage1=true PLDISTROTAGS=$TAGS_FILE +sface-GITPATH 2> /dev/null)
190 echo "Retrieved from $BUILD_DIR/$TAGS_FILE.."
191 echo " sface_GITPATH=$sface_GITPATH"
193 if [ -z "$sfa_GITPATH" ] ; then
194 sfa_GITPATH=$(make -C $BUILD_DIR stage1=true PLDISTROTAGS=$TAGS_FILE +sfa-GITPATH 2> /dev/null)
195 echo "Retrieved from $BUILD_DIR/$TAGS_FILE.."
196 echo " sfa_GITPATH=$sfa_GITPATH"
198 [ -z "$dry_run" ] && package "$@" $sface_GITPATH $sfa_GITPATH