[alt.sources] Yet Another Bourne Script

joe@tekbspa.UUCP (Joe Angelo) (05/08/88)

Here is yet another stupid script and very customized to a particular
need -- 

    I've been collecting usenet sources for 6 yrs now either from
    USENET postings or from the work of others in preparing an
    archive site. Collecting from USENET is still a do-it-by-hand
    procedure; however, the later, collecting from an archive site
    and be made semi-automatic --> providing a directory listing of
    the sources is given.


    Most archive sites are into providing a "LISTING" file which is
    simply an 'ls -lR' of thier directory tree. So, it's nice to
    edit the LISTING file and select what you want to retreive.
    Generallly, LISTING files are rather large and an interactive
    "Do you want to copy this one?" script is pretty darn boring.

    Since automation to me still means interaction ;-), my method
    is to ``vi LISTING'' and pipe interesting lines to a script
    called "gf" ... gf then returns a UUCP command line and the 
    editor replaces the orginal lines with the UUCP commands.
    
    When I've finished, I simply grep the UUCP lines from my new
    LISTING file and pipe them to ``sh -v''.

    gf.sh needs SYSTEM defined as the remote UUCP system (you must
    have a direct UUCP connection) and DIRLISTING as the ``ls -lR''
    output file from that site. ``gf'' then scans the DIRLISTING file for
    lines that match it's stdin (as pipe into it from vi with ``#!!'');
    while scanning, ``gf'' reminders the last directory name it's seen
    (a directory name is a line in DIRLISTING that ends with ":" and
    relative pathnames will need minor correcting); ``gf'' then produres
    output such as:

            D=dirname; mkf $D; uucp SYSTEM!$d/file.. $d

    "file", ofcourse, is $NF on the input line.

    For example, if your LISTING file contained:


      /u3/archive/sources/alt:
      total 0

      /u3/archive/sources/games:
      total 6
      drwxr-xr-x   3 news     news         112 Dec 10 14:38 others
      drwxr-xr-x  12 news     news         704 Dec 10 10:12 vol1
      drwxr-xr-x  12 news     news         384 Dec 10 11:40 vol2
      drwxr-xr-x  17 news     news         384 Mar 11 22:47 vol3
      drwxr-xr-x   4 news     news         112 Apr 10 22:47 vol4
      drwxr-xr-x   2 news     news          32 Apr  8 13:37 vol5

      /u3/archive/sources/games/others:
      total 267
      -rw-r--r--   1 news     news       50686 Jun 15  1987 atc.TAR.Z
      -rw-r--r--   1 news     news        2821 Dec 10 12:13 calform.shar.Z
      drwxr-xr-x   2 news     news         176 Dec 10 14:38 empire
      -rw-r--r--   1 news     news       11713 Jun 15  1987 lotto.sh.Z
      -rw-r--r--   1 news     news      200134 Jun 15  1987 phan.TAR.Z

      /u3/archive/sources/games/others/empire:
      .
      .

    And, in vi, you moved to atc.TAR.Z and piped two lines into ``gf'',
    via the vi-commands "2!!gf", ``gf'' returns:

      D=/u3/archive/sources/games/others;mkt $D; uucp aeras!$D/atc.TAR.Z ./$D
      D=/u3/archive/sources/games/others;mkt $D; uucp aeras!$D/calform.shar.Z ./$D

    ``gf'' will do nothing but, perhaps, alter your LISTING file (so
    use a temp copy...gosh) and it's eash to modify ``gf'' to return the
    input string as output and print the UUCP command line into yet another
    file  (printf... >> "outfile"). Later, you simply grep '^D=' from
    your new listing and pump to the shell.
      
    ``mkf'' (also enclosed) as yet-yet another stupid script to
    make relative directories given pathname arguments; thus, preserving
    the orginal directory structure from the remote machine (but from
    a relative point in your file system).

    gf.sh:

    # IFS is nothing but a start and end quote on two lines.
    IFS='
    '

    SYSTEM=aeras
    DIRLISTING=LISTING.work
    # get stdin
    FILES=`cat `

    for file in $FILES
    do
        awk < $DIRLISTING '
        NF >= 1 {
            if(substr($1,length($1),1) == ":") {
                    LASTDIR=substr($1,1,length($1)-1)
            }
            if( $0 == "'$file'") {
                    printf("D=%s;mkt $D; uucp '$SYSTEM'!$D/%s ./$D\n", LASTDIR, $NF)
                    exit 0
            }
        }'
    done

    
mkt:

    for f in $*
    do
        #                       ...spaces below, not tabs.
        list=`echo $f | tr '/' ' '`
        for dir in $list
        do
            parts="$parts$dir/"
            mkdir `echo $parts | sed 's;/$;;'` 2>/dev/null
            chmod 777 $parts
        done
    done

-- 
"I'm trying             Joe Angelo -- Senior Systems Engineer/Systems Manager
 to think               at Teknekron Software Systems, Palo Alto 415-325-1025
 but nothing
 happens!"              uunet!tekbspa!joe -OR- tekbspa!joe@uunet.uu.net