Contents of /trunk/udhcp/udhcpc.sh
Parent Directory | Revision Log
Revision 593 -
(show annotations)
(download)
(as text)
Sat May 17 10:46:18 2008 UTC (16 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 1420 byte(s)
Sat May 17 10:46:18 2008 UTC (16 years, 4 months ago) by niro
File MIME type: application/x-sh
File size: 1420 byte(s)
-udhcp client script
1 | #!/bin/sh |
2 | |
3 | # global options passed by udhcpc |
4 | # what to run |
5 | # $1 - which command to run, possible are: bound|deconfig|nak|renew |
6 | # router - routers address |
7 | # subnet - the subnet |
8 | # dhcptype - type of dhcp |
9 | # interface - which iface gets configured |
10 | # serverid - ip of the dhcd server |
11 | # dns - dns to use |
12 | # ip - ip-address to use |
13 | # lease - lease time of a dhcp configuration |
14 | # mask - network mask to use |
15 | |
16 | # renew dhcp leases |
17 | bound() |
18 | { |
19 | local RESOLV_CONF="/etc/resolv.conf" |
20 | local BROADCAST |
21 | local NETMASK |
22 | local i |
23 | |
24 | [[ -n ${broadcast} ]] && BROADCAST="broadcast ${broadcast}" |
25 | [[ -n ${subnet} ]] && NETMASK="netmask ${subnet}" |
26 | |
27 | /sbin/ifconfig ${interface} ${ip} ${BROADCAST} ${NETMASK} |
28 | |
29 | if [ -n "${router}" ] |
30 | then |
31 | echo "deleting routers" |
32 | while /sbin/route del default gw 0.0.0.0 dev ${interface} |
33 | do : |
34 | done |
35 | |
36 | metric=0 |
37 | for i in ${router} |
38 | do |
39 | /sbin/route add default gw ${i} dev ${interface} metric $((metric++)) |
40 | done |
41 | fi |
42 | |
43 | echo -n > ${RESOLV_CONF} |
44 | [[ -n ${domain} ]] && echo "domain ${domain}" >> ${RESOLV_CONF} |
45 | for i in ${dns} |
46 | do |
47 | echo adding dns ${i} |
48 | echo "nameserver ${i}" >> ${RESOLV_CONF} |
49 | done |
50 | } |
51 | |
52 | renew() |
53 | { |
54 | # same as bound() |
55 | bound |
56 | } |
57 | |
58 | deconfig() |
59 | { |
60 | /sbin/ifconfig ${interface} 0.0.0.0 |
61 | } |
62 | |
63 | # what to do if a dhcp request failed |
64 | nak() |
65 | { |
66 | echo "Received a NAK: ${message}" |
67 | } |
68 | |
69 | |
70 | case $1 in |
71 | bound) bound ;; |
72 | renew) renew ;; |
73 | deconfig) deconfig ;; |
74 | nak) nak ;; |
75 | esac |