#! /bin/sh -e set -e indir=$1; shift outdir=$1; shift die () { echo "$@" 1>&2 exit 1 } escape () { sed 's/&/\&/g;s//\>/g' } template () { cat="$1"; shift points="$1"; shift author=$(echo $1 | escape); shift cat < $cat $points

$cat for $points points

EOF echo "
" cat echo "
" if [ $# -gt 0 ]; then echo "

Associated files:

" echo " " fi cat < Team hash: Answer:
Puzzle by $author
EOF } cat=$(basename $indir) uanswers=$outdir/answers.unsorted usummary=$outdir/summary.unsorted echo -n > $uanswers rm -f $usummary for dn in $indir/[0-9]*; do [ -d $dn ] || continue points=$(basename $dn) echo $dn tgt=$outdir/puzzles/$points mkdir -p $tgt touch $tgt/index.html if [ -f $dn/Makefile ]; then # If there's a Makefile, run make make -C $dn || exit 1 files=$(cd $tgt; echo *) fi if [ -f $dn/@manifest.txt ]; then # If there's a manifest, use that files=$(cat $dn/@manifest.txt) else # Otherwise, look for special files and copy the rest files= for fn in $dn/*; do case $(basename $fn) in @*) # Handle meta-information later ;; *~|"#"*) # Don't copy temporary or backup files ;; ,*) # Copy but don't list ln -f $fn $tgt/ ;; *) ln -f $fn $tgt/ files="$files $(basename $fn)" ;; esac done fi # Append answers if [ -f $dn/@answer.txt ]; then awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/@answer.txt >> $uanswers else die "$dn/@answer.txt: No such file or directory" fi # Append summary if [ -f $dn/@summary.txt ]; then awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/@summary.txt >> $usummary fi # Read author if [ -f $dn/@author.txt ]; then author=$(cat $dn/@author.txt) else die "$dn/@author.txt does not exist." fi # Generate index now that we have a list of files if [ -f $dn/@index.mdwn ]; then markdown --html4tags $dn/@index.mdwn fi | template $cat $points "$author" $files > $tgt/index.html done sort -n $uanswers > $outdir/answers.txt [ -f $usummary ] && sort -ns $usummary > $outdir/summary.txt rm -f $uanswers $usummary