/[baselayout]/branches/baselayout-1_12/net-scripts/net.modules.d/dhcpcd
Gentoo

Contents of /branches/baselayout-1_12/net-scripts/net.modules.d/dhcpcd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1302 - (show annotations) (download)
Thu Jul 14 16:29:45 2005 UTC (9 years ago) by uberlord
File size: 4202 byte(s)
New pump and dhcpcd helpers as pump now does everything it should - weeeeee
1 #!/bin/bash
2 # Copyright (c) 2004-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4
5 # Contributed by Roy Marples (uberlord@gentoo.org)
6
7 # Fix any potential localisation problems
8 # Note that LC_ALL trumps LC_anything_else according to locale(7)
9 dhcpcd() {
10 LC_ALL=C /sbin/dhcpcd "$@"
11 }
12
13 # char* dhcpcd_provides(void)
14 #
15 # Returns a string to change module definition for starting up
16 dhcpcd_provides() {
17 echo "dhcp"
18 }
19
20 # void dhcpcd_depend(void)
21 #
22 # Sets up the dependancies for the module
23 dhcpcd_depend() {
24 after interface
25 }
26
27 # bool dhcpcd_check_installed(void)
28 #
29 # Returns 1 if dhcpcd is installed, otherwise 0
30 dhcpcd_check_installed() {
31 if [[ -x /sbin/dhcpcd ]]; then
32 if dhcpcd -h 2>&1 | grep -q "etcDir" ; then
33 return 0
34 else
35 ${1:-false} && eerror "We require dhcpcd-1.3.22_p4-r10"
36 return 1
37 fi
38 fi
39
40 ${1:-false} && eerror "For DHCP (dhcpcd) support, emerge net-misc/dhcpcd"
41 return 1
42 }
43
44 # bool dhcpcd_check_depends(void)
45 #
46 # Checks to see if we have the needed functions
47 dhcpcd_check_depends() {
48 local f
49
50 for f in interface_exists interface_get_address; do
51 [[ $( type -t ${f} ) == "function" ]] && continue
52 eerror "dhcpcd: missing required function ${f}\n"
53 return 1
54 done
55
56 return 0
57 }
58
59 # char* dhcpcd_get_vars(char *interface)
60 #
61 # Returns a string spaced with possible user set
62 # configuration variables
63 dhcpcd_get_vars() {
64 echo "dhcpcd_$1 dhcp_$1"
65 }
66
67 # bool dhcpcd_stop(char *iface)
68 #
69 # Stop DHCP on an interface by calling dhcpcd -z $iface
70 #
71 # Returns 0 (true) when a DHCP address dropped
72 # otherwise return 1
73 dhcpcd_stop() {
74 local iface=$1 count signal pidfile="/var/run/dhcpcd-$1.pid" d
75
76 dhcpcd_check_installed || return 0
77
78 [[ ! -f ${pidfile} ]] && return 0
79
80 ebegin "Stopping dhcpcd on ${iface}"
81 local pid=$( < ${pidfile} )
82
83 local ifvar=$( bash_variable "${iface}" )
84 eval d=\" \$\{dhcp_${ifvar}\} \"
85 [[ ${d} == " " ]] && d=" ${dhcp} "
86
87 if [[ ${d} == *" release "* ]]; then
88 signal="HUP"
89 else
90 signal="TERM"
91 fi
92
93 kill -s "${signal}" "${pid}" &>/dev/null
94 process_finished "${pid}" dhcpcd
95 eend $? "timed out"
96 return $?
97 }
98
99 # bool dhcpcd_start(char *iface)
100 #
101 # Start DHCP on an interface by calling dhcpcd $iface $options
102 #
103 # Returns 0 (true) when a DHCP address is obtained, otherwise 1
104 dhcpcd_start() {
105 local iface="$1" opts hostname pidfile="/var/run/dhcpcd-$1.pid"
106 local ifvar=$( bash_variable "${iface}" ) metric d
107
108 interface_exists "${iface}" true || return 1
109
110 # Get our options
111 eval opts=\" \$\{dhcpcd_${ifvar}\} \"
112
113 # Map some generic options to dhcpcd
114 eval d=\" \$\{dhcp_${ifvar}\} \"
115 [[ ${d} == " " ]] && d=" ${dhcp} "
116 [[ ${d} == *" nodns "* ]] && opts="${opts} -R"
117 [[ ${d} == *" nontp "* ]] && opts="${opts} -N"
118 [[ ${d} == *" nonis "* ]] && opts="${opts} -Y"
119 [[ ${d} == *" nogateway "* ]] && opts="${opts} -G"
120
121 # We transmit the hostname by default
122 if [[ ${d} != *" nosendhost "* && ${opts} != *" -h "* ]]; then
123 hostname=$( hostname )
124 [[ -n ${hostname} && ${hostname} != "(none)" \
125 && ${hostname} != "localhost" ]] \
126 && opts="-h \"${hostname}\" ${opts}"
127 fi
128
129 # Stop dhcpcd from bringing the interface down when we exit
130 opts="${opts} -o"
131
132 # Add our route metric
133 eval metric=\"\$\{metric_${ifvar}\}\"
134 [[ -n ${metric} ]] && opts="${opts} -m ${metric}"
135
136 # Instruct dhcpcd to use our wrapper
137 opts="${opts} -c \"/lib/rcscripts/net.modules.d/helpers.d/dhcpcd-wrapper\""
138
139 # Instruct dhcpcd to create it's files in our state dir
140 opts="${opts} -e \"${statedir}/${iface}\""
141
142 # Bring up DHCP for this interface (or alias)
143 ebegin "Running dhcpcd"
144
145 # Halt any existing dhcpcd process
146 dhcpcd_stop "${iface}"
147
148 [[ ! -d "${statedir}/${iface}" ]] && mkdir -p "${statedir}/${iface}"
149
150 if [[ ${background} == "yes" ]]; then
151 eval dhcpcd ${opts} ${iface} &
152 eend 0
153 go_background
154 fi
155
156 eval dhcpcd ${opts} ${iface}
157 eend $? || return 1
158
159 # DHCP succeeded, show address retrieved
160 local addr=$( interface_get_address "${iface}" )
161 einfo "${iface} received address ${addr}"
162
163 return 0
164 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.20