#!/bin/sh
#
# register - register for Duke programming contest
#
# Usage: register

address=contest@juliet.cs.duke.edu

echo Duke Internet Contest Registration

if test $# -ne 0; then
	echo Arguments ignored.
fi

echo 'Enter the name of your institution (e.g., "University of Fiji"):'
echo -n "> "
read institution

echo 'Enter the name of your team (e.g., "First Team"):'
echo -n "> "
read teamname

echo -n "Enter the name of the first team member: "
read member1

echo -n "Enter the name of the second team member (hit ENTER if none): "
read member2

echo -n "Enter the name of the third team member (hit ENTER if none): "
read member3

echo -n "Enter the name of the fourth team member (hit ENTER if none): "
read member4

echo -n "Does any member have a bachelors-level degree (y or n)? "
read graduate

if test "$graduate" = "y"; then
    echo "Does any member have a PhD degree, or "
    echo -n "has any member finished two years of grad school (y or n)? "
    read prof
    if test "$prof" = "y"; then
    	   class="III"
    elif test "$prof" = "n"; then
    	   echo -n "Are there at least two undergraduate students (y or n)? "
    	   read ugrad
    	   if test "$ugrad" = "y"; then
        	   class="II"
    	   elif test "$ugrad" = "n"; then
        	   class="III"
    	   else
    	   	  echo "Inappropriate response $ugrad"
    	   	  exit 1
    	   fi
    else
    	   echo "Inappropriate response $prof"
    	   exit 1
    fi
elif test "$graduate" = "n"; then
	class="I"
else
	echo "Inappropriate response $graduate"
	exit 1
fi

echo ""
echo "Enter the email address where you receive contest mail."
echo "It should be fully specified (eg, myname@cs.school.edu):"
echo -n "> "
read email

echo ""
echo Institution: "$institution"
echo Team name: "$teamname"
echo Your team members:
echo "  $member1"
echo "  $member2"
echo "  $member3"
echo "  $member4"
echo "Class-$class team."
echo "Email address $email"

echo ""
echo -n 'Confirm registration (type "yes" to confirm): '
read confirm

if test "$confirm" = "yes"; then
Mail -s "register92" $address << EOF
TEAMNAME $teamname
AFFILIATION $institution
NAME1 $member1
NAME2 $member2
NAME3 $member3
NAME4 $member4
CLASS $class
ADDRESS $email
EOF
    echo Team registered. Please wait for a reply in the mail,
    echo at the above email address. It may take 5-20 minutes.
    echo Be patient. Please do NOT reregister.  Do not submit
    echo any programs to be judged before you are assigned a
    echo team number.
else
	echo Not registered. Try again, perhaps.
fi

echo ""
echo "Your system clock indicates that the time is:"
echo -n "    "
# if your system doesn't generate UTC time with the following command,
# uncomment the following line and comment out the "date -u" line
#TZ=GMT0 date
date -u
echo "The contest begins when your system clock reaches:"
echo "    Tue Nov 17 23:00:00 GMT 1992"
