VOL-595 - container image name consistency and general cleanup

Change-Id: Iccac1ccba61537cefa046118df139196e9e87713
diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base
index 8e5c09b..e087e0f 100644
--- a/docker/Dockerfile.base
+++ b/docker/Dockerfile.base
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +11,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
 
 FROM ubuntu:xenial
 
diff --git a/docker/Dockerfile.base.alpine b/docker/Dockerfile.base.alpine
index ac1d93c..8d04cb1 100644
--- a/docker/Dockerfile.base.alpine
+++ b/docker/Dockerfile.base.alpine
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,8 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
 
-FROM alpine:3.4
+FROM alpine:3.6
 
 MAINTAINER Zsolt Haraszti <zharaszt@ciena.com>
 MAINTAINER Ali Al-Shabibi <ali.al-shabibi@onlab.us>
diff --git a/docker/Dockerfile.cli b/docker/Dockerfile.cli
index 95d5617..0c04759 100755
--- a/docker/Dockerfile.cli
+++ b/docker/Dockerfile.cli
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
+ARG TAG=latest
 
-FROM cord/voltha-base
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Sergio Slobodrian <sslobodr@ciena.com>
 
diff --git a/docker/Dockerfile.configpush b/docker/Dockerfile.configpush
index 895e0ee..f096852 100644
--- a/docker/Dockerfile.configpush
+++ b/docker/Dockerfile.configpush
@@ -1,4 +1,18 @@
-FROM alpine:3.5
+# Copyright 2018 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+FROM alpine:3.6
 
 RUN apk --update add curl
 
diff --git a/docker/Dockerfile.consul b/docker/Dockerfile.consul
index 64f11b2..cd6d0b3 100644
--- a/docker/Dockerfile.consul
+++ b/docker/Dockerfile.consul
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +11,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
 
 FROM consul:0.9.2
 
diff --git a/docker/Dockerfile.dashd b/docker/Dockerfile.dashd
index 74ef2f6..05cf57e 100755
--- a/docker/Dockerfile.dashd
+++ b/docker/Dockerfile.dashd
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
+ARG TAG=latest
 
-FROM cord/voltha-base
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Sergio Slobodrian <sslobodr@ciena.com>
 
diff --git a/docker/Dockerfile.envoy b/docker/Dockerfile.envoy
index afe1977..6484f4b 100644
--- a/docker/Dockerfile.envoy
+++ b/docker/Dockerfile.envoy
@@ -1,3 +1,17 @@
+# Copyright 2018 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 FROM lyft/envoy:29361deae91575a1d46c7a21e913f19e75622ebe
 
 RUN apt-get update && apt-get -q install -y \
diff --git a/docker/Dockerfile.fluentd b/docker/Dockerfile.fluentd
index 4e04a2f..ed5417c 100644
--- a/docker/Dockerfile.fluentd
+++ b/docker/Dockerfile.fluentd
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,14 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
 
 #DockerFile to Create Fluentd Forwards inside cord-voltha
 FROM fluent/fluentd:v0.14.23.rc1
+MAINTAINER Voltha Community <info@opennetworking.org>
+
+RUN apk add --update bash
 COPY fluentd_config/fluent.conf /fluentd/etc/
 COPY fluentd_config/fluent-agg.conf /fluentd/etc/
+COPY docker/config/wait_for_it.sh /bin/wait_for_it.sh
+COPY fluentd_config/entrypoint.sh /bin/entrypoint.sh
+RUN chmod 755 /bin/wait_for_it.sh /bin/entrypoint.sh
diff --git a/docker/Dockerfile.golang b/docker/Dockerfile.golang
index 0b6648c..b23f9e6 100644
--- a/docker/Dockerfile.golang
+++ b/docker/Dockerfile.golang
@@ -1,3 +1,17 @@
+# Copyright 2018 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 FROM golang:1.9.2
 MAINTAINER Alex Peters <info@alexanderpeters.de>
 
