add uci v0.2 - implements batch mode and a command for listing changes to a package
[openwrt/svn-archive/archive.git] / package / uci / files / uci / lib / config / uci.sh
1 #!/bin/sh
2 # Shell script compatibility wrappers for /sbin/uci
3 #
4 # Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 uci_load() {
21 local PACKAGE="$1"
22
23 _C=0
24 export ${NO_EXPORT:+-n} CONFIG_SECTIONS=
25 export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=0
26 export ${NO_EXPORT:+-n} CONFIG_SECTION=
27
28 eval "$(/sbin/uci ${LOAD_STATE:+-P /var/state} -S -n export "$PACKAGE")"
29
30 ${CONFIG_SECTION:+config_cb}
31 }
32
33 uci_set_default() {
34 local PACKAGE="$1"
35 /sbin/uci -q show "$1" > /dev/null && return 0
36 /sbin/uci import "$1"
37 }
38
39 uci_revert_state() {
40 local PACKAGE="$1"
41 local CONFIG="$2"
42 local OPTION="$3"
43
44 /bin/uci -P /var/state revert "$PACKAGE${CONFIG:+.$CONFIG}${OPTION:+.$OPTION}"
45 }
46
47 uci_set_state() {
48 local PACKAGE="$1"
49 local CONFIG="$2"
50 local OPTION="$3"
51 local VALUE="$4"
52
53 [ -z "$VALUE" ] && return 0
54 /sbin/uci -P /var/state set "$PACKAGE.$CONFIG${OPTION:+.$OPTION}=$VALUE"
55 }
56
57 uci_set() {
58 local PACKAGE="$1"
59 local CONFIG="$2"
60 local OPTION="$3"
61 local VALUE="$4"
62
63 /sbin/uci set "$PACKAGE.$CONFIG.$OPTION=$TYPE"
64 }
65
66 uci_add() {
67 local PACKAGE="$1"
68 local TYPE="$2"
69 local CONFIG="$3"
70
71 /sbin/uci set "$PACKAGE.$CONFIG=$TYPE"
72 }
73
74 uci_rename() {
75 local PACKAGE="$1"
76 local CONFIG="$2"
77 local VALUE="$3"
78
79 /sbin/uci rename "$PACKAGE.$CONFIG=$VALUE"
80 }
81
82 uci_remove() {
83 local PACKAGE="$1"
84 local CONFIG="$2"
85 local OPTION="$3"
86
87 /sbin/uci del "$PACKAGE.$CONFIG${OPTION:+.$OPTION}"
88 }
89
90 uci_commit() {
91 local PACKAGE="$1"
92 /sbin/uci commit $PACKAGE
93 }