/[baselayout]/trunk/net-scripts/net.modules.d/dhcpcd
Gentoo

Contents of /trunk/net-scripts/net.modules.d/dhcpcd

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1753 - (show annotations) (download)
Fri Dec 9 15:08:06 2005 UTC (8 years, 11 months ago) by uberlord
File size: 3535 byte(s)
Remove nasty undocumented backgrounding as we now support
ifplugd, netplug and wpa_supplicant-0.4.x which do much better jobs.
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 # void dhcpcd_depend(void)
14 #
15 # Sets up the dependancies for the module
16 dhcpcd_depend() {
17 after interface
18 provide dhcp
19 functions interface_exists interface_get_address
20 variables dhcpcd dhcp
21 }
22
23 # bool dhcpcd_check_installed(void)
24 #
25 # Returns 1 if dhcpcd is installed, otherwise 0
26 dhcpcd_check_installed() {
27 if [[ -x /sbin/dhcpcd ]]; then
28 if dhcpcd -h 2>&1 | grep -q "etcDir" ; then
29 return 0
30 else
31 ${1:-false} && eerror "We require dhcpcd-1.3.22_p4-r12 or newer"
32 return 1
33 fi
34 fi
35
36 ${1:-false} && eerror "For DHCP (dhcpcd) support, emerge net-misc/dhcpcd"
37 return 1
38 }
39
40 # char* dhcpcd_get_vars(char *interface)
41 #
42 # Returns a string spaced with possible user set
43 # configuration variables
44 dhcpcd_get_vars() {
45 echo "dhcpcd_$1 dhcp_$1"
46 }
47
48 # bool dhcpcd_stop(char *iface)
49 #
50 # Stop DHCP on an interface by calling dhcpcd -z $iface
51 #
52 # Returns 0 (true) when a DHCP address dropped
53 # otherwise return 1
54 dhcpcd_stop() {
55 local iface=$1 count signal pidfile="/var/run/dhcpcd-$1.pid" d
56
57 [[ ! -f ${pidfile} ]] && return 0
58
59 ebegin "Stopping dhcpcd on ${iface}"
60 local pid=$( < "${pidfile}" )
61
62 local ifvar=$( bash_variable "${iface}" )
63 d="dhcp_${ifvar}"
64 d=" ${!d} "
65 [[ ${d} == " " ]] && d=" ${dhcp} "
66
67 if [[ ${d} == *" release "* ]]; then
68 signal="HUP"
69 else
70 signal="TERM"
71 fi
72
73 kill -s "${signal}" "${pid}" &>/dev/null
74 process_finished "${pid}" dhcpcd
75 eend $? "timed out"
76 return $?
77 }
78
79 # bool dhcpcd_start(char *iface)
80 #
81 # Start DHCP on an interface by calling dhcpcd $iface $options
82 #
83 # Returns 0 (true) when a DHCP address is obtained, otherwise 1
84 dhcpcd_start() {
85 local iface="$1" opts pidfile="/var/run/dhcpcd-$1.pid"
86 local ifvar=$( bash_variable "${iface}" ) metric d
87
88 interface_exists "${iface}" true || return 1
89
90 # Get our options
91 opts="dhcpcd_${ifvar}"
92 opts="${!opts}"
93
94 # Map some generic options to dhcpcd
95 d="dhcp_${ifvar}"
96 d=" ${!d} "
97 [[ ${d} == " " ]] && d=" ${dhcp} "
98 [[ ${d} == *" nodns "* ]] && opts="${opts} -R"
99 [[ ${d} == *" nontp "* ]] && opts="${opts} -N"
100 [[ ${d} == *" nonis "* ]] && opts="${opts} -Y"
101 [[ ${d} == *" nogateway "* ]] && opts="${opts} -G"
102
103 # We transmit the hostname by default:q
104 if [[ " ${d} " != *" nosendhost "* && " ${opts} " != *" -h "* ]]; then
105 local hname=$( hostname )
106 [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \
107 && opts="-h \"${hname}\" ${opts}"
108 fi
109
110 # Stop dhcpcd from bringing the interface down when we exit
111 opts="${opts} -o"
112
113 # Add our route metric
114 metric="metric_${ifvar}"
115 [[ -n ${!metric} && ${!metric} != "0" ]] && opts="${opts} -m ${!metric}"
116
117 # Instruct dhcpcd to use our wrapper
118 opts="${opts} -c \"${svclib}/net.modules.d/helpers.d/dhcpcd-wrapper\""
119
120 # Instruct dhcpcd to create it's files in our state dir
121 opts="${opts} -e \"${statedir}/${iface}\""
122
123 # Bring up DHCP for this interface (or alias)
124 ebegin "Running dhcpcd"
125
126 # Halt any existing dhcpcd process
127 dhcpcd_stop "${iface}"
128
129 [[ ! -d "${statedir}/${iface}" ]] && mkdir -m 0755 -p "${statedir}/${iface}"
130 eval dhcpcd "${opts}" "${iface}"
131 eend $? || return 1
132
133 # DHCP succeeded, show address retrieved
134 local addr=$( interface_get_address "${iface}" )
135 einfo "${iface} received address ${addr}"
136
137 return 0
138 }
139
140 # vim:ts=4

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20