#!/bin/bash

CVS_RSH=/usr/bin/ssh
CVSROOT=:ext:turing.cs.gettysburg.edu:/Courses/cvsroot
CVS=/usr/bin/cvs

#check command line arguments
if [ $# != 4 ]
    then
        echo "Usage: cvscollect course project userFile dest" 1>&2
        echo "   course: csXXX" 1>&2
        echo "   project: which submission to download" 1>&2
        echo "   userFile: a file containing the user names" 1>&2
	echo "   dest: a destination directory" 1>&2
        exit 1
fi

#make sure the user file is readable
if [ ! -r "$3" ]
    then
      echo "User file $3 is unreadble." 1>&2
      exit 1
fi
#download each via CVS
#cat "$3" |
FILES=" "
while read line
do
    #echo "${1}/${line}/${2} "
    FILES="${FILES} ${1}/${line}/${2} "
done < "$3"
#echo $FILES
$CVS -d $CVSROOT get -d $4 $FILES
