Mercurial > ec-dotfiles
comparison bin/rar2zip @ 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 |
comparison
equal
deleted
inserted
replaced
| 3:39ef7f7236fc | 4:94ee419ad047 |
|---|---|
| 1 #!/bin/sh | |
| 2 to_lower() { | |
| 3 printf "%s" "$1" | tr '[:upper:]' '[:lower:]' | |
| 4 } | |
| 5 full_path() { | |
| 6 # It all depends on the first character. | |
| 7 start=${i%${i#?}} | |
| 8 path= | |
| 9 case "${start}" in | |
| 10 /) path="${1}";; # / is absolute. No change. | |
| 11 *) path="${2}/${1}";; # Anything else must be prefixed with $2 (hopefully $PWD) | |
| 12 esac | |
| 13 printf "%s" "${path}" # Return. | |
| 14 } | |
| 15 for i in "$@"; do | |
| 16 src_ext="${i##*.}" | |
| 17 src_path="$(full_path "${i}" "${PWD}")" | |
| 18 if [ -f "${src_path}" ] && [ -r "${src_path}" ] && [ "${src_ext}" != "${i}" ] && [ "$(to_lower ${src_ext})" = "rar" ]; then | |
| 19 tmpdir=".tmp.${i##*/}" | |
| 20 if mkdir -p "${tmpdir}"; then | |
| 21 if 7z x -o"${tmpdir}" -- "${src_path}"; then | |
| 22 (cd "${tmpdir}" && 7z a -mx=1 -tzip "${src_path%.*}.zip" -- "*";) | |
| 23 fi | |
| 24 rm -r "${tmpdir}" | |
| 25 fi | |
| 26 else | |
| 27 echo "Invalid input: ${i}" | |
| 28 fi | |
| 29 done | |
| 30 |
