Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 1 | #!/bin/sh |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 2 | # udhcpc script edited by Tim Riker <Tim@Rikers.org> |
| 3 | |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 4 | RESOLV_CONF="/etc/resolv.conf" |
Denis Vlasenko | 1b47bbd | 2009-04-21 00:17:00 +0000 | [diff] [blame] | 5 | |
Denys Vlasenko | c8ab67c | 2009-05-10 23:27:43 +0200 | [diff] [blame] | 6 | [ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; } |
Denis Vlasenko | 1b47bbd | 2009-04-21 00:17:00 +0000 | [diff] [blame] | 7 | |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 8 | NETMASK="" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 9 | [ -n "$subnet" ] && NETMASK="netmask $subnet" |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 10 | BROADCAST="broadcast +" |
| 11 | [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 12 | |
| 13 | case "$1" in |
| 14 | deconfig) |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 15 | echo "Setting IP address 0.0.0.0 on $interface" |
| 16 | ifconfig $interface 0.0.0.0 |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 17 | ;; |
| 18 | |
| 19 | renew|bound) |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 20 | echo "Setting IP address $ip on $interface" |
| 21 | ifconfig $interface $ip $NETMASK $BROADCAST |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 22 | |
| 23 | if [ -n "$router" ] ; then |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 24 | echo "Deleting routers" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 25 | while route del default gw 0.0.0.0 dev $interface ; do |
| 26 | : |
| 27 | done |
| 28 | |
Eric Andersen | 1aee3ff | 2004-10-13 07:18:05 +0000 | [diff] [blame] | 29 | metric=0 |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 30 | for i in $router ; do |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 31 | echo "Adding router $i" |
Eric Andersen | 1aee3ff | 2004-10-13 07:18:05 +0000 | [diff] [blame] | 32 | route add default gw $i dev $interface metric $((metric++)) |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 33 | done |
| 34 | fi |
| 35 | |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 36 | echo "Recreating $RESOLV_CONF" |
| 37 | echo -n > $RESOLV_CONF-$$ |
Denis Vlasenko | 1b47bbd | 2009-04-21 00:17:00 +0000 | [diff] [blame] | 38 | [ -n "$domain" ] && echo "search $domain" >> $RESOLV_CONF-$$ |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 39 | for i in $dns ; do |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 40 | echo " Adding DNS server $i" |
Denis Vlasenko | 1b47bbd | 2009-04-21 00:17:00 +0000 | [diff] [blame] | 41 | echo "nameserver $i" >> $RESOLV_CONF-$$ |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 42 | done |
Denis Vlasenko | ea4f084 | 2009-04-16 20:04:09 +0000 | [diff] [blame] | 43 | mv $RESOLV_CONF-$$ $RESOLV_CONF |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 44 | ;; |
| 45 | esac |
| 46 | |
| 47 | exit 0 |