xRDP – How to easily install xrdp on Debian Distribution using debian-xrdp-installer-1.0 script (Preview Version!!!)

  The script hereafter is outdated and has been replaced by a newer version.  Please Check the Download page for latest version

Hello World, 

In our previous post,  we have provided a quick step by step guide on how to install Debian 10 distribution using the MATE Desktop interface.  Based on this installation guide, we will now have a look on how to perform an automated installation of the xRDP Software solution.   If you are following us on a regular base, you know that we have developed a small script that can be used to automate the xrdp installation.  However, the script is specifically targeting Ubuntu Operating system (the official and standard version shipping with Gnome Desktop interface).  

Some readers have been requesting to publish possibly a fork of the script that would be specifically targeting Debian Distribution or to include support for Debian in the original script.  We have decided to create a Debian version of the script which will be called debian-xrdp-installer-1.0.sh because we wanted to make a first release available quite quickly.  Both script are sharing a lot of common code and it’s possible that in the near future, we will merge these two scripts.  The famous xrdp-installer script would be supported on Ubuntu Operating System and Debian Distributions 

We will see later what would be the best approach. For the moment, let’s introduce the xrdp installer script for Debian…. 

Overview 

The debian-xrdp-installer-x.x.sh script ease the installation and post-configuration actions of xRDP on top of Debian Operating System.  This script is the first iteration for Debian and is based on our famous xrdp-installer script (targeting specifically Ubuntu Operating System).  This script should be working fine against Debian 10 where MATE Desktop interface has been installed.   

What’s new in this release – Version 1.0 (Preview Version) ?

This is the first version of the script targeting Debian Operating system.   This version 1.0 is basically a fork version of the original xrdp-installer script.  This means that the script support

  • the standard installation mode (i.e. using the precompiled xrdp package available on the Debian repository)
  • the custom installation mode (i.e.  using source code and compiling it on the fly for you ) 

Desktop interface supported : MATE & Gnome

Debian Operating system ships with multiple Desktop interface to be installed based on the user preferences.  You can choose from 

  • Gnome
  • MATE
  • KDE Plasma
  • xfce
  • LXE
  • LXQT
  • cinnamon

Originally, we were targeting only Debian systems running MATE Desktop interface.  Since the original script is running properly against Gnome Desktop interface, we have performed some additional tests against Debian and Gnome interface.  The script is working fine against Gnome Desktop as well.   

In summary, the debian-xrdp-installer script has been fully tested against 

  • Debian 10 + Mate Desktop interface
  • Debian 10 + Gnome Desktop Interface  

We have also decided to test other Desktop interface and it’s possible that the script would run fine against all the mentioned Desktop interface listed above.  This is based on best efforts and some limitations still applies…This is not fully implemented and tested

Download the Script 

The script can be download at this location  :    debian-xrdp-installer-1.0.zip 

Note : All the xrdp scripts can be found at https://www.c-nergy.be/products.html

How to Use the Script

The debianxrdp-installer-1.0 script will work in a similar way as the original script version. The following section will explain how to download, extract, set executable mode and perform the installation using the script.  The script provides some switches that can be used to customize the installation process.

So, let’s see how this would be working…. 

Disclaimer

The script is provided AS IS.  Use it at your own risk !!! 

Prerequisites and assumptions  

The following conditions should be met in order to have the best results while using the script

  • We assume that your machine is connected to internet while performing the installation.  This is needed as additional packages and software needs to be downloaded and installed on your Ubuntu machine
  • The script runs against a supported Operating system (Debian Distribution)
  • MATE Desktop & Gnome Desktop is supported (Currently, testing other Desktop interfaces)
  • To have sound redirection, computer needs to have sound card available

Script version & Supported Debian Version

The debian-xrdp-installer-1.0.sh script will support the following Debian Operating system

  • Debian 10 (Buster)

Step 1 – Download the script 

To download the script, you have multiple options.   You can from a Terminal issue the following command 

wget https://www.c-nergy.be/downloads/xRDP/debian-xrdp-installer-1.0.zip

You can also simply use your browser and click on the link to download the script :  

Step 2 – unzip the file 

After downloading the zip package containing the file, you will need to unzip it first. To unzip the package, you can use the Terminal console and issue the following command 

unzip debian-xrdp-installer-1.0.zip 

You can also use the GUI and the Nautilus file manager to select the downloaded package, right-click on it and select the option Extract Here

Step 2 – Set Execute Right on the script

Download the debian-xrdp-installer-1.0.sh script to your system, extract content and mark it as executable . To do this, perform the following action in a terminal console

chmod +x  ~/Downloads/debian-xrdp-installer-1.0.sh

Note : Adjust the path where the debian-xrdp-Installer-1.0.sh script to reflect your environment

Step 2 – Run as normal user 

The script needs to be run as a normal user.  The script will start running and will prompt you for password when sudo actions are initiated.  If you run the script as root or using sudo command, the Download folder does not exist for the root user and the script fails to run as expected.   To overcome this situation, the script also check which user is executing the script. If the script is run under sudo or root accounts, a warning message will be displayed and the script will not execute

Step 3 – Switches and parameters 

The debian-xrdp-installer-1.0.sh script can be executed as is (with no parameters or switches). This will perform a standard (and basic) installation of xRDP.  No sound or custom xrdp login script will be made available.  However, remote desktop, drive redirection and clipboard redirection would be available with this installation mode.  

The debian-xrdp-installer-1.0.sh script accept also some additional parameters that will help customize the xrdp installation and enable additional features.  The script provides the following parameters 

--help or -h          => will display a basic help menu
--sound or -s         => will enable sound redirection 
--loginscreen or -l   => will customize the xRDP login screen 
--remove or -r        => will remove the xrdp package 
--custom or -c        => will perform a custom installation (i.e. compiled from sources)

Step 4 – Perform xRDP installation using the script 

