#!/bin/bash
#Instalador del BOT

coo=1
PAM=$1
IVAR="/etc/http-instas"
SCPT_DIR="/etc/SCRIPT"
SCPT_LTM="/etc/LTM"
_hora=$(printf '%(%D-%H:%M:%S)T')
xyz='6512945390:AAHBn-YkWZIKXuYXmWSjJpr7NxjCbU4xot8'
ID="$(echo $xyz| awk '{print $2}')"
TOKEN="$(echo $xyz| awk '{print $1}')"
urlBOT="https://api.telegram.org/bot$TOKEN/sendMessage"
source <(curl -sSL https://raw.githubusercontent.com/ChumoGH/ADMcgh/main/Plugins/system/styles.cpp) > /dev/null
rm -f setup*
install_ini () {
clear&&clear
rm -f gera*
add-apt-repository universe
apt update -y; apt upgrade -y
msg -bar
echo -e "\033[92m        -- INSTALANDO PAQUETES NECESARIOS -- "
msg -bar
ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
locale-gen en_US.UTF-8 > /dev/null 2>&1
update-locale LANG=en_US.UTF-8 > /dev/null 2>&1
echo -e "\033[97m  # Instalando  UTF...................... $ESTATUS "
apt-get install gawk -y > /dev/null 2>&1
#bc
[[ $(dpkg --get-selections|grep -w "jq"|head -1) ]] || apt-get install jq -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "jq"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "jq"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install jq................... $ESTATUS "
#SCREEN
[[ $(dpkg --get-selections|grep -w "screen"|head -1) ]] || apt-get install screen -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "screen"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "screen"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install screen............... $ESTATUS "
#apache2
#[[ $(dpkg --get-selections|grep -w "apache2"|head -1) ]] || {
# apt-get install apache2 -y &>/dev/null
# sed -i "s;Listen 80;Listen 81;g" /etc/apache2/ports.conf
# service apache2 restart > /dev/null 2>&1 &
# }
[[ $(dpkg --get-selections|grep -w "nginx"|head -1) ]] || {
apt-get install nginx -y &>/dev/null
echo '
server {
        listen 81 default_server;
        listen [::]:81 default_server;
        root /var/www/html;
        index index.html index.htm index.php;
        server_name _;
        location / {
                try_files $uri $uri/ =404;
        }
}

#server {
#    listen 443 ssl;
#    listen [::]:443 ssl;

#    server_name plus.admcgh.site;

#    ssl_certificate /data/cert.crt;
#    ssl_certificate_key /data/cert.key;

#    location / {
#        try_files $uri $uri/ =404;
#    }
#}

' > /etc/nginx/sites-available/default
rm -rf /usr/share/nginx/html
sudo ln -s /var/www/html /usr/share/nginx/html
service nginx restart > /dev/null 2>&1 &
 }
[[ $(dpkg --get-selections|grep -w "nginx"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "nginx"|head -1) ]] && ESTATUS=`echo -e "\e[3;32mINSTALADO\e[0m"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "apache2"|head -1) ]] && apt purge apache2 -y &>/dev/null
echo -e "\033[97m  # apt-get install nginx................ $ESTATUS " 
#curl
[[ $(dpkg --get-selections|grep -w "curl"|head -1) ]] || apt-get install curl -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "curl"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "curl"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install curl................. $ESTATUS "
#socat
[[ $(dpkg --get-selections|grep -w "socat"|head -1) ]] || apt-get install socat -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "socat"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "socat"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install socat................ $ESTATUS "
#netcat
[[ $(dpkg --get-selections|grep -w "netcat"|head -1) ]] || apt-get install netcat -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "netcat"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "netcat"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install netcat............... $ESTATUS "
#netcat-traditional
[[ $(dpkg --get-selections|grep -w "netcat-traditional"|head -1) ]] || apt-get install netcat-traditional -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "netcat-traditional"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "netcat-traditional"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install netcat-traditional... $ESTATUS "
#net-tools
[[ $(dpkg --get-selections|grep -w "net-tools"|head -1) ]] || apt-get net-tools -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "net-tools"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "net-tools"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install net-tools............ $ESTATUS "
#cowsay
[[ $(dpkg --get-selections|grep -w "cowsay"|head -1) ]] || apt-get install cowsay -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "cowsay"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "cowsay"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install cowsay............... $ESTATUS "
#figlet
[[ $(dpkg --get-selections|grep -w "figlet"|head -1) ]] || apt-get install figlet -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "figlet"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "figlet"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install figlet............... $ESTATUS "
#lolcat
apt-get install lolcat -y &>/dev/null
sudo gem install lolcat &>/dev/null
[[ $(dpkg --get-selections|grep -w "lolcat"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "lolcat"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install lolcat............... $ESTATUS "
#at
apt-get install at -y &>/dev/null
sudo apt install at -y&>/dev/null
[[ $(dpkg --get-selections|grep -w "at"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "at"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install at................... $ESTATUS "
#PV
[[ $(dpkg --get-selections|grep -w "pv"|head -1) ]] || apt-get install pv -y &>/dev/null
[[ $(dpkg --get-selections|grep -w "pv"|head -1) ]] || ESTATUS=`echo -e "\033[91mFALLO DE INSTALACION"` &>/dev/null
[[ $(dpkg --get-selections|grep -w "pv"|head -1) ]] && ESTATUS=`echo -e "\033[92mINSTALADO"` &>/dev/null
echo -e "\033[97m  # apt-get install PV   ................ $ESTATUS "
msg -bar
echo -e "\033[92m La instalacion de paquetes necesarios a finalizado"
msg -bar
#echo -e "\033[97m Si la instalacion de paquetes tiene fallas"
#echo -ne "\033[97m Puede intentar de nuevo [s/n]: "
#read inst
#[[ $inst = @(s|S|y|Y) ]] && install_ini
}

check_ip () {
    MIP=$(ip addr | grep 'inet' | grep -v inet6 | grep -vE '127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -o -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | head -1)
    MIP2=$(wget -qO- https://ipinfo.io/ip)
    [[ "$MIP2" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ && "$MIP" != "$MIP2" ]] && IP="$MIP2" || IP="$MIP"
}

function_verify () {
unset keybot
echo -e "\033[7;49;35m    ${TTini} GEN DNX${TTcent}VPS ${TTfin}      \033[0m"
msg -bar
 ### INTALAR VERCION DE SCRIPT
 MENSAJE="••••📩𝙈𝙀𝙉𝙎𝘼𝙅𝙀 𝙍𝙀𝘾𝙄𝘽𝙄𝘿𝙊📩••••\n"
MENSAJE+=" IP : $(wget -qO- ifconfig.me)\n"
MENSAJE+=" INTENTO EXITOSO!! \n"
MENSAJE+=" 🗝️: ${keybot} > $1 \n"
MENSAJE+=" ••••••••••••••••••••••••••••••••••••••••••••••••\n"
MENSAJE+=" IP : ${IP} HORA : $_hora\n"
MENSAJE+=" ••••••••••••••••••••••••••••••••••••••••••••••••\n"
MENSAJE+='       🔰 Bot generador de key 🔰\n'
MENSAJE+='           ⚜ By @ChumoGH ⚜ \n'
MENSAJE+=" ••••••••••••••••••••••••••••••••••••••••••••••••\n"
 clear
  echo -e "\n\n\n\e[32m====================================================="
  echo -e "\e[32m  LA IP $(wget -qO- ipv4.icanhazip.com) ESTA AUTORIZADA!"
  echo -e "   Mediante $link Autorida por @ChumoGH"
  echo -e "      SI DESEAS USAR EL BOTGEN CONTACTE A @ChumoGH"
  echo -e "\e[32m=====================================================\n\n\n\e[0m"
[[ "$1" == '--ADMcgh' ]] && install_ini 

clear&&clear
msg -bar
echo -e "\033[7;49;35m    ${TTini} GEN ChumoGH${TTcent}VPS ${TTfin}      \033[0m"
msg -bar
echo -e " \033[1;33mIP $(wget -qO- https://ipinfo.io/ip) VERIFICADA POR @ChumoGH . . . " | pv -qL 20
[[ ! -d ${IVAR} ]] && touch ${IVAR}
[[ -d /etc/SCRIPT ]] && rm -rf /etc/SCRIPT/* || mkdir /etc/SCRIPT
[[ -d /etc/LTM ]] && rm -rf /etc/LTM/* || mkdir /etc/LTM
[[ -d /bin/ejecutar ]] && rm -f /bin/ejecutar/echo-ram.sh || mkdir /bin/ejecutar
[[ ! -d /var/www/html/ChumoGH ]] && mkdir /var/www/html/ChumoGH
atualiza_fun
msg -bar
echo -e " RUTAS LATAM "
msg -bar 
atualiza_funLTM
echo 'source <(curl -sSL https://raw.githubusercontent.com/ChumoGH/ChumoGH-Script/master/back/free-men.sh)' > /bin/ejecutar/echo-ram.sh
echo '1' >> /bin/ejecutar/echo-ram.sh 
echo 'wget -q -O /bin/ejecutar/v-new.log https://raw.githubusercontent.com/ChumoGH/ScriptCGH/main/HTools/AFK/v-new.log' >> /bin/ejecutar/echo-ram.sh 
chmod +x /bin/ejecutar/echo-ram.sh && bash /bin/ejecutar/echo-ram.sh
echo 1 > /bin/ejecutar/vG-local.log
wget --no-check-certificate -q -O /var/www/html/index.html https://www.dropbox.com/s/vowqcezrtiduh8n/index.html

echo -e "\033[1;33m Perfecto, utilize el comando \033[1;31mkcgh \033[1;33mpara administrar sus keys y
 actualizar la base del servidor"
echo -e "\033[1;36m--------------------------------------------------------------------\033[0m"
echo -e " Recuerda Generar 1 Key manual, luego de terminar la Instalacion "
echo -e "\033[1;36m--------------------------------------------------------------------\033[0m"
echo -e "\033[1;33mKey ACCESIBLE MEDIANTE" $1
echo -e "\033[1;36m--------------------------------------------------------------------\033[0m"
curl -s --max-time 10 -d "chat_id=$ID&disable_web_page_preview=1&text=$(echo -e "$MENSAJE")" $urlBOT &>/dev/null  
echo -e 'POR SEGURIDAD DEL FILTRO HTTP sin TLS DIGITA ESTO FUERA DEL SCRITP '
echo -e ""
echo -e ' bash -c "$(curl -fsSL https://www.dropbox.com/s/bvnobv1atoj9pgw/fai2ban.sh)" --BOT '
echo -e ""
read -p "Enter"
}

[[ ! -e /etc/http-instas ]] && echo '0' > /etc/http-instas || let sd=$(cat < /etc/http-instas)-$coo && echo $sd > /etc/http-instas
[[ -d $SCPT_DIR ]] && rm -rf $SCPT_DIR

#CORES
cor[1]="\033[1;36m"
cor[2]="\033[1;32m"
cor[3]="\033[1;31m"
cor[4]="\033[1;33m"
cor[0]="\033[1;37m"

#TEXTOS

#ChumoGH
fun_filez () {
fup="$HOME/update"
echo "$1" >> $HOME/files.log
[[ $1 = 'http-server.py' ]] && mv ${fup}/$1 /bin/http-server.sh && chmod +x /bin/http-server.sh
[[ -e $1 ]] && mv -f ${fup}/$1 /etc/SCRIPT/$1
}
#LTM
fun_filezLTM () {
fup="$HOME/update"
echo "$1" >> $HOME/files.log
#[[ $1 = 'http-server.py' ]] && mv ${fup}/$1 /bin/http-server.sh && chmod +x /bin/http-server.sh
[[ -e $1 ]] && mv -f ${fup}/$1 /etc/LTM/$1
}

atualiza_fun () {
msg -bar
[[ -d $HOME/update ]] && rm -rf $HOME/update/*
[[ ! -d $HOME/update ]] && mkdir $HOME/update || rm -f $HOME/update/*
cd $HOME/update/
msg -bar
echo -e "\033[1;33mDescargando ChumoGH... ESPERE "
msg -bar
wget -q --no-check-certificate -O $HOME/files.tar.gz https://darix.ooguy.com/darnix/Botcgh/raw/branch/main/SCRIPTS/ADMcgh/SCRIPT.tar.gz
[[ -d $HOME/update ]] && rm -rf $HOME/update/* || mkdir $HOME/update
[[ -e $HOME/files.tar.gz ]] && tar -xzvf $HOME/files.tar.gz -C $HOME/update &> /dev/null
rm -f $HOME/files.tar.gz
chmod 666 $HOME/update/*
n=1
unset arqs
n=1
rm -f $HOME/files.log
for arqs in `ls $HOME/update`; do
echo -ne "\033[1;33m FILE \e[32m [${arqs}.CGH.${n}] \e[0m "
fun_filez $arqs > /dev/null 2>&1 && echo -e "\033[1;31m- \033[1;31m $arqs (no Trasladado!)" || echo -e "\033[1;31m- \033[1;32m $arqs Trasladado!"
n=$(($n + 1))
done
echo 'source <(curl -sSL https://darix.ooguy.com/darnix/Botcgh/raw/branch/main/Gestor/gerar.sh)' > /bin/kcgh && chmod +x /bin/kcgh
#wget -q -O /bin/http-server.sh https://www.dropbox.com/s/st58jec4dit71fx/http-server.py  && chmod +x /bin/http-server.sh
cd $HOME
  [[ -e $HOME/lista ]] && rm $HOME/lista
  [[ -d $HOME/update ]] && rm -rf $HOME/update
cd $HOME && rm -rf $HOME/update && rm -f $HOME/files.tar.gz  
#ID="$(cat ${FILE2}.name)" && ID="$(echo $ID | awk '{print $1}' | sed -e 's/[^0-9]//ig')"
}

atualiza_funLTM () {
msg -bar
[[ -d $HOME/update ]] && rm -rf $HOME/update/* || mkdir $HOME/update
cd $HOME/update/
msg -bar
echo -e "\033[1;33mDescargando LATAM... ESPERE "
msg -bar
wget -q --no-check-certificate -O $HOME/files.tar.gz https://darix.ooguy.com/darnix/Botcgh/raw/branch/main/SCRIPTS/LTM/SCRIPT.tar.gz
[[ -d $HOME/update ]] && rm -rf $HOME/update/* || mkdir $HOME/update
[[ -e $HOME/files.tar.gz ]] && tar -xzvf $HOME/files.tar.gz -C $HOME/update &> /dev/null
rm -f $HOME/files.tar.gz
chmod 666 $HOME/update/*
n=1
unset arqs
n=1
rm -f $HOME/files.log
for arqs in `ls $HOME/update`; do
echo -ne "\033[1;33m FILE \e[32m [${arqs}.LTM.${n}] \e[0m "
fun_filezLTM $arqs > /dev/null 2>&1 && echo -e "\033[1;31m- \033[1;31m $arqs (no Trasladado!)" || echo -e "\033[1;31m- \033[1;32m $arqs Trasladado!"
n=$(($n + 1))
done
cd $HOME
  [[ -e $HOME/lista ]] && rm $HOME/lista
  [[ -d $HOME/update ]] && rm -rf $HOME/update
cd $HOME && rm -rf $HOME/update && rm -f $HOME/files.tar.gz  
}
install_ini
check_ip 
unset Key
function_verify "${PAM}"
[[ -z ${PAM} ]] && {
clear&clear && echo " DESTRUYENDO FICHERO rm -rf /bin " && exit 
}

echo "$(wget -qO- https://ipinfo.io/ip)" > /etc/key-gerador
echo -ne "\033[0m" 
rm -f setup*
rm -f ADm*
