On Sun, Aug 23, 2009 at 11:36:32 +0200, Daniel Baumann wrote:

> Steve Langasek wrote:
> > Apt runs .config scripts /before/ the preinst
> > scripts, using the dpkg-preconfigure hook
> 
> ok.
> 
> > Either this question needs to be deferred until after we know the preinst as
> > run
> 
> will do that then.
> 
> > or, preferrably, it should be dropped entirely, because magic debconf
> > tokens are *not* a policy-compliant way to manage config files.
> 
> how do you suggest do do it different then? i'm not aware of a better
> way to allow configuration through debconf be disabled by sysadmin.
> 
Why would you want that?

debconf-devel(7) has some examples how to deal with config files.  So,
how about something like the following (untested):

diff -u tftp-hpa-5.0/debian/tftpd-hpa.config 
tftp-hpa-5.0/debian/tftpd-hpa.config
--- tftp-hpa-5.0/debian/tftpd-hpa.config
+++ tftp-hpa-5.0/debian/tftpd-hpa.config
@@ -6,15 +6,15 @@
 
-if [ ! -e /etc/default/tftpd-hpa ] || \
-   grep -qs '^#DEBCONF#' /etc/default/tftpd-hpa
-then
-       db_input low tftpd-hpa/username || true
-       db_go
-
-       db_input low tftpd-hpa/directory || true
-       db_go
-else
-       db_input low tftpd-hpa/no-debconf-token
-       db_go
+CONFIGFILE=/etc/default/tftpd-hpa
+
+if [ -e $CONFIGFILE ]; then
+       . $CONFIGFILE || true
+
+       db_set tftpd-hpa/username "$TFTP_USERNAME"
+       db_set tftpd-hpa/directory "$TFTP_DIRECTORY"
 fi
 
+db_input low tftpd-hpa/username || true
+db_input low tftpd-hpa/directory || true
+db_go || true
+
 db_stop
diff -u tftp-hpa-5.0/debian/changelog tftp-hpa-5.0/debian/changelog
--- tftp-hpa-5.0/debian/changelog
+++ tftp-hpa-5.0/debian/changelog
@@ -1,3 +1,9 @@
+tftp-hpa (5.0-6) UNRELEASED; urgency=low
+
+  * Deal with /etc/default/tftpd-hpa in a policy compliant way.
+
+ -- Julien Cristau <[email protected]>  Sun, 23 Aug 2009 14:27:55 +0200
+
 tftp-hpa (5.0-5) unstable; urgency=low
 
   * Adding missing build-depends to autotools-dev (Closes: #541550).
diff -u tftp-hpa-5.0/debian/tftpd-hpa.postinst 
tftp-hpa-5.0/debian/tftpd-hpa.postinst
--- tftp-hpa-5.0/debian/tftpd-hpa.postinst
+++ tftp-hpa-5.0/debian/tftpd-hpa.postinst
@@ -4,6 +4,8 @@
 
 . /usr/share/debconf/confmodule
 
+CONFIGFILE=/etc/default/tftpd-hpa
+
 case "${1}" in
        configure)
                db_version 2.0
@@ -16,28 +18,30 @@
 
                db_stop
 
-               if [ ! -e /etc/default/tftpd-hpa ] || \
-                  grep -qs '^#DEBCONF#' /etc/default/tftpd-hpa
-               then
-
-cat > /etc/default/tftpd-hpa << EOF
-# /etc/default/tftpd-hpa
-
-## The configuration of this file is managed by debconf as long
-## as a line beginning with the '#DEBCONF#' token is included.
-##
-## Do not edit this file manually, use:
-## dpkg-reconfigure tftpd-hpa
-
-#DEBCONF#
+               if [ ! -e $CONFIGFILE ]; then
 
+                       cat > $CONFIGFILE << EOF
 TFTP_USERNAME="${TFTP_USERNAME}"
 TFTP_DIRECTORY="${TFTP_DIRECTORY}"
 EOF
-               else
-                       . /etc/default/tftpd-hpa
                fi
 
+               cp -a -f $CONFIGFILE $CONFIGFILE.tmp
+
+               # If the admin deleted or commented some variables but then set
+               # them via debconf, (re-)add them to the config file.
+               test -z "$TFTP_USERNAME" || \
+                       grep -Eq '^ *TFTP_USERNAME=' $CONFIGFILE || \
+                       echo "TFTP_USERNAME=" >> $CONFIGFILE
+               test -z "$TFTP_DIRECTORY" || \
+                       grep -Eq '^ *TFTP_DIRECTORY=' $CONFIGFILE || \
+                       echo "TFTP_DIRECTORY=" >> $CONFIGFILE
+
+               sed -e "s/^ 
*TFTP_USERNAME=.*/TFTP_USERNAME=\"$TFTP_USERNAME\"/" \
+                   -e "s/^ 
*TFTP_DIRECTORY=.*/TFTP_DIRECTORY=\"$TFTP_DIRECTORY\"/" \
+                   < $CONFIGFILE > $CONFIGFILE.tmp
+               mv -f $CONFIGFILE.tmp $CONFIGFILE
+
                if ! getent passwd | grep -q "^${TFTP_USERNAME}"
                then
                        adduser --system --home ${TFTP_DIRECTORY} 
--no-create-home --quiet --gecos 'tftp daemon' --group ${TFTP_USERNAME}



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to