Gate - simple mail->news->mail gateway suite (Part 1 or 1)

Clay Luther cluther at supernet.haus.com
Thu Dec 20 14:15:15 AEST 1990


I wrote this one afternoon to handle the gating of mail to news and news to
mail.  It is written in script, and tries not to get too fancy.

If you have any questions or *especially* suggestions of improvements, please
email me at 

  cluther at supernet.haus.com
  uunet!supernet!cluther

Enjoy.

Clay Luther


#! /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:
#	GATE.README
#	gatenews
#	gatemail
#	inews.new
# This archive created: Wed Dec 19 21:07:02 1990
export PATH; PATH=/bin:$PATH
if test -f 'GATE.README'
then
	echo shar: will not over-write existing file "'GATE.README'"
else
cat << \SHAR_EOF > 'GATE.README'
GATE
----
Verion 1.0

Clay Luther, 1990

Synopsis:  Transfer mail to a news group, and news from that news group back
           to mail.  In effect, become a news/mail gateway.

[ It's a hack, yes, but it's a nice hack. ]

Gate is made up of 2 scripts, and a very slightly hacked version of the C News
inews.

gatemail:  Transfer a mail article (taken from stdin) to a news group via inews.

gatenews:  Transfer an article from news to a mailing list.

inews.new: An inews hack that allows the specification of no signature
           inclusion (-z).


Assumptions
-----------

These programs were written with the assumption you are running C News and
a mailing program that allows mail to be piped to a program via an alias (aka
sendmail or smail via the aliases file).  The C News dependency is only
reflected in the use of inews.new, which is simply the C News inews script
with about 4 lines of code added to suppress the inclusion of the executor's
signature file.


SETUP
-----

[ The directories and file names given are what gatenews and gatemail expect.
  You may easily edit both scripts to change these values. ]

[ Below, I will assume that mail is coming from some mailing list called 
  goof-l at foo.com. ]

Copy gatemail, gatenews, and inews.new to /usr/lib/news.  Make sure they are
+rw to everyone.

Next, create some mailing aliases.  You should have an incoming mail alias and
an outgoing mail alias.  They should be set up as:

#incoming alias
goof:"|/usr/lib/news/gatemail goof-l alt.goof"
#outgoing alias
goof-l:goof-l at foo.com

Create a sys entry for the gateway in /usr/lib/news/sys:

goof-l:alt.goof/all:F:/usr/spool/news/gatenews/goof-l

[ gatenews looks in /usr/spool/news/gatenews by default ]
Next, create a cron entry for gatenews (run by news, preferably):

#run gatenews after sendbatches
50 * * * * /usr/lib/news/gatenews goof-l goof-l goof

Subscribe to goof-l at foo.com as goof at your.site.

Finally:

addgroup alt.goof y

Your set.

What's Going On Here?
---------------------

Mail from the mailing list arrives at your site and is handed to the gatemail
program via stdin.

gatemail goof-l alt.goof < mail

The goof-l parameter states the real name of the mailing list.  The second
parameter states what group to post this article to.

Gatemail strips the mail headers off the mail after first grepping out the
subject, from, and reply-to lines.  It then adds a range of news headers:

Newsgroups: [set to alt.goof (aka parameter $2)]
From: [set to the From: line of the message]
Subject: [set to the Subject: of the message]
Reply-To: [set to the From: line of the message]
Organization: [set to the string "Gated to News by your.site"]
Path: [set to goof-l (aka the group name aka your alias for the mailing list)]
Sender: [set to the Reply-To: line of the message]
Lines: [set to the number of lines in the message]

The Path and Organization headers are especially important.  Gatenews (the
other script) checks the Organization header to determine if the news article
was gated to news from mail (and therefore should not be sent the other way).
The Path gives a valid path back through your machine to the mailing list by
way of your alias for the mailing list.

One last thing, gatenews installs a faux header "X-Gateway:" in articles
gated to mail.  If gatemail detects this X-Gateway: header (and it is from
this host), then the mail is appropriately ignored.

Here is a sample of how gatemail would work:

A Message comes in from goof-l:

