#!/bin/bash # x11vnc option '-noxrecord' added as workaround for crashing bug # See https://github.com/LibVNC/x11vnc/issues/61 # # The option is not be needed with latest x11vnc from source, but we don't rely # on the remote side being up to date. ssh() { command ssh "$@" 2>&1 | sed 's/^/REMOTE> /' } direct_connection() { port=$((5900 + ${local_display#*:})) ssh -o ControlPath=none -n \ -L $port:localhost:$port \ ${remote_port:+-p $remote_port} \ "$remote_host" \ "x11vnc -noxrecord -nopw -ncache -ncache_cr -localhost -display ${remote_display}" & pid=$! sleep 1 # surrender race xvncviewer -encodings "copyrect tight zrle hextile" localhost:0 kill $pid } share_display() { if [ "$DEBUG" ] then set -x fi port=5500 while fuser -vk $port/tcp do sleep 0.1 done x11vnc -noxrecord -q -nopw -ncache -ncache_cr -localhost -display "${local_display}" -rfbport "$port" & X11VNC=$! trap 'if [ ! "$DEBUG" ]; then exec 2>/dev/null; fi; set -- "$X11VNC" "$SSH"; ps hu "$@"; kill "$@"' EXIT while ! fuser -v $port/tcp do [ -e /proc/"$X11VNC" ] || break sleep 0.1 done # TODO: spin waiting for port 5500 ssh -n \ ${remote_port:+ -p "$remote_port" } \ "$remote_host" \ "fuser -vk $port/tcp && sleep 1" ssh -n \ -o ControlPath=none \ -o ExitOnForwardFailure=yes \ -R "localhost:$port:localhost:$port" \ ${remote_port:+ -p "$remote_port" } \ "$remote_host" \ "DISPLAY=${remote_display} xvncviewer localhost:$port" 2>&1 & SSH=$! wait -n } if [ "$1" = -r ] then shift cmd=share_display elif [ "$1" = -d ] then shift cmd=direct_connection else cmd=direct_connection fi remote_host=${1:-blackboard} case "$remote_host" in *:*) remote_port=${remote_host##*:} remote_host=${remote_host%:*} ;; *) remote_port= ;; esac remote_display=${2:-:0} local_display=${3:-:0} $cmd