#!/bin/sh

if [ $# -lt 1 ]; then
   echo "Usage: $0 <tagnames>"
   echo "        e.g. $0 stable trunk"
   exit 0
fi
SVNTAGS=$1

export PATH_SUFFIX=$(cd `dirname $0`;pwd)

echo "Running nightly tests for ${SVNTAGS}"

run_nightly_scripts="pvfs2/test/run-nightly pvfs2/maint/build pvfs2/test/automated"

#remove existing files
cd $PATH_SUFFIX
sudo /bin/rm -rf `pwd`/pvfs2
mkdir -p pvfs2/test
mkdir -p pvfs2/maint/build

#checkout needed directories and files to run the nightly process
cd ${PATH_SUFFIX}/pvfs2/maint
svn export --force -q http://www.orangefs.org/svn/orangefs/${SVNTAGS}/maint/build
if [ $? != 0 ]
then
   echo "Failed to export maint/build directory from SVN"
   exit 1
fi

cd ${PATH_SUFFIX}/pvfs2/test
svn export --force -q http://www.orangefs.org/svn/orangefs/${SVNTAGS}/test/run-nightly
if [ $? != 0 ]
then
   echo "Failed to export the run-nightly file from SVN"
   exit 1
fi

svn export --force -q http://www.orangefs.org/svn/orangefs/${SVNTAGS}/test/automated
if [ $? != 0 ]
then
   echo "Failed to export test/automated directory from SVN"
   exit 1
fi


cd ${PATH_SUFFIX}/pvfs2/test
echo "Current working directory is `pwd`"
#./run-nightly $SVNTAGS

exit 
