mirror of
https://github.com/dirtbags/moth.git
synced 2025-01-05 11:30:41 -07:00
8166469fee
TODO: neale says points should be written to state/points.tmp then be moved into state/points.new to avoid race condition (multiple processes touching the file causing the file to change risking bad data in state/points.log). It might be wise to do some validation in bin/points that tosses bad data.
40 lines
865 B
Bash
Executable file
40 lines
865 B
Bash
Executable file
#! /bin/sh
|
|
|
|
cd $(dirname $0)/..
|
|
|
|
# Do nothing if `disabled` is present
|
|
if [ -f disabled ]; then
|
|
exit
|
|
fi
|
|
|
|
# Reset to initial state if `reset` is present
|
|
if [ -f reset ]; then
|
|
rm -f state/teams/* state/points.new/* state/points.tmp/*
|
|
: > state/points.log
|
|
rm -f reset
|
|
fi
|
|
|
|
# Collect new points
|
|
find state/points.new -type f | while read fn; do
|
|
# Skip files opened by another process
|
|
lsof $fn | grep -q $fn && continue
|
|
|
|
# Skip partially written files
|
|
[ $(wc -l < $fn) -gt 0 ] || continue
|
|
|
|
# filter the file for unique awards
|
|
sort -k 4 $fn | uniq -f 1 | sort -n >> state/points.log
|
|
|
|
# Now kill the file
|
|
rm -f $fn
|
|
done
|
|
|
|
# Generate new puzzles.html
|
|
if www/cgi-bin/puzzles.cgi > www/puzzles.new; then
|
|
mv www/puzzles.new www/puzzles.html
|
|
fi
|
|
|
|
# Generate new points.json
|
|
if bin/points state/points.log > www/points.new; then
|
|
mv www/points.new www/points.json
|
|
fi
|