#!/bin/sh
# This is a shell archive (shar 3.21)
# made 04/21/1995 12:26 UTC by tal@plts.org
# Source directory /home/tal/work.mgc/checkgroups/FTP
#
# existing files WILL be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   1562 -rw-r--r-- NOTES
#    700 -rwxr-xr-x checkfile
#    294 -rwxr-xr-x make.checkfile
#   3624 -rwxr-xr-x whatsent
#    123 -rwxr-xr-x prep.newsgroups
#   1376 -rwxr-xr-x regen.newsgroups
#
if touch 2>&1 | fgrep '[-amc]' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= NOTES ==============
echo "x - extracting NOTES (Text)"
sed 's/^X//' << 'SHAR_EOF' > NOTES &&
XCHECKFILE:
X	This does a "checkgroups" based on a file.
X1. Get the latest listing from ftp.uu.net:/uunet-info/newsgroups.Z
X	ncftp ftp.uu.net:/uunet-info/newsgroups.Z
X
X2. Run it as a checkgroups (output gets mailed to "news").
X	zcat newsgroups.Z | ./checkfile
X(ignore what it says about "add/delete/change these lines
Xin your newsgroups file, the REGENERATE stuff below
Xwill do that for you)
X
X
XWHATSENT:
X	This figures out what groups are sent to a site:
X1.  List the newsgroups sent to "plts":
X./whatsent plts
X2.  Generate a checkfile of just those newsgroups for that site:
X ./make.checkfile plts
X
XBUG:  newsgroups.Z sometimes has "newsgroup<space>description"
Xrather than "newsgroups<tab>description".  The script
Xprep.newsgroups fixes this.  (I think all the scripts now
Xpass newsgroups.Z though this script)
X
X
XREGENERATE YOUR /usr/lib/news/newsfeeds FILE:
X
X1. Get the latest listing from ftp.uu.net:/uunet-info/newsgroups.Z
X	ncftp ftp.uu.net:/uunet-info/newsgroups.Z
X2. Run it through this script, who's output is your new newsgroups file
X    zcat newsgroups.Z | ./regen.newsgroups | sort>/usr/lib/news/newsgroups.new
X(prep.newsgroups is not needed in the above command)
X3. Move it into place
X	rm -f /usr/lib/newsgroups.3
X	mv /usr/lib/news/newsgroups.2 /usr/lib/news/newsgroups.3
X	mv /usr/lib/news/newsgroups.1 /usr/lib/news/newsgroups.2
X	mv /usr/lib/news/newsgroups.0 /usr/lib/news/newsgroups.1
X	mv /usr/lib/news/newsgroups   /usr/lib/news/newsgroups.0
X	mv /usr/lib/news/newsgroups.new /usr/lib/news/newsgroups
X	chown news.news /usr/lib/news/newsgroups*
X
XTom
SHAR_EOF
$TOUCH -am 0421082595 NOTES &&
chmod 0644 NOTES ||
echo "restore of NOTES failed"
set `wc -c NOTES`;Wc_c=$1
if test "$Wc_c" != "1562"; then
	echo original size 1562, current size $Wc_c
fi
# ============= checkfile ==============
echo "x - extracting checkfile (Text)"
sed 's/^X//' << 'SHAR_EOF' > checkfile &&
X#! /bin/sh
X##  $Revision: 1.1 $
X##  Script to execute checkgroups based on file 
X 
X##  =()<. @<_PATH_SHELLVARS>@>()=
X. /usr/lib/news/innshellvars
XT=${TMPDIR}
X 
XPAT=`${AWK} '{ print $1 }' ${ACTIVE} | ${AWK} -F. '{ print $1 "\\\." }'\
X	| sort -u \
X	| (tr '\012' '|' ; echo '') \
X	| ${SED} -e 's/|$//'`
X
X#
X# Extract the hierarchies we want
X#
X${EGREP} "^(${PAT})" >/tmp/checkfile.$$.1
X
X#
X# remove the Warren censored groups
X#
X${EGREP} -v '^(alt\.sex\b|alt\.sex\.|rec\.arts\.erotica|alt\.binaries\.pictures\.erotica)' </tmp/checkfile.$$.1 >/tmp/checkfile.$$.2
X
X#
X# Ship this off to the docheckgroups script
X#
X${CONTROLPROGS}/docheckgroups </tmp/checkfile.$$.2
X
Xrm /tmp/checkfile.$$.1 /tmp/checkfile.$$.2
X
SHAR_EOF
$TOUCH -am 0421082595 checkfile &&
chmod 0755 checkfile ||
echo "restore of checkfile failed"
set `wc -c checkfile`;Wc_c=$1
if test "$Wc_c" != "700"; then
	echo original size 700, current size $Wc_c
