comparison bin/cek @ 4:94ee419ad047

Added bin-ec - a collection of scripts.
author Edho Prima Arief <me@myconan.net>
date Sat, 10 Jul 2010 12:38:52 +0000
parents
children 8fc79d327ccd
comparison
equal deleted inserted replaced
3:39ef7f7236fc 4:94ee419ad047
1 #!/bin/sh
2
3 bn() { basename "/$*"; }
4 #cs() { cksfv -- "$@"; }
5 cs() { cek.rb "$@"; }
6 if [ "$#" -lt 1 ]; then
7 cat <<EOF
8 Usage: $(bn "$0") file1 file2 ... fileN
9 EOF
10 exit 1
11 fi
12
13 file_ok=0
14 file_unre=0
15 file_err=0
16 file_nocrc=0
17 for file in "$@"; do
18 st="nofile"
19 if [ -f "${file}" ] && [ -r "${file}" ]; then
20 crc=$(cs "${file}" | tail -1 | sed -e 's/.*\([A-F0-9]\{8\}\)$/\1/')
21 nocrc=$(bn "${file}" | sed -e 's/.*[[(][A-Fa-f0-9]\{8\}[])].*//')
22 st="nocrc"
23 if [ ! -n "${nocrc}" ]; then
24 # the filename has CRC. Yay
25 filecrc=$(bn "${file}" | sed -e 's/.*[[(]\([A-Fa-f0-9]\{8\}\)[])].*/\1/;y/abcdef/ABCDEF/')
26 if [ "${filecrc}" = "${crc}" ]; then
27 st="fileok"
28 file_ok=$((file_ok+1))
29 else
30 st="filerr"
31 file_err=$((file_err+1))
32 fi
33 else
34 st="nocrc"
35 file_nocrc=$((file_nocrc+1))
36 fi
37 else
38 st="nofile"
39 file_unre=$((file_unre+1))
40 fi
41 case "${st}" in
42 "nofile") ret="not a file or unreadable";;
43 "nocrc") ret="${crc}";;
44 "fileok") ret="${crc} - OK!";;
45 "filerr") ret="${crc} - ERROR - should be ${filecrc}";;
46 esac
47 printf "%s\n" "${file}: ${ret}"
48 done
49 echo "--------------------------------"
50 [ "${file_ok}" -gt 0 ] && echo "Files ok: ${file_ok}"
51 [ "${file_err}" -gt 0 ] && echo "Files broken: ${file_err}"
52 [ "${file_nocrc}" -gt 0 ] && echo "Files without crc information: ${file_nocrc}"
53 [ "${file_unre}" -gt 0 ] && echo "Files unreadable or not file: ${file_unre}"