2015-04-10 16:37:21 -06:00
|
|
|
#! /bin/sh
|
|
|
|
|
2016-09-21 10:14:13 -06:00
|
|
|
if [ -n "$1" ]; then
|
|
|
|
cd $1
|
|
|
|
else
|
|
|
|
cd $(dirname $0)/..
|
|
|
|
fi
|
|
|
|
basedir=$(pwd)
|
2015-04-10 16:37:21 -06:00
|
|
|
|
2017-07-14 16:56:09 -06:00
|
|
|
[ -n "$DEBUG" ] && printf "Updating moth instance in %s\n" $(pwd)
|
2017-02-05 16:42:41 -07:00
|
|
|
|
2015-04-10 16:37:21 -06:00
|
|
|
# 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/*
|
2015-04-12 11:11:15 -06:00
|
|
|
: > state/points.log
|
2015-04-21 07:59:35 -06:00
|
|
|
rm -f reset
|
2015-04-10 16:37:21 -06:00
|
|
|
fi
|
|
|
|
|
2016-09-21 10:14:13 -06:00
|
|
|
# Create a list of currently-active categories
|
|
|
|
: > state/categories.txt.new
|
|
|
|
for dn in packages/*; do
|
|
|
|
cat=${dn##packages/}
|
|
|
|
echo "$cat" >> state/categories.txt.new
|
|
|
|
done
|
|
|
|
mv state/categories.txt.new state/categories.txt
|
|
|
|
|
2015-04-10 16:37:21 -06:00
|
|
|
# Collect new points
|
|
|
|
find state/points.new -type f | while read fn; do
|
2015-06-06 21:17:55 -06:00
|
|
|
# Skip files opened by another process
|
|
|
|
lsof $fn | grep -q $fn && continue
|
|
|
|
|
|
|
|
# Skip partially written files
|
|
|
|
[ $(wc -l < $fn) -gt 0 ] || continue
|
2015-04-18 19:13:07 -06:00
|
|
|
|
2015-06-06 21:17:55 -06:00
|
|
|
# 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
|
2015-04-10 16:37:21 -06:00
|
|
|
done
|
|
|
|
|
2016-09-21 16:10:29 -06:00
|
|
|
# Generate new puzzles.json
|
|
|
|
if bin/puzzles $basedir > state/puzzles.json.new; then
|
|
|
|
mv state/puzzles.json.new state/puzzles.json
|
2015-04-10 16:37:21 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Generate new points.json
|
2016-09-21 16:10:29 -06:00
|
|
|
if bin/points $basedir > state/points.json.new; then
|
|
|
|
mv state/points.json.new state/points.json
|
2015-04-10 16:37:21 -06:00
|
|
|
fi
|