From franklin@ug.cs.dal.ca Sat Oct  2 20:51:27 1993
Newsgroups: comp.sys.mac.misc
Path: news.itd.umich.edu!destroyer!caen!usenet.cis.ufl.edu!eng.ufl.edu!spool.mu.edu!howland.reston.ans.net!math.ohio-state.edu!cs.utexas.edu!uunet!psinntp!nstn.ns.ca!cs.dal.ca!ug.cs.dal.ca!franklin
From: franklin@ug.cs.dal.ca (Steve Franklin)
Subject: MAC.ARCHIVE.UMICH.EDU script for processing new file listings
Message-ID: <CE2wHy.7w1@cs.dal.ca>
Sender: usenet@cs.dal.ca (USENET News)
Nntp-Posting-Host: ug.cs.dal.ca
Organization: Math, Stats & CS, Dalhousie University, Halifax, NS, Canada
Date: Tue, 28 Sep 1993 19:22:45 GMT
Lines: 98


The following script is intended to act as a front-end script for reading
new mac.archive file listings. Every couple of weeks a file comes up on the
newsgroups (or in your mail box if you're on the mailing list) which gives
the listing of all new files added since the last file... This script lets
you get a quick list of all the files (as has just recently been implemented
into the list), then lets you retrieve the info on specific files, or
retrieve them... I find it a heck of a lot easier to work with than goin
through the list itself, so you might too...

   Incedentally, it will run with ncftp or ftp, but ncftp is a bazillion
times nicer (especially with the auto-redial) so you might consider having
it installed if it isn't already.

Steve Franklin

franklin@ug.cs.dal.ca





#!/bin/sh

####### Conditions, and locations of binaries

# If you're going to use ftp instead of ncftp (why, I wouldn't know...)
# Then you're going to have to uncomment the other FTP entry, and also
# go down to near the bottom where the FTP args are ( In the Getfile function)


FTP=/local/bin/ncftp
#FTP=/usr/ucb/ftp
ECHO=/usr/bin/echo
DEFAULT="mac.archive.umich.edu"
####### test conditions ##############
if [ $# -lt 1 ]
then
    echo process - used to process new archive listings
    echo "USAGE: process FILENAME (hostname)"
    exit 1
fi

if [ ! -f $1 ]
then
    echo Error: File does not exist.
    exit 1
fi

host="$2"

if [ -z "$host" ]
then host="$DEFAULT"
fi

rm $HOME/.tmpfile $HOME/.tmpfile2 $HOME/.tmpfile3 2>/dev/null >/dev/null

cp $1 $HOME/.tmpfile
echo "Franklin's umich script... email franklin@ug.cs.dal.ca with help or questions"

####### Functions #########

Getfile () 
{ 
   (
#    $ECHO open  $1;       # If using ftp, not ncftp, use this one

    $ECHO open -ard5g100 $1;   # If using ncftp, use this one
    $ECHO binary;
    $ECHO prompt;
    $ECHO cd $2;
    $ECHO get $3;
    $ECHO bye ) | $FTP >$HOME/ftp.log &
}

# Program body #

cat $HOME/.tmpfile | grep "\/mac\/" > $HOME/.tmp1
cat $HOME/.tmp1| grep \/ | awk -F"/" '{printf"%-25s %s\n",$3,$NF}' | sort | uniq >> $HOME/.tmpfile2
page $HOME/.tmpfile2

LETTER="Y"

until [ "$LETTER" = "n" ]
do
$ECHO "(S)ave a copy, (g)et a file, (quit), re(D)isplay, or (I)nfo on a file"
read LETTER
case $LETTER in
      S|s) cp $HOME/.tmpfile2 $HOME/PROCESS.output; $ECHO "A copy has been saved in your home directory";;
      G|g) $ECHO "What is the filename you want to fetch?"; read FILE; FILE1=`grep $FILE $HOME/.tmpfile`; FILENAME=`basename $FILE1`; DIR=`dirname $FILE1`; Getfile $host $DIR $FILENAME; echo "getting $FILENAME in $DIR from $host";; 
      Q|q) rm $HOME/.tmpfile2 $HOME/.tmpfile 2>/dev/null >/dev/null; exit 1;;
      d|D) page $HOME/.tmpfile2;;
      i|I) $ECHO "What file would you like more information on?"; read INFO;NUM=`/usr/bin/grep -n $INFO newfiles | tail -1 | awk -F":" '{printf"%s\n",$1}'` ; NUM=`expr $NUM + 15`; head -$NUM $1 | tail -16 > $HOME/.tmpfile3; NUM2=`/usr/bin/grep -n "\/mac\/" $HOME/.tmpfile3 | head -2 | tail -1 | awk -F":" '{printf"%s\n",$1}'`; cat $HOME/.tmpfile3 | head -` expr $NUM2 - 1 ` ;;
      *) $ECHO "Please make a better choice than that";;
esac
done

rm $HOME/.tmpfile2 $HOME/.tmpfile 2>/dev/null >/dev/null