[mod.sources] extract usenet moderator list from postings

sources-request@panda.UUCP (01/24/86)

Mod.sources:  Volume 3, Issue 94
Submitted by: seismo!sun!calma!adams (Robert Adams)


The following is an awk script that builds the usenet moderators
list for from the list of moderators posted to mod.newslists.
I wish this operation was automatic (like checkgroups) but this
makes maintaining it much easier.

	adams@calma.UUCP		-- Robert Adams
	...!{sun,ucbvax}!calma!adams
------------------ cut here ------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	README
#	modgen
#	getpath
# This archive created: Wed Jan 22 09:36:33 1986
export PATH; PATH=/bin:$PATH
echo shar: extracting "'README'" '(1308 characters)'
if test -f 'README'
then
	echo shar: will not over-write existing file "'README'"
else
sed 's/^	X//' << \SHAR_EOF > 'README'
	X*** Build moderators list from mod.newslists posting ***
	X
	X'modgen' is a script that attempts to build a moderators list
	Xfor the usenet software from the list of moderators that is posted
	Xto mod.newslists.  It attempts to find two portions of the
	Xposted information: 1) a listing of other domain to uucp domain
	Xmappings (lines with "==" in them), and 2) a listing of moderated
	Xgroup to internet address mapping.  I then substitutes the uucp
	Xaddress for the corresponding other domain address and outputs
	Xthat list.
	X
	XThis list is then processed through a program called 'getpath'.
	X'getpath' is a quick script that takes an internet formed address
	Xand, using the pathalias generated file, creates a uucp path
	Xaddress.  'getpath' does not know about other domains -- it is
	Xonly good for uucp hosts so some use of 'grep' is made to
	Xseperate address that are in the uucp domain from address in
	Xother domains (at our site, we've modified sendmail.cf to fob
	Xdomains off onto our smarter neighbors).
	X
	XThe output of 'modgen' is a correctly formatted moderators
	Xlist all ready for placing into /usr/lib/news/moderators.  It
	Xis always best, though, to check the file to just make sure.
	X
	XThis script worked on the posted moderators list for January 1986.
	X
	X	adams@calma.UUCP		-- Robert Adams
	X	...!{sun,ucbvax}!calma!adams
SHAR_EOF
if test 1308 -ne "`wc -c < 'README'`"
then
	echo shar: error transmitting "'README'" '(should have been 1308 characters)'
fi
fi # end of overwriting check
echo shar: extracting "'modgen'" '(2524 characters)'
if test -f 'modgen'
then
	echo shar: will not over-write existing file "'modgen'"
else
sed 's/^	X//' << \SHAR_EOF > 'modgen'
	X#! /bin/sh
	X#   6 Dec 85 Robert Adams: as released
	X#  16 Dec 85 Robert Adams: check for uucpPath being null
	X#
	X#  This is a hack that reads the list of moderators the is
	X#  posted to mod.newslists and attempts to build a
	X#  /usr/lib/news/moderators file.  It depends greatly on the
	X#  format of the information in the posting because the posting
	X#  is in human readable form and is not easily parsed.
	X#  There is one section that gives a internet to uucp address
	X#  mapping (lines with double equals "==" in them) and another
	X#  section that lists moderated groups and the internet
	X#  address of the moderator.  This thing takes the first
	X#  section and attempts to build the uucp "internet-like"
	X#  addresses for the moderators.  It outputs this to a temp
	X#  file and then invokes 'getpath' to change the uucp addresses
	X#  into uucp paths.  The output is in the format of the moderators
	X#  file.
	X#  Invocation is:
	X#     modgen < /usr/spool/news/mod/newslist/?? > /usr/lib/news/moderators
	X#  but it usually best to look at the file and "clean it up".
	X#
	Xawk '
	XBEGIN {
	X	state = "begin";
	X}
	X#scan and fetch the internet to uucp mapping
	X(state == "begin" || state == "uucpmapping") && /.*==.*/ {
	X	uucpmap[$1] = $3;
	X	state = "uucpmapping";
	X}
	X#scan upto the final table
	Xstate == "uucpmapping" && /^Group[	]*Submissions$/ {
	X	state = "modmapping";
	X}
	X#suck up the group to internet address mapping
	Xstate == "modmapping" && /.*@.*/ {
	X	modgroup[$1] = $1;
	X	modmap[$1] = $2;
	X	# (some entries have two addresses seperated by comma. Remove second one)
	X	if (index(modmap[$1], ",")) {
	X		modmap[$1] = substr(modmap[$1], 1, index(modmap[$1], ",")-1 );
	X	}
	X}
	XEND {
	X	if (state == "modmapping") {
	X		# for each internet addr, replace internet host with uucp host
	X		for (mod in modgroup) {
	X			host = substr(modmap[mod], index(modmap[mod], "@")+1);
	X			if (length(uucpmap[host])) {
	X				modmap[mod] = substr(modmap[mod], 0, index(modmap[mod], "@"));
	X				modmap[mod] = modmap[mod] uucpmap[host];
	X			}
	X		}
	X		# output all of the addresses
	X		for (mod in modgroup)
	X			print modgroup[mod] "		" modmap[mod];
	X	}
	X	else {
	X		print "invalid input file format";
	X	}
	X}
	X' > /tmp/modgenA$$
	Xset - `grep ".uucp$" /tmp/modgenA$$`
	X# for each uucp domain addr, map internet addr to uupc path
	Xwhile [ "X$1" != "X" ] ; do
	X	uucpPath=`getpath $2`
	X	if [ "$uucpPath" = "" ] ; then
	X		uucpPath=$2
	X	fi
	X	echo $1 "		" $uucpPath >> /tmp/modgenB$$
	X	shift; shift
	Xdone
	X# combine uucp and other domain address lines
	Xgrep -v ".uucp$" /tmp/modgenA$$ | cat - /tmp/modgenB$$
	Xrm /tmp/modgen[A-Z]$$
