#!/bin/bash
txtred=$(tput bold ; tput setaf 1) 
txtgreen=$(tput bold ; tput setaf 2) 
txtyellow=$(tput bold ; tput setaf 3) 
clear

# Definición de colores (opcional, para resaltar)
GREEN='\033[0;32m'
NC='\033[0m' # No Color

satlink_info() {
  clear
  cat <<"EOF"
              https://t.me/Satlink502
              
███████╗ █████╗ ████████╗██╗     ██╗███╗   ██╗██╗  ██╗
██╔════╝██╔══██╗╚══██╔══╝██║     ██║████╗  ██║██║ ██╔╝
███████╗███████║   ██║   ██║     ██║██╔██╗ ██║█████╔╝
╚════██║██╔══██║   ██║   ██║     ██║██║╚██╗██║██╔═██╗
███████║██║  ██║   ██║   ███████╗██║██║ ╚████║██║  ██╗
╚══════╝╚═╝  ╚═╝   ╚═╝   ╚══════╝╚═╝╚═╝  ╚═══╝╚═╝  ╚═╝
IPTV-CATV-RESTREAM                  info@satlink.com.gt
EOF
}

items=(1 "INSTALAR DRIVERS TBS"
       2 "INSTALAR ASTRA-LATEST"
       3 "ACTUALIZAR A ASTRA-SATLINK"
       4 "BACKUP ASTRA-SATLINK"
       5 "LICENCIA ASTRA-SATLINK"
       6 "ACTIVAR UDP"
       7 "DESINSTALAR ASTRA")

while choice=$(dialog --title "SATLINK" \
                      --backtitle "https://t.me/Satlink502" \
                      --menu "MENU DE INSTALACION V.2" 18 35 7 "${items[@]}" \
                 2>&1 >/dev/tty)
    do
    case $choice in
        1)
echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "             ${GREEN}Iniciando la instalación...${NC}         "
echo -e "└───────────────────────────────────────────────────────────┘ "

cd / ; curl -sSf https://cdn.cesbo.com/astra/scripts/drv-tbs.sh | sh && echo "" > ~/.bash_history && history -c ; clear

echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "               ${GREEN}Instalación completada.${NC}           "
echo -e "└───────────────────────────────────────────────────────────┘ "

satlink_info

sleep 3s

        ;;

        2)
echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "             ${GREEN}Iniciando la instalación...${NC}         "
echo -e "└───────────────────────────────────────────────────────────┘ "

cd / ; curl -Lo /usr/bin/astra https://cesbo.com/and/astra-250612 ; chmod +x /usr/bin/astra && cd / ; mkdir -p /etc/astra && cd /etc/astra/ ; echo "Introduzca su licencia de ASTRA" ; read keyastra && curl -o /etc/astra/license.txt https://cesbo.com/astra-license/$keyastra && astra init ; systemctl start astra ; systemctl enable astra ; echo "" > ~/.bash_history && history -c ; clear

echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "               ${GREEN}Instalación completada.${NC}           "
echo -e "└───────────────────────────────────────────────────────────┘ "
sleep 3s 

echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "             ${GREEN}Instalando Logotipos...${NC}         "
echo -e "└───────────────────────────────────────────────────────────┘ "

mkdir -m 777 /var/lib/astra/tvg-logo/ ; cd /var/lib/astra/tvg-logo/ ; wget https://github.com/SatlinkGT/LOGOS/raw/main/logos70w.zip ; unzip logos70w.zip ; echo "" > ~/.bash_history && history -c ; clear

echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "               ${GREEN}Instalación completada.${NC}           "
echo -e "└───────────────────────────────────────────────────────────┘ "
sleep 3s 

        ;;

        3)

echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "             ${GREEN}Iniciando la instalación...${NC}         "
echo -e "└───────────────────────────────────────────────────────────┘ "

bash <(curl -s https://menu.satlink.com.gt/astra/astra-satlink.sh)

echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "               ${GREEN}Instalación completada.${NC}           "
echo -e "└───────────────────────────────────────────────────────────┘ "

satlink_info

sleep 3s
        ;;

        4)

echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "             ${GREEN}Iniciando la descarga...${NC}         "
echo -e "└───────────────────────────────────────────────────────────┘ "

curl -o /etc/astra/astra.conf https://menu.satlink.com.gt/astra/astra.conf ; systemctl restart astra ; echo "" > ~/.bash_history && history -c ; clear

echo -e "┌────── SATLINK MENU INSTALL - https://t.me/Satlink502 ─────┐ "
echo -e "               ${GREEN}Descarga completada.${NC}           "
echo -e "└───────────────────────────────────────────────────────────┘ "

satlink_info

sleep 3s

        ;;

        5)

bash <(curl -s https://menu.satlink.com.gt/astra/astra-key.sh)

        ;;

        6)

echo ""
echo "${txtyellow} ┌──────────────────────────────────────┐ "
echo "${txtyellow} │              ACTIVANDO UDP           │ "
echo "${txtyellow} └──────────────────────────────────────┘ "
sed '2s/"_output":/"output":/' /etc/astra/astra.conf ; systemctl restart astra ; echo "" > ~/.bash_history && history -c ; clear


        ;;

        7)

echo ""
echo "${txtyellow} ┌──────────────────────────────────────┐ "
echo "${txtyellow} │          DESINSTALANDO ASTRA         │ "
echo "${txtyellow} └──────────────────────────────────────┘ "

systemctl stop astra ; systemctl disable astra | astra remove ; rm -rf /usr/bin/astra /etc/astra ; rm -rf /lib/systemd/system/astra.service ; cd / ; echo "" > ~/.bash_history && history -c ; clear

        ;;     

        *) ;; # some action on other
    esac
done
clear # clear after user pressed Cancel
