awx: variable initialization fix
[openwrt/svn-archive/archive.git] / package / base-files / files / usr / share / udhcpc / default.script
1 #!/bin/sh
2 [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
3 . /etc/functions.sh
4 include /lib/network
5
6 RESOLV_CONF="/tmp/resolv.conf.auto"
7
8 hotplug_event() {
9 scan_interfaces
10 for ifc in $interfaces; do
11 config_get ifname $ifc ifname
12 [ "$ifname" = "$interface" ] || continue
13
14 config_get proto $ifc proto
15 [ "$proto" = "dhcp" ] || continue
16
17 env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
18 done
19 }
20
21 case "$1" in
22 deconfig)
23 ifconfig $interface 0.0.0.0
24 hotplug_event ifdown
25 ;;
26 renew|bound)
27 ifconfig $interface $ip \
28 netmask ${subnet:-255.255.255.0} \
29 broadcast ${broadcast:-+}
30
31 [ "$router"] && {
32 for i in $router ; do
33 echo "adding router $i"
34 route add default gw $i dev $interface
35 valid="$valid|$i"
36
37 done
38
39 echo "deleting old routes"
40 $(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}')
41 }
42
43 [ -n "$dns" ] && {
44 echo -n > $RESOLV_CONF
45 ${domain:+echo search $domain} >> $RESOLV_CONF
46 for i in $dns ; do
47 echo "adding dns $i"
48 echo "nameserver $i" >> $RESOLV_CONF
49 done
50 }
51
52 hotplug_event ifup
53
54 # user rules
55 [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
56 ;;
57 esac
58
59 exit 0