diff --git a/lch b/lch index 5f1205b..86c87c3 100755 --- a/lch +++ b/lch @@ -4,73 +4,50 @@ DEST=$1 shift 1 ORIG=$@ +if [[ -e /usr/lib/lch/resources.sh ]]; then . /usr/lib/lch/resources.sh; else . ./lib/resources.sh; fi if [[ -e /usr/lib/lch/compressor.sh ]]; then . /usr/lib/lch/compressor.sh; else . ./lib/compressor.sh; fi if [[ -e /usr/lib/lch/decompressor.sh ]]; then . /usr/lib/lch/decompressor.sh; else . ./lib/decompressor.sh; fi -if [[ -e /usr/lib/lch/check.sh ]]; then . /usr/lib/lch/check.sh; else . ./lib/check.sh; fi +if [[ -e /usr/lib/lch/installer.sh ]]; then . /usr/lib/lch/installer.sh; else . ./lib/installer.sh; fi -function help() -{ - echo "Help:" - echo "-----" - echo "" - echo "lch [-h] [-v] [-c] [-i] [FILE [FILE...]]" - echo "" - echo "Examples:" - echo "$ lch -h - This help" - echo "$ lch -v - Print version" - echo "$ lch -c - Check compresion systems" - echo "$ lch -i - Install the compressors dependencies" - echo "$ lch file.zip - Decompress" - echo "$ lch file.zip /home/file - Compress" - echo "$ lch files.zip file1 file2 - Compress multiple" - echo "" - echo "Supported extensions:" - echo " rar, tar, tar.gz, tar.bz2, tar.xz, bz2, tgz, gz, zip, 7z" - echo "" - echo "Run 'man lch' for more info." - echo "" -} - -if [ "$DEST" = "--help" ] || [ "$DEST" = "-h" ] -then - help - exit 0 -fi - -if [ "$DEST" = "--check" ] || [ "$DEST" = "-c" ] -then - check - exit 0 -fi - -if [ "$DEST" = "--install" ] || [ "$DEST" = "-i" ] -then - install $DEST $@ - exit 0 -fi if [ "$DEST" = "--version" ] || [ "$DEST" = "-v" ] -then +then echo "Linux Compression Humanized $VERSION" exit 0 else echo -e "\nlch $VERSION" echo -e "---------\n" -fi -if [ -z "$DEST" ] -then - help - exit 1 -else - if [ -n "$ORIG" ] - then - echo "Compressor:" - echo -e "-----------\n" - compressor $DEST $ORIG - else - echo "Decompressor:" - echo -e "-------------\n" - decompressor $DEST - fi + case $DEST in + "--help" | "-h") + help + exit 0 + ;; + "--check" | "-c") + check + exit 0 + ;; + "--install" | "-i") + install $DEST $@ + exit 0 + ;; + *) + if [ -z "$DEST" ] + then + help + exit 1 + else + if [ -n "$ORIG" ] + then + echo "Compressor:" + echo -e "-----------\n" + compressor $DEST $ORIG + else + echo "Decompressor:" + echo -e "-------------\n" + decompressor $DEST + fi + fi + ;; + esac fi \ No newline at end of file diff --git a/lib/compressor.sh b/lib/compressor.sh index 1fb658d..8b7905b 100644 --- a/lib/compressor.sh +++ b/lib/compressor.sh @@ -1,11 +1,7 @@ #!/usr/bin/env bash -function lowercase() -{ - echo "$DEST" | tr 'A-Z' 'a-z' -} function compressor() -{ +{ case $(lowercase) in *.tar) tar -cvf $DEST $ORIG @@ -39,7 +35,7 @@ function compressor() echo -e "For more information run 'lch --help'\n" ;; esac - + echo -e "\nDone" exit 0 } diff --git a/lib/decompressor.sh b/lib/decompressor.sh index 4c138f4..6063106 100644 --- a/lib/decompressor.sh +++ b/lib/decompressor.sh @@ -1,8 +1,5 @@ #!/usr/bin/env bash -function lowercase() -{ - echo "$DEST" | tr 'A-Z' 'a-z' -} + function decompressor() { case $(lowercase) in diff --git a/lib/check.sh b/lib/installer.sh similarity index 81% rename from lib/check.sh rename to lib/installer.sh index 3ea2679..38bcc93 100644 --- a/lib/check.sh +++ b/lib/installer.sh @@ -1,28 +1,4 @@ #!/usr/bin/env bash -function check() -{ - local a=false - echo -e "Verification of compression systems:\n" - echo -e "Systems\t\t\tStatus" - echo "----------------------------------" - for i in "rar" "unrar" "tar" "bzip2" "gzip" "zip" "unzip" "7za" - do - if ! [ -x "$(command -v $i)" ] - then - echo -e "$i\t\t\t\e[91mNot Installed\e[0m" - $a = true - else - echo -e "$i\t\t\t\e[32mInstalled\e[0m" - fi - done - - if $a - then - echo -e "\nIn order to use all the extensions install the packages: tar, bzip2, gzip, zip, unzip, 7za, rar, unrar" - fi - echo "" - exit 0 -} function rarInstall(){ if [ -e "$(command -v wget)" ] diff --git a/lib/resources.sh b/lib/resources.sh new file mode 100644 index 0000000..068d0b1 --- /dev/null +++ b/lib/resources.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +function help() +{ + echo "Help:" + echo "-----" + echo "" + echo "lch [-h] [-v] [-c] [-i] [FILE [FILE...]]" + echo "" + echo "Examples:" + echo "$ lch -h - This help" + echo "$ lch -v - Print version" + echo "$ lch -c - Check compresion systems" + echo "$ lch -i - Install the compressors dependencies" + echo "$ lch file.zip - Decompress" + echo "$ lch file.zip /home/file - Compress" + echo "$ lch files.zip file1 file2 - Compress multiple" + echo "" + echo "Supported extensions:" + echo " rar, tar, tar.gz, tar.bz2, tar.xz, bz2, tgz, gz, zip, 7z" + echo "" + echo "Run 'man lch' for more info." + echo "" +} + +function check() +{ + local a=false + echo -e "Verification of compression systems:\n" + echo -e "Systems\t\t\tStatus" + echo "----------------------------------" + for i in "rar" "unrar" "tar" "bzip2" "gzip" "zip" "unzip" "7za" + do + if ! [ -x "$(command -v $i)" ] + then + echo -e "$i\t\t\t\e[91mNot Installed\e[0m" + $a = true + else + echo -e "$i\t\t\t\e[32mInstalled\e[0m" + fi + done + + if $a + then + echo -e "\nIn order to use all the extensions install the packages: tar, bzip2, gzip, zip, unzip, 7za, rar, unrar" + fi + echo "" + exit 0 +} + +function lowercase() +{ + echo "$DEST" | tr 'A-Z' 'a-z' +} \ No newline at end of file