>From utacfd.utarl.edu!mdaeng!goof-l at supernet.haus.com Wed Dec 19 13:52:06 1990
Return-Path: <utacfd.utarl.edu!mdaeng!goof-l at supernet.haus.com>
Received: from supernet.haus.com by enigma.haus.com (4.1/SMI-4.1)
        id AA00646; Wed, 19 Dec 90 13:52:05 CST
Received: by supernet.haus.com (/\=-/\ Smail3.1.18.1 #18.16)
        id <m0im9kD-0009NeC at supernet.haus.com>; Wed, 19 Dec 90 13:46 CST
Received: from mdaeng.UUCP by utacfd.utarl.edu with UUCP (4.0/25-eef)
        id AA14147; Wed, 19 Dec 90 13:26:02 CST
Received:  by mdaeng.mdaeng.com (4.0/25-eef)
        id AA10913; Wed, 19 Dec 90 12:48:50 CST
Date: Wed, 19 Dec 90 12:48:50 CST
From: mdaeng!rwn at utacfd.utarl.edu (Ralph Noack)
Reply-To: mdaeng!goof-l at utacfd.utarl.edu (Goofball Mailing List)
Message-Id: <9012191848.AA10913 at mdaeng.mdaeng.com>
To: goof at enigma.haus.com
Subject: Just Testing

This is just a friendly sample thingy.

This gets intercepted by the goof alias and piped to:

gatemail goof-l alt.goof

which produces the article:

Newsgroup: alt.goof
From: mdaeng!rwn at utacfd.utarl.edu (Ralph Noack)
Subject: Just Testing
Reply-To: mdaeng!rwn at utacfd.utarl.edu (Ralph Noack)
Organization: Gated to News by enigma.haus.com
Path: goof-l
Sender: mdaeng!goof-l at utacfd.utarl.edu (Goofball Mailing List)
Lines: 2

This is just a friendly sample thingy.

This gets piped to inews -z -h.  The -z option supresses the .signature
inclusion.  Inews will post the article to alt.goof.


On the other side, gatenews is pulling stuff off news and sending it to the
mailing list.

Every hour (or whenever), sendbatches executes and creates the file

/usr/spool/news/gatenews/goof-l

which contains a list of file names of articles in alt.goof that need to be
mailed (or might need to be mailed).

After sendbatches is run, gatenews is run

gatenews goof-l goof-l goof

where the first parameter is the address/alias to mail the articles to, the
second parameter is the name of the spool file in /usr/spool/news/gatenews,
and goof is the local alias of the mailing list (need to set the From: line of
the article viz mail).

Gatenews processes the articles in the spool file one by one.  First, it checks
the message id's of the article against a log file; if the message id is in the
log file, then the article is not mailed.  Next, the Organization: line is 
checked.  If it is equal to "Gated to News by <this.site>", then the article
is not mailed.

If the article gets past those tests, then it is assumed to be OK for mailing.
The From: and Subject: lines are grepped out of the article and the rest of the
headers are trashed.  The mailer program is then called, setting the appropriate
fields and piping the rest of the article to it.

In the original gatenews, fastmail is used.  Fastmail is part of the Elm
package.  Sendmail could be used instead, but you will have to hack the line
that performs the mailing in gatenews.

Gatenews logs the message in its log file and cleans up.


Other Files
-----------

/usr/lib/news/gatemail.log
/usr/lib/news/gatenews.log 


If you have any questions or ESPECIALLY enhancements or suggestions, please
mail me at


cluther at supernet.haus.com
uunet!supernet!cluther

Clay Luther

SHAR_EOF
fi # end of overwriting check
if test -f 'gatenews'
then
	echo shar: will not over-write existing file "'gatenews'"
else
cat << \SHAR_EOF > 'gatenews'
:
# gatenews - a script to gate news from news to mail
# Clay Luther, 1990, Version 1
# cluther at supernet.haus.com
# Usage: gatenews dest spoolfile from

# Defines
SPOOL='/usr/spool/news/gatenews'
NEWSDIR='/usr/lib/news'

if [ $# -ne 3 ]
then
  echo "Usage: gatenews dest spoolfile from"
  echo "  where dest is the address of the destination, and"
  echo "  spoolfile is the name of a file in $SPOOL"
  echo "  from is the local address to set the from line to"
  exit 1
fi

DEST=$1
HIST="$NEWSDIR/gatenews.log"
SFILE="$SPOOL/$2"
NEWS='news'
MAIL='/usr/local/bin/fastmail'
TMP="/tmp/gate$$"
MAILNAME="$NEWSDIR/mailname"
HOST=`cat $MAILNAME`
ORG="Gated to News by $HOST" 
FNAME="$3@$HOST"


if [ ! -f "$SFILE" ]
then
  exit 0
fi

if [ ! -f "$HIST" ]
then
  echo "" | cat > $HIST
  chmod +rw $HIST
  chown $NEWS $HIST
fi

S=`cat $SFILE`
rm -f $SFILE

for F in $S
do
  if [ -f "$F" ] 
  then
#    echo $F
    MID=`grep "^Message-ID:" $F`   # Obtain Message ID
    if [ "$MID" ]
    then
      INSTR="$MID -> $DEST"
      PREV=`grep "$MID" $HIST`          # Check for it in gatehist file
      if [ -z "$PREV" ]
      then  # he hasn't been mailed before

# Get the Organization Line - IMPORTANT
        FORG=`grep "^Organization:.*$ORG" $F`   
        if [ ! "$FORG" ]
        then   # it's ok, we didn't make this!
#more $F
        # Save the From line
        FROM=`grep "^From:" $F | awk '{ \
                                    size=split($0,s)
                                    for (i=2;i<=size;i++) {
                                      printf("%s ",s[i])
                                    }
                                    printf("%s","\n")
                                    }'`
        # Save the Subject line
        SUBJ=`grep "^Subject:" $F | awk '{ \
                                    size=split($0,s)
                                    for (i=2;i<=size;i++) {
                                      printf("%s ",s[i])
                                    }
                                    printf("%s","\n")
                                    }'`

        # Make an entry in $TMP
        (
        echo "X-Gateway: $HOST"
        ) | cat > $TMP

        # The above is necessary to catch mail echoed back to us!

        # Strip away the news headers and store output in $TMP
        awk '\
               BEGIN {
                 x=0
               }
               {
                 if ( x == 0 ) {
                   if ( NF == 0 ) {
                     x=1
                   }
                 } else {
                   print $0
                 }
               }' $F >> $TMP 

         # OK, we have a From line, a Subject Line, and a source file
         # Time to mail it and log it
         
         # This line may need tweaking, depending on your mailer
         $MAIL -r "$FROM" -s "$SUBJ" -f "$FNAME" $TMP $DEST
         # Log the message id
         echo $INSTR | cat >> $HIST
       fi  # we didn't make it
       fi  # wasn't in hist file
     fi    # if grep $MID
   fi    # $F existed
done     # with loop

# Clean up
rm -f $TMP

# Check the $HIST log for being way too long
LEN=`wc -l $HIST | awk '{print $1}'`
if [ $LEN -gt 2000 ]
then
  tail -2000 $HIST > $TMP
  mv $TMP $HIST
fi
SHAR_EOF
chmod +x 'gatenews'
fi # end of overwriting check
if test -f 'gatemail'
then
	echo shar: will not over-write existing file "'gatemail'"
else
cat << \SHAR_EOF > 'gatemail'
:
# gatemail - accept a mail message and gate it to a newsgroup
# Clay Luther, 1990, Version 1
# cluther at supernet.haus.com
# usage: gatemail group newsgroup < mailfile

# Check for a parameter
if [ $# -ne 2 ]
then
  echo "Usage: gatemail newsgroup < mailfile"
  exit 1
fi

TMP="/tmp/gm$$"
cat > $TMP

F="/tmp/GM$$"
INEWS='/usr/lib/news/inews.new'
GROUPNAME=$1
GROUP=$2
NEWSDIR='/usr/lib/news'
LOG="$NEWSDIR/gatemail.log"
NEWS='news'
MAILNAME="$NEWSDIR/mailname"
HOST=`cat $MAILNAME`
ORG="Gated to News by $HOST"
POST="/tmp/post$$"

if [ ! -f $LOG ]
then
  echo "" | cat > $LOG
  chmod +rw $LOG
  chown $NEWS $LOG
fi

XGATE=`grep "^X-Gateway:.*$HOST" $TMP`

if [ ! "$XGATE" ]
then

FROM=`grep "^From:" $TMP | awk '{ \
                            size=split($0,s)
                            for (i=2;i<=size;i++) {
                              printf("%s ",s[i])
                            }
                            printf("%s","\n")
                            }'`

REPLY=`grep "^Reply-To:" $TMP | awk '{ \
                            size=split($0,s)
                            for (i=2;i<=size;i++) {
                              printf("%s ",s[i])
                            }
                            printf("%s","\n")
                            }'`

SUBJ=`grep "^Subject:" $TMP | awk '{ \
                            size=split($0,s)
                            for (i=2;i<=size;i++) {
                              printf("%s ",s[i])
                            }
                            printf("%s","\n")
                            }'`

# Strip away the headers
awk '\
       BEGIN {
         x=0
       }
       {
         if ( x == 0 ) {
           if ( NF == 0 ) {
             x=1
           }
         } else {
           print $0
         }
       }' $TMP > $F 

# call inews to mail it
LINES=`wc -l $F | awk '{print $1}'`
LINES=`expr $LINES + 7`
(
echo "Newsgroups: $GROUP"
echo "From: $FROM"
#echo "From: $REPLY"
echo "Subject: $SUBJ"
#echo "Reply-To: $REPLY"
echo "Reply-To: $FROM"
echo "Organization: $ORG"
echo "Path: $GROUPNAME"
echo "Sender: $REPLY"
echo "Lines: $LINES"
echo ""
cat $F
) | cat > $POST

$INEWS -z -h $POST

DATE=`date`
# Log it
echo "$DATE $GROUP: $FROM [$SUBJ]" >> $LOG

fi # this was gated from news by us and echoed by the target

#Clean up
rm -f $TMP $F $POST

# Clean up the log if it is too long
LENGTH=`wc -l $LOG | awk '{print $1}'`
if [ $LENGTH -gt 1000 ]
then
  tail -1000 $LOG > $TMP
  mv $TMP $LOG
fi
SHAR_EOF
chmod +x 'gatemail'
fi # end of overwriting check
if test -f 'inews.new'
then
	echo shar: will not over-write existing file "'inews.new'"
else
cat << \SHAR_EOF > 'inews.new'
: /bin/sh
# inews [-p] [-debug k] [-x site] [-hMD] [-t subj] [-n ng] [-e exp] [-F ref] \
#  [-d dist] [-a mod] [-f from] [-o org] [-C ng] [file...] - inject news:
#	censor locally-posted article and field the "inews -C" kludge;
#	munge the articles, enforce feeble attempts at Usenet security,
#	generate lots of silly headers.
#
# Yes, it's big, slow and awkward.  The alternative is casting a lot of
# local policy in C.

# =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
 ${NEWSCONFIG-/usr/lib/news/bin/config}
export NEWSCTL NEWSBIN NEWSARTS NEWSPATH NEWSUMASK NEWSMASTER NEWSCONFIG
PATH=$NEWSCTL/bin:$NEWSBIN/inject:$NEWSBIN/relay:$NEWSBIN:$NEWSPATH; export PATH
PASSEDFROM='';	export PASSEDFROM	# passed to anne.jones in environ.

debug=''			# flags
exclusion=''
hdrspresent=no
autopost=no
waitcmd='status=0'
relayopts=-i			# redirect stdout to log

input=/tmp/in$$in		# uncensored input
inhdrs=/tmp/in$$hdr		# generated by tear: headers
inbody=/tmp/in$$body		# generated by tear: body
censart=/tmp/in$$cens		# censored input
nglist=/tmp/in$$ngs		# newsgroups: list
modroute=/tmp/in$$route		# route to moderator's forwarder
exitflag=/tmp/in$$exit		# exit status, if present
outfile=/tmp/in$$out		# relaynews stdout
rmlist="$inhdrs $inbody $input $censart $nglist $modroute $exitflag $outfile"
grpok=/tmp/in$$grp		# flag file: groups okay if present

# cluther addition
nosig=no

umask $NEWSUMASK

# "inews -p": invoke rnews
case "$1" in
-p)
	shift
	cat $* | relaynews -r	# feed directly to relaynews, seat belts off
	exit
	;;
