moth/packages/mcp/service/pointsd/run

52 lines
1.1 KiB
Bash
Executable File

#! /bin/sh -e
exec 2>&1
install -d /var/lib/ctf
# Create CTF user
touch /etc/group /etc/passwd
addgroup -g 56634 nogroup || true
adduser -D -S -h /var/lib/ctf -H ctf || true
# Set up base directories
NEWDIR=/var/lib/ctf/points.new
install -d /var/www
install -d /var/lib/ctf
install -o ctf -m 0755 -d $NEWDIR
install -o ctf -m 0755 -d /var/lib/ctf/points.tmp
# Make tokens database now, this is as good a time as any
TOKENS=/var/lib/ctf/tokens.db
for fn in $TOKENS /opt/*/tokens.txt; do
[ -f "$fn" ] || continue
cat $fn
done | sort | uniq > $TOKENS.new
mv $TOKENS.new $TOKENS
# Create some files
CLAIM=/var/lib/ctf/claim.db
touch $CLAIM
chown ctf $CLAIM
touch /var/lib/ctf/points.log
# Generate preliminary scoreboard
if ! [ -f /var/www/scoreboard.html ]; then
/opt/mcp/bin/scoreboard < /dev/null > /var/www/scoreboard.html
fi
if [ -x /sbin/inotifyd ]; then
exec /sbin/inotifyd ./pointsd $NEWDIR:y
fi
# Simulate inotifyd
cd $NEWDIR
while true; do
for fn in *; do
[ -f "$fn" ] || continue
./pointsd m $NEWDIR $fn
done
sleep 7
done