diff --git a/docker/Dockerfile.grafana b/docker/Dockerfile.grafana
index d8b2cbf..a821747 100755
--- a/docker/Dockerfile.grafana
+++ b/docker/Dockerfile.grafana
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +11,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
 
 FROM kamon/grafana_graphite:3.0
 
diff --git a/docker/Dockerfile.j2 b/docker/Dockerfile.j2
new file mode 100644
index 0000000..8e6566e
--- /dev/null
+++ b/docker/Dockerfile.j2
@@ -0,0 +1,22 @@
+# Copyright 2017 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+FROM alpine:3.6
+MAINTAINER Voltha Community <info@opennetworking.org>
+
+RUN apk --update add python py-pip
+RUN pip install j2cli
+COPY config/j2_entry_point /j2_entry_point
+RUN chmod 755 /j2_entry_point
+ENTRYPOINT [ "/j2_entry_point" ]
diff --git a/docker/Dockerfile.logstash b/docker/Dockerfile.logstash
index a90ecb0..861b3c0 100644
--- a/docker/Dockerfile.logstash
+++ b/docker/Dockerfile.logstash
@@ -1,3 +1,17 @@
+# Copyright 2018 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Build from latest stable load
 FROM docker.elastic.co/logstash/logstash:5.6.0
 
diff --git a/docker/Dockerfile.netconf b/docker/Dockerfile.netconf
index b46a822..b740aae 100644
--- a/docker/Dockerfile.netconf
+++ b/docker/Dockerfile.netconf
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
+ARG TAG=latest
 
-FROM cord/voltha-base
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Zsolt Haraszti <zharaszt@ciena.com>
 MAINTAINER Ali Al-Shabibi <ali.al-shabibi@onlab.us>
diff --git a/docker/Dockerfile.netopeer b/docker/Dockerfile.netopeer
index 5dc0711..4b31e55 100644
--- a/docker/Dockerfile.netopeer
+++ b/docker/Dockerfile.netopeer
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2017 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +11,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
 
 FROM centos:7
 
diff --git a/docker/Dockerfile.nginx b/docker/Dockerfile.nginx
index 000583a..33b8068 100755
--- a/docker/Dockerfile.nginx
+++ b/docker/Dockerfile.nginx
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
+ARG TAG=latest
 
-FROM cord/voltha-base
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Sergio Slobodrian <sslobodr@ciena.com>
 
diff --git a/docker/Dockerfile.ofagent b/docker/Dockerfile.ofagent
index 20d97dc..733b9df 100644
--- a/docker/Dockerfile.ofagent
+++ b/docker/Dockerfile.ofagent
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
+ARG TAG=latest
 
-FROM cord/voltha-base
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Zsolt Haraszti <zharaszt@ciena.com>
 MAINTAINER Ali Al-Shabibi <ali.al-shabibi@onlab.us>
diff --git a/docker/Dockerfile.onos b/docker/Dockerfile.onos
index 528d90b..6d8ce41 100644
--- a/docker/Dockerfile.onos
+++ b/docker/Dockerfile.onos
@@ -1,3 +1,17 @@
+# Copyright 2018 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 FROM maven:3-jdk-8-alpine as download
 MAINTAINER Open Networking Foundation <info@opennetworking.org>
 
diff --git a/docker/Dockerfile.opennms b/docker/Dockerfile.opennms
index 31233ef..5a45fce 100644
--- a/docker/Dockerfile.opennms
+++ b/docker/Dockerfile.opennms
@@ -1,3 +1,17 @@
+# Copyright 2018 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 # Build from latest stable load
 FROM opennms/horizon-core-web:19.0.1-1
 
diff --git a/docker/Dockerfile.portainer b/docker/Dockerfile.portainer
index e3a894f..0e17188 100644
--- a/docker/Dockerfile.portainer
+++ b/docker/Dockerfile.portainer
@@ -1,3 +1,17 @@
+# Copyright 2018 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
 FROM centurylink/ca-certs
 
 COPY tmp_portainer /
diff --git a/docker/Dockerfile.registrator b/docker/Dockerfile.registrator
index 219cc4d..940449e 100644
--- a/docker/Dockerfile.registrator
+++ b/docker/Dockerfile.registrator
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,7 +11,6 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
 
 FROM gliderlabs/registrator:v7
 
