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
TIMEOUT=15
QUIET=0
WAITFOR_TIMEOUT=15
WAITFOR_QUIET=0
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() {
@ -13,15 +13,15 @@ usage() {
Usage:
$0 host:port [-t timeout] [-- command args]
-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
USAGE
exit "$exitcode"
}
wait_for() {
for _ in $(seq $TIMEOUT) ; do
nc -z "$HOST" "$PORT" > /dev/null 2>&1
for _ in $(seq $WAITFOR_TIMEOUT) ; do
nc -z "$WAITFOR_HOST" "$WAITFOR_PORT" > /dev/null 2>&1
result=$?
if [ $result -eq 0 ] ; then
@ -40,21 +40,21 @@ while [ $# -gt 0 ]
do
case "$1" in
*:* )
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
WAITFOR_HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
WAITFOR_PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
shift 1
;;
-q | --quiet)
QUIET=1
WAITFOR_QUIET=1
shift 1
;;
-t)
TIMEOUT="$2"
if [ "$TIMEOUT" = "" ]; then break; fi
WAITFOR_TIMEOUT="$2"
if [ "$WAITFOR_TIMEOUT" = "" ]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
WAITFOR_TIMEOUT="${1#*=}"
shift 1
;;
--)
@ -76,7 +76,7 @@ if ! [ -x "$(command -v nc)" ]; then
exit 1
fi
if [ "$HOST" = "" ] || [ "$PORT" = "" ]; then
if [ "$WAITFOR_HOST" = "" ] || [ "$WAITFOR_PORT" = "" ]; then
echoerr "Error: you need to provide a host and port to test."
usage 2
fi