From: Roy Marples Date: Sun, 2 Jun 2013 15:18:50 +0000 (+0000) Subject: Try and support more systems without hostname(1) X-Git-Tag: v5.99.7~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3ea7cb598ff975e7a63b334f69e2508a3b9dbad3;p=thirdparty%2Fdhcpcd.git Try and support more systems without hostname(1) --- diff --git a/dhcpcd-hooks/30-hostname b/dhcpcd-hooks/30-hostname index 7cfeb6fc..35d7e867 100644 --- a/dhcpcd-hooks/30-hostname +++ b/dhcpcd-hooks/30-hostname @@ -6,17 +6,32 @@ _hostname() local name= if [ -z "$1" ]; then - if [ -r /proc/sys/kernel/hostname ]; then + if type hostname >/dev/null 2>&1; then + hostname + elif [ -r /proc/sys/kernel/hostname ]; then read name /dev/null 2>&1; then + sysctl -n kern.hostname + elif sysctl kernel.hostname >/dev/null 2>&1; then + sysctl -n kernel.hostname else - hostname + 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 }