aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2022-06-08 13:37:53 -0500
committerWilliam Hubbs <w.d.hubbs@gmail.com>2022-06-08 13:40:29 -0500
commitd2b31440708bd0cb70e5317e05b8ae80e4866269 (patch)
treee93fa6157dfa64435439373223dee616ee7d75db
parentcddb29507dfb9f8a3cac88b4611289c724529ca8 (diff)
clean up hostname service script
- use _ throw-away variable to get rid of a shellcheck warning - remove tests for /etc/hostname and just try to read it - drop reference to bash HOSTNAME variable. - make source of host name more accurate X-Gentoo-Bug: 850577 X-Gentoo-Bug-URL: https://bugs.gentoo.org/850577
-rw-r--r--init.d/hostname.in16
1 files changed, 7 insertions, 9 deletions
diff --git a/init.d/hostname.in b/init.d/hostname.in
index 5d597ad5..3d70a2f3 100644
--- a/init.d/hostname.in
+++ b/init.d/hostname.in
@@ -19,20 +19,18 @@ depend()
start()
{
- local h source x
- if [ -s /etc/hostname ] && [ -r /etc/hostname ]; then
- read h x </etc/hostname
- source="from /etc/hostname"
- else
- # HOSTNAME variable used to be defined in caps in conf.d/hostname.
- # It is also a magic variable in bash.
- h=${hostname:-${HOSTNAME}} # checkbashisms: false positive (HOSTNAME var)
+ local h source
+ if read -r h _ 2> /dev/null < @SYSCONFDIR@/hostname; then
+ source="@SYSCONFDIR@/hostname"
+ elif [ -n "${hostname}" ]; then
+ h=${hostname}
+ source="@SYSCONFDIR@/conf.d/${RC_SVCNAME}"
fi
if [ -z "$h" ]; then
einfo "Using default system hostname"
return 0
fi
- ebegin "Setting hostname to $h $source"
+ ebegin "Setting hostname to $h from $source"
hostname "$h"
eend $? "Failed to set the hostname"
}