#!/bin/sh # # Get demos, problems, etc for the contestant. # # File: hpcm_get # Author: Bob Walton # Date: Thu May 4 07:39:05 EDT 2006 # # The authors have placed this program in the public # domain; they make no warranty and accept no liability # for this program. # # RCS Info (may not be true date or author): # # $Author: hc3 $ # $Date: 2006/05/04 13:47:15 $ # $RCSfile: hpcm_get,v $ # $Revision: 1.11 $ # If this is not bash and bash is available, switch to # using bash. Note that `which bash` may output a # grubby error message and no error code if bash does # not exist. Some non-bash sh'es have trouble with # `test -e'. # bash=`which bash 2>/dev/null` if test "$BASH" = "" -a "$bash" != "" -a -x "$bash" then exec bash "$0" "$@" fi # Check for an consume -* options. # force=no case "$1" in -force ) force=yes shift ;; -* ) echo " hpcm_get [-force] [name ...] When used without a name, gets all help, demos, and problems files. When used with a name, gets the named files or directories. Getting a directory recursively gets the contents of that directory. Everything gotten should be installed in the \`contest home' directory which contains the HPCM_ ADDRESS file. This is done automatically if you have included help/sh/procmailrc in your ~/.procmailrc file (see the email_unix_tools help file), and your mailer uses procmail to deliver mail. Otherwise you need to copy the return message into a file and input that file to hpcm_ extract while the current directory is the contest home directory or one of its descendants. So for example, hpcm_get demos gets files named \`demos/...' to be put in the directory ../../demos if ../.. is the contest home directory because it contains a readable HPCM_ ADDRESS file while . and .. do not. Without the -force option, hpcm_get refuses to get things that seem to be already gotten. With -force, it will get them anyway, which is useful if the version gotten is more recent or more complete than what was previously gotten." exit 1 ;; esac # Look for HPCM_ADDRESS file to fine home. # if test -r HPCM_ADDRESS then home=. elif test -r ../HPCM_ADDRESS then home=.. elif test -r ../../HPCM_ADDRESS then home=../.. elif test -r ../../../HPCM_ADDRESS then home=../../.. else echo "ERROR: Cannot find HPCM_ADDRESS file" exit 1 fi # Loop through the name arguments, or use `help demos' # as names if there are no name arguments. # if test "${*:+yes}" = "" then names="help demos problems" else names="$*" fi for name in $names do case "$name" in help/* | help ) dir=help ;; demos/* | demos ) dir=demos ;; problems/* | problems ) dir=problems ;; *) echo "IGNORING \`$name';" echo " first component of name is" \ "not \`help', \`demos', or" \ "\`problems'." continue ;; esac # Get $name by email if it has not already been # gotten or if -force option given. # if test -e "$home/$name" -a "$force" = "no" then echo "IGNORING \`$name';" echo " it has been gotten already;" echo " use -force to get it again." else echo "Sending email to get \`$name'." echo "Subject: get $name" | hpcm_sendmail sleep 2 fi done exit 0