OS: Merged Linux and BSD distro detection

This commit is contained in:
Muhammad Herdiansyah 2016-12-18 11:31:11 +07:00
parent 0386551664
commit 7726133333
1 changed files with 20 additions and 19 deletions

View File

@ -53,8 +53,8 @@ get_distro() {
[[ "$distro" ]] && return [[ "$distro" ]] && return
case "$os" in case "$os" in
"Linux") "Linux" | "BSD" | "MINIX")
if [[ "$(< /proc/version)" == *"Microsoft"* || "$(< /proc/sys/kernel/osrelease)" == *"Microsoft"* ]]; then if [[ "$(< /proc/version)" == *"Microsoft"* || "$(< /proc/sys/kernel/osrelease)" == *"Microsoft"* ]]; then ## ERRORS NEED TO BE SUPPRESSED!
case "$distro_shorthand" in case "$distro_shorthand" in
"on") distro="$(lsb_release -sir) [Windows 10]" ;; "on") distro="$(lsb_release -sir) [Windows 10]" ;;
"tiny") distro="Windows 10" ;; "tiny") distro="Windows 10" ;;
@ -95,9 +95,9 @@ get_distro() {
elif [[ -d "/system/app/" && -d "/system/priv-app" ]]; then elif [[ -d "/system/app/" && -d "/system/priv-app" ]]; then
distro="Android $(getprop ro.build.version.release)" distro="Android $(getprop ro.build.version.release)"
else elif [[ -f "/etc/os-release" || -f "/usr/lib/os-release" ]]; then
# Source the os-release file. # Source the os-release file
for file in /etc/os-release /usr/lib/os-release /etc/*release /usr/lib/*release; do for file in /etc/os-release /usr/lib/os-release; do
source "$file" 2>/dev/null && break source "$file" 2>/dev/null && break
done done
@ -111,6 +111,21 @@ get_distro() {
# Workarounds for distros that go against the os-release standard. # Workarounds for distros that go against the os-release standard.
[[ -z "${distro// }" ]] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease /usr/lib/*ease)" [[ -z "${distro// }" ]] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease /usr/lib/*ease)"
[[ -z "${distro// }" ]] && distro="$(awk -F'=' '{print $2; exit}' /etc/*ease /usr/lib/*ease)" [[ -z "${distro// }" ]] && distro="$(awk -F'=' '{print $2; exit}' /etc/*ease /usr/lib/*ease)"
else
distro="$(cat /etc/*-release)" # UUOC, but using usual bash $(< *-file) returns "ambiguous redirect"
if [[ -z "$distro" ]]; then
case "$distro_shorthand" in
"on" | "tiny") distro="$kernel_name" ;;
*) distro="$kernel_name $kernel_version" ;;
esac
distro="${distro/DragonFly/DragonFlyBSD}"
# Workarounds for FreeBSD based distros.
[[ -f "/etc/pcbsd-lang" ]] && distro="PCBSD"
[[ -f "/etc/rc.conf.trueos" ]] && distro="TrueOS"
[[ -f "/etc/pacbsd-release" ]] && distro="PacBSD" # /etc/pacbsd-release is an empty file
fi
fi fi
distro="$(trim_quotes "$distro")" distro="$(trim_quotes "$distro")"
;; ;;
@ -153,20 +168,6 @@ get_distro() {
os_arch="off" os_arch="off"
;; ;;
"BSD" | "MINIX")
case "$distro_shorthand" in
"tiny" | "on") distro="$kernel_name" ;;
*) distro="$kernel_name $kernel_version" ;;
esac
distro="${distro/DragonFly/DragonFlyBSD}"
# Workarounds for FreeBSD based distros.
[[ -f "/etc/pcbsd-lang" ]] && distro="PCBSD"
[[ -f "/etc/trueos-lang" ]] && distro="TrueOS"
[[ -f "/etc/pacbsd-release" ]] && distro="PacBSD"
;;
"Windows") "Windows")
distro="$(wmic os get Caption /value)" distro="$(wmic os get Caption /value)"