esac

# process arguments: for options, cat headers onto $input; cat files onto $input
>$input
cleanup="test ! -f $HOME/dead.article -o -w $HOME/dead.article &&
  cat $input >>$HOME/dead.article &&
  { echo $0: article in $HOME/dead.article >&2; rm -f $rmlist; }; exit 1"
trap "$cleanup" 0 1 2 3 15
while :
do
	case $# in
	0)	break ;;		# arguments exhausted
	esac

	case "$1" in
	# peculiar to C news
        -z) shift; nosig=yes;;
	-debug)	shift; debug="$1" ;;
	-A)	autopost=yes ;;		# wait for free space
	-V)	relayopts= ;;		# verbose: don't redirect stdout (or stderr)
	-W)	waitcmd='wait; status=$?' ;;	# wait for completion
	# useful standard options
	-h)	hdrspresent=yes ;;
	-x)	shift; exclusion="-x $1" ;;	# you're welcome, erik (2.11)
	# silly options supplied by newsreaders
	-a)	shift; echo "Approved: $1" >>$input ;;
	-c)	shift; echo "Control: $1" >>$input ;;
	-d)	shift; echo "Distribution: $1" >>$input ;;
	-e)	shift; echo "Expires: $1" >>$input ;;
	-f)	shift; echo "From: $1" >>$input ;;
	-n)	shift; echo "Newsgroups: $1" >>$input ;;
	-r)	shift; echo "Reply-To: $1" >>$input ;;
	-t)	shift; echo "Subject: $1" >>$input ;;	# aka Title:
	-D)	# obsolete, undocumented: meant "don't check for recordings".
		# last present in B 2.10.1, invoked by readnews for followups.
		;;
	-F)	# undocumented in B 2.10.1, documented in B 2.11.
		shift; echo "References: $1" >>$input ;;
	-M)	# this apparently just sets From: to the author of the article
		# instead of the poster (moderator), by leaving the From: line
		# alone (under -h); easy to implement.
		;;

	# pass next options as environment variables to anne.jones
	-o)	shift; ORGANIZATION="$1"; export ORGANIZATION ;;

	-C)
		cat <<eg >&2
