[net.sources] A revised and enhanced RNGET script.

tron@nsc.UUCP (Ronald S. Karr) (08/29/86)

Recently, I received some revisions to the rnget script that I posted
to the net a few weeks ago (Message-ID: <3739@nsc.UUCP>).  The revision
was from Robert O. Domitz <rod@pecnos.UUCP> and added a feature for
saving the text of an article prior to the shar archive to some file.
I liked the idea.  I also recently added a feature to make it possible
for the archive to be filtered through a command other than /bin/sh.

The shell archive below contains these two new revisions, plus some
small bug fixes (well, typo fixes).

  Ronald S. Karr			USENET: hplabs!nsc!tron
  National Semiconductor, Sunnyvale	ARPA:   tron@nsc.NSC.COM
---------------------- 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:
#	rnget.1
#	rnget
# This archive created: Thu Aug 28 18:10:50 1986
export PATH; PATH=/bin:/usr/bin:$PATH
echo shar: "extracting 'rnget.1'" '(2606 characters)'
if test -f 'rnget.1'
then
	echo shar: "will not over-write existing file 'rnget.1'"
else
sed 's/^	X//' << \SHAR_EOF > 'rnget.1'
	X.TH RNGET 1 local
	X.ad b
	X.SH NAME
	Xrnget \- unbundle a shell archive package
	X.SH SYNOPSIS
	X\fBrnget\fR [\fB-p\fI pattern\fR] [\fB-r \fIfile\fR]
	X[\fB-f \fIprog\fR] [\fIdirectory\fR]
	X.SH DESCRIPTION
	X.B rnget
	Xunbundles the distribution package into the specified directory.
	XIf the directory does not exist, it is created.
	X.PP
	X.B rnget
	Xchanges to the given directory (if given) and then
	Xreads its standard input and searches for the given pattern
	X(default to "[#:]") at the beginning of a line.
	XAll lines previous to that are saved in a file.
	XThe line with the pattern and all subsequent lines are passed
	Xto the standard input of \fIprog\fR (default /bin/sh) for processing.
	X.PP
	XThe idea is that the input is a shar file contained inside
	Xof a news article, with a scan done before hand for the
	Xbeginning of the shar.  For shars that don't begin with `#'
	Xor `:' \fB-p\fP can be used to specify something else.
	X.PP
	X.B rnget
	Xcan be used from `rn' using the command:
	X.sp 1
	X.ce
	X| rnget directory
	X.sp 1
	Xto cause the shell archive contained in the current article to be
	Xextracted (using a rather simple algorithm) and piped into /bin/sh
	Xfor processing.  Unlike the simpler:  w | (cd dir; sh)  command,
	Xthis works if there is text before the actual start of the archive.
	X.PP
	XAvailable options are:
	X.TP 7
	X.B \-p
	XThe next argument is interpreted to be the search pattern to be used
	Xto indicate the end of the text to be saved in the file and the
	Xbeginning of the text to be passed to the shell.
	XThe default pattern is "[#:]".
	X.TP 7
	X.B \-r
	XThe next arguement is interpreted to be the name of the file which
	Xthis routine saves the material at the beginning of the article before
	Xthe pattern is encountered.
	XThe default name is "READ_ME".
	X.TP 7
	X.B \-f
	XThe next argument is interpreted to be the command to execute for
	Xfiltering the shell archive.  For example, if you really just
	Xwanted to send only the archive to a file,
	Xyou could use the rn
	Xcommand:  \fB| rnget -r /dev/null -f "cat > file"\fR.
	X.TP 7
	X.I directory
	XThis is the name of the directory into which the archive is to be
	Xunbundled.
	XIf not given, the current directory is used.
	X.SH FILES
	X.TP 7
	XREAD_ME
	XThe default file used to collect the text which appears before the patten
	Xappears in the shar archive.
	X.SH DIAGNOSTICS
	XThe diagnostics are self-explanitory.
	X.SH "SEE ALSO"
	Xrn(1),
	Xshar(1),
	Xsh(1).
	X.SH BUGS
	XOwnerships and permissions for archived files are not retained.
	X.SH AUTHORS
	X.SS "Original Shell Script"
	XRonald S. Karr, National Semiconductor Inc., Sunnyvale, CA
	X.SS "Revisions and Manual Page"
	XR. O. Domitz, Concurrent Computer Corporation, Tinton Falls, NJ
