The Android Open Source Project | f7c5421 | 2009-03-03 19:29:22 -0800 | [diff] [blame] | 1 | # Lookup the hostname in DNS if not set |
| 2 | |
| 3 | lookup_hostname() |
| 4 | { |
Dmitry Shmidt | e86eee1 | 2011-01-24 16:27:51 -0800 | [diff] [blame] | 5 | [ -z "$new_ip_address" ] && return 1 |
The Android Open Source Project | f7c5421 | 2009-03-03 19:29:22 -0800 | [diff] [blame] | 6 | local h= |
| 7 | # Silly ISC programs love to send error text to stdout |
| 8 | if type dig >/dev/null 2>&1; then |
Dmitry Shmidt | e86eee1 | 2011-01-24 16:27:51 -0800 | [diff] [blame] | 9 | h=$(dig +short -x $new_ip_address) |
The Android Open Source Project | f7c5421 | 2009-03-03 19:29:22 -0800 | [diff] [blame] | 10 | if [ $? = 0 ]; then |
Dmitry Shmidt | e86eee1 | 2011-01-24 16:27:51 -0800 | [diff] [blame] | 11 | echo "$h" | sed 's/\.$//' |
The Android Open Source Project | f7c5421 | 2009-03-03 19:29:22 -0800 | [diff] [blame] | 12 | return 0 |
| 13 | fi |
| 14 | elif type host >/dev/null 2>&1; then |
Dmitry Shmidt | e86eee1 | 2011-01-24 16:27:51 -0800 | [diff] [blame] | 15 | h=$(host $new_ip_address) |
The Android Open Source Project | f7c5421 | 2009-03-03 19:29:22 -0800 | [diff] [blame] | 16 | if [ $? = 0 ]; then |
Dmitry Shmidt | e86eee1 | 2011-01-24 16:27:51 -0800 | [diff] [blame] | 17 | echo "$h" \ |
The Android Open Source Project | f7c5421 | 2009-03-03 19:29:22 -0800 | [diff] [blame] | 18 | | sed 's/.* domain name pointer \(.*\)./\1/' |
| 19 | return 0 |
| 20 | fi |
| 21 | fi |
| 22 | return 1 |
| 23 | } |
| 24 | |
| 25 | set_hostname() |
| 26 | { |
Dmitry Shmidt | e86eee1 | 2011-01-24 16:27:51 -0800 | [diff] [blame] | 27 | if [ -z "$new_host_name" -a -z "$new_fqdn_name" ]; then |
The Android Open Source Project | f7c5421 | 2009-03-03 19:29:22 -0800 | [diff] [blame] | 28 | export new_host_name="$(lookup_hostname)" |
| 29 | fi |
| 30 | } |
| 31 | |
Dmitry Shmidt | e86eee1 | 2011-01-24 16:27:51 -0800 | [diff] [blame] | 32 | if $if_up; then |
| 33 | set_hostname |
| 34 | fi |