#!/bin/sh
# $FreeBSD$
#
# create HTML showing numbers of packages vs errors. Run this in a directory
# accessible to the web server.
#
# alpha is obsolete
SUPPORTED_ARCHS="amd64 i386 ia64 sparc64"
ROOT_DIRECTORY=/var/portbuild
OUTFILE=`basename $0 | sed -e "s/^do//"`".html"
TMPFILE=.${OUTFILE}
# stylesheet seems like overkill for something this simple
TABLEBGCOLOR="#F0F0F0"
THCOLOR="#E0E0FF"
TDCOLOR_DONE="lightgreen"
TDCOLOR_NOT_DONE="lightyellow"
# subroutines
write_header () {
echo "" > ${TMPFILE}
echo "
" >> ${TMPFILE}
echo "FreeBSD package building statistics" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "FreeBSD package building statistics
" >> ${TMPFILE}
echo "as of `date`
" >> ${TMPFILE}
}
write_table_begin () {
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo " | " >> ${TMPFILE}
echo "cvs date | " >> ${TMPFILE}
echo "latest log | " >> ${TMPFILE}
echo "INDEX | " >> ${TMPFILE}
echo "build logs | " >> ${TMPFILE}
echo "packages | " >> ${TMPFILE}
echo "errors | " >> ${TMPFILE}
echo "skipped | " >> ${TMPFILE}
echo "not yet built | " >> ${TMPFILE}
echo "running? | " >> ${TMPFILE}
echo "completed? | " >> ${TMPFILE}
echo "
" >> ${TMPFILE}
}
write_row () {
# first, gather data
arch=$1
build=$2
directory=${ROOT_DIRECTORY}/${arch}/${build}
branch=`echo $build | sed -e "s/-exp//"`
if [ "$branch" = "4" ]; then
indexfile=$directory/ports/INDEX
else
indexfile=$directory/ports/INDEX-$branch
fi
# work around the fact that 5-exp is really 6-exp-prime
if [ ! -f $indexfile ]; then
if [ -d $directory/ports ]; then
indexfile=$directory/ports/`cd $directory/ports&&ls INDEX* 2> /dev/null | head -1`
else
# work around the fact that 4 is EOL and thus has no ports/ directory
indexfile=$directory/logs/`cd $directory/logs&&ls INDEX* 2> /dev/null | head -1`
fi
fi
# column: date of CVS checkout
cvsdone=" "
if [ -f $directory/cvsdone ]; then
cvsdone="$(cat $directory/cvsdone | awk '{printf("%s %s\n",$2,$3)}')"
if [ -z "$cvsdone" ]; then
cvsdone=" "
fi
fi
# column: datestamp and URL of latest log
latest=" "
if [ -d $directory/logs ]; then
latest_suffix="$(cd $directory/logs; ls -rtTl | grep '\.log' | tail -1 | awk '{printf("%s\">%s %s\n",$10,$6,$7)}')"
if [ "$latest_suffix" ]; then
latest="" >> ${TMPFILE}
echo "$arch-$build | " >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "$cvsdone | " >> ${TMPFILE}
echo "$latest | " >> ${TMPFILE}
# note: ports/INDEX-n is copied to a file called errorlogs/INDEX
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "$n_index | " >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "$n_logs | " >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "$n_packages | " >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "$n_errors | " >> ${TMPFILE}
echo "$n_duds | " >> ${TMPFILE}
echo "$n_not_yet_built | " >> ${TMPFILE}
echo "$running_flag | " >> ${TMPFILE}
echo "$completed_flag | " >> ${TMPFILE}
echo "" >> ${TMPFILE}
}
write_table_end () {
echo "
" >> ${TMPFILE}
echo "
" >> ${TMPFILE}
}
write_footer () {
echo "explanation of columns:
" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "- latest log is the date of the latest logfile.
" >> ${TMPFILE}
echo "- cvs date is the date of the latest CVS checkout done by the script. It may be inaccurate if a manual checkout was done later.
" >> ${TMPFILE}
echo "- INDEX is number of ports in the INDEX file built from the latest cvs checkout.
" >> ${TMPFILE}
echo "- build logs is number of packages attempted. Note: if a run was restarted, you may see duplicates here.
" >> ${TMPFILE}
echo "- packages is number of packages successfully built. Note: if a run was restarted, you may see duplicates here.
" >> ${TMPFILE}
echo "- errors is number of packages that failed. Note: if a run was restarted, you may see duplicates here.
" >> ${TMPFILE}
echo "- skipped is number of packages that were skipped due to NO_PACKAGE, IGNORE, BROKEN, FORBIDDEN, and so forth (\"duds\" file).
" >> ${TMPFILE}
echo "- not yet built is the INDEX column minus the build logs plus the errors plus the skipped. These are packages that have not been built for one reason or another. Note: interrupted and/or restarted builds can make this number inaccurate because of the duplicates, above.
" >> ${TMPFILE}
echo "- running is whether there are still processes running.
" >> ${TMPFILE}
echo "- completed is whether that build terminated normally or not, as seen from the logfile.
" >> ${TMPFILE}
echo "
" >> ${TMPFILE}
echo "notes:
" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "- on the -exp builds, editors/openoffice.org* are skipped to save time.
" >> ${TMPFILE}
echo "
" >> ${TMPFILE}
echo "" >> ${TMPFILE}
echo "" >> ${TMPFILE}
}
# main
write_header
# display all the mainstream builds first
for arch in ${SUPPORTED_ARCHS}; do
# drop 4 as obsolete
builds=`ls ${ROOT_DIRECTORY}/${arch} | grep '^[5-9]$' | sort`
if [ ! -z "$builds" ]; then
write_table_begin
for build in ${builds}; do
write_row ${arch} ${build}
done
write_table_end
fi
done
# then display all -exp builds (probably only of interest to portmgr;
# would break up the logical flow of the above)
for arch in ${SUPPORTED_ARCHS}; do
builds=`ls ${ROOT_DIRECTORY}/${arch} | grep '^[1-9]-exp$' | sort`
if [ ! -z "$builds" ]; then
write_table_begin
for build in ${builds}; do
write_row ${arch} ${build}
done
write_table_end
fi
done
write_footer
mv -f ${TMPFILE} ${OUTFILE}