OpenWrt Forum Archive

Topic: [Howto]Using UCI as stand alone

The content of this topic has been archived on 26 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Using UCI as stand alone

UCI (Unified Configuration Interface) can be used as stand alone. With this you can make use of UCI in your own distribution. It's also useful in the future for writing and testing OpenWrt UCI configuration files and init scripts on a Linux box instead on the router.
UCI is maintained by nbd (Felix Fietkau) at http://nbd.name/gitweb.cgi?p=uci.git;a=summary

Checkout and compile UCI

cd ~
git clone git://nbd.name/uci.git ~/uci/
cd ~/uci/
make
sudo make install
sudo mkdir -p /etc/config

Example UCI config file (/etc/config/test):

config 'test' 'abc'
        option 'test_var' 'value'
openwrt@ubuntu-laptop:~/uci$ uci show test
test.abc=test
test.abc.test_var=value
openwrt@ubuntu-laptop:~/uci$ uci set test.abc.test_var=foobar
openwrt@ubuntu-laptop:~/uci$ sudo uci commit test
openwrt@ubuntu-laptop:~/uci$ uci show test
test.abc=test
test.abc.test_var=foobar

Notes
  * Currently the config path is hardcoded to /etc/config/
  * Init script related files such as rc.common has to be fixed to run as stand alone

(Last edited by forum2008 on 13 Apr 2008, 17:41)

thank you

Hey, Just a note that the build system was replaced with cmake. One has to first run cmake, and then make/make install, etc.

Good to see the CMake build system. Is it possible to completely disable the Lua dependency? I'd like to use PHP instead.

Scanning dependencies of target ucimap-example
[ 93%] Building C object CMakeFiles/ucimap-example.dir/ucimap-example.c.o                                                                                                    
/home/markc/Devel/uci/ucimap-example.c:18:20: fatal error: ucimap.h: No such file or directory                                                                               
compilation terminated.
make[2]: *** [CMakeFiles/ucimap-example.dir/ucimap-example.c.o] Error 1
make[1]: *** [CMakeFiles/ucimap-example.dir/all] Error 2
make: *** [all] Error 2

However the uci and uci-static binaries built okay.

(Last edited by markc on 26 Sep 2011, 17:46)

Just comment out the ADD_SUBDIRECTORY(lua) line in CMakeLists.txt

Hi!

Code:
cd ~
git clone git://nbd.name/uci.git ~/uci/
cd ~/uci/
make

----------------

make:*** No targets specified and no makefile found. Stop.

Sad~~

Try...

cd
git clone git://nbd.name/uci.git
mkdir uci/build
cd uci/build
cmake ..
make

I'm still seeing this error (however, after 100% this time)...

[100%] Building C object CMakeFiles/ucimap-example.dir/ucimap-example.c.o                                                                                                    
/home/markc/Devel/uci/ucimap-example.c:18:20: fatal error: ucimap.h: No such file or directory                                                                               
compilation terminated.
make[2]: *** [CMakeFiles/ucimap-example.dir/ucimap-example.c.o] Error 1
make[1]: *** [CMakeFiles/ucimap-example.dir/all] Error 2
make: *** [all] Error 2

And FWIW if anyone is interested in a PHP replacement for LUA then let me know as I've made a START and will push it to Github eventually (sooner if any else is interested in cooperating).

Update: I see what the problem is for the error above, ucimap-example.c uses an include line of <ucimap.h> whereas it should be "ucimap.h" to include the current ucimap.h otherwise it'll include the PREVIOUS builds /usr/include/ucimap.h which may be out of date and certainly not available until after a make install.

(Last edited by markc on 6 Nov 2011, 07:09)

I'm getting these errors:

cmake ..
CMake Warning at lua/CMakeLists.txt:34 (IF):
  given arguments:

    "NOT" "No such file or directory" "EQUAL" "0" "OR" "EQUAL" ""

  Unknown arguments specified


CMake Error at lua/CMakeLists.txt:48 (INSTALL):
  install TARGETS given no LIBRARY DESTINATION for module target "uci_lua".


-- Configuring incomplete, errors occurred!

Hi,
I got it to work, this is what I did.


git clone git://nbd.name/uci.git ~/uci/
cd ~/uci/
cmake CMakeLists.txt
make

then run:
./uci-static
(shows help)


Example
# cat /etc/config/test
config 'test' 'abc'
        option 'test_var' 'value'

Run:
./uci-static show test
test.abc=test
test.abc.test_var=value

Cheers
-Anders

I've compiled and installed UCI package to x86 native linux machine.
UCI config file was correctly updated with set and commit command,
but UCI setting was not applied to system. 

I tried changing IP address of a network interface (eth1).   
Even though UCI config file was updated well,
'ifconfig' command shows actual IP address was never changed.   
I did '/etc/init.d/network restart' after uci commiting, but it did not help.   

Please let me know if I'm missing some steps.

Thanks in advance.

I just tried the @carlberg post above yours and the simple test case worked for me on Archlinux/x86_64. Even though I ran the test as a normal user it wrote to a root owned file (/etc/config/test) so there goes my first thought about perhaps needing sudo.

I'd like to try some routing tests as well. What were your /etc/config/* settings for your eth1?

markc wrote:

SPAM ALERT
Can someone remove the above post and ban liudaolunhui please!

Done. For next time, there's also a "report" link on each post (in the bottom right corner, gray on gray, so easy to overlook).

Hi

git clone git://nbd.name/uci.git ~/uci/
cd ~/uci/
cmake CMakeLists.txt
make

/root/uci/blob.c:18:29: 致命错误: libubox/blobmsg.h:没有那个文件或目录
编译中断。
make[2]: *** [CMakeFiles/uci.dir/blob.c.o] 错误 1
make[1]: *** [CMakeFiles/uci.dir/all] 错误 2
make: *** [all] 错误 2

sad~

carlberg wrote:

Hi,
I got it to work, this is what I did.


git clone git://nbd.name/uci.git ~/uci/
cd ~/uci/
cmake CMakeLists.txt
make

then run:
./uci-static
(shows help)


Example
# cat /etc/config/test
config 'test' 'abc'
        option 'test_var' 'value'

Run:
./uci-static show test
test.abc=test
test.abc.test_var=value

Cheers
-Anders

I copy and pasted that into my node and it didn't do anything.

The discussion might have continued from here.