add hotplug stuff to trunk/
[openwrt-10.03/.git] / package / base-files / default / usr / share / udhcpc / default.script
1 #!/bin/sh
2 [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
3
4 RESOLV_CONF="/tmp/resolv.conf"
5
6 hotplug_event() {
7         nvram show 2>&- | grep _proto=dhcp | {
8                 while :; do
9                         read FOO
10                         [ -z "$FOO" ] && break
11                         FOO="${FOO%%_*}"
12                         [ "$(nvram get ${FOO}_ifname)" = "${interface}" ] || continue
13                         env -i ACTION="$1" INTERFACE="${FOO}" PROTO=dhcp /sbin/hotplug iface
14                 done
15         }
16 }
17
18 case "$1" in
19         deconfig)
20                 ifconfig $interface 0.0.0.0
21                 hotplug_event ifdown
22         ;;
23         renew|bound)
24                 ifconfig $interface $ip \
25                 netmask ${subnet:-255.255.255.0} \
26                 broadcast ${broadcast:-+}
27
28                 if [ -n "$router" ] ; then
29                         echo "deleting routers"
30                         while route del default gw 0.0.0.0 dev $interface ; do :; done
31                                         
32                         for i in $router ; do
33                                 route add default gw $i dev $interface
34                         done
35                 fi
36
37                 echo -n > $RESOLV_CONF
38                 ${domain:+echo search $domain} >> $RESOLV_CONF
39                 for i in $dns ; do
40                         echo adding dns $i
41                         echo nameserver $i >> $RESOLV_CONF
42                 done
43                 
44                 hotplug_event ifup
45                 
46                 # user rules
47                 [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
48         ;;
49 esac
50
51 exit 0