mirror of
https://github.com/rsmarples/dhcpcd.git
synced 2024-11-25 11:03:29 +08:00
Try and support more systems without hostname(1)
This commit is contained in:
parent
9a862f317e
commit
3ea7cb598f
@ -6,17 +6,32 @@ _hostname()
|
||||
local name=
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
if [ -r /proc/sys/kernel/hostname ]; then
|
||||
read name </proc/sys/kernel/hostname && echo "$name"
|
||||
else
|
||||
if type hostname >/dev/null 2>&1; then
|
||||
hostname
|
||||
elif [ -r /proc/sys/kernel/hostname ]; then
|
||||
read name </proc/sys/kernel/hostname && echo "$name"
|
||||
elif sysctl kern.hostname >/dev/null 2>&1; then
|
||||
sysctl -n kern.hostname
|
||||
elif sysctl kernel.hostname >/dev/null 2>&1; then
|
||||
sysctl -n kernel.hostname
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ -w /proc/sys/kernel/hostname ]; then
|
||||
# Always prefer hostname(1) if we have it
|
||||
if type hostname >/dev/null 2>&1; then
|
||||
hostname "$1"
|
||||
elif [ -w /proc/sys/kernel/hostname ]; then
|
||||
echo "$1" >/proc/sys/kernel/hostname
|
||||
elif sysctl kern.hostname >/dev/null 2>&1; then
|
||||
sysctl -w "kern.hostname=$1"
|
||||
elif sysctl kernel.hostname >/dev/null 2>&1; then
|
||||
sysctl -w "kernel.hostname=$1"
|
||||
else
|
||||
# We know this will fail, but it will now fail
|
||||
# with an error to stdout
|
||||
hostname "$1"
|
||||
fi
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user