#!/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

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

# 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=`grep -v '^#' system_list | awk -F: '{print $1}'`
versions=`sed -e 's/#//' system_list | awk -F: '{print $1}' | uniq`

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="${cvsModule}_src.tar.gz">the Charm++ source code</a> used here.<br>
The most recent nightly build charm++ source is also available at cvs server with module "charm-nightly-test".<br>
View <a href="../prev/">the previous autobuild status</a>, or 
<a href="../">all previous status pages</a>.<br>
Latest precompiled binaries (including source) can be found <a href="../bin">here</a>.<br><br>

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

for v in $versions
do
        m=`grep '^'$v":" system_list 2>/dev/null`
       	l=`grep $v":" system_list`
        buildMachine=`echo $l | awk -F: '{print $2}' | awk -F@ '{print $2}'`
        description=`echo $l | awk -F: '{print $9}'`
	if test -z "$m"
	then
		status='Test skipped'
		echo "Skipped" >  messages/$v
	else
		status=`cat status/$v`
	fi
	cat >> $out << END_ROW
	<tr><td><a href="$v.txt">$v</a></td> 
        <td style="width: 25%">$status</td> 
        <td>$description</td> <td>$buildMachine</td></tr>
END_ROW
	Do cp messages/$v $outDir/$v.txt
done

cat >> $out << END_TRAILER
</table>
<br>
Maintained by <A HREF="mailto:gzheng@uiuc.edu">Gengbin Zheng</A>.<br>
Return to <a href="/">Charm++ Home Page</a>
</BODY></HTML>
END_TRAILER

Do scp $outDir/* $webMachine:$webMachCur

rm -fr $outDir
