1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-14 15:36:34 +00:00
Interlisp.maiko/bin/checksum

79 lines
2.2 KiB
Bash
Executable File

#! /bin/sh
# First line invokes Bourne shell
# ============================================================================
# ABSTRACT:
# Bourne script for checking/generating checksums for files contained
# in a specific Medley release directory. Should normally be invoked
# by ldechecksum and expects the calling script to be connected to
# the medley installation directory. Also, expects the directory
# <medleydir>checksumdir to exist. "< W > ..." warning and "< E > ..."
# error messages will be issued.
#
# SYNOPSIS:
# checksum -cg dir
#
# -c generates a FOO.check file and compares it to FOO.sum.
# -g generates a FOO.sum file.
# NOTE: One of -c or -g is required.
# dir the name of the Medley release directory containing files
# for which checksum checking/generating will be performed.
#
# CHANGES:
# 05-05-89 Carl Gadener : added "trap" to delete created file if
# interrupted. Also "FOO.check" files are now
# deleted after being used.
# 12-14-88 Carl Gadener : Had to rewrite it for Bourne shell because
# the "foreach" loop in csh doesn't accept
# enough args.
# ============================================================================
#
if test $# -lt 2
then
echo "Usage: checksum -cg dir"
exit 2
else
case $1 in
-c) suffix="check"
operation="Verifying"
;;
-g) suffix="sum"
operation="Generating checksum for"
;;
*) echo "Usage: checksum -cg dir"
exit 2 ;;
esac
fi
if test -d $2
then
resultdir=`pwd`/checksumdir
resultfile=`echo "$2" | sed s/\\\//-/g`
# If interrupted be sure to delete created file
trap "/bin/rm -f $resultdir/$resultfile.$suffix ; exit" 1 2 3 15
cd $2
echo "$operation: $2"
echo "Checksum for directory: $2" > $resultdir/$resultfile.$suffix
echo "" >> $resultdir/$resultfile.$suffix
for file in `/bin/ls -FL | /bin/grep -v "/" `
do
echo "E > `sum $file` $file" >> $resultdir/$resultfile.$suffix
done
if test "$1" = "-c" # Verifying
then
/bin/diff $resultdir/$resultfile.sum \
$resultdir/$resultfile.check | grep "<"
# Remove check-file after check has been done
/bin/rm -f $resultdir/$resultfile.check
fi
else
echo "< W > `pwd`/$2 : Directory not installed"
fi