multi decompress


SUBMITTED BY: Guest

DATE: Dec. 6, 2013, 9:06 a.m.

FORMAT: Bash

SIZE: 3.0 kB

HITS: 687

  1. #!/bin/bash
  2. # Default extraction target CWD
  3. exdir="."
  4. _unzip() {
  5. unzip "$1" -d "$exdir"
  6. }
  7. while [ -n "$1" ]; do
  8. case "$1" in
  9. "-h")
  10. echo "Usage: unpack [-D dir] [files]
  11. -D dir Set output directory
  12. files Files to extract/decompress"
  13. exit 0
  14. ;;
  15. "-D")
  16. shift
  17. # ignore checks
  18. # [ -d "$1" -a -w "$1" ] && exdir="$1"
  19. # `readlink' important when $exdir compared with `pwd'
  20. exdir="`readlink -f \"$1\"`"
  21. ;;
  22. -*)
  23. # switches
  24. ;;
  25. *)
  26. break
  27. ;;
  28. esac
  29. shift
  30. done
  31. while [ -n "$1" ]; do
  32. bfn="${1##*/}" # base file name
  33. fn="${bfn%.*}" # without extension
  34. exfn="${exdir}/${fn}" # base file in output dir
  35. lcbfn=`echo "${1##*/}" | tr "[:upper:]" "[:lower:]"`; # lower case base file name
  36. apn=`readlink -f "$1"` # absolute path name
  37. case "$lcbfn" in
  38. *.tar)
  39. tar -C "$exdir" -xvf "$1";;
  40. *.tgz|*.tar.gz|*.dsl)
  41. tar -C "$exdir" -xvzf "$1";;
  42. *.tbz2|*.tar.bz2|*.tbz)
  43. tar -C "$exdir" -xvjf "$1";;
  44. *.tar.z|*.taz)
  45. tar -C "$exdir" -xvZf "$1";;
  46. *.z)
  47. if [ "`pwd`" = "$exdir" ]; then
  48. uncompress "$1"
  49. else
  50. uncompress -c "$1" > "${exfn}"
  51. fi;;
  52. *.gz)
  53. if [ "`pwd`" = "$exdir" ]; then
  54. gunzip -dv "$1"
  55. else
  56. gunzip -dcv "$1" > "${exfn}"
  57. fi;;
  58. *.bz2)
  59. if [ "`pwd`" = "$exdir" ]; then
  60. bunzip2 -dv "$1"
  61. else
  62. bunzip2 -dcv "$1" > "${exfn}"
  63. fi;;
  64. *.arj)
  65. arj e "$1" "$exdir";;
  66. *.lzh|*.lha)
  67. lha -xvw="$exdir" "$1";;
  68. *.rar)
  69. unrar x "$1" "$exdir";;
  70. *.zip|*.wsz|*.xpi)
  71. _unzip "$1";;
  72. *.odt|*.ods)
  73. _unzip "$1";;
  74. *.docx|*.pptx|*.xlsx)
  75. _unzip "$1";;
  76. *.jar)
  77. if [ -x "`which jar`" ]; then
  78. jar -xvf "$1"
  79. else
  80. _unzip "$1"
  81. fi;;
  82. *.zoo)
  83. if cd "$exdir"; then
  84. zoo x "$apn"
  85. cd -
  86. fi;;
  87. *.deb)
  88. dpkg -X "$1" "$exdir";;
  89. *.rpm)
  90. if cd "$exdir"; then
  91. rpm2cpio "$apn" | cpio -vid
  92. cd -
  93. fi;;
  94. *.7z)
  95. 7zr x -o"$exdir" "$1";;
  96. *.cab|*.msi)
  97. cabextract -d "$exdir" "$1";;
  98. *.ace)
  99. if cd "$exdir"; then
  100. unace e "$apn"
  101. cd -
  102. fi;;
  103. *.ha)
  104. if cd "$exdir"; then
  105. ha xa "$apn"
  106. cd -
  107. fi;;
  108. *.alz)
  109. unalz -d "$exdir" "$1";;
  110. *.arc|*.ark)
  111. if cd "$exdir"; then
  112. nomarch "$apn"
  113. cd -
  114. fi;;
  115. #*.uha
  116. # dosemu uharcd.exe x -t"$exdir" "$1";;
  117. #*.dar
  118. # true;;
  119. *.a|*.ar)
  120. ar xo "$1";;
  121. *.iso)
  122. exdir="$exdir" unpack-iso "$1";;
  123. thumbs.db|ehthumbs.db|thumbcache_*.db)
  124. vinetto -o "$exdir" "$1";;
  125. *)
  126. mime="`file -i "$1"`"
  127. case "$mime" in
  128. "application/x-zip")
  129. _unzip "$1";;
  130. *)
  131. echo "unpack: Unknown compression type." >&2
  132. file -k "$1" >&2;;
  133. esac;;
  134. esac
  135. shift
  136. done
  137. exit $?

comments powered by Disqus