2 # Shell script compatibility wrappers for /sbin/uci
4 # Copyright (C) 2008-2010 OpenWrt.org
5 # Copyright (C) 2008 Felix Fietkau <nbd@nbd.name>
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
22 UCI
="${UCI:-/sbin/uci}"
23 UCI_STATE_DIR
="${IPKG_INSTROOT}/var/state}"
32 if [ -z "$CONFIG_APPEND" ]; then
33 for VAR
in $CONFIG_LIST_STATE; do
34 export ${NO_EXPORT:+-n} CONFIG_
${VAR}=
35 export ${NO_EXPORT:+-n} CONFIG_
${VAR}_LENGTH
=
37 export ${NO_EXPORT:+-n} CONFIG_LIST_STATE
=
38 export ${NO_EXPORT:+-n} CONFIG_SECTIONS
=
39 export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS
=0
40 export ${NO_EXPORT:+-n} CONFIG_SECTION
=
43 DATA
="$($UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${LOAD_STATE:+-P "$UCI_STATE_DIR"} -S -n export "$PACKAGE" 2>/dev/null)"
45 [ "$RET" != 0 -o -z "$DATA" ] ||
eval "$DATA"
48 ${CONFIG_SECTION:+config_cb}
54 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q show
"$PACKAGE" > /dev
/null
&& return 0
55 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} import
"$PACKAGE"
56 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit
"$PACKAGE"
64 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P "$UCI_STATE_DIR" revert "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
73 [ "$#" = 4 ] || return 0
74 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P "$UCI_STATE_DIR" set "$PACKAGE.
$CONFIG${OPTION:+.$OPTION}=$VALUE"
78 uci_revert_state "$1" "$2" "$3"
79 uci_set_state "$1" "$2" "$3" "$4"
88 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.
$CONFIG.
$OPTION=$VALUE"
92 uci_get "$1" "$2" "$3" "$4" ""$UCI_STATE_DIR""
102 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${STATE:+-P $STATE} -q get "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
104 [ "$RET" -ne 0 ] && [ -n "$DEFAULT" ] && echo "$DEFAULT"
113 if [ -z "$CONFIG" ]; then
114 export ${NO_EXPORT:+-n} CONFIG_SECTION
="$($UCI add "$PACKAGE" "$TYPE")"
116 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG=$TYPE"
117 export ${NO_EXPORT:+-n} CONFIG_SECTION
="$CONFIG"
126 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} rename
"$PACKAGE.$CONFIG=$VALUE"
134 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} del
"$PACKAGE.$CONFIG${OPTION:+.$OPTION}"
139 $UCI ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit
$PACKAGE