clean up ssh_proxycommand function (no functional change)
authorJameson Rollins <jrollins@finestructure.net>
Sat, 30 Oct 2010 00:56:25 +0000 (20:56 -0400)
committerJameson Rollins <jrollins@finestructure.net>
Sat, 30 Oct 2010 06:31:08 +0000 (02:31 -0400)
src/share/m/ssh_proxycommand

index 110309ee6ba671575d2df90e380c2db04d0a5b02..3ac70e1dc8865bd99edd3ee8e79122121adfb2c3 100644 (file)
 # 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
-
-}