Smarter handling of generated configuration files
Background:
Some time ago[0], I brought up the idea of adapting the conffile mechanism to
dynamically-generated configuration files. These days, many packages generate
their config files at install time, optionally asking questions through
debconf. I think it would be nice to have a uniform way of dealing with such
config files that gives administrators at least some of the advantages of the
current conffile mechanism.
Several packages implement a similar mechanism on their own, to varying degrees
of success. I hope that by centralizing this process in a library, the user
can be presented with a consistent interface, and it will be easier to allow
packages to do the right thing, while giving the user maximum flexibility.
Today:
I actually sat down and prototyped such a mechanism. The basic idea is to load
a shell/Perl library from the maintainer scripts:
- In postinst, after generating a configuration file:
config_conffile_savehash /etc/package.conf
This will calculate a hash of the given config file, and save it in a (text)
database.
- In config, at whatever point it makes sense to ask the question (debconf
should already be loaded):
config_conffile_ask <priority> <package>/<question> "Package Name" /etc/package.conf
This call will look up the hash saved by a previous configuration run (above)
and compare it to the hash of the current config file. If they are equal, no
action is taken. If they differ (indicating that the file has been
hand-edited), the user will be prompted via debconf as to whether or not it
is OK to overwrite the existing configuration. A stock template is used[1],
and the package name and configuration file are substituted into it. The
resulting answer is saved in <package>/<question> for use in the postinst.
It might be better to always ask this question at a fixed priority; I haven't
decided.
Of course, once the user has chosen to have their config file under automatic
control, this selection will be saved until the package is reconfigured
(assuming that debconf answers are saved). It might be wise to tweak this so
that (optionally) the question is always asked, each time the config file is
modified, to more closely emulate conffile behavior.
I hope to add more functionality to this library in the future, for example:
- Questions about setuid/setgid programs, with the ability to prompt for
and execute dpkg statoverrides
- Whether to start a daemon by default
- Other common tasks
Comments? Suggestions?
[0] http://lists.debian.org/debian-devel-0101/msg01852.html
[1] Using a common template should make it easier to maintain a clear, correct
and well-translated template for this question. Currently, debconf shared
templates must be included in every package that uses them, so this
attempt is thwarted. But I hope that debconf could be modified to use
these common templates in addition to those provided by the package being
configured.
--
- mdz
Reply to: