fixes and impreovements
authorIan Kelling <iank@fsf.org>
Fri, 3 Jul 2020 21:41:45 +0000 (17:41 -0400)
committerIan Kelling <iank@fsf.org>
Fri, 3 Jul 2020 21:41:45 +0000 (17:41 -0400)
src/identify-distros
src/package-manager-abstractions

index c3cfc723c585d9737d958a874026eb54146482bf..f9d68ff95e934d6b11548b3804e9f429d40d417d 100644 (file)
@@ -77,7 +77,7 @@ EOF
         if (( ${#shortest} > ${#name} )); then
             shortest=$name
         fi
-    done < <(echo "$policy" | sed -rn "$expression" | sort -rn)
+    done < <(echo "$policy" | sed -rn "$expression" | sort -rn || [[ $? == 141 ]])
     echo "$shortest"
 
 }
@@ -95,7 +95,7 @@ debian-codename() {
     isdeb || return 0
     local policy="$(apt-cache policy)" || return $?
     archive=$(debian-archive "$policy")
-    echo "$policy" | sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q"
+    echo "$policy" | sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" || [[ $? == 141 ]]
 }
 debian-codename-compat() {
     local n=$(debian-codename)
@@ -103,6 +103,9 @@ debian-codename-compat() {
         flidas)
             echo xenial
             ;;
+        etiona)
+          echo bionic
+          ;;
         *)
             echo $n
             ;;
index a050be9dc4061ff2bbae3e3c4fac2aceb394fb14..9311038c4f0b616d6b7ad1837d25a413edbfb3ff 100644 (file)
@@ -48,8 +48,27 @@ if command -v yum &> /dev/null; then
   }
 
 elif command -v apt-get &>/dev/null; then
+  plock-wait() {
+    local i
+    i=0
+    while fuser /var/lib/dpkg/lock &>/dev/null; do
+      sleep 1
+      i=$(( i+1 ))
+      if (( i > 300 )); then
+        echo "error: timed out waiting for /var/lib/dpkg/lock" >&2
+        return 1
+      fi
+    done
+  }
   pcheck() {
-    if dpkg -s -- "$@" | grep -Fx "Status: install ok installed" &>/dev/null; then
+    for arg; do
+      if [[ $1 == -* ]]; then
+        shift
+      else
+        break
+      fi
+    done
+    if dpkg -s -- "$@" |& grep -Fx "Status: install ok installed" &>/dev/null; then
       return 1
     fi
     return 0
@@ -79,25 +98,32 @@ elif command -v apt-get &>/dev/null; then
   }
   pi() {
     pcheck "$@" || return 0
-    while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
     pupdate
     local s; [[ $EUID != 0 ]] && s=sudo
+    if [[ $- != *i* ]]; then
+      echo pi "$@"
+    fi
     $s $PI_PREFIX apt-get -y install --purge --auto-remove "$@"
   }
 
   pi-nostart() {
+    local ret=
     pcheck "$@" || return 0
-    while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
+    plock-wait
     pupdate
     local s; [[ $EUID != 0 ]] && s=sudo
     local f=/usr/sbin/policy-rc.d
-    $s dd of=$f <<EOF
+    $s dd of=$f 2>/dev/null <<EOF
 #!/bin/sh
 exit 101
 EOF
     $s chmod +x $f
-    $s apt-get -y install --purge --auto-remove "$@"
+    if [[ $- != *i* ]]; then
+      echo pi-nostart "$@"
+    fi
+    $s apt-get -y install --purge --auto-remove "$@" || ret=$?
     $s rm $f
+    return $ret
   }
   pf() {
     # package name and descriptions
@@ -115,13 +141,21 @@ EOF
   }
   pu() {
     local s; [[ $EUID != 0 ]] && s=sudo
-    while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
+    local needed=false
+    for arg; do
+      if dpkg -s -- "$arg" &>/dev/null; then
+        needed=true
+        break
+      fi
+    done
+    $needed || return 0
+    plock-wait
     $s apt-get -y remove --purge --auto-remove  "$@"
     # seems slightly redundant, but it removes more stuff sometimes.
     $s apt-get -y autoremove
   }
   pup() { # upgrade
-    while fuser /var/lib/dpkg/lock &>/dev/null; do sleep 1; done
+    plock-wait
     pupdate
     local s; [[ $EUID != 0 ]] && s=sudo
     $s apt-get -y dist-upgrade --purge --auto-remove "$@"