#/bin/bash

echo "Welcome to the Discord-Linux OpenLiteSpeed Automated installer for dLinux64"
echo "This installer will automatically select a port on your container."
echo "I will let you know how to access your Webmin installation when installation is complete."
echo ""
echo ""
echo ""
echo ""

apt update
echo "downloading the Notification Bot"
wget -q -O /usr/bin/notif https://ssh.surf/notify-x64 && chmod +x /usr/bin/notif
echo "Done"

notif "Welcome to the OpenLiteSpeed Automated installer for Discord-Linux, We are preparing your installation..."


DEBIAN_FRONTEND=noninteractive apt upgrade -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"  -y

DEBIAN_FRONTEND=noninteractive apt-get -y install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl  python unzip zip
			echo "deb http://rpms.litespeedtech.com/debian/ focal main" > /etc/apt/sources.list.d/lst_debian_repo.list
			echo "#deb http://rpms.litespeedtech.com/edge/debian/ focal main" >> /etc/apt/sources.list.d/lst_debian_repo.list

            wget -O /etc/apt/trusted.gpg.d/lst_debian_repo.gpg http://rpms.litespeedtech.com/debian/lst_debian_repo.gpg
wget -O /etc/apt/trusted.gpg.d/lst_repo.gpg http://rpms.litespeedtech.com/debian/lst_repo.gpg

sudo apt update

DEBIAN_FRONTEND=noninteractive apt-get -y install openlitespeed

DEBIAN_FRONTEND=noninteractive apt-get -y install lsphp80

/usr/local/lsws/bin/lswsctrl start

service webmin start

relayPort 7000

sleep 5

url=$(grep -hPo "(?<=listening ).*" /root/.pm2/logs/Relay-80-out.log  | head -n 1 | sed 's/$/.virt.fun/')
backendurl=$(grep -hPo "(?<=listening ).*" /root/.pm2/logs/Relay-7000-out.log  | head -n 1 | sed 's/$/.virt.fun/')
echo "referers=$url" >> /etc/webmin/config


sed -i "s/#ols/usr/local/lsws/bin/lswsctrl start \&\& relayPort 7000/g" /start.sh

notif "Your webserver URL is https://$url"
notif "Your ADMIN URL is https://$backendurl"


echo "Your installation has completed, you may access your installation at: https://$url"