You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.3 KiB
Bash
73 lines
1.3 KiB
Bash
#!/bin/bash
|
|
#
|
|
# Look up the given filename in the description file and confirm that
|
|
# the checksum matches
|
|
#
|
|
# FIXME
|
|
# - the description file is expected to be in the current dir
|
|
# - does not handle description file entries with more than just the sha1 tag
|
|
|
|
DESCRIPTIONS='Descriptions.txt'
|
|
|
|
if [ "$1" == "--rm_on_fail" ]; then
|
|
RM_ON_FAIL=yes
|
|
shift
|
|
fi
|
|
|
|
FILE="$1"
|
|
if [ -z "$FILE" ]; then
|
|
echo "Need filename" 2>&1
|
|
exit 1
|
|
fi
|
|
shift
|
|
|
|
# The name of the Descriptions.txt entry to use
|
|
CHECKNAME="$1"
|
|
if [ -z "$CHECKNAME" ]; then
|
|
# default to the same as the filename
|
|
CHECKNAME="$FILE"
|
|
fi
|
|
|
|
do_exit_fail() {
|
|
if [ "$RM_ON_FAIL" ]; then
|
|
rm -f "$FILE"
|
|
fi
|
|
exit 1
|
|
}
|
|
|
|
LINE=$(egrep "^$CHECKNAME " "$DESCRIPTIONS")
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "Unknown file $CHECKNAME" 2>&1
|
|
do_exit_fail
|
|
fi
|
|
|
|
if [ ! -e "$FILE" ]; then
|
|
echo "File $FILE does not exist" 2>&1
|
|
do_exit_fail
|
|
fi
|
|
|
|
SUM_FIELD=$(echo "$LINE" | awk -- '{print $2}')
|
|
|
|
TYPE=$(echo "$SUM_FIELD" | cut -d: -f1)
|
|
EXPECT=$(echo "$SUM_FIELD" | cut -d: -f2)
|
|
|
|
case "$TYPE" in
|
|
sha1)
|
|
GOT=$(sha1sum "$FILE" | cut -d" " -f1)
|
|
;;
|
|
*)
|
|
echo "Unknown checksum type $TYPE for $CHECKNAME" 2>&1
|
|
do_exit_fail
|
|
;;
|
|
esac
|
|
|
|
if [ "$EXPECT" != "$GOT" ]; then
|
|
echo "File $FILE failed checksum check" 2>&1
|
|
|
|
do_exit_fail
|
|
fi
|
|
|
|
exit 0
|
|
|