Last active
October 4, 2024 19:08
-
-
Save JimiC/80be050956aa6e3739cca3e892244ad8 to your computer and use it in GitHub Desktop.
Install XRDP with optional PulseAudio and Polkit on Debian distros (including MX Linux)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script based on linux-vm-tools for Debian distros. | |
# This script is for Debian based distros, to download and install XRDP+XORGXRDP via | |
# source. | |
# | |
# Major thanks to: http://c-nergy.be/blog/?p=11336 for the tips. | |
# | |
############################################################################### | |
# Update our machine to the latest code if we need to. | |
# | |
if [ "$(id -u)" -eq 0 ]; then | |
echo 'This script must be run without root privileges' >&2 | |
exit 1 | |
fi | |
sudo apt update && sudo apt upgrade -y | |
if [ -f /var/run/reboot-required ]; then | |
echo "A reboot is required in order to proceed with the install." >&2 | |
echo "Please reboot and re-run this script to finish the install." >&2 | |
exit 1 | |
fi | |
############################################################################### | |
# Error handler | |
# | |
set -e; | |
############################################################################### | |
# XRDP | |
# | |
xrdp() | |
{ | |
# Install the xrdp service so we have the auto start behavior | |
sudo apt install -y xrdp xorgxrdp | |
first_process=$(ps --no-headers -o comm 1) | |
if [ $first_process = 'systemd' ]; then | |
sudo systemctl stop xrdp | |
sudo systemctl stop xrdp-sesman | |
elif [ $first_process = 'init' ]; then | |
sudo service xrdp stop | |
else | |
echo "Unable to determine boot manager" | |
exit 1 | |
fi | |
# Configure the installed XRDP ini files. | |
# use vsock transport. | |
sudo sed -i_orig -e 's/port=3389/port=vsock:\/\/-1:3389/g' /etc/xrdp/xrdp.ini | |
# use rdp security. | |
sudo sed -i_orig -e 's/security_layer=negotiate/security_layer=rdp/g' /etc/xrdp/xrdp.ini | |
# remove encryption validation. | |
sudo sed -i_orig -e 's/crypt_level=high/crypt_level=none/g' /etc/xrdp/xrdp.ini | |
# disable bitmap compression since its local its much faster | |
sudo sed -i_orig -e 's/bitmap_compression=true/bitmap_compression=false/g' /etc/xrdp/xrdp.ini | |
# Add script to setup the ubuntu session properly | |
if [ ! -e /etc/xrdp/startdebian.sh ]; then | |
cat << EOF | sudo tee -a /etc/xrdp/startdebian.sh > /dev/null | |
#!/bin/sh | |
# If you not using GNOME, remove GNOME_SHELL_SESSION_MODE. | |
export GNOME_SHELL_SESSION_MODE=debian | |
# Change the XDG_CURRENT_DESKTOP with your default DE/WM | |
export XDG_CURRENT_DESKTOP=debian:GNOME | |
exec /etc/xrdp/startwm.sh | |
EOF | |
sudo chmod a+x /etc/xrdp/startdebian.sh | |
fi | |
# use the script to setup the ubuntu session | |
sudo sed -i_orig -e 's/startwm/startdebian/g' /etc/xrdp/sesman.ini | |
# rename the redirected drives to 'shared-drives' | |
sudo sed -i -e 's/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g' /etc/xrdp/sesman.ini | |
# Changed the allowed_users | |
sudo sed -i_orig -e 's/allowed_users=console/allowed_users=anybody/g' /etc/X11/Xwrapper.config | |
# Blacklist the vmw module | |
if [ ! -e /etc/modprobe.d/blacklist-vmw_vsock_vmci_transport.conf ]; then | |
echo "blacklist vmw_vsock_vmci_transport" | sudo tee -a /etc/modprobe.d/blacklist-vmw_vsock_vmci_transport.conf > /dev/null | |
fi | |
#Ensure hv_sock gets loaded | |
if [ ! -e /etc/modules-load.d/hv_sock.conf ]; then | |
echo "hv_sock" | sudo tee -a /etc/modules-load.d/hv_sock.conf > /dev/null | |
fi | |
# reconfigure the service | |
if [ $first_process = 'systemd' ]; then | |
sudo systemctl daemon-reload | |
sudo systemctl start xrdp | |
elif [ $first_process = 'init' ]; then | |
sudo service xrdp force-reload | |
fi | |
echo "XRDP installation completed" | |
} | |
############################################################################### | |
# Build and setup PulseAudio module for XRDP on MX Linux | |
# | |
audio_drivers() | |
{ | |
sudo apt install -y build-essential dpkg-dev libpulse-dev git autoconf automake libtool libltdl-dev | |
git clone https://github.com/neutrinolabs/pulseaudio-module-xrdp.git | |
cd pulseaudio-module-xrdp | |
scripts/install_pulseaudio_sources_apt_wrapper.sh | |
./bootstrap && ./configure PULSE_DIR=$HOME/pulseaudio.src | |
make | |
sudo make install | |
cd ~ | |
rm -rf ~/pulseaudio* | |
echo "PulseAudio drivers installation completed" | |
} | |
############################################################################### | |
# Configure the policy xrdp session | |
# | |
polkit() | |
{ | |
git clone https://github.com/matt335672/pk-local | |
cd pk-local | |
if [ ! $(getent group pk-local) ]; then | |
sudo addgroup pk-local | |
fi | |
if [ ! $(getent group pk-local | grep -w $(logname)) ]; then | |
echo "Adding $(logname) to group pk-local" | |
sudo usermod -aG pk-local $(logname) | |
fi | |
sudo ./setup-pk-local --enable | |
cd ~ | |
rm -rf ~/pk-local | |
echo "XRDP session policy configured" | |
} | |
# | |
# End | |
############################################################################### | |
############################################################################### | |
# Main script | |
# | |
xrdp | |
echo "" | |
echo -n "Do you want to install audio drivers? [Yy | Nn] " | |
read response | |
if [ `echo $response | tr 'a-z' 'A-Z'` = 'Y' ]; then | |
audio_drivers | |
fi | |
echo "" | |
echo -n "Do you want to configure the xrdp policy? [Yy | Nn] | |
NOTE: Select 'Yy' ONLY is you understand the consequences of this action | |
Read about it at https://github.com/matt335672/pk-local before you preceed " | |
read response | |
if [ `echo $response | tr 'a-z' 'A-Z'` = 'Y' ]; then | |
polkit | |
fi | |
sudo apt autoremove -y | |
echo "" | |
echo "Please turn off your VM Machine and execute 'Set-VM -VMName \"<Name>\" -EnhancedSessionTransportType HvSocket' in PowerShell Admin and turn on again your VM Machine" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment