net: net.lo, lots of scripts

The program function in depend blocks is now able to search paths by
itself. If passed multiple arguments or multiple calls, at least one of
the arguments passed must be a program or a shell builtin (eg ip built
into busybox). If a qualified path is specified, only that path will be
checked, otherwise it will be checked as a builtin, then $PATH will be
checked for the named binary (via type).

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
This commit is contained in:
Robin H. Johnson 2012-01-08 16:24:03 -08:00
parent d02d3af02e
commit 4255ba175b
10 changed files with 36 additions and 42 deletions

View File

@ -172,7 +172,9 @@ _configure_variables()
_which()
{
local i OIFS
# Empty
[ -z "$1" ] && return
# check paths
OIFS="$IFS"
IFS=:
for i in $PATH ; do
@ -181,6 +183,22 @@ _which()
IFS=$OIFS
}
# Like _which, but also consider shell builtins, and multiple alternatives
_program_available()
{
[ -z "$1" ] && return 0
local x=
for x; do
case "${x}" in
/*) [ -x "${x}" ] && break;;
*) type "${x}" >/dev/null 2>&1 && break;;
esac
unset x
done
[ -n "${x}" ] && echo $x && return 0
return 1
}
_show_address()
{
einfo "received address $(_get_inet_address "${IFACE}")"
@ -323,11 +341,10 @@ _load_modules()
eval set -- \$module_${i}_program
if [ -n "$1" ]; then
x=
for x; do
[ -x "${x}" ] && break
done
[ -x "${x}" ] || continue
if ! _program_available "$@" >/dev/null; then
vewarn "Skipping module $mod due to missing program: $@"
continue
fi
fi
if ${starting}; then
eval set -- \$module_${i}_program_start
@ -335,15 +352,10 @@ _load_modules()
eval set -- \$module_${i}_program_stop
fi
if [ -n "$1" ]; then
x=
for x; do
case "${x}" in
/*) [ -x "${x}" ] && break;;
*) type "${x}" >/dev/null 2>&1 && break;;
esac
unset x
done
[ -n "${x}" ] || continue
if ! _program_available "$@" >/dev/null; then
vewarn "Skipping module $mod due to missing program: $@"
continue
fi
fi
eval provides=\$module_${i}_provide

View File

@ -1,19 +1,10 @@
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
# Released under the 2-clause BSD license.
_br2684ctl()
{
if [ -x /usr/sbin/br2684ctl ]; then
echo /usr/sbin/br2684ctl
else
echo /sbin/br2684ctl
fi
}
br2684ctl_depend()
{
before ppp
program start $(_br2684ctl)
program start br2684ctl
}
_config_vars="$_config_vars bridge bridge_add brctl"
@ -42,7 +33,7 @@ br2684ctl_pre_start()
esac
einfo "Starting RFC 2684 Bridge control on ${IFACE}"
start-stop-daemon --start --exec $(_br2684ctl) --background \
start-stop-daemon --start --exec $(_which br2684ctl) --background \
--make-pidfile --pidfile "/var/run/br2684ctl-${IFACE}.pid" \
-- -c "${IFACE#nas*}" ${opts}
eend $?

View File

@ -4,7 +4,7 @@
bridge_depend()
{
before interface macnet
program /sbin/brctl
program brctl
}
_config_vars="$_config_vars bridge bridge_add brctl"

View File

@ -3,10 +3,7 @@
ethtool_depend()
{
local x
x=$(_which ethtool)
[ -z "$x" ] && return 1
program $x
program ethtool
before interface
}

View File

@ -6,6 +6,7 @@ _config_vars="$_config_vars link suffix relay"
ip6to4_depend()
{
after interface
program ip
}
ip6to4_pre_start()

View File

@ -3,10 +3,7 @@
iproute2_depend()
{
local x
x=$(_which ip)
[ -z "$x" ] && return 1
program $x
program ip
provide interface
after ifconfig
}

View File

@ -4,6 +4,7 @@
macchanger_depend()
{
before macnet
# no program 'macchanger', as we have partial functionality without it
}
_config_vars="$_config_vars mac"

View File

@ -5,10 +5,7 @@
macvlan_depend()
{
local x
x=$(_which ip)
[ -z "${X}" ] && return 1
program $x
program ip
after interface
before dhcp macchanger
}

View File

@ -4,6 +4,7 @@
tuntap_depend()
{
before bridge interface macchanger
program ip openvpn tunctl
}
_config_vars="$_config_vars iproute2 openvpn tunctl"

View File

@ -3,10 +3,7 @@
vlan_depend()
{
local x
x=$(_which ip)
[ -z "$x" ] && return 1
program $x
program ip
after interface
before dhcp
}