All config values are treated as strings. It is up to the package that the config file is for, to interpret as it sees fit.
Compare uci show with uci export and with the actual contents of the file in /etc/config
root@meshnode-8ec9:~# uci show system
system.@system[0]=system
system.@system[0].hostname='meshnode-8ec9'
system.@system[0].timezone='GMT0'
system.@system[0].zonename='UTC'
system.@system[0].ttylogin='0'
system.@system[0].log_size='128'
system.@system[0].urandom_seed='0'
system.ntp=timeserver
system.ntp.enabled='1'
system.ntp.enable_server='0'
system.ntp.server='0.openwrt.pool.ntp.org' '1.openwrt.pool.ntp.org' '2.openwrt.pool.ntp.org' '3.openwrt.pool.ntp.org'
root@meshnode-8ec9:~#
root@meshnode-8ec9:~# uci export system
package system
config system
option hostname 'meshnode-8ec9'
option timezone 'GMT0'
option zonename 'UTC'
option ttylogin '0'
option log_size '128'
option urandom_seed '0'
config timeserver 'ntp'
option enabled '1'
option enable_server '0'
list server '0.openwrt.pool.ntp.org'
list server '1.openwrt.pool.ntp.org'
list server '2.openwrt.pool.ntp.org'
list server '3.openwrt.pool.ntp.org'
root@meshnode-8ec9:~# cat /etc/config/system
config system
option hostname 'OpenWrt'
option timezone 'GMT0'
option zonename 'UTC'
option ttylogin '0'
option log_size '128'
option urandom_seed '0'
config timeserver 'ntp'
option enabled '1'
option enable_server '0'
list server '0.openwrt.pool.ntp.org'
list server '1.openwrt.pool.ntp.org'
list server '2.openwrt.pool.ntp.org'
list server '3.openwrt.pool.ntp.org'
root@meshnode-8ec9:~#
As you can see from my example above, the config values are always enclosed by single quotes.
You can parse the export output to find lists.
You should always work with actual uci command outputs and not the config file directly because there can be uncommitted values present because uci supports dynamic configurations.
Edit: You can check for dynamic configs with the uci changes command, eg:
root@meshnode-8ec9:~# uci changes system
system.cfg01e48a.hostname='meshnode-8ec9'
root@meshnode-8ec9:~#
The problem is in cases where none of them have been set yet.
I am trying to perfect a DSL command line frontend for UCI
And instead of making everything a key/value pair, I want booleans to be able to be set by just adding the variable's name to enable it, or prefixing it with "no" like "novariablename" so set it false.
But that only works if I can lookup the variable and figure out their types.
So from your answer it seems, no it isn't possible, you have to bring your own lookup table for data types and list ?
I see how uci export could be used to tell if it's a config or list, but only for currently set variables.
So I think for my purpose, I will have to compile a full lookup table of data types and lists.
What do you mean by this? A new package, or something tat manipulates the config of something else?
Every uci config file is unique to a specific package or set of packages. The package itself, or its Procd script, is responsible for interpreting the uci output.
This is pretty much what all packages do internally for their own configs already.
I don't see the point of what you are trying to do..
Yes. With the UBUS / UCI relationship this task is a doddle.
. /usr/shr/libubus/jshn.sh
# don't pollute!
json_set_namespace "tmpPrfx" _curPrfx
# here's the 'magic'
json_load "$(ubus -v call uci get '{"config": "CONFIG-FILE-OF-INTEREST"}')"
# this function returns the name of the top-level JSON element, i.e., 'values'
json_get_keys _k
json_select $_k
# this function returns the named or anonymous (UCI-generated) name(s) of UCI section(s)
# e.g., 'dhcp' -> "lan odhcpd cfg03411c"
json_get_keys _k
# the third 'section' (anonymous) is of type 'dnsmasq'
json_select ${_k##* }
json_get_keys _k
# -> "_anonymous _type _name _index domainneeded localise_queries rebind_protection expandhosts readethers leasefile domain local rebind_localhost cachesize quietdhcp nointerface server localservice nohosts logfacility noresolv"
json_get_var _v "noresolv"
# $_v = 'true'
json_get_type _t "noresolv"
# $_t = 'string'
json_get_var _v "server"
# $_v = 'J_A6'
json_get_type _t "server"
# $_t = 'array'
json_cleanup
json_set_namespace $_curPrfx
The assertion that all UCI values (from configuration files) are 'string' is true. But when using active UCI data (that which is loaded into UBUS), all JSON types are valid e.g., 'object', 'array', 'boolean' and 'string'. This JSON is a valid UCI configuration -