#! /bin/tcsh -f # Last edited on 2007-03-14 18:47:42 by stolfi set usage = "$0 [ -tag TAG ] main.{gif|png} main.pov [ FILES... ]" # This script is executed by students in order to hand labwork in. # Copies the named files from the current directory to the user's # directory "public_html/mc930/YYYY-MM-DD/", creating it if necessary. Also # sets the proper file and directory permissions. # If "-tag" is given, the destination directory will be # "public_html/mc930/YYYY-MM-DD-TAG/". # Must be executed in a Linux environment. if ( $#argv < 2 ) then echo "$0: bad arguments" echo "usage: ${usage}"; exit 1 endif set tag = "" while ( ( $#argv > 0 ) && ( "/$1" =~ /-* ) ) if ( ( $#argv >= 2 ) && ( "/$1" == "/-tag" ) ) then set tag = "-$2"; shift; shift; else echo 'invalid option "'"$1"'"'; echo "usage: ${usage}"; exit 1 endif end set image = "$1"; shift set source = "$1"; shift set extras = ( $* ) # Make sure the files have the right extension: if ( ( "@${image}" != "@main.png" ) && ( "@${image}" != "@main.gif" ) ) then echo "${image}"' should be "main.png" or "main.gif"'; exit 1 endif if ( "@${source:e}" != "@pov" ) then echo "${source}"' should be "main.pov"'; exit 1 endif set dt = `/bin/date '+%Y-%m-%d'` set pubdir = "${HOME}/public_html/mc930/${dt}${tag}" # Make sure the target directory exists: mkdir -p ${pubdir} # Make sure the target directory is writable by user: chmod u+w ${pubdir} # Make sure that the target directory is readable through HTTP: set tmp = ${pubdir} while ( "@${tmp}" != "@${HOME}" ) chmod a+rX ${tmp} set tmp = "${tmp:h}" end chmod -v a+X ${HOME} # Check whether we succeeded: if ( ! ( -d ${pubdir} ) ) then echo "failed to create directory ${pubdir}"; exit 1 endif if ( ! ( -w ${pubdir} ) ) then echo "directory ${pubdir} is not writable"; exit 1 endif # Remove any previously exported version of the exported files: ( cd ${pubdir} && \ /bin/rm -fv main.png main.gif main.pov ${image} ${source} ${extras} \ ) # Make sure the files exist and have nonzero length, # then copy them to the target directory and make sure that # they are accessible through HTTP: foreach f ( ${image} ${source} ${extras} ) if ( ! -r ${f} ) then echo "I cannot find ${f} in the current directory"; exit 1 endif if ( -z ${f} ) then echo "File ${f} has zero length"; exit 1 endif set dest = "${pubdir}/${f}" cp -avi ${f} ${dest} chmod og=r,u=rw ${dest} end