home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / input / rnews < prev   
Text File  |  1995-04-27  |  2KB  |  87 lines

  1. #! /bin/sh
  2. # Incoming-news spooling.
  3. # Arguments are options etc., not filenames -- it looks tempting to
  4. # put "$*" after newsspool, but there are security problems.
  5.  
  6. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  7. . ${NEWSCONFIG-/etc/news/bin/config}
  8.  
  9. PATH=$NEWSCTL/bin:$NEWSBIN/input:$NEWSBIN:$NEWSPATH ; export PATH
  10. umask $NEWSUMASK
  11.  
  12. # sort out arguments; pretty simple for now
  13. decompress=
  14. for dummy
  15. do
  16.     case "$1" in
  17.     -d)    decompress="$2"
  18.         case "$decompress" in
  19.         .*)    decompress=    ;;
  20.         */*)    decompress=    ;;
  21.         esac
  22.         shift
  23.         ;;
  24.     --)    shift ; break    ;;
  25.     -*)    echo "$0: unknown option \`$1'" >&2 ; exit 2    ;;
  26.     *)    break    ;;
  27.     esac
  28.     shift
  29. done
  30. if test " $decompress" != " "
  31. then
  32.     decompress="$NEWSBIN/decompressors/$decompress"
  33.     if test ! -r "$decompress"
  34.     then
  35.         decompress=
  36.     fi
  37. fi
  38.  
  39. # check space, assuming a pretty large batch (no cheap way to find real size)
  40. counter=1
  41. while test " `spacefor 250000 incoming`" -le 0
  42. do
  43.     # Warn sysadmin -- he just might be listening and able to act -- and
  44.     # stall a little bit in hopes that it's transient.
  45.     if test " $counter" -eq 1
  46.     then
  47.         report -u 'news space shortage' <<'!'
  48. Incoming news will be discarded due to space shortage unless more room
  49. becomes available within 15 min.
  50. !
  51.     fi
  52.     if test " $counter" -gt 1111        # four tries is plenty
  53.     then
  54.         # oh no! -- nothing we can do, really...
  55.         cat >/dev/null
  56.         echo incoming news discarded due to space shortage |
  57.                         report -u 'news discarded'
  58.         exit 1
  59.     fi
  60.     if test ! -f $NEWSCTL/rnews.stall
  61.     then
  62.         counter="1$counter"
  63.     else            # avoid repeating the sysadmin warning
  64.         counter=2
  65.     fi
  66.     sleep 300
  67. done
  68.  
  69. # spool it
  70. case "$decompress" in
  71. '')    newsspool        ;;
  72. *)    $decompress | newsspool    ;;
  73. esac >/tmp/ngripe.$$ 2>&1
  74. if test ! -s /tmp/ngripe.$$
  75. then
  76.     # it worked
  77.     rm -f /tmp/ngripe.$$
  78.     exit 0
  79. fi
  80.  
  81. # something went wrong
  82. # there really isn't any way to save the data if newsspool fails,
  83. # not without causing other problems
  84. report -u 'newsspool or decompressor failure' </tmp/ngripe.$$
  85. rm -f /tmp/ngripe.$$
  86. exit 1
  87.