diff --git a/lch b/lch index a311d9c..0067165 100755 --- a/lch +++ b/lch @@ -1,5 +1,5 @@ #!/usr/bin/env bash -VERSION=0.5r10 +VERSION=0.6r8 DEST=$1 shift 1 ORIG=$@ @@ -9,9 +9,6 @@ if [[ -e ./lib/compressor.sh ]]; then . ./lib/compressor.sh; else . /usr/lib/lc if [[ -e ./lib/decompressor.sh ]]; then . ./lib/decompressor.sh; else . /usr/lib/lch/decompressor.sh; fi if [[ -e ./lib/installer.sh ]]; then . ./lib/installer.sh; else . /usr/lib/lch/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 ee5750d..96e433b 100644 --- a/lib/compressor.sh +++ b/lib/compressor.sh @@ -36,5 +36,5 @@ function compressor() ;; esac - echo -e "\nDone" -} + echo -e "\nFile $DEST compressed." +} \ No newline at end of file diff --git a/lib/decompressor.sh b/lib/decompressor.sh index b1258b1..6302289 100644 --- a/lib/decompressor.sh +++ b/lib/decompressor.sh @@ -36,5 +36,5 @@ function decompressor() ;; esac - echo -e "\nDone" + echo -e "\nFile $DEST decompressed." } \ No newline at end of file diff --git a/lib/installer.sh b/lib/installer.sh index b374563..ef24acc 100644 --- a/lib/installer.sh +++ b/lib/installer.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash function rarInstall(){ - if [ -e "$(command -v wget)" ] + if [ -e "$(command -v wget)" ] || [ -e "$(command -v curl)" ] then if [[ "$(uname -m)" == "x86_64" ]] then @@ -11,74 +11,61 @@ function rarInstall(){ RAR_URL="https://www.rarlab.com/rar/rarlinux-5.9.1.tar.gz" RAR_FILE="rarlinux-5.9.1.tar.gz" fi - wget $RAR_URL - tar -zxvf $RAR_FILE + if [ -e "$(command -v wget)" ] + then + wget -q $RAR_URL > /dev/null + else + curl -s -o $RAR_FILE $RAR_URL > /dev/null + fi + tar -zxvf $RAR_FILE > /dev/null cd rar - cp -v rar unrar /usr/local/bin/ + cp -v rar unrar /usr/local/bin/ > /dev/null cd .. - rm -r rar $RAR_FILE - echo "rar/unrar installed." + rm -r rar $RAR_FILE > /dev/null + complete_install "rar" 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 or curl 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 } function install() { - echo -e "Install dependencies\n" - if [ "$UID" != "0" ]; then echo " Only root can execute this script, sorry." echo " Try 'sudo lch $@'" exit 0 fi - - if [ -e "$(command -v rar)" ] - then - echo "rar installed." + + if [ $# -eq 1 ]; then + # Poner aviso "Vamos a instalarlo todo y mucho" + read -p "Do you want to install non-free software? (rar, unrar) [y/N]: " PRIVSOFT + case ${PRIVSOFT} in + y | Y | yes) + PRIVSOFT=true + echo -e "\nInstall all dependencies (with non-free)\n";; + *) + PRIVSOFT=false + echo -e "\nOnly will install free software.\n";; + esac else - read -p "Do you want to install non-free software? (rar, unrar) [Y/N]: " PRIVSOFT - case ${PRIVSOFT} in - y|Y) - rarInstall;; - n|N) - echo -e "\nOnly will install free software.\n";; - *) - echo -e "Options: 'Y' or 'N': ";; - esac + PRIVSOFT=false fi - + if [ -x "$(command -v apt)" ] then - echo -e "APT system detected\n" - apt install -y tar bzip2 gzip zip unzip p7zip-full p7zip-rar 1> /dev/null - elif [ -n "$(grep "centos" /etc/*-release)" ] - then - echo -e "CentOS system detected\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 tar bzip2 gzip zip unzip p7zip p7zip-plugins 1> /dev/null - elif [ -x "$(command -v dnf)" ] - then - echo -e "DNF system detected\n" - dnf install -y -q tar bzip2 gzip zip unzip p7zip p7zip-plugins 1> /dev/null + if [[ -e ./lib/installers/deb.sh ]]; then . ./lib/installers/deb.sh; else . /usr/lib/lch/installers/deb.sh; fi elif [ -x "$(command -v yum)" ] then - echo -e "Yum system detected\n" - yum install -y -q tar bzip2 gzip zip unzip p7zip p7zip-plugins 1> /dev/null + if [[ -e ./lib/installers/rpm.sh ]]; then . ./lib/installers/rpm.sh; else . /usr/lib/lch/installers/rpm.sh; fi elif [ -x "$(command -v pacman)" ] then - echo -e "Pacman system detected\n" - pacman -Sqy --noconfirm tar bzip2 gzip zip unzip p7zip 1> /dev/null + if [[ -e ./lib/installers/pacman.sh ]]; then . ./lib/installers/pacman.sh; else . /usr/lib/lch/installers/pacman.sh; fi elif [ -x "$(command -v zypper)" ] then - echo -e "Zypper system detected\n" - zypper install -y tar bzip2 gzip zip unzip p7zip-full 1> /dev/null + if [[ -e ./lib/installers/zypper.sh ]]; then . ./lib/installers/zypper.sh; else . /usr/lib/lch/installers/zypper.sh; fi else - echo -e "System installer not detected\n" + echo -e "System installer not detected" fi echo -e "\nDependencies installation finished\n" diff --git a/lib/installers/deb.sh b/lib/installers/deb.sh new file mode 100644 index 0000000..3e9b16c --- /dev/null +++ b/lib/installers/deb.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +# Functions + +function get_dep(){ + wheel true & + WPID=$! + apt-get install -y $@ &> /dev/null + if [[ $? -ne 0 ]]; then + if [[ $@ == "p7zip-full" ]]; then failed_install 7z; else failed_install $@; fi + else + if [[ $@ == "p7zip-full" ]]; then complete_install 7z; else complete_install $@; fi + fi + disown $WPID + kill $WPID &> /dev/null +} + +# Run + +echo -e "APT system detected" +echo "---------------------" + +wheel true & +WPID=$! +apt-get update 1> /dev/null +disown $WPID +kill $WPID &> /dev/null + + +if [ $# -eq 1 ]; then + if $PRIVSOFT; then + rarInstall + fi + for installer in "tar" "bzip2" "gzip" "zip" "unzip" "p7zip-full" + do get_dep $installer + done +else + for i in $@ + do + if [ $i -ne "-i" ] + then + case $i in + "rar" | "unrar") + rarInstall + ;; + "7z" | "7zip" | "p7zip") + get_dep p7zip-full + ;; + *) + get_dep $i + ;; + esac + fi + done +fi \ No newline at end of file diff --git a/lib/installers/pacman.sh b/lib/installers/pacman.sh new file mode 100644 index 0000000..8154713 --- /dev/null +++ b/lib/installers/pacman.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# Function + +function get_dep(){ + wheel true & + WPID=$! + pacman -Sqy --noconfirm $@ &> /dev/null + if [[ $? -ne 0 ]]; then + if [[ $@ == "p7zip" ]]; then failed_install 7z; else failed_install $@; fi + else + if [[ $@ == "p7zip" ]]; then complete_install 7z; else complete_install $@; fi + fi + disown $WPID + kill $WPID &> /dev/null +} + +# Run +echo -e "Pacman system detected" +echo "---------------------" + +wheel true & +WPID=$! +pacman -F -y 1> /dev/null +disown $WPID +kill $WPID &> /dev/null + +if [ $# -eq 1 ]; then + if $PRIVSOFT; then + rarInstall + fi + for installer in "tar" "bzip2" "gzip" "zip" "unzip" "p7zip" + do get_dep $installer + done +else + for i in $@ + do + if [ $i -ne "-i" ] + then + case $i in + "rar" | "unrar") + rarInstall + ;; + "7z" | "7zip" | "p7zip") + get_dep p7zip + ;; + *) + get_dep $i + ;; + esac + fi + done +fi \ No newline at end of file diff --git a/lib/installers/rpm.sh b/lib/installers/rpm.sh new file mode 100644 index 0000000..2eb2fbc --- /dev/null +++ b/lib/installers/rpm.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +# Functions + +function get_dep(){ + wheel true & + WPID=$! + if [[ $@ == "p7zip-plugins" ]]; then + yum install -y -q $@ 1> /dev/null + else + yum install -y -q $@ 1> /dev/null + if [[ $? -ne 0 ]]; then + if [[ $@ == "p7zip" ]]; then failed_install 7z; else failed_install $@; fi + else + if [[ $@ == "p7zip" ]]; then complete_install 7z; else complete_install $@; fi + fi + fi + disown $WPID + kill $WPID &> /dev/null +} + +function install_centos(){ + if [ -n "$(grep "centos" /etc/*-release)" ]; then + yum install -y -q epel-release &> /dev/null + rpm --quiet --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8 &> /dev/null + rpm -U --quiet http://mirrors.kernel.org/fedora-epel/6/i386/epel-release-6-8.noarch.rpm &> /dev/null + fi +} + +# Run + +echo -e "YUM system detected" +echo "---------------------" + +wheel true & +WPID=$! +yum -y -q update &> /dev/null +disown $WPID +kill $WPID &> /dev/null + +if [ $# -eq 1 ]; then + install_centos + if $PRIVSOFT; then + rarInstall + fi + for installer in "tar" "bzip2" "gzip" "zip" "unzip" "p7zip" "p7zip-plugins" + do get_dep $installer + done +else + for i in $@ + do + if [ $i -ne "-i" ] + then + case $i in + "rar" | "unrar") + rarInstall + ;; + "7z" | "7zip" | "p7zip") + install_centos + get_dep p7zip + get_dep p7zip-plugins + ;; + *) + get_dep $i + ;; + esac + fi + done +fi + + +# [ -n "$(grep "centos" /etc/*-release)" ] + + +# echo -e "CentOS system detected" +# 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 tar bzip2 gzip zip unzip p7zip p7zip-plugins 1> /dev/null +# elif +# then +# echo -e "DNF system detected" +# dnf install -y -q tar bzip2 gzip zip unzip p7zip p7zip-plugins 1> /dev/null +# elif +# then +# echo -e "Yum system detected" +# yum install -y -q tar bzip2 gzip zip unzip p7zip p7zip-plugins 1> /dev/null \ No newline at end of file diff --git a/lib/installers/zypper.sh b/lib/installers/zypper.sh new file mode 100644 index 0000000..e3dcfae --- /dev/null +++ b/lib/installers/zypper.sh @@ -0,0 +1,54 @@ + +#!/usr/bin/env bash + +# Function + +function get_dep(){ + wheel true & + WPID=$! + zypper install -y $@ &> /dev/null + if [[ $? -ne 0 ]]; then + if [[ $@ == "p7zip-full" ]]; then failed_install 7z; else failed_install $@; fi + else + if [[ $@ == "p7zip-full" ]]; then complete_install 7z; else complete_install $@; fi + fi + disown $WPID + kill $WPID &> /dev/null +} + +# Run +echo -e "Zypper system detected" +echo "---------------------" + +wheel true & +WPID=$! +zypper -q up -y 1> /dev/null +disown $WPID +kill $WPID &> /dev/null + +if [ $# -eq 1 ]; then + if $PRIVSOFT; then + rarInstall + fi + for installer in "tar" "bzip2" "gzip" "zip" "unzip" "p7zip-full" + do get_dep $installer + done +else + for i in $@ + do + if [ $i -ne "-i" ] + then + case $i in + "rar" | "unrar") + rarInstall + ;; + "7z" | "7zip" | "p7zip") + get_dep p7zip-full + ;; + *) + get_dep $i + ;; + esac + fi + done +fi \ No newline at end of file diff --git a/lib/resources.sh b/lib/resources.sh index ee8790d..73e296c 100644 --- a/lib/resources.sh +++ b/lib/resources.sh @@ -34,6 +34,8 @@ function check() echo "----------------------------------" for i in "7z" "bzip2" "gzip" "rar" "tar" "unrar" "unzip" "zip" do + wheel true & + WPID=$! if ! [ -x "$(command -v $i)" ] then echo -e "$i\t\t\t\e[91mNot Installed\e[0m" @@ -41,6 +43,8 @@ function check() else echo -e "$i\t\t\t\e[32mInstalled\e[0m" fi + disown $WPID + kill $WPID &> /dev/null done if $a @@ -64,10 +68,31 @@ function error_not_install() function executer() { + wheel true & + WPID=$! if [ -x "$(command -v $1)" ] then - "$@" + "$@" 1> /dev/null else error_not_install $1 fi + disown $WPID + kill $WPID &> /dev/null +} + +function complete_install(){ + echo -e "$@:\t\t\t\e[32mComplete\e[0m" +} + +function failed_install(){ + echo -e "$@:\t\t\t\e[91mFailed\e[0m" +} + +function wheel() { + sp='/-\|' + while $1; do + printf '%.1s\b' "$sp" + sp=${sp#?}${sp%???} + sleep 0.1s + done } \ No newline at end of file