]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Try and support more systems without hostname(1)
authorRoy Marples <roy@marples.name>
Sun, 2 Jun 2013 15:18:50 +0000 (15:18 +0000)
committerRoy Marples <roy@marples.name>
Sun, 2 Jun 2013 15:18:50 +0000 (15:18 +0000)
dhcpcd-hooks/30-hostname

index 7cfeb6fcc455690297143a1fc0de7b6c040645bf..35d7e867f70ceac2146cba96fd0240e2bdff0936 100644 (file)
@@ -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 </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
-                       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
 }