aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2024-09-04 13:49:47 -0300
committerSilvio Rhatto <rhatto@riseup.net>2024-09-04 13:49:47 -0300
commitc7cdbd4442b0ae8289a6715755af161fbae204a4 (patch)
tree705141125927bb4e735db30fbfbb3c06e3095284
parentd50c3847192acbb3a5be68b67320fd1819fa81fb (diff)
downloadutils-cli-main.tar.gz
utils-cli-main.tar.bz2
Fix: vnc: support for multiple usersmain
-rwxr-xr-xvnc26
1 files changed, 17 insertions, 9 deletions
diff --git a/vnc b/vnc
index 94ce3d6..a5d9a28 100755
--- a/vnc
+++ b/vnc
@@ -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