diff --git a/docker/Dockerfile.shovel b/docker/Dockerfile.shovel
index 7270e20..3a411fb 100644
--- a/docker/Dockerfile.shovel
+++ b/docker/Dockerfile.shovel
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
+ARG TAG=latest
 
-FROM cord/voltha-base
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Zsolt Haraszti <zharaszt@ciena.com>
 MAINTAINER Ali Al-Shabibi <ali.al-shabibi@onlab.us>
diff --git a/docker/Dockerfile.tester b/docker/Dockerfile.tester
index 617ef13..a9b1a10 100644
--- a/docker/Dockerfile.tester
+++ b/docker/Dockerfile.tester
@@ -1,4 +1,20 @@
-FROM cord/voltha-base
+# Copyright 2018 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+ARG TAG=latest
+
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Zsolt Haraszti <zharaszt@ciena.com>
 MAINTAINER Ali Al-Shabibi <ali.al-shabibi@onlab.us>
diff --git a/docker/Dockerfile.tools b/docker/Dockerfile.tools
index 5fd0510..168ffee 100755
--- a/docker/Dockerfile.tools
+++ b/docker/Dockerfile.tools
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
+ARG TAG=latest
 
-FROM cord/voltha-base
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Sergio Slobodrian <sslobodr@ciena.com>
 
diff --git a/docker/Dockerfile.voltha b/docker/Dockerfile.voltha
index 6f6ce6f..ece248b 100644
--- a/docker/Dockerfile.voltha
+++ b/docker/Dockerfile.voltha
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
 # Copyright 2016 the original author or authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,9 +11,9 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
+ARG TAG=latest
 
-FROM cord/voltha-base
+FROM voltha/voltha-base:${TAG}
 
 MAINTAINER Zsolt Haraszti <zharaszt@ciena.com>
 MAINTAINER Ali Al-Shabibi <ali.al-shabibi@onlab.us>
