Cover V04, I05
Article
Listing 1
Listing 2
Listing 3

sep95.tar


Listing 3: qarcs wrapper script

#!/bin/sh
#
#       $Id$
#
#       qarcs
#
#       Combine a set of RCS commands to use by the QA people.  QA needs
#       to archive entire directory trees efficiently and update those
#       trees for use on various test systems later.  The mkarc(1) script
#       creates such an archive and the dearc script extracts from such
#       an archive.  this script uses mkarc to create the archive when
#       needed or uses dearc to extract from the archive when needed.
#       Once the archive is available, the specific commands in this
#       script maintain the file using RCS.
#
#       This script supports common RCS commands depending on the program
#       name used to start this script.  Commands include:
#
#       qarco:          Check out an archive update for modification.
#                       Extract the tree from the archive.
#
#       qarget:         Get an archive without checking it out for
#                       modification.  Extract the tree from the archive.
#
#       qartoc:         Get an archive solely to read the table of
#                       contents.  Remove the checked-out copy when done.
#
#       qarci:          Check in an archive update after modification.
#                       Create the archive from the tree and then destroy
#                       the tree.
#
#       qarlog:         Print an archive's revision control log.
#
#       qarwhich:       Display a list of archives already checked in.
#
#       qarcs:          Modify an archive file's RCS attributes.
#
#       qarmerge:       Merge two archive revisions.
#
#       qarinstall:     Create the links for the program's invocation
#                       names.
#
#       qarhelp:        Print this script's usage.
#
#       Except for qarget, qarhelp, and qarinstall, these commands
#       correspond with the RCS commands named similarly.  The options
#       available to those commands are passed through to them by these
#       qar commands.  The tree archives are compressed and uuencoded.
#       No diff would report useful information.  See rcsintro(1) for an
#       overview of RCS and a crossreference to the other RCS commands
#       and their options.  There is no equivalent to rcsdiff provided.
#
#       Make the primary name qarinstall.  Then run qarinstall to
#       automatically create the links when installing it for the first
#       time.
#
#       Lawrence S Reznick -- 94Nov15

usage () {
echo "Usage: progname [-P rcs] [-D dest]" \
"[-X] [-H] [rcs-opts] archivenames"
echo
echo "Archives compressed directory trees using rcs."
echo
echo "Options:  See rcsintro(1) and other rcs man pages" \
"for rcs_options."
echo
echo "-P: New path to hold the rcs archives ($QARCSDIR)."
echo "-D: New destination dir holding the tree ($DESTDIR)."
echo "-X: Turn on shell debugging."
echo "-H: Get help from commands other than qarhelp."
echo
echo "Program Names:"
echo
echo "qarco:    Check out an archive update for modification."
echo "          Extract the tree from the archive."
echo
echo "qarget:   Get an archive without checking it out for"
echo "          modification.  Extract the tree from the"
echo "          archive."
echo
echo "qartoc:   Get an archive solely to read the table of"
echo "          contents.  Remove the checked-out copy when"
echo "          done."
echo
echo "qarci:    Check in an archive update after modification."
echo "          Create the archive from the tree and then"
echo "          destroy the tree."
echo
echo "qarlog:   Print an archive's revision control log."
echo
echo "qarwhich: Display a list of archives already checked in."
echo
echo "qarcs:    Modify an archive file's RCS attributes."
echo
echo "qarmerge: Merge two archive revisions."
echo
echo "qarinstall:       Create the links for the program's"
echo "          invocation names."
echo
echo "qarhelp:  Print this usage message."
echo
}

baddir () {
echo "$1 isn't a directory!" 1>&2
}

#
#       Main program starts here
#

progname=`basename $0`

#
#       Initialize variables
#

#
# Uncomment the complex RCSPATH assignment if rcs is in different paths
# on differing machines.  Otherwise, the GNU RCS files should be in
# /usr/local/bin.
#

#RCSPATH=`dirname \`type rcs | awk '{print $NF}'\``
RCSPATH=/usr/local/bin

