#!/bin/sh
#
# Bring the autobuild cvs archive up-to-date.
# Orion Sky Lawlor, olawlor@acm.org, 2004/9/2
#

source config

# Give up if there's no cvs machine in the config file.
[ -z "$cvsMachine" ] && exit 0

# Exit giving this reason for failure.
Die() {
	echo "cvs fatal> " $@ 
	exit 1
}

# Run this command or die
Do() {
	echo "cvs> " $@
	$@ 
	err="$?"
	if [ $err -ne 0 ] 
	then
		Die "error code $err during " $@ 
	fi
}

versions=`grep -v '^#' system_list | awk -F: '{print $1}' `

# Check to see if every version built properly.
for v in $versions
do
	s=`cat status/$v`
	if [ "$s" != "Good" ]
	then
		echo "Error $s in platform $v-- not updating cvs."
		exit 1
	fi
done

# If so, update the CVS repository:
#    charm-nightly-test becomes charm-nightly
#    charm-nightly becomes charm-nightly-old
#    previous charm-nightly-old is removed
Do ssh $cvsMachine << EOF
Do() {
        echo "remote cvs> " \$@
        \$@
        err="\$?"
        if [ \$err -ne 0 ]
        then
                echo "remote cvs fatal> error code \$err during " \$@
		exit 1
        fi
}

 Do cd $cvsRootPath
 rm -fr $cvsModule-nightly-old
 Do mv $cvsModule-nightly $cvsModule-nightly-old
 Do mv $cvsModule-nightly-test $cvsModule-nightly
 echo "remote cvs archive updated."
EOF


