cascading-pr/cascading-pr-lib.sh

75 lines
1.1 KiB
Bash
Raw Normal View History

2023-10-11 18:05:11 +02:00
# SPDX-License-Identifier: MIT
declare -A options
2023-10-12 19:13:07 +02:00
PREFIX===============
2023-10-11 18:05:11 +02:00
VERBOSE=false
2023-10-12 15:12:52 +02:00
2023-10-11 18:05:11 +02:00
DEBUG=false
2023-10-12 15:12:52 +02:00
2023-10-11 18:05:11 +02:00
: ${EXIT_ON_ERROR:=true}
2023-10-12 15:12:52 +02:00
: ${TMPDIR:=$(mktemp -d)}
2023-10-11 18:05:11 +02:00
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() {
2023-10-12 19:13:07 +02:00
echo "$PREFIX $@"
2023-10-11 18:05:11 +02:00
}
function fatal_error() {
log_error "$@"
if $EXIT_ON_ERROR ; then
exit 1
else
return 1
fi
}
2023-10-12 19:13:07 +02:00
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
}
2023-10-11 18:05:11 +02:00
function host_port() {
local url="$1"
local host_port="${url##http*://}"
echo ${host_port%%/}
}