From 147cb67824b213045826677946166c8ee807f23c Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 12 Feb 2019 20:33:05 -0600 Subject: [PATCH] Use os-release whenever possible for the distro script (#220) Except centos... https://bugs.centos.org/view.php?id=8359 --- snmp/distro | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/snmp/distro b/snmp/distro index cd9e814..75fa74d 100755 --- a/snmp/distro +++ b/snmp/distro @@ -24,6 +24,7 @@ elif [ "${OS}" = "Linux" ] ; then DIST=$(cat /etc/redhat-release | awk '{print $1}') if [ "${DIST}" = "CentOS" ]; then DIST="CentOS" + IGNORE_OS_RELEASE=1 # https://bugs.centos.org/view.php?id=8359 elif [ "${DIST}" = "CloudLinux" ]; then DIST="CloudLinux" elif [ "${DIST}" = "Mandriva" ]; then @@ -77,10 +78,6 @@ elif [ "${OS}" = "Linux" ] ; then REV=$(sed -n -e 's/^.*PHOTON_BUILD_NUMBER=//p' /etc/photon-release) IGNORE_LSB=1 # photon os does not have /etc/lsb-release nor lsb_release - elif [ -f /etc/os-release ] ; then - DIST=$(grep '^NAME=' /etc/os-release | cut -d= -f2- | tr -d '"') - REV=$(grep '^VERSION_ID=' /etc/os-release | cut -d= -f2- | tr -d '"') - elif [ -f /etc/openwrt_version ] ; then DIST="OpenWrt" REV=$(cat /etc/openwrt_version) @@ -94,29 +91,33 @@ elif [ "${OS}" = "Linux" ] ; then REV=$(echo SP$(grep PATCHLEVEL /etc/SuSE-release | cut -d = -f 2 | tr -d " ")) fi - if [ -f /etc/lsb-release -a "${IGNORE_LSB}" != 1 ] ; then - LSB_DIST=$(lsb_release -si) - LSB_REV=$(lsb_release -sr) - if [ "$LSB_DIST" != "" ] ; then - DIST=$LSB_DIST - fi - if [ "$LSB_REV" != "" ] ; then - REV=$LSB_REV - fi - fi - if [ -x "$(command -v awk)" ]; then # some distros do not ship with awk if [ "`uname -a | awk '{print $(NF)}'`" = "DD-WRT" ] ; then DIST="dd-wrt" - fi + fi if [ "`uname -a | awk '{print $(NF)}'`" = "ASUSWRT-Merlin" ] ; then DIST="ASUSWRT-Merlin" REV=`nvram show | grep buildno= | egrep -o '[0-9].[0-9].[0-9]'` > /dev/null 2>&1 fi fi - if [ -n "${REV}" ] - then + # try standardized os version methods + if [ -f /etc/os-release -a "${IGNORE_OS_RELEASE}" != 1 ] ; then + source /etc/os-release + STD_DIST="$NAME" + STD_REV="$VERSION_ID" + elif [ -f /etc/lsb-release -a "${IGNORE_LSB}" != 1 ] ; then + STD_DIST=$(lsb_release -si) + STD_REV=$(lsb_release -sr) + fi + if [ -n "${STD_DIST}" ]; then + DIST="${STD_DIST}" + fi + if [ -n "${STD_REV}" ]; then + REV="${STD_REV}" + fi + + if [ -n "${REV}" ]; then OSSTR="${DIST} ${REV}" else OSSTR="${DIST}"