X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=src%2Fidentify-distros;h=9c2221f43b7826137f1bbe3206984321fa3356eb;hb=ed512c188a79f67fb69a6befadbe0043c435747b;hp=f75cb0f36b3b936c3a9970a9c36300bf0d48ba43;hpb=c242c573b6ebeeacd95734446881be4bad8a0bbd;p=distro-functions diff --git a/src/identify-distros b/src/identify-distros index f75cb0f..9c2221f 100644 --- a/src/identify-distros +++ b/src/identify-distros @@ -14,66 +14,130 @@ # limitations under the License. distro-name() { - if [[ -f /etc/fedora-release ]]; then - echo fedora - elif [[ -e /etc/os-release ]]; then - sed -rn 's/^ID=(.*)/\1/p' /etc/os-release - else - echo "unknown distro" - return 1 - fi + 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` + echo $(distro-name)$(debian-archive) +} + +distro-num() { + # Subshell keeps environment clean. + ( . /etc/os-release + # in ubuntu the .x matters, trisquel it doesnt + if [[ $ID == ubuntu ]]; then + echo $VERSION_ID + else + echo ${VERSION_ID%%.*} + fi + ) } debian-archive() { - isdeb || return 0 - local archive - 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 || [[ $? == 141 ]]) + echo "$shortest" + } isdebian-testing() { - [[ $(debian-archive) == testing ]] + [[ $(debian-archive) == testing ]] } # I only do testing or stable. isdebian-stable() { - [[ $(debian-archive) == stable ]] + [[ $(debian-archive) == stable ]] } debian-codename() { - isdeb || return 0 - local policy="$(apt-cache policy)" - archive=$(debian-archive "$policy") - echo "$policy" | sed -rn "s/^.*a=$archive,n=([a-z]+).*/\1/p;T;q" + 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" || [[ $? == 141 ]] +} +debian-codename-compat() { + local n=$(debian-codename) + case $n in + flidas) + echo xenial + ;; + etiona) + echo bionic + ;; + *) + echo $n + ;; + esac } + isfedora() { - [[ $(distro-name) == fedora ]] + [[ $(distro-name) == fedora ]] } isdebian() { - [[ $(distro-name) == debian ]] + [[ $(distro-name) == debian ]] } isarch() { - [[ $(distro-name) == arch ]] + [[ $(distro-name) == arch ]] } -# is debian/apt based -isdeb() { command -v apt-get &>/dev/null; } isubuntu() { - [[ $(distro-name) == ubuntu ]] + [[ $(distro-name) == ubuntu ]] +} +istrisquel() { + [[ $(distro-name) == trisquel ]] } +# is debian/apt based +isdeb() { command -v apt-get &>/dev/null; }