diff --git a/doc/packages.txt b/doc/packages.txt
index 90805dd..dce545c 100644
--- a/doc/packages.txt
+++ b/doc/packages.txt
@@ -4,15 +4,34 @@ CTF Packages
Packages are squashfs files.
A hypothetical package named pkgname.sfs will be mounted under
-/srv/pkgname. The following top-level files and directories are
+/opt/pkgname. The following top-level files and directories are
significant:
-* /www/ - Will appear as http://host/pkgname/, CGI can be run
-* /bin/ - Will be added to $PATH
-* /puzzles/ - Will appear as a puzzle category (see "Puzzles" below)
+* /setup - Run after package is mounted
+* /bin/ - Added to $PATH for login shells
+* /puzzles/ - Appears as a puzzle category (see "Puzzles" below)
* /answers.txt - Puzzle answers for category pkgname (see "Puzzles" below)
+setup script
+------------
+
+The setup script (if it exists and is executable) will be run from within
+the mounted directory. This is mostly so you can copy things out of your
+read-only package and into read/write areas.
+
+Don't start your service here, instead, make a new directory in
+/var/service and place a "run" script in it. More information can be found
+at .
+
+Some common actions in setup:
+
+ cp -r service/* /var/service # Install startup services
+
+ # Set up a file with ownership
+ install -o ctf -m 0644 /var/lib/ctf/whatever.db
+
+
Puzzles
-------
diff --git a/mcp/Makefile b/mcp/Makefile
index 5f2c1bb..f46402d 100644
--- a/mcp/Makefile
+++ b/mcp/Makefile
@@ -12,12 +12,14 @@ $(PACKAGE): build
cp setup $(PKGDIR)
find bin -not -name '*~' | cpio -p $(PKGDIR)
- cp src/in.tokend src/tokencli src/pointscli $(PKGDIR)/bin
+ cp src/in.tokend $(PKGDIR)/bin
+ cp src/tokencli src/pointscli $(PKGDIR)/bin
+ cp src/puzzles.cgi $(PKGDIR)/bin
find service -not -name '*~' -not -name '#*' | cpio -p $(PKGDIR)
find www -not -name '*~' -not -name '#*' | cpio -p $(PKGDIR)
- cp src/puzzler.cgi src/puzzles.cgi src/claim.cgi $(PKGDIR)/www
+ cp src/puzzler.cgi src/claim.cgi $(PKGDIR)/www
mksquashfs $(PKGDIR) $(PACKAGE) -all-root -noappend
diff --git a/mcp/bin/register b/mcp/bin/register
index efdaecc..6be7af6 100755
--- a/mcp/bin/register
+++ b/mcp/bin/register
@@ -5,10 +5,15 @@ if [ $# -ne 1 ]; then
exit 64
fi
+escape () {
+ sed 's/&/\&/g;s/\</g;s/>/\>/g'
+}
+
# Don't overwrite files
set -C
base=${CTF_BASE:-/var/lib/ctf}
+www=${CTF_BASE:-/var/www}
# Assign a color. I spent two days selecting this color pallette for
# people with protanopia. Please don't change these colors.
@@ -45,3 +50,6 @@ echo "$1" > $base/teams/names/$hash
echo "$color" > $base/teams/colors/$hash
echo "Registered with hash: $hash"
+
+# Write teams.html if it's an actual contest
+/opt/mcp/bin/teams.sh > $www/teams.html.new && mv $www/teams.html.new $www/teams.html
diff --git a/mcp/bin/run-ctf b/mcp/bin/run-ctf
index 89c7295..0d7e4ff 100755
--- a/mcp/bin/run-ctf
+++ b/mcp/bin/run-ctf
@@ -10,17 +10,6 @@ STATE=${CTF_BASE:-/var/lib/ctf}
NEWPOINTS=$STATE/points.new
POINTS=$STATE/points.log
SCOREBOARD=$WWW/scoreboard.html
-PUZZLES=$WWW/puzzles.html
-TEAMS=$WWW/teams.html
-
-install -u ctf -m 0644 /dev/null $STATE/tokens.db
-install -u ctf -m 0644 /dev/null $STATE/claim.db
-install -u root -m 0644 /dev/null $POINTS
-
-install -u ctf -d $NEWPOINTS
-install -u root -d $STATE/teams/names
-install -u root -d $STATE/teams/colors
-install -u root -d $STATE/token.keys
if ! [ -f $SCOREBOARD ]; then
$BIN/scoreboard < $POINTS > $SCOREBOARD
@@ -42,16 +31,6 @@ while true; do
$BIN/scoreboard < $POINTS > $SCOREBOARD.new && mv $SCOREBOARD.new $SCOREBOARD
fi
- # Render puzzles list
- if [ $STATE/puzzler.db -nt $PUZZLES ]; then
- $WWW/puzzles.cgi > $PUZZLES.new && mv $PUZZLES.new $PUZZLES
- fi
-
- # Render team names
- if [ $STATE/teams/names -nt $TEAMS ]; then
- $BIN/teams.sh > $TEAMS.new && mv $TEAMS.new $TEAMS
- fi
-
now=$(date +%s)
if [ $now -lt $next ]; then
sleep $(expr $next - $now)
diff --git a/mcp/bin/scoreboard b/mcp/bin/scoreboard
index 4d39475..bacb3cf 100755
--- a/mcp/bin/scoreboard
+++ b/mcp/bin/scoreboard
@@ -66,7 +66,7 @@ function output( t, c) {
BEGIN {
base = ENVIRON["CTF_BASE"]
if (! base) {
- base = "/srv/ctf"
+ base = "/var/lib/ctf"
}
# Only display two decimal places
@@ -101,13 +101,19 @@ BEGIN {
# Get team colors and names
for (team in teams) {
- fn = base "/teams/colors/" team
- getline colors_by_team[team] < fn
- close(fn)
+ # Busybox awk segfaults if you try to close a file that didn't
+ # exist. We work around it by calling cat.
+ cmd = sprintf("cat %s/teams/colors/%s", base, team)
+ cmd | getline color
+ if (! color) color = "cccccc";
+ colors_by_team[team] = color
+ close(cmd)
- fn = base "/teams/names/" team
- getline names_by_team[team] < fn
- close(fn)
+ cmd = sprintf("cat %s/teams/names/%s", base, team)
+ cmd | getline name
+ if (! name) name = team
+ names_by_team[team] = name
+ close(cmd)
}
# Sort categories
diff --git a/mcp/bin/teams.sh b/mcp/bin/teams.sh
index 08985e9..cabafe1 100755
--- a/mcp/bin/teams.sh
+++ b/mcp/bin/teams.sh
@@ -1,6 +1,6 @@
#! /bin/sh
-cd /var/lib/ctf/teams/names
+cd ${CTF_BASE:-/var/lib/ctf}/teams/names
escape () {
sed 's/&/\&/g;s/\</g;s/>/\>/g'
@@ -21,7 +21,7 @@ EOF
echo "
"
echo "Team Name | Token |
"
-for i in ??????; do
+for i in *; do
echo ""
escape < $i
echo " | $i |
"
@@ -32,4 +32,4 @@ cat <Use your team's token to claim points.