home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2660 / checkgroups next >
Text File  |  1991-02-04  |  4KB  |  152 lines

  1. #! /bin/sh
  2. : check active file for missing or extra newsgroups
  3. : '@(#)checkgroups    1.25    1/15/89'
  4.  
  5. . ${NEWSCONFIG-/usenet/bin.server/config}
  6.  
  7. if  test  ! -s $NEWSCTL/newsgroups
  8. then
  9.     cp /dev/null $NEWSCTL/newsgroups
  10. fi
  11. echo "" >/tmp/$$out
  12. # Read first line of stdin.  If of the form "-n group", then only check
  13. # for the specified group.  Otherwise, assume doing standard groups
  14. sed -e "/^From: /w /tmp/$$out" -e '/^[a-zA-Z-]*: /d' -e '/^$/d' -e '/^[#:]/d' | (
  15. read line
  16. case "${line}" in
  17. -n*)
  18.     # Doing specific group.  extract group name and preserve
  19.     # all of current newsgroups file except for that group.
  20.     # Then append entries for this group.
  21.     group=`echo "x${line}" | sed -e 's/x-n /^/' -e 's/$/[.     ]/'`
  22.     egrep -v "${group}" $NEWSCTL/newsgroups > /tmp/$$a
  23.     cat /tmp/$$a - > $NEWSCTL/newsgroups
  24.     ;;
  25. *)
  26.     # Get the distributions from the checkgroups message itself
  27.     # This allows sites to append their local groups to the distributed
  28.     # checkgroups message and prevents stray checkgroups from other sites
  29.     # from showing all the local groups as being bad groups.
  30.     #
  31.     echo "${line}" > /tmp/$$msg
  32.     cat >> /tmp/$$msg
  33.     cp /dev/null /tmp/$$b
  34.     pipe=''
  35.     sed -e "s;[     ].*;;" -e "s;\..*;;" -e "s;^!;;" /tmp/$$msg | sort -u |
  36.         while read dist
  37.         do
  38.             group=`cat /tmp/$$b`
  39.             group="${group}${pipe}^$dist[.     ]"
  40.             echo "${group}" > /tmp/$$b
  41.             pipe='|'
  42.         done
  43.     group=`cat /tmp/$$b`
  44.     egrep -v "${group}" $NEWSCTL/newsgroups > /tmp/$$a
  45.     cat /tmp/$$a > $NEWSCTL/newsgroups
  46.     sed -e "/^!/d" /tmp/$$msg >> $NEWSCTL/newsgroups
  47.     rm -f /tmp/$$b /tmp/$$msg
  48.     ;;
  49. esac
  50.  
  51. egrep "${group}" $NEWSCTL/active | sed 's/ .*//' | sort >/tmp/$$active
  52. egrep "${group}" $NEWSCTL/newsgroups | sed 's/[     ].*//' | sort >/tmp/$$newsgrps
  53.  
  54. comm -13 /tmp/$$active /tmp/$$newsgrps >/tmp/$$missing
  55. comm -23 /tmp/$$active /tmp/$$newsgrps >/tmp/$$remove
  56.  
  57. egrep "${group}" $NEWSCTL/active | sed -n "/m\$/s/ .*//p" |
  58.     sort > /tmp/$$amod.all
  59. egrep "${group}" $NEWSCTL/newsgroups |
  60. sed -n "/Moderated/s/[     ][     ]*.*//p" | sort > /tmp/$$ng.mod
  61.  
  62. comm -12 /tmp/$$missing /tmp/$$ng.mod >/tmp/$$add.mod
  63. comm -23 /tmp/$$missing /tmp/$$ng.mod >/tmp/$$add.unmod
  64. cat /tmp/$$add.mod /tmp/$$add.unmod >>/tmp/$$add
  65.  
  66. comm -23 /tmp/$$amod.all /tmp/$$remove >/tmp/$$amod
  67. comm -13 /tmp/$$ng.mod /tmp/$$amod >/tmp/$$ismod
  68. comm -23 /tmp/$$ng.mod /tmp/$$amod >/tmp/$$nm.all
  69. comm -23 /tmp/$$nm.all /tmp/$$add >/tmp/$$notmod
  70.  
  71. echo "" >>/tmp/$$out
  72. if test -s /tmp/$$remove
  73. then
  74.     (
  75.     echo "# The following newsgroups are non-standard."
  76.     sed "s/^/#    /" /tmp/$$remove
  77.     echo ""
  78.     #echo "# You can remove them by executing the commands:"
  79.     #for i in `cat /tmp/$$remove`
  80.     #do
  81.     #    echo "    /usr/lib/news/rmgroup $i"
  82.     #done
  83.     #echo ""
  84.     ) 2>&1 >>/tmp/$$out
  85. fi
  86.  
  87. if test -s /tmp/$$add
  88. then
  89.     (
  90.     echo "# The following newsgroups were missing and should be added."
  91.     sed "s/^/#    /" /tmp/$$add
  92.     echo ""
  93.     #echo "# You can do this by executing the command(s):"
  94.     #for i in `cat /tmp/$$add.unmod`
  95.     #do
  96.     #    echo '/usr/lib/news/inews -C '$i' </dev/null'
  97.     #done
  98.     #for i in `cat /tmp/$$add.mod`
  99.     #do
  100.     #    echo '/usr/lib/news/inews -C '$i' moderated </dev/null'
  101.     #done
  102.     #echo ""
  103.     ) 2>&1 >>/tmp/$$out
  104. fi
  105.  
  106. if test -s /tmp/$$ismod
  107. then
  108.     (
  109.     echo "# The following newsgroups are not moderated and are marked moderated."
  110.     sed "s/^/#    /" /tmp/$$ismod
  111.     echo ""
  112.     #echo "# You can correct this by executing the command(s):"
  113.     #for i in `cat /tmp/$$ismod`
  114.     #do
  115.     #    echo '/usr/lib/news/inews -C '$i' </dev/null'
  116.     #done
  117.     #echo ""
  118.     ) 2>&1 >>/tmp/$$out
  119. fi
  120.  
  121. if test -s /tmp/$$notmod
  122. then
  123.     (
  124.     echo "# The following newsgroups are moderated and not marked so."
  125.     sed "s/^/#    /" /tmp/$$notmod
  126.     echo ""
  127.     #echo "# You can correct this by executing the command(s):"
  128.     #for i in `cat /tmp/$$notmod`
  129.     #do
  130.     #    echo '/usr/lib/news/inews -C '$i' moderated </dev/null'
  131.     #done
  132.     #echo ""
  133.     ) 2>&1 >>/tmp/$$out
  134. fi
  135.  
  136. if test -s /tmp/$$out
  137. then
  138.     (echo    "Subject: Problems with your active file"
  139.     echo ""
  140.     cat /tmp/$$out
  141.     ) | if test $# -gt 0
  142.         then
  143.             PATH=/bin:$PATH
  144.             mail $1
  145.         else
  146.             cat
  147.         fi    
  148. fi
  149. )
  150.  
  151. rm -f /tmp/$$*
  152.