''​UCI''​ is a small utility written in [[wp>C (programming language)|C]] (a [[wp>​shell script]]-wrapper is available as well) and is intended to //​centralize//​ the whole configuration of a device running OpenWrt. UCI is the successor of the NVRAM based configuration found in the historical OpenWrt branch [[about:​history|White Russian]] and a wrapper for the standard configuration files programs bring with them, like e.g. ''/​etc/​network/​interfaces'',​ ''/​etc/​exports'',​ ''/​etc/​dnsmasq.conf'',​ ''/​etc/​samba/​samba.conf''​ etc.

+

+

| {{:​meta:​icons:​tango:​dialog-information.png?​nolink}} | UCI configuration files are located ​ in the directory **''/​etc/​config/''​**\\ Their documentation can be accessed online in the OpenWrt-Wiki under [[doc:​uci|UCI configuration files]]. |

+

+

They can be altered with any text editor or with the command line utility program ''​uci''​ or through various programming APIs (like Shell, Lua and C). The WUI [[doc:​techref:​LuCI]] e.g. uses Lua to manipulate them.

+

+

==== Dependencies of UCI ====

+

* ''​libuci''​ a small library for UCI written in [[wp>C (programming language)|C]]

+

* ''​libuci-lua''​ is a libuci-plugin for [[wp>Lua (programming language)|Lua]] which is utilized by e.g. [[doc:​techref:​LuCI]]

+

Both are maintained in the same git as UCI.

+

+

+

===== Packages =====

+

The functionality is provided by the two packages ''​uci''​ and ''​libuci''​. The package ''​libuci-lua''​ is also available.

(Luci has however a [[http://​luci.subsignal.org/​api/​luci/​modules/​luci.model.uci.html#​Cursor.get_first|Cursor:​get_first]] function that is similiar to get except it takes a type instead as section as second argument.)

+

+

===== Additional Information =====

+

+

See also [[http://​luci.subsignal.org/​api/​luci/​modules/​luci.model.uci.html|LuCI UCI model functions]]. Thats what LuCI uses. It extends the uci cursor class with a few more convenience functions.

+

----

+

+

+

+

===== Usage outside of OpenWrt =====

+

If you want to use the libuci apart from OpenWrt (for e.g. you are developing an application in C on your host computer) then prepare as follows:

+

+

Grab the source.

+

<​code>​git clone https://​git.openwrt.org/​project/​uci.git

+

</​code>​

+

+

Go to the source directory (where the CMakeLists.txt lives) and optionally configure the build without Lua bindings:

+

<​code>​cd uci/; cmake [-D BUILD_LUA:​BOOL=OFF] .</​code>​

+

+

Build and install uci as root (this will install uci into /​usr/​local/,​ see this thread on how to install and use uci without root permissions in your home directory: https://​forum.openwrt.org/​viewtopic.php?​id=40547):​

+

<​code>​make install</​code>​

+

+

Open /​etc/​ld.so.conf and add the place where you installed the uci library:

+

<​code>​vi /​etc/​ld.so.conf</​code>​

+

+

Add this line somewhere to /​etc/​ld.so.conf

+

<​code>/​usr/​local/​lib</​code>​

+

+

Execute ldconfig as root to apply the changes to /​etc/​ld.so.conf

+

<​code>​ldconfig</​code>​

+

+

To compile your application you have to link it against the uci library. Append -luci in your Makefile:

+

<​code>​$(CC) test.o -o test -luci</​code>​

+

+

And examples on how to use UCI in C can be found in this thread: https://​forum.openwrt.org/​viewtopic.php?​pid=183335#​p183335

+

To get more examples look into the source directory of uci which you got by git clone and open cli.c or ucimap-example.c

+

+

+

===== Make UCI in UBUNTU 16.04 , Raspbian Jessie or similar=====

+

If you want to use uci in Debian, UBUNTU or similar, ​ do the following steps:

+

+

First make a directory for download source codes:

+

<​code>​

+

mkdir ~/​Desktop/​uci

+

</​code>​

+

+

**1- Install json-c**

+

+

Install the required packages:

+

<​code>​

+

sudo apt-get install dh-autoreconf git

+

</​code>​

+

+

Download source code:

+

<​code>​

+

cd ~/​Desktop/​uci

+

git clone https://​github.com/​json-c/​json-c.git

+

</​code>​

+

+

Make and install json-c:

+

<​code>​

+

cd json-c

+

sh ./​autogen.sh

+

./configure

+

make

+

sudo make install

+

make check

+

</​code>​

+

+

**2- Install libubox**

+

+

Install the required packages:

+

<​code>​

+

sudo apt-get install lua5.1 liblua5.1-0-dev cmake

+

</​code>​

+

+

Download source code:

+

<​code>​

+

cd ~/​Desktop/​uci

+

git clone https://​git.openwrt.org/​project/​libubox.git

+

</​code>​

+

+

Make and install libubox:

+

<​code>​

+

cd libubox

+

cmake .

+

make

+

sudo make install

+

</​code>​

+

+

**3- Install uci**

+

+

Download source code:

+

<​code>​

+

cd ~/​Desktop/​uci

+

git clone https://​git.openwrt.org/​project/​uci.git

+

</​code>​

+

+

Make and install uci:

+

<​code>​

+

cd uci

+

cmake .

+

sudo make install

+

</​code>​

+

+

Now u can use uci :

+

<​code>​

+

uci

+

</​code>​

+

+

If you still see this message:

+

<​code>​

+

error while loading shared libraries: libubox.so: cannot open shared object file: No such file or directory

+

</​code>​

+

+

edit this file:

+

<​code>​

+

sudo nano /​etc/​environment

+

</​code>​

+

+

Add this command into it:

+

<​code>​

+

LD_LIBRARY_PATH=/​usr/​local/​lib

+

</​code>​

+

+

or this file

+

<​code>​

+

sudo nano /​etc/​profile

+

</​code>​

+

+

Add these commands into it:

+

<​code>​

+

LD_LIBRARY_PATH=/​usr/​local/​lib

+

export LD_LIBRARY_PATH

+

</​code>​

+

+

This will let you restart your computer.

+

+

===== Functioning =====

+

All ''​uci set'',​ ''​uci add'',​ ''​uci rename''​ and ''​uci delete''​ commands are staged in ''/​tmp''​ and written to flash at once with ''​uci commit''​.

+

This obviously does not apply to people using text editors, but to scripts, guis and other programs working with uci files.