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
This commit is contained in:
William Hubbs 2022-06-08 13:37:53 -05:00
parent cddb29507d
commit d2b3144070

View File

@ -19,20 +19,18 @@ depend()
start() start()
{ {
local h source x local h source
if [ -s /etc/hostname ] && [ -r /etc/hostname ]; then if read -r h _ 2> /dev/null < @SYSCONFDIR@/hostname; then
read h x </etc/hostname source="@SYSCONFDIR@/hostname"
source="from /etc/hostname" elif [ -n "${hostname}" ]; then
else h=${hostname}
# HOSTNAME variable used to be defined in caps in conf.d/hostname. source="@SYSCONFDIR@/conf.d/${RC_SVCNAME}"
# It is also a magic variable in bash.
h=${hostname:-${HOSTNAME}} # checkbashisms: false positive (HOSTNAME var)
fi fi
if [ -z "$h" ]; then if [ -z "$h" ]; then
einfo "Using default system hostname" einfo "Using default system hostname"
return 0 return 0
fi fi
ebegin "Setting hostname to $h $source" ebegin "Setting hostname to $h from $source"
hostname "$h" hostname "$h"
eend $? "Failed to set the hostname" eend $? "Failed to set the hostname"
} }