From 9b94c2b1f0e830b0fd4fddd80683c610156a91fa Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 12 Oct 2017 00:55:34 +0000 Subject: [PATCH] Move assigned.txt into state --- Dockerfile.moth | 5 +---- bin/once | 25 +++++++++++++++++++------ docs/overview.md | 2 +- www/cgi-bin/koth.lua | 2 +- www/cgi-bin/register.cgi | 2 +- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Dockerfile.moth b/Dockerfile.moth index 533919e..bf7f5ee 100644 --- a/Dockerfile.moth +++ b/Dockerfile.moth @@ -2,14 +2,11 @@ FROM neale/eris RUN apk --no-cache add lua5.2 RUN apk --no-cache add lua5.3 +RUN ln -s lua5.2 /usr/bin/lua # Install MOTH. This could be less obtuse. COPY www /moth/www COPY bin /moth/bin -RUN mkdir -p /moth/state/teams /moth/state/points.new /moth/state/points.tmp -RUN chown www:www /moth/state/teams /moth/state/points.new /moth/state/points.tmp -RUN mkdir -p /moth/packages -RUN touch /moth/state/points.log RUN ln -s ../state/puzzles.json /moth/www/puzzles.json RUN ln -s ../state/points.json /moth/www/points.json diff --git a/bin/once b/bin/once index af4d152..c218aed 100755 --- a/bin/once +++ b/bin/once @@ -13,16 +13,19 @@ log () { # Do nothing if `disabled` is present if [ -f disabled ]; then - log "Instance disabled: doing nothing" + log "Instance disabled; doing nothing" exit fi -# Reset to initial state if `reset` is present -if [ -f reset ]; then - log "Resetting state" - rm -f state/teams/* state/points.new/* state/points.tmp/* +# Reset to initial state? +if [ ! -f state/initialized ]; then + log "Resetting contest state" + + rm -rf state/teams state/points.new state/points.tmp + mkdir -p state/teams state/points.new state/points.tmp + chown www:www state/teams state/points.new state/points.tmp # Needs root. Use Docker. : > state/points.log - rm -f reset + echo 'Remove this file to obliterate teams and points' > state/initialized fi # Create some team names if needed @@ -31,6 +34,16 @@ if [ ! -f state/assigned.txt ]; then hd state/assigned.txt fi +# Install new categories +for pkg in puzzles/*; do + cat=$(basename $pkg .zip) + if [ ! -f packages/$cat/installed ] || [ $pkg -nt packages/$cat/installed ]; then + log "Installing $pkg" + bin/install-category $pkg + : >packages/$cat/installed + fi +done + # Helpful error message if [ $(ls packages | wc -l) -eq 0 ]; then log "error: No packages installed" diff --git a/docs/overview.md b/docs/overview.md index 4403eaf..94d2885 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -85,7 +85,7 @@ There are five entries in each instance directory, described in detail below: -`assigned.txt` +`state/assigned.txt` ---------------- This is just a list of tokens that have been assigned. diff --git a/www/cgi-bin/koth.lua b/www/cgi-bin/koth.lua index 412d1b9..ad83c9b 100644 --- a/www/cgi-bin/koth.lua +++ b/www/cgi-bin/koth.lua @@ -98,7 +98,7 @@ end -- Traverse up to find assigned.txt for i = 0, 5 do - local f = io.open(koth.path("assigned.txt")) + local f = io.open(koth.path("state/assigned.txt")) if (f) then f:close() break diff --git a/www/cgi-bin/register.cgi b/www/cgi-bin/register.cgi index c1ca49d..7017016 100755 --- a/www/cgi-bin/register.cgi +++ b/www/cgi-bin/register.cgi @@ -13,7 +13,7 @@ hash = hash:match("[0-9a-f]*") if ((hash == "") or (team == "")) then koth.page("Invalid Entry", "Oops! Are you sure you got that right?") -elseif (not koth.anchored_search(koth.path("assigned.txt"), hash)) then +elseif (not koth.anchored_search(koth.path("state/assigned.txt"), hash)) then koth.page("Invalid Hash", "Oops! I don't have a record of that hash. Did you maybe use capital letters accidentally?") end