#!/bin/sh # Fritz Sieker # set -x # Simple script to produce a number of files from CSV class list(s). # # The files produced include: # $CheckinDir/users - used by the checkin program # $CheckinDir/assignments - used by the checkin program # $CheckinDir/allLogins # $CheckinDir/mapCStoRamCT # $CheckinDir/*.login (one for each file passed to script) # $CheckinDir/*.map (one for each file passed to script) # # The script can work with files from two sources: # # AREISWeb file(s) - use the export CSV file to save the class list # "Legal Name" (contains last, first), "eName" (columns of interest) # 4th line contains column names # data starts at 5th line # # RamCT file(s) - export (at a minimum) the following columns # "Last Name" "First Name", and Username" (columns of interest) # 1st line of file contains column names # data starts at 2nd line # #------------------------------------------------------------------------ usage() { echo "Usage: genUsers [AW | RamCT] classListFile1 [classListFile2 ...]" echo echo "Ex: makeUsers AW CS-161-001.csv CS-161-002.csv" exit 1 } #------------------------------------------------------------------------ makeHeader() { cat << @endOfUsersHeader # Put usernames, one per line, in this file # Usernames listed here will be allowed to # Run the checkin/peek/etc.. programs # So, this file should contain the usernames # of people in the class! # # If for whatever reason, you want to allow # EVERYONE to submit files, just put a line # in this file with the word EVERYONE # It must be on the line by itself, and be in # all capitals. Add instructor, TA's for logins convenientce # put logins for TA's, etc above this line @endOfUsersHeader } #------------------------------------------------------------------------ genAssignmentsFile() { cat << @$endOfAssignHeader # Each line of this file should contain a name # of an assignment and three dates/times # the dates/times are optional # The first date is the date a homework is assigned # students will not be able to turn it in before this date. # The second date is the due-date # students will be given a warning telling them that the # Assignment is late if they try to turn an assignment # after this date, but they will be allowed to turn it in. # and the assignment name will be prefixed with "LATE_" # The final date is the drop-dead date # students will NOT be allowed to turn it in after this date. # Dates are of the form MM/DD/YYYY@hh:mm:ss # hh is in the range 0 - 23 (Hours after midnight) # mm and ss are in the range 0 - 59 # hh mm and ss are all optional, and will be 0 if omited # which would be midnight (0:0:0) # For example: # HW3 8/8/2005@9:50 8/12/2005@9 8/13/2005 # Means that 'HW3' was assigned on Mon Aug 8, 2005 at 9:50 am # (monday after class) # and is due on Friday Aug 12 at 9am (at the beginning of class) # but can be turned in at any point before Sat the 13th # so, Friday night at 11:59:59 is the latest that it would be accepted. # # If you leave the dates off, then no date-checking will be done for # that assignment. For example: # HW0 # Means that there is an assignment which can be turned in at *any* time @$endOfAssignHeader } #----------------------------------------------------------------------------- # simple linear search for name getColNum() { colName="$1" colNum=`awk -F, '{print NF}' $hdrFile` while [ $colNum -gt 0 ] do nthCol=`cut -d, -f$colNum $hdrFile` if [ "X$colName" = "X$nthCol" ] then break; fi colNum=`expr $colNum - 1` done echo $colNum } #----------------------------------------------------------------------------- # get info from a section/class file processOneFile() { csvFile=$1 echo "processing file: $csvFile" rm -f $tmpFile1 $tmpFile2 head -n $nameLineNum $csvFile | tail -n 1 | sed -s 's/\"//g' > $hdrFile lastNameColNum=`getColNum "$lastNameColName"` firstNameColNum=`getColNum "$firstNameColName"` idColNum=`getColNum "$idColName"` # In AriewWeb, format of "Full Name" is: "LastName, FirstName MiddleName" if [ $type = "AW" ] then firstNameColNum=`expr $lastNameColNum + 1` idColNum=`expr $idColNum + 1` fi # line where actual data begins dataLine=`expr $nameLineNum + 1` #columns containing lastName, firstName, ID getCols="-f$lastNameColNum,$firstNameColNum,$idColNum" tail -n +$dataLine $csvFile | cut -d, $getCols | sed -s 's/\"//g' > $tmpFile1 while read line do lastName=`echo $line | cut -d, -f1` firstName=`echo $line | cut -d, -f2` # next line necessary because AriewWeb has middle name as well firstName=`echo $firstName | cut -d' ' -f1` id=`echo $line | cut -d, -f3` # now try to get cs login finger $lastName | fgrep Login | fgrep -i -w $firstName > $tmpFile2 if [ $? -ne 0 ] then login="UNKNOWN" echo "unknown CS user: $lastName, $firstName" else numUsers=`wc -l $tmpFile2 | cut -d' ' -f1` if [ $numUsers -eq 1 ] then login=`cut -d' ' -f2 $tmpFile2` else login=AMBIGUOUS echo "AMBIGUOUS: $lastName, $firstName" fi fi echo "$login" >> $loginNames echo "$login,$id" >> $mapNames done < $tmpFile1 } #------------------------------------------------------------------------ if [ $# -lt 2 ] then usage fi if [ -z "$CheckinDir" ] then CheckinDir=~/Checkin fi type=$1 shift case $type in AW) lastNameColName="Legal Name" firstNameColName="Legal Name" idColName="eName" nameLineNum=4 ;; RamCT) lastNameColName="Last Name" firstNameColName="First Name" idColName="Username" nameLineNum=1 ;; *) usage ;; esac usersFile=$CheckinDir/users tmpFile1=tmp1$$ tmpFile2=tmp2$$ hdrFile=header while [ $# -gt 0 ] do csvFile=$1 bName=`basename $csvFile .csv` loginNames=$CheckinDir/${bName}.login mapNames=$CheckinDir/${bName}.map touch $loginNames $mapNames processOneFile $csvFile chmod 600 $loginNames $mapNames shift done # create summary Files allFile=$CheckinDir/allLogins cat $CheckinDir/*.login | sort -u > $allFile chmod 600 $allFile mapFile=$CheckinDir/mapCStoRamCT echo "Login,User ID" > $mapFile cat $CheckinDir/*.map | sort -u >> $mapFile chmod 600 $mapFile makeHeader > $usersFile cat $CheckinDir/allLogins >> $usersFile chmod 644 $usersFile assignFile=$CheckinDir/assignments genAssignmentsFile > $assignFile chmod 600 $assignFile rm -f $tmpFile1 $tmpFile2