diff options
author | Felix Fietkau <nbd@openwrt.org> | 2006-09-22 23:03:08 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2006-09-22 23:03:08 +0000 |
commit | 03e53fd5d4d10c853e6b55c1261510d04b1e43b2 (patch) | |
tree | 44386adddc720bd537d485cde3797c3422aeae1f /openwrt/docs | |
parent | ac4b0b4122d0f4bba6ee6df6f2f9773e2d6d6179 (diff) | |
download | mtk-20170518-03e53fd5d4d10c853e6b55c1261510d04b1e43b2.zip mtk-20170518-03e53fd5d4d10c853e6b55c1261510d04b1e43b2.tar.gz mtk-20170518-03e53fd5d4d10c853e6b55c1261510d04b1e43b2.tar.bz2 |
add basic documentation for the config file api
SVN-Revision: 4808
Diffstat (limited to 'openwrt/docs')
-rw-r--r-- | openwrt/docs/config.txt | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/openwrt/docs/config.txt b/openwrt/docs/config.txt new file mode 100644 index 0000000..5988158 --- /dev/null +++ b/openwrt/docs/config.txt @@ -0,0 +1,72 @@ + == Structure of the configuration files == + +The config files are divided into sections and options/values. + +Every section has a type, but does not necessarily have a name. +Every option has a name and a value and is assigned to the section +it was written under. + +Syntax: + +config <type> [<name>] # Section + option <name> <value> # Option + + +Every parameter needs to be a single string and is formatted exactly +like a parameter for a shell function. The same rules for Quoting and +special characters also apply, as it is parsed by the shell. + + + + == Parsing configuration files in custom scripts == + +To be able to load configuration files, you need to include the common +functions with: + +. /etc/functions.sh + +Then you can use config_load <name> to load config files. The function +first checks for <name> as absolute filename and falls back to loading +it from /etc/config (which is the most common way of using it). + +If you want to use special callbacks for sections and/or options, you +need to define the following shell functions before running config_load +(after including /etc/functions.sh): + +config_cb() { + local type="$1" + local name="$2" + # commands to be run for every section +} + +option_cb() { + # commands to be run for every option +} + +You can also alter option_cb from config_cb based on the section type. +This allows you to process every single config section based on its type +individually. + +config_cb is run every time a new section starts (before options are being +processed). You can access the last section through the CONFIG_SECTION +variable. Also an extra call to config_cb (without a new section) is generated +after config_load is done. +That allows you to process sections both before and after all options were +processed. + +You can access already processed options with the config_get command +Syntax: + +config_get <section> <option> # prints the value of the option +config_get <variable> <section> <option> # stores the value inside the variable + +In busybox ash the three-option config_get is faster, because it does not +result in an extra fork, so it is the preferred way. + +Additionally you can also modify or add options to sections by using the +config_set command. + +Syntax: + +config_set <section> <option> <value> + |