#! /bin/sh -e indir=$1; shift outdir=$1; shift escape () { sed 's/&/\&/g;s//\>/g' } template () { cat="$1"; shift points="$1"; shift cat < $cat $points

$cat for $points points

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

Associated files:

" echo " " fi cat < Team: Answer: EOF } cat=$(basename $indir) uanswers=$outdir/answers.unsorted if [ -f $indir/summary.txt ]; then cp $indir/summary.txt $outdir/ fi > $uanswers for dn in $indir/[0-9]*; do [ -d $dn ] || continue points=$(basename $dn) echo $dn tgt=$outdir/puzzles/$points mkdir -p $tgt if [ -f $dn/Makefile ]; then # If there's a makefile, run make make -C $dn DESTDIR=$(pwd)/$tgt files=$(cd $tgt; echo *) else # Otherwise, look for special files and copy the rest files= for fn in $dn/*; do case $(basename $fn) in key|index.mdwn) # Handle these later ;; *~|"#"*) # Don't copy temporary or backup files ;; ,*) # Copy but don't list cp $fn $tgt/ ;; *) cp $fn $tgt/ files="$files $(basename $fn)" ;; esac done fi # Append keys while read answer; do echo $points $answer done < $dn/key >> $uanswers # 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 $files > $tgt/index.html done sort -n $uanswers > $outdir/answers.txt rm $uanswers