在openwrt中, 默认一种配置文件,默认的路径/etc/config,在这里面的所有配置文件如需要修改只需使用uci 这个指令来修改。
以下uci 指令参数:
root@xxxx:~# uci
Usage: uci [<options>] <command> [<arguments>]
Commands:
batch
export [<config>]
import [<config>]
changes [<config>]
commit [<config>]
add <config> <section-type>
add_list <config>.<section>.<option>=<string>
del_list <config>.<section>.<option>=<string>
show [<config>[.<section>[.<option>]]]
get <config>.<section>[.<option>]
set <config>.<section>[.<option>]=<value>
delete <config>[.<section>[[.<option>][=<id>]]]
rename <config>.<section>[.<option>]=<name>
revert <config>[.<section>[.<option>]]
reorder <config>.<section>=<position>
举个栗子来认识uci 是如何修改配置文件的,here we go!
配置文件 /etc/config/herewego.conf (mqtt的配置参数)的内容如下:
config lagent_0
option mqtt_port '8883'
option cafile '/etc/lagent/rootCA.crt'
option certfile '/etc/lagent/cert.pem'
option keyfile '/etc/lagent/privkey.pem'
option model 'lds.gateway.g151'
config lagent_1
option mqtt_port '8883'
option cafile '/etc/lagent/rootCA.crt'
option certfile '/etc/lagent/cert.pem'
option keyfile '/etc/lagent/privkey.pem'
option model 'lds.gateway.g151'
1, 修改lagent_0的下model参数 值: uci set herewego.@lagent_0[-1].model=lds.gateway.g111
在herewego.conf这个文件中有两个config 参数lagent_0, lagent_1 , uci 里面读取到这个文件后, 会将文件中的config参数保存到结构体链表中,默认数据索引是从-1开始, 同理修改lagent_1中的参数时使用索引0 , uci set herewego.@lagent_1[0].model=lds.gateway.g111
2, 在lagent_0中增加参数did : uci add herewego.@lagent_0[-1].did=xxxxxxxxxxxx
3, 删除lagent_0中的did : uci delete herewego.@lagent_0[-1].did
4, 获取lagent_0中的did : uci get herewego.@lagent_0[-1].did
以上为增删改查基本应用。