#! /bin/sh BASE=/tmp/p2 mkdir -p $BASE if ! [ -f $BASE/nonce ]; then dd if=/dev/urandom count=1 | md5sum - > $BASE/nonce fi clear read nonce < $BASE/nonce esc () { printf '%s' "$*" | sed 's/[^-0-9A-Za-z ]/_/g; s/ /+/g' } newteam () { echo '== Team Creation ==' echo echo -n 'What would you like your team to be called (3-12 chars)? ' read -r name echo namelen=$(printf "%s" "$name" | wc -c) if [ $namelen -lt 3 ] || [ $namelen -gt 12 ]; then echo 'Invalid name length' return fi hash=$(printf '%s %s' "$nonce" "$name" | md5sum | cut -b 1-8) if [ -d $BASE/$hash ]; then echo "That name is already in use. Try another one." return fi mkdir $BASE/$hash printf '%s' "$name" > $BASE/$hash/.name cat < ' read -r answer match=$(awk -v ans="$answer" '(substr($0, length($1)+2) == ans) { print substr(FILENAME, 6, length(FILENAME)-17) " " $1; }' /opt/*/answers.txt) cat=${match% *} points=${match#* } fn=$BASE/$hash/$cat.$points if [ -f $fn ]; then echo "You've already received points for this answer." else printf "%s %s\n" $cat $points > $fn echo "You get $points more points in the $cat category." # run puzzles.cgi # update scoreboard echo "Check the puzzles overview for newly-unlocked content!" fi done