very first draft for dmg packaging - all set in script, no option
authorThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 14 Mar 2011 14:02:22 +0000 (15:02 +0100)
committerThierry Parmentelat <thierry.parmentelat@sophia.inria.fr>
Mon, 14 Mar 2011 14:02:22 +0000 (15:02 +0100)
macos/build-dmg.sh [new file with mode: 0755]

diff --git a/macos/build-dmg.sh b/macos/build-dmg.sh
new file mode 100755 (executable)
index 0000000..0144705
--- /dev/null
@@ -0,0 +1,137 @@
+#!/bin/sh
+
+# PURPOSE
+# package a combination of sfa+sface into a snow leopard dmg install disk
+# 
+# NOTES
+# we leverage the first similar packaging initially made by Baris Metin
+# 
+# REQUIREMENTS
+# sface-skel.dmg is the skeleton that has Qt and all the other third-party software
+#   it is expected to be found in the local directory
+#   should be made available on http://mirror.onelab.eu/third-party/ as well
+# the script expects the taglevels for both sfa and sface, 
+#   in order to retrieve the corresponding code and to label the resulting package properly
+#
+
+# the place to search for the  skeleton
+SKEL_REPO=http://mirror.onelab.eu/third-party
+
+sfa_GITPATH=git://git.onelab.eu/sfa.git@sfa-1.0-20
+sface_GITPATH=git://git.onelab.eu/sface.git@sface-0.1-5
+sface_GITPATH=git://git.onelab.eu/sface.git@master
+
+# hard-wired for snow-leopard for now
+arch=snow-leopard
+
+# does not affect final dmg size as it's compressed
+DISK_SIZE=100M
+
+########################################
+COMMAND=$(basename $0)
+
+# extract the tag part of a GITPATH
+function git_url () { echo $1 | cut -d @ -f 1 ; }
+function git_tag () { echo $1 | cut -d @ -f 2 ; }
+
+# go in $dest and retrieve $path part of codebase based on gitpath, e.g.
+# git_retrieve \
+#     git://git.onelab.eu/sface.git@sface-0.1-5 
+#     sface 
+#     /Volumes/sface-skel-sn/sface.app/Contents/Resources/
+function git_retrieve () {
+    gitpath=$1; shift
+    path=$1; shift
+    dest=$1; shift
+
+    giturl=$(git_url $gitpath)
+    gittag=$(git_tag $gitpath)
+    [ -d $dest ] || mkdir -p $dest
+    pushd $dest >& /dev/null
+    git archive --remote=${giturl} ${gittag} | tar -xf - ${path}
+    popd
+}
+
+function die () {
+    echo "$@" "- exiting" 
+    exit 1
+}
+
+function main () {
+    skel_name=sface-skel-${arch}
+    skel_dmg=./${skel_name}.dmg
+    skel_mnt=/Volumes/${skel_name}
+
+    sfa_release=sfa-$(git_tag $sfa_GITPATH | sed -e s,sfa-,,)
+    sface_release=sface-$(git_tag $sface_GITPATH | sed -e s,sface-,,)
+    release=$(git_tag $sfa_GITPATH)-$(git_tag $sface_GITPATH)
+
+    img_name=${sface_release}-${sfa_release}-${arch}
+    img_dmg=./${img_name}.dmg
+    img_raw_dmg=./${img_name}.raw.dmg
+    img_mnt=/Volumes/${img_name}
+
+    # check we're clear
+    [ -f $img_dmg ] && die "output dmg $img_dmg already exists"
+    [ -f $img_raw_dmg ] && die "please clean up tmp file $img_raw_dmg"
+
+    # mount the skeleton if not yet avail.
+    if [ ! -d $skel_mnt ] ; then
+        # locate skel dmg
+       if [ ! -f $skel_dmg ] ; then
+           echo "Retrieving $skel_dmg from $SKEL_REPO"
+           curl -O $SKEL_REPO/$skel_dmg
+       fi
+       # needless to check for existence as curl will have created on anyway
+       if ! hdiutil mount $skel_dmg ; then
+           die "Could not mount $skel_dmg
+Please check it is published at $SKEL_REPO
+Also make sure to trash the current one before retrying"
+       fi
+    fi
+    [ -d $skel_mnt ] || die "Could not mount skeleton $skel_dmg"
+
+    # if image already mounted, it's an old run
+    [ -d $img_mnt ] && die "Image already mounted on $img_mount"
+
+    hdiutil create -size $DISK_SIZE -fs HFS+J -volname ${img_name} $img_raw_dmg
+    hdiutil attach -readwrite -mount required $img_raw_dmg 
+
+    # copy skeleton as-is
+    tar -C $skel_mnt -cf - . | tar -C $img_mnt -xf -
+    # places relative to mount point
+    app=sface.app
+    resource_path=$app/Contents/Resources
+    bin_path=$app/Contents/MacOS
+    icon_path=$app/Contents/Resources/
+    background_path=background
+    # retrieve sfa/sfa and sface/sface in the image
+    git_retrieve $sfa_GITPATH sfa $img_mnt/$resource_path/
+    git_retrieve $sface_GITPATH sface $img_mnt/$resource_path/
+    # copy binaries from sface to the bin dir
+    for bin in sface.bin sface-run; do 
+       git_retrieve $sface_GITPATH $bin $img_mnt/$bin_path
+    done
+    # install background and app icons
+    git_retrieve $sface_GITPATH macos/background.png $img_mnt/$background_path
+    git_retrieve $sface_GITPATH macos/appIcon.icns $img_mnt/$icon_path
+
+    # this apparently requires xcode
+    /Developer/Tools/SetFile -a V $img_mnt/$background_path
+    # clean up just in case
+    find $img_mnt -name '*pyc' | xargs rm -f
+    find $img_mnt -name '*~' | xargs rm -f
+
+    echo "Please open $img_mnt under Finder ..."
+    read _
+
+    hdiutil detach $img_mnt
+    rm -f $img_dmg
+    hdiutil convert -format UDZO -imagekey zlib-level=9 -o $img_dmg $img_raw_dmg
+    # clean up the raw image
+    rm -f $img_raw_dmg
+    # unmount the skeleton
+    hdiutil unmount $skel_mnt
+}
+
+main "$@"