home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / CNEWS / _CNEWS.TAR / usr / lib / newsbin / ctl / checkgroups next >
Encoding:
Text File  |  1994-09-02  |  2.9 KB  |  97 lines

  1. #! /bin/sh
  2. # checkgroups - check active file for missing or extra newsgroups or groups
  3. #    with incorrect moderation status, and update the newsgroups file.
  4. #    stdin must a checkgroups news article, sends mail to $NEWSMASTER.
  5.  
  6. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  7. . ${NEWSCONFIG-/var/lib/news/bin/config}
  8. export NEWSCTL NEWSBIN NEWSARTS
  9. PATH=$NEWSCTL/bin:$NEWSBIN:$NEWSPATH ; export PATH
  10. desc=/tmp/cg$$d
  11. hiers=/tmp/cg$$h
  12. canact=/tmp/cg$$a
  13. newact=/tmp/cg$$n
  14. diffs=/tmp/cg$$df
  15. actgrps=/tmp/cg$$ag
  16. newgrps=/tmp/cg$$ng
  17. samegrps=/tmp/cg$$sg
  18. addgrps=/tmp/cg$$ad
  19. remgrps=/tmp/cg$$rm
  20. sameact=/tmp/cg$$sa
  21. samenew=/tmp/cg$$sn
  22. modchng=/tmp/cg$$mc
  23.  
  24. umask $NEWSUMASK
  25. trap 'rm -f /tmp/cg$$*; exit' 0 1 2 15
  26.  
  27. # behead stdin (checkgroups article) & ignore lines that don't fit the syntax
  28. # (should just be able to reject tabless lines, but Bitnet buggers that).
  29. # ignore signatures and initial !mod lines.
  30. ngalpha='-_+a-zA-Z0-9'
  31. sed -n -e '1,/^$/d' -e '1{/^!mod$/d;}' -e '/^-- $/,$d' \
  32.     -e "/^[$ngalpha][     ][     ]*/p" \
  33.     -e "/^[$ngalpha][$ngalpha.]*[$ngalpha][     ][     ]*/p" \
  34.     >$desc
  35.  
  36. # generate list of hierarchies affected
  37. sed 's/\..*//' $desc | sort -u >$hiers
  38.  
  39. # backup newsgroups before updating it
  40. cp $NEWSCTL/newsgroups $NEWSCTL/newsgroups.bac || { exit 1; }
  41. # toss out old newsgroups rubbish
  42. hierlist="`cat $hiers`"        # message is assumed authoritative for these
  43. hierpat="` echo $hierlist | tr ' ' , `"    # one more time, with commas
  44. (gngp -av "$hierpat" $NEWSCTL/newsgroups.bac
  45.  # add new newsgroups rubbish
  46.  cat $desc) >$NEWSCTL/newsgroups
  47.  
  48. # canonicalise active file & select interesting hierarchies
  49. awk '{
  50.     modstat = $4
  51.     if (modstat != "y" && modstat != "m")
  52.         modstat = "y"
  53.     print $1, modstat
  54. }' $NEWSCTL/active | gngp -a "$hierpat" | sort >$canact
  55.  
  56. # canonicalise body into an active-file-like thing
  57. awk '
  58. /Moderated/    { print $1, "m" } # TODO: " (Moderated)$"? as per B 2.11.19
  59. !/Moderated/    { print $1, "y" }
  60. ' $desc | sort >$newact
  61.  
  62. # what's different?  first, what groups have vanished or appeared?
  63. sed 's/ .*//' $canact >$actgrps
  64. sed 's/ .*//' $newact >$newgrps
  65. comm -12 $actgrps $newgrps >$samegrps
  66. comm -23 $actgrps $newgrps >$remgrps
  67. comm -13 $actgrps $newgrps >$addgrps
  68. if test -s $remgrps; then
  69.     echo
  70.     echo 'obsolete groups:'
  71.     cat $remgrps
  72. fi >$diffs
  73. if test -s $addgrps; then
  74.     echo
  75.     echo 'new groups:'
  76.     cat $addgrps
  77. fi >>$diffs
  78.  
  79. # next, what surviving groups have changed moderation status?
  80. join $samegrps $canact >$sameact
  81. join $samegrps $newact >$samenew
  82. comm -13 $sameact $samenew >$modchng
  83. if test -s $modchng; then
  84.     echo
  85.     echo 'groups needing moderation status changed to that shown:'
  86.     cat $modchng
  87. fi >>$diffs
  88.  
  89. if test -s $diffs; then
  90.     (echo "Subject: possible active file problems"; echo;
  91.      echo "If you believe this checkgroups control message, the following"
  92.      echo "differences may reflect groups that should be added, deleted,"
  93.      echo "or have their moderation status(es) changed:"
  94.      cat $diffs) | mail "$NEWSMASTER"
  95. fi
  96. exit 0        ## end of new one
  97.