UCI

来源:互联网 发布:域名top区别 编辑:程序博客网 时间:2024/05/21 07:01

1.文件语法

config <type> ["<name>"]

option <name> "<value>"

eg:

config system        option hostname OpenWrt        option timezone UTCconfig timeserver ntp        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        option enabled 1        option enable_server 0


config标志着一个配置节的开始,timeserver为该配置节的类型标志,ntp为该配置节的名称(一个配置节可以没有名称但是必须要有类型标志),没有名称的配置节称为匿名配置节。

option标志着一个选项对
option hostname OpenWrt
        option timezone UTC

定义了配置节的两个简单配置。(类型和选项是应用程序决定的,类型一般应用于应用程序如何处理配置节包含的配置选项。)

list关键字表示有多个值被定义,所有的语句都是同一个名字。例子中的NTP服务器地址组合为相同顺序单链表来处理。

注意:UCI标识符和配置文件的名称只能包含字母、数字和_。

2.统一配置

UCI配置文件都存放在/etc/config/下面,系统启动时,/etc/init.d/下的初始化脚本会将UCI配置文件转换为软件包的原始配置文件。

3.UCI命令

语法:

其中<config>代表的是配置文件名,<section>表示配置节的名字,<option>表示选项的名字

Usage: uci [<options>] <command> [<arguments>]Commands:        batch        export     [<config>]   #导出配置文件,eg:uci export system        import     [<config>]        changes    [<config>]        commit     [<config>]        add        <config> <section-type>     #为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>Options:        -c <path>  set the search path for config files (default: /etc/config)        -d <str>   set the delimiter for list values in uci show        -f <file>  use <file> as input instead of stdin        -m         when importing, merge data into an existing package        -n         name unnamed sections on export (default)        -N         don't name unnamed sections        -p <path>  add a search path for config change files        -P <path>  add a search path for config change files and use as default        -q         quiet mode (don't print error messages)        -s         force strict mode (stop on parser errors, default)        -S         disable strict mode        -X         do not use extended syntax on 'show'


eg:

#添加匿名配置节

uci add system buttoncfg055d81


#添加一个有名配置节

    uci set system.light=led

名字为light,类型为led


#添加一个选项对

uci set system.@button[-1].name=reset

设置指定配置节选项的值(如果没有该选项则添加):

 option name 'reset'
#对已存在的list选项增加字符串

uci add_list system.ntp.server="ntp.qkbook.net"

在ntp下会生成list server 'ntp.qkbook.net'


#导出配置

uci export system
  package systemconfig system        option hostname 'OpenWrt'        option timezone 'UTC'config timeserver 'ntp'        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'        list server 'ntp.qkbook.net'        list server 'ntp.qkbook.net'        option enabled '1'        option enable_server '0'config button        option name 'reset'config led 'light'

#对给定的配置文件写入修改(若未给定则对所有的配置文件写入文件系统)

uci commit systemuci commit
注:所有的uci set、uci add等命令将配置写入一个临时的位置,在运行uci commit 时才会写入实际的存储位置

0 0