1 (edited by forum2008 2008-04-13 15:41:33)

Topic: [Howto]Using UCI as stand alone

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

Re: [Howto]Using UCI as stand alone

thank you

Re: [Howto]Using UCI as stand alone

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

4 (edited by markc 2011-09-26 15:46:25)

Re: [Howto]Using UCI as stand alone

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.

Re: [Howto]Using UCI as stand alone

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

Re: [Howto]Using UCI as stand alone

Sounds like you rather want to work a bit on this article:  http://wiki.openwrt.org/doc/techref/uci

Re: [Howto]Using UCI as stand alone

Hi!

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

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

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

Sad~~

------------------------------
http://www.leang.org:88/index.php
http://routers.3322.org:88
------------------------------

8 (edited by markc 2011-11-06 06:09:41)

Re: [Howto]Using UCI as stand alone

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.

Re: [Howto]Using UCI as stand alone

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!

Re: [Howto]Using UCI as stand alone

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

Re: [Howto]Using UCI as stand alone

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.

Re: [Howto]Using UCI as stand alone

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?

Re: [Howto]Using UCI as stand alone

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).