#!/usr/bin/env bash
##############################################################
#     Script Para Automatizacion De Kraken Console           #
#           Author: Marian Sanchez                           #
##############################################################


if [ -e /tmp/package_failed_temp ]; then
						
							echo -e "\e[93m Esta respuesta solo funciona en equipos RedHat o derivados que tengan acceso a internet y esten subscritos .... Espere un momento\e[0m"


							readarray -t arregloX < /tmp/package_failed_temp

							for c in ${arregloX[@]}
							do

								echo "SERVIDOR $c " > /tmp/install_log
								sshpass -p $2 ssh $c -o ConnectTimeout=5 "echo $2 | sudo -S yum install $1 -y" 2>> /tmp/install_log
								sshpass -p $2 ssh $c -o ConnectTimeout=5 "rpm -qa | grep $1" 2>> /tmp/install_log
							
								if [ $? -eq 0 ]; then
								
									echo $c >> /tmp/install_ok

								
								else
								
									echo $c >> /tmp/install_fail
	
								fi
								
							done
																				
						
						
fi

log=$(cat /tmp/install_log)
ok=$(cat /tmp/install_ok)
nok$(cat /tmp/install_fail)

echo -e "\e[32m PAQUETE $1 INSTALADO EN SERVIDOR \e[0m"
echo -e "\e[32m $ok \e[0m"
echo -e "\n"
echo -e "\e[31m PAQUETE $1 NO INSTALADO EN SERVIDOR \e[0m"
echo -e "\e[31m $nok \e[0m"
echo -e "\n"


echo -e "\e[93m --------------------- LOGS ------------------------ \e[0m"
echo -e "\e[93m $log \e[0m"
echo -e "\n\n"

rm -f /tmp/package_failed_temp &> /dev/null
rm -f /tmp/install_log &> /dev/null
rm -f /tmp/install_ok &> /dev/null
rm -f /tmp/install_fail &> /dev/null

exit;
