: Shell script to collect readership list and send to remote site.
# Probably best to run as root to be able to read all user .newsrc files,
# but if you are concerned about security you may simply have to
# tell people to keep those files readable by somebody.

# It contains a line of the form: "Subject: feed sitename password"
# and a blank line.  "sitename" is your site's name.
# Directory with collection programs
FEEDBIN=/v/src/nl/lib
# Directory where feed information is kept, including one dir for
# each site you feed, and the password files etc.
BATCHDIR=/lg/lib/news/feed
# Make sure the pass file is readably ONLY by the user who will run
# this program, as it contains your system password for updating the
# feed file on the site that feeds you.
PASSFILE=$BATCHDIR/feedpass

# You will also want to customize the transmission command that sends
# the results of this script to your feed site.  That's at the bottom
# of this script.   You should also create the 'local_dels' sed script
# and 'add_default' file or per-site add_SITE files.

RCL=/tmp/rcl.$$
SUB=/tmp/sub.$$

if test $# -ne 1 ; then
	echo Usage:   collect "<sitename>"
	exit 1
	fi

# Start by collecting the site .newsrc files for sites YOU feed
# But delete the destination site, if you happen to feed back to them with
# a .newsrc
find $BATCHDIR -name newsrc -print | grep -v $1 >$RCL

# Add on any local permanent additions (hidden .newsrcs etc.)

if test -r $BATCHDIR/extrarc; then 
	cat $BATCHDIR/extrarc >>$RCL
fi

# Add the user's .newsrc files.  Add options to this command line to provide
# patterns for newsrc files used on your system.  The default is ".newsrc"

$FEEDBIN/listrc >>$RCL

# Now collect readership, but pass result through sed script that can
# delete any local groups which you don't want to bother asking
# for.  For example, there is no point in asking for hiearachies that you
# know the other site doesn't have or won't send you.  This can also be done
# with the standard deletion mechanisms at the other end, but it is more
# efficient for you to do it here.

# You may want to add something collected from nntp logs here, too.
if test -r $BATCHDIR/local_dels ; then
	SEDCOM="sed -f $BATCHDIR/local_dels"
else
	# delete local groups, by default
	SEDCOM="sed -e '/\./!d'"
fi

$FEEDBIN/arbit <$RCL | eval $SEDCOM >$SUB

# The sed script can contain stuff like "/^clari/d" and "/\./!d" to remove
# all groups without dots.

# Now concat your own local additions, either add_SITENAME or add__default

if test -r $BATCDIR/add_$1 ; then
	cat $BATCHDIR/add_$1 >>$SUB
 else
	if test -r $BATCHDIR/add__default ; then
		cat $BATCHDIR/add__default >>$SUB
	fi
fi


# Now add the password line and feed it off via uux or mail, choose the
# line you like below, or make your own.

# (grep "site=$1\$" $PASSFILE ; cat $SUB ) | uux - -r $1!setfeed
(grep "site=$1\$" $PASSFILE ; cat $SUB ) | cat >/tmp/report

# Use line below instead for mail link. 
# Note use of ! address below.  Switch to @ address if needed.
# (grep "site=$1\$" $PASSFILE; cat $SUB ) | mail $1!setfeed

# Clean up
rm -f $RCL $SUB