$0: you either want to use addgroup (see newsaux(8)) to make
$0: $2 locally, or this to make it network-wide:
inews -h <<'!'
Control: newgroup $2
Subject: newgroup $2
Newsgroups: $2
Approved: you at hostname

Non-empty.
!
eg
		exit 1
		;;
	-*)
		echo "$0: bad option $1" >&2
		exit 1
		;;
	*)					# is a filename; append file
		# B 2.11 kludge: assume -h if input starts with headers.
		# apparently the B 2.11 newsreaders assume this.
		tear /tmp/in$$ <$1
		if test -s $inhdrs; then
			hdrspresent=yes
		fi

		case "$hdrspresent" in
		no)	echo "" >>$input; hdrspresent=yes ;;
		esac
		# capture incoming news in case relaynews fails
		if cat $inhdrs $inbody >>$input; then
			: far out
		else
			echo "$0: lost news; cat status $?" >&2
			exit 1
		fi
		fileseen=yes
		;;
	esac
	shift		# pass option or filename (any value was done above)
done

# if no files named, read stdin
case "$fileseen" in
yes)	;;
*)
	# B 2.11 kludge: assume -h if input starts with headers
	# apparently the B 2.11 newsreaders assume this.
	tear /tmp/in$$
	if test -s $inhdrs; then
		hdrspresent=yes
	fi

	case "$hdrspresent" in
	no)	echo "" >>$input; hdrspresent=yes ;;
	esac
	# capture incoming news in case relaynews fails
	if cat $inhdrs $inbody >>$input; then
		: far out
	else
		echo "$0: lost news; cat status $?" >&2
		exit 1
	fi
	;;
