Commit version 24.12.13800
This commit is contained in:
100
scripts/distro
100
scripts/distro
@ -2,7 +2,7 @@
|
||||
#
|
||||
# Observium License Version 1.0
|
||||
#
|
||||
# Copyright (c) 2013-2019 Joe Holden, (c) 2015 Mike Stupalov
|
||||
# Copyright (C) 2013-2019 Joe Holden, (C) 2014-2024 Observium Limited
|
||||
#
|
||||
# The intent of this license is to establish the freedom to use, share and contribute to
|
||||
# the software regulated by this license.
|
||||
@ -46,7 +46,7 @@
|
||||
#
|
||||
# URL: [https://www.observium.org/files/distro]
|
||||
|
||||
DISTROSCRIPT="2.2.5"
|
||||
DISTROSCRIPT="2.3.2"
|
||||
|
||||
if [ -z ${DISTROFORMAT} ]; then
|
||||
DISTROFORMAT="pipe"
|
||||
@ -87,11 +87,21 @@ getdistro() {
|
||||
if [ -f /etc/armbian-release ]; then
|
||||
# Armbian uses incorrect os-release
|
||||
DISTRO="Armbian"
|
||||
elif [ -f /etc/orangepi-release ]; then
|
||||
# Orange Pi uses incorrect os-release
|
||||
DISTRO="Orange OS"
|
||||
elif [ -f /boot/dietpi/.version ]; then
|
||||
# This is clone of Raspbian, but distro/version incorrect
|
||||
DISTRO="DietPi"
|
||||
else
|
||||
# note, this source include also set variable name $VERSION, ie on debian "10 (buster)"
|
||||
. /etc/os-release
|
||||
#DISTRO=`echo ${NAME} | awk '{print $1}'`
|
||||
DISTRO="${NAME% *}"
|
||||
if [ "${DISTRO}" = "Linux" ]; then
|
||||
# ie: Linux Mint
|
||||
DISTRO="${NAME#Linux *}"
|
||||
fi
|
||||
fi
|
||||
elif [ -x /usr/bin/lsb_release ]; then
|
||||
DISTRO=`/usr/bin/lsb_release -si 2>/dev/null`
|
||||
@ -181,12 +191,19 @@ getdistro() {
|
||||
DISTRO=
|
||||
fi
|
||||
|
||||
# Additional Distro fixes
|
||||
if [ "${DISTRO}" = "Debian GNU/Linux" ]; then
|
||||
DISTRO="Debian"
|
||||
elif [ "${DISTRO}" = "Red" -o "${DISTRO}" = "RedHatEnterpriseServer" ]; then
|
||||
DISTRO="RedHat"
|
||||
elif [ "${DISTRO}" = "VMware Photon" ]; then
|
||||
DISTRO="Photon"
|
||||
elif [ "${DISTRO}" = "Arch" ]; then
|
||||
DISTRO="ArchLinux"
|
||||
DISTRO="Arch Linux"
|
||||
elif [ "${DISTRO}" = "Orange" ]; then
|
||||
DISTRO="Orange OS"
|
||||
elif [ "${DISTRO}" = "Amazon" ]; then
|
||||
DISTRO="Amazon Linux"
|
||||
fi
|
||||
|
||||
elif [ "${OS}" = "FreeBSD" ]; then
|
||||
@ -194,6 +211,8 @@ getdistro() {
|
||||
DISTRO="pfSense"
|
||||
elif [ -f /etc/platform -a -f /etc/prd.name ]; then
|
||||
DISTRO=`cat /etc/prd.name`
|
||||
elif [ -x /usr/local/sbin/opnsense-version ]; then
|
||||
DISTRO="OPNsense"
|
||||
elif [ -f /usr/local/bin/pbreg ]; then
|
||||
DISTRO="PC-BSD"
|
||||
elif [ -f /usr/sbin/hbsd-update -o -f /etc/hbsd-update.conf ]; then
|
||||
@ -261,6 +280,8 @@ getversion() {
|
||||
#elif [ "${DISTRO}" = "HardenedBSD" ]; then
|
||||
# tmp=`sysctl -n hardening.version 2>/dev/null`
|
||||
# VERSION=``
|
||||
elif [ "${DISTRO}" = "OPNsense" ]; then
|
||||
VERSION=`/usr/local/sbin/opnsense-version | awk '{ print $2 }'`
|
||||
elif [ -f /etc/prd.version ]; then
|
||||
VERSION=`cat /etc/prd.version`
|
||||
elif [ -f /bin/freebsd-version ]; then
|
||||
@ -282,6 +303,14 @@ getversion() {
|
||||
elif [ "${DISTRO}" = "Armbian" ]; then
|
||||
#. /etc/armbian-release
|
||||
VERSION=`awk -F '=' '/VERSION=/ { print $2 }' /etc/armbian-release`
|
||||
elif [ "${DISTRO}" = "Orange OS" ]; then
|
||||
#. /etc/orangepi-release
|
||||
VERSION=`awk -F '=' '/VERSION=/ { print $2 }' /etc/orangepi-release`
|
||||
elif [ "${DISTRO}" = "DietPi" ]; then
|
||||
. /boot/dietpi/.version
|
||||
VERSION="${G_DIETPI_VERSION_CORE}.${G_DIETPI_VERSION_SUB}.${G_DIETPI_VERSION_RC}"
|
||||
elif [ -f /etc/orangepi-os-version ]; then
|
||||
VERSION=`awk -F ' - ' '{ print $NF }' /etc/orangepi-os-version | sed 's/-linux.*//'`
|
||||
elif [ -f /etc/os-release ]; then
|
||||
. /etc/os-release
|
||||
VERSION="${VERSION_ID}"
|
||||
@ -348,7 +377,7 @@ detectvirt() {
|
||||
KVM*|[Go][Oo][Oo][Gg][Ll][Ee]*)
|
||||
type=kvm
|
||||
;;
|
||||
zvm|oracle|bochs|uml|parallels|kvm|qemu|qnx|acrn|powervm)
|
||||
zvm|oracle|amazon|bochs|uml|parallels|kvm|qemu|qnx|acrn|powervm)
|
||||
type="${1}"
|
||||
;;
|
||||
vm-other)
|
||||
@ -417,6 +446,14 @@ getvirt() {
|
||||
if [ "${OS}" = "Linux" ]; then
|
||||
if [ "${VIRT}" = "none" -a -f /usr/bin/systemd-detect-virt ]; then
|
||||
tmp=`/usr/bin/systemd-detect-virt -v`
|
||||
# systemd-detect-virt falsely detects "Microsoft" virtualisation
|
||||
# https://github.com/systemd/systemd/issues/21468
|
||||
if [ "${tmp}" = "microsoft" -a -f /sys/devices/virtual/dmi/id/product_name ]; then
|
||||
tmp2=`cat /sys/devices/virtual/dmi/id/product_name`
|
||||
if [ "${tmp2}" = "KVM" ]; then
|
||||
tmp="${tmp2}"
|
||||
fi
|
||||
fi
|
||||
VIRT=`detectvirt "${tmp}"`
|
||||
fi
|
||||
if [ "${VIRT}" = "none" -a -f /sys/devices/virtual/dmi/id/product_name ]; then
|
||||
@ -470,6 +507,61 @@ getvirt() {
|
||||
return 0
|
||||
}
|
||||
|
||||
help() {
|
||||
cat << EOF
|
||||
Usage: distro [-f format] [-o out] [-h] [-v]
|
||||
|
||||
Options:
|
||||
-f <format> Output format: pipe (default), twopipe, json, ini, export
|
||||
-o <out> Show specific parameter only: os, kernel, arch, distro,
|
||||
version, virt, cont
|
||||
-h Show help
|
||||
-v Show version
|
||||
|
||||
See the distro homepage at https://docs.observium.org/distro_script
|
||||
and source code at https://github.com/observium/distroscript
|
||||
EOF
|
||||
}
|
||||
|
||||
while getopts vho:f: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
v) echo $DISTROSCRIPT; exit;;
|
||||
h) help; exit;;
|
||||
o)
|
||||
getos
|
||||
getdistro
|
||||
if [ "${OPTARG}" = "os" ]; then
|
||||
#getos
|
||||
echo $OS
|
||||
elif [ "${OPTARG}" = "kernel" ]; then
|
||||
getkernel
|
||||
echo $KERNEL
|
||||
elif [ "${OPTARG}" = "arch" ]; then
|
||||
getarch
|
||||
echo $ARCH
|
||||
elif [ "${OPTARG}" = "distro" ]; then
|
||||
#getdistro
|
||||
echo $DISTRO
|
||||
elif [ "${OPTARG}" = "version" ]; then
|
||||
getversion
|
||||
echo $VERSION
|
||||
elif [ "${OPTARG}" = "virt" ]; then
|
||||
getvirt
|
||||
echo $VIRT
|
||||
elif [ "${OPTARG}" = "cont" ]; then
|
||||
getcont
|
||||
echo $CONT
|
||||
fi
|
||||
exit
|
||||
;;
|
||||
f) if [ "${OPTARG}" = "pipe" -o "${OPTARG}" = "twopipe" -o "${OPTARG}" = "json" -o "${OPTARG}" = "export" -o "${OPTARG}" = "ini" ]; then
|
||||
DISTROFORMAT=${OPTARG}
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z ${DISTROEXEC+x} ]; then
|
||||
|
||||
getos
|
||||
|
Reference in New Issue
Block a user