From 4e04efe1afd90b78ece707fcf334a312d5336700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Adolfo=20Mesa=20Rold=C3=A1n?= Date: Sat, 3 Oct 2020 08:01:47 +0200 Subject: [PATCH] 0.5r9 - Executer --- lch | 5 +++- lib/compressor.sh | 63 +++++++-------------------------------------- lib/decompressor.sh | 63 +++++++-------------------------------------- lib/installer.sh | 2 +- lib/resources.sh | 10 +++++++ 5 files changed, 33 insertions(+), 110 deletions(-) diff --git a/lch b/lch index c08e0b1..4bf708b 100755 --- a/lch +++ b/lch @@ -1,5 +1,5 @@ #!/usr/bin/env bash -VERSION=0.5r8 +VERSION=0.5r9 DEST=$1 shift 1 ORIG=$@ @@ -9,6 +9,9 @@ if [[ -e /usr/lib/lch/compressor.sh ]]; then . /usr/lib/lch/compressor.sh; else if [[ -e /usr/lib/lch/decompressor.sh ]]; then . /usr/lib/lch/decompressor.sh; else . ./lib/decompressor.sh; fi if [[ -e /usr/lib/lch/installer.sh ]]; then . /usr/lib/lch/installer.sh; else . ./lib/installer.sh; fi + +# executer tar -cvf $DEST $ORIG + if [ "$DEST" = "--version" ] || [ "$DEST" = "-v" ] then echo "Linux Compression Humanized $VERSION" diff --git a/lib/compressor.sh b/lib/compressor.sh index 362b32e..ee5750d 100644 --- a/lib/compressor.sh +++ b/lib/compressor.sh @@ -4,76 +4,31 @@ function compressor() { case $(lowercase) in *.tar) - if [ -x "$(command -v tar)" ] - then - tar -cvf $DEST $ORIG - else - error_not_install "tar" - fi + executer tar -cvf $DEST $ORIG ;; *.tar.gz | *.tgz) - if [ -x "$(command -v tar)" ] - then - tar -czvf $DEST $ORIG - else - error_not_install "tar" - fi + executer tar -czvf $DEST $ORIG ;; *.tar.bz2 | *.tbz | *.tbz2 | *.tb2) - if [ -x "$(command -v tar)" ] - then - tar -c $ORIG | bzip2 > $DEST - else - error_not_install "tar" - fi + executer tar -c $ORIG | bzip2 > $DEST ;; *.tar.xz | *.txz) - if [ -x "$(command -v tar)" ] - then - tar -cJf $DEST $ORIG - else - error_not_install "tar" - fi + executer tar -cJf $DEST $ORIG ;; *.bz2) - if [ -x "$(command -v bzip2)" ] - then - bzip2 -c $ORIG > $DEST - else - error_not_install "bzip2" - fi + executer bzip2 -c $ORIG > $DEST ;; *.gz) - if [ -x "$(command -v gzip)" ] - then - gzip -c $ORIG > $DEST - else - error_not_install "gzip" - fi + executer gzip -c $ORIG > $DEST ;; *.zip) - if [ -x "$(command -v zip)" ] - then - zip -r $DEST $ORIG - else - error_not_install "zip" - fi + executer zip -r $DEST $ORIG ;; *.7z) - if [ -x "$(command -v 7z)" ] - then - 7z a $DEST $ORIG - else - error_not_install "7z" - fi + executer 7z a $DEST $ORIG ;; *.rar) - if [ -x "$(command -v rar)" ] - then - rar a $DEST $ORIG - else - error_not_install "rar" - fi + executer rar a $DEST $ORIG ;; *) echo "Extension not found." diff --git a/lib/decompressor.sh b/lib/decompressor.sh index 78691ad..b1258b1 100644 --- a/lib/decompressor.sh +++ b/lib/decompressor.sh @@ -4,76 +4,31 @@ function decompressor() { case $(lowercase) in *.tar) - if [ -x "$(command -v tar)" ] - then - tar -xvf $DEST - else - error_not_install "tar" - fi + executer tar -xvf $DEST ;; *.tar.gz | *.tgz) - if [ -x "$(command -v tar)" ] - then - tar -xzvf $DEST - else - error_not_install "tar" - fi + executer tar -xzvf $DEST ;; *.tar.bz2 | *.tbz | *.tbz2 | *.tb2) - if [ -x "$(command -v tar)" ] - then - tar xjf $DEST - else - error_not_install "tar" - fi + executer tar xjf $DEST ;; *.tar.xz | *.txz) - if [ -x "$(command -v tar)" ] - then - tar -xf $DEST - else - error_not_install "tar" - fi + executer tar -xf $DEST ;; *.bz2) - if [ -x "$(command -v bzip2)" ] - then - bzip2 -d $DEST - else - error_not_install "bzip2" - fi + executer bzip2 -d $DEST ;; *.gz) - if [ -x "$(command -v gzip)" ] - then - gzip -d $DEST - else - error_not_install "gzip" - fi + executer gzip -d $DEST ;; *.zip) - if [ -x "$(command -v unzip)" ] - then - unzip $DEST - else - error_not_install "unzip" - fi + executer unzip $DEST ;; *.7z | *.arj | *.cab | *.dmg | *.iso | *.lzh | *.lzma | *.rpm | *.squashfs | *.vdi | *.vhd | *.vmdk | *.win | *.xar | *.z) - if [ -x "$(command -v 7z)" ] - then - 7z e -y $DEST - else - error_not_install "7z" - fi + executer 7z e -y $DEST ;; *.rar) - if [ -x "$(command -v unrar)" ] - then - unrar x $DEST - else - error_not_install "unrar" - fi + executer unrar x $DEST ;; *) echo "Extension not found." diff --git a/lib/installer.sh b/lib/installer.sh index 7600ea4..1ac828f 100644 --- a/lib/installer.sh +++ b/lib/installer.sh @@ -19,7 +19,7 @@ function rarInstall(){ rm -r rar $RAR_FILE echo "rar/unrar installed." else - echo -e "\n\e[91m[Error]\e[0m - Wget is not installed, so rar could not be installed.\nPlease install wget.\n" + echo -e "\n\e[91m[Error]\e[0m - wget is not installed, so rar could not be installed.\nPlease install wget.\n" read -p "Press [ENTER] to continue installing or [CTRL+C] to exit." fi } diff --git a/lib/resources.sh b/lib/resources.sh index 778d2e5..ee8790d 100644 --- a/lib/resources.sh +++ b/lib/resources.sh @@ -60,4 +60,14 @@ function error_not_install() { echo -e "$@ \e[91mis not installed\e[0m, use 'lch -i' to install and 'lch -c' to check." exit 0 +} + +function executer() +{ + if [ -x "$(command -v $1)" ] + then + "$@" + else + error_not_install $1 + fi } \ No newline at end of file