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

How to use hidden debconf questions



I recently started to convert the debian-edu-config package to use
hidden debconf questions when configuring the init.d scripts at
install time.  Here is a small recipe and code example.  I'm not happy
with the code, as it is way to verbose.  It should be simple to add
hidden debconf questions.  It should not require 20 lines of code.

Anyway.  The following steps are required

 - Make use the script read the default from somewhere, and the host
   specific overrides from a file in /etc/ if it exist.  The code I
   use in this example look like this:

      UPDATE=/usr/bin/update-hostname-from-ip
      ENABLED=false
      [ -f /etc/default/update-hostname ] && . /etc/default/update-hostname
      [ -x "$UPDATE" -a true = "$ENABLED" ] || exit 0

 - Add a debconf template to the package (and make sure it is
   installed).  Mine look like this:

      Template: debian-edu-config/update-hostname
      Type: boolean
      Default: false
      Description: Should the init.d/update-hostname script run at boot time
       Internal template used to set the configuration value at install time.

 - Add a code fragment like this to the postinst script:

      ENABLED_DEFAULT=false
      ENABLED=$ENABLED_DEFAULT
      DEFAULTFILE=/etc/default/update-hostname
      # Load current value if set in /etc/
      if [ -f $DEFAULTFILE ] ; then
          . $DEFAULTFILE
          if [ "$ENABLED" ] ; then
      	db_set debian-edu-config/update-hostname "$ENABLED"
          fi
      fi
      db_get debian-edu-config/update-hostname
      # Only replace if the value changed
      if [ -f $DEFAULTFILE ] ; then
          if [ "$RET" != "$ENABLED" ] ; then
      	sed "s/ENABLED=.+/ENABLED=\"$RET\"" < $DEFAULTFILE > $DEFAULTFILE.new &&
      	    mv $DEFAULTFILE.new $DEFAULTFILE	    
          fi
      else
          # Only create or update the file if the value isn't the default value
          if [ "$ENABLED_DEFAULT" != "$RET" ] ; then
      	echo "ENABLED=\"$RET\"" >> $DEFAULTFILE
          fi
      fi

   This code is not perfect, as it have its own copy of the default
   value.  Done properly, it should load the default value from the
   same place as the init.d script.

This will make sure the debconf value is used if the /etc/
configuration file is missing, and that the value if the file in /etc/
is used if the file exist.  This way, preseeding work, but only during
install.

(Hm, 444 unread messages on debian-custom.  I really need to stop
reading email soon.  It seem to be the only way to make sure I get
anything done.)



Reply to: