2017-06-28 11:19:32 +00:00
|
|
|
#!/bin/sh -e
|
2014-01-20 12:47:45 +00:00
|
|
|
#
|
|
|
|
# 2012 Steven Armstrong (steven-cdist at armstrong.cc)
|
2014-01-20 12:50:42 +00:00
|
|
|
# 2014 Nico Schottelius (nico-cdist at schottelius.org)
|
2019-08-15 14:15:47 +00:00
|
|
|
# 2019 Dennis Camera (dennis.camera at ssrq-sds-fds.ch)
|
2014-01-20 12:47:45 +00:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
os=$(cat "$__global/explorer/os")
|
2014-04-24 23:48:58 +00:00
|
|
|
if [ -f "$__object/parameter/name" ]; then
|
|
|
|
name_should="$(cat "$__object/parameter/name")"
|
|
|
|
else
|
2016-09-02 15:39:22 +00:00
|
|
|
case "$os" in
|
2019-10-06 16:02:24 +00:00
|
|
|
# RedHat-derivatives and BSDs
|
|
|
|
centos|fedora|redhat|scientific|freebsd|netbsd|openbsd)
|
|
|
|
# Hostname is FQDN
|
2018-10-05 09:34:10 +00:00
|
|
|
name_should="${__target_host}"
|
2016-09-02 15:39:22 +00:00
|
|
|
;;
|
|
|
|
*)
|
2019-10-06 16:02:24 +00:00
|
|
|
# Hostname is only first component of FQDN
|
2018-10-05 09:34:10 +00:00
|
|
|
name_should="${__target_host%%.*}"
|
2016-09-02 15:39:22 +00:00
|
|
|
;;
|
|
|
|
esac
|
2014-04-24 23:48:58 +00:00
|
|
|
fi
|
|
|
|
|
2014-01-20 12:47:45 +00:00
|
|
|
|
|
|
|
not_supported() {
|
|
|
|
echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2
|
|
|
|
echo "Please contribute an implementation for it if you can." >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$os" in
|
2019-08-15 14:16:38 +00:00
|
|
|
archlinux|debian|suse|ubuntu|devuan|coreos|alpine|macosx)
|
2014-04-24 23:48:58 +00:00
|
|
|
# handled in gencode-remote
|
|
|
|
:
|
|
|
|
;;
|
2019-10-06 15:56:37 +00:00
|
|
|
centos|fedora|redhat|scientific)
|
2014-04-24 23:48:58 +00:00
|
|
|
__key_value sysconfig-hostname \
|
|
|
|
--file /etc/sysconfig/network \
|
2019-10-06 16:01:58 +00:00
|
|
|
--delimiter '=' --exact_delimiter \
|
2014-04-24 23:48:58 +00:00
|
|
|
--key HOSTNAME \
|
2019-10-06 16:01:58 +00:00
|
|
|
--value "\"$name_should\""
|
2014-04-24 23:48:58 +00:00
|
|
|
;;
|
2018-03-26 06:53:31 +00:00
|
|
|
freebsd)
|
|
|
|
__key_value rcconf-hostname \
|
|
|
|
--file /etc/rc.conf \
|
2019-10-06 16:01:58 +00:00
|
|
|
--delimiter '=' --exact_delimiter \
|
2018-03-26 06:53:31 +00:00
|
|
|
--key 'hostname' \
|
|
|
|
--value "$name_should"
|
|
|
|
;;
|
2019-10-05 18:10:52 +00:00
|
|
|
netbsd)
|
|
|
|
__key_value rcconf-hostname \
|
|
|
|
--file /etc/rc.conf \
|
2019-10-06 16:01:58 +00:00
|
|
|
--delimiter '=' --exact_delimiter \
|
2019-10-05 18:10:52 +00:00
|
|
|
--key 'hostname' \
|
|
|
|
--value "\"$name_should\""
|
|
|
|
# To avoid confusion, ensure that the hostname is only stored once
|
|
|
|
__file /etc/myname --state absent
|
|
|
|
;;
|
2016-09-02 15:39:22 +00:00
|
|
|
openbsd)
|
|
|
|
echo "$name_should" | __file /etc/myname --source -
|
|
|
|
;;
|
2014-04-24 23:48:58 +00:00
|
|
|
*)
|
2019-08-15 14:15:47 +00:00
|
|
|
# On other operating systems we fall back to hostnamectl if available…
|
|
|
|
test -n "$(cat "$__object/explorer/has_hostnamectl")" || not_supported
|
2014-04-24 23:48:58 +00:00
|
|
|
;;
|
2014-01-20 12:47:45 +00:00
|
|
|
esac
|