The following sections will provide some examples and scenario on how you can use the script….. 

Standard Installation – No Parameter

As mentioned above, you can decide to use the default xrdp package available in the Debian repository and perform a basic installation which will provide you remote desktop capability and will also customize the remote sesssion.  The script will ensure that the same look n’ feel will be maintained when the user logs on locally or remotely. 

To perform a standard installation, you execute the script with no parameters.  Open a Terminal console, browse to the location where the script has been downloaded and issue the following command 

 ./debian-xrdp-installer-1.0.sh

When the xrdp installation package will start, you be requested to enter your password. Provide the password and proceed with the installation. Wait for completion of the script.  The machine will not reboot automatically when done so you can review the actions performed by the script….

Standard Installation with Parameters

The script can be used to perform a standard installation and still passes some parameters to get the most of the xRDP packages and their features.  For all the Debian versions, we could use the following combination of parameters 

./debian-xrdp-installer-1.0.sh -s      (this would enable the sound redirection) 
./debian-xrdp-installer-1.0.sh -l      (this would customize the xrdp login screen -see here)

Obviously, you can combine the switches (any order) to have more features enabled  

./debian-xrdp-installer-1.0.sh -s -l      (this would enable the sound redirection and customize the xrdp login screen)

Important Notes

The script can be run multiple times on the same machine.  If you have run initially the script with no parameters but you decide afterward to enable additional features, the script can be re-executed and the additional features will be enabled.  

Custom Installation – Default Installation 

Custom installation script is really flexible. Custom installation means that the script will compile the xrdp package from the source binaries. The custom installation script always uses the latest xrdp package version available 

To perform a custom installation, you will need at minimum to pass one parameter.  The following command line shows you how to perform a custom installation  

./debian-xrdp-installer-1.0.sh -c     (this would perform a custom installation but will not enabled adv features like sound redirection or custom login screen)

Custom Installation – Additional Options  

If a user wants to enable additional features, you will pass some additional parameters as shown in the following examples 

./debian-xrdp-installer-1.0.sh -c -s     (this would perform a custom install and enable sound redirection)
./debian-xrdp-installer-1.0.sh -c -l     (this would perform a custom install and customize xrdp login screen)
./debian-xrdp-installer-1.0.sh -c -l -s  (this would perform a custom install, enable sound and customize login screen)

Important Notes

The script can be run multiple times on the same machine.  If you have run initially the script with no parameters but you decide afterward to enable additional features, the script can be re-executed and the additional features will be enabled.  

Remove Installation option

This version of the script also ship with the option to remove xRDP package.  The removal option should be only used  if you have uses this version of this script to perform the installation.  To remove the xrdp package, you would simply execute the following command  

./debian-xrdp-installer-1.0.sh -r     (to remove the xrdp packages)

Step 5 – Test your configuration 

After the script has run and after the reboot/shutdown and start process, it’s time to test and see if you can indeed perform a smooth remote connection to your Debian machine.  Start your favorite rdp client and simply enter your credentials and start testing your installation.  

Click on Picture for better Resolution

If everything is ok, you will see the xrdp login screen.  In the screenshot below, you can see that we have used the -l option in order to customize the layout….. 

Click on Picture for better Resolution

If your configuration is good, you will then be able to access your Debian Desktop interface (either MATE or Gnome) 

Click on Picture for better Resolution

 

Known issues and limitations 

Known Issues 

Keyboard layout & Mate Desktop   

If you are using English keyboard, you will not be affected by this problem.  However, if you are like me and you are using a non-English keyboard, you will notice that when connected remotely to your Mate desktop session through xRDP software, the keyboard layout default is set to English Keyboard. This can be quite annoying. To fix that, you will need to add within the remote desktop session the keyboard layout you want to use.  In a next release of the script, we will fix this issue directly within the script. 

So, as you can see hereafter on the screenshot, we are using the Belgian Keyboard when connected locally on the machine 

Click on Picture for better Resolution

When performing the remote desktop connection, we check again the login screen and we can see that the English keyboard is listed.  We have removed it and add the belgian keyboard to solve this issue….However, it seems that when you reconnect, you keyboard layout will not stick and you will have to perform the change each time…. 

Click on Picture for better Resolution

Again, as mentioned earlier, this will be fixed with the next release of the script….

Drive Redirection  

To redirect your drives to your xrdp remote session, you have to ensure that the only option selected in the local resources tab are the Clipboard option and the drive option. Check the screenshot below and ensure that you have the same settings.

Click on picture for better resolution

Click on picture for better resolution

When these settings have been set accordingly, you should see the thin client folder populated with redirected drives coming from your Windows machine.

Sound redirection Issue

If the Sound redirection option has been selected, rebooting the Debian system is not enough and the sound redirection might not work.  if the sound redirection option has been selected, you will have to shutdown your Debian machine and then start it again in order to ensure that the sound redirection feature would work as expected.

However, this usually is not sufficient.  To have sound working, you can decide to wait min 30 sec and see if the xrdp_sink are loaded or you simply execute the following command within your remote session and the sound will start working 

pulseaudio -k

Black Screen or disconnected immediately after connecting

As mentioned and explained multiple times,  this situation will happen (or can happen) when the same user account is used concurrently locally and remotely.  In other words,  the problem is related to the fact that the same user account is already logged in locally and a remote connection is attempted at the same time.  With xRDP software solution, a specific user account can be logged on either locally or remotely but not both….  

You can read more information and some workarounds (provided as is) to try to fix the issues in the following posts 

Limitations

Switch between standard and Custom install

This version of the script can be run multiple times on the same machine.  However, because of this new behavior, you cannot perform a standard installation and then decide to perform the custom installation.  Once you have selected your installation mode, you will have to stick to it.  This is kind of checked by the script.  

