aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2022-07-14 14:50:08 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2022-07-14 14:50:16 -0400
commitca722ae27d1cbdb602b5077e6e3218ff14c32599 (patch)
treefbf85cc61b6cbc5bba4ea7f5289234f7b88136f1
parent33f1f213a304ac8d19ecb5c38e9cde8f33a39356 (diff)
downloadjupyter_safe_port-ca722ae27d1cbdb602b5077e6e3218ff14c32599.tar.gz
Avoid using SSH on localhost
-rwxr-xr-xbin/jupyter_safe_port21
1 files changed, 13 insertions, 8 deletions
diff --git a/bin/jupyter_safe_port b/bin/jupyter_safe_port
index ced6ce1..91981c0 100755
--- a/bin/jupyter_safe_port
+++ b/bin/jupyter_safe_port
@@ -94,17 +94,22 @@ elif (( port_remote_begin < $PORT_MIN )) || (( port_remote_begin > $PORT_MAX ));
exit 1
fi
-# Execute the port test script on the remote host
-port_remote=$(cat $(which next_tcp_port) | ssh $server "bash -s -- $port_remote_begin $port_remote_end")
-if (( $? )); then
- echo "error: $server: connection failed" >&2
- exit 1
-fi
-
# Handle nonsensical host request (i.e. remote host is the local host)
# You can't bind to the same port twice
-if [[ $(hostname) =~ $server ]] && (( port_remote == port_local_begin )); then
+# And there's no reason to use ssh to obtain the port information either
+if [[ $(hostname) =~ $server ]] || [[ $server == "localhost"* ]]; then
+ # Adjust local port to avoid collision with "remote" port
(( port_local_begin++ ))
+
+ # Execute the port test script on the local host
+ port_remote=$(next_tcp_port $port_remote_begin $port_remote_end)
+ if (( $? )); then
+ echo "error: $server: connection failed" >&2
+ exit 1
+ fi
+else
+ # Execute the port test script on the remote host
+ port_remote=$(cat $(which next_tcp_port) | ssh $server "bash -s -- $port_remote_begin $port_remote_end")
fi
port_local=$(next_tcp_port $port_local_begin)