Is using a custom config file ok?

Hi folks,

So my project has some code which implements its own config writing and reading mechanisms and uses its own config file (in /etc/[projectdirectory]). This is to support running on a generic Linux platform. Considering that eventually I'll probably want to release the project for OpenWrt, should I implement support for UCI, or is it Ok to use my existing config-related code (and a separate config file) on OpenWrt?

Many packages have their own (internal) config files stored on OpenWrt systems. That is quite ok.
(But avoid storing non-uci config in /etc/config where uci config files are)

Creating a new dir into /etc is also ok.

Some packages also have the OpenWrt uci config file and the packages' init script has functionality to parse the uci config into the package's internal config syntax.
E.g. wifi config in uci format is in /etc/config/wireless but is then written by the wifi init script as proper hostapd config to /tmp/run/hostapd-phy0.conf (into RAMdisk)


The first package I thought of that does this is dnsmasq, where it has both a canned config in /etc/dnsmasq.conf and the from-config generated one in /tmp/etc/dnsmasq.conf.cfg01411c.

For your OpenWrt install, if you want to expose some options in a /etc/config/geoip uci file, you might want to look at what I did with the snort3 package ( I've used ucode templates (like fw4 uses) to generate both .nft and snort .conf files. The generated configs end up in (by default) /tmp/snort.d/ and programmatically include files out of the base install in /etc/snort/, sort of like dnsmasq does with its various configs.

(I chose to use ucode because jow designed it for use in templating output just like this, and you can do things much more easily than in sh for the most part (dicts/associative arrays and real objects are the big ones for me). Plus, it's guaranteed to exist on all OpenWrt installs due to the fw4 dependency.)


BTW you know that one of my pet projects is implementation of arrays for posix shell? You should try it. Works much faster than calling external binaries.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.