QARCSDIR=/archive/RCS

CWD=`pwd`
DESTDIR=$CWD

QUIET=-q

OPT=

MANDOPT=                # I've always loved the term "mandatory options"

PREFIXCMD=
SUFFIXCMD=

if [ "$progname" = "qarhelp" ]
then
usage
exit 0
fi

#
#       Collect options
#
#       Must use the roundabout "! -z" syntax to pass hyphenated options
#       through the test program uninterpreted.
#

while [ ! -z "$1" ]
do
case "$1" in
-H)                     # Give help
usage
exit 0
;;

-P)                     # Set a different QARCSDIR
shift
QARCSDIR=${1:-$QARCSDIR}

if [ ! -d $QARCSDIR ]
then
baddir $QARCSDIR
exit 1
fi
;;

-D)                     # Set destination directory
shift
if [ "$1" - "." ]
then
DESTDIR=$DESTDIR/.
else
DESTDIR=${1:-$DESTDIR}

if [ `expr "$DESTDIR" : "\/"` -ne 1 ]
then
DESTDIR=$CWD/$DESTDIR
fi
fi
;;

-X)                     # Set shell debugging on
set -x
QUIET=
;;

-*)                     # Pass on all other options
OPT="$OPT $1"
;;

*)                      # Found dirtree
break
;;
esac
shift
done

#
#       Look at this script's name to see which command to run.
#       qarhelp has already been run.
#

case $progname in

qarinstall)                     # Recreate this script's links
for f in qarco qarget qartoc qarci \
qarlog qarwhich qarcs qarmerge qarhelp
do
ln -s $0 $f
chmod a+x $f
done
echo "Links created:"
ls -l qar*

mkdir $QARCSDIR
if [ ! -d $QARCSDIR ]
then
baddir $QARCSDIR
exit 1
fi
chmod 775 $QARCSDIR
exit 0
;;

qarco)                          # Check out an archive
CMD=co
MANDOPT=-l
SUFFIXCMD='dearc `basename $f .Z.uu`.Z.uu $DESTDIR'
SUFFIXCMD=$SUFFIXCMD' ; rm -f `basename $f .Z.uu`.Z.uu
;;

qarget)                         # Get an unmodifiable archive
CMD=co
SUFFIXCMD='dearc `basename $f .Z.uu`.Z.uu $DESTDIR'
SUFFIXCMD=$SUFFIXCMD' ; rm -f `basename $f .Z.uu`.Z.uu
;;

qartoc)                         # Check out only for the Table of Contents
CMD=co
SUFFIXCMD='dearc -t `basename $f .Z.uu`.Z.uu'
SUFFIXCMD=$SUFFIXCMD' ; rm -f `basename $f .Z.uu`.Z.uu
;;

qarci)                          # Check in an archive
PREFIXCMD='mkarc $DESTDIR $f'
CMD=ci
;;

qarlog)                         # Print an archive's log
CMD=rlog
QUIET=                  # Sun doesn't mind it; HP complains
;;

qarwhich)                       # List archive filenames
if [ ! -d $QARCSDIR ]
then
baddir $QARCSDIR
exit 1
fi

ls $QARCSDIR | egrep ,v | sed 's/,v//'
exit 0
;;

qarcs)                          # Change RCS file attributes
CMD=rcs
;;

qarmerge)                       # Merge two archive revisions
CMD=rcsmerge
;;

*)                              # Not a supported command
echo "$progname: \"$progname\" is not one of the qarcs commands."
echo
usage
exit 1
;;
esac

#
#       Grab remaining arguments as directory tree archive names
#

if [ $# -eq 0 ]
then
echo "Must name at least one dirtree!" 1>&2
exit 2
fi

cd $QARCSDIR

for f
do
eval $PREFIXCMD
$RCSPATH/$CMD $QUIET $OPT $MANDOPT `basename $f .Z.uu`.Z.uu
if [ $? -ne 0 ]
then
rm -f `basename $f .Z.uu`.Z.uu
else
eval $SUFFIXCMD
fi
done