From 45556aef4dcc1ae78bbe68bc4842703d26f4763a Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 18 Sep 2019 13:11:45 -0400 Subject: xvnc: add option -r to share local display to remote side --- dot/local/bin/xvnc | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'dot/local/bin/xvnc') diff --git a/dot/local/bin/xvnc b/dot/local/bin/xvnc index 951c079..9bc982b 100755 --- a/dot/local/bin/xvnc +++ b/dot/local/bin/xvnc @@ -1,33 +1,57 @@ #!/bin/sh -remote_host=${1:-blackboard} -remote_display=${2:-:0} -local_display=${3:-0} direct_connection() { port=$((5900 + local_display)) ssh -o ControlPath=none -n \ - -L $port:localhost:$port "$remote_host" 'x11vnc -nopw -ncache -ncache_cr -localhost -display :0' & + -L $port:localhost:$port "$remote_host" "x11vnc -nopw -ncache -ncache_cr -localhost -display ${remote_display}" & pid=$! sleep 1 # surrender race xvncviewer -encodings "copyrect tight zrle hextile" localhost:0 kill $pid } +quietly() +{ + "$@" >/dev/null 2>&1 +} + reverse_connection() { port=5500 xvncviewer -fullscreen -encodings "copyrect tight zrle hextile" -listen & pid=$! - ssh -o ControlPath=none \ - -R $port:localhost:$port "$remote_host" \ - "x11vnc -nopw -localhost -display ${remote_display} -coe localhost:$port -rfbport 0" \ - >/dev/null 2>&1 + quietly ssh -o ControlPath=none \ + -R $port:localhost:$port "$remote_host" \ + "x11vnc -q -nopw -localhost -display ${remote_display} -coe localhost:$port -rfbport 0" kill $pid } -if [ "$USE_DIRECT_CONNECTION" ]; then - direct_connection +share_display() +{ + set -x + port=5500 + fuser -vk $port/tcp + ssh -o ControlPath=none \ + -o ExitOnForwardFailure=yes \ + -f \ + -L $port:localhost:$port "$remote_host" \ + "fuser -vk $port/tcp; DISPLAY=${remote_display} xvncviewer -fullscreen -encodings 'copyrect tight zrle hextile' -listen" + trap "fuser -vk $port/tcp" INT + sleep 1 + x11vnc -q -nopw -localhost -display ${local_display} -coe localhost:$port -rfbport 0 +} + +if [ "$1" = -r ] +then + shift + cmd=share_display else - reverse_connection + cmd=reverse_connection fi + +remote_host=${1:-blackboard} +remote_display=${2:-:0} +local_display=${3:-:0} + +$cmd -- cgit v1.2.3