kiss-outdated: rewrite with useful error messages, etc

This commit is contained in:
Dylan Araps 2020-09-23 11:44:08 +03:00
parent 8a3a0b305a
commit cd6c95419d
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 40 additions and 38 deletions

View File

@ -1,52 +1,54 @@
#!/bin/sh #!/bin/sh
# Check repository packages for updates # Check repository for outdated packages
# #
# Intended behavior. # Intended behavior.
# shellcheck disable=2106 # shellcheck disable=2106
kiss search "${@:-*}" | (while read -r pkg_loc _; do { [ "$1" ] || {
read -r ver _ 2>/dev/null < "$pkg_loc/version" || continue printf 'usage: kiss outdated /path/to/repo\n' >&2
exit 1
}
pkg=${pkg_loc##*/} cd "$1" 2>/dev/null || {
printf 'repository %s is inaccessible\n' "$1" >&2
exit 1
}
# Fix some package names. printf 'Checking for outdated packages in %s\n' "$1" >&2
case $pkg in
*-bin) fix=${pkg%%-bin} ;;
*[0-9]r) fix=${pkg%%r} ;;
esac
# Ignore duplicates. for pkg in *; do
# shellcheck disable=2106 read -r ver _ < "$pkg/version" || {
case $seen in printf 'warning: %s/version not found' "$PWD/$pkg" >&2
*" ${fix:-$pkg} "*) continue ;; continue
*) seen=" $seen ${fix:-$pkg} " ;; }
esac
[ "$ver" = git ] && {
printf 'warning: skipping check for %s, version is git\n' "$pkg" >&2
continue
}
pkg=${pkg%%-bin}
pkg=${pkg%%-git}
rep=$(curl -s "https://repology.org/badge/latest-versions/$pkg.svg") || {
printf 'warning: failed to grab version for %s\n' "$pkg"
continue
}
# Grab the repology version from the SVG file.
rep=$(curl -s "https://repology.org/badge/latest-versions/${fix:-$pkg}.svg")
rep=${rep%</text>*} rep=${rep%</text>*}
rep=${rep##*>} rep=${rep##*>}
# Skip these. case $rep in
{ *", $ver"* | *"$ver,"* | "$ver")
case $rep in -|''|' ') continue; esac # Found match, do nothing.
case $ver in git) continue; esac ;;
}
# Split the comma separated list. - | '' | ' ')
# Intentional (and safe) splitting. printf 'warning: empty response from remote for %s\n' "$pkg"
# shellcheck disable=2086 ;;
{
IFS=', '
set -f
set +f -- $rep
unset IFS
}
# Parse comma separated version lists. *)
{ printf '%s\n' "$pkg $ver -> $rep"
for v; do case $v in "$ver") match=1; esac; done ;;
esac
[ "$match" ] || printf '%s\n' "$pkg $ver -> $rep" done
}
} & done; wait)