#!/bin/sh # By "Julian Stacey" from # ~jhs/public_html/src/bsd/jhs/bin/local/mail/ctm-freebsd-cvs-incoming # This script often fails initially on incompletely configured machine, # because permissions & ownerships & paths are wrong. # Here's how to easily test this script: # cp /home/yourname/mail/ctm/1000 /tmp/ctm # su mailnull-csh # sh -v /usr/local/bin/ctm-freebsd-cvs-incoming < /tmp/ctm # later I should I should add a check for pgp signature ref # http://www.freebsd.org/handbook/synching.html#CTM notify=freebsd-ctm-cvs-notify type=cvs-cur base=/pub/FreeBSD/development/FreeBSD-CVS prog=$0 PATH=/bin:/sbin:/usr/sbin:/usr/bin ; export PATH umask 022 # ; UMASK=022 ; export UMASK TMPDIR=/tmp ; export TMPDIR # Ctm_rmail calls ctm, # Ctm uses TMPDIR, # This file when installed is +sguid daemon:daemon (but does FreeBSD # care about sguid on shell scrips, maybe not). # daemon home=/root # /root/tmp is normally only # Writeable to either uid=0 or group=0=bin , & not group=1=daemon, # When this file send mail, the mail comes from mailnull # mailnull /etc/passwd is 26:26 # mailnull home is /var/spool/mqueue, which has no ./tmp id="`id` Failed to" test="`id` test" prog_pid="$prog pid=$$" prog_failed_error="$prog_pid Error: Failed" prog_failed_warning="$prog_pid Warning: Failed" # Verbose progress report. # (echo "$prog_pid start" | mail -s "$prog_pid start" $notify ) logdir=/pub/FreeBSD/development/CTM log=$logdir/$type.log pieces=/pub/FreeBSD/development/CTM/$type deltas=/pub/FreeBSD/development/CTM/$type # I was getting mail to postmaster: # ----- The following addresses had permanent fatal errors ----- # "|/usr/local/bin/ctm-freebsd-cvs-incoming" # (reason: 1) # (expanded from: freebsd-ctm-cvs-pipe@flip) # ----- Transcript of session follows ----- # No $home variable set. # "~/.mailrc": No match. # So now I assert a home (& i've run a touch .mailrc) HOME=$logdir ; export HOME # Ensure I can write essential paths & permissions from who I am running as. for object in $log $pieces/.dummy $deltas/.dummy do # (echo "$prog_pid $test $object" | \ # mail -s "$prog_pid $test $object" $notify ) touch $object || \ ( echo "$id touch $object" | \ mail -s "$prog_failed_error" $notify ; \ exit 1 ) done # Check but dont exit on non essentials. # It's only essential I receive # the CTMs OK, its not essential I always apply them immediately, # if EG I'm short of disk I might not apply immediately # or the tree may be on on another NFS mounted host that's not powered up ## for object in $base/.ctm_status ## do ## touch $object || \ ## ( echo "$id touch $object" | \ ## mail -s "$prog_failed_warning" $notify ) ## done # (echo "$prog_pid starting ctm_rmail" | \ # mail -s "$prog_pid starting ctm_rmail" $notify ) nice ctm_rmail -u -l $log -p $pieces -d $deltas -b $base # | mail -s "$prog_pid result" $notify 2>&1 # (echo "$prog_pid end" | mail -s "$prog_pid end" $notify ) # Sometimes the umask does not seem to work, so set it again here. # The -t is 'cos fairly often the deltas arrive over the Internet # out of numerical order; certainly something leaves many files 600. # Also if old deltas are resent, without -t they will not be set. # Even with this, some things still dont get set right, # the delta will get saved before being applied I guess, # & only after application to tree does the umask command here then get run, # & meantime shorter deltas have been written to deltas/ directory. # # I guess the src/*/ctm/ sets the mode wrongly. # I had a quick look at the source, but couldnt see it, # so for now quick cludgy fix is to not use head -1 but head -50 # but on a new empty system that bleats, so Ive reverted to -1 for xx cd $deltas xx=`ls -t | grep .gz | head -1` # The next 2 lines may: # - error if there's no deltas in a new empty directory yet. # - repeat a previous delta if the newly received thing has just gone # into the $pieces directory. chmod 444 $xx nice md5 $xx >> $logdir/$type.md5 exit 0