mini_fo fixes
[openwrt.git] / package / base-files / default / bin / uci
1 #!/bin/sh
2 # Shell script for interacting with config files
3 #
4 # Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
5 # Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org>
6 #
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.
11 #
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.
16 #
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
20
21 . /etc/functions.sh
22 include /lib/config
23
24 do_get() {
25 [ $# -ne 3 ] && {
26 uci_usage get
27 exit 1
28 }
29 local PACKAGE="$1"
30 local CONFIG="$2"
31 local OPTION="$3"
32
33 uci_load "$PACAKGE"
34 config_get "$CONFIG" "$OPTION"
35 }
36
37 do_set() {
38 [ $# -ne 4 ] && {
39 uci_usage set
40 exit 1
41 }
42 uci_set "$@"
43 }
44
45 do_add() {
46 [ $# -ne 3 ] && {
47 uci_usage add
48 exit 1
49 }
50 uci_add "$@"
51 }
52
53 do_rename() {
54 [ $# -ne 3 ] && {
55 uci_usage rename
56 exit 1
57 }
58 uci_rename "$@"
59 }
60
61 do_remove() {
62 [ $# -ne 3 -a $# -ne 2 ] && {
63 uci_usage rename
64 exit 1
65 }
66 uci_remove "$@"
67 }
68
69 do_commit() {
70 [ $# -ne 1 ] && {
71 uci_usage commit
72 exit 1
73 }
74 uci_commit "$1"
75 }
76
77 do_show() {
78 [ $# -gt 2 -o $# -lt 1 ] && {
79 uci_usage show
80 exit 1
81 }
82
83 PACKAGE="$1"
84 CONFIG="$2"
85 SECTION=""
86
87 config_cb() {
88 if [ -z "$CONFIG" -o "$CONFIG" = "$2" ]; then
89 append SECTION "$2"
90 option_cb() {
91 append "${CONFIG_SECTION}_VARS" "$1"
92 }
93 else
94 option_cb() {
95 return 0
96 }
97 fi
98 }
99
100 uci_load "$PACKAGE"
101
102 for section in $SECTION; do
103 config_get type "$section" TYPE
104 [ -z "$type" ] && continue
105 echo "@$section=$type"
106 eval "VARS=\"\${${section}_VARS}\""
107 for var in $VARS; do
108 config_get val "$section" "$var"
109 [ -n "$val" ] && {
110 echo "${section}.${var}=${val}"
111 config_set "$section" "$var" ""
112 }
113 done
114 config_set "$section" TYPE ""
115 done
116 }
117
118 uci_usage() {
119 case "$1" in
120 show) echo "$0 show <package> [<config>]";;
121 get) echo "$0 get <package> <config> <option>";;
122 set) echo "$0 set <package> <config> <option> <value>";;
123 add) echo "$0 add <package> <type> <config>";;
124 del) echo "$0 del <package> <config> [<option>]";;
125 rename) echo "$0 rename <package> <config> <name>";;
126 commit) echo "$0 commit <package>";;
127 *)
128 echo "Syntax: $0 <command> <arguments...>"
129 echo
130 uci_usage show
131 uci_usage get
132 uci_usage set
133 uci_usage add
134 uci_usage del
135 uci_usage rename
136 uci_usage commit
137 echo
138 exit 1
139 ;;
140 esac
141 }
142
143 if [ $# -eq 0 ] ; then
144 uci_usage
145 exit 0
146 fi
147 CMD="$1"
148 shift
149 case "$CMD" in
150 set) do_set "$@";;
151 add) do_add "$@";;
152 del) do_remove "$@";;
153 rename) do_rename "$@";;
154 get) do_get "$@";;
155 show) do_show "$@";;
156 commit) do_commit "$@";;
157 *) uci_usage;;
158 esac
159 exit 0
This page took 0.051488 seconds and 5 git commands to generate.