diff --git a/package/base-files/files/etc/functions.sh b/package/base-files/files/etc/functions.sh index 4d84bb81e..72e60bb51 100755 --- a/package/base-files/files/etc/functions.sh +++ b/package/base-files/files/etc/functions.sh @@ -120,7 +120,11 @@ config_set() { local section="$1" local option="$2" local value="$3" - export ${NO_EXPORT:+-n} "CONFIG_${section}_${option}=$value" + local old_section="$CONFIG_SECTION" + + CONFIG_SECTION="$section" + option "$option" "$value" + CONFIG_SECTION="$old_section" } config_foreach() { diff --git a/package/base-files/files/lib/config/uci-update.awk b/package/base-files/files/lib/config/uci.awk similarity index 77% rename from package/base-files/files/lib/config/uci-update.awk rename to package/base-files/files/lib/config/uci.awk index efa875850..e3f946731 100644 --- a/package/base-files/files/lib/config/uci-update.awk +++ b/package/base-files/files/lib/config/uci.awk @@ -1,4 +1,4 @@ -# Configuration update functions +# Configuration update functions - AWK API # # Copyright (C) 2006 by Fokus Fraunhofer # Copyright (C) 2006 by Felix Fietkau @@ -17,6 +17,32 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# parameters: 1 +function config_load(package, var) { + while (("/bin/ash -c '. /etc/functions.sh; unset NO_EXPORT; config_load \""package"\"; env | grep \"^CONFIG_\"'" | getline) == 1) { + sub("^CONFIG_", "") + if (match($0, "=") == 0) { + if (var != "") CONFIG[var] = CONFIG[var] "\n" $0 + next + } + var=substr($0, 1, RSTART-1) + CONFIG[var] = substr($0, RSTART+1, length($0) - RSTART) + } +} + +# parameters: 2 +function config_get(package, option) { + return CONFIG[package "_" option] +} + +# parameters: 3 +function config_get_bool(package, option, default, var) { + var = config_get(package, option); + if ((var == "enabled") || (var == "1") || (var == "on")) return 1 + if ((var == "disabled") || (var == "0") || (var == "off")) return 1 + return (var && var != "0" ? 1 : 0) +} + function read_file(filename, result) { while ((getline