2 # Shell script compatibility wrappers for /sbin/uci
4 # Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
5 # Copyright (C) 2009 Daniel Dickinson
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # $UCI and $UCISTATE must be set
35 if [ -z "$CONFIG_APPEND" ]; then
41 DATA
="$($UCI -P $UCISTATE -S -n export "$PACKAGE" 2>/dev/null)"
43 [ "$RET" != 0 -o -z "$DATA" ] ||
eval "$DATA"
46 ${CONFIG_SECTION:+config_cb}
51 config_cb
() { return 0; }
52 option_cb
() { return 0; }
53 list_cb
() { return 0; }
60 CONFIG_NUM_SECTIONS
=$
(($CONFIG_NUM_SECTIONS + 1))
61 name
="${name:-cfg$CONFIG_NUM_SECTIONS}"
62 append CONFIG_SECTIONS
"$name"
63 [ -n "$NO_CALLBACK" ] || config_cb
"$cfgtype" "$name"
64 CONFIG_SECTION
="$name"
65 eval "CONFIG_${CONFIG_SECTION}_TYPE=\"$cfgtype\""
69 local varname
="$1"; shift
72 eval "CONFIG_${CONFIG_SECTION}_${varname}=\"$value\""
73 [ -n "$NO_CALLBACK" ] || option_cb
"$varname" "$*"
77 local varname
="$1"; shift
81 config_get len
"$CONFIG_SECTION" "${varname}_LENGTH"
82 len
="$((${len:-0} + 1))"
83 config_set
"$CONFIG_SECTION" "${varname}_ITEM$len" "$value"
84 config_set
"$CONFIG_SECTION" "${varname}_LENGTH" "$len"
85 append
"CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP"
86 list_cb
"$varname" "$*"
91 "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
92 *) eval "$1=\${CONFIG_${2}_${3}}";;
98 [ "$#" -ge 1 ] && shift
100 [ "$#" -ge 1 ] && shift
101 local section cfgtype
103 [ -z "$CONFIG_SECTIONS" ] && return 0
104 for section
in ${CONFIG_SECTIONS}; do
105 config_get cfgtype
"$section" TYPE
106 [ -n "$type" -a "x$cfgtype" != "x$type" ] && continue
107 $function "$section" "$@"
120 eval "$var=\${$var:+\${$var}\${value:+\$sep}}\$value"