Mercurial > ec-dotfiles
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/cek Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,53 @@ +#!/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}"