esac
trap '' 1 2 15			# ignore signals to avoid losing articles

# run the remainder in the background for the benefit of impatient people
# who lack a window system
(
trap "$cleanup" 0
tear /tmp/in$$ <$input		# output in $inhdrs and $inbody
# canonicalise header keyword capitalisation.
# greps for Control: and Approved: later assume this, as does defhdrs.awk.
canonhdr <$inhdrs >/tmp/in$$realtmp
mv /tmp/in$$realtmp $inhdrs
# pad zero-line articles, since old B [ir]news are confused by them
# and the news readers generate zero-line control messages, alas.
if test ! -s $inbody; then
	(echo '';
	 echo This article was probably generated by a buggy news reader.) \
	 >$inbody
fi

# deduce which tr we have: v6 or v7
case "`echo B | tr A-Z a-z `" in
b)	trversion=v7 ;;
B)	trversion=v6 ;;			# or System V
esac
export trversion

# post with new headers and .signature
(anne.jones <$inhdrs		# bash headers
# UNCOMMENTED
#lines="`			# sop to msb, just uncomment to use
#(sed 1d $inbody;	# take out the first (blank) line
#if test -r $HOME/.signature; then
#	echo '-- '
#	sed 4q $HOME/.signature
#fi) | wc -l `"
#echo Lines: $lines
# UNCOMMENTED

 # strip invisible chars from body, a la B news.  bells and escapes are right out.
 case "$trversion" in
 v7)	tr -d  '\1-\7\13\15-\37' ;;
 v6)	tr -d '[\1-\7]\13[\15-\37]' ;;
 esac <$inbody