So, if you have performed a standard installation but afterwards you might want to use the custom installation option, the script will ignore the request.  If you want to move from standard install mode to custom mode (or vice versa), the correct process is 

  • remove xrdp (using the debian-xrdp-installer-1.0.sh -r option) 
  • perform a new installation using your selected installation mode (standard or custom install mode) 

Switch between Desktop Interfaces

The script is detecting the desktop interface when it is executed. If you want to use a different Desktop interface after running the script, the remote desktop interface might look different to what you would expected.  To ensure consistent look’n feel, if you change desktop interface would be to either remove and re-run the script from the new desktop interface loaded.  The other option would be to update the /etc/xrdp/startwm.sh file accordingly.   

In the next release of this script, we might include an additional switch to easily support the change of Desktop Interface…..  

Not Tested Desktop Interfaces

As mentioned earlier, the script is fully tested against MATE and Gnome Desktop interface and should be working as expected.  If your running this preview version of the script against other Desktop interfaces such as KDE, cinnamon or LXQT,  you might encounter some small issues such as polkit policy popup or missing default windows manager for LXQT or software rendering notifications for Cinnamon interface.    All these behaviors are to be expected since we have no tested all the possible combination yet…. 

Final Notes

This is it for this post !  

This script should be seen as a first and stable version of the xrdp-installer script for Debian OS.  You should be able to install xrdp on a Debian machine running MATE desktop or Gnome Desktop and have it working accordingly.  If you look at the code, you will still see some references to Ubuntu Operating system.  This is expected since we are using our original xrdp-installer script to create this fork.  The debian script has provided us the opportunity to introduce some code changes that could be beneficial and will definitely be added to the original script… So, expect to see a new version released soon

Finally, we do not know yet if we will be keeping two versions of the script (one for Ubuntu OS and one for Debian) or if we will merge them into a single script.  This is still work in progress but should be working in most of cases.  We should release new “stable” version quite soon….

Please if you have time or want to help us in creating the best xrdp installer script, download the script, test it and provide constructive feedback.  If you find a bug or an issue with the script, let us know as well so we can try to fix it.  

Till next time

Annex – The Script Source code 

#!/bin/bash
#####################################################################################################
# Script_Name : debian-xrdp-installer-1.0.sh
# Description : Perform xRDP installation on Debian Distribution 
# Date : May 2021
# written by : Griffon
# WebSite :https://www.c-nergy.be - https://www.c-nergy.be/blog
# Version : 1.0 
# History : 1.0   -  re-write std vs custom mode installation detection
#         : 0.9   -  Cleanup code and validate it against debian OS 
#         : 0.8   -  Adding basic error handling when installing additional packages 
#         : 0.7   -  Adding Prep_OS Function (might be use later to support more version)
#         : 0.6   -  Change fix_theme function - new color scheme and custom logo
#         : 0.5   -  add Debian Source url for custom install 
#         : 0.4   -  Changed code to detect if gnome tweaks needs to be installed or not
#         : 0.3   -  Adding variable for Desktop interface detection (future usage)
#         : 0.2   -  re-write code OS detection and supported version 
#         : 0.1   -  Forking original xrdp-installer-script      
# Disclaimer : Script provided AS IS. Use it at your own risk....
#              You can use this script and distribute it as long as credits are kept 
#              in place and unchanged   
####################################################################################################
#---------------------------------------------------#
# Variables and Constants                           #
#---------------------------------------------------#

#--Automating Script versioning 
ScriptVer="1.0"

#--Detecting  OS Version 
version=$(lsb_release -sd)
codename=$(lsb_release -sc)
Release=$(lsb_release -sr)

#--Detecting variable related to Desktop interface and Directory path (to support more desktop interfaces at a later stage) 
DesktopVer="$XDG_CURRENT_DESKTOP" 
SessionVer="$GNOME_SHELL_SESSION_MODE"
ConfDir="$XDG_DATA_DIRS"

#Define Dwnload variable to point to ~/Downloads folder of user running the script
Dwnload=$(xdg-user-dir DOWNLOAD)

#Initialzing other variables
modetype="unknown"

#--------------------------------------------------------------------------#
# -----------------------Function Section - DO NOT MODIFY -----------------#
#--------------------------------------------------------------------------#

#---------------------------------------------------#
# Function 0  - check for supported OS version  ....#
#---------------------------------------------------#

check_os()
{
echo
/bin/echo -e "\e[1;33m   |-| Detecting Distribution version        \e[0m"
case $version in
 *"Debian"*)
  /bin/echo -e "\e[1;32m       |-| Debian Version : $version\e[0m"
  ;;
 
*)
    /bin/echo -e "\e[1;31m  !--------------------------------------------------------------!\e[0m"
    /bin/echo -e "\e[1;31m  ! Your system is not running a supported version               !\e[0m"
    /bin/echo -e "\e[1;31m  ! The script has been tested only on the following versions    !\e[0m"
    /bin/echo -e "\e[1;31m  ! Debian Distribution running MATE Desktop or Gnome            !\e[0m"
    /bin/echo -e "\e[1;31m  ! The script is exiting...                                     !\e[0m"             
    /bin/echo -e "\e[1;31m  !--------------------------------------------------------------!\e[0m"
    echo
    exit
    ;;
esac
echo
}

#---------------------------------------------------#
# Function 1  - check xserver-xorg-core package....
#---------------------------------------------------#

check_hwe()
{
echo
/bin/echo -e "\e[1;33m   |-| Detecting xserver-xorg-core package installed \e[0m"
xorg_no_hwe_install_status=$(dpkg-query -W -f ='${Status}\n' xserver-xorg-core 2>/dev/null)
xorg_hwe_install_status=$(dpkg-query -W -f ='${Status}\n' xserver-xorg-core-hwe-$Release 2>/dev/null) 

if [[ "$xorg_hwe_install_status" =~ \ installed$ ]]
then
#  hwe version is installed on the system
/bin/echo -e "\e[1;32m  |-| xorg package version: xserver-xorg-core-hwe \e[0m"
HWE="yes"
elif [[ "$xorg_no_hwe_install_status" =~ \ installed$ ]]
then
/bin/echo -e "\e[1;32m  |-| xorg package version: xserver-xorg-core \e[0m"
HWE="no"
else
/bin/echo -e "\e[1;31m  |-| Error checking xserver-xorg-core flavour \e[0m"
exit 1
fi
}