fi
# ============= make.checkfile ==============
echo "x - extracting make.checkfile (Text)"
sed 's/^X//' << 'SHAR_EOF' > make.checkfile &&
X#! /bin/sh
X
X# This is a quick script that does what "NOTES" tell you
X# to do (the "zcat newsgroups.Z | sort | join -j2 1 -t'TAB' - /tmp/$$.1")
X# line.
X
Xecho \!mod
X./whatsent $1 | sort > /tmp/$$.1
Xsort < /usr/lib/news/newsgroups | ./prep.newsgroups | join -j2 1 -t'	' - /tmp/$$.1
X
Xrm /tmp/$$.1
X
SHAR_EOF
$TOUCH -am 0421082595 make.checkfile &&
chmod 0755 make.checkfile ||
echo "restore of make.checkfile failed"
set `wc -c make.checkfile`;Wc_c=$1
if test "$Wc_c" != "294"; then
	echo original size 294, current size $Wc_c
fi
# ============= whatsent ==============
echo "x - extracting whatsent (Text)"
sed 's/^X//' << 'SHAR_EOF' > whatsent &&
X#! /usr/local/bin/perl
X
X#
X# Given a host name, this outputs the list of newsgroups
X# that we send to that site.
X#
X
X$NEWSFEEDS_FILE = '/usr/lib/news/newsfeeds';
X#$NEWSGROUPS_FILE = '/usr/lib/news/newsgroups';
X$ACTIVE_FILE = '/usr/lib/news/active';
X
Xsub usage {
X	print <<END
XUsage:
X	whatsent hostname
XOutputs what newsgroups this site sends to hostname.
XEND
X;
X	exit 1;
X}
X
X#
X# Figure out site name
X#
X$HOST = shift;
X&usage unless $HOST;
X
X#
X# build $group_to_flag{}
X#
Xopen(ACTIVE, $ACTIVE_FILE) || die "Can't open $ACTIVE_FILE: $!";
Xwhile (<ACTIVE>) {
X	($name, $hi, $lo, $flag) = split;
X	$group_to_flag{ $name } = $flag;
X}
Xclose ACTIVE;
X
X#
X# build $group_to_description{}
X#
X#open(NG, $NEWSGROUPS_FILE) || die "Can't open $NEWSGROUPS_FILE: $!";
X#while (<NG>) {
X#	($name, @description) = split;
X#	$description = join(' ', @description);
X#	$group_to_description{ $name } = $description;
X#}
X#close NG;
X
Xsub donfline {
X	$_ = @_[0];
X	local($name, $glist, $flags, $file, $site, $excludelist, $grouplist, $distlist, @flags);
X	($name, $glist, $flags, $file) = split(':');
X	($site, $excludelist) = split('/', $name);
X	($grouplist, $distlist) = split('/', $glist);
X	(@flags) = split(',', $glist);
X#print STDERR "FEED=$site\n";
X	return ($site, $excludelist, $grouplist, $distlist, $file, @flags);
X}
X
X#
X# find ME line
X#
Xopen(NF, $NEWSFEEDS_FILE) || die "Can't open $NEWSFEEDS_FILE: $!";
X$line = "";
Xwhile (<NF>) {
X#	print;
X	next if /^\s*$/;
X	next if /^#/;
X	chop;
X	$line = $line . $_;
X	if (/\\$/) {
X		chop($line);
X		next;
X	} else {
X		# print "LINE=$line\n";
X		($site, $junk, $grouplist, @junk) = &donfline($line);
X		# print "SITE=$site\nLIST=$grouplist\n";
X		$site_to_list{$site} = $grouplist;
X#		$meline = $line if $line =~ /^ME:/;
X		$line = "";
X	}
X}
Xclose NF;
X# print "LINE=$line\n" if $line;
X($site, $junk, $grouplist, @junk) = &donfline($line) if $line;
X$site_to_list{$site} = $grouplist if $line;
X# print "SITE=$fname\nLIST=$grouplist\n" if $line;
X# print "MELINE=$meline\n";
X
X#print "\nComputing for DEFAULT\n";
X#
X# compute group defaults
X#
X#print join(" ", %site_to_list), "\n";
X
X#
X# $_ is site.
X# mark/unmark entries in $groups_we_send{}
X#
Xsub dosite {
X	local($site, $pat);
X	$site = @_[0];
X	$pat = $site_to_list{$site};
X
Xprint STDERR "******** HANDLING $site\n";
X	foreach ( split(',', $pat) ) {
X		print STDERR "WILDMAT=$_\n";
X		# is this a "take" or "remove"?
X		$set = ! /^\!/;		# 0= !foo,  1= foo
X		substr($_,0,1) = "" unless $set;
X		# convert from wildmat to Perl regex.
X		s/\./\\./g;
X		s/\*/.*/g;
X		s/\?/./g;
X		s/\+/\\+/g;
X		$pat = '^' . $_ . '$';
X
X#		# "take" or "remove" such newsgroups.
X#		foreach $group ( keys %group_to_flag ) {
X#			if ($group =~ /$pat/i) {
X#				if ($set) {
X#					$groups_we_send{ $group } = 1;
X#print STDERR "SENT=$group\n";
X#				} else {
X#					delete $groups_we_send{ $group };
X#print STDERR "NOT=$group\n";
X#				}
X#			}
X#		}
X
X		print STDERR "PERL=$pat\n";
X
X		# "take" or "remove" such newsgroups.
X		if ($set) {
X#			grep(/$pat/i && (print STDERR "ADD $_\n") && ($groups_we_send{$_}=1), keys %group_to_flag);
X			grep(/$pat/i && ($groups_we_send{$_}=1), keys %group_to_flag);
X		} else {
X#			grep(/$pat/i && (print STDERR "DEL $_\n") && delete($groups_we_send{$_}), keys %group_to_flag);
X			grep(/$pat/i && delete($groups_we_send{$_}), keys %group_to_flag);
X		}
X
X	}
X}
X
Xprint STDERR "\n";
Xprint STDERR "Computing for ME\n";
X&dosite('ME');
Xprint STDERR "Computing for $HOST\n";
X&dosite($HOST);
X
X#grep( (!$groups_we_send{$_}) && delete($groups_we_send{$_}), keys %groups_we_send);
X
X# output $groups_we_send{} in "checkgroups" format
Xprint STDERR "GROUPS WE SEND:\n";
Xprint join("\n", keys %groups_we_send ), "\n";
SHAR_EOF
$TOUCH -am 0421082695 whatsent &&
chmod 0755 whatsent ||
echo "restore of whatsent failed"
set `wc -c whatsent`;Wc_c=$1
if test "$Wc_c" != "3624"; then
	echo original size 3624, current size $Wc_c
