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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 236 - (show annotations) (download)
Tue Feb 14 13:00:44 2006 UTC (8 years, 7 months ago) by phreak
File size: 3299 byte(s)
Merging r1881
1 #!/bin/bash
2 # Copyright (c) 2004-2006 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-2.0.0 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 # bool dhcpcd_stop(char *iface)
41 #
42 # Stop DHCP on an interface by calling dhcpcd -z $iface
43 #
44 # Returns 0 (true) when a DHCP address dropped
45 # otherwise return 1
46 dhcpcd_stop() {
47 local iface=$1 count signal pidfile="/var/run/dhcpcd-$1.pid" d
48
49 [[ ! -f ${pidfile} ]] && return 0
50
51 ebegin "Stopping dhcpcd on ${iface}"
52 local pid=$( < "${pidfile}" )
53
54 local ifvar=$( bash_variable "${iface}" )
55 d="dhcp_${ifvar}"
56 d=" ${!d} "
57 [[ ${d} == " " ]] && d=" ${dhcp} "
58
59 if [[ ${d} == *" release "* ]]; then
60 signal="HUP"
61 else
62 signal="TERM"
63 fi
64
65 kill -s "${signal}" "${pid}" &>/dev/null
66 process_finished "${pid}" dhcpcd
67 eend $? "timed out"
68 return $?
69 }
70
71 # bool dhcpcd_start(char *iface)
72 #
73 # Start DHCP on an interface by calling dhcpcd $iface $options
74 #
75 # Returns 0 (true) when a DHCP address is obtained, otherwise 1
76 dhcpcd_start() {
77 local iface="$1" opts pidfile="/var/run/dhcpcd-$1.pid"
78 local ifvar=$( bash_variable "${iface}" ) metric d
79
80 interface_exists "${iface}" true || return 1
81
82 # Get our options
83 opts="dhcpcd_${ifvar}"
84 opts="${!opts}"
85
86 # Map some generic options to dhcpcd
87 d="dhcp_${ifvar}"
88 d=" ${!d} "
89 [[ ${d} == " " ]] && d=" ${dhcp} "
90 [[ ${d} == *" nodns "* ]] && opts="${opts} -R"
91 [[ ${d} == *" nontp "* ]] && opts="${opts} -N"
92 [[ ${d} == *" nonis "* ]] && opts="${opts} -Y"
93 [[ ${d} == *" nogateway "* ]] && opts="${opts} -G"
94
95 # We transmit the hostname by default:q
96 if [[ " ${d} " != *" nosendhost "* && " ${opts} " != *" -h "* ]]; then
97 local hname=$( hostname )
98 [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \
99 && opts="-h \"${hname}\" ${opts}"
100 fi
101
102 # Stop dhcpcd from bringing the interface down when we exit
103 opts="${opts} -o"
104
105 # Add our route metric
106 metric="metric_${ifvar}"
107 [[ -n ${!metric} && ${!metric} != "0" ]] && opts="${opts} -m ${!metric}"
108
109 # Instruct dhcpcd to use our wrapper
110 opts="${opts} -c \"${svclib}/net.modules.d/helpers.d/dhcpcd-wrapper\""
111
112 # Instruct dhcpcd to create it's files in our state dir
113 opts="${opts} -e \"${statedir}/${iface}\""
114
115 # Bring up DHCP for this interface (or alias)
116 ebegin "Running dhcpcd"
117
118 [[ ! -d "${statedir}/${iface}" ]] && mkdir -m 0755 -p "${statedir}/${iface}"
119 eval dhcpcd "${opts}" "${iface}"
120 eend $? || return 1
121
122 # DHCP succeeded, show address retrieved
123 local addr=$( interface_get_address "${iface}" )
124 einfo "${iface} received address ${addr}"
125
126 return 0
127 }
128
129 # vim:ts=4

  ViewVC Help
Powered by ViewVC 1.1.20