#!/bin/bash

echo "Welcome to the Discord-Linux Whoogle Automated installer"
echo "This installer will automatically select a port on your container."
echo "I will let you know how to access your installation when this process is complete."
echo ""
echo ""
echo ""
echo "Sleeping for 5 seconds, please close this process if you do not wish to continue"

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

notif "Welcome to the Whoogle Automated installer for Discord-Linux, we will begin by updating your system. Please wait..."

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

DEBIAN_FRONTEND=noninteractive apt-get -y install python3.9-venv

#https://askubuntu.com/questions/916199/install-apt-show-versions-inside-an-ubuntu-docker-container

sh /var/tools/getsystemctl.sh

cd /home
git clone https://github.com/benbusby/whoogle-search.git
cd whoogle-search
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

wget -q -O whoogle.env https://ssh.surf/install/whoogle/config 

wget -q -O whoogleStart.json https://ssh.surf/install/whoogle/whoogleStart.json



hostname=$(hostname)

echo "Grabbing a port from your container from our API"
port=$(curl -s  https://findport.ssh.surf/?id=$hostname)

echo "Setting port in our config"
sed -i "s/5000/${port}/g" run

pm2 start whoogleStart.json

echo "Your whoogle installation has completed, you may access your installation at: http://ssh.surf:$port"

notif "Your whoogle installation has completed, you may access your installation at: http://ssh.surf:$port"


