[LEDE-DEV] Stock config files as templates
Magnus Kroken
mkroken at gmail.com
Tue Jul 25 10:28:10 PDT 2017
Hi Philip
On 25.07.2017 18:29, Philip Prindeville wrote:
> I’m guessing I’d need a sed script with a loop to gather all of the ‘server’ lines and replace them with one.
>
> Or am I missing something obvious?
I think you are. Look at Dnsmasq and OpenVPN for two examples of UCI
config integration. They do things slightly differently in terms of
handling config files in upstream format (Dnsmasq/OpenVPN native config
files), but they both use them.
Dnsmasq ships /etc/dnsmasq.conf, completely commented out. Users who
need to or prefer to configure Dnsmasq in its native format can add
their options to this file. The Dnsmasq init script parses the UCI
configuration, and writes out a native Dnsmasq config file based on the
UCI config to /tmp/etc/dnsmasq.conf.${cfg}. This temporary file includes
/etc/dnsmasq.conf. Dnsmasq is finally started with the temporary config
file specified on the command line, and will then include everything
specified in /etc/dnsmasq.conf.
The OpenVPN init script parses each UCI openvpn section, and writes out
an OpenVPN native config file to /tmp/etc for each section. OpenVPN is
then started with the temporary config file specified on the command
line. The OpenVPN init script also checks for any *.conf files in
/etc/openvpn, and if any exist it will start an OpenVPN instance for
each of them, specifying each *.conf file in /etc/openvpn on the command
line.
Unlike Dnsmasq, OpenVPN UCI instances and native config instances
(/etc/openvpn/*.conf) do not overlap (one exception: a native config
instance can be disabled in UCI). Each single OpenVPN instance must be
configured *either* entirely in UCI, *or* entirely in /etc/openvpn/*.conf.
If it makes sense to run onlye one instance, or more instances with some
options common to all instances, the Dnsmasq approach makes sense. If
running several instances with no common options between all, the
OpenVPN approach makes more sense.
There may be more ways to do it, but both of these seem better than
sed-ing a file. If you can avoid writing to flash outside of package
install/image upgrade, it is best to do so (by only writing to /tmp).
> Thanks,
>
> -Philip
Regards
/Magnus
More information about the Lede-dev
mailing list