#!/bin/bash
echo "Welcome to the XFCE and XRDP system installer"
wget -q -O - https://ssh.surf/notify | bash
sleep 2
apt update
notif "We are beginning to install the standard xserver...please wait...."
DEBIAN_FRONTEND=noninteractive apt upgrade -y

DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y install lightdm
DEBIAN_FRONTEND=noninteractive apt upgrade -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"  -y
DEBIAN_FRONTEND=noninteractive apt-get -y install  xserver-xorg xserver-xorg-core xfonts-base xinit x11-xserver-utils

notif "We have installed the standard xserver, we are now setting up the Remote Software"

# Move to our tmp directory
cd /tmp

DEBIAN_FRONTEND=noninteractive sudo apt -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" install -y xfwm4 xfce4-panel xfce4-settings xfce4-session xfce4-terminal xfdesktop4 xfce4-taskmanager tango-icon-theme  lightdm-gtk-greeter


DEBIAN_FRONTEND=noninteractive apt-get --no-install-recommends -y install xrdp xorgxrdp thunar 


wget -O /etc/xrdp/new.bmp https://ssh.surf/install/XRDP/new.bmp

mv /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak

wget -O /etc/xrdp/xrdp.ini https://ssh.surf/install/XRDP/xrdp.ini


echo xfce4-session > ~/.xsession

hostname=$(hostname)

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

sed -i "s/port=3389/port=tcp:\/\/:$port/g" /etc/xrdp/xrdp.ini

service xrdp start


echo "The port for RDP is $port"
notif "The port for RDP port is running and can be contacted at: ssh.surf:$port using any RDP Client"