]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Move looking up the hostname in DNS to a sample hook file as it's not something we...
authorRoy Marples <roy@marples.name>
Tue, 22 Apr 2008 10:41:57 +0000 (10:41 +0000)
committerRoy Marples <roy@marples.name>
Tue, 22 Apr 2008 10:41:57 +0000 (10:41 +0000)
README
dhcpcd.8.in
dhcpcd.sh.in
hook-samples/dhcpcd-compat.sh [moved from hook-samples/dhcpcd-compat with 100% similarity]
hook-samples/lookup_hostname.sh [new file with mode: 0644]
hook-samples/ntp.sh [moved from hook-samples/ntp with 99% similarity]
hook-samples/ypbind.sh [moved from hook-samples/ypbind with 99% similarity]

diff --git a/README b/README
index 77890a828be1606148806d0f150297614998642a..5c53ea0c631628e92fc2924d98b60992288eb23f 100644 (file)
--- a/README
+++ b/README
@@ -42,7 +42,8 @@ commandline compatible with prior versions.
 
 Hooks
 -----
-We provide example exit hooks for NTP (www.ntp.org) and ypbind (Linux).
+We provide example exit hooks for looking up the hostname in DNS,
+NTP (www.ntp.org) and ypbind (Linux).
 There are not installed by default as they are platform dependant.
 
 
index 8ff4f6053ea2e1d4a94c20961996f0409c6a13dc..fa4f00de767aa7a83c51b60dd00a6a803c9dc443 100644 (file)
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd Apr 13, 2008
+.Dd Apr 22, 2008
 .Dt DHCPCD 8 SMM
 .Sh NAME
 .Nm dhcpcd
@@ -71,8 +71,7 @@ if available, otherwise directly to
 .Pa /etc/resolv.conf .
 If the hostname is currenly blank, (null) or localhost then
 .Nm
-will set the hostname to the one supplied by the DHCP server, or look it up
-in DNS if none supplied.
+will set the hostname to the one supplied by the DHCP server.
 .Nm
 then daemonises and waits for the lease renewal time to lapse.
 Then it attempts to renew its lease and reconfigure if the new lease changes.
index 5915d00c636beef25929144ec2651130b7b6da23..f7fb01bd286788b8541820417da2285cebb31d3b 100644 (file)
@@ -87,38 +87,15 @@ restore_resolv_conf()
 need_hostname()
 {
        case "$(hostname)" in
-               ""|"(none)"|localhost) return 0;;
+               ""|"(none)"|localhost|"${old_host_name}") return 0;;
        esac
        return 1
 }
 
-lookup_hostname()
-{
-       local h=
-       # Silly ISC programs love to send error text to stdout
-       if type host >/dev/null 2>&1; then
-               h=`host ${new_ip_address}`
-               if [ $? = 0 ]; then 
-                       echo "${h}" \
-                       | sed 's/.* domain name pointer \(.*\)./\1/'
-                       return 0
-               fi
-       elif type dig >/dev/null 2>&1; then
-               h=`dig +short -x ${new_ip_address}`
-               if [ $? = 0 ]; then
-                       echo "${h}" | sed 's/\.$//'
-                       return 0
-               fi
-       fi
-       return 1
-}
-
 set_hostname()
 {
-       if [ -n "${old_host_name}" ] || need_hostname; then
-               local name="${new_host_name}"
-               [ -z "${name}" ] && name="$(lookup_hostname)"
-               [ -n "${name}" ] && hostname "${name}"
+       if need_hostname; then
+               hostname "${new_host_name}"
        fi
 }
 
diff --git a/hook-samples/lookup_hostname.sh b/hook-samples/lookup_hostname.sh
new file mode 100644 (file)
index 0000000..c829b2d
--- /dev/null
@@ -0,0 +1,46 @@
+# Sample exit hook to lookup the hostname in DNS if not set
+
+lookup_hostname()
+{
+       local h=
+       # Silly ISC programs love to send error text to stdout
+       if type dig >/dev/null 2>&1; then
+               h=`dig +short -x ${new_ip_address}`
+               if [ $? = 0 ]; then
+                       echo "${h}" | sed 's/\.$//'
+                       return 0
+               fi
+       elif type host >/dev/null 2>&1; then
+               h=`host ${new_ip_address}`
+               if [ $? = 0 ]; then 
+                       echo "${h}" \
+                       | sed 's/.* domain name pointer \(.*\)./\1/'
+                       return 0
+               fi
+       fi
+       return 1
+}
+
+do_hostname()
+{
+       if [ -z "${new_host_name}" ] && need_hostname; then
+               local hname="$(lookup_hostname)"
+               if [ -n "${hname}" ]; then
+                       hostname "${hname}"
+               fi
+       fi
+}
+
+case "${reason}" in
+       TEST)
+               ;;
+       BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)
+               do_hostname
+               ;;
+       EXPIRE|FAIL|IPV4LL|RELEASE|STOP)
+               ;;
+       *)
+               echo "lookup_hostname: unsupported reason ${reason}" >&2
+               false
+               ;;
+esac
similarity index 99%
rename from hook-samples/ntp
rename to hook-samples/ntp.sh
index c0a6a7b0272a13924e4db6c15798aff286ae50a2..ff8e8fbb306d13e35fd9c71b8403d5fd87184221 100644 (file)
@@ -1,4 +1,3 @@
-#!/bin/sh
 # Sample exit hook script for ntp
 
 # Detect OpenRC or BSD rc
similarity index 99%
rename from hook-samples/ypbind
rename to hook-samples/ypbind.sh
index 7637720baf561f257f8778077da327ca1ca3f36e..64d96fef7f61ed4d58ce8d7a00082850463c7618 100644 (file)
@@ -1,4 +1,3 @@
-#!/bin/sh
 # Sample exit hook for ypbind
 # This script is only suitable for the Linux version.