moth/packages/00common/service/pointsd/pointsd

44 lines
931 B
Plaintext
Raw Normal View History

#! /bin/sh -e
fn=$2/$3
2012-07-22 17:14:06 -06:00
PACKAGES=$CTF_BASE/packages
STATE=$CTF_BASE/state
WWW=$CTF_BASE/www
2012-07-22 17:14:06 -06:00
POINTS=$STATE/points.log
BACKUP=$WWW/backup.png
SCOREBOARD=$WWW/scoreboard.html
PUZZLES=$WWW/puzzles.html
# Only do this if this score hasn't yet been recorded
if [ -n "$(sort -k2 $POINTS $fn | uniq -f1 -d)" ]; then
exit
fi
# Append point. pointsd is called serially from inotify,
# so we don't need to lock it.
cat $fn >> $POINTS
rm $fn
# Generate new backup if we can find a password file
2012-07-22 17:14:06 -06:00
for pwfile in $PACKAGES/*/password; do
if [ -f $pwfile ]; then
(
cat bkup.png
2012-07-22 17:14:06 -06:00
tar cf - $STATE | gzip -c | $PACKAGES/*/bin/tea 3< $pwfile
) > $BACKUP.new
mv $BACKUP.new $BACKUP
break
fi
done
# Render scoreboard
./mkpage scoreboard < $POINTS > $SCOREBOARD.new
mv $SCOREBOARD.new $SCOREBOARD
# Render puzzles list
./mkpage puzzles.cgi > $PUZZLES.new
mv $PUZZLES.new $PUZZLES