#!/bin/bash

echo "Welcome to the Discord-Linux HasteBin Automated installer"
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 "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 HasteBin Automated installer for Discord-Linux, We are preparing your installation..."

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

cd /home

notif "Cloning into /home/haste-server"
git clone https://github.com/seejohnrun/haste-server.git

cd haste-server

npm install

npm update

sed -i "s/7777/10002/g" config.js


notif "Configuring HasteBin and starting it's server"
wget -O hasteBinStart.json https://ssh.surf/install/hastebin

cd /home/haste-server && pm2 start hasteBinStart.json

sed -i "s/#hastebin/cd \/home\/haste-server \&\& pm2 start hasteBinStart.json \&\& relayPort 10002/g" /start.sh

relayPort 10002
sleep 2

url=$(grep -hPo "(?<=listening ).*" /root/.pm2/logs/Relay-10002-out.log  | head -n 1 | sed 's/$/.virt.fun/')

notif "Your HasteBin is now running at https://$url"
