From: Ian Kelling <iank@fsf.org>
Date: Tue, 3 Dec 2024 20:47:02 +0000 (-0500)
Subject: fix bugs i dunno how I lived with these for so long
X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;ds=sidebyside;p=distro-functions

fix bugs i dunno how I lived with these for so long
---

diff --git a/src/identify-distros b/src/identify-distros
index c275db6..80bb39c 100644
--- a/src/identify-distros
+++ b/src/identify-distros
@@ -144,7 +144,7 @@ debian-codename() {
   local policy
   policy="$(apt-cache policy)"
   archive=$(debian-archive "$policy")
-  printf "%s\n" "$policy" | sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" || [[ $? == 141 ]]
+  sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" <<<"$policy"
 }
 debian-codename-compat() {
   local n
diff --git a/src/package-manager-abstractions b/src/package-manager-abstractions
index 8b7989b..a765967 100644
--- a/src/package-manager-abstractions
+++ b/src/package-manager-abstractions
@@ -68,7 +68,9 @@ elif command -v apt-get &>/dev/null; then
       fi
     done
   }
+  # returns 1 if $@ are all already installed packages.
   pcheck() {
+    local arg count
     for arg; do
       if [[ $1 == -* ]]; then
         shift
@@ -76,8 +78,10 @@ elif command -v apt-get &>/dev/null; then
         break
       fi
     done
-    if dpkg -s -- "$@" |& grep -Fx "Status: install ok installed" &>/dev/null; then
-      return 1
+    if count=$(dpkg -s -- "$@" 2>/dev/null | grep -cFx "Status: install ok installed"); then
+      if [[ $count == "$#" ]]; then
+        return 1
+      fi
     fi
     return 0
   }
@@ -119,7 +123,7 @@ elif command -v apt-get &>/dev/null; then
         fi
       fi
     done
-    if (( cachetime > limittime )); then
+    if (( cachetime < limittime )); then
       $s apt-get update
     fi
   }