PrepOS()

{
if [[ *"$version"* = *"Debian"*  ]]
then
 #Disable cdrom source.list to avoid prompt during install # DEBIAN SPECIFIC
 sudo sed -i 's/deb cdrom:/#deb cdrom:/' /etc/apt/sources.list
 sudo apt-get update
fi
}

############################################################################
# INSTALLATION MODE : STANDARD
############################################################################

#---------------------------------------------------#
# Function 2  - Install xRDP Software....
#---------------------------------------------------#

install_xrdp()
{
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Installing XRDP Packages...Proceeding...  !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo

if [[ $HWE = "yes" ]] && [[ "$version" = *"Ubuntu 18.04"* ]];
then
    sudo apt-get install xrdp -y
    sudo apt-get install xorgxrdp-hwe-18.04
else
    sudo apt-get install xrdp -y
fi
}

############################################################################
# ADVANCED INSTALLATION MODE : CUSTOM INSTALLATION
############################################################################

#---------------------------------------------------#
# Function 3 - Install Prereqs...
#---------------------------------------------------#

install_prereqs() {
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Installing PreReqs packages..Proceeding.  ! \e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo

if [[ *"$version"* = *"Debian"*  ]]
then

#Debian Specific - add in source backport package to download necessary packages - Debian Specific
sudo apt-get install -y software-properties-common
sudo apt-add-repository -s -y 'deb http://deb.debian.org/debian '$codename'-backports main'

sudo apt-get update 

#--Needed to be created manually or compilation fails 
sudo mkdir /usr/local/lib/xrdp/
fi
#--End Debian Specific --# 

#Install packages
sudo apt-get -y install git
sudo apt-get -y install libx11-dev libxfixes-dev libssl-dev libpam0g-dev libtool libjpeg-dev flex bison gettext autoconf libxml-parser-perl libfuse-dev xsltproc libxrandr-dev python-libxml2 nasm fuse pkg-config git intltool checkinstall
echo

#-- check if no error during Installation of missing packages

if [ $? -eq 0 ]
then 
/bin/echo -e "\e[1;33m   |-| Preprequesites installation successfully       \e[0m"
else 
echo
/bin/echo -e "\e[1;31m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;31m   !   Error while installing prereqs            !\e[0m"
/bin/echo -e "\e[1;31m   !   The Script is exiting....                 !\e[0m"
/bin/echo -e "\e[1;31m   !---------------------------------------------!\e[0m"
exit
fi

#-- check if hwe stack needed or not 
if [ $HWE = "yes" ];
then
    # - xorg-hwe-* to be installed
    /bin/echo -e "\e[1;32m       |-| xorg package version: xserver-xorg-core-hwe-$Release \e[0m"
    sudo apt-get install -y xserver-xorg-dev-hwe-$Release xserver-xorg-core-hwe-$Release    
else
    #-no-hwe
    /bin/echo -e "\e[1;32m       |-| xorg package version: xserver-xorg-core \e[0m"
    echo
    sudo apt-get install -y xserver-xorg-dev xserver-xorg-core
fi

}

#---------------------------------------------------#
# Function 4 - Download XRDP Binaries... 
#---------------------------------------------------#

get_binaries() { 
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Download xRDP Binaries.......Proceeding.  ! \e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo

#cd ~/Downloads
Dwnload=$(xdg-user-dir DOWNLOAD)

cd $Dwnload
#Check if xrdp folder already exists.  if yes; delete it and download again in order to get latest version

if [ -d "$Dwnload/xrdp" ] 
then
    sudo rm -rf xrdp
fi

#Check if xorgxrdp folder already exists.  if yes; delete it and download again in order to get latest version
if [ -d "$Dwnload/xorgxrdp" ] 
then
    sudo rm -rf xorgxrdp
fi

## -- Download the xrdp latest files
echo
/bin/echo -e "\e[1;32m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;32m   !  Preparing download xrdp package            !\e[0m"
/bin/echo -e "\e[1;32m   !---------------------------------------------!\e[0m"
echo
git clone https://github.com/neutrinolabs/xrdp.git
echo
/bin/echo -e "\e[1;32m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;32m   !  Preparing download xorgxrdp package        !\e[0m"
/bin/echo -e "\e[1;32m   !---------------------------------------------!\e[0m"
echo
git clone https://github.com/neutrinolabs/xorgxrdp.git
}

#---------------------------------------------------#
# Function 5 - compiling xrdp... 
#---------------------------------------------------#

compile_source() { 
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Compile xRDP packages .......Proceeding.  !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo

cd $Dwnload/xrdp

#Get the release version automatically
pkgver=$(git describe  --abbrev=0 --tags  | cut -dv -f2)
sudo ./bootstrap
sudo ./configure --enable-fuse --enable-jpeg --enable-rfxcodec
sudo make

#-- check if no error during compilation 
if [ $? -eq 0 ]
then 
/bin/echo -e "\e[1;33m   |-| Make Operation Completed successfully       \e[0m"
else 
echo
/bin/echo -e "\e[1;31m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;31m   !   Error while Executing make                !\e[0m"
/bin/echo -e "\e[1;31m   !   The Script is exiting....                 !\e[0m"
/bin/echo -e "\e[1;31m   !---------------------------------------------!\e[0m"
exit
fi
sudo checkinstall --pkgname=xrdp --pkgversion=$pkgver --pkgrelease=1 --default

#xorgxrdp package compilation
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Compile xorgxrdp packages....Proceeding.  !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo

cd $Dwnload/xorgxrdp

#Get the release version automatically
pkgver=$(git describe  --abbrev=0 --tags  | cut -dv -f2)
sudo ./bootstrap 
sudo ./configure 
sudo make

# check if no error during compilation 
if [ $? -eq 0 ]
then 
echo
/bin/echo -e "\e[1;33m   |-| Make Operation Completed successfully       \e[0m"
echo
else 
echo
/bin/echo -e "\e[1;31m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;31m   !   Error while Executing make                !\e[0m"
/bin/echo -e "\e[1;31m   !   The Script is exiting....                 !\e[0m"
/bin/echo -e "\e[1;31m   !---------------------------------------------!\e[0m"
exit
fi

sudo checkinstall --pkgname=xorgxrdp --pkgversion=1:$pkgver --pkgrelease=1 --default

}