fi
# ============= prep.newsgroups ==============
echo "x - extracting prep.newsgroups (Text)"
sed 's/^X//' << 'SHAR_EOF' > prep.newsgroups &&
X#! /usr/mgc/bin/perl
X
Xwhile (<>) {
X	@LIST = split;
X	print $LIST[0], "\t";
X	shift(@LIST);
X	print join(' ', @LIST), "\n";
X}
X
SHAR_EOF
$TOUCH -am 0421082595 prep.newsgroups &&
chmod 0755 prep.newsgroups ||
echo "restore of prep.newsgroups failed"
set `wc -c prep.newsgroups`;Wc_c=$1
if test "$Wc_c" != "123"; then
	echo original size 123, current size $Wc_c
fi
# ============= regen.newsgroups ==============
echo "x - extracting regen.newsgroups (Text)"
sed 's/^X//' << 'SHAR_EOF' > regen.newsgroups &&
X#! /usr/mgc/bin/perl
X
X#
X# This lists the newsgroup descriptions you need to add
X# to your $NEWSGROUPS_FILE.
X# (THIS ISN'T FINISHED YET)
X#
X
X$NEWSFEEDS_FILE = '/usr/lib/news/newsfeeds';
X$NEWSGROUPS_FILE = '/usr/lib/news/newsgroups';
X$ACTIVE_FILE = '/usr/lib/news/active';
X
Xsub usage {
X	print <<END
XUsage:
X	regen.newsgroups <masterlist >newlisting
XOutputs what newsgroups this site sends to hostname.
XEND
X;
X	exit 1;
X}
X
X#
X# Read In active file (build group_to_flag)
X#
X
X#
X# build $group_to_flag{}
X#
Xopen(ACTIVE, $ACTIVE_FILE) || die "Can't open $ACTIVE_FILE: $!";
Xwhile (<ACTIVE>) {
X	($name, $hi, $lo, $flag) = split;
X	$group_to_flag{ $name } = $flag;
X}
Xclose ACTIVE;
X
X#
X# Read In newsgroups file (build group_to_description);
X#
X
X#
X# build $group_to_description{}
X#
Xopen(NG, $NEWSGROUPS_FILE) || die "Can't open $NEWSGROUPS_FILE: $!";
Xwhile (<NG>) {
X	($name, @description) = split;
X	$description = join(' ', @description);
X	$group_to_description{ $name } = $description;
X}
Xclose NG;
X
X#
X# Read stdin and update group_to_descrtion if we get that newsgroup
X#
Xwhile (<>) {
X	($name, @description) = split;
X	$description = join(' ', @description);
X	$group_to_description{ $name } = $description if defined($group_to_flag{ $name } );
X}
X
X#
X# Output to stdout the group_to_description list.
X#
X
Xforeach ( keys %group_to_description ) {
X	print $_, "\t", $group_to_description{ $_ }, "\n";
X}
X
SHAR_EOF
$TOUCH -am 0421082595 regen.newsgroups &&
chmod 0755 regen.newsgroups ||
echo "restore of regen.newsgroups failed"
set `wc -c regen.newsgroups`;Wc_c=$1
if test "$Wc_c" != "1376"; then
	echo original size 1376, current size $Wc_c
fi
exit 0
