Linux: Move /etc/os-release directly below lsb_release

We are assuming that people's /etc/os-release are standard, and any distro
without it will use the "fallback" methods they have.
This commit is contained in:
Muhammad Herdiansyah 2019-07-18 15:18:29 +07:00
parent 9d4855a18f
commit f4cfdfa47c
1 changed files with 17 additions and 17 deletions

View File

@ -877,6 +877,23 @@ get_distro() {
esac
distro="$(lsb_release "$lsb_flags")"
elif [[ -f "/etc/os-release" || \
-f "/usr/lib/os-release" || \
-f "/etc/openwrt_release" ]]; then
files=("/etc/os-release" "/usr/lib/os-release" "/etc/openwrt_release")
# Source the os-release file
for file in "${files[@]}"; do
source "$file" && break
done
# Format the distro name.
case "$distro_shorthand" in
"on") distro="${NAME:-${DISTRIB_ID}} ${VERSION_ID:-${DISTRIB_RELEASE}}" ;;
"tiny") distro="${NAME:-${DISTRIB_ID:-${TAILS_PRODUCT_NAME}}}" ;;
"off") distro="${PRETTY_NAME:-${DISTRIB_DESCRIPTION}} ${UBUNTU_CODENAME}" ;;
esac
elif [[ -f "/etc/GoboLinuxVersion" ]]; then
case "$distro_shorthand" in
"on" | "tiny") distro="GoboLinux" ;;
@ -906,23 +923,6 @@ get_distro() {
elif [[ -f "/etc/lsb-release" && "$(< /etc/lsb-release)" == *CHROMEOS* ]]; then
distro="$(awk -F '=' '/NAME|VERSION/ {printf $2 " "}' /etc/lsb-release)"
elif [[ -f "/etc/os-release" || \
-f "/usr/lib/os-release" || \
-f "/etc/openwrt_release" ]]; then
files=("/etc/os-release" "/usr/lib/os-release" "/etc/openwrt_release")
# Source the os-release file
for file in "${files[@]}"; do
source "$file" && break
done
# Format the distro name.
case "$distro_shorthand" in
"on") distro="${NAME:-${DISTRIB_ID}} ${VERSION_ID:-${DISTRIB_RELEASE}}" ;;
"tiny") distro="${NAME:-${DISTRIB_ID:-${TAILS_PRODUCT_NAME}}}" ;;
"off") distro="${PRETTY_NAME:-${DISTRIB_DESCRIPTION}} ${UBUNTU_CODENAME}" ;;
esac
elif type -p guix >/dev/null; then
case "$distro_shorthand" in
"on" | "tiny") distro="GuixSD" ;;