home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / nov / expov < prev    next >
Text File  |  1995-01-02  |  1KB  |  60 lines

  1. #! /bin/sh
  2. # expov - expire obsolete overview entries
  3.  
  4. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  5. . ${NEWSCONFIG-/etc/news/bin/config}
  6.  
  7. PATH=$NEWSCTL/bin:$NEWSBIN/nov:$NEWSBIN:$NEWSPATH ; export PATH
  8. umask $NEWSUMASK
  9.  
  10. lock LOCKoverview $$
  11. trap "unlock LOCKoverview ; rm -f $NEWSCTL/active.ovt ; trap 0 ; exit" 0 1 2 15
  12.  
  13. cd $NEWSCTL
  14. lock LOCK $$
  15. cp active active.ovt
  16. unlock LOCK
  17.  
  18. # the sort is an attempt to maximise locality of reference in the file system
  19. sort active.ovt | tr . / |
  20.     while read d max min rest
  21.     do
  22.         cd $NEWSARTS
  23.         if test ! -d $d
  24.         then
  25.             continue
  26.         fi
  27.         cd $d
  28.         o=$NEWSOV/$d
  29.         if test ! -r $o/.overview
  30.         then
  31.             if test ! -d $o
  32.             then
  33.                 case "$rest" in
  34.                 x*|=*)    ;;    # not worth complaining
  35.                 *)    echo "$0: directory \`$o' does not exist" >&2 ;;
  36.                 esac
  37.                 continue
  38.             fi
  39.             touch $o/.overview
  40.         fi
  41.         if ls -f | expovguts $max $min $o/.overview
  42.         then
  43.             : okay
  44.         else
  45.             echo "$0: expovguts failed in $d" >&2
  46.             echo "    ...using fallback code" >&2
  47.  
  48.             # fallback
  49.             # could use one less temporary if GNU sort didn't
  50.             # have bugs in -o
  51.             sort $o/.overview >$o/.sov
  52.             ls | egrep '^[0-9]+$' | join -t'    ' - $o/.sov |
  53.                             sort -n >$o/.nov
  54.             mv $o/.nov $o/.overview
  55.             rm -f $o/.sov
  56.         fi
  57.     done
  58.  
  59. # and the trap handles cleanup
  60.