if test "$nosig" = "no"; then
 if test -r $HOME/.signature; then
	echo "-- "; sed 4q $HOME/.signature	# glue on first bit of signature
 fi
fi) >$censart
### the article is fully assembled now in $censart ###

# to post or to mail? that is the question; whether 'tis nobler in the mind
# to suffer the slings and arrows of outrageous mailers - Bill Shakespeare
if grep -s '^Control:' $inhdrs >/dev/null; then
	echo "control"			# a dreadful hack around all.all.ctl
else
	sed -n '
/^Newsgroups:[	 ]/{
s/^Newsgroups:[	 ]*\(.*\)$/\1/p
q
}
' <$inhdrs
fi >$nglist

if test ! -s $nglist; then		# no Newsgroups:
	exit 1				# anne.jones will have already complained
fi

# look up groups in active, to determine disposition of this message.
# n, x and (unapproved) m flags are dealt with on the spot; if none are
# seen, the article is posted normally.
# escape egrep metacharacters.  In theory one could add " ' ` \ to the list.
egreppat="^(` sed -e 's/[.+*()|[]/\\\\&/g' -e 's/,/|/g' <$nglist `) "
egrep "$egreppat" $NEWSCTL/active >/dev/null || {
	echo "$0: `cat $nglist` matches no groups in $NEWSCTL/active" >&2
	exit 1
}
rm -f $grpok
egrep "$egreppat" $NEWSCTL/active |
	(while read ng high low flag junk	# look at next group's active entry
	do
		>>$grpok
		case "$flag" in
		[nx])
			echo "$0: sorry, $ng may not be posted to locally." >&2
			trap 0		# this is a child process - no cleanup here
			echo 1 >$exitflag
			exit 1		# dregs in /tmp/in$$*
			;;
		m)
			if grep -s '^Approved:[	 ]' $inhdrs >/dev/null; then
				:		# just post normally
			else
				# un-Approved article: mail it to the moderator(s).
				# look for a route for this group.
				# a dreadful B 2.11 hack: backbone == all
				(sed 's/^backbone[	 ]/all /' \
							$NEWSCTL/mailpaths |
						gngp -a -r "`cat $nglist`";
						echo 'default	%s') |
					sed -n "1{s/^[^	 ]*[	 ][	 ]*//
					  s/%s/` echo $ng | tr . - `/;p;q;}" \
						>$modroute
				moderator="`cat $modroute `"
				# TODO: next line confuses nn; change to stdout?
				echo "$0: mailing your article to $moderator" >&2
				mail "$moderator" <$censart
				trap 0	# this is a child process - no cleanup here
				echo 0 >$exitflag
				exit 0
			fi
			;;

			# "" matches short active entries,
			#	to be backward compatible.
			# * matches garbage flags, to be cautious.
		y|""|*)
			# okay so far, but wait until we see all Newsgroups:.
			;;
		esac
	done
	trap 0					# paranoia - no clean up
	)
