view bin/cek @ 452:a07ee25c6304

Color all those gits!
author Edho Arief <edho@myconan.net>
date Fri, 08 Feb 2013 19:03:49 +0900
parents 08d5f6023998
children 7f5234a312f7
line wrap: on
line source

#!/bin/sh

bn() { basename "/$*"; }
#cs() { cksfv -- "$@"; }
cs() { cek.py "$@"; }
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}"