debian-forge-composer/test/cases/shared_lib.sh
Tomáš Hozza b010a855f6 test/shared_lib.sh: make *print functions print to stderr
This will allow using them inside Bash function that return values,
without tainting the returned value.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
2025-04-01 08:40:13 +02:00

47 lines
1 KiB
Bash
Executable file

#!/usr/bin/bash
function nvrGreaterOrEqual {
local rpm_name=$1
local min_version=$2
set +e
rpm_version=$(rpm -q --qf "%{version}" "${rpm_name}")
rpmdev-vercmp "${rpm_version}" "${min_version}" 1>&2
if [ "$?" != "12" ]; then
# 0 - rpm_version == min_version
# 11 - rpm_version > min_version
# 12 - rpm_version < min_version
echo "DEBUG: ${rpm_version} >= ${min_version}" 1>&2
set -e
return
fi
set -e
false
}
function get_build_info() {
local key="$1"
local fname="$2"
if rpm -q --quiet weldr-client; then
key=".body${key}"
if nvrGreaterOrEqual "weldr-client" "35.6" 2> /dev/null; then
key=".[0]${key}"
fi
fi
jq -r "${key}" "${fname}"
}
# Colorful timestamped output.
function greenprint {
echo -e "\033[1;32m[$(date -Isecond)] ${1}\033[0m" >&2
}
function yellowprint {
echo -e "\033[1;33m[$(date -Isecond)] ${1}\033[0m" >&2
}
function redprint {
echo -e "\033[1;31m[$(date -Isecond)] ${1}\033[0m" >&2
}