diff options
Diffstat (limited to 'dot/local/bin/xvnc')
-rwxr-xr-x | dot/local/bin/xvnc | 46 |
1 files changed, 35 insertions, 11 deletions
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 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | remote_host=${1:-blackboard} | ||
3 | remote_display=${2:-:0} | ||
4 | local_display=${3:-0} | ||
5 | 2 | ||
6 | direct_connection() | 3 | direct_connection() |
7 | { | 4 | { |
8 | port=$((5900 + local_display)) | 5 | port=$((5900 + local_display)) |
9 | ssh -o ControlPath=none -n \ | 6 | ssh -o ControlPath=none -n \ |
10 | -L $port:localhost:$port "$remote_host" 'x11vnc -nopw -ncache -ncache_cr -localhost -display :0' & | 7 | -L $port:localhost:$port "$remote_host" "x11vnc -nopw -ncache -ncache_cr -localhost -display ${remote_display}" & |
11 | pid=$! | 8 | pid=$! |
12 | sleep 1 # surrender race | 9 | sleep 1 # surrender race |
13 | xvncviewer -encodings "copyrect tight zrle hextile" localhost:0 | 10 | xvncviewer -encodings "copyrect tight zrle hextile" localhost:0 |
14 | kill $pid | 11 | kill $pid |
15 | } | 12 | } |
16 | 13 | ||
14 | quietly() | ||
15 | { | ||
16 | "$@" >/dev/null 2>&1 | ||
17 | } | ||
18 | |||
17 | reverse_connection() | 19 | reverse_connection() |
18 | { | 20 | { |
19 | port=5500 | 21 | port=5500 |
20 | xvncviewer -fullscreen -encodings "copyrect tight zrle hextile" -listen & | 22 | xvncviewer -fullscreen -encodings "copyrect tight zrle hextile" -listen & |
21 | pid=$! | 23 | pid=$! |
22 | ssh -o ControlPath=none \ | 24 | quietly ssh -o ControlPath=none \ |
23 | -R $port:localhost:$port "$remote_host" \ | 25 | -R $port:localhost:$port "$remote_host" \ |
24 | "x11vnc -nopw -localhost -display ${remote_display} -coe localhost:$port -rfbport 0" \ | 26 | "x11vnc -q -nopw -localhost -display ${remote_display} -coe localhost:$port -rfbport 0" |
25 | >/dev/null 2>&1 | ||
26 | kill $pid | 27 | kill $pid |
27 | } | 28 | } |
28 | 29 | ||
29 | if [ "$USE_DIRECT_CONNECTION" ]; then | 30 | share_display() |
30 | direct_connection | 31 | { |
32 | set -x | ||
33 | port=5500 | ||
34 | fuser -vk $port/tcp | ||
35 | ssh -o ControlPath=none \ | ||
36 | -o ExitOnForwardFailure=yes \ | ||
37 | -f \ | ||
38 | -L $port:localhost:$port "$remote_host" \ | ||
39 | "fuser -vk $port/tcp; DISPLAY=${remote_display} xvncviewer -fullscreen -encodings 'copyrect tight zrle hextile' -listen" | ||
40 | trap "fuser -vk $port/tcp" INT | ||
41 | sleep 1 | ||
42 | x11vnc -q -nopw -localhost -display ${local_display} -coe localhost:$port -rfbport 0 | ||
43 | } | ||
44 | |||
45 | if [ "$1" = -r ] | ||
46 | then | ||
47 | shift | ||
48 | cmd=share_display | ||
31 | else | 49 | else |
32 | reverse_connection | 50 | cmd=reverse_connection |
33 | fi | 51 | fi |
52 | |||
53 | remote_host=${1:-blackboard} | ||
54 | remote_display=${2:-:0} | ||
55 | local_display=${3:-:0} | ||
56 | |||
57 | $cmd | ||