diff options
Diffstat (limited to 'vnc')
-rwxr-xr-x | vnc | 26 |
1 files changed, 17 insertions, 9 deletions
@@ -6,8 +6,9 @@ # Parameters BASENAME="`basename $0`" SERVER="$1" -LOCALPORT="${2:-5901}" -REMOTEPORT="${3:-5901}" +REMOTEUSER="$2" +LOCALPORT="${3:-5901}" +REMOTEPORT="${4:-5901}" # Clipboard options # In practice, clipboard limitations are not working as expected @@ -16,7 +17,7 @@ REMOTEPORT="${3:-5901}" VIEWER_OPTS="-AcceptClipboard=off -SendClipboard=off -SetPrimary=off -SendPrimary=off" function usage { - echo "usage: $BASENAME <server> [localport] [remoteport]" + echo "usage: $BASENAME <server> [user] [localport] [remoteport]" cat <<EOF setup instructions @@ -42,9 +43,16 @@ if [ "$1" == "--help" ]; then usage fi -# Check +# Set user +if [ -z "$REMOTEUSER" ]; then + REMOTEUSER="`whoami`" +fi + +# Set config if [ -z "$SERVER" ]; then - if [ -h "$HOME/.vnc/default.passwd" ]; 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 @@ -52,7 +60,7 @@ if [ -z "$SERVER" ]; then fi # Check if vncserver is running in the remote server and start otherwise -ssh $SERVER <<EOF +ssh $REMOTEUSER@$SERVER <<EOF HOSTNAME="\$(cat /etc/hostname)" if [ -e "\$HOME/.vnc/\$HOSTNAME:1.pid" ]; then @@ -69,12 +77,12 @@ 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 +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/$SERVER.passwd" ]; then - vncviewer $VIEWER_OPTS -passwd $HOME/.vnc/$SERVER.passwd localhost:$LOCALPORT +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 |