X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=src%2Fidentify-distros;h=c3cfc723c585d9737d958a874026eb54146482bf;hb=b603450a2502e1ae500f1527d4c4e8002e15d9be;hp=f75cb0f36b3b936c3a9970a9c36300bf0d48ba43;hpb=c242c573b6ebeeacd95734446881be4bad8a0bbd;p=distro-functions diff --git a/src/identify-distros b/src/identify-distros index f75cb0f..c3cfc72 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 policy="${1:-$(apt-cache policy)}" + local archive expression pri name highpri shortest + local policy="${1:-$(apt-cache policy)}" || return $? # 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" + } @@ -59,10 +93,22 @@ isdebian-stable() { debian-codename() { isdeb || return 0 - local policy="$(apt-cache policy)" + local policy="$(apt-cache policy)" || return $? 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; }