#!/bin/bash
[[ ! -e /usr/local/lib/drowkid/msg ]] && {
	[[ -d /usr/local/lib/drowkid ]] || mkdir -p /usr/local/lib/drowkid
	wget -O /usr/local/lib/drowkid/msg https://darix.ooguy.com/drowkid01/dpbt/raw/branch/main/otros/msg >/dev/null 2>&1
	chmod +rwx /usr/local/lib/drowkid/msg
	wget -qO- ipv4.icanhazip.com > /usr/local/lib/drowkid/ipdk
}

echo '0' >/etc/http-instas
cor=("\033[1;36m" "\033[1;32m" "\033[1;31m" "\033[1;33m" "\033[1;37m" )

source /usr/local/lib/drowkid/msg
[[ $(dpkg --get-selections|grep -w 'figlet') ]] && apt-get install figlet -y >/dev/null 2>&1
[[ $(dpkg --get-selections|grep -w 'lolcat') ]] && apt-get install lolcat -y >/dev/null 2>&1
[[ -d /etc/scripts ]] && rm -rf /etc/scripts 
[[ -d $SCPT_DIR ]] && rm -rf $SCPT_DIR

install_ini() {
    clear
    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 "apache2" | head -1) ]] || ESTATUS=$(echo -e "\033[91mFALLO DE INSTALACION") &>/dev/null
    #[[ $(dpkg --get-selections | grep -w "apache2" | head -1) ]] && ESTATUS=$(echo -e "\033[92mINSTALADO") &>/dev/null
    #echo -e "\033[97m  # apt-get install apache2.............. $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 install 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 "
    #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     Reintentar Install Paquetes [ 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- ipv4.icanhazip.com)
    [[ "$MIP" != "$MIP2" ]] && IP="$MIP2" || IP="$MIP"
    echo "$IP" >/usr/bin/vendor_code
}

function downbt(){
local varl='https://darix.ooguy.com/drowkid01/dpbt/raw/branch/main'
[[ ! -e /bin/ShellBot.sh ]] && wget -O /bin/ShellBot.sh https://darix.ooguy.com/drowkid01/dpbt/raw/branch/main/otros/ShellBot.sh >/dev/null 2>&1
[[ ! -e /bin/http-server.sh ]] && wget -O /bin/http-server.sh https://darix.ooguy.com/drowkid01/dpbt/raw/branch/main/exec/http-dk.sh  && chmod +x /bin/http-server.sh
[[ ! -d /etc/CAT-BOT ]] && mkdir -p /etc/CAT-BOT || rm -rf /etc/CAT-BOT/*
wget -O /etc/CAT-BOT/BotGen.sh "${varl}/exec/BotGen.sh" >/dev/null 2>&1
chmod +rwx /bin/ShellBot.sh /bin/http-server.sh /etc/CAT-BOT/BotGen.sh
unset admin
while read admin; do
	read -p $'\e[1;30m[•] \e[1;34mIngresa tu ID: \e[1;36m' id
	[[ -z $id ]] && id='7570680285'
	tput cuu1&&tput dl1
	read -p $'\e[1;30m[•] \e[1;34mIngresa el token: \e[1;36m' token
	[[ -z $token ]] && token='7980942317:AAHVTvcJDHuvYzEkauzQYB1ARf_9OEYQKlU'
	data="$id|$token"
	data+="${#admin}"
done <<< "$data"
[[ -z $admin ]] && admin="$id|$token"
clear&&clear
wget -O /bin/gerar $varl/exec/menu.sh >/dev/null 2>&1
echo $data > /etc/CAT-BOT/data
echo '999' > /etc/CAT-BOT/limit
echo '@drowkid01' > /etc/CAT-BOT/resell
echo $id > /etc/CAT-BOT/num-key.cont
clear
figlet 'BOTGEN'|lolcat
msg -b&&print_center -ama "\e[1;32m[+] INSTALADO CORRECTAMENTE [+]"
msg -b
}

#==>> instalación de scripts.
function downfilez(){
mkdir -p /etc/scripts
link='https://darix.ooguy.com/drowkid01/dpbt/raw/branch/main/scripts'
scpconf='/etc/scripts/scripts.json'
wget -O $scpconf $link/scripts.json >/dev/null 2>&1
for i in `seq 0 3`; do
	name[$i]=$(cat "$scpconf"|jq ".scripts[$i].data.nombre"|tr -d '"')
	ruta[$i]=$(cat "$scpconf"|jq ".scripts[$i].data.ruta"|tr -d '"')
	inst[$i]=$(cat "$scpconf"|jq ".scripts[$i].data.instal"|tr -d '"')
	arqs[$i]=$(cat "$scpconf"|jq ".scripts[$i].data.files"|tr -d '"')
	linK[$i]="$link/${name[$i]}.tar"
	scp="${name[$i]}|"
	echo "${name[$i]}|${ruta[$i]}|${inst[$i]}|${arqs[$i]}" >> /usr/local/lib/drowkid/scripts.conf
done
mkdir -p /etc/scripts
[[ ! -e /etc/scripts/scripts.conf ]] && ln -s /usr/local/lib/drowkid/scripts.conf /etc/scripts/scripts.conf
cd /etc/scripts
clear&&clear
print_center -m 'INSTALANDO SCRIPTS'
for i in `seq 0 3`; do
	mkdir -p "/etc/scripts/${name[$i]}"
	msg -b&&unset z
	wget -O "/etc/scripts/${name[$i]}/${name[$i]}.tar" "${linK[$i]}" >/dev/null 2>&1
	cd "${ruta[$i]}"&&tar xpf "${name[$i]}.tar" >/dev/null 2>&1
	rm -rf "${ruta[$i]}/${name[$i]}.tar" userDIR 0 *.txt
	echo -e "		\e[1;30m[#\e[1;34mSCRIPT: \e[1;36m${name[$i]}\e[1;30m]\n"&&msg -b
	#[[ $(ls "${ruta[$i]}") == $(echo "${arqs[$i]}") ]] && continue || echo -e "\e[1;31m[x] error al descargar el script ${name[$i]} [x]"&&return $?
	for x in `ls "/etc/scripts/${name[$i]}"`;do
		echo -e "		\e[1;30m[#\e[1;34mfile: ${z:=1} \e[1;36m${x}\e[1;30m]"
		sleep 0.4&&z=$((${z:=1} + 1 ))
		[[ $z == "${#arqs[$i]}" ]] && break
	done
done
}

unset Key
case $1 in
 '-i'|'--install')
	add-apt-repository universe
	apt update -y
	apt upgrade -y
	install_ini
	clear
	downfilez
 ;;
 '-s'|'--script')
	downfilez
 ;;
 '-b'|'--botgen')
	downbt
 ;;
esac
