|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# |
| 4 | +# This script is for openSUSE Tumbleweed Linux to configure XRDP for enhanced session mode |
| 5 | +# |
| 6 | +# The confioguration is adapted from the Arch script. |
| 7 | +# |
| 8 | + |
| 9 | +# Set desktop environment, used later to change SESSION="*****" in /etc/xrdp/starwm.sh |
| 10 | +desktop_env=gnome |
| 11 | +# Change to kde if --kde passed |
| 12 | +if [ $# -gt 0 ] && [ $1 = "--kde" ]; then |
| 13 | + desktop_env=plasma |
| 14 | +fi |
| 15 | + |
| 16 | +############################################################### |
| 17 | +# Install XRDP |
| 18 | +# |
| 19 | +if [ "$(id -u)" -ne 0 ]; then |
| 20 | + echo 'This script must be run with root privileges' >&2 |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# Use rpm -q to check for exact package name, install if missing |
| 25 | +if ! rpm -q xrdp 2>&1 > /dev/null ; then |
| 26 | + echo 'Refreshing repo cache' |
| 27 | + zypper refresh |
| 28 | + echo 'Installing missing xrdp package using zypper' |
| 29 | + zypper -n install xrdp |
| 30 | +fi |
| 31 | + |
| 32 | +############################################################### |
| 33 | +# Configure XRDP |
| 34 | +# |
| 35 | +systemctl enable xrdp |
| 36 | +systemctl enable xrdp-sesman |
| 37 | + |
| 38 | +XRDP_INI_FILE=/etc/xrdp/xrdp.ini |
| 39 | +XRDP_INI_BAK_FILE=$XRDP_INI_FILE.enh_sess_orig.bak |
| 40 | +# Create backup of original XRDP ini file |
| 41 | +if [ ! -f "$XRDP_INI_BAK_FILE" ]; then |
| 42 | + cp $XRDP_INI_FILE $XRDP_INI_BAK_FILE |
| 43 | + echo "Original config file saved in $XRDP_INI_BAK_FILE" |
| 44 | +fi |
| 45 | +# Configure the installed XRDP ini files |
| 46 | +# use vsock transport |
| 47 | +sed -i_orig -e 's/port=3389/port=vsock:\/\/-1:3389/g' $XRDP_INI_FILE |
| 48 | +# use rdp security |
| 49 | +sed -i_orig -e 's/security_layer=negotiate/security_layer=rdp/g' $XRDP_INI_FILE |
| 50 | +# remove encryption validation |
| 51 | +sed -i_orig -e 's/crypt_level=high/crypt_level=none/g' $XRDP_INI_FILE |
| 52 | +# disable bitmap compression since its local its much faster |
| 53 | +sed -i_orig -e 's/bitmap_compression=true/bitmap_compression=false/g' $XRDP_INI_FILE |
| 54 | +# |
| 55 | +# sed -n -e 's/max_bpp=32/max_bpp=24/g' $XRDP_INI_FILE |
| 56 | + |
| 57 | +XRDP_SESMAN_INI_FILE=/etc/xrdp/sesman.ini |
| 58 | +# use the default lightdm x display |
| 59 | +sed -i_orig -e 's/X11DisplayOffset=10/X11DisplayOffset=0/g' $XRDP_SESMAN_INI_FILE |
| 60 | +# rename the redirected drives to 'shared-drives' |
| 61 | +sed -i_orig -e 's/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g' $XRDP_SESMAN_INI_FILE |
| 62 | + |
| 63 | +# adjust startwm.sh (this is needed only in Leap, not needed in Tumbleweed) |
| 64 | +if [ "$(grep -e 'SESSION=".*"' /etc/xrdp/startwm.sh)" ]; then |
| 65 | + sed -i_orig -e "s/SESSION=\".*\"/SESSION=\"$desktop_env\"/g" /etc/xrdp/startwm.sh |
| 66 | + echo "Changed session to '${desktop_env^^}'" |
| 67 | +fi |
| 68 | + |
| 69 | +# Change the allowed_users |
| 70 | +echo "allowed_users=anybody" > /etc/X11/Xwrapper.config |
| 71 | + |
| 72 | +# Ensure hv_sock gets loaded |
| 73 | +if [ ! -e /etc/modules-load.d/hv_sock.conf ]; then |
| 74 | + echo "hv_sock" > /etc/modules-load.d/hv_sock.conf |
| 75 | +fi |
| 76 | + |
| 77 | +# Configure the policy xrdp session |
| 78 | +cat > /etc/polkit-1/rules.d/02-allow-colord.rules <<EOF |
| 79 | +polkit.addRule(function(action, subject) { |
| 80 | + if ((action.id == "org.freedesktop.color-manager.create-device" || |
| 81 | + action.id == "org.freedesktop.color-manager.modify-profile" || |
| 82 | + action.id == "org.freedesktop.color-manager.delete-device" || |
| 83 | + action.id == "org.freedesktop.color-manager.create-profile" || |
| 84 | + action.id == "org.freedesktop.color-manager.modify-profile" || |
| 85 | + action.id == "org.freedesktop.color-manager.delete-profile") && |
| 86 | + subject.isInGroup("users")) |
| 87 | + { |
| 88 | + return polkit.Result.YES; |
| 89 | + } |
| 90 | +}); |
| 91 | +EOF |
| 92 | + |
| 93 | +# Compile selinux module IF selinux is installed |
| 94 | +if rpm -q selinux 2>&1 > /dev/null ; then |
| 95 | + checkmodule -M -m -o allow-vsock.mod allow-vsock.te |
| 96 | + semodule_package -o allow-vsock.pp -m allow-vsock.mod |
| 97 | + # Install the selinux module! |
| 98 | + semodule -i allow-vsock.pp |
| 99 | +fi |
| 100 | + |
| 101 | +############################################################################### |
| 102 | + |
| 103 | +echo "####### Configuration Done #######" |
| 104 | +echo "Next to do" |
| 105 | +echo "Shutdown this VM" |
| 106 | +echo "On your host machine in an Administrator powershell prompt, execute this command: " |
| 107 | +echo " Set-VM -VMName <your_vm_name> -EnhancedSessionTransportType HvSocket" |
| 108 | +echo "Start this VM, and you will see Enhanced mode available!" |
0 commit comments