if test ! -r $grpok; then
	echo "$0: no active groups in `cat $nglist`" >&2
	exit 1			# abnormal exit - cleans up, makes dead.article
fi
rm -f $grpok
if test -f $exitflag; then
	exitstatus="`cat $exitflag`"
	case "$exitstatus" in
	0)	rm -f $rmlist; trap 0 ;; # normal exit - cleanup, no dead.article
	esac
	exit $exitstatus	# trap 0 may cleanup, make dead.article
fi

### if the article was mailed, that happened above; posting will happen below ###

# deal with inadequate free space
case "$autopost" in
no)
	if test "`spacefor 1 articles`" -le 0; then
		echo "$0: too little space free on $NEWSARTS" >&2
		exit 1			# dregs in /tmp/in$$* for trap 0
	fi
	;;
*)
	iter=0
	while test "`spacefor 1 articles`" -le 0 -o "`spacefor 1 control`" -le 0
	do
		sleep 30
		iter=`expr $iter + 1`
		case "$iter" in
		3)
			mail "$NEWSMASTER" <<!
Subject: free space too low on $NEWSARTS

There is too little free space on $NEWSARTS for inews to run comfortably.
!
			;;
		esac
	done
	;;
esac

# to get here, we must have seen no n, x, nor (unapproved) m flags.
# <$censart is used rather than a pipe to work around a bug in the 4.2 sh
# which made it sometimes return the wrong exit status (that of anne.jones).
# execute relaynews commands on the server, for the sake of locking.
# may not use "exec" or sh will leave /tmp/sh* files from here docs in /tmp.
me="`hostname`"
server=`cat $NEWSCTL/server 2>/dev/null`
case "$server" in
"")	server="$me" ;;			# if no server file, assume this is it
esac
case "$me" in
$server)
	relaynews $relayopts -s $exclusion -d "$debug" <$censart
	status=$?
#	echo "status $? from relaynews" >>/tmp/inewsdebug # DEBUG
	;;
*)
	# send article+commands to remote shell, including clean up
	(echo "sed 's/^-//' >/tmp/irsh\$\$ <<'!'"	# remove guard
	 sed 's/^[^A-EG-Za-z0-9]/-&/' $censart	# prepend guard
	 echo !
	 cat <<!
PATH=$PATH relaynews $relayopts -s $exclusion -d "$debug" </tmp/irsh\$\$
!
	 echo 'echo status $?'
	 echo 'rm -f /tmp/irsh$$') |
		rsh $server /bin/sh >$outfile

	status=`sed -n '/^status /s///p' $outfile `
	sed '/^status /d' $outfile	# print relaynews's stdout
	;;
esac
case "$status" in
0)
	rm -f $rmlist			# far out, it worked: clean up
	if test ! -f $NEWSCTL/sys; then
		echo "$0: $NEWSCTL/sys missing; your news can't leave this machine" >&2
	fi
	trap 0				# normal exit: cleanup done
	;;
esac
exit $status				# trap 0 may cleanup, make dead.article
) &
eval $waitcmd				# wait & get status if -W given
trap 0					# let the background run on unmolested
exit $status
SHAR_EOF
chmod +x 'inews.new'
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
Clay Luther, Postmaster          cluther at supernet.haus.com 
  Harris Adacom Corporation      cluther at enigma.haus.com
  Voice:  214/386-2356           MS 23, PO Box 809022, Dallas, Tx 75380-9022
  Fax:    214/386-2159           Your mileage may vary.  Void where prohibited.



More information about the Alt.sources mailing list