From c442a86d27c751ef17115b34015627b648a7feaa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Uwe=20K=C3=B6cher?= Date: Tue, 25 Jul 2017 22:02:55 +0200 Subject: [PATCH] more unique and simplified OS major version number with lsb_release and grep of reg. ex. --- candi.sh | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/candi.sh b/candi.sh index 5828655..abd9a63 100755 --- a/candi.sh +++ b/candi.sh @@ -560,27 +560,30 @@ guess_platform() { elif [ ! -z "$CRAYOS_VERSION" ]; then echo cray - - elif [ -f /etc/fedora-release ]; then - echo fedora`lsb_release -r -s` - - elif [ -f /etc/redhat-release ]; then - local RHELNAME=`gawk '{if (match($0,/\((.*)\)/,f)) print f[1]}' /etc/redhat-release` - case ${RHELNAME} in - "Maipo"*) echo rhel7;; - "Core"*) echo centos7;; - esac - + elif [ -x /usr/bin/lsb_release ]; then - local DISTRO=$(lsb_release -i -s) - local CODENAME=$(lsb_release -c -s) - local DESCRIPTION=$(lsb_release -d -s) - case ${DISTRO}:${CODENAME}:${DESCRIPTION} in - *:*:*Debian*9*) echo debian9;; - *:*:*Ubuntu*) echo ubuntu`lsb_release -r -s`;; - *:*:*openSUSE\ 12*) echo opensuse12;; - *:*:*openSUSE\ 13*) echo opensuse13;; - esac + local OSVER=$(lsb_release -r -s |grep -o -E '[0-9]+' |head -n 1) + + if [ -f /etc/fedora-release ]; then + echo fedora${OSVER} + + elif [ -f /etc/centos-release ]; then + echo centos${OSVER} + + elif [ -f /etc/redhat-release ]; then + echo rhel${OSVER} + + else + local DISTRO=$(lsb_release -i -s) + local CODENAME=$(lsb_release -c -s) + local DESCRIPTION=$(lsb_release -d -s) + case ${DISTRO}:${CODENAME}:${DESCRIPTION} in + *:*:*Debian*9*) echo debian9;; + *:*:*Ubuntu*) echo ubuntu${OSVER};; + *:*:*openSUSE\ 12*) echo opensuse12;; + *:*:*openSUSE\ 13*) echo opensuse13;; + esac + fi fi } -- 2.39.5