Package: debconf
Version: 1.5.46
Severity: wishlist
Several bugs (for example #684923 and #476946) complain that packages
are using debconf as a registry while it is not. At the Utrecht BSP[1],
we discussed about this and have the following suggestion to improve
debconf, which would fix bugs like these, and improve the user's
experience also for packages which don't have actual bugs.
Debconf has a cache to remember an answer the last time a question was
asked, in order to use that as a default for the next time. Most debconf
answers are also stored in a config file.
This means that the same answer to a question is stored in two places:
the config file, and debconf's cache. Some maintainer scripts seem to
assume that debconf's cache is more important than the configuration
file. This is a bug, summarized as "debconf is not a registry".
In fact, debconf itself suffers from this as well: when a user
reconfigures a package, pressing enter (for the default) on all
questions but the ones that should be changed, the expected outcome
would be that only those configuration options are changed. However, it
uses the values from its cache instead, which means that it will reset
changes which were made manually to the configuration files to their old
values.
The proposed solution is to add functionality to debconf, which can read
and edit config files. Example api:
# Get a value from a config file, using the question's default if the
# value is not in the config file.
db_getconfig [file] [key]
# Edit the config file to hold a new value.
db_setconfig [file] [key] [value]
A problem with this is that debconf will need to know the file format of
the config file. We suggest to solve this pragmatically: Many config
files are either lists of "key = value" pairs (with comments), or ini
files (which are identical, plus titles). Our idea is to implement
support for those in debconf, and allow packages to supply their own
versions of getconfig (which only takes a key from the file and doesn't
do anything with defaults) and setconfig, to support "special" config
files.[2]
The result of this would be that the above problem would be solved;
packages can easily use debconf and the defaults to answers that have
been changed manually in the config file are automatically used.
An example of this (for a very simple config file format) I have
implemented in the maintainer scripts of pioneers-meta-server.
Thanks,
Bas Wijnen
[1] http://wiki.debian.org/BSP/2012/10/nl/Utrecht
[2] The reason for using this functionality even if debconf cannot parse
your config file would be to support future debconf extensions, like
"reset settings to defaults from package".
Acknowledgement sent
to Joey Hess <[email protected]>:
Extra info received and forwarded to list. Copy sent to Debconf Developers <[email protected]>.
(Sat, 13 Oct 2012 17:30:08 GMT) (full text, mbox, link).
Bas Wijnen wrote:
> The proposed solution is to add functionality to debconf, which can read
> and edit config files.
debconf already contains this functionality. It's called a config
script.
Packages that do not use the config script to read their config files
before using debconf to ask questions are buggy, yes.
> A problem with this is that debconf will need to know the file format of
> the config file.
A config script is a completely general solution to that problem.
--
see shy jo
Acknowledgement sent
to Bas Wijnen <[email protected]>:
Extra info received and forwarded to list. Copy sent to Debconf Developers <[email protected]>.
(Sun, 14 Oct 2012 10:21:05 GMT) (full text, mbox, link).
First of all, I'm happy that we agree on the way things are supposed to
work. However, I think you slightly misunderstood my proposal.
On Sat, Oct 13, 2012 at 01:27:31PM -0400, Joey Hess wrote:
> Bas Wijnen wrote:
> > The proposed solution is to add functionality to debconf, which can read
> > and edit config files.
>
> debconf already contains this functionality. It's called a config
> script.
That's not exactly what I meant. The config script should be used to
read the config file, set up defaults, and ask questions (or not) using
those defaults. Many packages have simple config files (ini files or
simpler).
If I understand you correctly, you are saying that each of those
packages should implement parsing code for it in its config script. My
point is that this results in needless code duplication. Therefore I
would like to move this parsing code to debconf, so most packages can
simply use a function call. Packages which have more complex config
files must still implement parsing code for it themselves.
As an example, I have quoted the two functions that I use in
pioneers-meta-server (one in the config script, the other in the
postinst). I think it would benefit many packages if functions like
these (but perhaps a bit more eleborate, to support slightly more
complex files) would be in debconf.
> Packages that do not use the config script to read their config files
> before using debconf to ask questions are buggy, yes.
Good to hear that we agree on that. :-)
Thanks,
Bas
----------- Function from config, with usage example ------------
# This function will read variable $1 and set it as default to debconf
# question $2. If the variable $1 is unset or empty, the template's default
# will be used.
conffile_parse ()
{
variable="$1"
question="$2"
# Read the default from the config file.
default="`eval 'echo $'"$variable"`"
# Correct boolean values so debconf understands them.
if [ "$default" ] ; then
db_metaget "$question" type
if [ "$RET" = boolean ] ; then
case "$default" in
yes|Yes|YES|true|True|TRUE|1)
default=true
;;
no|No|NO|false|False|FALSE|0)
default=false
;;
*)
echo "Warning: value '$default' of variable '$variable' not a boolean: ignored."
default=
;;
esac
fi
fi
# If we still have a default to set, do so.
if [ "$default" ] ; then
db_set "$question" "$default"
fi
}
# Parse values from the config file and use them as defaults.
conffile_parse PORT_RANGE pioneers-meta-server/ports
conffile_parse META_SERVER_NAME pioneers-meta-server/name
conffile_parse META_SERVER_ARGS pioneers-meta-server/arguments
----------- Function from postinst, with usage example ------------
# This function will change variable $1 to the result of debconf question $2.
# If it already had the right setting, the file is not touched.
conffile_edit ()
{
variable="$1"
question="$2"
# Get the answer to the debconf question.
db_get "$question" || return 0
# Do nothing if the value hasn't changed.
test "$RET" != "`eval 'echo $'"$variable"`" || return 0
if grep -q "^$variable=" "$CONFIG_FILE" ; then
# Edit the conffile to contain the new setting.
sed -i "s/^\($variable=\).*\$/\\1'$RET'/" "$CONFIG_FILE"
else
# Or if the setting isn't in the conffile yet, add it.
echo "$variable='$RET'" >> "$CONFIG_FILE"
fi
return 0
}
conffile_edit PORT_RANGE pioneers-meta-server/ports
conffile_edit META_SERVER_NAME pioneers-meta-server/name
conffile_edit META_SERVER_ARGS pioneers-meta-server/arguments