From d50c3847192acbb3a5be68b67320fd1819fa81fb Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Tue, 20 Aug 2024 20:42:16 -0300 Subject: Initial import --- vnc | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 vnc (limited to 'vnc') diff --git a/vnc b/vnc new file mode 100755 index 0000000..94ce3d6 --- /dev/null +++ b/vnc @@ -0,0 +1,80 @@ +#!/bin/bash +# +# Wrapper around ssh and vncviewer +# + +# Parameters +BASENAME="`basename $0`" +SERVER="$1" +LOCALPORT="${2:-5901}" +REMOTEPORT="${3:-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 [localport] [remoteport]" + cat <:~/.vnc/passwd ~/.vnc/.passwd # copy the secret + $BASENAME # use our magic script to do everything else + +EOF + + exit 1 +} + +# Usage +if [ "$1" == "--help" ]; then + usage +fi + +# Check +if [ -z "$SERVER" ]; then + if [ -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 $SERVER < /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 $SERVER sleep 10 + +# Run VNC client +# Copy $SERVER:~/.vnc/passwd into $HOME/.vnc/$SERVER.passwd for passwordless login +if [ -e "$HOME/.vnc/$SERVER.passwd" ]; then + vncviewer $VIEWER_OPTS -passwd $HOME/.vnc/$SERVER.passwd localhost:$LOCALPORT +else + vncviewer $VIEWER_OPTS localhost:$LOCALPORT +fi -- cgit v1.2.3