Home | History | Annotate | Line # | Download | only in hooks
      1 # Lookup the hostname in DNS if not set
      2 
      3 lookup_hostname()
      4 {
      5 	[ -z "$new_ip_address" ] && return 1
      6 	# Silly ISC programs love to send error text to stdout
      7 	if command -v dig >/dev/null 2>&1; then
      8 		h=$(dig +short -x $new_ip_address)
      9 		if [ $? = 0 ]; then
     10 			echo "$h" | sed 's/\.$//'
     11 			return 0
     12 		fi
     13 	elif command -v host >/dev/null 2>&1; then
     14 		h=$(host $new_ip_address)
     15 		if [ $? = 0 ]; then 
     16 			echo "$h" \
     17 			| sed 's/.* domain name pointer \(.*\)./\1/'
     18 			return 0
     19 		fi
     20 	elif command -v getent >/dev/null 2>&1; then
     21 		h=$(getent hosts $new_ip_address)
     22 		if [ $? = 0 ]; then
     23 			echo "$h" | sed 's/[^ ]* *\([^ ]*\).*/\1/'
     24 			return 0
     25 		 fi
     26 	fi
     27 	return 1
     28 }
     29 
     30 set_hostname()
     31 {
     32 	if [ -z "${new_host_name}${new_fqdn_name}" ]; then
     33 		export new_host_name="$(lookup_hostname)"
     34 	fi
     35 }
     36 
     37 if $if_up; then
     38 	set_hostname
     39 fi
     40