Linux Compression Humanized
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
5.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
  1. #!/bin/bash
  2. VERSION=0.2r3
  3. DEST=$1
  4. shift 1
  5. ORIG=$@
  6. function decompressor()
  7. {
  8. case $DEST in
  9. *.tar)
  10. tar -xvf $DEST
  11. ;;
  12. *.tar.gz | *.tgz)
  13. tar -xzvf $DEST
  14. ;;
  15. *.tar.bz2 | *.tbz | *.tbz2 | *.tb2)
  16. tar xjf $DEST
  17. ;;
  18. *.tar.xz | *.txz)
  19. tar -xf $DEST
  20. ;;
  21. *.bz2)
  22. bzip2 -d $DEST
  23. ;;
  24. *.gz)
  25. gzip -d $DEST
  26. ;;
  27. *.zip)
  28. unzip $DEST
  29. ;;
  30. *.7z)
  31. 7za e $DEST
  32. ;;
  33. *)
  34. echo "Extension not found."
  35. echo -e "For more information run 'lch --help'\n"
  36. ;;
  37. esac
  38. echo -e "\nDone"
  39. exit 0
  40. }
  41. function compressor()
  42. {
  43. case $DEST in
  44. *.tar)
  45. tar -cvf $DEST $ORIG
  46. ;;
  47. *.tar.gz | *.tgz)
  48. tar -czvf $DEST $ORIG
  49. ;;
  50. *.tar.bz2 | *.tbz | *.tbz2 | *.tb2)
  51. tar -c $ORIG | bzip2 > $DEST
  52. ;;
  53. *.tar.xz | *.txz)
  54. tar -cJf $DEST $ORIG
  55. ;;
  56. *.bz2)
  57. bzip2 -c $ORIG > $DEST
  58. ;;
  59. *.gz)
  60. gzip -c $ORIG > $DEST
  61. ;;
  62. *.zip)
  63. zip -r $DEST $ORIG
  64. ;;
  65. *.7z)
  66. 7za a $DEST $ORIG
  67. ;;
  68. *)
  69. echo "Extension not found."
  70. echo -e "For more information run 'lch --help'\n"
  71. ;;
  72. esac
  73. echo -e "\nDone"
  74. exit 0
  75. }
  76. function help()
  77. {
  78. echo "Help:"
  79. echo "-----"
  80. echo ""
  81. echo "lch [-h] [-v] [-c] [-i] [FILE [FILE]]"
  82. echo ""
  83. echo "Examples:"
  84. echo "$ lch -h -This help"
  85. echo "$ lch -v -print version"
  86. echo "$ lch -c -check compresion systems"
  87. echo "$ lch -i -install the compressors dependencies."
  88. echo "$ lch file.zip /home/file -Compress"
  89. echo "$ lch file.zip -Decompress"
  90. echo ""
  91. echo "Supported extensions:"
  92. echo " tar, tar.gz, tar.bz2, tar.xz, bz2, tgz, gz, zip, 7z"
  93. echo ""
  94. echo "Run 'man lch' for more info."
  95. echo ""
  96. }
  97. function check()
  98. {
  99. local a=false
  100. echo -e "Verification of compression systems:\n"
  101. echo -e "Systems\t\t\tStatus"
  102. echo "----------------------------------"
  103. for i in "tar" "bzip2" "gzip" "zip" "7za"
  104. do
  105. if ! [ -x "$(command -v $i)" ]
  106. then
  107. echo -e "$i\t\t\t\e[91mNot Installed\e[0m"
  108. $a = true
  109. else
  110. echo -e "$i\t\t\t\e[32mInstalled\e[0m"
  111. fi
  112. done
  113. if $a
  114. then
  115. echo -e "\nIn order to use all the extensions install the packages: tar, bzip2, gzip, zip, 7za"
  116. fi
  117. echo ""
  118. exit 0
  119. }
  120. function install()
  121. {
  122. echo -e "Install dependencies\n"
  123. if [ "$UID" != "0" ]; then
  124. echo " Only root can execute this script, sorry."
  125. echo " Try 'sudo $0 $DEST'"
  126. exit 0
  127. fi
  128. if [ -x "$(command -v apt)" ]
  129. then
  130. echo -e "Detect APT system\n"
  131. apt install -y tar bzip2 gzip zip p7zip-full 1> /dev/null
  132. elif [ -x "$(command -v dnf)" ] && ! [ -n "$(grep "centos" /etc/*-release)" ]
  133. then
  134. echo -e "Detect DNF system\n"
  135. dnf install -y -q tar bzip2 gzip zip p7zip 1> /dev/null
  136. elif [ -x "$(command -v yum)" ] && ! [ -n "$(grep "centos" /etc/*-release)" ]
  137. then
  138. echo -e "Detect Yum system\n"
  139. yum install -y -q tar bzip2 gzip zip p7zip 1> /dev/null
  140. elif [ -n "$(grep "centos" /etc/*-release)" ]
  141. then
  142. echo -e "Detect CentOS system\n"
  143. yum install -y -q epel-release 1> /dev/null
  144. rpm -U --quiet http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm 1> /dev/null
  145. rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 1> /dev/null
  146. yum repolist 1> /dev/null
  147. yum install -y -q p7zip p7zip-plugins 1> /dev/null
  148. yum install -y -q tar bzip2 gzip zip 1> /dev/null
  149. elif [ -x "$(command -v pacman)" ]
  150. then
  151. echo -e "Detect Pacman system\n"
  152. pacman -Sqy --noconfirm tar bzip2 gzip zip p7zip 1> /dev/null
  153. elif [ -x "$(command -v zypper)" ]
  154. then
  155. echo -e "Detect Zypper system\n"
  156. zypper install -y tar bzip2 gzip zip p7zip-full 1> /dev/null
  157. else
  158. echo -e "System installer not detected\n"
  159. fi
  160. echo -e "\nDependencies installation completed\n"
  161. exit 0
  162. }
  163. if [ "$DEST" = "--help" ] || [ "$DEST" = "-h" ]
  164. then
  165. help
  166. exit 0
  167. fi
  168. if [ "$DEST" = "--check" ] || [ "$DEST" = "-c" ]
  169. then
  170. check
  171. exit 0
  172. fi
  173. if [ "$DEST" = "--install" ] || [ "$DEST" = "-i" ]
  174. then
  175. install
  176. exit 0
  177. fi
  178. if [ "$DEST" = "--version" ] || [ "$DEST" = "-v" ]
  179. then
  180. echo "Linux Compression Humanized $VERSION"
  181. exit 0
  182. else
  183. echo -e "\nlch $VERSION"
  184. echo -e "---------\n"
  185. fi
  186. if [ -z "$DEST" ]
  187. then
  188. help
  189. exit 1
  190. else
  191. if [ -n "$ORIG" ]
  192. then
  193. echo "Compressor:"
  194. echo "-----------"
  195. echo ""
  196. compressor $DEST $ORIG
  197. else
  198. echo "Decompressor:"
  199. echo "-------------"
  200. echo ""
  201. decompressor $DEST
  202. fi
  203. fi