summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'net-scripts/net.modules.d/helpers.d')
-rwxr-xr-xnet-scripts/net.modules.d/helpers.d/dhcp6
-rw-r--r--net-scripts/net.modules.d/helpers.d/functions49
-rw-r--r--net-scripts/net.modules.d/helpers.d/module-loader26
3 files changed, 64 insertions, 17 deletions
diff --git a/net-scripts/net.modules.d/helpers.d/dhcp b/net-scripts/net.modules.d/helpers.d/dhcp
index 3996c1a..133ffae 100755
--- a/net-scripts/net.modules.d/helpers.d/dhcp
+++ b/net-scripts/net.modules.d/helpers.d/dhcp
@@ -102,12 +102,12 @@ fi
# Configure our hostname - but only if we need it
if [[ -n ${hostname} ]]; then
- x=$( /bin/hostname )
- [[ ${x} == "(none)" || ${x} == "localhost" ]] && /bin/hostname "${hostname}"
+ x=$( hostname )
+ [[ ${x} == "(none)" || ${x} == "localhost" ]] && hostname "${hostname}"
fi
[[ ! -d "${statedir}/${interface}" ]] \
-&& mkdir -m 0755 -p "${statedir}/${interface}"
+ && mkdir -m 0755 -p "${statedir}/${interface}"
# Only setup the information we're told to
# By default that's everything
diff --git a/net-scripts/net.modules.d/helpers.d/functions b/net-scripts/net.modules.d/helpers.d/functions
index 5f80d34..3931fb4 100644
--- a/net-scripts/net.modules.d/helpers.d/functions
+++ b/net-scripts/net.modules.d/helpers.d/functions
@@ -508,6 +508,14 @@ process_finished() {
return 1
}
+# bool is_function(char* name)
+#
+# Returns 0 if the given name is a shell function, otherwise 1
+is_function() {
+ [[ -z $1 ]] && return 1
+ [[ $(type -t "$1") == "function" ]]
+}
+
# void function_wrap(char* source, char* target)
#
# wraps function calls - for example function_wrap(this, that)
@@ -515,7 +523,7 @@ process_finished() {
function_wrap() {
local i
- [[ $( type -t "${2}_provides" ) == "function" ]] && return
+ is_function "${2}_depend" && return
for i in $( typeset -f | grep -o '^'"${1}"'_[^ ]*' ); do
eval "${2}${i#${1}}() { ${i} \"\$@\"; }"
@@ -557,21 +565,36 @@ configure_variables() {
local ifvar=$( bash_variable "${iface}" )
for mod in ${MODULES[@]}; do
- func="${mod}_get_vars"
- if [[ $( type -t ${func} ) == "function" ]]; then
- ivars=( $( "${func}" "${ifvar}" ) )
- ovars1=( $( "${func}" "${option1}" ) )
- [[ -n ${option2} ]] && ovars2=( $( "${func}" "${option2}" ) )
- for ((i = 0; i<${#ivars[@]}; i++)); do
- x=""
- [[ -n ${ovars2[i]} ]] && eval x=( \"\$\{${ovars2[i]}\[@\]\}\" )
- [[ -z ${x} ]] && eval x=( \"\$\{${ovars1[i]}\[@\]\}\" )
- [[ -n ${x} ]] && eval "${ivars[i]}=( "\"\$\{x\[@\]\}\"" )"
- done
- fi
+ is_function ${mod}_variables || continue
+ for v in $(${mod}_variables) ; do
+ x=""
+ [[ -n ${option2} ]] && eval x=( \"\$\{${v}_${option2}\[@\]\}\" )
+ [[ -z ${x} ]] && eval x=( \"\$\{${v}_${option1}\[@\]\}\" )
+ [[ -n ${x} ]] && eval "${v}_${ifvar}=( "\"\$\{x\[@\]\}\"" )"
+ done
done
return 0
}
+# Provide a wrapper for hostname if it's not available
+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
+ ctl="domainname"
+ shift
+ fi
+
+ if [[ -n $1 ]]; then
+ sysctl -q -w "${kernel}.${ctl}=$1"
+ else
+ sysctl -n "${kernel}.${ctl}"
+ fi
+ }
+fi
+
# vim:ts=4
diff --git a/net-scripts/net.modules.d/helpers.d/module-loader b/net-scripts/net.modules.d/helpers.d/module-loader
index f4f5f95..1434bbb 100644
--- a/net-scripts/net.modules.d/helpers.d/module-loader
+++ b/net-scripts/net.modules.d/helpers.d/module-loader
@@ -11,6 +11,15 @@
conf=$(add_suffix "/etc/conf.d/net")
[[ -e ${conf} ]] && source "${conf}"
+# Create some dummy functions, so we can depend on a module
+after() { return; }
+before() { return; }
+need() { return; }
+provide() { return; }
+installed() { return; }
+functions() { return; }
+variables() { eval "${MODULE}_variables() { echo \"$*\"; }"; }
+
# Guess which interface module to load - we prefer iproute2
if [[ -x /sbin/ip ]]; then
interface_module="iproute2"
@@ -34,14 +43,29 @@ MODULES=( "system" )
# Load our modules
. "${MODULES_DIR}/${interface_module}"
+MODULE="interface"
+${interface_module}_depend
function_wrap "${interface_module}" interface
-. "${MODULES_DIR}/macnet"
+
+if [[ -e "${MODULES_DIR}/macnet" ]]; then
+ . "${MODULES_DIR}/macnet"
+ MODULE="macnet"
+ macnet_depend
+fi
+
. "${MODULES_DIR}/system"
+MODULE="system"
+system_depend
if [[ -n ${wireless_module} ]]; then
. "${MODULES_DIR}/${wireless_module}"
+ MODULE="${wireless_module}"
+ ${wireless_module}_depend
function_wrap "${wireless_module}" wireless
. "${MODULES_DIR}/essidnet"
fi
+# Dummy dhcp
+dhcp_variables() { echo "dhcp"; }
+
# vim:ts=4