#!/bin/sh

BRANCH=ng_9.21_branch
export ROOT=/home/ngbuild/$BRANCH/ng_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
tar czf /home/ngbuild/export/$1/root_branch_$2.tgz .

#
# Reset "latest" symlink to point to the new archive
#
cd /home/ngbuild/export/$1
rm -f latest_branch
ln -s root_branch_$2.tgz latest_branch

#
# Expand the archive into a mountable tree
#
cd ..
rm -rf latest_branch.new latest_branch.prev
mkdir latest_branch.new
cd latest_branch.new
tar xzf ../$1/latest_branch
echo "Expanded ROOT from $1 build dated $2" > README
cd ..
mv latest_branch latest_branch.prev
mv latest_branch.new latest_branch
rm -rf latest_branch.prev

cd ..
#
# Now rsync the export tree to the public build share on filestore
#
# cd ..
# rsync -avz --delete --password-file=./rsync.pw export/ ngbuild@filestore::build/NG
