2010-09-24 17:24:43 -06:00
|
|
|
#! /bin/sh -e
|
|
|
|
|
2010-10-22 11:04:04 -06:00
|
|
|
set -e
|
|
|
|
|
2010-09-24 17:24:43 -06:00
|
|
|
indir=$1; shift
|
|
|
|
outdir=$1; shift
|
|
|
|
|
2011-03-24 17:12:33 -06:00
|
|
|
die () {
|
|
|
|
echo "$@" 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2010-09-24 17:24:43 -06:00
|
|
|
escape () {
|
|
|
|
sed 's/&/\&/g;s/</\</g;s/>/\>/g'
|
|
|
|
}
|
|
|
|
|
|
|
|
template () {
|
|
|
|
cat="$1"; shift
|
|
|
|
points="$1"; shift
|
2011-03-24 17:12:33 -06:00
|
|
|
author=$(echo $1 | escape); shift
|
2010-09-24 17:24:43 -06:00
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>$cat $points</title>
|
|
|
|
<link rel="stylesheet" href="/ctf.css" type="text/css">
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<h1>$cat for $points points</h1>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo " <div class=\"readme\">"
|
|
|
|
cat
|
|
|
|
echo " </div>"
|
|
|
|
|
|
|
|
if [ $# -gt 0 ]; then
|
|
|
|
echo " <p>Associated files:</p>"
|
|
|
|
echo " <ul>"
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
fn="$1"; shift
|
|
|
|
efn="$(echo $fn | escape)"
|
|
|
|
echo " <li><a href=\"$fn\">$efn</a></li>"
|
|
|
|
done
|
|
|
|
echo " </ul>"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat <<EOF
|
2010-11-01 17:05:14 -06:00
|
|
|
<form action="/puzzler.cgi" method="post" accept-charset="utf-8">
|
2010-09-24 17:24:43 -06:00
|
|
|
<input type="hidden" name="c" value="$cat">
|
|
|
|
<input type="hidden" name="p" value="$points">
|
2011-01-06 08:43:40 -07:00
|
|
|
Team hash:<input name="t" size="8">
|
2010-09-24 17:24:43 -06:00
|
|
|
Answer:<input name="a" size="20">
|
|
|
|
<input type="submit" value="submit">
|
|
|
|
</form>
|
2011-03-24 17:12:33 -06:00
|
|
|
<address>Puzzle by $author</address>
|
2010-09-24 17:24:43 -06:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
cat=$(basename $indir)
|
|
|
|
uanswers=$outdir/answers.unsorted
|
2010-10-25 11:15:12 -06:00
|
|
|
usummary=$outdir/summary.unsorted
|
2010-09-24 17:24:43 -06:00
|
|
|
|
2010-10-25 11:15:12 -06:00
|
|
|
echo -n > $uanswers
|
|
|
|
rm -f $usummary
|
2010-09-24 17:24:43 -06:00
|
|
|
|
|
|
|
for dn in $indir/[0-9]*; do
|
|
|
|
[ -d $dn ] || continue
|
|
|
|
points=$(basename $dn)
|
|
|
|
|
|
|
|
echo $dn
|
|
|
|
|
|
|
|
tgt=$outdir/puzzles/$points
|
|
|
|
mkdir -p $tgt
|
2011-03-04 19:43:02 -07:00
|
|
|
touch $tgt/index.html
|
2010-09-24 17:24:43 -06:00
|
|
|
|
2010-10-12 16:58:34 -06:00
|
|
|
if [ -f $dn/Makefile ]; then
|
2011-03-25 16:22:17 -06:00
|
|
|
# If there's a Makefile, run make
|
|
|
|
make -C $dn || exit 1
|
2010-10-12 16:58:34 -06:00
|
|
|
files=$(cd $tgt; echo *)
|
2011-03-25 16:22:17 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f $dn/@manifest.txt ]; then
|
|
|
|
# If there's a manifest, use that
|
|
|
|
files=$(cat $dn/@manifest.txt)
|
2010-10-12 16:58:34 -06:00
|
|
|
else
|
|
|
|
# Otherwise, look for special files and copy the rest
|
|
|
|
files=
|
|
|
|
for fn in $dn/*; do
|
|
|
|
case $(basename $fn) in
|
2011-03-24 17:12:33 -06:00
|
|
|
@*)
|
2011-03-25 16:22:17 -06:00
|
|
|
# Handle meta-information later
|
2010-10-12 16:58:34 -06:00
|
|
|
;;
|
|
|
|
*~|"#"*)
|
2011-03-25 16:22:17 -06:00
|
|
|
# Don't copy temporary or backup files
|
2010-10-12 16:58:34 -06:00
|
|
|
;;
|
|
|
|
,*)
|
2011-03-25 16:22:17 -06:00
|
|
|
# Copy but don't list
|
2011-03-03 10:41:05 -07:00
|
|
|
ln -f $fn $tgt/
|
2010-10-12 16:58:34 -06:00
|
|
|
;;
|
|
|
|
*)
|
2011-03-03 10:41:05 -07:00
|
|
|
ln -f $fn $tgt/
|
2010-10-12 16:58:34 -06:00
|
|
|
files="$files $(basename $fn)"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2011-03-24 17:12:33 -06:00
|
|
|
# Append answers
|
|
|
|
if [ -f $dn/@answer.txt ]; then
|
|
|
|
awk -v P=$points '/./ { printf("%d %s\n", P, $0); }' < $dn/@answer.txt >> $uanswers
|
2010-10-25 15:52:18 -06:00
|
|
|
else
|
2011-03-24 17:12:33 -06:00
|
|
|
die "$dn/@answer.txt: No such file or directory"
|
2010-10-22 11:04:04 -06:00
|
|
|
fi
|
2010-10-25 11:15:12 -06:00
|
|
|
|
|
|
|
# Append summary
|
2011-03-24 17:12:33 -06:00
|
|
|
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."
|
2010-10-25 15:52:18 -06:00
|
|
|
fi
|
2010-09-24 17:24:43 -06:00
|
|
|
|
|
|
|
# Generate index now that we have a list of files
|
2011-03-24 17:12:33 -06:00
|
|
|
if [ -f $dn/@index.mdwn ]; then
|
|
|
|
markdown --html4tags $dn/@index.mdwn
|
|
|
|
fi | template $cat $points "$author" $files > $tgt/index.html
|
2010-09-24 17:24:43 -06:00
|
|
|
done
|
|
|
|
|
|
|
|
sort -n $uanswers > $outdir/answers.txt
|
2010-10-25 11:15:12 -06:00
|
|
|
[ -f $usummary ] && sort -ns $usummary > $outdir/summary.txt
|
|
|
|
rm -f $uanswers $usummary
|