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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3176 - (show annotations) (download) (as text)
Sun Sep 26 21:45:36 2010 UTC (3 years, 6 months ago) by vapier
File MIME type: text/x-sh
File size: 3084 byte(s)
handle argument munging with different versions of dhcpcd by Gil Kloepfer & Mike Pagano #262097

1 # Copyright 2004-2007 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" opt= opts= new= args= 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 dhcpcd options
69 eval args=\$dhcpcd_${ifvar}
70 [[ -n ${dhcpcd} ]] && args="${dhcpcd} ${args}"
71
72 # Get generic dhcp options
73 eval opts=\$dhcp_${ifvar}
74 [[ -z ${opts} ]] && opts=${dhcp}
75
76 # Figure out which version of dhcpcd we have so we know
77 # which style of option to use
78 case $(dhcpcd --version) in
79 "dhcpcd "[123]*) new=false ;;
80 *) new=true ;;
81 esac
82
83 # Map some generic options to dhcpcd
84 for opt in ${opts} ; do
85 case "${opt}" in
86 nodns)
87 ${new} \
88 && args="${args} -C resolv.conf" \
89 || args="${args} -R"
90 ;;
91 nontp)
92 ${new} \
93 && args="${args} -C ntp.conf" \
94 || args="${args} -N"
95 ;;
96 nonis)
97 ${new} \
98 && args="${args} -C yp.conf" \
99 || args="${args} -Y"
100 ;;
101 nogateway) args="${args} -G" ;;
102 nosendhost) args="${args} -h ''" ;;
103 esac
104 done
105
106 # We transmit the hostname by default
107 if [[ " ${args} " != *" -h "* ]]; then
108 local hname=$(hostname)
109 [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \
110 && args="-h \"${hname}\" ${args}"
111 fi
112
113 # Add our route metric
114 metric="metric_${ifvar}"
115 [[ -n ${!metric} && ${!metric} != "0" ]] && args="${args} -m ${!metric}"
116
117 # Bring up DHCP for this interface (or alias)
118 ebegin "Running dhcpcd"
119
120 eval /sbin/dhcpcd "${args}" "${iface}"
121 eend $? || return 1
122
123 # DHCP succeeded, show address retrieved
124 local addr=$(interface_get_address "${iface}")
125 einfo "${iface} received address ${addr}"
126
127 return 0
128 }
129
130 # vim: set ts=4 :

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.20