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

  1. #! /bin/sh
  2. # addmissing - add missing articles to history
  3. # Has a SORTTMP hook for feeding in a "-T dir" option if sort's default
  4. # temporary directory is short of space.
  5. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  6. . ${NEWSCONFIG-/var/lib/news/bin/config}
  7.  
  8. PATH=$NEWSCTL/bin:$NEWSBIN/expire:$NEWSBIN:$NEWSPATH ; export PATH
  9. umask $NEWSUMASK
  10.  
  11. dbzrebuild=n
  12. case "$1" in
  13. -d)    dbzrebuild=y    ;;
  14. esac
  15.  
  16. # get main lock for history examination, and lock out expire too
  17. lock="$NEWSCTL/LOCK"
  18. ltemp="$NEWSCTL/L.$$"
  19. echo $$ >$ltemp
  20. trap "rm -f $ltemp ; exit 0" 0 1 2 15
  21. while true
  22. do
  23.     if newslock $ltemp $lock
  24.     then
  25.         trap "rm -f $ltemp $lock ; exit 0" 0 1 2 15
  26.         break
  27.     fi
  28.     sleep 30
  29. done
  30. if newslock $ltemp $NEWSCTL/LOCKexpire
  31. then
  32.     trap "rm -f $ltemp $lock $NEWSCTL/LOCKexpire ; exit 0" 0 1 2 15
  33. else
  34.     echo "$0: expire is running, $0 aborted" >&2
  35.     exit 1
  36. fi
  37.  
  38. # check space
  39. cd $NEWSCTL
  40. size="`sizeof history history.pag history.dir`"
  41. if test " `spacefor $size control`" -le 0
  42. then
  43.     echo "$0: not enough space for temporaries, $0 aborted" >&2
  44.     exit 1
  45. fi
  46.  
  47. # put together a list of known filenames from history
  48. egrep '    .*    ' history | sed 's/.*    //' | tr '. ' '/
  49. ' | egrep '/' | sort -u $SORTTMP >/tmp/hist$$
  50.  
  51. # release the main lock, temporarily
  52. trap "rm -f $ltemp $NEWSCTL/LOCKexpire ; exit 0" 0 1 2 15
  53. rm $lock
  54.  
  55. # sweep the tree, ignoring things that arrive while we're working
  56. cd $NEWSARTS
  57. them=
  58. for f in `ls | egrep -v '\.|(^lost\+found$)'`
  59. do
  60.     if test -d $f -a -r $f
  61.     then
  62.         them="$them $f"
  63.     fi
  64. done
  65. find $them -type f -name '[0-9]*' ! -newer $ltemp -print |
  66.     sort $SORTTMP >/tmp/tree$$
  67.  
  68. # find missing files, and build history entries for them
  69. comm -13 /tmp/hist$$ /tmp/tree$$ | histinfo | sort $SORTTMP |
  70.     awk -f $NEWSBIN/expire/histdups | histslash >/tmp/new$$
  71.  
  72. # check for oddities
  73. if egrep '^<[^>]*@trash>    ' /tmp/new$$ >/dev/null
  74. then
  75.     echo "$0: (warning) empty/trash articles found, will expire at once" >&2
  76.     echo "$0:     (grep history file for '@trash' to see them)" >&2
  77. fi
  78.  
  79. # lock things up again and plug them in
  80. cd $NEWSCTL
  81. while true
  82. do
  83.     if newslock $ltemp $lock
  84.     then
  85.         trap "rm -f $ltemp $lock $NEWSCTL/LOCKexpire ; exit 0" 0 1 2 15
  86.         break
  87.     fi
  88.     sleep 30
  89. done
  90. if test " $dbzrebuild" = " y"
  91. then
  92.     cat /tmp/new$$ >>history
  93.     dbz history
  94. else
  95.     dbz -a history /tmp/new$$
  96. fi
  97.  
  98. rm -f /tmp/hist$$ /tmp/tree$$ /tmp/new$$
  99.