CentOS support for __hostname

Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
Nico Schottelius 2014-04-25 01:48:58 +02:00
parent f9783f5f77
commit 9127e06109
4 changed files with 69 additions and 12 deletions

View file

@ -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 <http://www.gnu.org/licenses/>.
#
#
# Retrieve the contents of /etc/hostname
#
if [ -f /etc/sysconfig/network ]; then
awk -F= '/^HOSTNAME=/ { print $2 }' /etc/sysconfig/network
fi

View file

@ -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
case "$os" in
archlinux|debian|ubuntu)
if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then
exit 0
fi
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
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

View file

@ -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
@ -32,6 +38,13 @@ case "$os" in
# handled in gencode-remote
:
;;
centos)
__key_value sysconfig-hostname \
--file /etc/sysconfig/network \
--delimiter '=' \
--key HOSTNAME \
--value "$name_should" --exact_delimiter
;;
*)
not_supported
;;

View file

@ -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