#!/bin/sh

export TOPDIR=$(dirname $0)

. $TOPDIR/settings.sh
. $TOPDIR/common.sh

OUTDIR=$1
ARCH=$2
RESULTS=$3

OUTFILE=$OUTDIR/$ARCH/HEADER.html
INLOGS="/org/cdbuilder.debian.org/dst/deb-cd/log"
OUTLOGS="build-logs/$DATE"

grep -q WARNING $OUTFILE
if [ $? -ne 0 ] ; then
    echo >> $OUTFILE
    echo "<p><strong>WARNING:</strong>" >>  $OUTFILE
    echo "This build is not up to date; it is the most recent successful build.</p>" >> $OUTFILE
    echo >> $OUTFILE
    echo "<p>Later weekly builds failed with errors:</p>" >> $OUTFILE
fi

echo "<hr>" >> $OUTFILE
echo "<ul>" >> $OUTFILE
mkdir -p ${OUTDIR}/${ARCH}/${OUTLOGS}
for RESULT in $RESULTS; do
    TYPE=`echo $RESULT | awk -F / '{print $1}'`
    ERROR=`echo $RESULT | awk -F / '{print $2}'`
    DATE=`echo $RESULT | awk -F / '{print $3}'`
    LOGFILE=`echo $RESULT | awk -F / '{print $4}'`
    BUILDTYPE=`echo $TYPE | sed 's/FAIL//g'`
    cp ${INLOGS}/${LOGFILE} ${OUTDIR}/${ARCH}/${OUTLOGS}/${BUILDTYPE}.log
    DESC=`build_description ${BUILDTYPE}`
    echo "<li>$DESC build failed with error $ERROR at $DATE; <a href=\"$OUTLOGS/${BUILDTYPE}.log\">logfile</a>" >> $OUTFILE

done
echo "</ul>" >> $OUTFILE

