From 9127e0610932b52abaa52cf2e28afd41d03eec3b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 25 Apr 2014 01:48:58 +0200 Subject: [PATCH] CentOS support for __hostname Signed-off-by: Nico Schottelius --- .../__hostname/explorer/hostname_sysconfig | 26 ++++++++++++++++++ cdist/conf/type/__hostname/gencode-remote | 27 +++++++++++++++---- cdist/conf/type/__hostname/manifest | 27 ++++++++++++++----- docs/changelog | 1 + 4 files changed, 69 insertions(+), 12 deletions(-) create mode 100755 cdist/conf/type/__hostname/explorer/hostname_sysconfig diff --git a/cdist/conf/type/__hostname/explorer/hostname_sysconfig b/cdist/conf/type/__hostname/explorer/hostname_sysconfig new file mode 100755 index 00000000..d0d7b4e7 --- /dev/null +++ b/cdist/conf/type/__hostname/explorer/hostname_sysconfig @@ -0,0 +1,26 @@ +#!/bin/sh +# +# 2014 Nico Schottelius (nico-cdist at schottelius.org) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Retrieve the contents of /etc/hostname +# + +if [ -f /etc/sysconfig/network ]; then + awk -F= '/^HOSTNAME=/ { print $2 }' /etc/sysconfig/network +fi diff --git a/cdist/conf/type/__hostname/gencode-remote b/cdist/conf/type/__hostname/gencode-remote index 3d208cbe..eec3bc9f 100755 --- a/cdist/conf/type/__hostname/gencode-remote +++ b/cdist/conf/type/__hostname/gencode-remote @@ -28,14 +28,24 @@ fi os=$(cat "$__global/explorer/os") name_running=$(cat "$__global/explorer/hostname") name_config=$(cat "$__object/explorer/hostname_file") +name_sysconfig=$(cat "$__object/explorer/hostname_file") has_hostnamectl=$(cat "$__object/explorer/has_hostnamectl") ################################################################################ # If everything is ok -> exit # -if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then - exit 0 -fi +case "$os" in + archlinux|debian|ubuntu) + if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then + exit 0 + fi + ;; + centos) + if [ "$name_sysconfig" = "$name_should" -a "$name_running" = "$name_should" ]; then + exit 0 + fi + ;; +esac ################################################################################ # Setup hostname @@ -45,6 +55,13 @@ echo changed >> "$__messages_out" if [ "$has_hostnamectl" ]; then echo "hostnamectl set-hostname '$name_should'" else - echo "hostname '$name_should'" - echo "printf '%s\n' '$name_should' > /etc/hostname" + case "$os" in + archlinux|debian|ubuntu) + echo "hostname '$name_should'" + echo "printf '%s\n' '$name_should' > /etc/hostname" + ;; + centos) + echo "hostname '$name_should'" + ;; + esac fi diff --git a/cdist/conf/type/__hostname/manifest b/cdist/conf/type/__hostname/manifest index 0544a6f9..b6985c1c 100755 --- a/cdist/conf/type/__hostname/manifest +++ b/cdist/conf/type/__hostname/manifest @@ -20,6 +20,12 @@ # os=$(cat "$__global/explorer/os") +if [ -f "$__object/parameter/name" ]; then + name_should="$(cat "$__object/parameter/name")" +else + name_should="$(echo "${__target_host%%.*}")" +fi + not_supported() { echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 @@ -28,11 +34,18 @@ not_supported() { } case "$os" in - archlinux|debian|ubuntu) - # handled in gencode-remote - : - ;; - *) - not_supported - ;; + archlinux|debian|ubuntu) + # handled in gencode-remote + : + ;; + centos) + __key_value sysconfig-hostname \ + --file /etc/sysconfig/network \ + --delimiter '=' \ + --key HOSTNAME \ + --value "$name_should" --exact_delimiter + ;; + *) + not_supported + ;; esac diff --git a/docs/changelog b/docs/changelog index bea0859c..6e69251f 100644 --- a/docs/changelog +++ b/docs/changelog @@ -7,6 +7,7 @@ Changelog 3.1.3: * New Type: __yum_repo (Steven Armstrong) + * Type __hostname: Add support for CentOS 3.1.2: 2014-04-12 * Documentation: Add missing environment variables to reference