#!/bin/sh
#
# Bring the autobuild website status up-to-date.
# This script is called by the build_on_system scripts,
# which run simultaniously, so this script needs to be 
# reentrant.
# 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
}

versions=`awk -F: '{print $1}' system_list`

outDir="web/$$/"
Do mkdir $outDir
out="web/$$/index.html"
cat > $out << END_HEADER
<html>
<title>Charm++ Automated-Build Status</title>
<body bgcolor="#ffFFff">
<h1>Charm++ Automated-Build Status</h1>
This page generated on `date` <br>
Download <a href="charm_src.tar.gz">the Charm++ source code</a> used here.<br>
View <a href="../prev/">the previous autobuild status</a>, or 
<a href="../">all previous status pages</a>.<br>

<table border=2 width=100%>
<tr>
<td><B>Version</B></td> <td><B>Status</B></td>
END_HEADER

for v in $versions
do
	cat >> $out << END_ROW
	<tr><td><a href="$v.txt">$v</a></td> <td>`cat status/$v`</td></tr>
END_ROW
	Do cp messages/$v $outDir/$v.txt
done

cat >> $out << END_TRAILER
</table>
Return to <a href="/">Charm++ Home Page</a>
</BODY></HTML>
END_TRAILER

Do scp $outDir/* $webMachine:$webMachCur

rm -fr $outDir
