Skip to content

Instantly share code, notes, and snippets.

@unique-EJ
Last active August 16, 2024 05:18
Show Gist options
  • Select an option

  • Save unique-EJ/3e6142d8c1540f191866baf7b6c98b4d to your computer and use it in GitHub Desktop.

Select an option

Save unique-EJ/3e6142d8c1540f191866baf7b6c98b4d to your computer and use it in GitHub Desktop.
Start application, and X server, on a remote machine (SSH).
# Start application, and X server, on a remote machine (SSH).
# ". Xserver.sh [app name]", "pgrep [app name]"
if [ $# -ge 1 ]; then
app="$@" # The positional parameters (app).
session="startlxde-pi"
commands="\
cd /tmp/; mkfifo -m 607 .command;
env echo -e \"declare DISPLAY=:0; \$(which ${session}) &
${app}\" > .command &
env echo \"starting X server and app, ${app}\"
xinit \$(which sudo) --user='$(logname)' --login source \$(env pwd -P)/.command\
-- :0 || exit 1;
rm .command /tmp/.Xserver;"
cd /tmp/ || exit 1; mkfifo -m 607 .Xserver # named pipe
env echo -e "${commands}" > .Xserver &
# Switch to new virtual terminal, start program.
# shellcheck disable=SC2086
sudo openvt -l -s -- "$(which sudo)" --login -- source /tmp/.Xserver
cd -
fi
@unique-EJ
Copy link
Author

unique-EJ commented May 13, 2023

To get the SSH client IP address, do "${SSH_CONNECTION%% *}" - remote control/connect to device?
Switch to a Virtual Terminal in use (forced):

  • declare DISPLAY=:0; sudo openvt -f --console=1 -s -- $(which sudo) -u $(logname) -i env sleep 2
  • declare DISPLAY=:0; sudo openvt -f --console=1 -s -- $(which sudo) -u $(logname) -i exit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment