#!/bin/sh
#
#set -x
FIRSTCAP=/home/m1/bellenot/gb/firstcap
CODEWORD=/home/m1/bellenot/gb/codeword
MAKEFILE=/home/m1/bellenot/gb/Makefile.in
GB=/home/m1/bellenot/gb/gb.sh
echo "this will create a directory gb and install the gradebook"
echo "type any character to continue, ^C to exit"
read trash
if [ -d gb ] ; then
	echo "gb already exits"
	exit 1;
fi
if [ ! -d gb ] ; then
	mkdir gb
fi
cd gb
echo "enter the class in the roster form xyz4321.01"
read CLASS
if [ ! -f /home/m1/rosters/pub/$CLASS ] ; then
	echo "I don't see $CLASS"
	exit 1;
fi
echo "enter the full path to the html directory like /home/..../cal3/gb"
read URL
if [ ! -d $URL ] ; then
	mkdir -p $URL
fi
chmod 711 $URL
if [ ! -d $URL ] ; then
	echo "can't create $URL"
	exit 1;
fi
$FIRSTCAP </home/m1/rosters/pub/$CLASS >roll0
N=`wc -l roll0 | awk '{print $1}'`
$CODEWORD $N >temp
M=`sort temp | uniq | wc -l | awk '{print $1}'`
while [ $N -ne $M ] ;
do
	$CODEWORD $N >temp
	M=`sort temp | uniq | wc -l | awk '{print $1}'`
done
paste -d" " temp roll0 > codes
sed -e 's/^.*$/0/' roll0 > zeros
echo "Attend,\"Points\"" > attend.csv
paste -d, roll0 zeros >> attend.csv
echo "Grade,\"Points\"" > grade.csv
paste -d, roll0 zeros >> grade.csv
echo "Quizzes,\"Points\"" > quiz.csv
paste -d, roll0 zeros >> quiz.csv
echo "Projects,\"Points\"" > proj.csv
paste -d, roll0 zeros >> proj.csv
echo "Test,\"Points\"" > test.csv
paste -d, roll0 zeros >> test.csv
CODE=`head -1 codes | awk '{print $1}'`
sed -e s/Kowb/$CODE/ -e "s;URL;$URL;" $MAKEFILE >Makefile
cp $GB .
make fake-update
make 
make install
