blob: a5d9a2803cfa0e00f19d4f7259231d37f07cdd7e (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/bin/bash
#
# Wrapper around ssh and vncviewer
#
# Parameters
BASENAME="`basename $0`"
SERVER="$1"
REMOTEUSER="$2"
LOCALPORT="${3:-5901}"
REMOTEPORT="${4:-5901}"
# Clipboard options
# In practice, clipboard limitations are not working as expected
# So please do not use this script if you don't want to automatically share clipboard with the remote system
# This is probably a bug on xtigervncviewer
VIEWER_OPTS="-AcceptClipboard=off -SendClipboard=off -SetPrimary=off -SendPrimary=off"
function usage {
echo "usage: $BASENAME <server> [user] [localport] [remoteport]"
cat <<EOF
setup instructions
==================
* in the remote:
sudo apt install tigervnc-standalone-server # install in the remote server
vncpasswd # generate a ~/.vnc/passwd in the remote server
* in the local box:
scp <server>:~/.vnc/passwd ~/.vnc/<server>.passwd # copy the secret
$BASENAME <server> # use our magic script to do everything else
EOF
exit 1
}
# Usage
if [ "$1" == "--help" ]; then
usage
fi
# Set user
if [ -z "$REMOTEUSER" ]; then
REMOTEUSER="`whoami`"
fi
# Set config
if [ -z "$SERVER" ]; then
if [ -h "$HOME/.vnc/$REMOTEUSER@default.passwd" ]; then
SERVER="$(basename `readlink $HOME/.vnc/$REMOTEUSER@default.passwd` .passwd)"
elif [ -h "$HOME/.vnc/default.passwd" ]; then
SERVER="$(basename `readlink $HOME/.vnc/default.passwd` .passwd)"
else
usage
fi
fi
# Check if vncserver is running in the remote server and start otherwise
ssh $REMOTEUSER@$SERVER <<EOF
HOSTNAME="\$(cat /etc/hostname)"
if [ -e "\$HOME/.vnc/\$HOSTNAME:1.pid" ]; then
PID="\$(cat \$HOME/.vnc/\$HOSTNAME:1.pid)"
if ! ps \$PID &> /dev/null; then
/usr/bin/vncserver -alwaysshared -dpi 96 -localhost :1
fi
else
/usr/bin/vncserver -alwaysshared -dpi 96 -localhost :1
fi
EOF
# See http://www.g-loaded.eu/2006/11/24/auto-closing-ssh-tunnels/
# Optional SSH compression
#ssh -C -c blowfish -f -L 5901:127.0.0.1:5901 $SERVER sleep 10
ssh -f -L $LOCALPORT:127.0.0.1:$REMOTEPORT $REMOTEUSER@$SERVER sleep 10
# Run VNC client
# Copy $SERVER:~/.vnc/passwd into $HOME/.vnc/$SERVER.passwd for passwordless login
if [ -e "$HOME/.vnc/$REMOTEUSER@$SERVER.passwd" ]; then
vncviewer $VIEWER_OPTS -passwd $HOME/.vnc/$REMOTEUSER@$SERVER.passwd localhost:$LOCALPORT
else
vncviewer $VIEWER_OPTS localhost:$LOCALPORT
fi
|