summaryrefslogtreecommitdiff
path: root/examples/udhcp/simple.script
blob: ae093164092c8b86ab9bc272a893b6c27f0d0d79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh

# udhcpc script edited by Tim Riker <Tim@Rikers.org>

[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

RESOLV_CONF="/etc/resolv.conf"
NETMASK=""
[ -n "$subnet" ] && NETMASK="netmask $subnet"
BROADCAST="broadcast +"
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"

case "$1" in
	deconfig)
		echo "Setting IP address 0.0.0.0 on $interface"
		ifconfig $interface 0.0.0.0
		;;

	renew|bound)
		echo "Setting IP address $ip on $interface"
		ifconfig $interface $ip $NETMASK $BROADCAST

		if [ -n "$router" ] ; then
			echo "Deleting routers"
			while route del default gw 0.0.0.0 dev $interface ; do
				:
			done

			metric=0
			for i in $router ; do
				echo "Adding router $i"
				route add default gw $i dev $interface metric $((metric++))
			done
		fi

		echo "Recreating $RESOLV_CONF"
		echo -n > $RESOLV_CONF-$$
		[ -n "$domain" ] && echo search $domain >> $RESOLV_CONF-$$
		for i in $dns ; do
			echo " Adding DNS server $i"
			echo nameserver $i >> $RESOLV_CONF-$$
		done
		mv $RESOLV_CONF-$$ $RESOLV_CONF
		;;
esac

exit 0