1 # Copyright (C) 2009-2010 OpenWrt.org
2 # Copyright (C) 2009 Malte S. Stretz <http://msquadrat.de>
4 # This is a temporary file, I hope to have some of this stuff merged into
5 # /lib/functions.sh (without the fw_ prefix of course) one day.
7 fw_config_append
() { # <package>
8 CONFIG_APPEND
=1 config_load
"$@"
12 fw_config_once
() { # <function> <type>
21 config_foreach fw_config__once
"$type"
26 fw_config_get_section
() { # <config> <prefix> <type> <name> <default> ...
31 [ -n "$config" ] ||
return 1
34 export ${NO_EXPORT:+-n} -- "${prefix}NAME"="${config}"
35 config_get "${prefix}TYPE
" "$config" TYPE
38 [ "$1" == '{' ] && shift
39 while [ $# -ge 3 ]; do
44 # TODO: Move handling of defaults to /lib/functions.sh
45 # and get replace the case block with the following
48 # config_get${type:+_${type}} "${prefix}${name}" "$config" "$name" "$dflt" ||
return
52 config_get tmp
"$config" "$name" ||
return
53 [ -z "$tmp" ] && tmp
=$dflt
54 export ${NO_EXPORT:+-n} -- "${prefix}${name}=${tmp}"
62 local cmd=${prefix}config_get_${type}
63 type $cmd > /dev/null || {
64 cmd=config_get_${type}
66 type $cmd > /dev/null || {
67 echo "config
type $type (for $name) not supported
" >&2
70 $cmd "${prefix}${name}" "$config" "$name" "$dflt" || return
81 config_get addr "$conf" "$name" || return
82 [ -n "$addr" ] || addr=$dflt
85 [ "$mask" != "$addr" ] || mask=
90 *:*) vers=6; mask="${mask:-128}" ;;
91 *.*) vers=4; mask="${mask:-32}" ;;
94 export ${NO_EXPORT:+-n} -- "${varn}=${addr}"
95 export ${NO_EXPORT:+-n} -- "${varn}_prefixlen=${mask}"
96 export ${NO_EXPORT:+-n} -- "${varn}_version=${vers}"