summaryrefslogtreecommitdiff
path: root/dot/local/bin/xvnc
blob: 951c079d14ce3e3df107c37cde3c7bdbebe0f1b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/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' &
    pid=$!
    sleep 1 # surrender race
    xvncviewer -encodings "copyrect tight zrle hextile" localhost:0
    kill $pid
}

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
    kill $pid
}

if [ "$USE_DIRECT_CONNECTION" ]; then
    direct_connection
else
    reverse_connection
fi