aboutsummaryrefslogtreecommitdiff
path: root/local/bin/sshvnc
blob: fcee459bd703bcba8009377764a160c3ac9410e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env bash
set -eu

target="$1"

localport="5901"
while lsof -i:$localport; do
	localport=$((localport + 1))
done

ssh -L "$localport":localhost:5900 "$target" \
	'start-stop-daemon -v -w 1000 -bmp "/var/run/user/$(id -u)/sshvnc.pid" -e WAYLAND_DISPLAY=wayland-1 -S wayvnc localhost 5900'

vncviewer "localhost:$localport"

ssh "$target" 'start-stop-daemon -v -p /var/run/user/$(id -u)/sshvnc.pid -K wayvnc'
ssh -O cancel -L "$localport":localhost:5900 "$target"