#!/bin/bash # Copyright (c) Gene Cooperman 2001 # Permission to use is freely granted as long as this copyright notice remains. # This software has no warranty. # Directories: /course/com$course/$hw.handin # /course/com$course/$hw.handin-late # where $course and $hw are numbers, e.g.: /course/com3200/hw3.handin # Set handin directory to: go-r,go+wx,+t # For example: chmod go-r,go+wx,+t hw3.handin # When a homework is late, set handin directory to: go-wx,-t # and set handin-late directory to: go-r,go+wx,+t # One can do this automatically as: (sleep XXX; chmod ...) # if you trust the computer to stay up. # Script will guess homework num based on name: submit-$course-hw#-... # e.g.: change name to: submit-1100-hw4 for hw4 of com1100 # Currently only guesses hw# and nothing else. course=`basename $0 | sed -e 's%^submit-%%' | sed -e 's%-.*%%'` if test $course -lt 100 -o $course -gt 9999; then echo "Can't find correct course number." echo " expecting script with name: submit-COURSE_NUM-hwHW_NUM-..." exit 1 fi # course_alt=1355 # course=1130-2 # hw=hw1 num=`basename $0 | sed -e 's%^.*-hw%%' | sed -e 's%-.*%%'` if test -z "$hw" -a $num -ge 1 -a $num -le 9; then hw=hw$num dir=/course/com$course/$hw.handin else echo "Can't find correct hw number." echo " expecting script with name: submit-$course-hw#-..." exit 1 fi if test "submit-com$course-hw$num" = `basename $0`; then echo "Internal error. Please report to instructor." exit 1 fi if test ! -w $dir -a -d ${dir}-late; then dir=${dir}-late echo "" echo "This homework appears to be late." echo " It will be submitted to $dir ." echo "If the homework is in fact on time, please speak to the" echo " instructor about a bug in this script." fi if test $# != 1; then echo "" echo Usage: $0 FILENAME echo " Places user file in $dir/USERNAME-FILENAME.RANDOM" echo " where RANDOM makes it difficult for others to find the file" echo " The preferred format for FILENAME is: FILE.tar.gz" echo "" exit 1 fi from_file=$1 to_file=$dir/`whoami`-`basename $from_file`.$RANDOM$RANDOM if test ! -f $from_file; then echo "Sorry. I can't find the file: $from_file" echo "Please try again." fi echo "" echo "If your file is successfully submitted, you will see" echo " a confirmation message at the end of this command." echo "" if cp $from_file $to_file; then chmod go+r $to_file echo "Your file, $from_file, has been successfully submitted" echo " as file: $to_file" echo "" echo "If you change your mind, you can delete the file by doing:" echo " rm $to_file" echo "" # echo "Please remember to bring hardcopy of your program output" # echo " to hand in during class." echo "" else echo "Unable to copy from $from_file to $to_file" echo "Please check that the file exists: ls -l $from_file" echo "" echo "If you still have problems, please speak to the instructor." echo "" exit 1 fi