Skip to content

Commit

Permalink
init.d/hostname: fix /etc/hostname processing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
williamh committed Jul 26, 2024
1 parent ba6de6d commit 1c75bf3
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions init.d/hostname.in
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 1c75bf3

Please sign in to comment.