#!/bin/sh
# echo 'processlogs: at '`date`', begin'
# establish which directory the logfiles live in (leave out for
# backwards compatibility)
buildlogdir=$(realpath .)
if [ "$2" != "" ]; then buildlogdir="$2"; fi
baselogdir=$(basename ${buildlogdir})
# establish which directory INDEX lives in (leave out for
# backwards compatibility)
indexlogdir=$(realpath .)
if [ "$3" != "" ]; then indexlogdir="$3"; fi
# allow this script to be run from anywhere in the tree
scriptdir=$(dirname $0)
errorscript=$scriptdir/processonelog
# Figure out which arch we're building for
pb=/var/portbuild
rpb=$(realpath ${pb} | sed -e "s,/$,," )
arch=$(echo ${buildlogdir} | sed -e "s,${rpb}/,," | cut -f 1 -d /)
. ${pb}/${arch}/portbuild.conf
# create a name for the tempfile
of=.index.html
# delete lockfiles if more than a day old
find $of .lock -mmin +60 -delete 2>/dev/null
# exit if another instance of this program is running
if [ -f $of -o -f .lock ]; then exit; fi
# if there are no new logfiles, there is nothing to do here.
if [ -e .stamp -a $(echo $(find -f $buildlogdir -maxdepth 1 -newer .stamp -type f -name '*.log' 2>/dev/null | wc -l)) = "0" ]; then exit; fi
touch .stamp
touch .lock
# get the list of buildlogs.
set $buildlogdir/*.log
> .logs
#
# Read the log-files and write summaries to .logs in the format
# $filename|$portname|$affected|$logsize|$dir|$maintainer|\
# $reason|$tag|$broken|$datetime
#
# echo 'processlogs: at '`date`', begin processing log files'
if [ $# != 1 -o "x$1" != "x`dirname $1`/*.log" ]; then
while [ ! -z "$1" ]; do
filename=$(basename $1)
#echo 'processlogs: at '`date`', examining '$filename'
$errorscript $filename $indexlogdir >> .logs
shift
done
fi
# echo 'processlogs: at '`date`', end processing log files'
# XXX Sometimes log entries get doubled up for some reason
uniq .logs > .logs2
mv .logs2 .logs
num=$(wc -l < .logs)
header() {
echo "
Package building errors" >$of
echo "Package building errors
" >>$of
echo "View by " >>$of
echo "[ port " >>$of
echo "| maintainer " >>$of
echo "| category " >>$of
echo "| error " >>$of
echo "| builddate " >>$of
echo "]
" >>$of
if [ $num = "0" ]; then
echo "No errors (yet)" >>$of
else
if [ -s cvsdone ]; then
echo "CVS update finished at: $(cat cvsdone)
" >> $of
fi
latest=$(cd $buildlogdir; ls -rtTl *.log | tail -1 | awk '{printf("%s %s %s %s\n",$6,$7,$8,$9)}';)
echo "Timestamp of newest log: $latest
" >> $of
echo "\"Aff.\" is number of ports that depend on this one
" >> $of
echo "\"[B]\" indicates port is marked BROKEN
" >> $of
echo "$num errors
" >> $of
echo "" >>$of
echo "$1
" >>$of
fi
}
footer() {
echo "
" >>$of
echo "" >>$of
echo "" >>$of
}
# Now reread the .logs file and create the reports. If the .logs file
# has blanks in any field, this code won't work. Therefore, the
# code above has to guarantee that that won't happen, and the code
# below has to catch the metatoken.
# echo 'processlogs: at '`date`', create default output'
#
# Create "default" output, sorted on portname
#
header "Port | Aff. | Size | CVS | Maintainer | Reason | Build date | "
for i in `cat .logs | sort`; do
set $(echo "$i" | tr \| " " | sed -e "s@NONE@\\ @g")
mailto="$6"
if [ "$6" != " " ] ; then
mailto="$6"
fi
echo "" >> $of
echo "$2 | " >> $of
affby=$3
test $affby = "0" -o $affby = "-1" && affby=" "
echo "$affby | $4 Kb | " >> $of
echo "$5 | " >> $of
echo "$mailto | " >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
reason=$(echo $7 | tr '_' ' ')
echo "$reason" >> $of
echo " | " >> $of
date=$(echo ${10} | tr '_' ' ')
echo "$date | " >> $of
echo "
" >> $of
done
footer ""
mv -f $of index.html
# echo 'processlogs: at '`date`', create output sorted by category'
#
# Create output by category
#
header "CVS | Aff. | Size | Port | Maintainer | Reason | Build date | "
for i in `cat .logs | sort -t \\| +4`; do
set $(echo "$i" | tr \| " " | sed -e "s@NONE@\\ @g")
mailto="$6"
if [ "$6" != " " ] ; then
mailto="$6"
fi
echo "" >> $of
echo "$5 | " >> $of
affby=$3
test $affby = "0" -o $affby = "-1" && affby=" "
echo "$affby | $4 Kb | " >> $of
echo "$2 | " >> $of
echo "$mailto | " >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
reason=$(echo $7 | tr '_' ' ')
echo "$reason" >> $of
echo " | " >> $of
date=$(echo ${10} | tr '_' ' ')
echo "$date | " >> $of
echo "
" >> $of
done
footer ""
mv -f $of index-category.html
# echo 'processlogs: at '`date`', create output sorted by maintainer'
#
# Create output by maintainer
#
header "Maintainer | Port | Aff. | Size | CVS | Reason | Build date | "
for i in `cat .logs | sort -t \\| +5`; do
set $(echo "$i" | tr \| " " | sed -e "s@NONE@\\ @g")
mailto="$6"
if [ "$6" != " " ] ; then
mailto="$6"
fi
echo "" >> $of
echo "$mailto | " >> $of
echo "$2 | " >> $of
affby=$3
test $affby = "0" -o $affby = "-1" && affby=" "
echo "$affby | $4 Kb | " >> $of
echo "$5 | " >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
reason=$(echo $7 | tr '_' ' ')
echo "$reason" >> $of
echo " | " >> $of
date=$(echo ${10} | tr '_' ' ')
echo "$date | " >> $of
echo "
" >> $of
done
footer ""
mv -f $of index-maintainer.html
# echo 'processlogs: at '`date`', create output sorted by error'
#
# Create output by error
#
header "Reason | Port | Aff. | Size | CVS | Maintainer | Build date | "
for i in `cat .logs | sort -t \\| +7`; do
set $(echo "$i" | tr \| " " | sed -e "s@NONE@\\ @g")
mailto="$6"
if [ "$6" != " " ] ; then
mailto="$6"
fi
echo "" >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
reason=$(echo $7 | tr '_' ' ')
echo "$reason" >> $of
echo " | " >> $of
echo "$2 | " >> $of
affby=$3
test $affby = "0" -o $affby = "-1" && affby=" "
echo "$affby | $4 Kb | " >> $of
echo "$5 | " >> $of
echo "$mailto | " >> $of
date=$(echo ${10} | tr '_' ' ')
echo "$date | " >> $of
echo "
" >> $of
done
footer ""
mv -f $of index-reason.html
# echo 'processlogs: at '`date`', create output sorted by builddate'
#
# Create output by builddate
#
header "Build date | Port | Aff. | Size | CVS | Maintainer | Reason | "
for i in `cat .logs | sort -t \\| +9`; do
set $(echo "$i" | tr \| " " | sed -e "s@NONE@\\ @g")
mailto="$6"
if [ "$6" != " " ] ; then
mailto="$6"
fi
echo "" >> $of
date=$(echo ${10} | tr '_' ' ')
echo "$date | " >> $of
echo "$2 | " >> $of
affby=$3
test $affby = "0" -o $affby = "-1" && affby=" "
echo "$affby | $4 Kb | " >> $of
echo "$5 | " >> $of
echo "$mailto | " >> $of
echo "" >> $of
test "$9" = "broken" && echo "[B]" >> $of
reason=$(echo $7 | tr '_' ' ')
echo "$reason" >> $of
echo " | " >> $of
echo "
" >> $of
done
footer ""
mv -f $of index-builddate.html
# echo 'processlogs: at '`date`', create maintainer list'
#
# Get list of maintainers.
#
for i in `cat .logs | sort -t \\| +9`; do
set $(echo "$i" | tr \| " " | sed -e "s@NONE@\\ @g")
mailto="$6"
if [ "$6" != " " ] ; then
mailto="$6"
fi
maints="$maints $6"
done
echo $maints | sed -e 's/ /\
/g' | sort -fu > maintainers
# now remove the lockfile for this invocation, and exit
rm .lock
# echo 'processlogs: at '`date`', end'