home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / ctl / checkgroups next >
Text File  |  1994-09-08  |  3KB  |  103 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
  5.  
  6. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  7. . ${NEWSCONFIG-/etc/news/bin/config}
  8.  
  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$$* ; trap 0 ; 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. if test -r $NEWSCTL/newsgroups
  41. then
  42.     cp $NEWSCTL/newsgroups $NEWSCTL/newsgroups.bac || exit 1
  43. else
  44.     >$NEWSCTL/newsgroups.bac
  45. fi
  46. # toss out old newsgroups rubbish
  47. hierlist="`cat $hiers`"        # message is assumed authoritative for these
  48. hierpat="` echo $hierlist | tr ' ' , `"    # one more time, with commas
  49. (gngp -av "$hierpat" $NEWSCTL/newsgroups.bac
  50.  # add new newsgroups rubbish
  51.  cat $desc) >$NEWSCTL/newsgroups
  52.  
  53. # canonicalise active file & select interesting hierarchies
  54. awk '{
  55.     modstat = $4
  56.     if (modstat != "y" && modstat != "m")
  57.         modstat = "y"
  58.     print $1, modstat
  59. }' $NEWSCTL/active | gngp -a "$hierpat" | sort >$canact
  60.  
  61. # canonicalise body into an active-file-like thing
  62. awk '
  63. /Moderated/    { print $1, "m" } # TODO: " (Moderated)$"? as per B 2.11.19
  64. !/Moderated/    { print $1, "y" }
  65. ' $desc | sort >$newact
  66.  
  67. # what's different?  first, what groups have vanished or appeared?
  68. sed 's/ .*//' $canact >$actgrps
  69. sed 's/ .*//' $newact >$newgrps
  70. comm -12 $actgrps $newgrps >$samegrps
  71. comm -23 $actgrps $newgrps >$remgrps
  72. comm -13 $actgrps $newgrps >$addgrps
  73. if test -s $remgrps; then
  74.     echo
  75.     echo 'obsolete groups:'
  76.     cat $remgrps
  77. fi >$diffs
  78. if test -s $addgrps; then
  79.     echo
  80.     echo 'new groups:'
  81.     join $addgrps $newact
  82. fi >>$diffs
  83.  
  84. # next, what surviving groups have changed moderation status?
  85. join $samegrps $canact >$sameact
  86. join $samegrps $newact >$samenew
  87. comm -13 $sameact $samenew >$modchng
  88. if test -s $modchng; then
  89.     echo
  90.     echo 'groups needing moderation status changed to that shown:'
  91.     cat $modchng
  92. fi >>$diffs
  93.  
  94. if test -s $diffs; then
  95.     (echo "Subject: possible active file problems"; echo;
  96.      echo "If you believe this checkgroups control message for hierarchies"
  97.      echo "\`$hierpat', the following differences may reflect groups"
  98.      echo "that should be added, deleted, or have their moderation"
  99.      echo "status(es) changed:"
  100.      cat $diffs) | report 'checkgroups output'
  101. fi
  102. exit 0        ## end of new one
  103.