diff --git a/docker/config/j2_entry_point b/docker/config/j2_entry_point
new file mode 100644
index 0000000..cb7de93
--- /dev/null
+++ b/docker/config/j2_entry_point
@@ -0,0 +1,24 @@
+#!/bin/ash
+# Copyright 2017 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# enable reading template from stdin
+if [ $1 == "-" ]; then
+    TEMPLATE=$(mktemp -u)
+    cat > $TEMPLATE
+    shift
+    exec j2 $TEMPLATE $*
+else
+    exec j2 $*
+fi
diff --git a/docker/config/wait_for_it.sh b/docker/config/wait_for_it.sh
new file mode 100755
index 0000000..bbe4043
--- /dev/null
+++ b/docker/config/wait_for_it.sh
@@ -0,0 +1,177 @@
+#!/usr/bin/env bash
+#   Use this script to test if a given TCP host/port are available
+
+cmdname=$(basename $0)
+
+echoerr() { if [[ $QUIET -ne 1 ]]; then echo "$@" 1>&2; fi }
+
+usage()
+{
+    cat << USAGE >&2
+Usage:
+    $cmdname host:port [-s] [-t timeout] [-- command args]
+    -h HOST | --host=HOST       Host or IP under test
+    -p PORT | --port=PORT       TCP port under test
+                                Alternatively, you specify the host and port as host:port
+    -s | --strict               Only execute subcommand if the test succeeds
+    -q | --quiet                Don't output any status messages
+    -t TIMEOUT | --timeout=TIMEOUT
+                                Timeout in seconds, zero for no timeout
+    -- COMMAND ARGS             Execute command with args after the test finishes
+USAGE
+    exit 1
+}
+
+wait_for()
+{
+    if [[ $TIMEOUT -gt 0 ]]; then
+        echoerr "$cmdname: waiting $TIMEOUT seconds for $HOST:$PORT"
+    else
+        echoerr "$cmdname: waiting for $HOST:$PORT without a timeout"
+    fi
+    start_ts=$(date +%s)
+    while :
+    do
+        if [[ $ISBUSY -eq 1 ]]; then
+            nc -z $HOST $PORT
+            result=$?
+        else
+            (echo > /dev/tcp/$HOST/$PORT) >/dev/null 2>&1
+            result=$?
+        fi
+        if [[ $result -eq 0 ]]; then
+            end_ts=$(date +%s)
+            echoerr "$cmdname: $HOST:$PORT is available after $((end_ts - start_ts)) seconds"
+            break
+        fi
+        sleep 1
+    done
+    return $result
+}
+
+wait_for_wrapper()
+{
+    # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692
+    if [[ $QUIET -eq 1 ]]; then
+        timeout $BUSYTIMEFLAG $TIMEOUT $0 --quiet --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
+    else
+        timeout $BUSYTIMEFLAG $TIMEOUT $0 --child --host=$HOST --port=$PORT --timeout=$TIMEOUT &
+    fi
+    PID=$!
+    trap "kill -INT -$PID" INT
+    wait $PID
+    RESULT=$?
+    if [[ $RESULT -ne 0 ]]; then
+        echoerr "$cmdname: timeout occurred after waiting $TIMEOUT seconds for $HOST:$PORT"
+    fi
+    return $RESULT
+}
+
+# process arguments
+while [[ $# -gt 0 ]]
+do
+    case "$1" in
+        *:* )
+        hostport=(${1//:/ })
+        HOST=${hostport[0]}
+        PORT=${hostport[1]}
+        shift 1
+        ;;
+        --child)
+        CHILD=1
+        shift 1
+        ;;
+        -q | --quiet)
+        QUIET=1
+        shift 1
+        ;;
+        -s | --strict)
+        STRICT=1
+        shift 1
+        ;;
+        -h)
+        HOST="$2"
+        if [[ $HOST == "" ]]; then break; fi
+        shift 2
+        ;;
+        --host=*)
+        HOST="${1#*=}"
+        shift 1
+        ;;
+        -p)
+        PORT="$2"
+        if [[ $PORT == "" ]]; then break; fi
+        shift 2
+        ;;
+        --port=*)
+        PORT="${1#*=}"
+        shift 1
+        ;;
+        -t)
+        TIMEOUT="$2"
+        if [[ $TIMEOUT == "" ]]; then break; fi
+        shift 2
+        ;;
+        --timeout=*)
+        TIMEOUT="${1#*=}"
+        shift 1
+        ;;
+        --)
+        shift
+        CLI=("$@")
+        break
+        ;;
+        --help)
+        usage
+        ;;
+        *)
+        echoerr "Unknown argument: $1"
+        usage
+        ;;
+    esac
+done
+
+if [[ "$HOST" == "" || "$PORT" == "" ]]; then
+    echoerr "Error: you need to provide a host and port to test."
+    usage
+fi
+
+TIMEOUT=${TIMEOUT:-15}
+STRICT=${STRICT:-0}
+CHILD=${CHILD:-0}
+QUIET=${QUIET:-0}
+
+# check to see if timeout is from busybox?
+# check to see if timeout is from busybox?
+TIMEOUT_PATH=$(realpath $(which timeout))
+if [[ $TIMEOUT_PATH =~ "busybox" ]]; then
+        ISBUSY=1
+        BUSYTIMEFLAG="-t"
+else
+        ISBUSY=0
+        BUSYTIMEFLAG=""
+fi
+
+if [[ $CHILD -gt 0 ]]; then
+    wait_for
+    RESULT=$?
+    exit $RESULT
+else
+    if [[ $TIMEOUT -gt 0 ]]; then
+        wait_for_wrapper
+        RESULT=$?
+    else
+        wait_for
+        RESULT=$?
+    fi
+fi
+
+if [[ $CLI != "" ]]; then
+    if [[ $RESULT -ne 0 && $STRICT -eq 1 ]]; then
+        echoerr "$cmdname: strict mode, refusing to execute subprocess"
+        exit $RESULT
+    fi
+    exec "${CLI[@]}"
+else
+    exit $RESULT
+fi