forked from ungleich-public/cdist
		
	CentOS support for __hostname
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								f9783f5f77
							
						
					
				
			
			
				commit
				
					
						9127e06109
					
				
			
		
					 4 changed files with 69 additions and 12 deletions
				
			
		
							
								
								
									
										26
									
								
								cdist/conf/type/__hostname/explorer/hostname_sysconfig
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										26
									
								
								cdist/conf/type/__hostname/explorer/hostname_sysconfig
									
										
									
									
									
										Executable 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
 | 
				
			||||||
| 
						 | 
					@ -28,14 +28,24 @@ fi
 | 
				
			||||||
os=$(cat "$__global/explorer/os")
 | 
					os=$(cat "$__global/explorer/os")
 | 
				
			||||||
name_running=$(cat "$__global/explorer/hostname")
 | 
					name_running=$(cat "$__global/explorer/hostname")
 | 
				
			||||||
name_config=$(cat "$__object/explorer/hostname_file")
 | 
					name_config=$(cat "$__object/explorer/hostname_file")
 | 
				
			||||||
 | 
					name_sysconfig=$(cat "$__object/explorer/hostname_file")
 | 
				
			||||||
has_hostnamectl=$(cat "$__object/explorer/has_hostnamectl")
 | 
					has_hostnamectl=$(cat "$__object/explorer/has_hostnamectl")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
################################################################################
 | 
					################################################################################
 | 
				
			||||||
# If everything is ok -> exit
 | 
					# If everything is ok -> exit
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					case "$os" in
 | 
				
			||||||
 | 
					    archlinux|debian|ubuntu)
 | 
				
			||||||
        if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then
 | 
					        if [ "$name_config" = "$name_should" -a "$name_running" = "$name_should" ]; then
 | 
				
			||||||
            exit 0
 | 
					            exit 0
 | 
				
			||||||
        fi
 | 
					        fi
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					    centos)
 | 
				
			||||||
 | 
					        if [ "$name_sysconfig" = "$name_should" -a "$name_running" = "$name_should" ]; then
 | 
				
			||||||
 | 
					            exit 0
 | 
				
			||||||
 | 
					        fi
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
 | 
					esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
################################################################################
 | 
					################################################################################
 | 
				
			||||||
# Setup hostname
 | 
					# Setup hostname
 | 
				
			||||||
| 
						 | 
					@ -45,6 +55,13 @@ echo changed >> "$__messages_out"
 | 
				
			||||||
if [ "$has_hostnamectl" ]; then
 | 
					if [ "$has_hostnamectl" ]; then
 | 
				
			||||||
    echo "hostnamectl set-hostname '$name_should'"
 | 
					    echo "hostnamectl set-hostname '$name_should'"
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
 | 
					    case "$os" in
 | 
				
			||||||
 | 
					        archlinux|debian|ubuntu)
 | 
				
			||||||
            echo "hostname '$name_should'"
 | 
					            echo "hostname '$name_should'"
 | 
				
			||||||
            echo "printf '%s\n' '$name_should' > /etc/hostname"
 | 
					            echo "printf '%s\n' '$name_should' > /etc/hostname"
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					        centos)
 | 
				
			||||||
 | 
					            echo "hostname '$name_should'"
 | 
				
			||||||
 | 
					        ;;
 | 
				
			||||||
 | 
					    esac
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -20,6 +20,12 @@
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
os=$(cat "$__global/explorer/os")
 | 
					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() {
 | 
					not_supported() {
 | 
				
			||||||
   echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
 | 
					   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
 | 
					        # handled in gencode-remote
 | 
				
			||||||
        :
 | 
					        :
 | 
				
			||||||
    ;;
 | 
					    ;;
 | 
				
			||||||
 | 
					    centos)
 | 
				
			||||||
 | 
					        __key_value sysconfig-hostname \
 | 
				
			||||||
 | 
					            --file /etc/sysconfig/network \
 | 
				
			||||||
 | 
					            --delimiter '=' \
 | 
				
			||||||
 | 
					            --key HOSTNAME \
 | 
				
			||||||
 | 
					            --value "$name_should" --exact_delimiter
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
    *)
 | 
					    *)
 | 
				
			||||||
        not_supported
 | 
					        not_supported
 | 
				
			||||||
    ;;
 | 
					    ;;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ Changelog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
3.1.3:
 | 
					3.1.3:
 | 
				
			||||||
	* New Type: __yum_repo (Steven Armstrong)
 | 
						* New Type: __yum_repo (Steven Armstrong)
 | 
				
			||||||
 | 
						* Type __hostname: Add support for CentOS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
3.1.2: 2014-04-12
 | 
					3.1.2: 2014-04-12
 | 
				
			||||||
	* Documentation: Add missing environment variables to reference
 | 
						* Documentation: Add missing environment variables to reference
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue