Created
February 15, 2023 20:03
-
-
Save hrko/c7d0933bd327a3b989140a5cf358ab9e to your computer and use it in GitHub Desktop.
Small script to get the display started by XRDP. This is useful when you want to launch GUI apps from SSH on the XRDP session.
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/bash | |
# find session ids for current user | |
SESSION_IDS=$(loginctl list-sessions -o json | jq -r '.[] | select(.user == "'"$USER"'") | .session') | |
# find XRDP sessions | |
XRDP_SESSION_IDS=() | |
for item in $SESSION_IDS; do | |
SERVICE=$(loginctl show-session -P Service "${item}") | |
if [[ $SERVICE == "xrdp-sesman" ]]; then | |
XRDP_SESSION_IDS+=("${item}") | |
fi | |
done | |
# find active XRDP sessions | |
ACTIVE_XRDP_SESSION_IDS=() | |
for item in "${XRDP_SESSION_IDS[@]}"; do | |
STATE=$(loginctl show-session -P Active "${item}") | |
if [[ $STATE == "yes" ]]; then | |
ACTIVE_XRDP_SESSION_IDS+=("${item}") | |
fi | |
done | |
# if there is no active XRDP session, exit | |
if [[ ${#ACTIVE_XRDP_SESSION_IDS[@]} -eq 0 ]]; then | |
echo "ERROR: No active XRDP session found." >&2 | |
exit 1 | |
fi | |
# if there are multiple active XRDP sessions, exit | |
if [[ ${#ACTIVE_XRDP_SESSION_IDS[@]} -gt 1 ]]; then | |
echo "ERROR: Multiple active XRDP sessions found." >&2 | |
exit 1 | |
fi | |
# get the active XRDP session id | |
ACTIVE_XRDP_SESSION_ID="${ACTIVE_XRDP_SESSION_IDS[0]}" | |
echo "INFO: Active XRDP session id: ${ACTIVE_XRDP_SESSION_ID}" >&2 | |
# print export command to eval | |
DISPLAY=$(loginctl show-session -P Display "${ACTIVE_XRDP_SESSION_ID}") | |
echo "export DISPLAY=${DISPLAY}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment