# SPDX-License-Identifier: MIT declare -A options PREFIX=============== VERBOSE=false DEBUG=false : ${EXIT_ON_ERROR:=true} : ${TMPDIR:=$(mktemp -d)} function debug() { DEBUG=true set -x PS4='${BASH_SOURCE[0]}:$LINENO: ${FUNCNAME[0]}: ' } function verbose() { VERBOSE=true } function log() { echo "$@" >&2 } function log_error() { log "$@" } function log_verbose() { if $VERBOSE ; then log "$@" fi } function log_info() { echo "$PREFIX $@" } function fatal_error() { log_error "$@" if $EXIT_ON_ERROR ; then exit 1 else return 1 fi } function stash_debug() { echo start $SELF mkdir -p $TMPDIR > $TMPDIR/run.out tail --follow $TMPDIR/run.out | sed --unbuffered -n -e "/^$PREFIX/s/^$PREFIX //p" & pid=$! if ! $SELF --debug "$@" >& $TMPDIR/run.out ; then kill $pid cat $TMPDIR/run.out echo fail $SELF return 1 fi kill $pid echo success $SELF } function host_port() { local url="$1" local host_port="${url##http*://}" echo ${host_port%%/} }