1 |
< |
#!/usr/local/bin/bash |
2 |
< |
# Update |
1 |
> |
#!/bin/sh |
2 |
> |
# DHCP Client Exit Hooks |
3 |
|
# |
4 |
|
# Douglas Thrift |
5 |
|
# |
6 |
|
# $Id$ |
7 |
|
|
8 |
< |
read -e hostname interface name secret < ~/.update || exit $? |
8 |
> |
%%key%% |
9 |
> |
%%secret%% |
10 |
> |
%%hostname%% |
11 |
|
|
12 |
< |
old=`host $hostname | sed -Ee "s/^$hostname has address ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})$/\1/p;d"` |
13 |
< |
address=`ifconfig $interface | sed -Ee 's/^ inet ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) netmask 0x[0-9a-f]{8} broadcast [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/\1/p;d'` |
14 |
< |
|
15 |
< |
if [[ $old != $address ]]; then |
16 |
< |
nsupdate <<-EOF |
17 |
< |
key $name $secret |
18 |
< |
update delete $hostname A |
19 |
< |
update add $hostname 3600 A $address |
20 |
< |
send |
21 |
< |
EOF |
22 |
< |
fi |
12 |
> |
case $reason in |
13 |
> |
BOUND|RENEW|REBIND|REBOOT) |
14 |
> |
if [ "$old_ip_address" != "$new_ip_address" ]; then |
15 |
> |
nsupdate -d <<-EOF |
16 |
> |
key $key $secret |
17 |
> |
update delete $hostname A |
18 |
> |
update add $hostname 3600 A $new_ip_address |
19 |
> |
send |
20 |
> |
EOF |
21 |
> |
fi |
22 |
> |
;; |
23 |
> |
esac |