diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-02 21:02:17 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-03 01:41:21 -0400 |
commit | bd41a36a2538bb0d2ec3b4255180a3c8a89b4a9a (patch) | |
tree | eaf5943000a6cf5009e8a15c67c4c1f875ba8399 /src | |
parent | 6d0f63e52869070870e3192511c230d479c41939 (diff) |
libredbdiff: Add a helper for vercmp
I have a hard time reasoning about vercmp use in scripts, so add a
{{ A -lt B }} helper that works like [ A -lt B ], but for pacman versions.
Diffstat (limited to 'src')
-rwxr-xr-x | src/abslibre-tools/libredbdiff | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/abslibre-tools/libredbdiff b/src/abslibre-tools/libredbdiff index 65ba4d6..bb6e068 100755 --- a/src/abslibre-tools/libredbdiff +++ b/src/abslibre-tools/libredbdiff @@ -60,16 +60,27 @@ createdir() { fi } +# {{ A -lt B }} is like [ A -lt B ], but for pacman version numbers +{{() { + [[ $# = 4 ]] || panic + [[ $4 = '}}' ]] || panic + local a=$1 + local op=$2 + local b=$3 + + local cmp + cmp="$(vercmp "$a" "$b")" || die "vercmp failed" + [ "$cmp" "$op" 0 ] +} + # Globals: # - pkgname : the Parabola pkgname # - ver_prbl : a map of pkgname->arch_pkgver # - ver_arch : a map of pkgname->prbl_pkgver # - provides : a map of pkgname->provides compare_pkgs() { - local cmp if [[ -n "${ver_arch[$pkgname]}" ]] ; then - cmp=$(vercmp "${ver_prbl[$pkgname]}" "${ver_arch[$pkgname]}") - if [[ "$cmp" -lt 0 ]]; then + if {{ "${ver_prbl[$pkgname]}" -lt "${ver_arch[$pkgname]}" }}; then printf "$printf_format" \ '=' \ "$pkgname" \ @@ -82,8 +93,7 @@ compare_pkgs() { read -r -a _provides <<<"${provides[$pkgname]}" for provide in "${_provides[@]}"; do if [[ -n "${ver_arch[$provide]}" ]]; then - cmp=$(vercmp "${ver_prbl[$pkgname]}" "${ver_arch[$provide]}") - if [[ "$cmp" -lt 0 ]]; then + if {{ "${ver_prbl[$pkgname]}" -lt "${ver_arch[$provide]}" }}; then printf "$printf_format" \ 'p' \ "$pkgname" \ |