From: Ian Kelling Date: Mon, 22 Jan 2018 01:43:01 +0000 (-0500) Subject: various fixes and flidas support X-Git-Url: https://iankelling.org/git/?a=commitdiff_plain;h=6314c835343decaa195019ed2d38a1cb0d5f6a69;p=distro-functions various fixes and flidas support --- diff --git a/src/identify-distros b/src/identify-distros index f75cb0f..011ddb5 100644 --- a/src/identify-distros +++ b/src/identify-distros @@ -14,38 +14,72 @@ # limitations under the License. distro-name() { + local x if [[ -f /etc/fedora-release ]]; then echo fedora elif [[ -e /etc/os-release ]]; then sed -rn 's/^ID=(.*)/\1/p' /etc/os-release + elif type -p lsb_release &>/dev/null; then + # well, this is more standard, but it's 2 ms vs 200 ms + x=$(lsb_release -si); echo ${x,,} else echo "unknown distro" return 1 fi } +distro-name-compat() { + local x=$(distro-name) + case $x in + trisquel) + echo ubuntu + ;; + *) + echo $x + ;; + esac +} + distro-name-ver() { echo `distro-name``debian-archive` } debian-archive() { isdeb || return 0 - local archive + local archive expression pri name highpri shortest local policy="${1:-$(apt-cache policy)}" # a = archive # n = codename # o = origin # c = component (licensing component) # l = label (Debian{,-Security,-Updates}) - { for archive in stable testing unstable; do - # print priority + archive name. priority is in - # the previous line after finding the archive. - read -rd '' expression < ${#name} )); then + shortest=$name + fi + done < <(echo "$policy" | sed -rn "$expression" | sort -rn) + echo "$shortest" + } @@ -63,6 +97,18 @@ debian-codename() { archive=$(debian-archive "$policy") echo "$policy" | sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" } +debian-codename-compat() { + local n=$(debian-codename) + case $n in + flidas) + echo xenial + ;; + *) + echo $n + ;; + esac +} + isfedora() { [[ $(distro-name) == fedora ]] } @@ -72,8 +118,11 @@ isdebian() { isarch() { [[ $(distro-name) == arch ]] } -# is debian/apt based -isdeb() { command -v apt-get &>/dev/null; } isubuntu() { [[ $(distro-name) == ubuntu ]] } +istrisquel() { + [[ $(distro-name) == trisquel ]] +} +# is debian/apt based +isdeb() { command -v apt-get &>/dev/null; } diff --git a/src/package-manager-abstractions b/src/package-manager-abstractions index 6936c92..6d433d2 100644 --- a/src/package-manager-abstractions +++ b/src/package-manager-abstractions @@ -62,11 +62,27 @@ elif command -v apt-get &>/dev/null; then fi } pi() { + if dpkg -s -- "$@" &>/dev/null; then + return 0 + fi pupdate local s; [[ $EUID != 0 ]] && s=sudo $s apt-get -y install --purge --auto-remove "$@" } + pi() { + if dpkg -s -- "$@" &>/dev/null; then + return 0 + fi + pupdate + local s; [[ $EUID != 0 ]] && s=sudo + $s $PI_PREFIX apt-get -y install --purge --auto-remove "$@" + } + pi-nostart() { + if dpkg -s -- "$@" &>/dev/null; then + return 0 + fi + pupdate local s; [[ $EUID != 0 ]] && s=sudo local f=/usr/sbin/policy-rc.d $s dd of=$f </dev/null; then exit 101 EOF $s chmod +x $f - pi "$@" + $s apt-get -y install --purge --auto-remove "$@" $s rm $f } pf() { @@ -126,6 +142,7 @@ EOF apt-file find -x "$file"\$ else apt-file find -x /"$file"\$ + update-alternatives --list "$file" 2>/dev/null fi } pkgfiles() {