INN commit: branches/2.4/control (docheckgroups.in)

INN Commit Russ_Allbery at isc.org
Wed Feb 18 21:38:47 UTC 2009


    Date: Wednesday, February 18, 2009 @ 13:38:47
  Author: iulius
Revision: 8322

Backport commits 7670, 8317 et 8319 from CURRENT:

[7670]
First step towards a better handling of checkgroups:  an improved
version of docheckgroups.  Hopefully it is backward compatible.

  * The -u flag permits to update the newsgroups file (with the
    proper number of tabulations and an alphabetical sort),
    removing obsolete descriptions and adding new ones.

  * A second argument on command-line permits to specify which
    newsgroups should not be checked (it is pretty useful and
    will be used to handle drops in control.ctl as for checkgroups
    processing).

  * Detabify the script, use innshellvars' "${SORT}" instead of
    "sort" and add more comments inside the script.

  * The output is displayed better (more spaces and rewording)
    and mentions the possibility to use the -u flag and mod-active.

  * Fix a bug for moderated groups (" (Moderated)" should be
    searched, and not "(Moderated)").


[8317]
Be more consistent in wording.


[8319]
The pattern "a\+" is not recognized by a few sed implementations.
Therefore, we use "aa*" instead.

Modified:
  branches/2.4/control/docheckgroups.in

------------------+
 docheckgroups.in |  199 +++++++++++++++++++++++++++++++----------------------
 1 file changed, 120 insertions(+), 79 deletions(-)

Modified: docheckgroups.in
===================================================================
--- docheckgroups.in	2009-02-18 21:19:45 UTC (rev 8321)
+++ docheckgroups.in	2009-02-18 21:38:47 UTC (rev 8322)
@@ -1,36 +1,53 @@
 #! /bin/sh
 # fixscript will replace this line with code to load innshellvars
 
-##  $Revision$
+##  $Id$
 ##  Script to execute checkgroups text; results to stdout.
+##
+##  Usage: docheckgroups [-u] [include-pattern [exclude-pattern]] < message
+##
+##  If the -u flag is given, the newsgroups descriptions are automatically
+##  updated.
 
 T=${TMPDIR}
+UPDATEDESC=false
 
 cat /dev/null >${T}/$$out
 
-##  Copy the article without headers, append local newsgroups.
-cat >${T}/$$msg
-test -f ${LOCALGROUPS} && cat ${LOCALGROUPS} >>${T}/$$msg
+##  Parse arguments.
+if [ $# -gt 0 ]; then
+    case $1 in
+    -u) shift;
+        UPDATEDESC=true;;
+    esac
+fi
 
+##  Copy the message without excluded newsgroups and append local newsgroups.
+cat | ${EGREP} -v "${2:-^#}" >${T}/$$msg
+test -f ${LOCALGROUPS} && cat ${LOCALGROUPS} | ${EGREP} -v "^#" >>${T}/$$msg
+
 ##  Get the top-level newsgroup names from the message and turn it into
 ##  an egrep pattern.
 PATS=`${SED} <${T}/$$msg \
-	-e 's/[ 	].*//' -e 's/\..*//' \
-	-e 's/^!//' -e '/^$/d' \
-	-e 's/^/^/' -e 's/$/[. 	]/' \
-    | sort -u \
+        -e 's/[ 	].*//' -e 's/\..*//' \
+        -e 's/^!//' -e '/^$/d' \
+        -e 's/^/^/' -e 's/$/[. 	]/' \
+    | ${SORT} -u \
     | (tr '\012' '|' ; echo '' )\
     | ${SED} -e 's/|$//'`
 