#---------------------------------------------------#
# Function 6 - create services .... 
#---------------------------------------------------# 

enable_service() {
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Creating xRDP services.......Proceeding.  !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo 
sudo systemctl daemon-reload
sudo systemctl enable xrdp.service
sudo systemctl enable xrdp-sesman.service
sudo systemctl start xrdp
}

############################################################################
# COMMON FUNCTIONS - WHATEVER INSTALLATION MODE - Version Specific !!!
############################################################################

#---------------------------------------------------#
# Function 7 - Install Gnome Tweak Tool.... 
#---------------------------------------------------#

#If Gnome is the Desktop, install Tweaks utilty (optional)
install_tweak() 
{
if [ "$DesktopVer" = "MATE" ] || [ "$DesktopVer" = "KDE" ];
then
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   No Gnome Tweaks Needed...Proceeding...    !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
else
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Installing Gnome Tweak...Proceeding...    !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo
    sudo apt-get install gnome-tweak-tool -y
fi
}

#--------------------------------------------------------------------#
# Fucntion 8 - Allow console Access ....(seems optional in u18.04)
#--------------------------------------------------------------------#

allow_console() 

{
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Granting Console Access...Proceeding...   !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo
# Checking if Xwrapper file exists
if [ -f /etc/X11/Xwrapper.config ]
then
sudo sed -i 's/allowed_users=console/allowed_users=anybody/' /etc/X11/Xwrapper.config
else
    sudo bash -c "cat >/etc/X11/Xwrapper.config" <<EOF
    allowed_users=anybody
EOF
fi
}

#---------------------------------------------------#
# Function 9 - create policies exceptions .... 
#---------------------------------------------------#

