From: Ian Kelling Date: Fri, 3 Jul 2020 21:41:45 +0000 (-0400) Subject: fixes and impreovements X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=7fa28f7a5bc32b0e2de513fa7d9ae7c245c09c05;p=distro-functions fixes and impreovements --- diff --git a/src/identify-distros b/src/identify-distros index c3cfc72..f9d68ff 100644 --- a/src/identify-distros +++ b/src/identify-distros @@ -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 ;; diff --git a/src/package-manager-abstractions b/src/package-manager-abstractions index a050be9..9311038 100644 --- a/src/package-manager-abstractions +++ b/src/package-manager-abstractions @@ -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 </dev/null </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 "$@"