annotate bin/cek @ 287:d55ff9c0158a

More ren rules.
author Edho Arief <edho@myconan.net>
date Thu, 12 Jan 2012 15:02:53 +0700
parents 08d5f6023998
children 7f5234a312f7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
1 #!/bin/sh
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
2
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
3 bn() { basename "/$*"; }
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
4 #cs() { cksfv -- "$@"; }
79
08d5f6023998 Replace checksum calculator with python version.
Edho Prima Arief <me@myconan.net>
parents: 76
diff changeset
5 cs() { cek.py "$@"; }
4
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
6 if [ "$#" -lt 1 ]; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
7 cat <<EOF
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
8 Usage: $(bn "$0") file1 file2 ... fileN
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
9 EOF
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
10 exit 1
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
11 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
12
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
13 file_ok=0
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
14 file_unre=0
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
15 file_err=0
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
16 file_nocrc=0
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
17 for file in "$@"; do
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
18 st="nofile"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
19 if [ -f "${file}" ] && [ -r "${file}" ]; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
20 crc=$(cs "${file}" | tail -1 | sed -e 's/.*\([A-F0-9]\{8\}\)$/\1/')
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
21 nocrc=$(bn "${file}" | sed -e 's/.*[[(][A-Fa-f0-9]\{8\}[])].*//')
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
22 st="nocrc"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
23 if [ ! -n "${nocrc}" ]; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
24 # the filename has CRC. Yay
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
25 filecrc=$(bn "${file}" | sed -e 's/.*[[(]\([A-Fa-f0-9]\{8\}\)[])].*/\1/;y/abcdef/ABCDEF/')
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
26 if [ "${filecrc}" = "${crc}" ]; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
27 st="fileok"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
28 file_ok=$((file_ok+1))
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
29 else
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
30 st="filerr"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
31 file_err=$((file_err+1))
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
32 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
33 else
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
34 st="nocrc"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
35 file_nocrc=$((file_nocrc+1))
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
36 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
37 else
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
38 st="nofile"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
39 file_unre=$((file_unre+1))
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
40 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
41 case "${st}" in
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
42 "nofile") ret="not a file or unreadable";;
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
43 "nocrc") ret="${crc}";;
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
44 "fileok") ret="${crc} - OK!";;
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
45 "filerr") ret="${crc} - ERROR - should be ${filecrc}";;
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
46 esac
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
47 printf "%s\n" "${file}: ${ret}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
48 done
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
49 echo "--------------------------------"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
50 [ "${file_ok}" -gt 0 ] && echo "Files ok: ${file_ok}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
51 [ "${file_err}" -gt 0 ] && echo "Files broken: ${file_err}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
52 [ "${file_nocrc}" -gt 0 ] && echo "Files without crc information: ${file_nocrc}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
53 [ "${file_unre}" -gt 0 ] && echo "Files unreadable or not file: ${file_unre}"