kiss/contrib/kiss-outdated

97 lines
2.2 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Check repository for outdated packages
2020-05-09 12:28:09 -06:00
#
# Intended behavior.
# shellcheck disable=2106
2020-09-23 03:34:49 -06:00
remote_name() {
# Repology names some packages differently to us. This function fixes
# any known naming inconsistences that aren't a result of packaging error.
remote=$(printf %s "$1" | tr '[:upper:]' '[:lower:]')
remote=${remote%%-bin}
remote=${remote%%-git}
case $remote in
baselayout)
remote=baselayout-kiss
;;
2020-09-23 03:34:49 -06:00
gtk+[0-9])
remote=gtk
;;
kiss)
remote=kiss-package-manager
;;
st)
remote=st-term
;;
xf86-*)
remote=xdrv:${remote##*-}
;;
esac
}
2020-09-23 03:34:49 -06:00
remote_ver() {
# Grab the package's version as known by repology.org by downloading the
# SVG badge and extracting the version from the XML. This is far simpler
# to work with rather than using the API directly.
remote_name "$1"
2020-09-23 03:34:49 -06:00
rep=$(curl -s "https://repology.org/badge/latest-versions/$remote.svg") && {
remote_ver=${rep%</text>*}
remote_ver=${remote_ver##*>}
}
}
2020-09-23 02:51:19 -06:00
2020-09-23 03:34:49 -06:00
main() {
[ "$1" ] || {
printf 'usage: kiss outdated /path/to/repo\n' >&2
exit 1
}
2020-09-23 03:34:49 -06:00
cd "$1" 2>/dev/null || {
printf 'repository %s is inaccessible\n' "$1" >&2
exit 1
}
2020-09-23 03:34:49 -06:00
printf 'Checking repology.org for outdated packages in %s\n' "$1" >&2
2020-09-23 03:34:49 -06:00
for pkg in */; do
pkg=${pkg%%/}
2020-09-23 03:34:49 -06:00
read -r ver _ 2>/dev/null < "$pkg/version" || {
printf '%s: local version not found\n' "$pkg" >&2
continue
}
2020-09-23 03:34:49 -06:00
[ "$ver" = git ] && {
printf '%s: skipping, version is git\n' "$pkg" >&2
continue
}
2020-09-23 03:34:49 -06:00
remote_ver "$pkg" || {
printf '%s: failed to grab version from repology\n' "$pkg" >&2
continue
}
2020-09-23 03:34:49 -06:00
case $remote_ver in
*", $ver"* | *"$ver,"* | "$ver")
# Found match, do nothing.
;;
- | '' | ' ')
printf '%s: empty response, named correctly?\n' "$pkg" >&2
;;
*)
printf '%s: %s -> %s\n' "$pkg" "$ver" "$remote_ver"
;;
esac
done
}
main "$@"