#!/bin/bash

###################  Jungle-team   ######################
#                  jungle-team.es                       #
######################################################### 

ENLACE_URL="http://tropical.jungle-team.online/feeds"
IMAGE="blackhole"
SCRIPT="https://raw.githubusercontent.com/jungla-team/enigma2_pre_start/master/enigma2_pre_start.sh"
FONT="https://raw.githubusercontent.com/jungla-team/utilidades/master/DejaVuSansCondensed.ttf"
SOURCES="https://raw.githubusercontent.com/jungla-team/sources-epg-import/master/rytec.sources.xml"
INSCROSSEPG="enigma2-plugin-systemplugins-crossepg"
INSEPGIMPORT="enigma2-plugin-extensions-epgimport"
DIAS3="description=KoalaEPG 3 dias\nprotocol=xmltv\nchannels_url_0=http://tropical.jungle-team.online/epg/koala_epg.channels.xml.gz\nepg_url_0=http://tropical.jungle-team.online/epg/koala3.xml.gz\npreferred_language=spa"
DIAS7="description=KoalaEPG 7 dias\nprotocol=xmltv\nchannels_url_0=http://tropical.jungle-team.online/epg/koala_epg.channels.xml.gz\nepg_url_0=http://tropical.jungle-team.online/epg/koala7.xml.gz\npreferred_language=spa"
DIAS15="description=KoalaEPG 15 dias\nprotocol=xmltv\nchannels_url_0=http://tropical.jungle-team.online/epg/koala_epg.channels.xml.gz\nepg_url_0=http://tropical.jungle-team.online/epg/koala15.xml.gz\npreferred_language=spa"
DIAS30="description=KoalaEPG 30 dias\nprotocol=xmltv\nchannels_url_0=http://tropical.jungle-team.online/epg/koala_epg.channels.xml.gz\nepg_url_0=http://tropical.jungle-team.online/epg/koala30.xml.gz\npreferred_language=spa"

VERDE='\033[0;32m'
ROJO='\033[0;31m'
NC='\033[0m'


function Mensaje() {
	echo -e "$2$1${NC}"
}

function Error() {
	echo -e "\n\a  ${ROJO} $1${NC}" 1>&2
	exit 1
}

function CompruebaInternet() {

	wget -q --spider http://google.com
	
	if [ $? -ne 0 ]; then
		Error "Es necesario disponer de conexiÛn a Internet{NC}"
	fi

}

function Instalacionfeed() {

	Mensaje "Se procede a la instalacion utilidades Jungle-team para Blackhole, tenga paciencia....." $VERDE
	Mensaje "Enigma2 se ha parado, se iniciara nuevamente al terminar la instalacion" $VERDE
	
	init 4 &

    cpu=$(cat /etc/hostname | grep 4k)
    if [ "$cpu" > 0 ];
      then
        echo src/gz tropical-jungle-team $ENLACE_URL/$IMAGE/arm > /etc/opkg/tropical-jungle-team.conf
      else
        echo src/gz tropical-jungle-team $ENLACE_URL/$IMAGE/mipsel > /etc/opkg/tropical-jungle-team.conf
      fi

}

function listaypicon() {

	wget $SCRIPT -P /usr/bin/

}

function update() {
	
    opkg update
       
      
}


function diascrossepg() {

    echo -e $DIAS3 > /usr/crossepg/providers/Koala-epg-3.conf
    echo -e $DIAS7 > /usr/crossepg/providers/Koala-epg-7.conf
    echo -e $DIAS15 > /usr/crossepg/providers/Koala-epg-15.conf
    echo -e $DIAS30 > /usr/crossepg/providers/Koala-epg-30.conf
}

function crossepg() {
	
    opkg install $INSCROSSEPG
    sleep 3
    diascrossepg       
      
}

function epgimport() {
	
    opkg install $INSEPGIMPORT
    sleep 3
    rm -r /etc/epgimport/rytec.sources.xml
    wget $SOURCES -P /etc/epgimport/ 
      
}

function estrellas() {
	
    wget $FONT -P /usr/share/fonts/
    sed -i 's/tiny.ttf/DejaVuSansCondensed.ttf/g' "/usr/share/enigma2/skin.xml"
          
}

function permisos() {

	chmod 777 /usr/bin/enigma2_pre_start.sh

}


function logo(){
	clear
	echo -e "\e[32m${VERDE} ******************************************************************************\e[0m"
	echo -e "\e[32m${VERDE} *      _ _    _ _   _  _____ _      ______   _______ ______          __  __  *\e[0m"
    echo -e "\e[32m${VERDE} *     | | |  | | \ | |/ ____| |    |  ____| |__   __|  ____|   /\   |  \/  | *\e[0m"
    echo -e "\e[32m${VERDE} *     | | |  | |  \| | |  __| |    | |__ ______| |  | |__     /  \  | \  / | *\e[0m"
    echo -e "\e[32m${VERDE} *  _  | | |  | |     | | |_ | |    |  __|______| |  |  __|   / /\ \ | |\/| | *\e[0m"
    echo -e "\e[32m${VERDE} * | |_| | |__| | |\  | |__| | |____| |____     | |  | |____ / ____ \| |  | | *\e[0m"
    echo -e "\e[32m${VERDE} * \____/ \____/|_| \_|\_____|______|______|    |_|  |______/_/    \_\_|  |_| *\e[0m"        
	echo -e "\e[32m${VERDE} *        																	 *\e[0m"
	echo -e "\e[32m${VERDE} *                          Instalador Blackhole utilidades					 *\e[0m"
	echo -e "\e[32m${VERDE} *      grupo telegram: https://t.me/joinchat/Bv0_2hZ8jH6dsUJFoYG-Rg          *\e[0m"
	echo -e "\e[32m${VERDE} *                                                                            *\e[0m"
	echo -e "\e[32m${VERDE} *                           jungle-team.com                                  *\e[0m"
	echo -e "\e[32m${VERDE} ******************************************************************************\e[0m"
}

logo

CompruebaInternet

Instalacionfeed

listaypicon

update

crossepg

epgimport

estrellas

permisos

Mensaje "La instalacion jungle utilidades se ha instalado con exito ahora se activa nuevamente enigma2" $VERDE

init 3

Mensaje "Gracias por haber usado el instalador Jungle-Team visite https://t.me/joinchat/Bv0_2hZ8jH6dsUJFoYG-Rg para soporte" $ROJO
