#!/bin/bash
#Script-By : SATLINK ! 
txtred=$(tput bold ; tput setaf 1) # Vija-Kuqe
txtgreen=$(tput bold ; tput setaf 2) # Vija-Jeshile
txtyellow=$(tput bold ; tput setaf 3) # Vija-Verdhe
clear
echo ""
echo "${txtyellow} ┌──SATLINK MENU INSTALL - https://t.me/Satlink502───┐ "
echo "${txtyellow} │      Comprobando si XUI existe en el sistema      │ "
echo "${txtyellow} └───────────────────────────────────────────────────┘ "
[ ! -f "/etc/systemd/system/xuione.service" ] && echo "${txtred} ¡Advertencia! ¡Xui.One no está instalado en tu sistema!"
[ ! -d "/home/xui/config" ] && echo "${txtred} ¡Advertencia! ¡Xui.One no está instalado en tu sistema!"
sleep 3s
cd
echo "${txtred} ┌───────────SATLINK MENU INSTALL - https://t.me/Satlink502─────────┐ "
echo "${txtred} │ ¡Advertencia! Este script desinstalará los servicios Xui y MySQL.│ "
echo "${txtred} └──────────────────────────────────────────────────────────────────┘ "
echo "${txtred} ┌──SATLINK MENU INSTALL - https://t.me/Satlink502───┐ "
echo "${txtred} │                  ¿Quieres continuar?              │ "
echo "${txtred} └───────────────────────────────────────────────────┘ "
select yn in "Yes" "No"; do
    case $yn in
        Yes ) echo "${txtyellow} Seleccionaste Sí... ¡Desinstalando XUI.One y Mysql!"; break;;
        No ) exit;;
    esac
done
sleep 4s

sudo pkill -u xui 2>/dev/null
sudo kill $(ps aux | grep '[p]hp' | awk '{print $2}') 2>/dev/null
sudo kill $(ps aux | grep '[n]ginx' | awk '{print $2}') 2>/dev/null
sudo apt-get remove libcurl3 libcurl4 -y 2>/dev/null
sudo umount -f /home/xui/content/streams/
sudo umount -f /home/xui/tmp/
sudo sed -i '/xui/d' /etc/crontab
sudo sed -i '/xui/d' /etc/fstab
sudo sed -i '/xui/d' /etc/sudoers
sudo deluser xui 2>/dev/null
sudo groupdel xui 2>/dev/null
rm /var/spool/cron/crontabs/xui
rm /home/xui/ -rf
sudo systemctl stop mysql.service  
sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* default-mysql-client -y
sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql 2>/dev/null
sudo apt autoremove -y
sudo apt autoclean -y
echo "${txtgreen} ┌──SATLINK MENU INSTALL - https://t.me/Satlink502───┐ "
echo "${txtgreen} │                 Proceso finalizado.               │ "
echo "${txtgreen} └───────────────────────────────────────────────────┘ "