#!/bin/bash # Copyright (c) Gene Cooperman 2001, 2004 # Permission to use is freely granted as long as this copyright notice remains. # This software has no warranty. if test "$1" = ""; then echo "USAGE: "`basename $0` FILE echo " (USAGE for instructor): "`basename $0`' [--create | --is-late]' echo " Rename this script to submit-COURSE-hwWHICH." echo " For example, submit-csu660-hw2 will" echo " create and manage /net/course/csu660/hw2.handin" echo " Similarly, submit-csg389-hw1-sect1 will" echo " create and manage /net/course/csu389/hw1-sect1.handin" exit 0 fi # Directories: /net/course/$course/$hw.handin # /net/course/$course/$hw.handin-late # where $course and $hw are numbers, e.g.: /net/course/csu215/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-hwHW_NUM-..." # exit 1 # fi # course_alt=1355 # course=1130-2 hw=hw`basename $0 | sed -e 's%^.*-hw%%'` dir=/net/course/$course/$hw.handin #Obsolete: delete later # 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=/net/course/$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-$course-hw$num" = `basename $0`; then # echo "Internal error. Please report to instructor." # exit 1 # fi # Handle --create if test "$1" = --create; then echo "Creating $hw.handin and initializing with correct permissions" if test ! -r /net/course/$course/$hw.handin; then mkdir /net/course/$course/$hw.handin chmod go-r,go+wx,+t /net/course/$course/$hw.handin elif test ! -d /net/course/$course/$hw.handin; then echo "$hw.handin already exists and is not a directory" else echo "$hw.handin already exists" fi if ypcat group | grep $course: > /dev/null; then echo "Setting group permission for group $course" if test -r /net/course/$course/$hw.handin; then chgrp $course /net/course/$course/$hw.handin chmod g+rwx /net/course/$course/$hw.handin fi fi exit 0 fi # Handle --is-late if test "$1" = --is-late; then echo "Creating $hw.handin-late and modifying permissions" if test ! -r /net/course/$course/$hw.handin-late; then mkdir /net/course/$course/$hw.handin-late chmod go-wx,-t /net/course/$course/$hw.handin chmod go-r,go+wx,+t /net/course/$course/$hw.handin-late elif test ! -d /net/course/$course/$hw.handin-late; then echo "$hw.handin-late already exists and is not a directory" else echo "$hw.handin-late already exists; changing permissions only" chmod go-wx,-t /net/course/$course/$hw.handin chmod go-r,go+wx,+t /net/course/$course/$hw.handin-late fi if ypcat group | grep $course: > /dev/null; then if test -r /net/course/$course/$hw.handin-late; then chgrp $course /net/course/$course/$hw.handin-late chmod g+rwx /net/course/$course/$hw.handin-late chgrp $course /net/course/$course/$hw.handin chmod g+rwx /net/course/$course/$hw.handin fi fi exit 0 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