detects busybox 1.30.0+ with updated timeout flags

Busybox updated timeout's flags to match coreutils.
This broke the script that was specifically dealing
with BusyBox being different from coreutils.

To fix the problem without breaking support for older
versions of busy box, this a version check of busybox
to determine which version of the flags to use.

Note, the changes use bash's regular expression's BASH_REMATCH
to get the job done.  For Alpine users, this means you'll have
to install bash and execute wait-for-it using bash.
pull/81/head
Ian Turgeon 5 years ago
parent 54d1f0bfeb
commit 59bcd4b53e

@ -140,17 +140,23 @@ WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}
WAITFORIT_STRICT=${WAITFORIT_STRICT:-0}
WAITFORIT_CHILD=${WAITFORIT_CHILD:-0}
WAITFORIT_QUIET=${WAITFORIT_QUIET:-0}
# check to see if timeout is from busybox?
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
WAITFORIT_TIMEOUT_PATH=$(type -p timeout)
WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH)
# check to see if we're using busybox?
if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then
WAITFORIT_ISBUSY=1
WAITFORIT_BUSYTIMEFLAG="-t"
WAITFORIT_ISBUSY=1
fi
else
WAITFORIT_ISBUSY=0
WAITFORIT_BUSYTIMEFLAG=""
# see if timeout.c args have been updated in busybox v1.30.0 or newer
# note: this requires the use of bash on Alpine
if [[ $WAITFORIT_ISBUSY && $(busybox | head -1) =~ ^.*v([[:digit:]]+)\.([[:digit:]]+)\..+$ ]]; then
if [[ ${BASH_REMATCH[1]} -le 1 && ${BASH_REMATCH[2]} -lt 30 ]]; then
# using pre 1.30.0 version with `-t SEC` arg
WAITFORIT_BUSYTIMEFLAG="-t"
fi
fi
if [[ $WAITFORIT_CHILD -gt 0 ]]; then

Loading…
Cancel
Save