2010-09-23 18:23:00 -06:00
|
|
|
#! /bin/sh
|
|
|
|
|
|
|
|
# First argument is seconds between running everything
|
|
|
|
period=${1:-60}
|
|
|
|
|
2012-07-22 17:14:06 -06:00
|
|
|
packages=$CTF_BASE/packages
|
|
|
|
state=$CTF_BASE/state
|
|
|
|
www=$CTF_BASE/www
|
2010-09-23 18:23:00 -06:00
|
|
|
|
2012-07-22 17:14:06 -06:00
|
|
|
BIN=$packages/mcp/bin
|
|
|
|
|
|
|
|
NEWPOINTS=$state/points.new
|
|
|
|
POINTS=$state/points.log
|
|
|
|
SCOREBOARD=$www/scoreboard.html
|
2010-09-23 19:11:52 -06:00
|
|
|
|
2010-09-23 18:23:00 -06:00
|
|
|
if ! [ -f $SCOREBOARD ]; then
|
|
|
|
$BIN/scoreboard < $POINTS > $SCOREBOARD
|
2010-09-23 19:11:52 -06:00
|
|
|
fi
|
2010-09-23 18:23:00 -06:00
|
|
|
|
|
|
|
while true; do
|
|
|
|
start=$(date +%s)
|
|
|
|
next=$(expr $start + $period)
|
|
|
|
|
|
|
|
# Collect any new points
|
|
|
|
for fn in $NEWPOINTS/*; do
|
|
|
|
[ -f $fn ] || continue
|
|
|
|
cat $fn >> $POINTS || break
|
|
|
|
rm $fn
|
|
|
|
done
|
|
|
|
|
|
|
|
# Render scoreboard
|
|
|
|
if [ $POINTS -nt $SCOREBOARD ]; then
|
2010-09-23 19:11:52 -06:00
|
|
|
$BIN/scoreboard < $POINTS > $SCOREBOARD.new && mv $SCOREBOARD.new $SCOREBOARD
|
2010-09-23 18:23:00 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
now=$(date +%s)
|
|
|
|
if [ $now -lt $next ]; then
|
|
|
|
sleep $(expr $next - $now)
|
|
|
|
fi
|
|
|
|
done
|