create_polkit()
{
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Creating Polkit File...Proceeding...      !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo

#All Ubuntu version
sudo bash -c "cat >/etc/polkit-1/localauthority/50-local.d/45-allow.colord.pkla" <<EOF
[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes
EOF

if [[ "$version" = *"Ubuntu 20.10"* ]] || [[ "$version" = *"Ubuntu 20.04"* ]] || [[ "$version" = *"Ubuntu 21.04"* ]] || [[ "$version" = *"Pop!_OS 20.04"* ]] || [[ "$version" = *"Pop!_OS 20.10"* ]] || [[ "$version" = *"Pop!_OS 21.04"* ]] || [[ "$version" = *"Debian"* ]];
then
sudo bash -c "cat >/etc/polkit-1/localauthority/50-local.d/46-allow-update-repo.pkla" <<EOF
[Allow Package Management all Users]
Identity=unix-user:*
Action=org.freedesktop.packagekit.system-sources-refresh;org.freedesktop.packagekit.system-network-proxy-configure
ResultAny=yes
ResultInactive=yes
ResultActive=yes
EOF
fi
}

#---------------------------------------------------#
# Function 10 - Fixing Theme and Extensions .... 
#---------------------------------------------------#

fix_theme()
{
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Fix Theme and extensions...Proceeding...  !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo

# Checking if script has run already 

if [ -f /etc/xrdp/startwm.sh.griffon ]
then
sudo rm /etc/xrdp/startwm.sh
sudo mv /etc/xrdp/startwm.sh.griffon /etc/xrdp/startwm.sh
fi 

#Backup the file before modifying it
sudo cp /etc/xrdp/startwm.sh /etc/xrdp/startwm.sh.griffon
echo
sudo sed -i "4 a #Improved Look n Feel Method\ncat <<EOF > ~/.xsessionrc\nexport GNOME_SHELL_SESSION_MODE=$SessionVer\nexport XDG_CURRENT_DESKTOP=$DesktopVer\nexport XDG_DATA_DIRS=$ConfDir\nEOF\n" /etc/xrdp/startwm.sh
echo
}

#------------------------------------------------------------------#
# Function 11 - Enable Multi connection Support (Experimental) .... #
#------------------------------------------------------------------#

multi_conn()
{
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   ! Enable Multi connection Trick ..Proceeding. ! \e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"  
echo
#Fix Local & Remote session connections

if [ -d "/usr/local/share/xrdp" ] 
then
    #Custom installation detected 
    sudo sed -i "/wm_start()/i#Allow two sessions (local and remote)\nunset DBUS_SESSION_BUS_ADDRESS\nunset XDG_RUNTIME_DIR\n" /etc/xrdp/startwm.sh
else
    sudo sed -i "/test -x/i#Allow two sessions (local and remote)\nunset DBUS_SESSION_BUS_ADDRESS\nunset XDG_RUNTIME_DIR\n" /etc/xrdp/startwm.sh
fi
}

#---------------------------------------------------#
# Function 12 - Enable Sound Redirection .... 
#---------------------------------------------------#

enable_sound()
{
echo
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
/bin/echo -e "\e[1;33m   !   Enabling Sound Redirection...             !\e[0m"
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m"
echo
pulsever=$(pulseaudio --version | awk '{print $2}')

# Step 2 - Install Some PreReqs
sudo apt-get install libconfig-dev -y
sudo apt-get install git libpulse-dev autoconf m4 intltool build-essential dpkg-dev libtool libsndfile-dev libcap-dev -y libjson-c-dev
sudo apt build-dep pulseaudio -y

# Step 3 -  Download pulseaudio source in /tmp directory - Do not forget to enable source repositories -debian
cd /tmp
sudo apt source pulseaudio=$pulsever

# Step 4 - Compile
cd /tmp/pulseaudio-$pulsever
sudo ./configure

# step 5 - Create xrdp sound modules
sudo git clone https://github.com/neutrinolabs/pulseaudio-module-xrdp.git
cd pulseaudio-module-xrdp
sudo ./bootstrap 
sudo ./configure PULSE_DIR="/tmp/pulseaudio-$pulsever"
sudo make

#Step 6 copy files to correct location (as defined in /etc/xrdp/pulse/default.pa)
cd /tmp/pulseaudio-$pulsever/pulseaudio-module-xrdp/src/.libs
sudo install -t "/var/lib/xrdp-pulseaudio-installer" -D -m 644 *.so
sudo install -t "/usr/lib/pulse-$pulsever/modules" -D -m 644 *.so
echo

}

#---------------------------------------------------#
# Function 13 - Custom xRDP Login Screen .... 
#---------------------------------------------------#

custom_login()
{
echo 
/bin/echo -e "\e[1;33m   |-| Customizing xRDP login screen       \e[0m" 
Dwnload=$(xdg-user-dir DOWNLOAD)
cd $Dwnload
#chek if file exists if not - download it.... 
if [ -f "griffon_logo_xrdpd.bmp" ]
then
/bin/echo -e "\e[1;32m       |-| necessary file already available...skipping   \e[0m"
else
/bin/echo -e "\e[1;32m       |-| Downloading additional file...: logo_xrdp image   \e[0m"
wget http://www.c-nergy.be/downloads/griffon_logo_xrdpd.bmp
fi

#Check if script has run once...
if [ -f /etc/xrdp/xrdp.ini.griffon ]
then
sudo rm /etc/xrdp/xrdp.ini
sudo mv /etc/xrdp/xrdp.ini.griffon /etc/xrdp/xrdp.ini
fi 

#Backup file 
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.griffon

#Check where to copy the logo file
if [ -d "/usr/local/share/xrdp" ] 
then
    #Custom install 
    sudo cp griffon_logo_xrdpd.bmp /usr/local/share/xrdp
    sudo sed -i 's/ls_logo_filename=/ls_logo_filename=\/usr\/local\/share\/xrdp\/griffon_logo_xrdpd.bmp/g' /etc/xrdp/xrdp.ini
else
    #Std Install
    sudo cp griffon_logo_xrdpd.bmp /usr/share/xrdp
    sudo sed -i 's/ls_logo_filename=/ls_logo_filename=\/usr\/share\/xrdp\/griffon_logo_xrdpd.bmp/g' /etc/xrdp/xrdp.ini
fi

sudo sed -i 's/blue=009cb5/blue=dedede/' /etc/xrdp/xrdp.ini
sudo sed -i 's/#white=ffffff/white=dedede/' /etc/xrdp/xrdp.ini
sudo sed -i 's/#ls_title=My Login Title/ls_title=Remote Desktop for Linux/' /etc/xrdp/xrdp.ini
sudo sed -i 's/ls_top_window_bg_color=009cb5/ls_top_window_bg_color=27354D/' /etc/xrdp/xrdp.ini
sudo sed -i 's/ls_bg_color=dedede/ls_bg_color=ffffff/' /etc/xrdp/xrdp.ini
sudo sed -i 's/ls_logo_x_pos=55/ls_logo_x_pos=0/' /etc/xrdp/xrdp.ini
sudo sed -i 's/ls_logo_y_pos=50/ls_logo_y_pos=5/' /etc/xrdp/xrdp.ini
}

#---------------------------------------------------#
# Function 14 - Fix SSL Minor Issue .... 
#---------------------------------------------------#

fix_ssl() 
{ 
echo 
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m" 
/bin/echo -e "\e[1;33m   ! Fixing SSL Cert Issue ...                   !\e[0m" 
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m" 
echo
/bin/echo -e "\e[1;33m   |-| Checking Group membership ssl-cert        \e[0m" 
if id -Gn xrdp | grep ssl-cert 
then 
    /bin/echo -e "\e[1;32m       |-| xrdp is already member to ssl-cert...skipping   \e[0m"
else
    /bin/echo -e "\e[1;32m       |-| xrdp is not member to ssl-cert...Adding   \e[0m"
    sudo adduser xrdp ssl-cert 
fi
}

#---------------------------------------------------#
# Function 15 - Fixing env variables in XRDP .... 
#---------------------------------------------------#

fix_env()
{
/bin/echo -e "\e[1;33m   |-| Checking env variable settings       \e[0m" 

#Add this line to /etc/pam.d/xrdp-sesman if not present
if grep -Fxq "session required pam_env.so readenv=1 user_readenv=0" /etc/pam.d/xrdp-sesman 
   then
    /bin/echo -e "\e[1;32m       |-| settings for env. variable already set...   \e[0m"
   else
    /bin/echo -e "\e[1;32m       |-| Env. variable not set...Applying   \e[0m"
    sudo sed -i '1 a session required pam_env.so readenv=1 user_readenv=0' /etc/pam.d/xrdp-sesman
fi
}

#---------------------------------------------------#
# Function 16 - Removing XRDP Packages .... 
#---------------------------------------------------#

remove_xrdp()
{
echo 
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m" 
/bin/echo -e "\e[1;33m   ! Removing xRDP Packages...                   !\e[0m" 
/bin/echo -e "\e[1;33m   !---------------------------------------------!\e[0m" 
echo 

#remove the xrdplog file created by the script 
sudo rm /etc/xrdp/xrdp-installer-check.log

#----remove xrdp package
sudo systemctl stop xrdp
sudo systemctl disable xrdp
sudo apt-get autoremove xrdp -y
sudo apt-get purge xrdp -y

#---remove xorgxrdp
sudo systemctl stop xorgxrdp
sudo systemctl disable xorgxrdp

if [[ $HWE = "yes" ]] && [[ "$version" = *"Ubuntu 18.04"* ]];
then
    sudo apt-get autoremove xorgxrdp-hwe-18.04 -y 
    sudo apt-get purge xorgxrdp-hwe-18.04 -y
else
    sudo apt-get autoremove xorgxrdp -y 
    sudo apt-get purge xorgxrdp -y
fi

#---Cleanup files 

#Remove xrdp folder
if [ -d "$Dwnload/xrdp" ] 
then
    sudo rm -rf xrdp
fi

#Remove xorgxrdp folder
if [ -d "$Dwnload/xorgxrdp" ] 
then
    sudo rm -rf xorgxrdp
fi

#Remove custom xrdp logo file
if [ -f "$Dwnload/griffon_logo_xrdpd.bmp" ]
then
    sudo rm -f  "$Dwnload/griffon_logo_xrdpd.bmp"
fi
sudo systemctl daemon-reload
}

#---------------------------------------------------#
# Function 17 - Show Credits
#---------------------------------------------------#
sh_credits()
{
echo
/bin/echo -e "\e[1;36m   |----------------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;36m   | Installation Completed...Please test your xRDP configuration   !\e[0m" 
/bin/echo -e "\e[1;36m   | If Sound option selected, shutdown your machine completely     !\e[0m"
/bin/echo -e "\e[1;36m   | start it again to have sound working as expected               !\e[0m"
/bin/echo -e "\e[1;36m   |                                                                !\e[0m"
/bin/echo -e "\e[1;36m   | Credits : Written by Griffon - May 2021                        !\e[0m"
/bin/echo -e "\e[1;36m   |           www.c-nergy.be debian-xrdp-installer-v$ScriptVer.sh         !\e[0m"
/bin/echo -e "\e[1;36m   |           ver $ScriptVer                                              !\e[0m"
/bin/echo -e "\e[1;36m   |----------------------------------------------------------------!\e[0m"
echo

}

#---------------------------------------------------#
# SECTION FOR OPTIMIZING CODE USAGE...              #
#---------------------------------------------------#

install_common()
{
allow_console
create_polkit
fix_theme
fix_ssl
fix_env
}

install_custom()
{
install_prereqs
get_binaries
compile_source
enable_service
}

#--------------------------------------------------------------------------#
# -----------------------END Function Section             -----------------#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#------------                 MAIN SCRIPT SECTION       -------------------# 
#--------------------------------------------------------------------------#
#---------------------------------------------------#
# Script Version information Displayed              #
#---------------------------------------------------#

echo
/bin/echo -e "\e[1;36m   !-----------------------------------------------------------------!\e[0m"
/bin/echo -e "\e[1;36m   !   debian-xrdp-installer-$ScriptVer Script                              !\e[0m"
/bin/echo -e "\e[1;36m   !   Support Debian Distribution                                   !\e[0m"
/bin/echo -e "\e[1;36m   !   Written by Griffon - May 2021 - www.c-nergy.be              !\e[0m"
/bin/echo -e "\e[1;36m   !                                                                 !\e[0m"
/bin/echo -e "\e[1;36m   !   For Help and Syntax, type ./debian-xrdp-installer-$ScriptVer.sh -h    !\e[0m"
/bin/echo -e "\e[1;36m   !                                                                 !\e[0m"
/bin/echo -e "\e[1;36m   !-----------------------------------------------------------------!\e[0m"
echo

#----------------------------------------------------------#
# Step 0 -Detecting if Parameters passed to script ....    #
#----------------------------------------------------------#

for arg in "$@"
do
    #Help Menu Requested
    if [ "$arg" == "--help" ] || [ "$arg" == "-h" ]
    then
                echo "Usage Syntax and Examples"
                echo
                echo " --custom or -c           custom xRDP install (compilation from sources)"
                echo " --loginscreen or -l      customize xRDP login screen"
                echo " --remove or -r           removing xRDP packages"
                echo " --sound or -s            enable sound redirection in xRDP"
                echo
                echo "example                                                      "
                echo     
                echo " ./debian-xrdp-installer-$ScriptVer.sh -c -s  custom install with sound redirection"
                echo " ./debian-xrdp-installer-$ScriptVer.sh -l     standard install with custom login screen"
                echo " ./debian-xrdp-installer-$ScriptVer.sh        standard install no additional features"
                echo
                exit
    fi

    if [ "$arg" == "--sound" ] || [ "$arg" == "-s" ]
    then
        fixSound="yes"              
    fi 

    if [ "$arg" == "--loginscreen" ] || [ "$arg" == "-l" ]
    then
        fixlogin="yes"
    fi

    if [ "$arg" == "--custom" ] || [ "$arg" == "-c" ]
    then
        adv="yes"   
    fi

    if [ "$arg" == "--remove" ] || [ "$arg" == "-r" ]
    then
        removal="yes"       
    fi
done

#--------------------------------------------------------------------------------#
#-- Step 0 - Check that the script is run as normal user and not as root....
#-------------------------------------------------------------------------------#

if [[ $EUID -ne 0 ]]; 
then
    /bin/echo -e "\e[1;36m   !-------------------------------------------------------------!\e[0m"
    /bin/echo -e "\e[1;36m   !  Standard user detected....Proceeding....                   !\e[0m"
    /bin/echo -e "\e[1;36m   !-------------------------------------------------------------!\e[0m"
else
    echo
    /bin/echo -e "\e[1;31m   !-------------------------------------------------------------!\e[0m"
    /bin/echo -e "\e[1;31m   !  Script launched with sudo command. Script will not run...  !\e[0m"
    /bin/echo -e "\e[1;31m   !  Run script a standard user account (no sudo). When needed  !\e[0m"
    /bin/echo -e "\e[1;31m   !  script will be prompted for password during execution      !\e[0m"
    /bin/echo -e "\e[1;31m   !                                                             !\e[0m"
    /bin/echo -e "\e[1;31m   !  Exiting Script - No Install Performed !!!                  !\e[0m"
    /bin/echo -e "\e[1;31m   !-------------------------------------------------------------!\e[0m"
    echo
    exit
fi

#---------------------------------------------------#
#-- Step 1 - Try to Detect Ubuntu Version....       #
#---------------------------------------------------#

check_os

#--------------------------------------------------------#
#-- Step 2 - Try to detect if HWE Stack needed or not....#
#--------------------------------------------------------#

check_hwe

#--------------------------------------------------------------------------------#
#-- Step 3 - Check if Removal Option Selected
#--------------------------------------------------------------------------------#

if [ "$removal" = "yes" ];
then
    remove_xrdp
    echo
    sh_credits
    exit
fi

#---------------------------------------------------------#
# Step 4 - Executing the installation & config tasks .... #
#---------------------------------------------------------#

#-- Detect if multiple runs and install mode used..... 
echo
/bin/echo -e "\e[1;33m   |-| Checking if script has run at least once...        \e[0m"

if [ -f /etc/xrdp/xrdp-installer-check.log ]
then
    modetype=$(sed -n 1p /etc/xrdp/xrdp-installer-check.log)
    /bin/echo -e "\e[1;32m       |-| Script has already run. Detected mode...: $modetype\e[0m"
else 
    /bin/echo -e "\e[1;32m       |-| First run or xrdp-installer-check.log deleted. Detected : $modetype        \e[0m"
fi 

#---------------------------------------------------------------------------------------
#- Detect Standard vs custom install mode and additional options...
#----------------------------------------------------------------------------------------

    if [ "$adv" = "yes" ];
    then
        echo
        /bin/echo -e "\e[1;33m   |-| custom installation mode detected.        \e[0m"
    
        if [ $modetype = "custom" ];
        then 
            /bin/echo -e "\e[1;36m           |-| xrdp package is already installed using custom mode....skipping xrdp install        \e[0m"
        else 
            /bin/echo -e "\e[1;36m           |-| Proceed custom xrdp installation packages and customization tasks      \e[0m"
            PrepOS
            install_custom
            install_tweak
            install_common
      
            #create the file used a detection method 
            sudo touch /etc/xrdp/xrdp-installer-check.log
            sudo bash -c 'echo "custom" >/etc/xrdp/xrdp-installer-check.log'
        fi      
    else
        echo
            /bin/echo -e "\e[1;33m   |-| Additional checks Std vs Custom Mode..       \e[0m"
        if [ $modetype = "standard" ];
        then 
            /bin/echo -e "\e[1;35m           |-| xrdp package is already installed using standard mode....skipping xrdp install  \e[0m"
        elif [ $modetype = "custom" ]
        then 
            /bin/echo -e "\e[1;35m           |-| Checking for additional parameters"
        else
            /bin/echo -e "\e[1;32m       |-| Proceed standard xrdp installation packages and customization tasks      \e[0m"
            PrepOS
            install_xrdp
            install_tweak
            install_common
            
            #create the file 
            sudo touch /etc/xrdp/xrdp-installer-check.log
            sudo bash -c 'echo "standard" >/etc/xrdp/xrdp-installer-check.log'
        fi
    fi  #end if Adv option

#---------------------------------------------------------------------------------------
#- Check for Additional Options selected 
#----------------------------------------------------------------------------------------

if [ "$fixSound" = "yes" ]; 
then 
        enable_sound      
fi

if [ "$fixlogin" = "yes" ]; 
then
    echo
    custom_login
fi

#---------------------------------------------------------------------------------------
#- show Credits and finishing script
#--------------------------------------------------------------------------------------- 

sh_credits 
 

 

6 thoughts on “xRDP – How to easily install xrdp on Debian Distribution using debian-xrdp-installer-1.0 script (Preview Version!!!)

  1. @Craig,

    thank you for visiting our blog and providing feedback. Out of curiosity, can you tell me which Desktop Environment you have been using. is it Gnome Desktop or mate Desktop ?
    Can you tell us if you have performed a custom installation or a standard installation

    Till next time
    See ya

  2. Hello, thank you for all of your work on this tool!

    I am attempting to install on Rapsbian GNU/Linux 10 (buster) with Gnome 3.30.2 running.

    As Raspbian is based upon Debian, I had hoped it might work. However, the script exits with message that I am not running a supported version. Any thoughts on if this script would work if the version check was skipped?

  3. @James,

    Thank you for the visiting our blog and the feedback. We never tried the script against a Raspberry box and Raspbian GNU OS. IF you bypass the supported version check, there is a good chance that the installation would proceed and you might end up with a working xRDP instance. However, we would recommend you to use the version of the script xrdp-installer

    version 1.3

    since this one includes some additional check to try to find the correct Desktop to be used….Version 1.3 includes support for DEBIAN OS verison… IF you have the possibility to give it a try and provide us feedback that would be great so we could add this OS as a possible candidate in the next version of the script

    Waiting for your feedback,
    Hope this help
    Till next time
    See ya

  4. “oops something has gone wrong”

    google searches are flooded with these guides and 90% are WRONG. there is a bug in the current xrdp package

  5. @Nah,

    Thank you for sharing your experience. Please read carrefully the post and the information in the top of the post. This script/post is obsolete!!!. There is a link that will redirect you to the latest version of the script which will help you in installing xRDP on Debian systems. The script will check if you are trying to install the buggy version and will offer you to move with the custom installation. The script simply accept a bunch of switches and your xrdp software will be installed and working on your Debian

    Hope this help
    Till next time
    See ya

Leave a Reply