SHAR_EOF
if test 2524 -ne "`wc -c < 'modgen'`"
then
	echo shar: error transmitting "'modgen'" '(should have been 2524 characters)'
fi
chmod +x 'modgen'
fi # end of overwriting check
echo shar: extracting "'getpath'" '(1554 characters)'
if test -f 'getpath'
then
	echo shar: will not over-write existing file "'getpath'"
else
sed 's/^	X//' << \SHAR_EOF > 'getpath'
	X#!/bin/csh -f
	X#   1 Dec 85 Tim Radzykewycz: as released
	X#   2 Jan 86 Robert Adams: removed debugging, parameterized things, commented
	X#
	Xset BANG = '\!'
	Xset PathFile = "/usr/spool/uumap/paths"
	X#
	X#  Find host name and user name.  This should be able to parse
	X#  addresses of the form uname@host and host!uname, and the
	X#  first form should have priority, so that the combined
	X#  form 'host1!uname@host0' can be used.
	X#  Notice that this doesn't know about domaining!  In fact, it
	X#  strips any internet type domaining out before doing the host
	X#  search in the PathFile.
	X#
	X#  Invocation is:  getpath address
	X#  where getpath will output to standard out the path to the
	X#  user found in the PathFile.  If no path is found, the
	X#  unmodified path is output.  If no "address" is given, getpath
	X#  reads it from standard input.
	X#
	Xecho $1 | sed 's/\..*//' > /tmp/$$
	Xif ("$1" == "") then
	X    echo $< | sed 's/\..*//' > /tmp/$$
	Xendif
	Xgrep -s '@' /tmp/$$
	X# if there were matches, use form 'uname@host'
	Xif ($status == 0) then
	X    set host = `sed -e "s/.*@//" /tmp/$$`
	X    set uname = `sed -e "s/${host}//" -e "s/@//" /tmp/$$`
	Xelse
	X    set host = `sed -e "s/${BANG}.*//" /tmp/$$`
	X    set uname = `sed -e "s/${host}//" -e "s/${BANG}//" /tmp/$$`
	Xendif
	X#
	X#  Now, find the path to that host, and tack on the uname
	X#  to the end of it.
	Xset e_path = `grep "^${host}	" $PathFile`
	Xset uupath=`echo ${e_path} | sed -e 's/.*[ 	]//' -e "s/%s/${uname}/" | sed -e "s/${BANG}${BANG}/${BANG}/g"`
	Xif ("$uupath" == "") then
	X	set uupath=`cat /tmp/$$`
	Xendif
	Xecho $uupath
	Xrm -f /tmp/$$
SHAR_EOF
if test 1554 -ne "`wc -c < 'getpath'`"
then
	echo shar: error transmitting "'getpath'" '(should have been 1554 characters)'
fi
chmod +x 'getpath'
fi # end of overwriting check
#	End of shell archive
exit 0