common/xbps-src/shutils: add function for printing verbose messages

This commit is contained in:
classabbyamp 2024-02-10 01:47:06 -05:00 committed by classabbyamp
parent bdf562aa27
commit b3c54d73af
2 changed files with 17 additions and 22 deletions

View file

@ -188,6 +188,12 @@ msg_normal() {
fi fi
} }
msg_verbose() {
if [ -n "$XBPS_VERBOSE" ]; then
printf >&2 "$@"
fi
}
report_broken() { report_broken() {
if [ "$show_problems" = "ignore-problems" ]; then if [ "$show_problems" = "ignore-problems" ]; then
return return

View file

@ -8,19 +8,18 @@ update_check() {
local urlpfx urlsfx local urlpfx urlsfx
local -A fetchedurls local -A fetchedurls
# XBPS_UPDATE_CHECK_VERBOSE is the old way to show verbose messages
[ "$XBPS_UPDATE_CHECK_VERBOSE" ] && XBPS_VERBOSE="$XBPS_UPDATE_CHECK_VERBOSE"
if [ -r $update_override ]; then if [ -r $update_override ]; then
. $update_override . $update_override
if [ "$XBPS_UPDATE_CHECK_VERBOSE" ]; then msg_verbose "using $XBPS_TARGET_PKG/update overrides\n"
echo "using $XBPS_TARGET_PKG/update overrides" 1>&2
fi
if [ -n "$disabled" ]; then if [ -n "$disabled" ]; then
echo "update-check DISABLED for $original_pkgname: $disabled" 1>&2 msg_verbose "update-check DISABLED for $original_pkgname: $disabled\n"
return 0 return 0
fi fi
elif [ -z "$distfiles" ]; then elif [ -z "$distfiles" ]; then
if [ "$XBPS_UPDATE_CHECK_VERBOSE" ]; then msg_verbose "NO DISTFILES found for $original_pkgname\n"
echo "NO DISTFILES found for $original_pkgname" 1>&2
fi
return 0 return 0
fi fi
@ -94,9 +93,7 @@ update_check() {
esac esac
if [ "$rx" ]; then if [ "$rx" ]; then
# substitute url if needed # substitute url if needed
if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then msg_verbose "(folder) fetching $urlpfx and scanning with $rx\n"
echo "(folder) fetching $urlpfx and scanning with $rx" 1>&2
fi
skipdirs= skipdirs=
curl -A "xbps-src-update-check/$XBPS_SRC_VERSION" --max-time 10 -Lsk "$urlpfx" | curl -A "xbps-src-update-check/$XBPS_SRC_VERSION" --max-time 10 -Lsk "$urlpfx" |
grep -Po -i "$rx" | grep -Po -i "$rx" |
@ -195,15 +192,11 @@ update_check() {
rx=${rx:-'(?<!-)\b\Q'"$pkgname"'\E[-_]?((src|source)[-_])?v?\K([^-/_\s]*?\d[^-/_\s]*?)(?=(?:[-_.](?:src|source|orig))?\.(?:[jt]ar|shar|t[bglx]z|tbz2|zip))\b'} rx=${rx:-'(?<!-)\b\Q'"$pkgname"'\E[-_]?((src|source)[-_])?v?\K([^-/_\s]*?\d[^-/_\s]*?)(?=(?:[-_.](?:src|source|orig))?\.(?:[jt]ar|shar|t[bglx]z|tbz2|zip))\b'}
if [ "${fetchedurls[$url]}" ]; then if [ "${fetchedurls[$url]}" ]; then
if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then msg_verbose "already fetched $url\n"
echo "already fetched $url" 1>&2
fi
continue continue
fi fi
if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then msg_verbose "fetching $url and scanning with $rx\n"
echo "fetching $url and scanning with $rx" 1>&2
fi
curl -H 'Accept: text/html,application/xhtml+xml,application/xml,text/plain,application/rss+xml' -A "xbps-src-update-check/$XBPS_SRC_VERSION" --max-time 10 -Lsk "$url" | curl -H 'Accept: text/html,application/xhtml+xml,application/xml,text/plain,application/rss+xml' -A "xbps-src-update-check/$XBPS_SRC_VERSION" --max-time 10 -Lsk "$url" |
grep -Po -i "$rx" grep -Po -i "$rx"
fetchedurls[$url]=yes fetchedurls[$url]=yes
@ -214,9 +207,7 @@ update_check() {
grep . || echo "NO VERSION found for $original_pkgname" 1>&2 grep . || echo "NO VERSION found for $original_pkgname" 1>&2
} | } |
while IFS= read -r found_version; do while IFS= read -r found_version; do
if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then msg_verbose "found version $found_version\n"
echo "found version $found_version"
fi
consider=true consider=true
p="$ignore " p="$ignore "
while [ -n "$p" ]; do while [ -n "$p" ]; do
@ -225,9 +216,7 @@ update_check() {
case "$found_version" in case "$found_version" in
$i) $i)
consider=false consider=false
if [ -n "$XBPS_UPDATE_CHECK_VERBOSE" ]; then msg_verbose "ignored $found_version due to $i\n"
echo "ignored $found_version due to $i"
fi
esac esac
done done
if $consider; then if $consider; then