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
39 config_get_bool enabled "$config" enabled 1
40 [ $enabled -eq 1 ] || return 1
42 [ "$1" == '{' ] && shift
43 while [ $# -ge 3 ]; do
48 # TODO: Move handling of defaults to /lib/functions.sh
49 # and get replace the case block with the following
52 # config_get${type:+_${type}} "${prefix}${name}" "$config" "$name" "$dflt" ||
return
56 config_get tmp
"$config" "$name" ||
return
57 [ -z "$tmp" ] && tmp
=$dflt
58 export ${NO_EXPORT:+-n} -- "${prefix}${name}=${tmp}"
66 local cmd=${prefix}config_get_${type}
67 type $cmd > /dev/null || {
68 cmd=config_get_${type}
70 type $cmd > /dev/null || {
71 echo "config
type $type (for $name) not supported
" >&2
74 $cmd "${prefix}${name}" "$config" "$name" "$dflt" || return
85 config_get addr "$conf" "$name" || return
86 [ -n "$addr" ] || addr=$dflt
89 [ "$mask" != "$addr" ] || mask=
94 *:*) vers=6; mask="${mask:-128}" ;;
95 *.*) vers=4; mask="${mask:-32}" ;;
98 export ${NO_EXPORT:+-n} -- "${varn}=${addr}"
99 export ${NO_EXPORT:+-n} -- "${varn}_prefixlen=${mask}"
100 export ${NO_EXPORT:+-n} -- "${varn}_version=${vers}"