[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

use and abuse of debconf



It has recently come to my attention that several developers are using
debconf as an excuse to write a quick hack rather than doing things
right. In particular I am talking about several packages that use
debconf to prompt the user for information, then write the information
to a file in /etc, and when upgraded or reconfigured, clobber any
manual changes to the file (and no, I'm not just talking about lilo).

As the author of debconf, this disgusts and saddens me. Debconf was
meant to make it easier to do things right, not to entice people to
write bad code. Red Hat has made a very bad name for itself amoung
knowledeable linux users by providing configuration tools that ignore
a sysadmin's manual changes to config files and that stomp over those
changes. Debian cannot go down this path; doing so would be a violation
of our tradition of quality and of doing the right thing.

Let me give two examples. 

First, we have a package that asks a question, and stores the answer 
to /etc/foo. The format of /etc/foo is simple; it is a set of var=value
lines. So the package has this as its config script:

#!/bin/sh -e
. /usr/share/debconf/confmodule
db_input medium foo/question || true
db_go || true

And this as its postinst:

#!/bin/sh -e
. /usr/share/debconf/confmodule
db_get foo/question
echo "# DO NOT modify this file; it is automatically generated." > /etc/foo
echo "QUESTION=$RET" >> /etc/foo

Each time the package is upgraded or dpkg-reconfigured, /etc/foo is
wiped out. Any changes the admin may have made are destroyed.

Now an example of a package that does it right. Its config script:

#!/bin/sh -e
. /usr/share/debconf/confmodule
if [ -e /etc/foo ]; then
	. /etc/foo || true
	if [ "$QUESTION" ]; then
		db_set foo/question $QUESTION
	fi
fi
db_input medium foo/question || true
db_go || true

And its postinst:

#!/bin/sh -e
. /usr/share/debconf/confmodule
db_get foo/question
if [ ! -e "/etc/foo" ]; then
	echo "# Configuration for foo" > /etc/foo
	echo "# Helpful comment here" >> /etc/foo
	echo "QUESTION=$RET" >> /etc/foo
else
	sed -e "s/QUESTION=.*/QUESTION=$RET/" < /etc/foo > /etc/foo.new
	mv -f /etc/foo.new /etc/foo
fi

I added only 6 lines to the config script and 6 lines to the postinst.
It wasn't hard. And this should allow the admin's manual changes to not
be blown away, and will even allow them to show up in debconf if the
package is reconfigured. This is not hard. It basic shell scripting, not
rocket science.

There is even a package called libconfhelper-perl that is desiged
specifically to help you do this (using a slightly different method), if
you don't mind using perl. Perhaps we should write something equivilant for
plain shell scripts.

Anyway, I plead once more -- don't abuse debconf! Use it in moderation,
think about what you're doing and how the admin will deal with it. Do 
things right.

-- 
see shy jo



Reply to: