moth/packages/mcp/bin/addteam

59 lines
1.3 KiB
Bash
Executable File

#! /bin/sh -e
if [ $# -ne 1 ]; then
echo "Usage: $0 TEAM" 1>&2
exit 64
fi
escape () {
sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g'
}
# Don't overwrite files
set -C
STATE=$CTF_BASE/state
WWW=$CTF_BASE/www
mkdir -p $STATE/teams/names
mkdir -p $STATE/teams/colors
if ! [ -f $STATE/teams/salt ]; then
dd if=/dev/urandom count=1 2>/dev/null | md5sum | cut -b 1-8 > $STATE/teams/salt
fi
salt=$(cat $STATE/teams/salt)
# Assign a color. I spent weeks selecting a color pallette that
# wouldn't be hell on people with protanopia. Please don't change these
# colors.
nteams=$(ls $STATE/teams/names/ | wc -l)
case $(expr $nteams % 10) in
0) color=a6cee3;;
1) color=1f78b4;;
2) color=b2df8a;;
3) color=33a02c;;
4) color=fb9a99;;
5) color=e31a1c;;
6) color=fdbf6f;;
7) color=ff7f00;;
8) color=cab2d6;;
9) color=6a3d9a;;
*)
echo 'ERROR ERROR' 1>&2
echo 'DOES NOT COMPUTE' 1>&2
exit 69
;;
esac
# Compute hash of team name; they'll use this for everything in the
# contest instead of their team name, which makes stuff much easier on
# me since all team hashes are in the set /[0-9a-f]{8}/.
hash=$(printf "%s:%s" $salt "$1" | md5sum | cut -b 1-8)
echo "$1" > $STATE/teams/names/$hash
echo "$color" > $STATE/teams/colors/$hash
echo "Registered with hash: $hash"