comparison bin/putcrc @ 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 08d5f6023998
comparison
equal deleted inserted replaced
3:39ef7f7236fc 4:94ee419ad047
1 #!/bin/sh
2 safe_path()
3 {
4 # It all depends on the first character.
5 __start=$(printf "%s" "$*" | cut -c 1)
6 __path=
7 case "${__start}" in
8 .|/) __path="$*";; # . and / is safe. No change.
9 *) __path="./$*";; # Anything else must be prefixed with ./
10 esac
11 printf "%s" "${__path}" # Return.
12 }
13
14 if [ "$#" -lt 1 ]; then
15 cat <<EOF
16 Usage: $(basename "/$0") file1 file2 ... fileN
17 EOF
18 exit 1
19 fi
20
21 for file in "$@"; do
22 if [ -f "${file}" ] && [ -r "${file}" ] && [ -n "$(printf "%s\n" "${file}" | sed -e 's/.*[A-F0-9]\{8\}.*//')" ]; then
23 filename="$(basename "$(safe_path "${file}")")"
24 dirname="$(dirname "$(safe_path "${file}")")"
25 myfile="$(printf "%s\n" "${filename%.*}" | sed -e 's/\([^]]\)$/\1 /')"
26 myext="${filename##*.}"; if [ "${myext}" = "${filename}" ]; then myext=""; else myext=".${myext}"; fi
27 crc=$(cek.rb "$(safe_path "${file}")" | tail -1 | sed -e 's/.*\([A-F0-9]\{8\}\)$/\1/')
28 mv -- "${file}" "${dirname}/${myfile}[${crc}]${myext}" && printf "%s => %s\n" "${file}" "${myfile}[${crc}]${myext}"
29 else
30 printf "%s\n" "${file} is not a file or unreadable"
31 fi
32 done