docs/config.tex describes the configuration system as follows:
"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"
However what it doesn't mention is how the sections are named, and this took me some headscratching to work out. I would like the following information to be added to the documentation.
Configuration sections have a heading "config <type> <name>", where the name is optional
If you don't provide a name, each config section is named "cfg1", "cfg2", "cfg3" etc.
So, to read the default /etc/config/system, which looks like this:
config system option log_ip 1.2.3.4
you need to access a section called "cfg1" as per the following code:
. /etc/functions.sh config_load system config_get foo cfg1 log_ip echo "$foo"
If you try the apparently obvious "config_get foo system log_ip" it reads nothing.
Alternatively, you can scan through all sections of type "system", which is what /etc/init.d/boot does:
. /etc/functions.sh config_load system wibble() { config_get foo "$1" log_ip echo "$foo" } # call function 'wibble' for each 'config system' section, passing the section name as $1 config_foreach wibble system
This is because /etc/config/system decided not to name the section. If the config file had said
config system settings option log_ip 1.2.3.4
then it could have been read by "config_get foo settings log_ip"
config_get_bool #The function of config_get_bool is similar to that of config_get, but this function converts the return value into an integer value
config_foreach callback_func section_type <customer_val> #Config_foreach calls a callback function for each section. As follows: #Callback_func is a callback function, which has 2 parameters, the first one is section name, and if you have a definition of customer_val, then the second is customer_val. We can call config_get and config_set in config_foreach