Cover V03, I06
Article
Figure 1
Listing 1
Listing 2
Listing 3
Listing 4
Sidebar 1

nov94.tar


Listing 3: fwedit.sh--An example suFirewall utility

#***********************************
#  fwedit - Get an s-file file for edit.
#************************************

usage() {
(
echo "usage: $FWPGM [ -r Rel ] File..."
) >&2
exit 1
}

if [ $# = 0 ]; then
usage
fi

# Read in control file.
. ${FWSDIR}/.SCCSctl

# Save original and force umask to what we want.
oldmask=`umask`
umask 007

# Process command line switches.
getOpts="-e"
while [ $# -gt 0 ]; do
case "$1" in
-D)
# Turn on debugging.
set -x
;;
-r?*)
# SID
rFOpt=`expr "$1" : '..\([0-9][0-9]*\)'`
if [ ! "$rFOpt" ]; then
echo "$FWPGM: bad -r value, $1" >&2
exit 2
fi
;;
-r)
# SID
rFOpt=`expr "$2" : '\([0-9][0-9]*\)'`
shift
if [ ! "$rFOpt" ]; then
echo "$FWPGM: bad -r value, $1." >&2
exit 2
fi
;;
-*)
# Must be a bad flag.
echo "${FWPGM}: bad flag, $1." >&2
usage
;;
*)
break
;;
esac
shift
done

count=0
if [ ! "${SCCSBASE}" ]; then
echo "$FWPGM: SCCSBASE must be set." >&2
exit 4
fi
for file in $*;do
rc=0
File=`basename $file`

echo "" >&2

if [ ! -r ${SCCSBASE}/s.$File ]; then
echo "$FWPGM($File): does not exist." >&2
rc=3
continue
fi

# If you are doing multiple SCCS commands within an
# suFirewall script, you will need to be able to lock
# the s-file until done with all operations.
# fwlock implements file locking via a lock file in the spirit
# of SCCS z-files. Its implementation is beyond the scope
# of this paper.
#
fwlock ${SCCSBASE}/Z.$File

# Get latest SID in s.File if rFOpt not provided.
if [ ! "$rFOpt" ]; then
rFOpt=`FWLatestTrunk $File`
fi

# Check to see if this release trunk is locked.
eval Locked=\$Locked_$rFOpt
if [ "$Locked" ]; then
echo "$FWPGM($File): \c" >&2
echo "locked for edits on release trunk $rFOpt." >&2
rm -f ${SCCSBASE}/Z.$File
rc=5
continue
fi

# Check for edits on specified trunk.
edits=""
edits=`FWEditsOnTrunk $rFOpt $File`
if [ "$edits" ]; then
echo "$FWPGM($File): \c" >&2
echo "out for edit on release trunk $rFOpt." >&2
echo "$edits" >&2
rm -f ${SCCSBASE}/Z.$File
rc=6
continue
fi

# Set -r option for get.
getSid="-r${rFOpt}"

# Check for writable file here
if realdo $FWREALUID "test -w $File"; then
if [ -t $FWSTDIN ]; then
echo "$FWPGM($file): \c" >&2
echo "Writable file exists, remove it? \c" >&2
read ans
case "$ans" in
Y|y|YES|yes)
realdo $FWREALUID "rm $File"
if [ $? != 0 ]; then
echo "$FWPGM($file): \c" >&2
echo "Cannot remove (?), ignoring edit request." >&2
rm -f ${SCCSBASE}/Z.$File
rc=7
continue
fi
;;
*)
echo "$FWPGM($file): \c" >&2
echo "Not removed, ignoring edit request." >&2
rm -f ${SCCSBASE}/Z.$File
rc=7
continue
;;
esac
else
echo "$FWPGM($file): \c" >&2
echo "Writable file exists, ignoring edit request." >&2
rm -f ${SCCSBASE}/Z.$File
rc=7
continue
fi
fi

# Disable interrupts for critical portion.
trap "" 1 2 3 15

# Do the SCCS get for edit.
echo "+ get ${getSid} ${getOpts} ${SCCSBASE}/s.$File" >&2
eval get ${getSid} ${getOpts} ${SCCSBASE}/s.$File
rc=$?

# Remove the lock file.
rm -f ${SCCSBASE}/Z.$File
if [ $rc = 0 ]; then
count=`expr $count + 1`
fi
# Enable interrupts
trap 1 2 3 15
done
echo "" >&2
echo "$FWPGM: $count file(s) successfully processed." >&2
exit $rc
# end