moth/bin/run-ctf

37 lines
861 B
Bash
Executable File

#! /bin/sh
# First argument is seconds between running everything
period=${1:-60}
CTF_BASE=${CTF_BASE:-/srv/ctf} export CTF_BASE
POINTS=$CTF_BASE/points.log
SCOREBOARD=$CTF_BASE/www/scoreboard.html
PUZZLES=$CTF_BASE/www/puzzles.html
while true; do
start=$(date +%s)
next=$(expr $start + $period)
# Collect any new points
for fn in $CTF_BASE/points.new/*; do
[ -f $fn ] || continue
cat $fn >> $POINTS || break
rm $fn
done
if [ $POINTS -nt $SCOREBOARD ]; then
$CTF_BASE/sbin/scoreboard < $POINTS > $SCOREBOARD.new
mv $SCOREBOARD.new $SCOREBOARD
fi
if [ $CTF_BASE/puzzler.db -nt $PUZZLES ]; then
$CTF_BASE/sbin/puzzles.cgi > $PUZZLES.new
mv $PUZZLES.new $PUZZLES
fi
now=$(date +%s)
if [ $now -lt $next ]; then
sleep $(expr $next - $now)
fi
done