home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / CNEWS / _CNEWS.TAR / usr / lib / newsbin / expire / mkhistory < prev    next >
Encoding:
Text File  |  1994-09-02  |  1.9 KB  |  81 lines

  1. #! /bin/sh
  2. # mkhistory - rebuild history file and friends
  3. # Note, most sorts will accept "-T dir" to say where to put temporary files;
  4. # this can be gotten in by setting the SORTTMP environment variable in the
  5. # caller to "-T dir" and exporting it.  Some sorts might ask you to do it
  6. # by setting TMPDIR instead.
  7.  
  8. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  9. . ${NEWSCONFIG-/var/lib/news/bin/config}
  10.  
  11. PATH=$NEWSCTL/bin:$NEWSBIN/expire:$NEWSBIN:$NEWSPATH ; export PATH
  12. umask $NEWSUMASK
  13.  
  14. sizemul=
  15. case "$#$1" in
  16. 0)            ;;
  17. 2-s)    sizemul="$2"    ;;
  18. *)    echo "Usage: $0 [-s sizemultiplier]" >&2
  19.     exit 2
  20.     ;;
  21. esac
  22.  
  23. lock="$NEWSCTL/LOCK"
  24. ltemp="$NEWSCTL/L.$$"
  25. echo $$ >$ltemp
  26. trap "rm -f $ltemp ; exit 0" 0 1 2 15
  27. while true
  28. do
  29.     if newslock $ltemp $lock
  30.     then
  31.         trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
  32.         break
  33.     fi
  34.     sleep 30
  35. done
  36. if newslock $ltemp $NEWSCTL/LOCKexpire
  37. then
  38.     trap "rm -f $ltemp $lock $NEWSCTL/LOCKexpire ; exit 0" 0 1 2 15
  39. else
  40.     echo "$0: expire is running, $0 aborted" >&2
  41.     exit 1
  42. fi
  43.  
  44. cd $NEWSARTS
  45. them=
  46. for f in `ls | egrep -v '\.|(^lost\+found$)'`
  47. do
  48.     if test -d $f -a -r $f
  49.     then
  50.         them="$them $f"
  51.     fi
  52. done
  53. find $them -type f -name '[0-9]*' -print | histinfo |
  54.     sort $SORTTMP -t'    ' +1n |
  55.     awk -f $NEWSBIN/expire/histdups | histslash >$NEWSCTL/history.n
  56.  
  57. cd $NEWSCTL
  58. if egrep '^<[^>]*@trash>    ' history.n >/dev/null
  59. then
  60.     echo "$0: (warning) empty/trash articles found, will expire at once" >&2
  61.     echo "$0:     (grep history file for '@trash' to see them)" >&2
  62. fi
  63. case "$sizemul" in
  64. '')    dbzparm=        ;;
  65. *)    size="`wc -l <history.n`"
  66.     awkpgm='{ printf "%ld\n", $1 * $2 }'
  67.     # why not use expr?  because it's only 16 bits wide on 16-bit machines
  68.     dbzparm="-p `echo $size $sizemul | awk \"$awkpgm\"`"
  69.     ;;
  70. esac
  71. dbz $dbzparm history.n
  72.  
  73. if test -f history
  74. then
  75.     mv history history.o
  76. else
  77.     true
  78. fi && mv history.n history &&
  79. rm -f history.pag history.dir &&
  80. mv history.n.pag history.pag && mv history.n.dir history.dir
  81.