view bin/cek @ 609:7f5234a312f7

Cleanup style
author nanaya <me@nanaya.pro>
date Fri, 07 Jul 2017 19:35:52 +0900
parents 08d5f6023998
children
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}"