head 1.3; access; symbols; locks alexis:1.3; strict; comment @# @; 1.3 date 98.08.07.11.33.43; author alexis; state Exp; branches; next 1.2; 1.2 date 98.03.01.22.29.20; author alexis; state Exp; branches; next 1.1; 1.1 date 98.02.28.14.46.50; author alexis; state Exp; branches; next ; desc @SCRIPT TO DOWNLOAD NEWS WITH 'SUCK' @ 1.3 log @milepost - seems to work @ text @#!SCRIPTSHELLCMD_MARKER PROGNAME=`basename $0` # $Id: getnews-suck.in,v 1.2 1998/03/01 22:29:20 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 ] { -i | -c }" echo " $PROGNAME -V" } >&2 exit 2 } main() { VERBOSE_LEVEL=2 MODE=unset # 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 ;; -i) MODE=inn ;; -c) MODE=cnews ;; -*) usage ;; *) break ;; esac shift done [ "X$1" != X ] && usage [ MODE = unset ] && usage [ ! -x SUCKGETNEWSCMD_MARKER.$MODE ] && error -f "can't execute SUCKGETNEWSCMD_MARKER.$MODE" # Lock out other calls to this program since is can take a while to run lock if [ $MODE = cnews ]; then # 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 # Stop Cnews processing while we get files su - news -c "NEWSBINDIR_MARKER/input/newsrunning off" < /dev/null else error -f "inn not supported yet!" fi # Get new news info "getting new news" 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 SUCKGETNEWSCMD_MARKER.$MODE < /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 if [ $MODE = cnews ]; then # 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 else error -f "inn not supported yet!" 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.2 log @cosmestic change to text @ text @d3 1 a3 1 # $Id: getnews-suck.in,v 1.1 1998/02/28 14:46:50 alexis Exp alexis $ d18 1 a18 1 echo "Usage: $PROGNAME [ -d | -v ]" d27 1 d43 2 d52 2 d58 10 a67 4 # 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 a70 1 su - news -c "NEWSBINDIR_MARKER/input/newsrunning off" < /dev/null d78 1 a78 1 elif SUCKGETNEWSCMD_MARKER < /dev/null; then d89 8 a96 4 # 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 d106 1 a106 1 ln $LOCKFILE.$$ $LOCKFILE && { rm $LOCKFILE.$$; return 0; } d112 1 a112 1 ln $LOCKFILE.$$ $LOCKFILE && { rm $LOCKFILE.$$; return 0; } @ 1.1 log @Initial revision @ text @d3 1 a3 1 # $Id: getnews.in,v 1.12 1998/02/05 12:27:22 alexis Exp $ d66 1 a66 1 warning "abandonning news retrieval - ppp is not up anymore" @