2008-02-03 08:48:15 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# Shell script compatibility wrappers for /sbin/uci
|
|
|
|
#
|
2010-05-17 22:31:05 +03:00
|
|
|
# Copyright (C) 2008-2010 OpenWrt.org
|
2008-02-03 08:48:15 +02:00
|
|
|
# Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
2008-08-01 00:11:15 +03:00
|
|
|
CONFIG_APPEND=
|
2008-02-03 08:48:15 +02:00
|
|
|
uci_load() {
|
|
|
|
local PACKAGE="$1"
|
2008-02-09 20:08:05 +02:00
|
|
|
local DATA
|
|
|
|
local RET
|
2008-02-03 08:48:15 +02:00
|
|
|
|
|
|
|
_C=0
|
2008-07-30 22:21:09 +03:00
|
|
|
if [ -z "$CONFIG_APPEND" ]; then
|
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTIONS=
|
|
|
|
export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=0
|
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTION=
|
|
|
|
fi
|
2008-02-03 08:48:15 +02:00
|
|
|
|
2010-01-27 06:59:14 +02:00
|
|
|
DATA="$(/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${LOAD_STATE:+-P /var/state} -S -n export "$PACKAGE" 2>/dev/null)"
|
2008-02-09 20:08:05 +02:00
|
|
|
RET="$?"
|
|
|
|
[ "$RET" != 0 -o -z "$DATA" ] || eval "$DATA"
|
|
|
|
unset DATA
|
2008-02-03 08:48:15 +02:00
|
|
|
|
|
|
|
${CONFIG_SECTION:+config_cb}
|
2008-02-09 20:08:05 +02:00
|
|
|
return "$RET"
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uci_set_default() {
|
|
|
|
local PACKAGE="$1"
|
2010-05-17 22:31:05 +03:00
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -q show "$PACKAGE" > /dev/null && return 0
|
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} import "$PACKAGE"
|
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit "$PACKAGE"
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uci_revert_state() {
|
|
|
|
local PACKAGE="$1"
|
|
|
|
local CONFIG="$2"
|
|
|
|
local OPTION="$3"
|
|
|
|
|
2010-01-27 06:59:14 +02:00
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state revert "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uci_set_state() {
|
|
|
|
local PACKAGE="$1"
|
|
|
|
local CONFIG="$2"
|
|
|
|
local OPTION="$3"
|
|
|
|
local VALUE="$4"
|
|
|
|
|
2008-08-20 15:34:17 +03:00
|
|
|
[ "$#" = 4 ] || return 0
|
2010-01-27 06:59:14 +02:00
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} -P /var/state set "$PACKAGE.$CONFIG${OPTION:+.$OPTION}=$VALUE"
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uci_set() {
|
|
|
|
local PACKAGE="$1"
|
|
|
|
local CONFIG="$2"
|
|
|
|
local OPTION="$3"
|
|
|
|
local VALUE="$4"
|
|
|
|
|
2010-01-27 06:59:14 +02:00
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG.$OPTION=$VALUE"
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|
|
|
|
|
2010-05-17 22:31:05 +03:00
|
|
|
uci_get_state() {
|
|
|
|
uci_get "$1" "$2" "$3" "$4" "/var/state"
|
|
|
|
}
|
|
|
|
|
|
|
|
uci_get() {
|
|
|
|
local PACKAGE="$1"
|
|
|
|
local CONFIG="$2"
|
|
|
|
local OPTION="$3"
|
|
|
|
local DEFAULT="$4"
|
|
|
|
local STATE="$5"
|
|
|
|
|
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} ${STATE:+-P $STATE} -q get "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
|
|
|
|
RET="$?"
|
|
|
|
[ "$RET" -ne 0 ] && [ -n "$DEFAULT" ] && echo "$DEFAULT"
|
|
|
|
return "$RET"
|
|
|
|
}
|
|
|
|
|
2008-02-03 08:48:15 +02:00
|
|
|
uci_add() {
|
|
|
|
local PACKAGE="$1"
|
|
|
|
local TYPE="$2"
|
|
|
|
local CONFIG="$3"
|
|
|
|
|
2008-02-09 19:27:43 +02:00
|
|
|
if [ -z "$CONFIG" ]; then
|
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTION="$(/sbin/uci add "$PACKAGE" "$TYPE")"
|
|
|
|
else
|
2010-01-27 06:59:14 +02:00
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} set "$PACKAGE.$CONFIG=$TYPE"
|
2008-02-09 19:27:43 +02:00
|
|
|
export ${NO_EXPORT:+-n} CONFIG_SECTION="$CONFIG"
|
|
|
|
fi
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uci_rename() {
|
|
|
|
local PACKAGE="$1"
|
|
|
|
local CONFIG="$2"
|
|
|
|
local VALUE="$3"
|
|
|
|
|
2010-01-27 06:59:14 +02:00
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} rename "$PACKAGE.$CONFIG=$VALUE"
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uci_remove() {
|
|
|
|
local PACKAGE="$1"
|
|
|
|
local CONFIG="$2"
|
|
|
|
local OPTION="$3"
|
|
|
|
|
2010-01-27 06:59:14 +02:00
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} del "$PACKAGE.$CONFIG${OPTION:+.$OPTION}"
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
uci_commit() {
|
|
|
|
local PACKAGE="$1"
|
2010-01-27 06:59:14 +02:00
|
|
|
/sbin/uci ${UCI_CONFIG_DIR:+-c $UCI_CONFIG_DIR} commit $PACKAGE
|
2008-02-03 08:48:15 +02:00
|
|
|
}
|