-${EGREP} "${PATS}" ${ACTIVE} | ${EGREP} "${1:-.}" | ${SED} 's/ .*//' | sort >${T}/$$active
-${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" | ${SED} 's/[ 	].*//' | sort >${T}/$$newsgrps
+##  Check for missing and obsolete newsgroups in active.
+${EGREP} "${PATS}" ${ACTIVE} | ${EGREP} "${1:-.}" | ${SED} 's/ .*//' | ${SORT} >${T}/$$active
+${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" | ${SED} 's/[ 	].*//' | ${SORT} >${T}/$$newsgrps
 
 comm -13 ${T}/$$active ${T}/$$newsgrps >${T}/$$missing
 comm -23 ${T}/$$active ${T}/$$newsgrps >${T}/$$remove
 
-${EGREP} "${PATS}" ${ACTIVE} | ${EGREP} "${1:-.}" | ${SED} -n '/ m$/s/ .*//p' | sort >${T}/$$amod.all
-${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" | ${SED} 's/\r\?$//' |
-${SED} -n '/(Moderated)$/s/[ 	].*//p' | sort >${T}/$$ng.mod
+##  Check for proper moderation flags in active (we need to be careful
+##  when dealing with wire-formatted articles manually fed from the spool).
+${EGREP} "${PATS}" ${ACTIVE} | ${EGREP} "${1:-.}" | ${SED} -n '/ m$/s/ .*//p' | ${SORT} >${T}/$$amod.all
+${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" | ${SED} 's/\r\?$//' \
+    | ${SED} -n '/ (Moderated)$/s/[ 	].*//p' | ${SORT} >${T}/$$ng.mod
 
 comm -12 ${T}/$$missing ${T}/$$ng.mod >${T}/$$add.mod
 comm -23 ${T}/$$missing ${T}/$$ng.mod >${T}/$$add.unmod
@@ -41,109 +58,133 @@
 comm -23 ${T}/$$ng.mod ${T}/$$amod >${T}/$$nm.all
 comm -23 ${T}/$$nm.all ${T}/$$add >${T}/$$notmod
 
-${EGREP} "${PATS}" ${NEWSGROUPS} | ${EGREP} "${1:-.}" | ${SED} 's/[	]\+/	/' | sort >${T}/$$localdesc
-${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" | ${SED} 's/\r\?$//' |
-${SED} 's/[	]\+/	/' | sort >${T}/$$newdesc
+##  Check for missing and obsolete newsgroups descriptions (possibly
+##  in wire format).  A few sed implementations do not recognize
+##  "[	]\+", so we use "	[	]*" instead.
+${EGREP} "${PATS}" ${NEWSGROUPS} | ${EGREP} "${1:-.}" | ${SED} 's/	[	]*/	/' | ${SORT} >${T}/$$localdesc
+${EGREP} "${PATS}" ${T}/$$msg | ${EGREP} "${1:-.}" | ${SED} 's/\r\?$//' \
+    | ${SED} 's/	[	]*/	/' | ${SORT} >${T}/$$newdesc
 
-if ! (head -1 ${T}/$$newdesc | egrep " [[:digit:]]+ [[:digit:]]+ " > /dev/null) ; then
-  comm -13 ${T}/$$localdesc ${T}/$$newdesc >${T}/$$missingdesc
-  comm -23 ${T}/$$localdesc ${T}/$$newdesc >${T}/$$removedesc
+comm -13 ${T}/$$localdesc ${T}/$$newdesc >${T}/$$missingdesc
+comm -23 ${T}/$$localdesc ${T}/$$newdesc >${T}/$$removedesc
+
+##  If the -u flag is given, update the newsgroups descriptions.
+if [ "${UPDATEDESC}" = "true" ] ; then
+    ${EGREP} -v "${PATS}" ${NEWSGROUPS} >${T}/$$updatednewsgroups
+    ${EGREP} "${PATS}" ${NEWSGROUPS} | ${EGREP} -v "${1:-.}" >>${T}/$$updatednewsgroups
+    cat ${T}/$$newdesc >>${T}/$$updatednewsgroups
+    mv -f ${NEWSGROUPS} ${NEWSGROUPS}.old
+    ${SORT} ${T}/$$updatednewsgroups | ${SED} 's/	[	]*/	/' \
+        | ${AWK} -F'\t' '{if (length($1) < 8) {print $1"\t\t\t"$2} \
+                    else {if (length($1) < 16) {print $1"\t\t"$2} \
+                    else {print $1"\t"$2}}}' >${NEWSGROUPS}
+    chmod 0664 ${NEWSGROUPS} ${NEWSGROUPS}.old
 fi
 
+##  Display information on newsgroups which need to be removed/added/changed.
 if [ -s ${T}/$$remove ] ; then
     (
-	echo "# The following newsgroups are non-standard."
-	${SED} "s/^/#	/" ${T}/$$remove
-	echo "# You can remove them by executing the commands:"
-	for i in `cat ${T}/$$remove` ; do
-	    echo "	${PATHBIN}/ctlinnd rmgroup $i"
-	    ${EGREP} "^$i	" ${NEWSGROUPS} >>${T}/$$ngdel
-	done
-	echo ''
+        echo "# The following newsgroups are non-standard and should be removed:"
+        echo "#"
+        ${SED} "s/^/#	/" ${T}/$$remove
+        echo "#"
+        echo "# You can remove them by executing the command(s):"
+        echo ""
+        for i in `cat ${T}/$$remove` ; do
+            echo "	${PATHBIN}/ctlinnd rmgroup $i"
+        done
+        echo ""
     ) >>${T}/$$out
 fi
 
 if [ -s ${T}/$$add ] ; then
     (
-	echo "# The following newsgroups were missing and should be added."
-	${SED} "s/^/#	/" ${T}/$$add
-	echo "# You can do this by executing the command(s):"
-	for i in `cat ${T}/$$add.unmod` ; do
-	    echo "	${PATHBIN}/ctlinnd newgroup $i y ${FROM}"
-	    ${EGREP} "^$i	" ${T}/$$msg >>${T}/$$ngadd
-	done
-	for i in `cat ${T}/$$add.mod` ; do
-	    echo "	${PATHBIN}/ctlinnd newgroup $i m ${FROM}"
-	    ${EGREP} "^$i	" ${T}/$$msg >>${T}/$$ngadd
-	done
-	echo ''
+        echo "# The following newsgroups are missing and should be added:"
+        echo "#"
+        ${SED} "s/^/#	/" ${T}/$$add
+        echo "#"
+        echo "# You can add them by executing the command(s):"
+        echo ""
+        for i in `cat ${T}/$$add.unmod` ; do
+            echo "	${PATHBIN}/ctlinnd newgroup $i y ${FROM}"
+        done
+        for i in `cat ${T}/$$add.mod` ; do
+            echo "	${PATHBIN}/ctlinnd newgroup $i m ${FROM}"
+        done
+        echo ""
     ) >>${T}/$$out
 fi
 
 if [ -s ${T}/$$ismod ] ; then
     (
-	echo "# The following groups are incorrectly marked as moderated:"
-	${SED} "s/^/#	/" ${T}/$$ismod
-	echo "# You can correct this by executing the following:"
-	for i in `cat ${T}/$$ismod` ; do
-	    echo "	${PATHBIN}/ctlinnd changegroup $i y"
-	    ${EGREP} "^$i	" ${T}/$$msg >>${T}/$$ngchng
-	done
-	echo ''
+        echo "# The following newsgroups are incorrectly marked as moderated"
+        echo "# and should have their status changed:"
+        echo "#"
+        ${SED} "s/^/#	/" ${T}/$$ismod
+        echo "#"
+        echo "# You can correct this by executing the command(s):"
+        echo ""
+        for i in `cat ${T}/$$ismod` ; do
+            echo "	${PATHBIN}/ctlinnd changegroup $i y"
+        done
+        echo ""
     ) >>${T}/$$out
 fi
 
 if [ -s ${T}/$$notmod ] ; then
     (
-	echo "# The following groups are incorrectly marked as unmoderated:"
-	${SED} "s/^/#	/" ${T}/$$notmod
-	echo "# You can correct this by executing the following:"
-	for i in `cat ${T}/$$notmod` ;do
-	    echo "	${PATHBIN}/ctlinnd changegroup $i m"
-	    ${EGREP} "^$i	" ${T}/$$msg >>${T}/$$ngchng
-	done
-	echo ''
+        echo "# The following newsgroups are incorrectly marked as unmoderated"
+        echo "# and should have their status changed:"
+        echo "#"
+        ${SED} "s/^/#	/" ${T}/$$notmod
+        echo "#"
+        echo "# You can correct this by executing the command(s):"
+        echo ""
+        for i in `cat ${T}/$$notmod` ; do
+            echo "	${PATHBIN}/ctlinnd changegroup $i m"
+        done
+        echo ""
     ) >>${T}/$$out
 fi
 
+##  Display information on descriptions which need to be removed/added.
 if [ -s ${T}/$$removedesc ] ; then
     (
-        echo "# The following newsgroups descriptions are obsolete."
+        echo "# The following newsgroups descriptions are obsolete and should be removed:"
+        echo "#"
         ${SED} "s/^/#	/" ${T}/$$removedesc
-        echo "# You can remove them by editing ${NEWSGROUPS}."
-        echo ''
+        echo "#"
+        if [ "${UPDATEDESC}" = "true" ] ; then
+            echo "# The file ${NEWSGROUPS} has just been updated accordingly."
+        else
+            echo "# You can remove them by editing ${NEWSGROUPS}"
+            echo "# or by using the -u flag with docheckgroups."
+        fi
+        echo ""
     ) >>${T}/$$out
 fi
 
 if [ -s ${T}/$$missingdesc ] ; then
     (
-        echo "# The following newsgroups descriptions were missing and should be added."
+        echo "# The following newsgroups descriptions are missing and should be added:"
+        echo "#"
         ${SED} "s/^/#	/" ${T}/$$missingdesc
-        echo "# You can add them by editing ${NEWSGROUPS}."
-        echo ''
+        echo "#"
+        if [ "${UPDATEDESC}" = "true" ] ; then
+            echo "# The file ${NEWSGROUPS} has just been updated accordingly."
+        else
+            echo "# You can add them by editing ${NEWSGROUPS}"
+            echo "# or by using the -u flag with docheckgroups."
+        fi
+        echo ""
     ) >>${T}/$$out
 fi
 
-
+##  We're done.
 test -s ${T}/$$out && {
     cat ${T}/$$out
-    echo 'exit # so you can feed this message into the shell'
-    echo "# And remember to update ${NEWSGROUPS}."
-    test -s ${T}/$$ngdel && {
-	echo "# Remove these lines:"
-	${SED} "s/^/#	/" ${T}/$$ngdel
-	echo ''
-    }
-    test -s ${T}/$$ngadd && {
-	echo "# Add these lines:"
-	${SED} "s/^/#	/" ${T}/$$ngadd
-	echo ''
-    }
-    test -s ${T}/$$ngchng && {
-	echo "# Change these lines:"
-	${SED} "s/^/#	/" ${T}/$$ngchng
-	echo ''
-    }
+    echo "exit # so you can feed this message into the shell (as well as mod-active)."
+    echo ""
 }
 
 rm -f ${T}/$$*




More information about the inn-committers mailing list