From d8e5772f33d0d8a3290a002f57781e91580c2512 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sat, 24 Mar 2007 13:43:04 +0000 Subject: [PATCH] rename uci-update.awk to uci.awk and add a few config_* functions git-svn-id: svn://svn.openwrt.org/openwrt/trunk@6666 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/files/etc/functions.sh | 6 ++- .../lib/config/{uci-update.awk => uci.awk} | 44 +++++++++++++++---- package/base-files/files/lib/config/uci.sh | 29 +++++++----- 3 files changed, 58 insertions(+), 21 deletions(-) rename package/base-files/files/lib/config/{uci-update.awk => uci.awk} (77%) diff --git a/package/base-files/files/etc/functions.sh b/package/base-files/files/etc/functions.sh index 4d84bb81e0..72e60bb511 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 efa8758507..e3f9467316 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