From 54194e3b89949fee15f10083970e04f1bf177fd5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gustavo=20Adolfo=20Mesa=20Rold=C3=A1n?=
 <gustavo.mesa@hidup.io>
Date: Sat, 3 Oct 2020 12:15:05 +0200
Subject: [PATCH] 0.6r2

---
 lch                               |  2 +-
 lib/installer.sh                  | 21 ++--------
 lib/installers/{apt.sh => deb.sh} |  2 +-
 lib/installers/rpm.sh             | 65 +++++++++++++++++++++++++++++++
 lib/resources.sh                  |  2 +-
 5 files changed, 72 insertions(+), 20 deletions(-)
 rename lib/installers/{apt.sh => deb.sh} (96%)
 create mode 100644 lib/installers/rpm.sh

diff --git a/lch b/lch
index 3f4dacc..034326e 100755
--- a/lch
+++ b/lch
@@ -1,5 +1,5 @@
 #!/usr/bin/env bash
-VERSION=0.6r1
+VERSION=0.6r2
 DEST=$1
 shift 1
 ORIG=$@
diff --git a/lib/installer.sh b/lib/installer.sh
index 27409aa..c9bebce 100644
--- a/lib/installer.sh
+++ b/lib/installer.sh
@@ -49,24 +49,11 @@ function install()
 
     if [ -x "$(command -v apt)" ]
     then
-        if [[ -e  ./lib/installers/apt.sh ]]; then . ./lib/installers/apt.sh; else . /usr/lib/lch/installers/apt.sh; fi
-        # Hasta aqui he modificado
-    elif [ -n "$(grep "centos" /etc/*-release)" ]
-    then
-        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 [ -x "$(command -v dnf)" ]
+        if [[ -e  ./lib/installers/deb.sh ]]; then . ./lib/installers/deb.sh; else . /usr/lib/lch/installers/deb.sh; fi
+    elif [ -x "$(command -v dnf)" ] || [ -x "$(command -v yum)" ]
     then
-        echo -e "DNF system detected"
-        dnf install -y -q tar bzip2 gzip zip unzip p7zip p7zip-plugins 1> /dev/null
-    elif [ -x "$(command -v yum)" ]
-    then
-        echo -e "Yum system detected"
-        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
+        # Hasta aqui he modificado
     elif [ -x "$(command -v pacman)" ]
     then
         echo -e "Pacman system detected"
diff --git a/lib/installers/apt.sh b/lib/installers/deb.sh
similarity index 96%
rename from lib/installers/apt.sh
rename to lib/installers/deb.sh
index 250654f..c2ce27e 100644
--- a/lib/installers/apt.sh
+++ b/lib/installers/deb.sh
@@ -26,7 +26,7 @@ if [ $# -eq 1 ]; then
 else
     for i in $@
     do
-        if [ $i != "-i" ]
+        if [ $i -ne "-i" ]
         then
             case $i in
                 "rar" | "unrar")
diff --git a/lib/installers/rpm.sh b/lib/installers/rpm.sh
new file mode 100644
index 0000000..c97ee1f
--- /dev/null
+++ b/lib/installers/rpm.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+
+# Function
+
+function get_dep(){
+    # Busca la manera de capturar el error. Y mostrar mensaje en rojo.
+    yum install -y -q $@ 1> /dev/null
+    if [[ $@ -ne "p7zip-plugins" ]]; then complete_install $@; fi
+}
+
+# Run
+
+echo -e "APT system detected"
+echo "---------------------"
+
+if [ $# -eq 1 ]; then 
+    if $PRIVSOFT; then 
+        rarInstall
+    fi
+    get_dep tar 
+    get_dep bzip2 
+    get_dep gzip 
+    get_dep zip
+    get_dep unzip 
+    get_dep p7zip
+    get_dep p7zip-plugins
+else
+    for i in $@
+    do
+        if [ $i -ne "-i" ]
+        then
+            case $i in
+                "rar" | "unrar")
+                    rarInstall
+                ;;
+                "7z" | "7zip" | "p7zip")
+                    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/resources.sh b/lib/resources.sh
index 2a27df8..c4b6e2e 100644
--- a/lib/resources.sh
+++ b/lib/resources.sh
@@ -72,6 +72,6 @@ function executer()
     fi
 }
 
-complete_install(){
+function complete_install(){
     echo -e "$@:\t\t\t\e[32mComplete\e[0m"
 }
\ No newline at end of file