From 87a0d91587568594a616c7f3588bc74106312761 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Wed, 11 Nov 2020 14:20:18 +0100 Subject: [PATCH] [type/__hostname] Fix OS version detection for SuSE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit everything should be suse now… --- cdist/conf/type/__hostname/manifest | 39 ++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest index d044072b..b80aa2ef 100755 --- a/cdist/conf/type/__hostname/manifest +++ b/cdist/conf/type/__hostname/manifest @@ -25,8 +25,6 @@ set_hostname_systemd() { } os=$(cat "${__global:?}/explorer/os") -os_version=$(cat "${__global:?}/explorer/os_version") -os_major=$(echo "${os_version}" | grep -o '^[0-9][0-9]*' || true) max_len=$(cat "${__object:?}/explorer/max_len") has_hostnamectl=$(cat "${__object:?}/explorer/has_hostnamectl") @@ -38,24 +36,10 @@ else case ${os} in # RedHat-derivatives and BSDs - (centos|fedora|redhat|scientific|freebsd|netbsd|openbsd|slackware) + (centos|fedora|redhat|scientific|freebsd|netbsd|openbsd|slackware|suse) # Hostname is FQDN name_should=${__target_host:?} ;; - (suse) - name_should=${__target_host:?} - - # Classic SuSE stores the FQDN in /etc/HOSTNAME, while - # systemd does not. The running hostname is the first - # component in both cases. - # In versions before 15.x, the FQDN is stored in /etc/hostname. - if test -n "${has_hostnamectl}" \ - && test "${os_major}" -ge 15 \ - && test "${os_major}" -ne 42 - then - name_should=${name_should%%.*} - fi - ;; *) # Hostname is only first component of FQDN on all other systems. name_should=${__target_host:?} @@ -158,6 +142,27 @@ in echo "${name_should}" | __file /etc/nodename --source - ;; (suse) + if test -s "${__global:?}/explorer/os_release" + then + # shellcheck source=/dev/null + os_version=$(. "${__global:?}/explorer/os_release" && echo "${VERSION}") + else + os_version=$(sed -n 's/^VERSION\ *=\ *//p' "${__global:?}/explorer/os_version") + fi + os_major=$(expr "${os_version}" : '\([0-9]\{1,\}\)') + + # Classic SuSE stores the FQDN in /etc/HOSTNAME, while + # systemd does not. The running hostname is the first + # component in both cases. + # In versions before 15.x, the FQDN is stored in /etc/hostname. + if test -n "${has_hostnamectl}" \ + && test "${os_major}" -ge 15 \ + && test "${os_major}" -ne 42 + then + # strip away everything but the first part from $name_should + name_should=${name_should%%.*} + fi + # Modern SuSE provides /etc/HOSTNAME as a symlink for # backwards-compatibility. Unfortunately it cannot be used # here as __file does not follow the symlink.