Skip to content

Commit

Permalink
add bin/ssh-proxy-home
Browse files Browse the repository at this point in the history
  • Loading branch information
sorah committed May 6, 2015
1 parent 9853d04 commit f872144
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions bin/ssh-proxy-home
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
sorah_ssh_port="$(grep '^# sorah_ssh_port: ' ~/.ssh/config|awk '{print $3}')"
if [ -z "${sorah_ssh_port}" ]; then
echo "specify '# sorah_ssh_port: ' in ~/.ssh/config" 1>&2
exit 1
fi

if dig +nonssearch +noall +comments her|grep -q NOERROR; then
if dig +short livermore.sorah.me | grep -q '^10\.'; then
# home
nw=home
else
# vpn
nw=vpn
fi
else
# external
nw=external
fi

if [ -n "$1" -a -n "$2" ]; then
host="$1"
port="$2"
fi

case "${nw}" in
home)
if [ -z "${host}" ]; then
host=oakland.her
port=${sorah_ssh_port}
fi

exec nc "${host}" "${port}"
;;
vpn)
if [ -z "${host}" ]; then
host=boston.her
port=${sorah_ssh_port}
fi

exec nc "${host}" "${port}"
;;
external)
if [ -z "${host}" ]; then
exec nc boston.sorah.me ${sorah_ssh_port}
else
exec ssh boston.sorah.me -W "${host}:${port}"
fi
;;
esac

0 comments on commit f872144

Please sign in to comment.