keithe@tekgvs.LABS.TEK.COM (Keith Ericson) (07/20/90)
In article <5213@castle.ed.ac.uk> elee24@castle.ed.ac.uk (H Bruce) writes: >Does anyone have an automated way of extracting programs from the postings in >comp.binaries.ibm.pc ? >Ideally this would order the postings correctly (they sometimes appear in the >wrong order) and extract and concatenate the uuencoded text. I read the news with "rn" on a VAX-11/785 running BSD4.3 and with the filesystem on my archive machine (a little UTEK box) NFS'd to a convenient location on the VAX. OK - so what... For SHAR'd archives I uses the following ksh script, which I call "rget." (I 'spose it could be written in Bourne Shell but that's up to you...) My normal usage is to pipe the first article to it with the following keystrokes: | rget <directory-name> Subsequent articles can be saved to the same place with just " | rget" since the destination directory information is re-used from the previous invocation if no specified on the command-line (and the new destination will be used until changed in a subsequent invocation.) If the directory does not exist it will be created if possible (you're prompted for a new directory name if the first one cannot be created). Header lines end up in "!READ+ME!" unless otherwise specified, and then only for the first article saved - the the default is to discard subsequent headers since they usually contain nothing useful. Quite frankly, I'm not sure what _all_ the options do since I almost (?) never use them... begin script "rget" --------------------------------------------------------------------- #!/usr/tools/bin/ksh askhim=true prog="$0" savename=$HOME/.rngettemp usage="usage: $prog [-P pattern] [-R file ] [-F prog] [ -S file] [-Q] [directory] OR $prog: -U [file]" if [ -f ${HOME}/.rngettemp ] then read pattern filter readme dir_name < ${HOME}/.rngettemp else pattern="/^[:#]/" readme="!READ+ME!" filter=/bin/sh dir_name="." fi if [ "$1" = "-U" ] then shift if [ $# -ge 1 ] then read pattern filter readme dir_name < "${HOME}/$1" else read pattern filter readme dir_name < ${HOME}/.rngettemp fi elif [ "$1" = "-Q" ] then askhim=false else while [ $# -gt 1 ] do case $1 in -U) print $usage exit 1 ;; -P) shift if [ $# -lt 1 ] then print $usage exit 1 fi pattern="/^$1/" shift ;; -F) shift if [ $# -lt 1 ] then print $usage exit 1 fi filter=$1 shift ;; -R) shift if [ $# -lt 1 ] then print $usage exit 1 fi readme="$1" shift ;; -S) shift if [ $# -lt 1 ] then print $usage exit 1 fi savename="$1" shift ;; esac done # directory name should be all that remains? if [ -n "$1" ] then dir_name=$1 fi fi if [ $askhim = true ] then dir_ok=false print "About to store files in $dir_name" print "OK to proceed [ynq]?" read ans < /dev/tty until [ $dir_ok = true ] do case $ans in q|Q) exit ;; n|N) print "New directory: [<name> or CR]" read dir < /dev/tty if [ -n "$dir" ] then dir_name=$dir fi ;; esac if [ -f $dir_name ] then print "$prog: $dir_name is not a directory!!" ans=n dir_ok=false elif [ ! -d $dir_name ] then mkdir $dir_name > /dev/null 2>&1 if [ $? -ne 0 ] then print "$prog: Could not create directory $dir_name." ans=n dir_ok=false else print "$prog: Created directory $dir_name" readme=!READ+ME! dir_ok=true fi else readme=/dev/null dir_ok=true fi done print "Header lines will go in $readme." print "OK to procede [ynq]?" read ans < /dev/tty case $ans in q|Q) exit ;; n|N) print "New header-file: [<name> or CR]" read hdr < /dev/tty if [ -n "$hdr" ] ; then readme=$hdr ; fi ;; ""|y|Y) ;; esac fi # askhim print "$pattern $filter $readme $dir_name" > "$savename" cd $dir_name /bin/rm -f $readme awk " BEGIN { skip = 1; copy = 2; state = skip; } state == skip && $pattern { state = copy; } state == skip { print \$0 >> \"$readme\"; } state == copy { print \$0 }" | $filter if [ $? -ne 0 ] then print "$prog: error in writing to shell" fi ---------------------------------------------------------------- end of script "rget" ********************************************************************* For uuencoded, not-shar'd archives such as distributed in comp.binaries.ibm.pc I use the following, called "nwr." Like rget it remembers the command-line entered destination directory for subsequent invocations, saving lots of typing and, more importantly, preventing errors incurred therein. Not until after all the parts are saved away do I worry about uudecoding them... My normal usage is to pipe the first article to it as | nwr <dirname>part1 (where "dirname" terminates with a "/" so it looks like | nwr ibmarchive/gif.dir/viewers.dir/vpic.dir/part1 ) Subsequent use would be like | nwr part2 Again, this is a KSH script, but it may be Bourne-able... begin script "nwr" ---------------------------------------------------------------- #!/usr/tools/bin/ksh # set -x NEWDIR=0 NEWFILE=0 # script to use within rn to save keystrokes while saving # multiple-part articles. This remembers the directory # name in $HOME/.nwrsavedir for automatic retrieval. case $# in 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 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 case $ans in c|C) mkdir ${DESTDIR%"/"} if $? then print "${DESTDIR%"/"} created" else print "Cannot create ${DESTDIR%"/"}" fi ;; n|N) print "(terminate name with a slash '/')" 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 echo 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 script "nwr" PS - I use the following alias to uudecode multiple-part postings: alias udec="sed '/^END-/,/^BEGIN-/d'| uudecode" meaning I type in cat part* | udec and the uudecoded archive pops out... Have Fun. kEITHe