Skip to content

Commit 1c75bf3

Browse files
committed
init.d/hostname: fix /etc/hostname processing
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.
1 parent ba6de6d commit 1c75bf3

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

init.d/hostname.in

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,28 @@ depend()
1919

2020
start()
2121
{
22-
local h source
23-
if read -r h _ 2> /dev/null < @SYSCONFDIR@/hostname; then
22+
local source
23+
if [ -s @SYSCONFDIR@/hostname ]; then
2424
source="@SYSCONFDIR@/hostname"
2525
elif [ -n "${hostname}" ]; then
26-
h=${hostname}
2726
source="@SYSCONFDIR@/conf.d/${RC_SVCNAME}"
2827
fi
29-
if [ -z "$h" ]; then
28+
if [ -z "$source" ]; then
3029
einfo "Using default system hostname"
3130
return 0
3231
fi
33-
ebegin "Setting hostname to $h from $source"
34-
hostname "$h"
32+
if [ "$source" = "@SYSCONFDIR@/conf.d/$RC_SVCNAME" ]; then
33+
ewarn "Setting hostname in @SYSCONFDIR@/conf.d/$RC_SVCNAME is deprecated"
34+
ewarn "and will be removed in the future."
35+
fi
36+
ebegin "Setting hostname from $source"
37+
if [ "$source" = "@SYSCONFDIR@/hostname" ]; then
38+
hostname -F "$source"
39+
else
40+
hostname "$hostname"
41+
fi
42+
if [ $? ]; then
43+
einfo "hostname set to $(hostname)"
44+
fi
3545
eend $? "Failed to set the hostname"
3646
}

0 commit comments

Comments
 (0)