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

Re: use and abuse of debconf



On Sun, Jan 14, 2001 at 11:58:33PM -0800, Joey Hess wrote:
> 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

An alternative method, that mimics conffile behaviour somewhat:

foo.templates:
	Template: foo/question
	...

	Template: foo/etc-foo-md5
	Type: string
	Default: not-present

foo.config:
	#!/bin/sh -e
	. /usr/share/debconf/confmodule
	db_input foo/question

foo.postinst:
	#!/bin/sh -e
	. /usr/share/debconf/confmodule
	db_get foo/etc-foo-md5; MD5=$RET
	if [ "$MD5" = "not-present" -a ! -e /etc/foo ] ||
		[ -e /etc/foo -a "$MD5" = $(md5sum < /etc/foo) ]
	then
		# config file under control of debconf still
		db_get foo/question; FOO=$RET
		(echo "# /etc/foo -- see foo(5) for info"
		 echo "QUESTION=$FOO"
		) > /etc/foo
		NEWMD5=$(md5sum < /etc/foo)
		db_set foo/etc-foo-md5 $NEWMD5
	fi

(untested, mind)

Cheers,
aj

-- 
Anthony Towns <aj@humbug.org.au> <http://azure.humbug.org.au/~aj/>
I don't speak for anyone save myself. GPG signed mail preferred.

     ``Thanks to all avid pokers out there''
                       -- linux.conf.au, 17-20 January 2001

Attachment: pgpivgefwhaj3.pgp
Description: PGP signature


Reply to: