#!/bin/csh -f # # Stanley - Staff manager for MyStaff # # This script is the staff manager, in that it makes sure that all of # the other staff scripts are up to date, either by copying updated # versions via rsync (if that is possible), or by copying the latest # version, updated or not, via anonymous ftp. # # The previous version is saved for backup with a ~ appended to the name. # # Stanley normally only updates members of MyStaff that are already in the # administration directory (same directory as Stanley), but adding # the -f flag causes him to copy over all members of the staff in # addition to updating existing members. # # The -q or -v flags make Stanley quiet or verbose. The default is quiet. # # You must have rsync installed to syncronize with rsync (duh). # You need to have GNU wget installed to update via ftp. # # Eric Myers - 8 March 2004 # @(#) $Id: Stanley,v 1.15 2006/03/27 17:56:54 myers Exp myers $ ######################################################################## # Parameters for download host: set srchost="ftp.spy-hill.com" set rsyncpath="MyStaff" # path on rysnc server set ftppath="pub/myers/src/adm" # path on ftp server ## List of scripts to keep current: set StaffList="what newlog Tara Ivan Cora Nigel Walter Monty Rupert Percy " set StaffList="$StaffList Wendy Otto dodump Stanley" ######################### ## Script name and version number for --version set RCSVERS = \ `echo '$Revision: 1.15 $' | sed -e 's/Revision: //' -e 's/$\(.*\) \$/\1/'` set RCSDATE = \ `echo '$Date: 2006/03/27 17:56:54 $' | sed -e 's/Date: //' -e 's/$\(.*\) \$/\1/'` set mypath=$0 set PROG=`basename $mypath` set quiet=1 # verbose or quiet set force=0 # all scripts or only those in use? set Nupdated=0 # number of succesful updates ######################### ## Command line arguments while ( $#argv > 0 ) switch ( $1 ) case --help: case -h: # HELP and quit echo "${PROG}: keeps MyStaff up to date via rsync or ftp. " echo "syntax: Stanley [-v] [-f] " exit 1 case -V: case --version: echo "${PROG} version $RCSVERS, dated $RCSDATE[1]" exit 1 case -q: # run quietly set quiet=1 breaksw case -v: # verbose set quiet=0 breaksw case -f: # force all scripts set force=1 breaksw default: echo "Unknown argument: $1" echo "syntax: Stanley [-v] [-f] " echo "Type '$PROG --help' for more information." exit 2 endsw shift end ######################### # Find the adm directory where MyStaff all live, which should be # where we find Stanley in the first place set admdir=`dirname $mypath` if ( "$mypath" == "./Stanley" ) set admdir = `pwd` if ( ! $quiet ) echo "adm directory is $admdir" if ( ! -d $admdir ) then if ( ! $quiet ) echo "${PROG}: cannot find adm directory here MyStaff live." exit 3 endif ######################### ## RSYNC: ( efficient transfer only if necessary ) ## cd $admdir foreach SCRIPT ( $StaffList ) if ( -x $SCRIPT || $force ) then if ( -f $SCRIPT && ! $quiet ) then echo -n "Current version: " what -s $SCRIPT endif rsync -uabzq rsync://$srchost/$rsyncpath/$SCRIPT $admdir set RC=$status if ( $RC != 0 ) then if ( ! $quiet ) echo "${PROG}: rsync failed: RC=$RC " break else if ( -f $SCRIPT~ ) chmod -x $SCRIPT~ if ( ! $quiet ) then echo -n "New version: " what -s $SCRIPT endif @ Nupdated = $Nupdated + 1 endif endif end ######################### ## Anonymous FTP (if rsync fails) ## if ( $Nupdated == 0 ) then if ( ! $quiet ) echo "${PROG}: rsync failed, trying ftp..." cd $admdir foreach SCRIPT ( $StaffList ) if ( -x $SCRIPT || $force ) then if ( -f $SCRIPT ) then if ( ! $quiet ) then echo -n "Current version: " what -s $SCRIPT endif chmod -x $SCRIPT mv -f $SCRIPT $SCRIPT~ endif wget -q --passive-ftp ftp://$srchost/$ftppath/$SCRIPT $admdir set RC=$status if ( $RC == 0 ) then chmod +x $SCRIPT if ( ! $quiet ) then echo -n "New version: " what -s $SCRIPT endif @ Nupdated = $Nupdated + 1 endif endif end endif #################### if ( $Nupdated > 0 && ! $quiet ) then echo "${PROG}: checked/updated $Nupdated files." endif exit 0 ##