renaming the various graphics used
[sface.git] / macos / build-dmg.sh
index b901ef0..930d55f 100755 (executable)
@@ -7,9 +7,9 @@
 # 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
+# sface-skel-snow-leopard.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
+#   otherwise it gets fetched at http://mirror.onelab.eu/third-party/ 
 # 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
 
@@ -53,12 +49,14 @@ function git_retrieve () {
 
     giturl=$(git_url $gitpath)
     gittag=$(git_tag $gitpath)
-    if [ -z "$filemode"] ; then
+    if [ -z "$filemode" ] ; then
        [ -d $dest ] || mkdir -p $dest
-       pushd $dest >& /dev/null
+       pushd $dest
        git archive --remote=${giturl} ${gittag} | tar -xf - ${path}
        popd
     else
+       destdir=$(dirname $dest)
+       [ -d $destdir ] || mkdir -p $destdir
        git archive --remote=${giturl} ${gittag} | tar -xOf - ${path} > ${dest}
     fi
 }
@@ -68,7 +66,11 @@ function die () {
     exit 1
 }
 
-function main () {
+function package () {
+    
+    sface_GITPATH=$1; shift
+    sfa_GITPATH=$1; shift
+
     skel_name=sface-skel-${arch}
     skel_dmg=./${skel_name}.dmg
     skel_mnt=/Volumes/${skel_name}
@@ -103,13 +105,13 @@ Also make sure to trash the current one before retrying"
     [ -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"
+    [ -d $img_mnt ] && die "Image already mounted on $img_mnt"
 
     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 -
+    tar -C $skel_mnt --exclude .Trashes -cf - . | tar -C $img_mnt -xf -
     # places relative to mount point
     app=sface.app
     resource_path=$app/Contents/Resources
@@ -121,7 +123,8 @@ Also make sure to trash the current one before retrying"
     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 --file $sface_GITPATH $bin $img_mnt/$bin_path/$bin
+       # don't use the --file mode as this loses the executable bit
+       git_retrieve $sface_GITPATH $bin $img_mnt/$bin_path
     done
     # install background and app icons
     git_retrieve --file $sface_GITPATH macos/background.png $img_mnt/$background_path/background.png
@@ -129,14 +132,23 @@ Also make sure to trash the current one before retrying"
     # xxx ?
     git_retrieve --file $sface_GITPATH macos/appIcon.icns $img_mnt/.VolumeIcon.icns
 
+    # instantiate version
+    sed -e "s,@VERSIONTAG@,$sfa_release,g" -e "s,@SCMURL@,${sfa_GITPATH},g" \
+       $img_mnt/$resource_path/sfa/util/version.py.in > $img_mnt/$resource_path/sfa/util/version.py
+
     # 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 _
+    if [ -n "$INTERACTIVE" ] ; then
+       echo "Please open $img_mnt under Finder ..."
+       read _
+    fi
 
     hdiutil detach $img_mnt
     rm -f $img_dmg
@@ -145,6 +157,54 @@ Also make sure to trash the current one before retrying"
     rm -f $img_raw_dmg
     # unmount the skeleton
     hdiutil unmount $skel_mnt
+
+}
+
+########################################
+# either provide a build dir and tags file
+# or sface-GITPATH sfa-GITPATH 
+function usage () {
+    echo "$COMMAND -b <build-dir> -t <tags-file>"
+    echo " or"
+    echo "$COMMAND -c <sface-GITPATH> -s <sfa-GITPATH>"
+    echo ""
+    echo "Common options"
+    echo " -n : dry-run"
+    echo " -i : let you open the image before getting wrapped"
+    echo " -h : this help"
+}
+
+DEFAULT_BUILD_DIR=$HOME/git/build
+DEFAULT_TAGS_FILE=onelab-k32-tags.mk
+
+function main () {
+    while getopts "b:t:c:s:hni" opt ; do
+       case $opt in 
+           b) BUILD_DIR=$OPTARG;;
+           t) TAGS_FILE=$OPTARG;;
+           c) sface_GITPATH=$OPTARG;;
+           s) sfa_GITPATH=$OPTARG;;
+           n) dry_run=true;;
+           i) INTERACTIVE=true;;
+           h) usage; exit 1 ;;
+       esac
+    done
+    shift $(($OPTIND - 1))
+
+    [ -z "$BUILD_DIR" ] && BUILD_DIR=$DEFAULT_BUILD_DIR
+    [ -z "$TAGS_FILE" ] && TAGS_FILE=$DEFAULT_TAGS_FILE
+    if [ -z "$sface_GITPATH" ] ; then
+       sface_GITPATH=$(make -C $BUILD_DIR stage1=true PLDISTROTAGS=$TAGS_FILE +sface-GITPATH 2> /dev/null)
+       echo "Retrieved from $BUILD_DIR/$TAGS_FILE.."
+       echo " sface_GITPATH=$sface_GITPATH"
+    fi
+    if [ -z "$sfa_GITPATH" ] ; then
+       sfa_GITPATH=$(make -C $BUILD_DIR stage1=true PLDISTROTAGS=$TAGS_FILE +sfa-GITPATH 2> /dev/null)
+       echo "Retrieved from $BUILD_DIR/$TAGS_FILE.."
+       echo " sfa_GITPATH=$sfa_GITPATH"
+    fi
+    [ -z "$dry_run" ] && package "$@" $sface_GITPATH $sfa_GITPATH
+       
 }
 
 main "$@"