summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2024-07-25 21:32:37 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2024-07-25 21:44:15 -0500
commit1c75bf370db4e8d467740e676a5d1dc2fc790ed7 (patch)
tree114fc382907ec8e3c8022debe5ebe3edb5e0e8ec
parentba6de6db466d30dd2dcb8f1c89c4a4bf5af80c20 (diff)
init.d/hostname: fix /etc/hostname processingorigin/improve-hostname
This is an alternative to #585 in which we keep the init script but use `hostname -F` to read the value from @SYSCONFDIR@/hostname. This allows for comments in the hostname file. Also, we deprecate using /etc/conf.d/* to set the host name.
-rw-r--r--init.d/hostname.in22
1 files changed, 16 insertions, 6 deletions
diff --git a/init.d/hostname.in b/init.d/hostname.in
index fc949336..f48f4521 100644
--- a/init.d/hostname.in
+++ b/init.d/hostname.in
@@ -19,18 +19,28 @@ depend()
start()
{
- local h source
- if read -r h _ 2> /dev/null < @SYSCONFDIR@/hostname; then
+ local source
+ if [ -s @SYSCONFDIR@/hostname ]; then
source="@SYSCONFDIR@/hostname"
elif [ -n "${hostname}" ]; then
- h=${hostname}
source="@SYSCONFDIR@/conf.d/${RC_SVCNAME}"
fi
- if [ -z "$h" ]; then
+ if [ -z "$source" ]; then
einfo "Using default system hostname"
return 0
fi
- ebegin "Setting hostname to $h from $source"
- hostname "$h"
+ if [ "$source" = "@SYSCONFDIR@/conf.d/$RC_SVCNAME" ]; then
+ ewarn "Setting hostname in @SYSCONFDIR@/conf.d/$RC_SVCNAME is deprecated"
+ ewarn "and will be removed in the future."
+ fi
+ ebegin "Setting hostname from $source"
+ if [ "$source" = "@SYSCONFDIR@/hostname" ]; then
+ hostname -F "$source"
+ else
+ hostname "$hostname"
+ fi
+ if [ $? ]; then
+ einfo "hostname set to $(hostname)"
+ fi
eend $? "Failed to set the hostname"
}