diff options
Diffstat (limited to 'dhcpcd-hooks/29-lookup-hostname')
-rw-r--r-- | dhcpcd-hooks/29-lookup-hostname | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/dhcpcd-hooks/29-lookup-hostname b/dhcpcd-hooks/29-lookup-hostname new file mode 100644 index 0000000..3dfade3 --- /dev/null +++ b/dhcpcd-hooks/29-lookup-hostname @@ -0,0 +1,34 @@ +# Lookup the hostname in DNS if not set + +lookup_hostname() +{ + [ -z "${new_ip_address}" ] && return 1 + 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 +} + +set_hostname() +{ + if [ -z "${new_host_name}" -a -z "${new_fqdn_name}" ]; then + export new_host_name="$(lookup_hostname)" + fi +} + +case "${reason}" in +BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_hostname;; +esac |