SHAR_EOF
if test 2606 -ne "`wc -c < 'rnget.1'`"
then
	echo shar: "error transmitting 'rnget.1'" '(should have been 2606 characters)'
fi
fi
echo shar: "extracting 'rnget'" '(1987 characters)'
if test -f 'rnget'
then
	echo shar: "will not over-write existing file 'rnget'"
else
sed 's/^	X//' << \SHAR_EOF > 'rnget'
	X#!/bin/sh
	X#
	X# NAME
	X#	rnget - get a shar archive from rn output.
	X#
	X# SYNOPSIS
	X#	rnget [-p pattern] [-r file] [f prog] [ directory ]
	X#
	X# DESCRIPTION
	X#	Rnget changes to the given directory (if given) and then
	X#	reads its standard input and searches for the given pattern
	X#	(default to "[#:]") at the beginning of a line and passes that
	X#	and all subsequent lines to the filter, defaulting to the
	X#	bourne shell, for processing.  Lines prior to the first line
	X#	matching the pattern are saved to the file, default READ_ME.
	X#
	X#	The idea is that the input is a shar file contained inside
	X#	of a news article, with a scan done before hand for the
	X#	beginning of the shar.  For shars that don't begin with '#'
	X#	or ':' -p can be used to specify something else.
	X#
	X#	Note:  If the directory does not exist, it is created.
	Xprog="$0"
	Xusage="usage: $prog [-p pattern] [-r file ] [-f prog] [directory]"
	Xpattern="/^[:#]/"
	Xreadme="READ_ME"
	Xfilter=/bin/sh
	Xwhile [ $# -gt 0 ]; do
	X	if [ $1 = -p ]; then
	X		shift
	X		if [ $# -lt 1 ]; then
	X			echo $usage
	X			exit 1
	X		fi
	X		pattern="/^$1/"
	X		echo "$prog: Trigger pattern is $pattern."
	X		shift
	X	elif [ $1 = -f ]; then
	X		shift
	X		if [ $# -lt 1 ]; then
	X			echo $usage
	X			exit 1
	X		fi
	X		filter=$1
	X		echo "$prog: Filter is $filter."
	X		shift
	X	elif [ $1 = -r ]; then
	X		shift
	X		if [ $# -lt 1 ]; then
	X			echo $usage
	X			exit 1
	X		fi
	X		readme="$1"
	X		echo "$prog: Header information is in $readme."
	X		shift
	X	else		# got a directory
	X		if [ -f $1 ]; then
	X			echo "$prog: $1 is not a directory!!"
	X			exit 2
	X		fi
	X		if [ ! -d $1 ]; then
	X			mkdir $1 > /dev/null 2>&1
	X			if [ $? -ne 0 ]; then
	X				echo "$prog: Could not create directory $1."
	X				exit 2
	X			fi
	X		fi
	X		cd $1
	X		echo "$prog: Directory is $1."
	X		shift
	X	fi
	Xdone
	Xrm -f $readme
	Xawk "
	XBEGIN	{
	X	skip = 1; copy = 2;
	X	state = skip;
	X}
	Xstate == skip && $pattern	{
	X	state = copy;
	X}
	Xstate == skip	{
	X	print \$0 >> \"$readme\";
	X}
	Xstate == copy	{
	X	print \$0
	X}" | $filter
	Xif [ $? -ne 0 ]; then
	X	echo "$prog:  error in writing to shell"
	Xfi
SHAR_EOF
if test 1987 -ne "`wc -c < 'rnget'`"
then
	echo shar: "error transmitting 'rnget'" '(should have been 1987 characters)'
fi
chmod +x 'rnget'
fi
exit 0
#	End of shell archive
-- 
  Ronald S. Karr			USENET: hplabs!nsc!tron
  National Semiconductor, Sunnyvale	ARPA:   decwrl!nsc!tron@ucbvax.ARPA