#!/bin/bash VERSION=0.2r3 DEST=$1 shift 1 ORIG=$@ function decompressor() { case $DEST in *.tar) tar -xvf $DEST ;; *.tar.gz | *.tgz) tar -xzvf $DEST ;; *.tar.bz2 | *.tbz | *.tbz2 | *.tb2) tar xjf $DEST ;; *.tar.xz | *.txz) tar -xf $DEST ;; *.bz2) bzip2 -d $DEST ;; *.gz) gzip -d $DEST ;; *.zip) unzip $DEST ;; *.7z) 7za e $DEST ;; *) echo "Extension not found." echo -e "For more information run 'lch --help'\n" ;; esac echo -e "\nDone" exit 0 } function compressor() { case $DEST in *.tar) tar -cvf $DEST $ORIG ;; *.tar.gz | *.tgz) tar -czvf $DEST $ORIG ;; *.tar.bz2 | *.tbz | *.tbz2 | *.tb2) tar -c $ORIG | bzip2 > $DEST ;; *.tar.xz | *.txz) tar -cJf $DEST $ORIG ;; *.bz2) bzip2 -c $ORIG > $DEST ;; *.gz) gzip -c $ORIG > $DEST ;; *.zip) zip -r $DEST $ORIG ;; *.7z) 7za a $DEST $ORIG ;; *) echo "Extension not found." echo -e "For more information run 'lch --help'\n" ;; esac echo -e "\nDone" exit 0 } 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 /home/file -Compress" echo "$ lch file.zip -Decompress" echo "" echo "Supported extensions:" echo " 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 "tar" "bzip2" "gzip" "zip" "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, 7za" fi echo "" exit 0 } function install() { echo -e "Install dependencies\n" if [ "$UID" != "0" ]; then echo " Only root can execute this script, sorry." echo " Try 'sudo $0 $DEST'" exit 0 fi if [ -x "$(command -v apt)" ] then echo -e "Detect APT system\n" apt install -y tar bzip2 gzip zip p7zip-full 1> /dev/null elif [ -x "$(command -v dnf)" ] && ! [ -n "$(grep "centos" /etc/*-release)" ] then echo -e "Detect DNF system\n" dnf install -y -q tar bzip2 gzip zip p7zip 1> /dev/null elif [ -x "$(command -v yum)" ] && ! [ -n "$(grep "centos" /etc/*-release)" ] then echo -e "Detect Yum system\n" yum install -y -q tar bzip2 gzip zip p7zip 1> /dev/null elif [ -n "$(grep "centos" /etc/*-release)" ] then echo -e "Detect CentOS system\n" yum install -y -q epel-release 1> /dev/null rpm -U --quiet http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm 1> /dev/null rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 1> /dev/null yum repolist 1> /dev/null yum install -y -q p7zip p7zip-plugins 1> /dev/null yum install -y -q tar bzip2 gzip zip 1> /dev/null elif [ -x "$(command -v pacman)" ] then echo -e "Detect Pacman system\n" pacman -Sqy --noconfirm tar bzip2 gzip zip p7zip 1> /dev/null elif [ -x "$(command -v zypper)" ] then echo -e "Detect Zypper system\n" zypper install -y tar bzip2 gzip zip p7zip-full 1> /dev/null else echo -e "System installer not detected\n" fi echo -e "\nDependencies installation completed\n" exit 0 } 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 exit 0 fi if [ "$DEST" = "--version" ] || [ "$DEST" = "-v" ] 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 "-----------" echo "" compressor $DEST $ORIG else echo "Decompressor:" echo "-------------" echo "" decompressor $DEST fi fi