/[vps]/baselayout-vserver/branches/baselayout-1_12/net-scripts/net/dhcpcd.sh
Gentoo

Contents of /baselayout-vserver/branches/baselayout-1_12/net-scripts/net/dhcpcd.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 414 - (show annotations) (download) (as text)
Wed Aug 16 08:23:44 2006 UTC (8 years, 2 months ago) by hollow
File MIME type: text/x-sh
File size: 2652 byte(s)
merge r2190
1 # Copyright (c) 2004-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # Contributed by Roy Marples (uberlord@gentoo.org)
5
6 # void dhcpcd_depend(void)
7 #
8 # Sets up the dependancies for the module
9 dhcpcd_depend() {
10 after interface
11 provide dhcp
12 functions interface_exists interface_get_address
13 }
14
15 # void dhcpcd_expose(void)
16 #
17 # Expose variables that can be configured
18 dhcpcd_expose() {
19 variables dhcpcd dhcp
20 }
21
22 # bool dhcpcd_check_installed(void)
23 #
24 # Returns 1 if dhcpcd is installed, otherwise 0
25 dhcpcd_check_installed() {
26 [[ -x /sbin/dhcpcd ]] && return 0
27 ${1:-false} && eerror "For DHCP (dhcpcd) support, emerge net-misc/dhcpcd"
28 return 1
29 }
30
31 # bool dhcpcd_stop(char *iface)
32 #
33 # Stop DHCP on an interface by calling dhcpcd -z $iface
34 #
35 # Returns 0 (true) when a DHCP address dropped
36 # otherwise return 1
37 dhcpcd_stop() {
38 local iface=$1 signal= pidfile="/var/run/dhcpcd-$1.pid" d=
39
40 [[ ! -f ${pidfile} ]] && return 0
41
42 ebegin "Stopping dhcpcd on ${iface}"
43
44 local ifvar=$(bash_variable "${iface}")
45 d="dhcp_${ifvar}"
46 d=" ${!d} "
47 [[ ${d} == " " ]] && d=" ${dhcp} "
48
49 if [[ ${d} == *" release "* ]] ; then
50 /sbin/dhcpcd -k "${iface}"
51 else
52 start-stop-daemon --stop --exec /sbin/dhcpcd --pidfile "${pidfile}"
53 fi
54 eend $?
55 }
56
57 # bool dhcpcd_start(char *iface)
58 #
59 # Start DHCP on an interface by calling dhcpcd $iface $options
60 #
61 # Returns 0 (true) when a DHCP address is obtained, otherwise 1
62 dhcpcd_start() {
63 local iface="$1" opts= pidfile="/var/run/dhcpcd-$1.pid"
64 local ifvar=$(bash_variable "${iface}") metric= d=
65
66 interface_exists "${iface}" true || return 1
67
68 # Get our options
69 opts="dhcpcd_${ifvar}"
70 opts="${!opts}"
71
72 # Map some generic options to dhcpcd
73 d="dhcp_${ifvar}"
74 d=" ${!d} "
75 [[ ${d} == " " ]] && d=" ${dhcp} "
76 [[ ${d} == *" nodns "* ]] && opts="${opts} -R"
77 [[ ${d} == *" nontp "* ]] && opts="${opts} -N"
78 [[ ${d} == *" nonis "* ]] && opts="${opts} -Y"
79 [[ ${d} == *" nogateway "* ]] && opts="${opts} -G"
80
81 # We transmit the hostname by default
82 if [[ " ${d} " != *" nosendhost "* && " ${opts} " != *" -h "* ]]; then
83 local hname=$(hostname)
84 [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \
85 && opts="-h \"${hname}\" ${opts}"
86 fi
87
88 # Add our route metric
89 metric="metric_${ifvar}"
90 [[ -n ${!metric} && ${!metric} != "0" ]] && opts="${opts} -m ${!metric}"
91
92 # Bring up DHCP for this interface (or alias)
93 ebegin "Running dhcpcd"
94
95 eval /sbin/dhcpcd "${opts}" "${iface}"
96 eend $? || return 1
97
98 # DHCP succeeded, show address retrieved
99 local addr=$(interface_get_address "${iface}")
100 einfo "${iface} received address ${addr}"
101
102 return 0
103 }
104
105 # vim: set ts=4 :

  ViewVC Help
Powered by ViewVC 1.1.20