Debconf in Debian Packages

- 3 mins

As part of my GSoC project, I had to find a way to ask users questions and install the packages depending on their given answers, my specific case was to ask the users to select an entry from multiple choices and download an archive from the chosen one, to achieve this, I used debconf.

So what is debconf ?

Debconf is a backend database, with a frontend that talks to it and presents an interface to the user. There can be many different types of frontends, from plain text to a web frontend. The frontend also talks to a special config script in the control section of a Debian package, and it can talk to postinst scripts and other scripts as well, all using a special protocol. These scripts tell the frontend what values they need from the database, and the frontend asks the user questions to get those values if they aren’t set.

Even better, we can make sure that the users get the questions in their own languages by using po-debconf.

Debconf Frontend

Steps:

$ apt install debconf po-debconf
Template: packagename/something
Type: select
Choices: choice1, choice2
Default: choice1
_Description: A short description here
 A longer description here about the quastion.
#!/bin/sh

set -e

# Source debconf library.
. /usr/share/debconf/confmodule

# Run template
db_input high packagename/something || true
db_go

#DEBHELPER#

exit 0
$ cd debian && mkdir po
$ echo "[type: gettext/rfc822deb] templates" > po/POTFILES.in
$ debconf-updatepo
Depends: debconf,
         po-debconf,
         ${misc:Depends}
#!/bin/sh

set -e

# Source debconf library.
. /usr/share/debconf/confmodule
db_get packagename/something

case "$1" in
    configure)
        make -C /var/cache/packagename/ DL_MIRROR="$RET" install
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

#DEBHELPER#

exit 0
#!/bin/sh

set -e

case "$1" in
    purge)
        rm -rf /var/cache/packagename
        if [ -e /usr/share/debconf/confmodule ]
        then
                # Source debconf library and purge db
                . /usr/share/debconf/confmodule
                db_purge
        fi
        ;;

    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
        ;;

    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 1
        ;;
esac

#DEBHELPER#

exit 0

Examples:

Sources

Mouaad Aallam

Mouaad Aallam

Software Engineer

rss facebook twitter github youtube mail spotify instagram linkedin google pinterest medium vimeo mastodon gitlab docker