#!/bin/bash

export NC_HOME=$HOME/nc
export ROOT=$NC_HOME/nc_root
if [[ xx"$1" == xx"" || yy"$2" == yy"" ]]; then 
    echo "Usage: $0 build curdate\n"
    exit 1
else
    echo "Archive $ROOT for $1 build for date $2"
fi

#
# Create a tar archive of $ROOT
#
cd $ROOT
mkdir -p $NC_HOME/export/$1
tar czf $NC_HOME/export/$1/root_$2.tgz .

#
# Reset "latest" symlink to point to the new archive
#
cd $NC_HOME/export/$1
rm -f latest
ln -s root_$2.tgz latest

#
# Expand the archive into a mountable tree
#

cd ..
rm -rf latest.new latest.prev
mkdir latest.new
cd latest.new
tar xzf ../$1/latest
echo "Expanded $ROOT from $1 build dated $2" > README
cd ..
mv latest latest.prev
mv latest.new latest
rm -rf latest.prev

cd ..
#
# This is not needed since filestore pulls the tree using smbclient.
# See the crontab for scbuild on filestore.  Don't recall why this
# was done, but perhaps it's a hassle to get rsync to work under cygwin.
#
# Now rsync the export tree to the public build share on filestore
#
# cd ..
# rsync -avz --delete --password-file=./rsync.pw export/ scbuild@filestore::build/NC_cygwin
