Debian Codegraph @

debian/tree/busybox-udeb/etc/udhcpc/default.script

raw
1 #!/bin/sh -e
2
3 # udhcpc client script to be used by Debian Installer
4 # Copyright (C) 2009, 2010 Otavio Salvador <[email protected]>
5
6 comma_separate() {
7 echo "$1" | sed 's/ /,/g'
8 }
9
10 do_resolv_conf() {
11 if [ -n "$domain$search$dns" ]; then
12 {
13 [ ! "$domain" ] || echo domain $domain
14 [ ! "$search" ] || echo search $search
15 for i in $dns ; do
16 echo nameserver $i
17 done
18 } > /etc/resolv.conf
19 fi
20 }
21
22 do_hostname() {
23 local current=$(cat /proc/sys/kernel/hostname)
24
25 if [ -z "$current" ] || [ "$current" = "(none)" ]; then
26 echo "$hostname" > /proc/sys/kernel/hostname
27 fi
28 }
29
30 do_leases() {
31 local file="/var/lib/udhcp/udhcpc.leases"
32
33 mkdir -p /var/lib/udhcp
34 cat >> $file <<EOF
35 lease {
36 interface "$interface";
37 fixed-address $ip;
38 filename "$boot_file";
39 option subnet-mask $subnet;
40 option domain-name "$domain";
41 option host-name "$hostname";
42 option domain-name-servers $(comma_separate "$dns");
43 option dhcp-server-identifier $serverid;
44 option dhcp-lease-time $lease;
45 option routers $(comma_separate "$router");
46 option ntp-servers $(comma_separate "$ntpsrv");
47 }
48 EOF
49 }
50
51 case "$1" in
52 deconfig)
53 ip link set "$interface" up
54 ip -4 addr flush dev "$interface"
55 ;;
56
57 bound|renew)
58 do_hostname
59
60 ip -4 addr add "$ip/$subnet" dev "$interface"
61
62 if [ -n "$mtu" ]; then
63 ip link set "$interface" mtu "$mtu"
64 fi
65
66 # special case for /32 subnets, use onlink when adding routes
67 [ ".$subnet" = .255.255.255.255 ] \
68 && onlink="dev $interface onlink" || onlink=
69 for r in "$router"; do
70 ip -4 route add default via "$r" $onlink
71 done
72
73 do_resolv_conf
74
75 # Get the domain name into a file suitable for netcfg to read.
76 printf "$domain" > /tmp/domain_name
77
78 if [ -n "$ntpsrv" ]; then
79 printf "$ntpsrv" > /tmp/dhcp-ntp-servers
80 fi
81
82 logger -t udhcpc "Got IP $ip (using $interface) and routing through $router"
83
84 do_leases
85 ;;
86 *)
87 echo "udhcpc: has been called with an unknown param: $1"
88 ;;
89 esac
90
91 exit 0