dotfiles/config/scripts/tunnel

25 lines
614 B
Plaintext
Raw Normal View History

2016-11-20 13:34:48 +00:00
#!/usr/bin/env bash
# Dynamically determines if the ssh connection
# is to be proxied through `proxytunnel`
# To be used with ssh_config ProxyCommand
2016-11-20 13:34:48 +00:00
host="$1"
port="$2"
2016-11-20 13:34:48 +00:00
if [ -z "$http_proxy" ]; then
2018-11-24 12:45:14 +00:00
socat "TCP:$host:$port" -
2016-11-20 13:34:48 +00:00
else
2016-11-20 17:34:53 +00:00
proxy=$(echo "$http_proxy" | sed 's/^https\?:\/\///' | sed 's/\/$//')
2016-11-20 13:34:48 +00:00
port=443 # Most won't want this
echo "$proxy" | grep '@'
if [ $? == 0 ]; then
user=$(echo $proxy | cut -d '@' -f 2)
proxy=$(echo $proxy | cut -d '@' -f 1)
proxytunnel -p $proxy -P $user -d $host:$port
else
proxytunnel -p $proxy -d $host:$port
fi
fi
2016-02-19 12:46:26 +00:00