head 1.14; access; symbols; locks alexis:1.14; strict; comment @# @; 1.14 date 98.08.07.11.33.43; author alexis; state Exp; branches; next 1.13; 1.13 date 98.03.01.22.29.10; author alexis; state Exp; branches; next 1.12; 1.12 date 98.02.05.12.27.22; author alexis; state Exp; branches; next 1.11; 1.11 date 97.11.11.12.17.06; author alexis; state Exp; branches; next 1.10; 1.10 date 97.10.26.20.15.59; author alexis; state Exp; branches; next 1.9; 1.9 date 97.10.26.18.56.20; author alexis; state Exp; branches; next 1.8; 1.8 date 97.10.26.12.12.34; author alexis; state Exp; branches; next 1.7; 1.7 date 97.10.26.10.14.46; author alexis; state Exp; branches; next 1.6; 1.6 date 97.02.15.11.39.19; author alexis; state Exp; branches; next 1.5; 1.5 date 97.02.15.11.05.00; author alexis; state Exp; branches; next 1.4; 1.4 date 97.02.01.21.51.41; author alexis; state Exp; branches; next 1.3; 1.3 date 97.01.31.14.43.34; author alexis; state Exp; branches; next 1.2; 1.2 date 97.01.31.10.22.48; author alexis; state Exp; branches; next 1.1; 1.1 date 97.01.22.10.34.38; author alexis; state Exp; branches; next ; desc @@ 1.14 log @milepost - seems to work @ text @#!SCRIPTSHELLCMD_MARKER PROGNAME=`basename $0` # $Id: getnews-slurp.in,v 1.13 1998/03/01 22:29:10 alexis Exp alexis $ VERSION="PATCHLEVEL_MARKER" ATTEMPT_LIMIT=20 LOCKFILE=LOCKDIR_MARKER/$PROGNAME.pid ############################################################################## # # # DON'T CHANGE ANYTHING BELOW HERE # # # ############################################################################## usage() { { echo "Usage: $PROGNAME [ -d | -v ] [ -f ] [ -u ] " echo " $PROGNAME -V" } >&2 exit 2 } main() { VERBOSE_LEVEL=2 FIX_CACKY_SLURP_FILE=false UPDATE_NNDB=false # Process options - author to add extra options! while [ "X$1" != X ]; do case "$1" in -V) if expr "$VERSION" : 'P.*R$' > /dev/null; then warning "this is a development version; use 'ident' for version information" exit 1 else echo "$PROGNAME version $VERSION" exit 0 fi ;; -d) [ "X$2" = X ] && usage VERBOSE_LEVEL=$2 shift ;; -v) VERBOSE_LEVEL=3 ;; -f) FIX_CACKY_SLURP_FILE=true ;; -u) UPDATE_NNDB=true ;; -*) usage ;; *) break ;; esac shift done [ "X$2" != X -o "X$1" = X ] && usage NEWSHOST=$1 # Lock out other calls to this program since is can take a while to run lock # Flush old batches in order for the article request list to be correct info "flushing old inbound batches" su - news -c "NEWSBINDIR_MARKER/input/newsrunning on" < /dev/null su - news -c NEWSBINDIR_MARKER/input/newsrun < /dev/null if [ $FIX_CACKY_SLURP_FILE = true ]; then info "fixing slurp date file" head -1 SLURPCFGDIR_MARKER/slurp.$NEWSHOST > /tmp/$PROGNAME.$$.fl cp SLURPCFGDIR_MARKER/slurp.$NEWSHOST SLURPCFGDIR_MARKER/slurp.$NEWSHOST.bak cat /tmp/$PROGNAME.$$.fl > SLURPCFGDIR_MARKER/slurp.$NEWSHOST rm -f /tmp/$PROGNAME.$$.fl SLURPCFGDIR_MARKER/slurp.$NEWSHOST.bak fi # Get new news info "getting new news" su - news -c "NEWSBINDIR_MARKER/input/newsrunning off" < /dev/null ATTEMPT=0 while :; do ATTEMPT=`expr $ATTEMPT + 1` info "attempt #$ATTEMPT/$ATTEMPT_LIMIT" if ! grep -q '^ppp0' /proc/net/route; then warning "abandonning news retrieval - ppp is not up" break elif su - news -c "SLURPCMD_MARKER -d $NEWSHOST" < /dev/null; then break elif [ $ATTEMPT -lt $ATTEMPT_LIMIT ]; then info "news retrieval failed, retrying" sleep 3 else warning "news retrieval failed, giving up" break fi done # Flush just received batches info "flushing new inbound batches" su - news -c "NEWSBINDIR_MARKER/input/newsrunning on" < /dev/null su - news -c NEWSBINDIR_MARKER/input/newsrun < /dev/null if [ $UPDATE_NNDB = true ]; then info "updating nn database" su - news -c NNMASTERCMD_MARKER < /dev/null fi # Unlock this program unlock info "done" } lock() { { echo $$ > $LOCKFILE.$$; } 2>/dev/null || error -f "can't create lock" ln $LOCKFILE.$$ $LOCKFILE 2>/dev/null && { rm $LOCKFILE.$$; return 0; } HOLDING_PID=`cat $LOCKFILE` [ "X$HOLDING_PID" = X ] && { rm $LOCKFILE.$$; error -f "empty lockfile: $LOCKFILE"; } [ -d /proc/$HOLDING_PID ] && { rm $LOCKFILE.$$; error -f "program running already! (pid=$HOLDING_PID)"; } info "removing stale lock (pid=$HOLDING_PID)" rm -f $LOCKFILE ln $LOCKFILE.$$ $LOCKFILE 2>/dev/null && { rm $LOCKFILE.$$; return 0; } rm $LOCKFILE.$$ error -f "couldn't lock after removing stale lockfile" } unlock() { rm -f $LOCKFILE } internal() { echo "$PROGNAME: \ INTERNAL ERROR: $*" exit 2 } VERBOSE_LEVEL=${VERBOSE_LEVEL:-2} error() { FATAL=false while :; do case "$1" in -f) FATAL=true ;; -*) internal "invalid option to error() '$1'" ;; *) break ;; esac shift done if [ $VERBOSE_LEVEL -ge 1 ]; then if [ $FATAL = true ]; then echo "$PROGNAME: \ FATAL ERROR: $*" >&2 else echo "$PROGNAME: \ ERROR: $*" >&2 fi fi [ $FATAL = true ] && exit 1 return 1 } VERBOSE_LEVEL=${VERBOSE_LEVEL:-2} warning() { [ $VERBOSE_LEVEL -ge 2 ] && { echo "$PROGNAME: \ WARNING: $*" >&2; } return 0 } VERBOSE_LEVEL=${VERBOSE_LEVEL:-2} debug() { if [ $VERBOSE_LEVEL -ge $1 ]; then shift if [ "X$MSG_HANDLE" = Xstderr ]; then echo "$PROGNAME: \ DEBUG: $*" >&2 else echo "$PROGNAME: \ DEBUG: $*" fi fi return 0 } VERBOSE_LEVEL=${VERBOSE_LEVEL:-2} info() { [ $VERBOSE_LEVEL -lt 3 ] && return while :; do case "$1" in -*) internal "invalid option to info() '$1'" ;; *) break ;; esac shift done if [ "X$MSG_HANDLE" = Xstderr ]; then echo "$PROGNAME: \ INFO: $*" >&2 else echo "$PROGNAME: \ INFO: $*" fi return 0 } umask 022 main "$@@" exit $? @ 1.13 log @cosmestic change to text @ text @d3 1 a3 1 # $Id: getnews-slurp.in,v 1.12 1998/02/05 12:27:22 alexis Exp alexis $ d110 1 a110 1 ln $LOCKFILE.$$ $LOCKFILE && { rm $LOCKFILE.$$; return 0; } d116 1 a116 1 ln $LOCKFILE.$$ $LOCKFILE && { rm $LOCKFILE.$$; return 0; } @ 1.12 log @standardised script @ text @d3 1 a3 1 # $Id: getnews.in,v 1.11 1997/11/11 12:17:06 alexis Exp alexis $ d79 1 a79 1 warning "abandonning news retrieval - ppp is not up anymore" @ 1.11 log @standardised (functions,markers,compiling) requires name of news host now @ text @d3 1 a3 1 # $Id: shell-script,v 1.1 1997/10/26 22:44:12 alexis Exp $ d30 1 d43 1 a45 1 -v) VERBOSE_LEVEL=3 ;; d52 1 a52 1 [ "X$1" = X -o "X$2" != X ] && usage d107 19 d133 1 d161 1 d169 1 d172 10 a181 2 [ $VERBOSE_LEVEL -ge $1 ] && { shift; echo "$PROGNAME: \ DEBUG: $*"; } d185 1 a189 2 COLOUR_REQUESTED=false a191 1 -c) COLOUR_REQUESTED=true ;; d198 3 a200 3 if [ $COLOUR_REQUESTED = true -a $HONOUR_COLOUR_REQUESTS = true ]; then echo "$BROWN$PROGNAME: \ INFO: $*$WHITE" a205 19 } lock() { { echo $$ > $LOCKFILE.$$; } 2>/dev/null || error -f "can't create lock" ln $LOCKFILE.$$ $LOCKFILE && { rm $LOCKFILE.$$; return 0; } HOLDING_PID=`cat $LOCKFILE` [ "X$HOLDING_PID" = X ] && { rm $LOCKFILE.$$; error -f "empty lockfile: $LOCKFILE"; } [ -d /proc/$HOLDING_PID ] && { rm $LOCKFILE.$$; error -f "program running already! (pid=$HOLDING_PID)"; } info "removing stale lock (pid=$HOLDING_PID)" rm -f $LOCKFILE ln $LOCKFILE.$$ $LOCKFILE && { rm $LOCKFILE.$$; return 0; } rm $LOCKFILE.$$ error -f "couldn't lock after removing stale lockfile" } unlock() { rm -f $LOCKFILE @ 1.10 log @more directory reorg fixes @ text @d1 1 a1 2 #!/bin/sh PATH=/bin:/usr/bin d3 1 a4 1 { expr $VERSION : 'P.*R' > /dev/null; } && VERSION="`echo '$Id: getnews.in,v 1.9 1997/10/26 18:56:20 alexis Exp alexis $' | cut -f3 -d' '` (development)" d7 1 a7 1 LOCKFILE=/var/run/$PROGNAME.pid d9 16 a24 1 lock() d26 78 a103 10 echo $$ > $LOCKFILE.$$ ln $LOCKFILE.$$ $LOCKFILE && { rm $LOCKFILE.$$; return 0; } HOLDING_PID=`cat $LOCKFILE` [ "X$HOLDING_PID" = X ] && { rm $LOCKFILE.$$; error "empty lockfile: $LOCKFILE"; } [ -d /proc/$HOLDING_PID ] && { rm $LOCKFILE.$$; error "program running already! (pid=$HOLDING_PID)"; } info "removing stale lock (pid=$HOLDING_PID)" rm -f $LOCKFILE ln $LOCKFILE.$$ $LOCKFILE && { rm $LOCKFILE.$$; return 0; } rm $LOCKFILE.$$ error "couldn't lock after removing stale lockfile" d105 2 a106 2 unlock() d108 3 a110 1 rm -f $LOCKFILE d115 23 a137 2 echo "$PROGNAME: ERROR: $1" exit 1 d142 10 a151 1 echo "$PROGNAME: WARNING: $1" d156 21 a176 1 echo "$PROGNAME: INFO: $1" d179 13 a191 2 # Lock out other calls to this program since is can take a while to run lock d193 4 a196 32 # First flush old batches in order for the article request list to be correct info "flushing old inbound batches" su - news -c "NEWSBINDIR_MARKER/input/newsrunning on" < /dev/null su - news -c NEWSBINDIR_MARKER/input/newsrun < /dev/null # Fix kacky slurp date file #info "fixing slurp date file" #head -1 /usr/local/lib/nntp/slurp.news.demon.co.uk > /tmp/$PROGNAME.$$.fl #cp /usr/local/lib/nntp/slurp.news.demon.co.uk /usr/local/lib/nntp/slurp.news.demon.co.uk.bak #cat /tmp/$PROGNAME.$$.fl > /usr/local/lib/nntp/slurp.news.demon.co.uk #rm -f /tmp/$PROGNAME.$$.fl # Get new news info "getting new news" su - news -c "NEWSBINDIR_MARKER/input/newsrunning off" < /dev/null ATTEMPT=0 while :; do ATTEMPT=`expr $ATTEMPT + 1` info "attempt #$ATTEMPT/$ATTEMPT_LIMIT" if ! grep -q '^ppp0' /proc/net/route; then warning "abandonning news retrieval - ppp is not up anymore" break elif su - news -c "/usr/local/lib/nntp/slurp -d news.demon.co.uk" < /dev/null; then break elif [ $ATTEMPT -lt $ATTEMPT_LIMIT ]; then info "news retrieval failed, retrying" sleep 3 else warning "news retrieval failed, giving up" break fi done d198 3 a200 13 # Flush just received batches info "flushing new inbound batches" su - news -c "NEWSBINDIR_MARKER/input/newsrunning on" < /dev/null su - news -c NEWSBINDIR_MARKER/input/newsrun < /dev/null # Update nn database # And update nn database # info "updating nn database" # su - news -c /usr/lib/nn/nnmaster < /dev/null # Unlock this program unlock info "done" @ 1.9 log @continued directory reorganisation @ text @d5 1 a5 1 { expr $VERSION : 'P.*R' > /dev/null; } && VERSION="`echo '$Id: getnews.in,v 1.8 1997/10/26 12:12:34 alexis Exp alexis $' | cut -f3 -d' '` (development)" d70 1 a70 1 elif su - news -c "/usr/local/lib/nntp/slurp -d news.demon.co.uk" < /dev/null > /dev/null 2>&1; then @ 1.8 log @stamped for release 1.0.6 @ text @d5 1 a5 1 { expr $VERSION : 'P.*R' > /dev/null; } && VERSION="`echo '$Id: getnews.in,v 1.7 1997/10/26 10:14:46 alexis Exp alexis $' | cut -f3 -d' '` (development)" d50 2 a51 2 su - news -c "NEWLCLSBINDIR_MARKER/input/newsrunning on" < /dev/null su - news -c NEWLCLSBINDIR_MARKER/input/newsrun < /dev/null d62 1 a62 1 su - news -c "NEWLCLSBINDIR_MARKER/input/newsrunning off" < /dev/null d83 2 a84 2 su - news -c "NEWLCLSBINDIR_MARKER/input/newsrunning on" < /dev/null su - news -c NEWLCLSBINDIR_MARKER/input/newsrun < /dev/null @ 1.7 log @step @ text @d5 1 a5 1 { expr $VERSION : 'P.*R' > /dev/null; } && VERSION="`echo '$Id: getnews,v 1.6 1997/02/15 11:39:19 alexis Exp alexis $' | cut -f3 -d' '` (development)" @ 1.6 log @improved version info. @ text @d5 1 a5 1 { expr $VERSION : 'P.*R' > /dev/null; } && VERSION="`echo '$Id$' | cut -f3 -d' '` (development)" d50 2 a51 2 su - news -c "/usr/lib/newsbin/input/newsrunning on" < /dev/null su - news -c /usr/lib/newsbin/input/newsrun < /dev/null d62 1 a62 1 su - news -c "/usr/lib/newsbin/input/newsrunning off" < /dev/null d83 2 a84 2 su - news -c "/usr/lib/newsbin/input/newsrunning on" < /dev/null su - news -c /usr/lib/newsbin/input/newsrun < /dev/null d88 2 a89 2 info "updating nn database" su - news -c /usr/lib/nn/nnmaster < /dev/null @ 1.5 log @added rcs id and 'done' message. @ text @d4 2 a5 3 # No need at current to make this part of the program. It is sufficient for # it to be just a comment. Ident will still get it. # $id$ @ 1.4 log @MILEPOST - WORKS @ text @d4 3 d49 1 a49 1 # First flush old batches d94 1 @ 1.3 log @MILEPOST - MAY NOT WORK @ text @d13 2 a14 2 [ "X$HOLDING_PID" = X ] && error "empty lockfile: $LOCKFILE" [ -d /proc/$HOLDING_PID ] && error "program running already! (pid=$HOLDING_PID)" d18 1 a19 1 return 1 d44 1 a44 1 lock || exit 1 d52 5 a56 5 info "fixing slurp date file" head -1 /usr/local/lib/nntp/slurp.news.demon.co.uk > /tmp/$PROGNAME.$$.fl cp /usr/local/lib/nntp/slurp.news.demon.co.uk /usr/local/lib/nntp/slurp.news.demon.co.uk.bak cat /tmp/$PROGNAME.$$.fl > /usr/local/lib/nntp/slurp.news.demon.co.uk rm -f /tmp/$PROGNAME.$$.fl d68 1 a68 1 elif su - news -c "/usr/local/lib/nntp/slurp -d news.demon.co.uk" < /dev/null; then @ 1.2 log @WORKING MILESTONE @ text @d6 39 d47 1 d52 1 d59 1 d64 5 a68 2 echo "$PROGNAME: INFO: attempt #$ATTEMPT/$ATTEMPT_LIMIT" if su - news -c "/usr/local/lib/nntp/slurp -d news.demon.co.uk" < /dev/null; then d71 1 a71 1 echo "$PROGNAME: INFO: news retrieval failed, retrying" d74 1 a74 1 echo "$PROGNAME: WARNING: news retrieval failed, giving up" d80 1 d85 2 d88 3 @ 1.1 log @Initial revision @ text @d8 1 d18 1 d22 1 a22 1 echo "$PROGNAME: INFO: attempt '#'$ATTEMPT/$ATTEMPT_LIMIT" d24 1 a24 1 break; d27 1 d30 1 a30 1 exit 1 d35 1 @