#!/bin/sh
#
# Prepare the autobuild website for a new run.
# This script is called by autobuild during startup.
# Orion Sky Lawlor, olawlor@acm.org, 2002/2/3
#

source config

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

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

rm -fr web/*

newDir="old."`date +"%Y_%m_%d__%H_%M"`
echo "update_web_start> Making web directory at $newDir"
Do ssh $webMachine << END_REMOTE
cd $webMachPath
#rm -fr bin/*
#(cd bin && ln -s charm_src.tar.gz charm.tar.gz)
rm -f prev
mv -f cur prev
mkdir $newDir
ln -s $newDir cur
#notUpdated=`find bin -not -ctime -14`
#if [ -n "\$notUpdated" ]; then
#  emailText="Hey guys, the following files have not been updated for 2 weeks. Is it time to check why it is not working?\n\n\$notUpdated"
#  echo -e \$emailText | mail -s "Charm++ Autobuild continuously failing" $mailRecip
#fi
cd cur
cat > index.html << END_HTML
<html>
<title>Charm++ Automated-Build Status</title>
<body bgcolor="#ffFFff">
<h1>Charm++ Automated-Build Starting...</h1>
Charm++ automated build started on `date`<br>
No compilations have finished yet.<br>
Return to <a href="/">Charm++ Home Page</a>
</BODY></HTML>
END_HTML

END_REMOTE

