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

46 lines
969 B
Bash
Executable File

#! /bin/sh -e
exec 2>&1
STATE=$CTF_BASE/state
WWW=$CTF_BASE/www
# Create CTF and nobody users
touch /etc/group /etc/passwd
addgroup -g 65534 nogroup || true
adduser -DH -G nogroup -u 65534 nobody || true
adduser -DHS ctf || true
# Set up base directories
NEWDIR=$STATE/points.new
TMPDIR=$STATE/points.tmp
install -o ctf -m 0755 -d $NEWDIR
install -o ctf -m 0755 -d $TMPDIR
# Create some files
touch $STATE/points.log
# Generate preliminary scoreboard
if [ ! -f $WWW/scoreboard.html ]; then
./mkpage scoreboard < /dev/null > $WWW/scoreboard.html
fi
# Generate preliminary puzzles list
if [ ! -f $WWW/puzzles.html ]; then
./mkpage puzzles.cgi > $WWW/puzzles.html
fi
# Run pointsd every time a new points file is dropped
if [ -x /sbin/inotifyd ]; then
exec /sbin/inotifyd ./pointsd $NEWDIR:y
fi
# Simulate inotifyd by polling
while true; do
find $NEWDIR -type f | while read fn; do
./pointsd m $NEWDIR ${fn##*/}
done
sleep 7
done