17827cba2SAaron LI# Lookup the hostname in DNS if not set 27827cba2SAaron LI 37827cba2SAaron LIlookup_hostname() 47827cba2SAaron LI{ 57827cba2SAaron LI [ -z "$new_ip_address" ] && return 1 67827cba2SAaron LI # Silly ISC programs love to send error text to stdout 7*80aa9461SRoy Marples if command -v dig >/dev/null 2>&1; then 87827cba2SAaron LI h=$(dig +short -x $new_ip_address) 97827cba2SAaron LI if [ $? = 0 ]; then 107827cba2SAaron LI echo "$h" | sed 's/\.$//' 117827cba2SAaron LI return 0 127827cba2SAaron LI fi 13*80aa9461SRoy Marples elif command -v host >/dev/null 2>&1; then 147827cba2SAaron LI h=$(host $new_ip_address) 157827cba2SAaron LI if [ $? = 0 ]; then 167827cba2SAaron LI echo "$h" \ 177827cba2SAaron LI | sed 's/.* domain name pointer \(.*\)./\1/' 187827cba2SAaron LI return 0 197827cba2SAaron LI fi 20*80aa9461SRoy Marples elif command -v getent >/dev/null 2>&1; then 217827cba2SAaron LI h=$(getent hosts $new_ip_address) 227827cba2SAaron LI if [ $? = 0 ]; then 237827cba2SAaron LI echo "$h" | sed 's/[^ ]* *\([^ ]*\).*/\1/' 247827cba2SAaron LI return 0 257827cba2SAaron LI fi 267827cba2SAaron LI fi 277827cba2SAaron LI return 1 287827cba2SAaron LI} 297827cba2SAaron LI 307827cba2SAaron LIset_hostname() 317827cba2SAaron LI{ 328d36e1dfSRoy Marples if [ -z "${new_host_name}${new_fqdn_name}" ]; then 337827cba2SAaron LI export new_host_name="$(lookup_hostname)" 347827cba2SAaron LI fi 357827cba2SAaron LI} 367827cba2SAaron LI 377827cba2SAaron LIif $if_up; then 387827cba2SAaron LI set_hostname 397827cba2SAaron LIfi 40