prefix env variables

This commit is contained in:
Robert Kaussow 2020-02-03 16:20:00 +01:00
parent 1eca9f9a84
commit bee6e2cf59

View File

@ -1,10 +1,10 @@
#!/bin/sh #!/bin/sh
TIMEOUT=15 WAITFOR_TIMEOUT=15
QUIET=0 WAITFOR_QUIET=0
echoerr() { echoerr() {
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi if [ "$WAITFOR_QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
} }
usage() { usage() {
@ -13,15 +13,15 @@ usage() {
Usage: Usage:
$0 host:port [-t timeout] [-- command args] $0 host:port [-t timeout] [-- command args]
-q | --quiet Do not output any status messages -q | --quiet Do not output any status messages
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout -t WAITFOR_TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes -- COMMAND ARGS Execute command with args after the test finishes
USAGE USAGE
exit "$exitcode" exit "$exitcode"
} }
wait_for() { wait_for() {
for _ in $(seq $TIMEOUT) ; do for _ in $(seq $WAITFOR_TIMEOUT) ; do
nc -z "$HOST" "$PORT" > /dev/null 2>&1 nc -z "$WAITFOR_HOST" "$WAITFOR_PORT" > /dev/null 2>&1
result=$? result=$?
if [ $result -eq 0 ] ; then if [ $result -eq 0 ] ; then
@ -40,21 +40,21 @@ while [ $# -gt 0 ]
do do
case "$1" in case "$1" in
*:* ) *:* )
HOST=$(printf "%s\n" "$1"| cut -d : -f 1) WAITFOR_HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
PORT=$(printf "%s\n" "$1"| cut -d : -f 2) WAITFOR_PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
shift 1 shift 1
;; ;;
-q | --quiet) -q | --quiet)
QUIET=1 WAITFOR_QUIET=1
shift 1 shift 1
;; ;;
-t) -t)
TIMEOUT="$2" WAITFOR_TIMEOUT="$2"
if [ "$TIMEOUT" = "" ]; then break; fi if [ "$WAITFOR_TIMEOUT" = "" ]; then break; fi
shift 2 shift 2
;; ;;
--timeout=*) --timeout=*)
TIMEOUT="${1#*=}" WAITFOR_TIMEOUT="${1#*=}"
shift 1 shift 1
;; ;;
--) --)
@ -76,7 +76,7 @@ if ! [ -x "$(command -v nc)" ]; then
exit 1 exit 1
fi fi
if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then if [ "$WAITFOR_HOST" = "" ] || [ "$WAITFOR_PORT" = "" ]; then
echoerr "Error: you need to provide a host and port to test." echoerr "Error: you need to provide a host and port to test."
usage 2 usage 2
fi fi