#!/bin/bash

export BUILD_ROOT=$HOME/nc/sw/twl
export ARCHIVE_ROOT=$HOME/twl/export/$1

mkdir -p $ARCHIVE_ROOT

if [[ xx"$1" == xx"" || yy"$2" == yy"" ]]; then 
    echo "Usage: $0 build curdate\n"
    exit 1
else
    echo "Archive $BUILD_ROOT for $1 build for date $2"
fi

#
# Create a tar archive of build tree
#
cd $BUILD_ROOT
tar czf $ARCHIVE_ROOT/twl_root_$2.tgz --exclude CVS .

#
# Reset "latest" symlink to point to the new archive
#
cd $ARCHIVE_ROOT
rm -f latest
ln -s twl_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 TWL ROOT from $1 build dated $2" > README
cd ..
mv latest latest.prev
mv latest.new latest
rm -rf latest.prev
