2 # Shell script defining macros for manipulating config files
4 # Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
5 # Copyright (C) 2006,2007 Felix Fietkau <nbd@openwrt.org>
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
23 [ -e "/etc/config/$1" ] && return 0
24 cat > "/etc/config/$1"
32 export ${NO_EXPORT:+-n} CONFIG_SECTIONS
=
33 export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS
=0
34 export ${NO_EXPORT:+-n} CONFIG_SECTION
=
39 cfg
="$UCI_ROOT/etc/config/$PACKAGE"
40 uci
="$UCI_ROOT/tmp/.uci/$PACKAGE"
41 state
="$UCI_ROOT/var/state/$PACKAGE"
46 [ -z "$cfg" -o \
! -f "$cfg" ] && return 1
49 ${CONFIG_SECTION:+config_cb}
51 [ -z "$uci" -o \
! -f "$uci" ] || .
"$uci"
52 [ -z "$LOAD_STATE" -z "$state" -o \
! -f "$state" ] || .
"$state"
59 awk -f $UCI_ROOT/lib
/config
/uci.
awk -f - <<EOF
70 config = read_file(\"$FILENAME\")
79 local PACKAGE_BASE
="$(basename "$PACKAGE")"
83 /*) UCIFILE
="$PACKAGE";;
85 UCIFILE
="/tmp/.uci/$PACKAGE_BASE"
91 echo "$UPDATE" >> "$UCIFILE"
97 FILE
="/var/state/$PACKAGE.$$"
98 grep -v "^config_set '$CONFIG' " "/var/state/$PAKAGE" > "$FILE"
99 mv "$FILE" "/var/state/$PACKAGE"
108 [ -z "$VALUE" ] && return 1
109 uci_set
"/var/state/$PACKAGE" "$CONFIG" "$OPTION" "$VALUE"
121 uci_add_update
"$PACKAGE" "config_set '$CONFIG' '$OPTION' '$VALUE'"
124 ( # spawn a subshell so you don't mess up the current environment
126 config_get OLDVAL
"$CONFIG" "$OPTION"
127 if [ "x$OLDVAL" != "x$VALUE" ]; then
128 config_get
type "$CONFIG" TYPE
131 ) || uci_add_update
"$PACKAGE" "config_set '$CONFIG' '$OPTION' '$VALUE'"
141 uci_add_update
"$PACKAGE" "config '$TYPE' '$CONFIG'"
149 uci_add_update
"$PACKAGE" "config_rename '$CONFIG' '$VALUE'"
157 if [ -z "$OPTION" ]; then
158 uci_add_update
"$PACKAGE" "config_clear '$CONFIG'"
160 uci_add_update
"$PACKAGE" "config_unset '$CONFIG' '$OPTION'"
166 local PACKAGE_BASE
="$(basename "$PACKAGE")"
172 LOCK
=`which lock` || LOCK
=:
173 $LOCK "/tmp/.uci/$PACKAGE_BASE.lock"
174 [ -f "/tmp/.uci/$PACKAGE_BASE" ] && (
179 append updatestr
"config = uci_update_config(config, \"@$2=$1\")" "$N"
182 append updatestr
"config = uci_update_config(config, \"$CONFIG_SECTION.$1=$2\")" "$N"
185 append updatestr
"config = uci_update_config(config, \"&$1=$2\")" "$N"
188 append updatestr
"config = uci_update_config(config, \"-$1.$2\")" "$N"
191 append updatestr
"config = uci_update_config(config, \"-$1\")" "$N"
194 .
"/tmp/.uci/$PACKAGE_BASE"
196 # completely disable handlers so that they don't get in the way
204 config_load
"$PACKAGE"
205 CONFIG_FILENAME
="${CONFIG_FILENAME:-$UCI_ROOT/etc/config/$PACKAGE_BASE}"
206 uci_do_update
"$CONFIG_FILENAME" "$updatestr" > "/tmp/.uci/$PACKAGE_BASE.new" && {
207 mv -f "/tmp/.uci/$PACKAGE_BASE.new" "$CONFIG_FILENAME" && \
208 rm -f "/tmp/.uci/$PACKAGE_BASE"
211 $LOCK -u "/tmp/.uci/$PACKAGE_BASE.lock"
This page took 0.050937 seconds and 5 git commands to generate.