#!/bin/bash # By Ashok Argent-Katwala . No rights reserved, do with it as you please. # v0.6 # If the sfv is correct, this script says nothing and exits if [ `sed --version >/dev/null 2>/dev/null && echo 1` ]; then sed='sed -r' # GNU sed (e.g. on Linux) else sed='sed -E' # BSD sed (e.g. on Mac OS X) fi if [ -z "$1" ]; then echo 1>&2 "Usage: $0 sfvfile" exit 1 fi if [ ! -f "$1" ]; then echo 1>&2 "No file found." exit 1 fi tab=$'\t' sfvfile="$1" exit_status=0 cd "$(dirname "$sfvfile")" sfv_values=$(cat "$(basename "$sfvfile")"| grep -v '^\s*;') ORIGIFS=$IFS IFS=`echo -en "\n\b"` for line in $sfv_values; do IFS=$ORIGIFS crc=`echo $line | $sed -e 's/.*[[:space:]]+([0-9A-Fa-f]{8})[[:space:]]*$/\\1/' | tr A-Z a-z | $sed -e 's/^0+//'` file=`echo $line | $sed -e 's/(.*)[[:space:]]+[0-9A-Fa-f]{8}[[:space:]]*$/\\1/'` if [ ! -f "$file" ]; then echo "MISSING$tab$file" exit_status=5 else actual=`cksum -o 3 "$file" | cut -f 1 -d' ' | $sed -e 's:^:obase=16;:' | bc | tr A-Z a-z | $sed -e 's/^0+//'` if [ "$crc" != "$actual" ]; then echo "BAD$tab$file" exit_status=5 fi fi done exit $exit_status