[comp.binaries.ibm.pc.d] Multipart-binaries articles made easier

keithe@tekgvs.LABS.TEK.COM (Keith Ericson) (03/06/90)

I, like many others, read news on a UNIX machine.  And I save articles,
including c.b.i.p. programs initially, at least, on that UNIX machine.

To ease the task of stashing away multi-part binaries I've developed the
following Korn shell* script, called "nwr." If invoked with a "full path name"
(meaning, the string conatains forward-slashes '/') it determines if a new
(sub)directory is required and, if so, creates it.  If invoked with just a
file-name (no '/' characters present) it prepends the previously-specified
directory specification to the file-name and stores the file there.  In this
manner you can specify the destination of part one with the instruction

	| new binaries/newprogram/part1

and send the subsequent parts to the same (sub)directory with the instructions

	| nwr part2
	...
	| nwr partN

Alternatively you can just append subsequent parts to the same file (but that's
not how _I_ do it.)

Once you have all the parts stashed away you can go to the subdirectory and
use the combine script to do the mass uudecode function:

	cat * | sed '/^END/,/^BEGIN/d'| uudecode

Herewith, then, is my "nwr" (you'll probably have to change the location of
the ksh executable in line one).

 *This might work with the MKS shell but I haven't tried it.  Last time I
  ported a UNIX ksh script to MKS it took a bit of doing, but that was MKS
  version 2.3c, and they're up to 3.1 now.

# script for use within rn to save keystrokes while saving multiple-part
#   articles.  This remembers the directory name in $HOME/.nwrsavedir for
#   automatic retrieval.
#		Keith Ericson - keithe@tekgvs.tek.labs.com
# This is yours for free.  If you want to claim you are responsible for
#   this, you'll probably get what you deserve :-)


#!/usr/tools/bin/ksh		# your ksh probably isn't here...
# set -x			# uncomment for debugging
NEWDIR=0
NEWFILE=0

case $# in		# there should only be one command-line argument...

	1)	DESTDIR=${1%"`basename $1`"}
		if	[ "$DESTDIR" = "" ]
		then	DESTFILE=${1}
			read DESTDIR < $HOME/.nwrsavedir
		else	DESTFILE=`basename ${1}`
			print "${DESTDIR}" > $HOME/.nwrsavedir
		fi
		;;

	*)	echo "usage: nwr [destdir-path/]destfile"
       		exit
	        ;;

esac

print DESTDIR = ${DESTDIR%"/"}
print DESTFILE = $DESTFILE

# determine if the destination directory exists.  If not, verify creation
# and upon a failure to create, prompt for new name or exit

while [ $NEWDIR = 0 ]
do
	if	test -d ${DESTDIR%"/"} 
	then	NEWDIR=1
	else	read ans?"${DESTDIR} does not exist: create, new name or exit (c/n/e)?" < /dev/tty

# Note: all of the following cases will cause the while loop to be re-executed
# even if the new directory is successfully created (case c|C).  The loop is
# finally exited when the "test -d ${DESTDIR%"/"}" is satisfied, guaranteeing
# that the directory does, in fact, exist.

		case $ans in 
		c|C)	mkdir ${DESTDIR%"/"}
			if $?
			then	print "${DESTDIR%"/"} created"
			else	print "Cannot create ${DESTDIR%"/"}"
			fi
			;;
		n|N)	read DESTDIR?"input new directory name: " < /dev/tty
			print "${DESTDIR}" > $HOME/.nwrsavedir
			;;
		e|E)	exit;;
		*)	print "Huh?"
			;;
		esac
	fi
done

while [ $NEWFILE = 0 ]
do
	if	[ -f "${DESTDIR}${DESTFILE}" ]
        then	read ans?"${DESTFILE} exists: replace, append or new name (r/a/n)?" < /dev/tty
	        case $ans in
			r|R)	print "replacing ${DESTDIR}${DESTFILE} with this article"
				cat <&0 > ${DESTDIR}${DESTFILE}
				NEWFILE=1
				;;
	
			a|A)	print "appending this article to ${DESTDIR}${DESTFILE}"
				cat <&0 >> ${DESTDIR}${DESTFILE}
				NEWFILE=1
				;;
	
			n|N)	read DESTFILE?"input new file name" < /dev/tty
				;;
		esac
	else	print "saving current article to ${DESTDIR}${DESTFILE}"
		cat <&0 > ${DESTDIR}${DESTFILE}
		NEWFILE=1
	fi
done
set +x

# end of nwr script