[__hostname] Only write to distro specific file when hostnamectl is missing

This commit is contained in:
Dennis Camera 2019-10-12 18:47:27 +02:00
parent c11e757dfa
commit 30c7d153e8
2 changed files with 26 additions and 11 deletions

View file

@ -78,6 +78,11 @@ in
echo "printf '%s\\n' '$name_should' > /etc/hostname"
echo "hostname -F /etc/hostname"
;;
gentoo)
# NOTE: Writing the hostname to file is done in the manifest for OpenRC.
# For systemd hostnamectl should take care of that.
echo "hostname '$name_should'"
;;
macosx)
echo "scutil --set HostName '$name_should'"
;;
@ -87,7 +92,7 @@ in
echo "printf '%s\\n' '$name_should' > /etc/HOSTNAME"
echo 'hostname -F /etc/HOSTNAME'
;;
centos|fedora|freebsd|gentoo|netbsd|openbsd|redhat|scientific)
centos|fedora|freebsd|netbsd|openbsd|redhat|scientific)
# NOTE: Writing the hostname to file is done in the manifest.
echo "hostname '$name_should'"
;;

View file

@ -52,18 +52,28 @@ in
:
;;
centos|fedora|redhat|scientific)
__key_value sysconfig-hostname \
--file /etc/sysconfig/network \
--delimiter '=' --exact_delimiter \
--key HOSTNAME \
--value "\"$name_should\""
if test -z "$(cat "$__object/explorer/has_hostnamectl")"
then
# Only write to /etc/sysconfig/network on non-systemd versions.
# On systemd-based versions this entry is ignored.
__key_value sysconfig-hostname \
--file /etc/sysconfig/network \
--delimiter '=' --exact_delimiter \
--key HOSTNAME \
--value "\"$name_should\""
fi
;;
gentoo)
__key_value confd-hostname \
--file /etc/conf.d/hostname \
--delimiter '=' --exact_delimiter \
--key 'hostname' \
--value "\"$name_should\""
if test -z "$(cat "$__object/explorer/has_hostnamectl")"
then
# Only write to /etc/conf.d/hostname on OpenRC-based installations.
# On systemd use hostnamectl(1) in gencode-remote.
__key_value confd-hostname \
--file /etc/conf.d/hostname \
--delimiter '=' --exact_delimiter \
--key 'hostname' \
--value "\"$name_should\""
fi
;;
freebsd)
__key_value rcconf-hostname \