annotate bin/rar2zip @ 5:de6ce93d40fc

Added action message. Fixed missed files.
author Edho Prima Arief <me@myconan.net>
date Sat, 17 Jul 2010 02:32:30 +0700
parents 94ee419ad047
children
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 to_lower() {
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
3 printf "%s" "$1" | tr '[:upper:]' '[:lower:]'
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
4 }
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
5 full_path() {
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
6 # It all depends on the first character.
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
7 start=${i%${i#?}}
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
8 path=
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
9 case "${start}" in
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
10 /) path="${1}";; # / is absolute. No change.
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
11 *) path="${2}/${1}";; # Anything else must be prefixed with $2 (hopefully $PWD)
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
12 esac
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
13 printf "%s" "${path}" # Return.
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
14 }
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
15 for i in "$@"; do
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
16 src_ext="${i##*.}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
17 src_path="$(full_path "${i}" "${PWD}")"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
18 if [ -f "${src_path}" ] && [ -r "${src_path}" ] && [ "${src_ext}" != "${i}" ] && [ "$(to_lower ${src_ext})" = "rar" ]; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
19 tmpdir=".tmp.${i##*/}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
20 if mkdir -p "${tmpdir}"; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
21 if 7z x -o"${tmpdir}" -- "${src_path}"; then
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
22 (cd "${tmpdir}" && 7z a -mx=1 -tzip "${src_path%.*}.zip" -- "*";)
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
23 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
24 rm -r "${tmpdir}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
25 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
26 else
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
27 echo "Invalid input: ${i}"
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
28 fi
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
29 done
94ee419ad047 Added bin-ec - a collection of scripts.
Edho Prima Arief <me@myconan.net>
parents:
diff changeset
30