v06i005: makekits revisited (makekits2)
sources-request at mirror.UUCP
sources-request at mirror.UUCP
Wed Jun 18 23:35:04 AEST 1986
Submitted by: pyramid!tolerant!bene!luke!itkin
Mod.sources: Volume 6, Issue 5
Archive-name: makekits2
As the final header comment indicates, this is a modification of a script
I posted a while back that includes the capability to traverse directories.
It seems to work very well, and I am posting it in response to some discussion
in net.sources.d about multi-part shar files. I hope that it will satisfy the
needs of those who have the problem.
[ I would be particularly interested in a /bin/sh or C version of
this that everyone could use. I somehow think it would make my
job a little easier. Steven's original version was posted in
mod.sources Vol2#16. Note that this version supports up to 10
kits, or 640K of source; just barely big enough for hack. --r$]
--------------------------------------------cut here-------------------
# This is a shell archive. Remove anything before this line,
# then unpack it by saving it in a file and typing "sh file".
echo x - makekits.csh
sed 's/^XX//' > "makekits.csh" <<'@//E*O*F makekits.csh//'
XX#! /bin/csh -f
XX#
XX# makekits - generate "kits" from source files for transmission across
XX# telephone lines. Generates an output file called MANIFEST. That
XX# file can be used by later executions of the program as the list of
XX# files.
XX#
XX# usage: makekits [ -cMt ] [ -m manifest ]
XX# [ -s size ] -k kitname [ files... ]
XX#
XX# note that to do directory traversal, you MUST include the name of
XX# the root directory in the list of file names. In fact, the simplest
XX# way to do it is JUST to include the root name as the list of files.
XX#
XX# for example, to traverse the current tree and put all regular files
XX# in the kits: "makekits -c -t /usr/local/src/abc"
XX#
XX# a short tutorial:
XX# first, if there is a file named MANIFEST, remove it
XX# if you are using a manifest, and it is named MANIFEST, change it
XX# second, DO NOT create your kits in the same directory as those
XX# files that are going into the kits, otherwise the kits will be
XX# in the kits will be in the kits will...
XX#
XX# change directory to the directory (or root of the directories) containing
XX# the files to be placed in kits
XX#
XX# execute the command "makekits -k /tmp/kit *" to pick up only plain
XX# files
XX#
XX# execute the command "makekits -t -k /tmp/kit -s 124 *" to pick up all
XX# files in the current directory and all subdirectories. this will
XX# cause the creation of a kit numbered zero (0) that will do nothing
XX# but create directories.
XX#
XX#--------------------------------------------------------------------------
XX# this script updated 04/18/86 based on a cry for help on the network from
XX# Alan Clegg (...!mcnc!ncsu!ncsuvx!abc) to handle directories
XX#--------------------------------------------------------------------------
XX# Steven List @ Benetics Corporation, Mt. View, CA
XX# {cdp,engfocus,idi,oliveb,plx,tolerant}!bene!luke!itkin
XX#--------------------------------------------------------------------------
XX#
XXset COMPRESS = cat # if -c, set to the local compression program
XXset KITSIZE = 62 # leave room for the shar stuff
XXset KITNAME = "" # either from command line or requested below
XXset MAN_NAME = "" # may be set from the command line
XXset MAX_KITS = 20 # limit the number of kits
XXset TRAVERSE = 0 # if -t, traverse all directory trees found
XX#
XX# process command line arguments
XX#
XXforeach i ( $* )
XX switch ($1)
XX case -c:
XX set COMPRESS = /usr/lib/news/compress
XX set KITSIZE = 100
XX shift
XX breaksw
XX case -k:
XX set KITNAME = $2
XX shift; shift
XX breaksw
XX case -m:
XX set MAN_NAME = $2
XX shift; shift
XX breaksw
XX case -M:
XX set MAN_NAME = MANIFEST
XX shift
XX breaksw
XX case -s:
XX set KITSIZE = $2
XX shift; shift
XX breaksw
XX case -t:
XX set TRAVERSE = 1
XX shift
XX breaksw
XX case -*:
XX echo "usage: makekits [-cMt ][-m manifest][-s size] -k kitname [files...]"
XX exit (1)
XX breaksw
XX default:
XX break
XX breaksw
XX endsw
XXend
XX#
XXif ( "$KITNAME" == "" ) then
XX echo "kitname is required"
XX echo "usage: makekits [-cMt ][-m manifest][-s size] -k kitname [files...]"
XX exit (2)
XXendif
XX#
XXset SIZE = ( 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 )
XXset FILES = ( ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' )
XX#
XXswitch ("$MAN_NAME")
XX case MANIFEST:
XX set argv = ( `sed 1,2d MANIFEST | awk '{print $1}'` )
XX mv MANIFEST MANIFEST.bu
XX breaksw
XX case "":
XX breaksw
XX default:
XX set argv = ( `cat $MAN_NAME` )
XX breaksw
XXendsw
XX#
XXset FLIST = ( "" )
XXset DIRS = ( "" )
XX######################################################################
XX#
XX# first, if specified, traverse all directories and add their file
XX# names to the list of files
XX#
XXif ( $TRAVERSE ) then
XX foreach file ( $* )
XX if ( -d $file ) then
XX set DIRS = ( $DIRS `find $file -type d -print` )
XX else if ( -r $file ) then
XX set FLIST = ( $FLIST $file )
XX endif
XX end
XX set BASE = `pwd`
XX foreach dir ( $DIRS )
XX cd $dir
XX foreach subfile ( * )
XX if ( -f $subfile ) set FLIST = ( $FLIST $dir/$subfile )
XX end
XX cd $BASE
XX end
XXelse
XX FLIST = ( $* )
XXendif
XX
XXecho > MANIFEST
XXforeach file ( $FLIST MANIFEST )
XX if ( -d $file ) continue
XX set thissize = ( `ls -s $file` )
XX set thissize = $thissize[1]
XX set kit = 0
XX while ( $kit < $MAX_KITS )
XX @ kit++
XX if ( ( $SIZE[$kit] + $thissize ) <= $KITSIZE ) then
XX set FILES[$kit] = "$FILES[$kit] $file"
XX @ SIZE[$kit] += $thissize
XX echo "$file $kit" >> MANIFEST
XX break
XX endif
XX end
XXend
XX#
XXsort -o MANIFEST MANIFEST
XXawk '\
XXBEGIN { print "File Name Kit Number"\
XX print "-------------- ----------"\
XX }\
XX{ printf "%-24s %d\n", $1, $2 }' MANIFEST > tmp$$
XXmv tmp$$ MANIFEST
XX######################################################################
XX#
XX# make a kit to create the directories, if necessary
XX#
XXif ( "$DIRS" != "" ) then
XX echo "Creating KIT 0 to make directories"
XX cat > ${KITNAME}0 << EndHead
XX#! /bin/sh
XX# This is a shell archive, meaning:
XX# 1. Remove everything above the #! /bin/sh line.
XX# 2. Save the resulting text in a file.
XX# 3. Execute the file with /bin/sh (not csh) to create the directories:
XXEndHead
XX foreach i ( $DIRS )
XX echo "# $i" >> ${KITNAME}0
XX end
XX echo "# This archive created: `date`" >> ${KITNAME}0
XX echo 'export PATH; PATH=/bin:$PATH' >> ${KITNAME}0
XX foreach i ( $DIRS )
XX cat >> ${KITNAME}0 << EndDIR
XXif test ! -d '$i'
XXthen
XX echo shar: creating directory "'$i'"
XX mkdir '$i'
XXfi
XXEndDIR
XX end
XX echo "# End of shell archive" >> ${KITNAME}0
XX echo "Completed KIT 0"
XXendif
XX######################################################################
XXforeach i ( 1 2 3 4 5 6 7 8 9 10 )
XX if ( $SIZE[$i] == 0 ) break
XX set NFILES = ( $FILES[$i] )
XX echo "Creating KIT $i ($KITNAME$i) - $#NFILES files, $SIZE[$i] blocks"
XX shar -p'XX#' -c -v $FILES[$i] | $COMPRESS > $KITNAME$i
XX echo "Completed KIT $i ($KITNAME$i)"
XXend
@//E*O*F makekits.csh//
chmod u=rw,g=rw,o=rw xxx
exit 0
More information about the Mod.sources
mailing list