diff options
author | 2006-02-27 13:15:18 +0000 | |
---|---|---|
committer | 2006-02-27 13:15:18 +0000 | |
commit | 8eb30724c1a19a754fe444da5e4fa990d953b49a (patch) | |
tree | 42141954490bb973cfc7d47ea1599fe33e16360b | |
parent | Merging baselayout r1924 (diff) | |
download | baselayout-vserver-8eb30724c1a19a754fe444da5e4fa990d953b49a.tar.gz baselayout-vserver-8eb30724c1a19a754fe444da5e4fa990d953b49a.tar.bz2 baselayout-vserver-8eb30724c1a19a754fe444da5e4fa990d953b49a.zip |
Merging r1928
svn path=/baselayout-vserver/trunk/; revision=265
35 files changed, 388 insertions, 387 deletions
@@ -5,6 +5,22 @@ Give a better error message when no valid DHCP client is installed. + 24 Feb 2006; Roy Marples <uberlord@gentoo.org>: + + Misc STYLE and quoting issues fixes in net scripts. + + dhclient and udhcpc now work with RFC violating space separated + domain names in /etc/resolv.conf - they get appended to the search + option if it's not specified. + + punted clean_pidfile and process_finished functions and as + start-stop-daemon as provided by rc-daemon.sh now provides + the same thing, just better. + + We now send extra configuration to dhclient via stdin. + This means we don't have to edit /etc/dhcp/dhclient.conf anymore + or warn users about script settings. Requires net-misc/dhcp-3.0.3-r5. + 22 Feb 2006; Mike Frysinger <vapier@gentoo.org>: Overhaul rc-update and make it more user friendly. diff --git a/ChangeLog.vserver b/ChangeLog.vserver index 32cface..5cdba37 100644 --- a/ChangeLog.vserver +++ b/ChangeLog.vserver @@ -1,6 +1,47 @@ # ChangeLog for Gentoo System Intialization ("rc") scripts # Copyright 1999-2006 Gentoo Foundation; Distributed under the GPLv2 + 27 Feb 2006; Christian Heim <phreak@gentoo.org>: + Merging latest changes to the rc-scripts branch. This merge is based + upon revision 1928. + + ChangeLog | 16 ++ + ChangeLog.vserver | 41 +++++ + net-scripts/conf.d/net.example | 22 -- + net-scripts/init.d/net.lo | 2 + net-scripts/net.modules.d/adsl | 2 + net-scripts/net.modules.d/arping | 12 - + net-scripts/net.modules.d/bonding | 7 + net-scripts/net.modules.d/bridge | 38 ++--- + net-scripts/net.modules.d/dhclient | 103 ++++++------- + net-scripts/net.modules.d/dhcpcd | 31 +--- + net-scripts/net.modules.d/essidnet | 10 - + net-scripts/net.modules.d/helpers.d/dhclient-wrapper | 2 + net-scripts/net.modules.d/helpers.d/dhcp | 32 +--- + net-scripts/net.modules.d/helpers.d/dhcp-state | 10 - + net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper | 14 - + net-scripts/net.modules.d/helpers.d/functions | 134 ++++++------------ + net-scripts/net.modules.d/helpers.d/module-loader | 14 - + net-scripts/net.modules.d/helpers.d/pppd-wrapper | 12 - + net-scripts/net.modules.d/helpers.d/pump-wrapper | 4 + net-scripts/net.modules.d/helpers.d/udhcpc-wrapper | 6 + net-scripts/net.modules.d/ifconfig | 30 ++-- + net-scripts/net.modules.d/ifplugd | 20 +- + net-scripts/net.modules.d/ipppd | 16 -- + net-scripts/net.modules.d/iptunnel | 6 + net-scripts/net.modules.d/iwconfig | 10 + + net-scripts/net.modules.d/macchanger | 22 +- + net-scripts/net.modules.d/macnet | 2 + net-scripts/net.modules.d/netplugd | 12 - + net-scripts/net.modules.d/pppd | 14 - + net-scripts/net.modules.d/pump | 4 + net-scripts/net.modules.d/rename | 2 + net-scripts/net.modules.d/system | 40 +++-- + net-scripts/net.modules.d/udhcpc | 31 +--- + net-scripts/net.modules.d/vlan | 18 +- + net-scripts/net.modules.d/wpa_supplicant | 36 ++-- + 35 files changed, 388 insertions(+), 387 deletions(-) + 23 Feb 2006; Christian Heim <phreak@gentoo.org>: Merging latest changes to the rc-scripts branch. This merge is based upon revision 1924. diff --git a/net-scripts/conf.d/net.example b/net-scripts/conf.d/net.example index a28bf43..f77c38f 100644 --- a/net-scripts/conf.d/net.example +++ b/net-scripts/conf.d/net.example @@ -209,7 +209,7 @@ #----------------------------------------------------------------------------- # DHCP -# DHCP can be provided by dhcpcd, dhclient, udhcpc or pump +# DHCP can be provided by dhclient, dhcpcd, pump or udhcpc. # # dhclient: emerge net-misc/dhcp # dhcpcd: emerge net-misc/dhcpcd @@ -217,17 +217,13 @@ # udhcpc: emerge net-misc/udhcp # If you have more than one DHCP client installed, you need to specify which -# one to use - otherwise we default to dhcpcd if available -#modules=( "udhcpc" ) # to select udhcpc over dhcpcd +# one to use - otherwise we default to dhcpcd if available. +#modules=( "dhclient" ) # to select dhclient over dhcpcd # # Notes: -# - dhcpcd, udhcpc and pump send the current hostname -# to the DHCP server by default -# pump always sends the current hostname - see below to disable -# udhcpc and dhcpcd from doing this +# - All clients send the current hostname to the DHCP server by default # - dhcpcd does not daemonize when the lease time is infinite -# - udhcp-0.9.3-r3 and earlier does not support getting NTP servers -# - dhclient does not support getting NTP servers +# - udhcp-0.9.3-r3 and earlier do not support getting NTP servers # - pump does not support getting NIS servers # - DHCP tends to erase any existing device information - so add # static addresses after dhcp if you need them @@ -250,9 +246,6 @@ #udhcpc_eth0="..." #pump_eth0="..." -# To set options for dhclient, you need to have an /etc/dhclient.conf file -# See the dhclient man page for details - # GENERIC DHCP OPTIONS # Set generic DHCP options like so #dhcp_eth0="release nodns nontp nonis nogateway nosendhost" @@ -263,11 +256,6 @@ # You can use any combination of the above options - the default is not to # use any of them. -# DHCLIENT -# dhclient can modify /etc/dhclient.conf (or the file specified by the -cf -# option) with the current hostname and to strip any script lines. To enable -# this, add dhclient_edit_config="yes" to /etc/conf.d/net - #----------------------------------------------------------------------------- # For APIPA support, emerge net-misc/iputils or net-analyzer/arping diff --git a/net-scripts/init.d/net.lo b/net-scripts/init.d/net.lo index 53a51c9..332834b 100755 --- a/net-scripts/init.d/net.lo +++ b/net-scripts/init.d/net.lo @@ -503,7 +503,7 @@ iface_start() { local iface="$1" mod config_counter="-1" x config_worked=false local RC_INDENTATION="${RC_INDENTATION}" local -a config fallback fallback_route conf a b - local ifvar=$( bash_variable "$1" ) i j + local ifvar="$(bash_variable "$1")" i j # Try and work out a metric for the interface if we're on auto x="metric_${ifvar}" diff --git a/net-scripts/net.modules.d/adsl b/net-scripts/net.modules.d/adsl index 5175315..ffc26e6 100644 --- a/net-scripts/net.modules.d/adsl +++ b/net-scripts/net.modules.d/adsl @@ -54,7 +54,7 @@ adsl_setup_vars() { # # Returns 0 (true) when successful, non-zero otherwise adsl_start() { - local iface="$1" exe cfgfile user ifvar=$( bash_variable "$1" ) + local iface="$1" exe cfgfile user ifvar="$(bash_variable "$1")" adsl_setup_vars "${iface}" start || return 1 diff --git a/net-scripts/net.modules.d/arping b/net-scripts/net.modules.d/arping index 3d178fa..aa1da8a 100644 --- a/net-scripts/net.modules.d/arping +++ b/net-scripts/net.modules.d/arping @@ -40,11 +40,11 @@ arping_address_exists() { # We need to bring the interface up to test interface_up "${iface}" - if [[ -x /sbin/arping ]]; then + if [[ -x /sbin/arping ]] ; then /sbin/arping -q -c 2 -w 3 -D -f -I "${iface}" "${address}" \ &>/dev/null || return 0 - elif [[ -x /usr/sbin/arping2 ]]; then - for (( i=0; i<3; i++ )); do + elif [[ -x /usr/sbin/arping2 ]] ; then + for (( i=0; i<3; i++ )) ; do /usr/sbin/arping2 -0 -c 1 -i "${iface}" "${address}" \ &>/dev/null && return 0 done @@ -64,7 +64,7 @@ arping_start() { einfo "Pinging gateways on ${iface} for configuration" gateways="gateways_${ifvar}[@]" - if [[ -z ${!gateways} ]]; then + if [[ -z ${!gateways} ]] ; then eerror "No gateways have been defined (gateways_${ifvar}=\"...\")" return 1 fi @@ -75,9 +75,9 @@ arping_start() { vebegin "${x}" if arping_address_exists "${iface}" "${x}" ; then for i in ${x//./ } ; do - if [[ ${#i} == "2" ]]; then + if [[ ${#i} == "2" ]] ; then conf="${conf}0${i}" - elif [[ ${#i} == "1" ]]; then + elif [[ ${#i} == "1" ]] ; then conf="${conf}00${i}" else conf="${conf}${i}" diff --git a/net-scripts/net.modules.d/bonding b/net-scripts/net.modules.d/bonding index 100ca28..9aa67e0 100644 --- a/net-scripts/net.modules.d/bonding +++ b/net-scripts/net.modules.d/bonding @@ -34,7 +34,7 @@ bonding_exists() { # # Bonds the interface bonding_pre_start() { - local iface="$1" s ifvar=$( bash_variable "$1" ) + local iface="$1" s ifvar="$(bash_variable "$1")" local -a slaves slaves="slaves_${ifvar}[@]" @@ -71,7 +71,7 @@ bonding_pre_start() { # finally add in slaves eoutdent - eval /sbin/ifenslave "${iface}" "${slaves[@]}" >/dev/null + /sbin/ifenslave "${iface}" ${slaves[@]} >/dev/null eend $? return 0 #important @@ -89,7 +89,8 @@ bonding_stop() { # don't trust the config, get the active list instead slaves="$( \ - sed -n -e 's/^Slave Interface: //p' /proc/net/bonding/${iface} | xargs \ + sed -n -e 's/^Slave Interface: //p' "/proc/net/bonding/${iface}" \ + | xargs \ )" [[ -z ${slaves} ]] && return 0 diff --git a/net-scripts/net.modules.d/bridge b/net-scripts/net.modules.d/bridge index 747dd1f..8bad1f6 100644 --- a/net-scripts/net.modules.d/bridge +++ b/net-scripts/net.modules.d/bridge @@ -39,13 +39,13 @@ bridge_get_ports() { # # Returns the bridge interface of the given interface bridge_get_bridge() { - local x=$( brctl show 2>/dev/null \ - | sed -e '1 {d}; /^[^ ]/ { N }; /.*'"$1"'.*/ {s/^\([^ \t]\+\).*/\1/p}; d' ) + local x="$( brctl show 2>/dev/null \ + | sed -e '1 {d}; /^[^ ]/ { N }; /.*'"$1"'.*/ {s/^\([^ \t]\+\).*/\1/p}; d')" local -a a=( ${x} ) - if [[ ${#a[@]} == "1" ]]; then + if [[ ${#a[@]} == "1" ]] ; then echo "${x}" - elif [[ $1 == "${a[3]}" ]]; then + elif [[ $1 == "${a[3]}" ]] ; then echo "${a[0]}" fi } @@ -62,12 +62,12 @@ bridge_exists() { # Creates the bridge - no ports are added here though # Returns 0 on success otherwise 1 bridge_create() { - local iface="$1" ifvar=$( bash_variable "$1" ) x i opts + local iface="$1" ifvar="$(bash_variable "$1")" x i opts ebegin "Creating bridge ${iface}" - x=$( brctl addbr "${iface}" 2>&1 ) - if [[ -n ${x} ]]; then - if [[ ${x//Package not installed/} != "${x}" ]]; then + x="$(brctl addbr "${iface}" 2>&1)" + if [[ -n ${x} ]] ; then + if [[ ${x//Package not installed/} != "${x}" ]] ; then eend 1 "Bridging (802.1d) support is not present in this kernel" else eend 1 "${x}" @@ -79,7 +79,7 @@ bridge_create() { for i in "${!opts}" ; do x="${i/ / ${iface} }" [[ ${x} == "${i}" ]] && x="${x} ${iface}" - x=$( brctl ${x} 2>&1 1>/dev/null ) + x="$(brctl ${x} 2>&1 1>/dev/null)" [[ -n ${x} ]] && ewarn "${x}" done eend 0 @@ -93,8 +93,8 @@ bridge_add_port() { interface_set_flag "${port}" promisc true interface_up "${port}" - e=$( brctl addif "${iface}" "${port}" 2>&1 ) - if [[ -n ${e} ]]; then + e="$(brctl addif "${iface}" "${port}" 2>&1)" + if [[ -n ${e} ]] ; then interface_set_flag "${port}" promisc false echo "${e}" >&2 return 1 @@ -116,7 +116,7 @@ bridge_delete_port() { # This can also be called by non-bridges so that the bridge can be created # dynamically bridge_pre_start() { - local iface="$1" ports briface i ifvar=$( bash_variable "$1" ) opts + local iface="$1" ports briface i ifvar="$(bash_variable "$1")" opts ports="bridge_${ifvar}[@]" briface="bridge_add_${ifvar}" opts="brctl_${ifvar}[@]" @@ -127,7 +127,7 @@ bridge_pre_start() { [[ -n ${!ports} ]] && bridge_stop "${iface}" # Allow ourselves to add to the bridge - if [[ -z ${!ports} && -n ${!briface} ]]; then + if [[ -z ${!ports} && -n ${!briface} ]] ; then ports="${iface}" iface="${!briface}" else @@ -137,15 +137,15 @@ bridge_pre_start() { # Create the bridge if needed bridge_exists "${iface}" || bridge_create "${iface}" - if [[ -n ${ports} ]]; then + if [[ -n ${ports} ]] ; then einfo "Adding ports to ${iface}" eindent - for i in ${ports}; do + for i in ${ports} ; do interface_exists "${i}" true || return 1 done - for i in ${ports}; do + for i in ${ports} ; do ebegin "${i}" bridge_add_port "${iface}" "${i}" eend $? || return 1 @@ -166,18 +166,18 @@ bridge_stop() { if bridge_exists "${iface}" ; then ebegin "Destroying bridge ${iface}" interface_down "${iface}" - ports=$( bridge_get_ports "${iface}" ) + ports="$(bridge_get_ports "${iface}")" deletebridge=true eindent else # Work out if we're added to a bridge for removal or not ports="${iface}" - iface=$( bridge_get_bridge "${iface}" ) + iface="$(bridge_get_bridge "${iface}")" [[ -z ${iface} ]] && return 0 extra=" from ${iface}" fi - for i in ${ports}; do + for i in ${ports} ; do ebegin "Removing port ${i}${extra}" bridge_delete_port "${iface}" "${i}" eend $? diff --git a/net-scripts/net.modules.d/dhclient b/net-scripts/net.modules.d/dhclient index c97360a..1483cb0 100644 --- a/net-scripts/net.modules.d/dhclient +++ b/net-scripts/net.modules.d/dhclient @@ -34,36 +34,29 @@ dhclient_check_installed() { # Stop dhclient on an interface # Always returns 0 dhclient_stop() { - local iface="$1" d - local pidfile="/var/run/dhclient-${iface}.pid" + local iface="$1" pidfile="/var/run/dhclient-$1.pid" [[ ! -f ${pidfile} ]] && return 0 - # We check for a dhclient process first as if we attempt to release - # an interface for which dhclient has obtained an IP in the past - # it causes a "RELEASE" event anyway. - local pid=$( < "${pidfile}" ) + ebegin "Stopping dhclient on ${iface}" - local ifvar=$( bash_variable "${iface}" ) - d="dhcp_${ifvar}" + local ifvar="$(bash_variable "${iface}")" + local d="dhcp_${ifvar}" d=" ${!d} " [[ ${d} == " " ]] && d=" ${dhcp} " - ebegin "Stopping dhclient on ${iface}" - if [[ ${d} == *" release "* ]]; then - local r=$( dhclient -q -r -pf "${pidfile}" \ - -sf "${MODULES_DIR}/helpers.d/dhclient-wrapper" "${iface}" ) + if [[ ${d} == *" release "* ]] ; then + local dhconf="interface \"${iface}\" {\n \ + script \"${MODULES_DIR}/helpers.d/dhclient-wrapper\";\n \ + }\n" + local r="$(echo -e "${dhconf}" \ + | dhclient -q -r -pf "${pidfile}" "${iface}" )" [[ ${r} == "deconfig" ]] - eend $? "dhclient returned a ${r}" - [[ -f "/var/cache/dhcp-${iface}.lease" ]] \ - && rm -f "/var/cache/dhcp-${iface}.lease" + eend $? "dhclient returned ${r}" else - kill -s TERM "${pid}" 2>/dev/null - clean_pidfile "${pidfile}" - eend 0 + start-stop-daemon --stop --exec /sbin/dhclient --pidfile "${pidfile}" + eend $? fi - - return 0 } # bool dhclient_start(char *iface) @@ -72,26 +65,22 @@ dhclient_stop() { # # Returns 0 (true) when a DHCP address is obtained, otherwise 1 dhclient_start() { - local iface="$1" opts ifvar=$( bash_variable "$1" ) d - local pidfile="/var/run/dhclient-${iface}.pid" edit="" + local iface="$1" ifvar="$(bash_variable "$1")" + local pidfile="/var/run/dhclient-${iface}.pid" local cffile="/etc/dhcp/dhclient.conf" interface_exists "${iface}" true || return 1 - edit="dhclient_edit_config_${ifvar}" - [[ -z ${!edit} ]] && edit="dhclient_edit_config" - if [[ ${!edit} == "yes" || ${!edit} == "true" ]]; then - edit=true - else - edit=false - fi - + # Load any dhclient.conf instructions specified by the user + local opts="dhclient_conf_${ifvar}" + local dhconf="${!opts}" + # Load our options opts="dhclient_${ifvar}" opts="${!opts}" # Work out our cffile - x="${opts##* -cf }" + local x="${opts##* -cf }" if [[ ${x} != "${opts}" ]]; then x="${x%% *}" if [[ -n ${x} ]]; then @@ -99,56 +88,56 @@ dhclient_start() { opts="${opts//-cf ${cffile}/}" fi fi - opts="${opts} -cf ${cffile}" - # Ensure that the cffile does not contain any script lines - # as that will stop our helpers from running + # Warn that we're going to override parts of their cffile if [[ -e ${cffile} ]] ; then - if grep -q "^[ \t]*script " "${cffile}" 2>/dev/null ; then - if ${edit} ; then - sed -i '/^[ \t]*script /d' "${cffile}" || return 1 - else - eerror "You have to remove the script parameter from ${cffile}" - return 1 - fi + opts="${opts} -cf ${cffile}" + if grep -q "^[ \t]*script[ \t]" "${cffile}" ; then + ewarn "The script specified in ${cffile} will not be used" fi - else - ${edit} && touch "${cffile}" 2>/dev/null fi - d="dhcp_${ifvar}" + local d="dhcp_${ifvar}" d=" ${!d} " [[ ${d} == " " ]] && d=" ${dhcp} " + local ah="" # Send our hostname by editing cffile - if ${edit} && [[ -e ${cffile} && ${d} != *" nosendhost "* ]] ; then - local hname=$( hostname ) + if [[ ${d} != *" nosendhost "* ]] ; then + local hname="$(hostname)" if [[ ${hname} != "(none)" && ${hname} != "localhost" ]]; then - sed -i '/^[ \t]*send[ \t]*host-name[ \t]*/d' "${cffile}" - if [[ -s ${cffile} ]]; then - sed -i '1 isend host-name "'"${hname}"'";' "${cffile}" - else - echo "send host-name \"${hname}\";" > "${cffile}" + ah="send host-name \"${hname}\"\n;" + # Warn that we're going to override parts of their cffile + if [[ -e ${cffile} ]] ; then + if grep -q "^[ \t]*send[ \t]*host-name[ \t]" "${cffile}" ; then + ewarn "The host-name \"${hname}\" will be sent instead of" + ewarn "the one specified in ${cffile}" + vewarn "Set dhcp_${ifvar}=\"nosendhost\" in /etc/conf.d/net" + vewarn "to stop this from happening" + fi fi fi fi + dhconf="${dhconf} interface \"${iface}\" {\n \ + script \"/${MODULES_DIR}/helpers.d/dhclient-wrapper\";\n \ + ${ah} + }" # Bring up DHCP for this interface (or alias) ebegin "Running dhclient" - local x=$( eval dhclient "${opts}" -1 -pf "${pidfile}" \ - -sf "${MODULES_DIR}/helpers.d/dhclient-wrapper" -q "${iface}" 2>&1 ) + x="$(echo -e "${dhconf}" | dhclient ${opts} -q -1 -pf "${pidfile}")" # We just check the last 5 letters [[ ${x:${#x} - 5:5} == "bound" ]] if [[ $? != "0" ]]; then - echo "${x}" - dhclient_stop "${iface}" &>/dev/null - eend 1 + # Kill the offending daemon as it likes to hang around + start-stop-daemon --stop --exec /sbin/dhclient --pidfile "${pidfile}" + eend 1 "${x}" return 1 fi eend 0 # DHCP succeeded, show address retrieved - local addr=$( interface_get_address "${iface}" ) + local addr="$(interface_get_address "${iface}")" einfo "${iface} received address ${addr}" return 0 diff --git a/net-scripts/net.modules.d/dhcpcd b/net-scripts/net.modules.d/dhcpcd index c467f2a..5fc64c0 100644 --- a/net-scripts/net.modules.d/dhcpcd +++ b/net-scripts/net.modules.d/dhcpcd @@ -4,12 +4,6 @@ # Contributed by Roy Marples (uberlord@gentoo.org) -# Fix any potential localisation problems -# Note that LC_ALL trumps LC_anything_else according to locale(7) -dhcpcd() { - LC_ALL=C /sbin/dhcpcd "$@" -} - # void dhcpcd_depend(void) # # Sets up the dependancies for the module @@ -44,28 +38,23 @@ dhcpcd_check_installed() { # Returns 0 (true) when a DHCP address dropped # otherwise return 1 dhcpcd_stop() { - local iface=$1 count signal pidfile="/var/run/dhcpcd-$1.pid" d + local iface=$1 signal pidfile="/var/run/dhcpcd-$1.pid" d [[ ! -f ${pidfile} ]] && return 0 ebegin "Stopping dhcpcd on ${iface}" - local pid=$( < "${pidfile}" ) - - local ifvar=$( bash_variable "${iface}" ) + + local ifvar="$(bash_variable "${iface}")" d="dhcp_${ifvar}" d=" ${!d} " [[ ${d} == " " ]] && d=" ${dhcp} " - if [[ ${d} == *" release "* ]]; then - signal="HUP" + if [[ ${d} == *" release "* ]] ; then + /sbin/dhcpcd -k "${iface}" else - signal="TERM" + start-stop-daemon --stop --exec /sbin/dhcpcd --pidfile "${pidfile}" fi - - kill -s "${signal}" "${pid}" &>/dev/null - process_finished "${pid}" dhcpcd eend $? "timed out" - return $? } # bool dhcpcd_start(char *iface) @@ -75,7 +64,7 @@ dhcpcd_stop() { # Returns 0 (true) when a DHCP address is obtained, otherwise 1 dhcpcd_start() { local iface="$1" opts pidfile="/var/run/dhcpcd-$1.pid" - local ifvar=$( bash_variable "${iface}" ) metric d + local ifvar="$(bash_variable "${iface}")" metric d interface_exists "${iface}" true || return 1 @@ -94,7 +83,7 @@ dhcpcd_start() { # We transmit the hostname by default:q if [[ " ${d} " != *" nosendhost "* && " ${opts} " != *" -h "* ]]; then - local hname=$( hostname ) + local hname="$(hostname)" [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \ && opts="-h \"${hname}\" ${opts}" fi @@ -116,11 +105,11 @@ dhcpcd_start() { ebegin "Running dhcpcd" [[ ! -d "${statedir}/${iface}" ]] && mkdir -m 0755 -p "${statedir}/${iface}" - eval dhcpcd "${opts}" "${iface}" + eval /sbin/dhcpcd "${opts}" "${iface}" eend $? || return 1 # DHCP succeeded, show address retrieved - local addr=$( interface_get_address "${iface}" ) + local addr="$( interface_get_address "${iface}" )" einfo "${iface} received address ${addr}" return 0 diff --git a/net-scripts/net.modules.d/essidnet b/net-scripts/net.modules.d/essidnet index eb114ea..3be0bc8 100644 --- a/net-scripts/net.modules.d/essidnet +++ b/net-scripts/net.modules.d/essidnet @@ -7,8 +7,8 @@ # motivation for me to make this and keep on improving it # Load our config if it exists -[[ -f $(add_suffix "/etc/conf.d/wireless" ) ]] \ - && source $(add_suffix "/etc/conf.d/wireless" ) +[[ -f "$(add_suffix "/etc/conf.d/wireless" )" ]] \ + && source "$(add_suffix "/etc/conf.d/wireless" )" # void essidnet_depend(void) # @@ -32,9 +32,9 @@ essidnet_pre_start() { wireless_exists "${iface}" || return 0 - local mac=$( wireless_get_ap_mac_address "${iface}" ) - local ESSID=$( wireless_get_essid "${iface}" ) - local essid=$( bash_variable ${ESSID} ) + local mac="$(wireless_get_ap_mac_address "${iface}")" + local ESSID="$(wireless_get_essid "${iface}")" + local essid="$(bash_variable "${ESSID}")" mac="${mac//:/}" vebegin "Configuring ${iface} for ESSID \"${ESSID//\\\\/\\\\}\"" 2>/dev/null diff --git a/net-scripts/net.modules.d/helpers.d/dhclient-wrapper b/net-scripts/net.modules.d/helpers.d/dhclient-wrapper index 08a9433..7dd1154 100755 --- a/net-scripts/net.modules.d/helpers.d/dhclient-wrapper +++ b/net-scripts/net.modules.d/helpers.d/dhclient-wrapper @@ -17,7 +17,7 @@ case "${reason}" in MEDIUM) exit 0 ;; esac -if [[ -z ${action} ]]; then +if [[ -z ${action} ]] ; then echo "dhclient sent an unknown action ${reason}!" >&2 exit 1 fi diff --git a/net-scripts/net.modules.d/helpers.d/dhcp b/net-scripts/net.modules.d/helpers.d/dhcp index ceb2d60..6a315af 100755 --- a/net-scripts/net.modules.d/helpers.d/dhcp +++ b/net-scripts/net.modules.d/helpers.d/dhcp @@ -22,8 +22,8 @@ case "${action}" in interface_del_addresses "${interface}" true service_started "${service}" && mark_service_inactive "${service}" remove_state "${interface}" - if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then - best_interface=$( select_best_interface ) + if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then + best_interface="$(select_best_interface)" apply_state "${best_interface}" fi echo "${action}" @@ -44,19 +44,19 @@ esac macnet_pre_start "${interface}" 1>/dev/null # Map wireless ESSID variables to interface variables -if [[ -n ${wireless_module} ]]; then +if [[ -n ${wireless_module} ]] ; then if wireless_exists "${interface}" ; then essidnet_pre_start "${interface}" 1>/dev/null fi fi # Calculate the metric for our routes -ifvar=$( bash_variable "${interface}" ) +ifvar="$(bash_variable "${interface}")" metric="metric_${ifvar}" metric="${!metric}" -if [[ -z ${metric} ]]; then - if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then - metric=$( calculate_metric "${interface}" ) +if [[ -z ${metric} ]] ; then + if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then + metric="$(calculate_metric "${interface}")" else metric="0" fi @@ -66,36 +66,32 @@ fi # Configure our IP address ip="${ip// /}" subnet="${subnet// /}" -cidr=$( netmask2cidr "${subnet}" ) +cidr="$(netmask2cidr "${subnet}")" broadcast="${broadcast// /}" [[ -n ${broadcast} ]] && broadcast="broadcast ${broadcast}" # If we don't have our address then we flush it and then add our new one -curip=$( interface_get_address "${interface}" ) +curip="$(interface_get_address "${interface}")" if [[ ${curip} != "${ip}/${cidr}" ]] ; then # Just remove IPv4 / inet addresses interface_del_addresses "${interface}" true interface_add_address "${interface}" "${ip}/${cidr}" "${broadcast}" fi -# Store the address in a cache for future usage -echo "${ip}" > "/var/cache/dhcp-${interface}.lease" -chmod 600 "/var/cache/dhcp-${interface}.lease" - d="dhcp_${ifvar}" d=" ${!d} " [[ ${d} == " " ]] && d=" ${dhcp} " # Configure our default route - we only have 1 default route -if [[ ${d} != *" nogateway "* ]]; then +if [[ ${d} != *" nogateway "* ]] ; then for r in ${routers}; do interface_default_route "${interface}" "${r}" "${metric:-0}" && break done fi # Configure our hostname - but only if we need it -if [[ -n ${hostname} ]]; then - x=$( hostname ) +if [[ -n ${hostname} ]] ; then + x="$(hostname)" [[ ${x} == "(none)" || ${x} == "localhost" ]] && hostname "${hostname}" fi @@ -108,8 +104,8 @@ fi [[ ${d} != *" nontp "* ]] && system_ntp "${interface}" [[ ${d} != *" nonis "* ]] && system_nis "${interface}" -if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then - best_interface=$( select_best_interface ) +if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then + best_interface="$(select_best_interface)" apply_state "${best_interface}" else apply_state "${interface}" diff --git a/net-scripts/net.modules.d/helpers.d/dhcp-state b/net-scripts/net.modules.d/helpers.d/dhcp-state index c5de21f..0b5d3c7 100644 --- a/net-scripts/net.modules.d/helpers.d/dhcp-state +++ b/net-scripts/net.modules.d/helpers.d/dhcp-state @@ -6,22 +6,22 @@ . "${svclib}/sh/rc-services.sh" . "${svclib}/net.modules.d/helpers.d/functions" -conf=$(add_suffix "/etc/conf.d/net") +conf="$(add_suffix /etc/conf.d/net)" [[ -e ${conf} ]] && source "${conf}" service="net.${interface}" -if [[ ${action} != "up" ]]; then +if [[ ${action} != "up" ]] ; then service_started "${service}" && mark_service_inactive "${service}" remove_state "${interface}" false else service_inactive "${service}" && mark_service_started "${service}" fi -if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then - best_interface=$( select_best_interface ) +if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then + best_interface="$(select_best_interface)" apply_state "${best_interface}" -elif [[ ${action} == "up" ]]; then +elif [[ ${action} == "up" ]] ; then apply_state "${interface}" fi diff --git a/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper b/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper index 5769103..ce86a3d 100755 --- a/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper +++ b/net-scripts/net.modules.d/helpers.d/dhcpcd-wrapper @@ -7,7 +7,7 @@ interface="${1##*/dhcpcd-}" interface="${interface%%.info}" -if [[ $2 != "up" && $2 != "new" ]]; then +if [[ $2 != "up" && $2 != "new" ]] ; then action="down" else action="up" @@ -20,24 +20,24 @@ fi macnet_pre_start "${interface}" 1>/dev/null # Map wireless ESSID variables to interface variables -if [[ -n ${wireless_module} ]]; then +if [[ -n ${wireless_module} ]] ; then if wireless_exists "${interface}" ; then essidnet_pre_start "${interface}" 1>/dev/null fi fi # Add any search paths if we have any defined -ifvar=$( bash_variable "${interface}" ) +ifvar="$(bash_variable "${interface}")" -if [[ ${action} == "up" ]]; then +if [[ ${action} == "up" ]] ; then d="dhcp_${ifvar}" d=" ${!d} " [[ ${d} == " " ]] && d=" ${dhcp} " resolv="${statedir}/${interface}/resolv.conf" - if [[ ${d} != *" nodns "* ]]; then + if [[ ${d} != *" nodns "* ]] ; then search="dns_search_${ifvar}" - if [[ -n ${!search} ]]; then + if [[ -n ${!search} ]] ; then tmp="${resolv}.$$" egrep -v "^[ \t]*(search|domain)[ \t]*" "${resolv}" > "${tmp}" echo "search ${!search}" >> "${tmp}" @@ -51,7 +51,7 @@ fi # As we override the -c option, we need to call the specified script ourself opts="dhcpcd_${ifvar}" exe="${!opts##* -c }" -if [[ -n ${exe} && ${exe} != "${!opts}" ]]; then +if [[ -n ${exe} && ${exe} != "${!opts}" ]] ; then exe="${exe%% *}" else exe="/etc/dhcpc/dhcpcd.exe" diff --git a/net-scripts/net.modules.d/helpers.d/functions b/net-scripts/net.modules.d/helpers.d/functions index 52f3da1..ff67435 100644 --- a/net-scripts/net.modules.d/helpers.d/functions +++ b/net-scripts/net.modules.d/helpers.d/functions @@ -60,23 +60,23 @@ remove_state() { apply_state() { local iface="$1" - if [[ -z ${iface} ]]; then - iface=$( select_best_interface ) + if [[ -z ${iface} ]] ; then + iface="$(select_best_interface)" [[ -z ${iface} ]] && return fi local d="${statedir}/${iface}" - if [[ -d ${d} ]]; then - local files=$( ls "${d}" ) + if [[ -d ${d} ]] ; then + local files="$(ls "${d}")" if [[ -n ${files} ]] ; then - if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then + if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then cp -pPR "${d}"/* "${netdir}" local file for file in ${files} ; do # Skip .sv files [[ ${file} == *".sv" ]] && continue - local link=$( readlink "/etc/${file}" 2>/dev/null ) - if [[ ${link} != "${netdir}/${file}" ]]; then + local link="$(readlink "/etc/${file}" 2>/dev/null)" + if [[ ${link} != "${netdir}/${file}" ]] ; then [[ -e "/etc/${file}" ]] && rm -f "/etc/${file}" ln -snf "${netdir}/${file}" "/etc/${file}" fi @@ -99,8 +99,9 @@ order_interfaces() { local ifaces extra ${1:-false} && extra=' && $2=="00000000"' - ifaces=$(awk '{if (NR>1 && $1!="lo"'"${extra}"') print $7, $1}' /proc/net/route \ - | sort -n | cut -d' ' -f2 | uniq) + ifaces="$(awk '{if (NR>1 && $1!="lo"'"${extra}"') print $7, $1}' \ + /proc/net/route \ + | sort -n | cut -d' ' -f2 | uniq)" # Append lo if it's up if ! ${1:-false} ; then @@ -140,16 +141,18 @@ merge_resolv() { j=0 for (( i=0; i<${#ifaces[@]}; i++ )); do f="${statedir}/${ifaces[i]}/resolv.conf" - srvs[i]=$( sed -n -e 's/^[ \t]*nameserver[ \t]*\([^#]*\).*/\1/p' "${f}" \ - | sed 2q ) + srvs[i]="$(sed -n -e 's/^[ \t]*nameserver[ \t]*\([^#]*\).*/\1/p' \ + "${f}" | sed 2q)" - search[i]=$( sed -n -e 's/^[ \t]*\(domain\|search\)[ \t]*\([^#]*\).*/\2/p' \ - "${f}" | sed -e '$!d' ) + search[i]="$(sed -n -e 's/^[ \t]*\(domain\|search\)[ \t]*\([^#]*\).*/\2/p' \ + "${f}" | sed -e '$!d')" - opts[i]=$( sed -n -e 's/^[ \t]*options[ \t]*\([^#]*\).*/\1#/p;' "${f}" | xargs ) - sortlist[i]=$( sed -n -e 's/^[ \t]*sortlist[ \t]*\([^#]*\).*/\1/p' "${f}" ) + opts[i]="$(sed -n -e 's/^[ \t]*options[ \t]*\([^#]*\).*/\1#/p;' "${f}" \ + | xargs )" + sortlist[i]="$(sed -n -e 's/^[ \t]*sortlist[ \t]*\([^#]*\).*/\1/p' \ + "${f}")" - if [[ -z ${srvs[i]} && -z ${opts[i]} && -z ${sortlist[i]} && -z ${search[i]} ]]; then + if [[ -z ${srvs[i]} && -z ${opts[i]} && -z ${sortlist[i]} && -z ${search[i]} ]] ; then unset srvs[i] unset search[i] unset opts[i] @@ -171,7 +174,7 @@ merge_resolv() { # Add interface primary nameservers for (( i=0;i<${#srvs[@]}; i++ )); do local -a n=( ${srvs[i]} ) - if [[ " ${new_srvs} " != *" ${n[0]} "* ]]; then + if [[ " ${new_srvs} " != *" ${n[0]} "* ]] ; then new_srvs="${new_srvs} ${n[0]}" # libc can only handle 3 name servers (( j++ )) @@ -180,11 +183,11 @@ merge_resolv() { done # Add interface secondary nameservers - if [[ ${j} -lt 3 ]]; then + if [[ ${j} -lt 3 ]] ; then for (( i=0;i<${#srvs[@]}; i++ )); do local -a n=( ${srvs[i]} ) [[ -z ${n[1]} ]] && continue - if [[ " ${new_srvs} " != *" ${n[1]} "* ]]; then + if [[ " ${new_srvs} " != *" ${n[1]} "* ]] ; then new_srvs="${new_srvs} ${n[1]}" # libc can only handle 3 name servers (( j++ )) @@ -195,7 +198,7 @@ merge_resolv() { local new_search n_search=0 for i in ${search[@]}; do - if [[ " ${new_search} " != *" ${i} "* ]]; then + if [[ " ${new_search} " != *" ${i} "* ]] ; then new_search="${new_search} ${i}" # libc limits us to 6 search domains (( n_search++ )) @@ -209,14 +212,14 @@ merge_resolv() { done # Remove duplicate options - new_opts=$( + new_opts="$( echo -e "${new_opts//\#/\n}" \ - | sort -u | sed -e 's/^/#/g' | xargs - ) + | sort -u | sed -e 's/^/#/g' | xargs \ + )" local new_sortlist n_sortlist=0 for i in ${sortlist[@]}; do - if [[ " ${new_sortlist} " != *" ${i} "* ]]; then + if [[ " ${new_sortlist} " != *" ${i} "* ]] ; then new_sortlist="${new_sortlist} ${i}" # libc limits us to 10 items (( n_sortlist++ )) @@ -231,8 +234,8 @@ merge_resolv() { for i in ${new_srvs[@]}; do echo "nameserver ${i}" >> "${f}" done - if [[ -n ${new_search} ]]; then - if [[ ${n_search} == "1" ]]; then + if [[ -n ${new_search} ]] ; then + if [[ ${n_search} == "1" ]] ; then echo "domain${new_search}" >> "${f}" else echo "search${new_search}" >> "${f}" @@ -284,7 +287,7 @@ merge_ntp() { echo -e "$@" | sort -u } - srvs=$( sort_unique ${srvs} ) + srvs="$(sort_unique ${srvs})" f="${netdir}/ntp.conf.$$" echo "# Generated by net-scripts for interfaces ${ifaces[@]}" > "${f}" @@ -325,7 +328,7 @@ select_best_interface() { local iface for iface in ${ifs[@]} ; do - if [[ -e "${statedir}/${iface}/resolv.conf" ]]; then + if [[ -e "${statedir}/${iface}/resolv.conf" ]] ; then echo "${iface}" return 0 fi @@ -343,20 +346,20 @@ calculate_metric() { local iface="$1" exclude='$1!="Iface" && $1!="lo"' # Have we already got a metric? - local m=$( awk '$1=="'${iface}'" && $2=="00000000" { print $7 }' \ - /proc/net/route ) - if [[ -n ${m} ]]; then + local m="$( awk '$1=="'${iface}'" && $2=="00000000" { print $7 }' \ + /proc/net/route )" + if [[ -n ${m} ]] ; then echo "${m}" return 0 fi - local itype=$( interface_type "${iface}" ) x i + local itype="$(interface_type "${iface}")" x i # If we're not a wireless device then exclude wireless from the # routing table so we stay < 1000 - if [[ -e /proc/net/wireless ]]; then + if [[ -e /proc/net/wireless ]] ; then if ! grep -q "^[ \t]*${iface}:[ \t]" /proc/net/wireless ; then - local i=$( sed -n -e 's/^[ \t]*\(.*\):.*/\1/p' /proc/net/wireless ) + local i="$(sed -n -e 's/^[ \t]*\(.*\):.*/\1/p' /proc/net/wireless)" for x in ${i} ; do exclude="${exclude} && "'$1'"!=\"${x}\"" done @@ -367,18 +370,18 @@ calculate_metric() { local ix="ppp|ippp" [[ ${itype} == "ppp" ]] && ix="ippp" [[ ${itype} == "ippp" ]] && ix="ppp" - i=$( sed -n -e 's/^[ ]*\('${ix}'[0-9]*\):.*$/\1/p' /proc/net/dev ) + i="$( sed -n -e 's/^[ ]*\('"${ix}"'[0-9]*\):.*$/\1/p' /proc/net/dev )" for x in ${i} ; do exclude="${exclude} && "'$1'"!=\"${x}\"" done - local m=$( awk "${exclude} { print "'$7'" }" /proc/net/route \ - | sort -rn | head -n 1 | cut -d' ' -f2 ) + local m="$( awk "${exclude} { print "'$7'" }" /proc/net/route \ + | sort -rn | head -n 1 | cut -d' ' -f2 )" m="${m:--1}" (( m ++ )) # If we're a wireless device then add 1000 so that wired interfaces take preference - if [[ -e /proc/net/wireless ]]; then + if [[ -e /proc/net/wireless ]] ; then grep -q "^[ \t]*${iface}:[ \t]" /proc/net/wireless && (( m+= 1000 )) fi @@ -397,7 +400,7 @@ netmask2cidr() { for i in ${1//./ }; do bin="" - while [[ ${i} != "0" ]]; do + while [[ ${i} != "0" ]] ; do bin=$[${i}%2]${bin} (( i=i>>1 )) done @@ -416,13 +419,13 @@ cidr2netmask() { (( octets=cidr/8 )) (( frac=cidr%8 )) - while [[ octets -gt 0 ]]; do + while [[ octets -gt 0 ]] ; do netmask="${netmask}.255" (( octets-- )) (( done++ )) done - if [[ ${done} -lt 4 ]]; then + if [[ ${done} -lt 4 ]] ; then for (( i=0; i<${frac}; i++ )); do (( sum+=cur )) (( cur/=2 )) @@ -430,7 +433,7 @@ cidr2netmask() { netmask="${netmask}.${sum}" (( done++ )) - while [[ ${done} -lt 4 ]]; do + while [[ ${done} -lt 4 ]] ; do netmask="${netmask}.0" (( done++ )) done @@ -452,10 +455,10 @@ ip_network() { [[ ${ip} != *.*.*.* ]] && return # If we didn't get parameter 2 then assume we have a CIDR - if [[ -z ${mask} ]]; then + if [[ -z ${mask} ]] ; then mask="${ip##*/}" [[ -z ${mask} || ${mask} == ${ip} ]] && return 1 - mask=$( cidr2netmask "${mask}" ) + mask="$(cidr2netmask "${mask}")" ip="${ip%%/*}" fi @@ -471,41 +474,6 @@ ip_network() { echo "${network}" } -# bool clean_pidfile(char *file) -# -# Removes the given pidfile if the process is not running -# Returns 1 if the process is still running otherwise 0 -clean_pidfile() { - local pidfile="$1" - - [[ ! -f ${pidfile} ]] && return 0 - local pid=$( < "${pidfile}" ) - - if [[ -n ${pid} ]]; then - local cmd="${pidfile##*/}" - cmd="${cmd%%-*}" - ps p "${pid}" 2>/dev/null | grep -q "${cmd}" && return 1 - fi - - rm -f "${pidfile}" - return 0 -} - -# bool process_finished(int pid, char* cmd) -# -# We wait for 10 seconds until the command ${cmd} -# stops running on the process ${pid} -process_finished() { - local i pid="$1" cmd="$2" secs="${3:-9}" - - for (( i=0; i<secs; i++ )); do - ps p "${pid}" 2>/dev/null | grep -q "${cmd}" || return 0 - sleep 1 - done - - return 1 -} - # bool is_function(char* name) # # Returns 0 if the given name is a shell function, otherwise 1 @@ -560,7 +528,7 @@ configure_variables() { local mod func x i local -a ivars ovars1 ovars2 - local ifvar=$( bash_variable "${iface}" ) + local ifvar="$(bash_variable "${iface}")" for mod in ${MODULES[@]}; do is_function ${mod}_variables || continue @@ -576,18 +544,18 @@ configure_variables() { } # Provide a wrapper for hostname if it's not available -if [[ -z $(type -p hostname) ]]; then +if [[ -z $(type -p hostname) ]] ; then hostname() { # Linux and *BSD seem to differ local kernel="kern" ctl="hostname" [[ $(uname) == "Linux" ]] && kernel="kernel" - if [[ $1 == "-y" || $1 == "--yp" || $1 == "nis" ]]; then + if [[ $1 == "-y" || $1 == "--yp" || $1 == "nis" ]] ; then ctl="domainname" shift fi - if [[ -n $1 ]]; then + if [[ -n $1 ]] ; then sysctl -q -w "${kernel}.${ctl}=$1" else sysctl -n "${kernel}.${ctl}" diff --git a/net-scripts/net.modules.d/helpers.d/module-loader b/net-scripts/net.modules.d/helpers.d/module-loader index fe6d1df..f978f68 100644 --- a/net-scripts/net.modules.d/helpers.d/module-loader +++ b/net-scripts/net.modules.d/helpers.d/module-loader @@ -12,7 +12,7 @@ MODULES_DIR="${svclib}/net.modules.d" conf="$(add_suffix /etc/conf.d/net)" [[ -e ${conf} ]] && source "${conf}" -conf="$(add_suffix /etc/conf.d/net.${interface})" +conf="$(add_suffix "/etc/conf.d/net.${interface}")" [[ -e ${conf} ]] && source "${conf}" # Create some dummy functions, so we can depend on a module @@ -25,9 +25,9 @@ functions() { return; } variables() { eval "${MODULE}_variables() { echo \"$*\"; }"; } # Guess which interface module to load - we prefer iproute2 -if [[ -x /sbin/ip ]]; then +if [[ -x /sbin/ip ]] ; then interface_module="iproute2" -elif [[ -x /sbin/ifconfig ]]; then +elif [[ -x /sbin/ifconfig ]] ; then interface_module="ifconfig" else echo "Can't find a known interface module" >&2 @@ -36,10 +36,10 @@ fi # iwconfig is the best bet for wireless - we use wpa_supplicant # only if we need to -if [[ -x /sbin/iwconfig ]]; then +if [[ -x /sbin/iwconfig ]] ; then wireless_module="iwconfig" elif [[ -x /sbin/wpa_supplicant \ - && -S "/var/run/wpa_supplicant/${interface}" ]]; then + && -S "/var/run/wpa_supplicant/${interface}" ]] ; then wireless_module="wpa_supplicant" fi @@ -51,7 +51,7 @@ MODULE="interface" ${interface_module}_depend function_wrap "${interface_module}" interface -if [[ -e "${MODULES_DIR}/macnet" ]]; then +if [[ -e "${MODULES_DIR}/macnet" ]] ; then . "${MODULES_DIR}/macnet" MODULE="macnet" macnet_depend @@ -61,7 +61,7 @@ fi MODULE="system" system_depend -if [[ -n ${wireless_module} ]]; then +if [[ -n ${wireless_module} ]] ; then . "${MODULES_DIR}/${wireless_module}" MODULE="${wireless_module}" ${wireless_module}_depend diff --git a/net-scripts/net.modules.d/helpers.d/pppd-wrapper b/net-scripts/net.modules.d/helpers.d/pppd-wrapper index 63a868a..c7f6f90 100644 --- a/net-scripts/net.modules.d/helpers.d/pppd-wrapper +++ b/net-scripts/net.modules.d/helpers.d/pppd-wrapper @@ -11,8 +11,8 @@ export IN_BACKGROUND="true" . "${svclib}/net.modules.d/helpers.d/module-loader" resolv="${statedir}/${interface}/resolv.conf" -if [[ ${action} == "up" ]]; then - if [[ -n ${DNS1} || -n ${DNS2} ]]; then +if [[ ${action} == "up" ]] ; then + if [[ -n ${DNS1} || -n ${DNS2} ]] ; then echo "# Generated by pppd for interface $1" > "${resolv}" chmod 0644 "${resolv}" [ -n ${DNS1} ] && echo "nameserver ${DNS1}" >> "${resolv}" @@ -20,12 +20,12 @@ if [[ ${action} == "up" ]]; then fi # Calculate the metric for our routes - ifvar=$( bash_variable "${interface}" ) + ifvar="$(bash_variable "${interface}")" metric="metric_${ifvar}" metric="${!metric}" - if [[ -z ${metric} ]]; then - if [[ ${RC_AUTO_INTERFACE} == "yes" ]]; then - metric=$( calculate_metric "${interface}" ) + if [[ -z ${metric} ]] ; then + if [[ ${RC_AUTO_INTERFACE} == "yes" ]] ; then + metric="$(calculate_metric "${interface}")" else metric="0" fi diff --git a/net-scripts/net.modules.d/helpers.d/pump-wrapper b/net-scripts/net.modules.d/helpers.d/pump-wrapper index fec705c..981480d 100755 --- a/net-scripts/net.modules.d/helpers.d/pump-wrapper +++ b/net-scripts/net.modules.d/helpers.d/pump-wrapper @@ -11,14 +11,14 @@ interface="$2" . /sbin/functions.sh -if [[ ${action} == "up" ]]; then +if [[ ${action} == "up" ]] ; then . "${svclib}/net.modules.d/helpers.d/module-loader" # Map MAC address variables to interface variables macnet_pre_start "${interface}" 1>/dev/null # Map wireless ESSID variables to interface variables - if [[ -n ${wireless_module} ]]; then + if [[ -n ${wireless_module} ]] ; then if wireless_exists "${interface}" ; then essidnet_pre_start "${interface}" 1>/dev/null fi diff --git a/net-scripts/net.modules.d/helpers.d/udhcpc-wrapper b/net-scripts/net.modules.d/helpers.d/udhcpc-wrapper index 3edab95..9548d07 100755 --- a/net-scripts/net.modules.d/helpers.d/udhcpc-wrapper +++ b/net-scripts/net.modules.d/helpers.d/udhcpc-wrapper @@ -18,4 +18,10 @@ export nis_servers_${interface}="${nissrv}" . /sbin/functions.sh "${svclib}/net.modules.d/helpers.d/dhcp" "$@" +if [[ $? == 0 ]] && [[ $1 == "bound" || $1 == "renew" ]] ; then + # Store the address in a cache for future usage + echo "${ip// /}" > "/var/cache/udhcpc-${interface}.lease" + chmod 600 "/var/cache/udhcpc-${interface}.lease" +fi + # vim:ts=4 diff --git a/net-scripts/net.modules.d/ifconfig b/net-scripts/net.modules.d/ifconfig index a7bbff8..966f817 100644 --- a/net-scripts/net.modules.d/ifconfig +++ b/net-scripts/net.modules.d/ifconfig @@ -40,7 +40,7 @@ ifconfig_check_installed() { # # Returns 1 if the interface exists, otherwise 0 ifconfig_exists() { - local e=$( ifconfig -a | grep -o "^$1" ) report="${2:-false}" + local e="$(ifconfig -a | grep -o "^$1")" report="${2:-false}" [[ -n ${e} ]] && return 0 if ${report} ; then @@ -93,7 +93,7 @@ ifconfig_set_flag() { ifconfig_get_address() { local -a x=( $( ifconfig "$1" \ | sed -n -e 's/.*inet addr:\([^ ]*\).*Mask:\([^ ]*\).*/\1 \2/p' ) ) - x[1]=$( netmask2cidr "${x[1]}" ) + x[1]="$(netmask2cidr "${x[1]}")" [[ -n ${x[0]} ]] && echo "${x[0]}/${x[1]}" } @@ -108,8 +108,8 @@ ifconfig_is_ethernet() { # # Fetch the mac address assingned to the network card ifconfig_get_mac_address() { - local mac=$( ifconfig "$1" | sed -n -e \ - 's/.*HWaddr[ \t]*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' ) + local mac="$(ifconfig "$1" | sed -n -e \ + 's/.*HWaddr[ \t]*\<\(..:..:..:..:..:..\)\>.*/\U\1/p')" [[ ${mac} != '00:00:00:00:00:00' \ && ${mac} != '44:44:44:44:44:44' \ && ${mac} != 'FF:FF:FF:FF:FF:FF' ]] \ @@ -131,7 +131,7 @@ ifconfig_set_name() { [[ -z $2 ]] && return 1 local current="$1" new="$2" - local mac=$( ifconfig_get_mac_address "${current}" ) + local mac="$(ifconfig_get_mac_address "${current}")" if [[ -z ${mac} ]]; then eerror "${iface} does not have a MAC address" return 1 @@ -185,7 +185,7 @@ ifconfig_del_addresses() { # # Returns config and config_fallback for the given interface ifconfig_get_old_config() { - local iface="$1" ifvar=$( bash_variable "$1" ) i inet6 + local iface="$1" ifvar="$(bash_variable "$1")" i inet6 config="ifconfig_${ifvar}[@]" config=( "${!config}" ) @@ -256,7 +256,7 @@ ifconfig_pre_start() { interface_exists "${iface}" || return 0 - local ifvar=$( bash_variable "$1" ) mtu + local ifvar="$(bash_variable "$1")" mtu # MTU support mtu="mtu_${ifvar}" @@ -275,7 +275,7 @@ ifconfig_pre_start() { # fail, the routine should still return success to indicate that # net.eth0 was successful ifconfig_post_start() { - local iface="$1" ifvar=$( bash_variable "$1" ) routes x metric mtu cidr + local iface="$1" ifvar="$(bash_variable "$1")" routes x metric mtu cidr metric="metric_${ifvar}" ifconfig_exists "${iface}" || return 0 @@ -338,7 +338,7 @@ ifconfig_post_start() { # # Adds the given address to the interface ifconfig_add_address() { - local iface="$1" i=0 r e real_iface=$(interface_device "$1") + local iface="$1" i=0 r e real_iface="$(interface_device "$1")" ifconfig_exists "${real_iface}" true || return 1 @@ -354,8 +354,8 @@ ifconfig_add_address() { # for multiple addresses if ifconfig "${iface}" | grep -Eq "\<inet addr:.*" ; then # Get the last alias made for the interface and add 1 to it - i=$( ifconfig | tac | grep -m 1 -o "^${iface}:[0-9]*" \ - | sed -n -e 's/'"${iface}"'://p' ) + i="$(ifconfig | tac | grep -m 1 -o "^${iface}:[0-9]*" \ + | sed -n -e 's/'"${iface}"'://p')" i="${i:-0}" (( i++ )) iface="${iface}:${i}" @@ -364,7 +364,7 @@ ifconfig_add_address() { # ifconfig doesn't like CIDR addresses local ip="${config[0]%%/*}" cidr="${config[0]##*/}" netmask if [[ -n ${cidr} && ${cidr} != "${ip}" ]]; then - netmask=$( cidr2netmask "${cidr}" ) + netmask="$(cidr2netmask "${cidr}")" config[0]="${ip} netmask ${netmask}" fi @@ -387,7 +387,7 @@ ifconfig_add_address() { r="$?" [[ ${r} != "0" ]] && return ${r} - local metric ifvar=$(bash_variable "${real_iface}") + local metric ifvar="$(bash_variable "${real_iface}")" # Remove the newly added route and replace with our metric metric="metric_${ifvar}" [[ ${!metric:-0} == "0" ]] && return ${r} @@ -396,14 +396,14 @@ ifconfig_add_address() { for (( i=1; i<${#config[@]}-1; i++ )); do if [[ ${config[i]} == "netmask" ]]; then netmask="${config[i+1]}" - cidr=$( netmask2cidr "${netmask}" ) + cidr="$(netmask2cidr "${netmask}")" break fi done [[ -z ${netmask} ]] && return ${r} fi - local network=$( ip_network "${ip}" "${netmask}" ) + local network="$(ip_network "${ip}" "${netmask}")" if route del -net "${network}/${cidr}" metric 0 dev "${iface}" \ 2>/dev/null ; then diff --git a/net-scripts/net.modules.d/ifplugd b/net-scripts/net.modules.d/ifplugd index edeefe9..13d4e89 100644 --- a/net-scripts/net.modules.d/ifplugd +++ b/net-scripts/net.modules.d/ifplugd @@ -29,7 +29,7 @@ ifplugd_check_installed() { # # Start ifplugd on an interface ifplugd_pre_start() { - local iface="$1" ifvar=$( bash_variable "$1" ) timeout opts + local iface="$1" ifvar="$(bash_variable "$1")" timeout opts local pidfile="/var/run/ifplugd.${iface}.pid" # We don't start ifplugd if we're being called from the background @@ -38,15 +38,15 @@ ifplugd_pre_start() { interface_exists "${iface}" || return 0 # ifplugd could have been started by the old init script - if [[ -e ${pidfile} ]]; then + if [[ -e ${pidfile} ]] ; then vewarn "ifplugd is already running on ${iface}" return 0 fi # We need a valid MAC address # It's a basic test to ensure it's not a virtual interface - local mac=$(interface_get_mac_address "${iface}") - if [[ -z ${mac} ]]; then + local mac="$(interface_get_mac_address "${iface}")" + if [[ -z ${mac} ]] ; then vewarn "ifplugd only works on interfaces with a valid MAC address" return 0 fi @@ -68,9 +68,9 @@ ifplugd_pre_start() { # Although ifplugd can, we prefer wpa_supplicant, unless explicitly told # so via our options if [[ " ${!opts} " != *" -m wlan "* \ - && " ${!opts} " != *" --api-mode=wlan "* ]]; then + && " ${!opts} " != *" --api-mode=wlan "* ]] ; then if is_function wireless_exists ; then - if wireless_exists "${iface}"; then + if wireless_exists "${iface}" ; then veinfo "ifplugd does not work on wireless interfaces" return 0 fi @@ -95,9 +95,9 @@ ifplugd_pre_start() { timeout="timeout_${ifvar}" timeout="${!timeout:--1}" - if [[ ${timeout} == "0" ]]; then + if [[ ${timeout} == "0" ]] ; then ewarn "WARNING: infinite timeout set for ${iface} to come up" - elif [[ ${timeout} -lt 0 ]]; then + elif [[ ${timeout} -lt 0 ]] ; then einfo "Backgrounding ..." exit 0 fi @@ -106,8 +106,8 @@ ifplugd_pre_start() { local i=0 while true ; do - if service_started "net.${iface}"; then - local addr=$( interface_get_address "${iface}" ) + if service_started "net.${iface}" ; then + local addr="$(interface_get_address "${iface}")" einfo "${iface} configured with address ${addr}" exit 0 fi diff --git a/net-scripts/net.modules.d/ipppd b/net-scripts/net.modules.d/ipppd index fd564a4..e7f5c2e 100644 --- a/net-scripts/net.modules.d/ipppd +++ b/net-scripts/net.modules.d/ipppd @@ -11,7 +11,7 @@ ipppd_depend() { after macnet before interface provide isdn - functions interface_exists interface_type clean_pidfile + functions interface_exists interface_type variables ipppd } @@ -30,7 +30,7 @@ ipppd_check_installed() { # # Returns 0 (true) when successful, non-zero otherwise ipppd_pre_start() { - local iface="$1" opts itype=$( interface_type "$1" ) + local iface="$1" opts itype="$(interface_type "$1")" local pidfile="/var/run/ipppd-${iface}.pid" # Check that we are a valid isdn interface @@ -39,20 +39,14 @@ ipppd_pre_start() { # Check that the interface exists interface_exists "${iface}" true || return 1 - if ! clean_pidfile "${pidfile}" ; then - ewarn "ipppd is already running on ${iface}" - eend 0 - return 0 - fi - - local ifvar=$( bash_variable "${iface}" ) + local ifvar="$(bash_variable "${iface}")" # Might or might not be set in conf.d/net opts="ipppd_${ifvar}" einfo "Starting ipppd for ${iface}" - eval start-stop-daemon --start --exec /usr/sbin/ipppd \ + start-stop-daemon --start --exec /usr/sbin/ipppd \ --pidfile "${pidfile}" \ - -- "${!opts}" pidfile "${pidfile}" \ + -- ${!opts} pidfile "${pidfile}" \ file "/etc/ppp/options.${iface}" >/dev/null eend $? || return $? diff --git a/net-scripts/net.modules.d/iptunnel b/net-scripts/net.modules.d/iptunnel index 13fd824..0f951ea 100644 --- a/net-scripts/net.modules.d/iptunnel +++ b/net-scripts/net.modules.d/iptunnel @@ -17,7 +17,7 @@ iptunnel_depend() { # # Create the device, give it the right perms iptunnel_pre_start() { - local iface="$1" opts ifvar=$( bash_variable "$1" ) + local iface="$1" opts ifvar="$(bash_variable "$1")" # Get our options eval opts="iptunnel_${ifvar}" @@ -38,11 +38,11 @@ iptunnel_stop() { [[ ${iface} == "sit0" ]] && return 0 interface_exists "${iface}" || return 0 - [[ -z $( interface_tunnel show "${iface}" 2>/dev/null ) ]] && return 0 + [[ -z $(interface_tunnel show "${iface}" 2>/dev/null) ]] && return 0 ebegin "Destroying tunnel ${iface}" interface_tunnel del "${iface}" - eend "$?" + eend $? } # vim:ts=4 diff --git a/net-scripts/net.modules.d/iwconfig b/net-scripts/net.modules.d/iwconfig index 30e0249..9d079c2 100644 --- a/net-scripts/net.modules.d/iwconfig +++ b/net-scripts/net.modules.d/iwconfig @@ -331,7 +331,13 @@ iwconfig_associate() { local mac="$3" wep_required="$4" w="(WEP Disabled)" local dessid="${ESSID//\\\\/\\\\}" key - iwconfig "${iface}" mode "${mode}" 2>/dev/null + if ! iwconfig "${iface}" mode "${mode}" ; then + eerror "Unable to change mode to ${mode}" + return 1 + fi + interface_down "${iface}" + interface_up "${iface}" + if [[ ${ESSID} == "any" ]]; then iwconfig "${iface}" ap any 2>/dev/null dessid="any" @@ -365,7 +371,7 @@ iwconfig_associate() { fi # Finally apply the user Config - iwconfig_user_config "${iface}" "${ESSIDVAR}" + #iwconfig_user_config "${iface}" "${ESSIDVAR}" vebegin "Connecting to \"${dessid}\" ${w}" diff --git a/net-scripts/net.modules.d/macchanger b/net-scripts/net.modules.d/macchanger index 773a3f2..a81d888 100644 --- a/net-scripts/net.modules.d/macchanger +++ b/net-scripts/net.modules.d/macchanger @@ -20,7 +20,7 @@ macchanger_pre_start() { # We don't change MAC addresses from background ${IN_BACKGROUND} && return 0 - local iface="$1" mac opts ifvar=$( bash_variable "$1" ) + local iface="$1" mac opts ifvar="$(bash_variable "$1")" mac="mac_${ifvar}" [[ -z ${!mac} ]] && return 0 @@ -32,15 +32,15 @@ macchanger_pre_start() { # The interface needs to be up for macchanger to work most of the time interface_down "${iface}" - mac=$( echo "${!mac}" | tr '[:upper:]' '[:lower:]' ) + mac="$(echo "${!mac}" | tr '[:upper:]' '[:lower:]')" case "${mac}" in # specific mac-addr, i wish there were a shorter way to specify this [0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]) # We don't need macchanger to change to a specific mac address interface_set_mac_address "${iface}" "${mac}" eend "$?" - if [[ $? == "0" ]]; then - mac=$( interface_get_mac_address "${iface}" ) + if [[ $? == "0" ]] ; then + mac="$(interface_get_mac_address "${iface}")" eindent einfo "changed to ${mac}" eoutdent @@ -67,22 +67,22 @@ macchanger_pre_start() { *) opts="${opts} ${mac}" ;; esac - if [[ ! -x /sbin/macchanger ]]; then + if [[ ! -x /sbin/macchanger ]] ; then eerror "For changing MAC addresses, emerge net-analyzer/macchanger" return 1 fi - mac=$( /sbin/macchanger ${opts} "${iface}" \ - | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' ) + mac="$( /sbin/macchanger ${opts} "${iface}" \ + | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' )" # Sometimes the interface needs to be up .... - if [[ -z ${mac} ]]; then + if [[ -z ${mac} ]] ; then interface_up "${iface}" - mac=$( /sbin/macchanger ${opts} "${iface}" \ - | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' ) + mac="$( /sbin/macchanger ${opts} "${iface}" \ + | sed -n -e 's/^Faked MAC:.*\<\(..:..:..:..:..:..\)\>.*/\U\1/p' )" fi - if [[ -z ${mac} ]]; then + if [[ -z ${mac} ]] ; then eend 1 "Failed to set MAC address" return 1 fi diff --git a/net-scripts/net.modules.d/macnet b/net-scripts/net.modules.d/macnet index 4c84b2d..d4a52bb 100644 --- a/net-scripts/net.modules.d/macnet +++ b/net-scripts/net.modules.d/macnet @@ -31,7 +31,7 @@ macnet_pre_start() { # address isn't consistent - mainly wireless cards with firmware uploading. interface_up "${iface}" - local mac=$( interface_get_mac_address "${iface}" ) + local mac="$(interface_get_mac_address "${iface}")" [[ -z ${mac} ]] && return 0 vebegin "Configuring ${iface} for MAC address ${mac}" 2>/dev/null diff --git a/net-scripts/net.modules.d/netplugd b/net-scripts/net.modules.d/netplugd index 109e569..244e047 100644 --- a/net-scripts/net.modules.d/netplugd +++ b/net-scripts/net.modules.d/netplugd @@ -39,8 +39,8 @@ netplugd_pre_start() { # We need a valid MAC address # It's a basic test to ensure it's not a virtual interface - local mac=$(interface_get_mac_address "${iface}") - if [[ -z ${mac} ]]; then + local mac="$(interface_get_mac_address "${iface}")" + if [[ -z ${mac} ]] ; then vewarn "netplug only works on interfaces with a valid MAC address" return 0 fi @@ -73,9 +73,9 @@ netplugd_pre_start() { timeout="plug_timeout_${ifvar}" timeout="${!timeout:--1}" - if [[ ${timeout} == "0" ]]; then + if [[ ${timeout} == "0" ]] ; then ewarn "WARNING: infinite timeout set for ${iface} to come up" - elif [[ ${timeout} -lt 0 ]]; then + elif [[ ${timeout} -lt 0 ]] ; then einfo "Backgrounding ..." exit 0 fi @@ -84,8 +84,8 @@ netplugd_pre_start() { local i=0 while true ; do - if service_started "net.${iface}"; then - local addr=$( interface_get_address "${iface}" ) + if service_started "net.${iface}" ; then + local addr="$( interface_get_address "${iface}" )" einfo "${iface} configured with address ${addr}" exit 0 fi diff --git a/net-scripts/net.modules.d/pppd b/net-scripts/net.modules.d/pppd index d74d7ba..eba4b21 100644 --- a/net-scripts/net.modules.d/pppd +++ b/net-scripts/net.modules.d/pppd @@ -63,19 +63,19 @@ pppd_update_secrets_file() { fi #escape username and remotename, used in following sed calls - local regex_username=$(pppd_regex_escape ${username}) - local regex_remotename=$(pppd_regex_escape ${remotename}) + local regex_username="$(pppd_regex_escape "${username}")" + local regex_remotename="$(pppd_regex_escape "${remotename}")" local regex_password local regex_filter="[ \t]*\"?${regex_username}\"?[ \t]*\"?${regex_remotename}\"?[ \t]*" #read old password, including " chars #for being able to distinct when we need to add or update auth info - local old_password=$( + local old_password="$( sed -r -e "/^${regex_filter}\".*\"[ \t]*\$/\ {s/^${regex_filter}(\".*\")[ \t]*\$/\1/;q;};\ d;" \ - ${filepath} - ) + "${filepath}" + )" if [[ -z "${old_password}" ]] ; then regex_username="${username//\\/\\\\}" @@ -103,7 +103,7 @@ pppd_update_secrets_file() { pppd_start() { ${IN_BACKGROUND} && return 0 - local iface="$1" ifvar=$( bash_variable "$1" ) opts="" link + local iface="$1" ifvar="$(bash_variable "$1")" opts="" link if [[ ${iface%%[0-9]*} != "ppp" ]] ; then eerror "PPP can only be invoked from net.ppp[0-9]" return 1 @@ -250,7 +250,7 @@ pppd_start() { fi if [[ " ${opts} " == *" updetach "* ]] ; then - local addr=$( interface_get_address "${iface}" ) + local addr="$(interface_get_address "${iface}")" einfo "${iface} received address ${addr}" else einfo "Backgrounding ..." diff --git a/net-scripts/net.modules.d/pump b/net-scripts/net.modules.d/pump index a4e8c35..f50a695 100644 --- a/net-scripts/net.modules.d/pump +++ b/net-scripts/net.modules.d/pump @@ -58,7 +58,7 @@ pump_stop() { # Returns 0 (true) when a dhcp address is obtained, otherwise # the return value from pump pump_start() { - local iface="$1" opts d ifvar=$( bash_variable "$1" ) search + local iface="$1" opts d ifvar="$(bash_variable "$1")" search interface_exists "${iface}" true || return 1 @@ -92,7 +92,7 @@ pump_start() { eend $? || return $? # pump succeeded, show address retrieved - local addr=$( interface_get_address "${iface}" ) + local addr="$(interface_get_address "${iface}")" einfo "${iface} received address ${addr}" return 0 diff --git a/net-scripts/net.modules.d/rename b/net-scripts/net.modules.d/rename index a02f17c..a9f8b8b 100644 --- a/net-scripts/net.modules.d/rename +++ b/net-scripts/net.modules.d/rename @@ -18,7 +18,7 @@ rename_depend() { # # Checks to see if we have to rename the interface rename_pre_start() { - local iface="$1" newname="" mac ifvar=$( bash_variable "$1" ) + local iface="$1" newname="" mac ifvar="$(bash_variable "$1")" interface_exists "${iface}" || return 0 diff --git a/net-scripts/net.modules.d/system b/net-scripts/net.modules.d/system index 36c279f..df28279 100644 --- a/net-scripts/net.modules.d/system +++ b/net-scripts/net.modules.d/system @@ -13,13 +13,13 @@ system_depend() { } system_dns_extra() { - local iface="$1" ifvar=$( bash_variable "$1" ) out="$2" x sortlist + local iface="$1" ifvar="$(bash_variable "$1")" out="$2" x sortlist local -a options x="dns_options_${ifvar}[@]" options=( "${!x}" ) [[ -z ${options} ]] && options=( "${dns_options[@]}" ) - for x in "${options[@]}"; do + for x in "${options[@]}" ; do echo "options ${x}" >> "${out}" done @@ -29,31 +29,43 @@ system_dns_extra() { } system_dns() { - local iface="$1" ifvar=$( bash_variable "$1" ) x domain search + local iface="$1" ifvar="$(bash_variable "$1")" x domain search local conffile="${statedir}/${iface}/resolv.conf" tmpfile="${conffile}.$$" local -a servers servers="dns_servers_${ifvar}[@]" [[ -z ${!servers} ]] && servers="dns_servers[@]" + servers="${!servers}" domain="dns_domain_${ifvar}" [[ -z ${!domain} ]] && domain="dns_domain" + domain="${!domain}" search="dns_search_${ifvar}" [[ -z ${!search} ]] && search="dns_search" + search="${!search}" - [[ -z ${!servers} && -z ${!domain} && -z ${!search} ]] && return 0 + [[ -z ${servers} && -z ${domain} && -z ${search} ]] && return 0 echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" chmod 644 "${tmpfile}" - [[ -n ${!domain} ]] && echo "domain ${!domain}" >> "${tmpfile}" + if [[ -n ${domain} ]] ; then + # Strip leading and trailing spaces + domain="${domain# *}" + domain="${domain%* }" + if [[ ${domain} == *" "* ]] ; then + [[ -z ${search} ]] && search="${domain}" + domain="${domain%% *}" + fi + echo "domain ${domain}" >> "${tmpfile}" + fi - for x in ${!servers} ; do + for x in ${servers} ; do echo "nameserver ${x}" >> "${tmpfile}" done - [[ -n ${!search} ]] && echo "search ${!search}" >> "${tmpfile}" + [[ -n ${search} ]] && echo "search ${search}" >> "${tmpfile}" system_dns_extra "${iface}" "${tmpfile}" @@ -61,7 +73,7 @@ system_dns() { } system_ntp() { - local iface="$1" ifvar=$( bash_variable "$1" ) x + local iface="$1" ifvar="$(bash_variable "$1")" x local conffile="${statedir}/${iface}/ntp.conf" tmpfile="${conffile}.$$" local -a servers @@ -75,7 +87,7 @@ system_ntp() { echo "restrict default noquery notrust nomodify" >> "${tmpfile}" echo "restrict 127.0.0.1" >> "${tmpfile}" - for x in ${!servers}; do + for x in ${!servers} ; do echo "restrict ${x} nomodify notrap noquery" >> "${tmpfile}" echo "server ${x}" >> "${tmpfile}" done @@ -87,7 +99,7 @@ system_ntp() { } system_nis() { - local iface="$1" ifvar=$( bash_variable "$1" ) domain x + local iface="$1" ifvar="$(bash_variable "$1")" domain x local conffile="${statedir}/${iface}/yp.conf" tmpfile="${conffile}.$$" local -a servers @@ -102,17 +114,17 @@ system_nis() { echo "# Generated by net-scripts for interface ${iface}" > "${tmpfile}" chmod 644 "${tmpfile}" - if [[ -n ${!domain} ]]; then + if [[ -n ${!domain} ]] ; then hostname -y "${!domain}" - if [[ -n ${!servers} ]]; then - for x in ${!servers}; do + if [[ -n ${!servers} ]] ; then + for x in ${!servers} ; do echo "domain ${!domain} server ${x}" >> "${tmpfile}" done else echo "domain ${!domain} broadcast" >> "${tmpfile}" fi else - for x in ${!servers}; do + for x in ${!servers} ; do echo "ypserver ${x}" >> "${tmpfile}" done fi diff --git a/net-scripts/net.modules.d/udhcpc b/net-scripts/net.modules.d/udhcpc index b7dde5a..7e998a4 100644 --- a/net-scripts/net.modules.d/udhcpc +++ b/net-scripts/net.modules.d/udhcpc @@ -39,26 +39,21 @@ udhcpc_stop() { [[ ! -f ${pidfile} ]] && return 0 ebegin "Stopping udhcpc on ${iface}" - local pid=$( < "${pidfile}" ) e=true + local pid="$(<"${pidfile}")" e=true - local ifvar=$( bash_variable "${iface}" ) + local ifvar="$(bash_variable "${iface}")" d="dhcp_${ifvar}" d=" ${!d} " [[ ${d} == " " ]] && d=" ${dhcp} " if [[ ${d} == *" release "* ]]; then kill -s USR2 "${pid}" &>/dev/null - [[ -f "/var/cache/dhcp-${iface}.lease" ]] \ - && rm "/var/cache/dhcp-${iface}.lease" + [[ -f "/var/cache/udhcpc-${iface}.lease" ]] \ + && rm "/var/cache/udhcpc-${iface}.lease" fi - kill -s TERM "${pid}" &>/dev/null - - [[ -f ${pidfile} ]] && rm -f "${pidfile}" - - ${e} - eend "$?" - return "$?" + start-stop-daemon --stop --exec /sbin/udhcpc --pidfile "${pidfile}" + eend $? } # bool udhcpc_start(char *iface) @@ -68,11 +63,11 @@ udhcpc_stop() { # Returns 0 (true) when a DHCP address is obtained, otherwise 1 udhcpc_start() { local iface="$1" opts pidfile="/var/run/udhcpc-$1.pid" - local cachefile="/var/cache/dhcp-$1.lease" d + local cachefile="/var/cache/udhcpc-$1.lease" d interface_exists "${iface}" true || return 1 - local ifvar=$( bash_variable "${iface}" ) opts + local ifvar="$(bash_variable "${iface}" )" opts opts="udhcpc_${ifvar}" opts="${!opts}" @@ -82,7 +77,7 @@ udhcpc_start() { if [[ " ${d} " != *" nosendhost "* ]]; then if [[ ! " ${opts}" =~ " -([hH] |-hostname=)" ]]; then - local hname=$( hostname ) + local hname="$(hostname)" [[ -n ${hname} && ${hname} != "(none)" && ${hname} != "localhost" ]] \ && opts="${opts} --hostname=${hname}" fi @@ -94,22 +89,22 @@ udhcpc_start() { # Try and load the cache if it exists if [[ -f ${cachefile} ]]; then if [[ " ${opts}" != *" --request="* && " ${opts} " != *" -r "* ]]; then - local x=$( < "${cachefile}" ) + local x="$(<"${cachefile}")" # Check for a valid ip [[ ${x} == *.*.*.* ]] && opts="${opts} --request=${x}" fi fi - x=$( eval udhcpc "${opts}" --now --pidfile="${pidfile}" \ + x="$( eval udhcpc "${opts}" --now --pidfile="${pidfile}" \ --interface="${iface}" \ --script="${MODULES_DIR}/helpers.d/udhcpc-wrapper" 2>&1 \ - | egrep -v '^info,' ) + | egrep -v '^info,' )" # We just check the last 5 letters [[ ${x:((${#x} - 5)):5} == "bound" ]] eend "$?" "${x}" || return 1 # DHCP succeeded, show address retrieved - local addr=$( interface_get_address "${iface}" ) + local addr="$(interface_get_address "${iface}")" einfo "${iface} received address ${addr}" return 0 diff --git a/net-scripts/net.modules.d/vlan b/net-scripts/net.modules.d/vlan index e35196a..4a103c2 100644 --- a/net-scripts/net.modules.d/vlan +++ b/net-scripts/net.modules.d/vlan @@ -62,7 +62,7 @@ vlan_check_kernel() { # # Setup vconfig vlan_pre_start() { - local iface="$1" opts i x e ifvar=$( bash_variable "$1" ) + local iface="$1" opts i x e ifvar="$(bash_variable "$1")" opts="vconfig_${ifvar}[@]" [[ -z ${!opts} ]] && return 0 @@ -71,14 +71,14 @@ vlan_pre_start() { vlan_check_kernel || return 1 interface_exists "${iface}" || return 1 - for (( i=0; i<${#opts[@]}; i++ )); do + for (( i=0; i<${#opts[@]}; i++ )) ; do if [[ ${opts[i]} == "set_name_type "* ]]; then x="${opts[i]}" else x="${opts[i]/ / ${iface} }" [[ ${x} == "${opts[i]}" ]] && x="${x} ${iface}" fi - e=$( vconfig ${x} 2>&1 1>/dev/null ) + e="$(vconfig ${x} 2>&1 1>/dev/null)" [[ -z ${e} ]] && continue eerror "vconfig ${x}" eerror "${e}" @@ -94,7 +94,7 @@ vlan_pre_start() { # # Always returns 0 (true) vlan_post_start() { - local iface="$1" vlan vlans vlans_old e ifname ifvar=$( bash_variable "$1" ) + local iface="$1" vlan vlans vlans_old e ifname ifvar="$(bash_variable "$1")" vlans="vlans_${ifvar}[@]" @@ -108,9 +108,9 @@ vlan_post_start() { interface_exists "${iface}" true || return 1 # Start vlans for this interface - for vlan in ${!vlans}; do + for vlan in ${!vlans} ; do einfo "Adding VLAN ${vlan} to ${iface}" - e=$( vconfig add "${iface}" "${vlan}" 2>&1 1>/dev/null ) + e="$(vconfig add "${iface}" "${vlan}" 2>&1 1>/dev/null)" if [[ -n ${e} ]] ; then eend 1 "${e}" continue @@ -118,10 +118,10 @@ vlan_post_start() { eend 0 # We need to work out the interface name of our new vlan id - ifname=$( \ + ifname="$( \ sed -n -e 's/^\([^ \t]*\) *| '"${vlan}"' *| .*'"${iface}"'$/\1/p' \ /proc/net/vlan/config - ) + )" iface_start "${ifname}" done @@ -138,7 +138,7 @@ vlan_stop() { vlan_check_installed || return 0 - for vlan in $( vlan_get_vlans "${iface}" ); do + for vlan in $(vlan_get_vlans "${iface}"); do einfo "Removing VLAN ${vlan##*.} from ${iface}" iface_stop "${vlan}" vconfig rem "${vlan}" >/dev/null diff --git a/net-scripts/net.modules.d/wpa_supplicant b/net-scripts/net.modules.d/wpa_supplicant index c695a27..184fd4d 100644 --- a/net-scripts/net.modules.d/wpa_supplicant +++ b/net-scripts/net.modules.d/wpa_supplicant @@ -29,11 +29,11 @@ wpa_supplicant_depend() { # Returns 0 if wpa_supplicant is installed, otherwise 1 wpa_supplicant_check_installed() { local report="${1:-false}" installed="0" - if [[ ! -x /sbin/wpa_supplicant ]]; then + if [[ ! -x /sbin/wpa_supplicant ]] ; then installed="1" ${report} && eerror "For WPA support (wpa_supplicant) support, emerge net-wireless/wpa_supplicant" fi - if [[ ! -e /proc/net/packet ]]; then + if [[ ! -e /proc/net/packet ]] ; then installed="1" if ${report} ; then eerror "wpa_supplicant requires Packet Socket" @@ -59,7 +59,7 @@ wpa_supplicant_get_essid() { for (( i=0; i<5; i++ )); do essid="$( wpa_cli -i"$1" status | sed -n -e 's/^ssid=//p' )" - if [[ -n ${essid} ]]; then + if [[ -n ${essid} ]] ; then echo "${essid}" return 0 fi @@ -105,7 +105,7 @@ wpa_supplicant_kill() { # This is important as future versions of wpa_supplicant # may send a disconnect message to wpa_cli when it shutsdown pidfile="/var/run/wpa_cli-${iface}.pid" - if ! clean_pidfile "${pidfile}" ; then + if [[ -f ${pidfile} ]] ; then ${report} && ebegin "Stopping wpa_cli on ${iface}" start-stop-daemon --stop --exec /bin/wpa_cli --pidfile "${pidfile}" ${report} && eend "$?" @@ -113,7 +113,7 @@ wpa_supplicant_kill() { # Now shutdown wpa_supplicant pidfile="/var/run/wpa_supplicant-${iface}.pid" - if ! clean_pidfile "${pidfile}" ; then + if [[ -f ${pidfile} ]] ; then ${report} && ebegin "Stopping wpa_supplicant on ${iface}" start-stop-daemon --stop --exec /sbin/wpa_supplicant \ --pidfile "${pidfile}" @@ -121,7 +121,7 @@ wpa_supplicant_kill() { else # Support wpa_supplicant-0.3.x local pid="$( pgrep -f "^/sbin/wpa_supplicant .* -i${iface}[ ]*$" )" - if [[ -n ${pid} ]]; then + if [[ -n ${pid} ]] ; then ${report} && ebegin "Stopping wpa_supplicant on ${iface}" kill -s TERM "${pid}" ${report} && eend 0 @@ -138,14 +138,14 @@ wpa_supplicant_kill() { # Returns 0 if wpa_supplicant associates and authenticates to an AP # otherwise, 1 wpa_supplicant_associate() { - local iface="$1" ifvar="$( bash_variable "$1" )" timeout + local iface="$1" ifvar="$(bash_variable "$1")" timeout timeout="associate_timeout_${ifvar}" [[ -z ${!timeout} ]] && timeout="wpa_timeout_${ifvar}" timeout="${!timeout:--1}" - if [[ ${timeout} == "0" ]]; then + if [[ ${timeout} == "0" ]] ; then ewarn "WARNING: infinite timeout set for association on ${iface}" - elif [[ ${timeout} -lt 0 ]]; then + elif [[ ${timeout} -lt 0 ]] ; then einfo "Backgrounding ..." exit 0 fi @@ -213,7 +213,7 @@ wpa_supplicant_pre_start() { # We only work on wirelesss interfaces unless a driver for wired # has been defined - if [[ ${opts} != *" -Dwired "* && ${opts} != *" -D wired "* ]]; then + if [[ ${opts} != *" -Dwired "* && ${opts} != *" -D wired "* ]] ; then if ! wpa_supplicant_exists "${iface}" ; then veinfo "wpa_supplicant only works on wireless interfaces" veinfo "unless the -D wired option is specified" @@ -223,8 +223,8 @@ wpa_supplicant_pre_start() { # Check for rf_kill - only ipw supports this at present, but other # cards may in the future - if [[ -e "/sys/class/net/${iface}/device/rf_kill" ]]; then - if [[ $( < "/sys/class/net/${iface}/device/rf_kill" ) != 0 ]]; then + if [[ -e "/sys/class/net/${iface}/device/rf_kill" ]] ; then + if [[ $( < "/sys/class/net/${iface}/device/rf_kill" ) != 0 ]] ; then eerror "Wireless radio has been killed for interface ${iface}" return 1 fi @@ -243,7 +243,7 @@ wpa_supplicant_pre_start() { ebegin "Starting wpa_supplicant on ${iface}" cfgfile="${opts##* -c}" - if [[ -n ${cfgfile} && ${cfgfile} != "${opts}" ]]; then + if [[ -n ${cfgfile} && ${cfgfile} != "${opts}" ]] ; then [[ ${cfgfile:0:1} == " " ]] && cfgfile="${cfgfile# *}" cfgfile="${cfgfile%% *}" else @@ -256,13 +256,13 @@ wpa_supplicant_pre_start() { opts="${opts} -c${cfgfile}" fi - if [[ ! -f ${cfgfile} ]]; then + if [[ ! -f ${cfgfile} ]] ; then eend 1 "configuration file ${cfgfile} not found!" return 1 fi local ctrl_dir="$( sed -n -e 's/[ \t]*#.*//g;s/[ \t]*$//g;s/^ctrl_interface=//p' "${cfgfile}" )" - if [[ ${ctrl_dir} != "/var/run/wpa_supplicant" ]]; then + if [[ ${ctrl_dir} != "/var/run/wpa_supplicant" ]] ; then eerror "${cfgfile} must set" eerror " ctrl_interface=/var/run/wpa_supplicant" eend 1 @@ -282,7 +282,7 @@ wpa_supplicant_pre_start() { # wpa_cli is now responsible for informing us of success/failure. # The downside of this is that we don't see the interface being configured # for DHCP/static. - if [[ ${version} -gt 399 ]]; then + if [[ ${version} -gt 399 ]] ; then opts="${opts} -W -P/var/run/wpa_supplicant-${iface}.pid" actfile="/etc/wpa_supplicant/wpa_cli.sh" # Support old file location @@ -324,8 +324,8 @@ wpa_supplicant_pre_start() { eval status=( $( wpa_cli -i"${iface}" status | sed -n -e 's/^\(bssid\|pairwise_cipher\|key_mgmt\)=\([^=]\+\).*/\"\U\2\"/p' | tr '[:lower:]' '[:upper:]' ) ) einfo "${iface} connected to \"${ESSID//\\\\/\\\\}\" at ${status[0]}" - if [[ ${status[2]} == "NONE" ]]; then - if [[ ${status[1]} == "NONE" ]]; then + if [[ ${status[2]} == "NONE" ]] ; then + if [[ ${status[1]} == "NONE" ]] ; then ewarn "not using any encryption" else veinfo "using ${status[1]}" |