mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-23 23:42:43 +00:00
add a variable to keep track of the list of sections when loading uci config files. add a function to iterate through sections
SVN-Revision: 5870
This commit is contained in:
parent
eb2f10c841
commit
1d23349bea
@ -31,9 +31,10 @@ reset_cb
|
|||||||
config () {
|
config () {
|
||||||
local cfgtype="$1"
|
local cfgtype="$1"
|
||||||
local name="$2"
|
local name="$2"
|
||||||
|
|
||||||
_C=$((_C + 1))
|
CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1))
|
||||||
name="${name:-cfg${_C}}"
|
name="${name:-cfg$CONFIG_NUM_SECTIONS}"
|
||||||
|
append CONFIG_SECTIONS "$name"
|
||||||
config_cb "$cfgtype" "$name"
|
config_cb "$cfgtype" "$name"
|
||||||
CONFIG_SECTION="$name"
|
CONFIG_SECTION="$name"
|
||||||
export -n "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
|
export -n "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
|
||||||
@ -60,6 +61,7 @@ config_rename() {
|
|||||||
eval "export -n \"$newvar=\${$oldvar}\""
|
eval "export -n \"$newvar=\${$oldvar}\""
|
||||||
unset "$oldvar"
|
unset "$oldvar"
|
||||||
done
|
done
|
||||||
|
CONFIG_SECTIONS="$(echo " $CONFIG_SECTIONS " | sed -e "s, $OLD , $NEW ,")"
|
||||||
|
|
||||||
[ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION="$NEW"
|
[ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION="$NEW"
|
||||||
}
|
}
|
||||||
@ -72,7 +74,10 @@ config_clear() {
|
|||||||
local SECTION="$1"
|
local SECTION="$1"
|
||||||
local oldvar
|
local oldvar
|
||||||
|
|
||||||
for oldvar in `set | grep ^CONFIG_${SECTION}_ | \
|
CONFIG_SECTIONS="$(echo " $CONFIG_SECTIONS " | sed -e "s, $OLD , ,")"
|
||||||
|
CONFIG_SECTIONS="${SECTION:+$CONFIG_SECTIONS}"
|
||||||
|
|
||||||
|
for oldvar in `set | grep ^CONFIG_${SECTION:+$SECTION_} | \
|
||||||
sed -e 's/\(.*\)=.*$/\1/'` ; do
|
sed -e 's/\(.*\)=.*$/\1/'` ; do
|
||||||
unset $oldvar
|
unset $oldvar
|
||||||
done
|
done
|
||||||
@ -81,6 +86,8 @@ config_clear() {
|
|||||||
config_load() {
|
config_load() {
|
||||||
local file="/etc/config/$1"
|
local file="/etc/config/$1"
|
||||||
_C=0
|
_C=0
|
||||||
|
CONFIG_SECTIONS=
|
||||||
|
CONFIG_NUM_SECTIONS=0
|
||||||
CONFIG_SECTION=
|
CONFIG_SECTION=
|
||||||
|
|
||||||
[ -e "$file" ] && {
|
[ -e "$file" ] && {
|
||||||
@ -104,6 +111,16 @@ config_set() {
|
|||||||
export -n "CONFIG_${section}_${option}=$value"
|
export -n "CONFIG_${section}_${option}=$value"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config_foreach() {
|
||||||
|
local function="$1"
|
||||||
|
local section
|
||||||
|
|
||||||
|
[ -z "$CONFIG_SECTIONS" ] && return 0
|
||||||
|
for section in ${CONFIG_SECTIONS}; do
|
||||||
|
eval "$function \"\$section\""
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
load_modules() {
|
load_modules() {
|
||||||
cd /etc/modules.d
|
cd /etc/modules.d
|
||||||
sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
|
sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
|
||||||
|
Loading…
Reference in New Issue
Block a user