diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/rar2zip	Sat Jul 10 12:38:52 2010 +0000
@@ -0,0 +1,30 @@
+#!/bin/sh
+to_lower() {
+  printf "%s" "$1" | tr '[:upper:]' '[:lower:]'
+}
+full_path() {
+  # It all depends on the first character.
+  start=${i%${i#?}}
+  path=
+  case "${start}" in
+    /) path="${1}";; # / is absolute. No change.
+    *) path="${2}/${1}";; # Anything else must be prefixed with $2 (hopefully $PWD)
+  esac
+  printf "%s" "${path}" # Return.
+}
+for i in "$@"; do
+  src_ext="${i##*.}"
+  src_path="$(full_path "${i}" "${PWD}")"
+  if [ -f "${src_path}" ] && [ -r "${src_path}" ] && [ "${src_ext}" != "${i}" ] && [ "$(to_lower ${src_ext})" = "rar" ]; then
+    tmpdir=".tmp.${i##*/}"
+    if mkdir -p "${tmpdir}"; then
+      if 7z x -o"${tmpdir}" -- "${src_path}"; then
+        (cd "${tmpdir}" && 7z a -mx=1 -tzip "${src_path%.*}.zip" -- "*";)
+      fi
+      rm -r "${tmpdir}"
+    fi
+  else
+    echo "Invalid input: ${i}"
+  fi
+done
+