#!/bin/sh

export ROOT=/home/ngbuild/ng/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_$2.tgz .

#
# Reset "latest" symlink to point to the new archive
#
cd /home/ngbuild/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 ..
#
# 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
