view bin/cek @ 54:fd518e13cf4d

[bash] for some reason solaris' PS1 \$ doesn't default to #.
author Edho Prima Arief <me@myconan.net>
date Thu, 28 Apr 2011 14:32:59 +0700
parents 94ee419ad047
children 8fc79d327ccd
line wrap: on
line source

#!/bin/sh

bn() { basename "/$*"; }
#cs() { cksfv -- "$@"; }
cs() { cek.rb "$@"; }
if [ "$#" -lt 1 ]; then
	cat <<EOF
Usage: $(bn "$0") file1 file2 ... fileN
EOF
	exit 1
fi

file_ok=0
file_unre=0
file_err=0
file_nocrc=0
for file in "$@"; do
	st="nofile"
	if [ -f "${file}" ] && [ -r "${file}" ]; then
		crc=$(cs "${file}" | tail -1 | sed -e 's/.*\([A-F0-9]\{8\}\)$/\1/')
		nocrc=$(bn "${file}" | sed -e 's/.*[[(][A-Fa-f0-9]\{8\}[])].*//')
		st="nocrc"
		if [ ! -n "${nocrc}" ]; then
		# the filename has CRC. Yay
			filecrc=$(bn "${file}" | sed -e 's/.*[[(]\([A-Fa-f0-9]\{8\}\)[])].*/\1/;y/abcdef/ABCDEF/')
			if [ "${filecrc}" = "${crc}" ]; then
				st="fileok"
				file_ok=$((file_ok+1))
			else
				st="filerr"
				file_err=$((file_err+1))
			fi
		else
			st="nocrc"
			file_nocrc=$((file_nocrc+1))
		fi
	else
		st="nofile"
		file_unre=$((file_unre+1))
	fi
	case "${st}" in
		"nofile") ret="not a file or unreadable";;
		"nocrc") ret="${crc}";;
		"fileok") ret="${crc} - OK!";;
		"filerr") ret="${crc} - ERROR - should be ${filecrc}";;
	esac
	printf "%s\n" "${file}: ${ret}"
done
echo "--------------------------------"
[ "${file_ok}" -gt 0 ] && echo "Files ok: ${file_ok}"
[ "${file_err}" -gt 0 ] && echo "Files broken: ${file_err}"
[ "${file_nocrc}" -gt 0 ] && echo "Files without crc information: ${file_nocrc}"
[ "${file_unre}" -gt 0 ] && echo "Files unreadable or not file: ${file_unre}"