#!/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 mail recipients in the config file.
[ -z "$mailRecip" ] && exit 0

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

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

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

status="status/email"
rm $status

for v in $versions
do
	len=`echo $v | wc -c`
	if test $len -gt 28
	then
		echo "$v:	" `cat status/$v` >> $status
	elif test $len -gt 15
	then
		echo "$v:		" `cat status/$v` >> $status
	elif test $len -gt 7
	then
		echo "$v:			" `cat status/$v` >> $status
	else
		echo "$v:				" `cat status/$v` >> $status
	fi
done

cat >> $status << END_OF_TRAILER

Autobuild status email generated on `date`
Note that this email is automatically sent 6 hours after autobuild started,
it may not reflect the most up-to-date status.
See the detailed results at:
  http://charm.cs.uiuc.edu/autobuild/cur/
Contact zhenggb@acm.org to be removed from this list.
END_OF_TRAILER

cat $status | mail -s "Charm++ Autobuild Status" $mailRecip
echo "Message sent to $mailRecip"
