Commit ae0b398b authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Make .ssh/forward more robust

- Removes 'nc' (netcat) as it had a tendency to timeout when idle.
- Searches for more 'python*' interpreters.
- Reduces the number of processes used. (The Python process execs the
  SSH proxy command so the shell can exec Python.)
parent 218c9232
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -117,7 +117,9 @@ def socket_pipe(host, port):
		rlist, wlist, _ = select.select(rlist, wlist, xlist, None)

def main():
	# First two args are host and port to connect to, then the fallback command
	host, port = sys.argv[1:3]
	fallback_cmd = sys.argv[3:]
	try:
		socket_pipe(host, port)
	except IOError as exc:
@@ -125,7 +127,7 @@ def main():
			"Connect to {}:{} failed: {}\n"
			.format(host, port, str(exc))
		)
		sys.exit(1)
		os.execvp(fallback_cmd[0], fallback_cmd)


if __name__ == '__main__':
+16 −6
Original line number Diff line number Diff line
#!/bin/sh
die(){ echo "$*" >&2; exit 1; }
has(){ type $1 >/dev/null 2>/dev/null; }
if has python; then
	python `dirname $0`/connect.py "$@" && exit
elif has nc; then
	nc -w 10 $1 $2 && exit

for PYTHON in python3.7 python3.6 python3.5 python3.4 python3.3 python3
	python2.7 python2 python
do
	if has $PYTHON; then
		break
	fi
done

if ! has $PYTHON; then
	echo >&2 "No python found, falling back immediately to SSH proxy"
	exec ssh -W $1:$2 $3
fi

# First two args: host & port
# Subsequent args: fallback command
exec ${PYTHON} `dirname $0`/connect.py $1 $2 ssh -W $1:$2 $3