2

I am writing a debian binary package for my application (foo). The postinst (post install) script wants to ask the user few questions and get the answers as well. I am trying to achieve this using debconf. But I am not able to see the UI screen, prompting user with questions. I doubt if my config and templates are even called by dpkg. I am using all the instructions as per the link debconf tutorial Could someone please clarify me on the below questions:

  1. I am placing the “config” script and “templates “ file inside /debian/tmp/DEBIAN/ . So is it the correct location in debian hierarchy? Are the names correct?
  2. Are my below scripts correct?

Snippet of control file (only relevant fields I am posting)

Depends: debconf (>= 0.2.17)

Snippet of config file

#!/bin/sh
set -e

#echo "Config being called"

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

# Do you like debian?
db_input medium foo/like_debian || true
db_go

# Check their answer.
db_get foo/like_debian
if [ "$RET" = "false" ]; then
    # Poor misguided one..
    db_input high foo/why_debian_is_great || true
    db_go
fi

Snippet of templates file

Template: foo/like_debian
Type: boolean
Description: Do you like Debian?
We'd like to know if you like the Debian GNU/Linux system.

Template: foo/why_debian_is_great
Type: note
Description: Poor misguided one. Why are you installing this package?
Debian is great. As you continue using Debian, we hope you will
discover the error in your ways.

Snippet of preinst:

#!/bin/sh
set -e
#echo "Stage preinst" $1

exit 0

Snippet of postinst:

#!/bin/sh
set -e
#echo "Stage postinst" $1

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

db_get foo/like_debian
if [ "$RET" = "false" ]; then
    touch "/home/myhome/ITWORKED"
fi

exit 0

Snippet of prerm:

#!/bin/sh
set -e
#echo "Stage prerm" $1

exit 0

Snippet of postrm:

#!/bin/sh
set -e
#echo "postrm" $1

exit 0

Thanks, -Sandeep

4 Answers 4

3

I made a blog post about creating your own debian packages at:

http://www.leaseweblabs.com/2013/06/creating-custom-debian-packages/

To save you from some reading, the directory structure should be like this:

  • DEBIAN
    • control (required)
    • templates (optional)
    • preinst (optional, chmod 0755)
    • postinst (optional, chmod 0755)
    • prerm (optional, chmod 0755)
    • postrm (optional, chmod 0755)
  • … (files to be installed at specified location)

Make sure the permissions and locations are like this, and it should work :)

1
  • 2
    thanks, but I have made half progress still. I have ensured the directory structure is correct. What I mean is control, config, templates, preinst, postinst, prerm, postrm are all in just 1 directory, that is "DEBIAN". Secondly all maintainer scripts (preinst, postinst, prerm, postrm) and config have 755 permissions. The templates and control have 644 permissions. What I mean by half progress is, if I run dpkg -i myapp.deb I do not see a UI poping out asking for interactive questions. But if I run dpkg-reconfigure myapp then a UI pops out with the questions. What am I doing wrong?
    – Sandeep
    Jul 18, 2013 at 9:56
2

I had the same issue that my question was only asked with a dpkg-reconfigure and not an install dpkg -i. My solution was to add a

db_fset package-name/question_name seen false

before

db_input high package-name/question_name || true
db_go
0

I solved the issue by typing

echo PURGE | debconf-communicate <packagename>

This command clears all the selections in the debconf database. I realized that when the selections present in the debconf database, the package installer never executes the input commands in the config file. Therefore, I put the purge command in the postrm file.

0

The problem comes from the question priority.

By default, the interface will only display question with priority high and critical, you can check this in debconf/priority in file /var/cache/debconf/config.dat

So, to have you question displayed, type

db_input high foo/like_debian || true

instead of

db_input medium foo/like_debian || true

From man debconf:

Another nice feature of debconf is that the questions it asks you are prioritized. If you don't want to be bothered about every little thing, you can set up debconf to only ask you the most important questions. On the other hand, if you are a control freak, you can make it show you all questions. Each question has a priority. In increasing order of importance:

  • low Very trivial questions that have defaults that will work in the vast majority of cases.
  • medium Normal questions that have reasonable defaults.
  • high Questions that don't have a reasonable default.
  • critical Questions that you really, really need to see (or else).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .