summaryrefslogtreecommitdiff
path: root/src/share/m/ssh_proxycommand
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/m/ssh_proxycommand')
-rw-r--r--src/share/m/ssh_proxycommand94
1 files changed, 49 insertions, 45 deletions
diff --git a/src/share/m/ssh_proxycommand b/src/share/m/ssh_proxycommand
index 110309e..3ac70e1 100644
--- a/src/share/m/ssh_proxycommand
+++ b/src/share/m/ssh_proxycommand
@@ -15,6 +15,55 @@
# established. Can be added to ~/.ssh/config as follows:
# ProxyCommand monkeysphere ssh-proxycommand %h %p
+# the ssh proxycommand function itself
+ssh_proxycommand() {
+ local connect='true'
+ local HOST
+ local PORT
+ local HOSTP
+ local URI
+
+ if [[ "$1" == '--no-connect' ]] ; then
+ connect='false'
+ shift 1
+ fi
+
+ HOST="$1"
+ PORT="$2"
+
+ if [ -z "$HOST" ] ; then
+ log error "Host not specified."
+ usage
+ exit 255
+ fi
+ if [ -z "$PORT" ] ; then
+ PORT=22
+ fi
+
+ # set the host URI
+ if [ "$PORT" != '22' ] ; then
+ HOSTP="${HOST}:${PORT}"
+ else
+ HOSTP="${HOST}"
+ fi
+ URI="ssh://${HOSTP}"
+
+ # passed HOST/PORT/HOSTP/URI
+ validate_monkeysphere
+
+ # exec a netcat passthrough to host for the ssh connection
+ if [[ "$connect" == 'true' ]] ; then
+ if (type nc &>/dev/null); then
+ exec nc "$HOST" "$PORT"
+ elif (type socat &>/dev/null); then
+ exec socat STDIO "TCP:$HOST:$PORT"
+ else
+ echo "Neither netcat nor socat found -- could not complete monkeysphere-ssh-proxycommand connection to $HOST:$PORT" >&2
+ exit 255
+ fi
+ fi
+}
+
validate_monkeysphere() {
local hostKey
@@ -266,48 +315,3 @@ EOF
-------------------- ssh continues below --------------------
EOF
}
-
-
-# the ssh proxycommand function itself
-ssh_proxycommand() {
-
-if [ "$1" = '--no-connect' ] ; then
- NO_CONNECT='true'
- shift 1
-fi
-
-HOST="$1"
-PORT="$2"
-
-if [ -z "$HOST" ] ; then
- log error "Host not specified."
- usage
- exit 255
-fi
-if [ -z "$PORT" ] ; then
- PORT=22
-fi
-
-# set the host URI
-if [ "$PORT" != '22' ] ; then
- HOSTP="${HOST}:${PORT}"
-else
- HOSTP="${HOST}"
-fi
-URI="ssh://${HOSTP}"
-
-validate_monkeysphere
-
-# exec a netcat passthrough to host for the ssh connection
-if [ -z "$NO_CONNECT" ] ; then
- if (type nc &>/dev/null); then
- exec nc "$HOST" "$PORT"
- elif (type socat &>/dev/null); then
- exec socat STDIO "TCP:$HOST:$PORT"
- else
- echo "Neither netcat nor socat found -- could not complete monkeysphere-ssh-proxycommand connection to $HOST:$PORT" >&2
- exit 255
- fi
-fi
-
-}