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

Re: debconf in preinst and postinst?



Christian T. Steigies wrote:
> I am still a little confused at what the config script does, how do I use
> it when I want to use debconf in several maintainer scripts, ie preinst and
> postinst? Add all db_ calls there? Does order matter? Is it a collection of
> "subroutines" for the different texts and questions?
> Or do I need seperate config scripts for each script now?

The config script is the script that is run at preconfiguration time.
When possible, packages should use the config script, and only the
config script to interact with the user, since using debconf to ask
questions in other scripts will result in the install pausing in the
middle to ask the question. The config script should also do no actions
except using debconf to ask questions. Aside from that, and from being
specific to debconf, the config script is a maintainer script like any
other.

> Also I am confused by this section in the tutorial:
> 
> The Config Script
> 
>  Note: 
>  These questions are asked by a separate config script, not by the postinst,
>  so the package can be configured before it is installed, or reconfigured
>  after it is installed. 
>  Do not make your postinst use debconf to ask questions.
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> But then it says:
>  Our config script already handles most of this. After debconf, the postinst
>  becomes:
> 
>  #!/bin/sh -e
> 
>  # Source debconf library.
>  . /usr/share/debconf/confmodule
>  db_get foo/like_debian
>  ^^^^^^^^^^^^^^^^^^^^^^
> So it is asking a question in the postinst?

No, the GET command retreives the answer to a question so the postinst
can act on it. Look at the turorial again, you will see the config
script uses an INPUT command to ask that same question.

> I don't want to ask a question
> in the postinst (I ask it in the preinst), in postinst I just want to
> display a message when an old score file is present and is removed. How do I
> do that?

No, your config script should test for this situation if possible, and
you should display the message there with the INPUT command.

> My files look like this now:
> 
> moon-buggy-esd.config:
> ----------------------
> # Source debconf library.
> . /usr/share/debconf/confmodule
> 
> # Sound hardware installed?
> db_input medium moon-buggy-esd/sound_hardware || true
> db_go
> 
> # Check their answer.
> db_get moon-buggy-esd/sound_hardware
> if [ "$RET" = "false" ]; then
>         # Do not install this package..
>         db_input high moon-buggy-esd/no_sound_hardware || true
>         db_go
> fi

This looks ok.

> # Old scorefile
> db_get moon-buggy-esd/old_score_file || true
> db_go

I don't see the point of retreiving the value of the question
moon-buggy-esd/old_score_file if you do nothing with it. 
You probably meant to use db_input.

> moon-buggy-esd.preinst:
> -----------------------
> #! /bin/sh -e
> 
> export DEBCONF_DEBUG=developer
> 
> case "$1" in
>     install|upgrade)
> # Source debconf library.
>         . /usr/share/debconf/confmodule
> 
>         db_get moon-buggy-esd/sound_hardware
>         if [ "$RET" = "false" ]; then
>             exit 1;
>         fi

This looks fine.

> moon-buggy-esd.postinst:
> ------------------------
> #! /bin/sh -e
> 
> export DEBCONF_DEBUG=developer
> 
> # Source debconf library.
>     . /usr/share/debconf/confmodule
> 
> if [ "$1" = configure ]
> then
> # (Re)move old scorefile and directory if it exists
>   if [ -e /var/lib/games/moon-buggy/mbscore ]
>   then 
>     db_get moon-buggy-esd/old_score_file
>     mv files around...

Why are you calling the GET command again, and again ignoring whatever
it returns?

> Files are moved, but I am never shown the note about the old score file.
> Somewhere I must be doing a very stupid mistake?

Probably confusing GET and INPUT. Perhaps you should read
/usr/doc/debian-policy/debconf_specification.txt.gz

> And another, not so urgent question.  Can templates be shared between
> different packages? When I install moon-buggy and later replace it by
> moon-buggy-esd, the moon-buggy templates are still there (unless I purge it,
> but then I loose the scores as well).  Some of the templates are identical
> in moon-bugy-esd (old score file). Is there a way to "reuse" them? I can not
> have both packages installed at the same time, so I never know it "the other"
> templates are already there. Maybe the templates should be purged, when "the
> other" package is installed to save some space?

Debconf allows multiple packages to contain templates and questions with
the same name. It keeps track of what packages include them, and will
only remove the templates and questions when all of those packages are
purged. This is all done automatically (except for requiring you call
the PURGE command in yout postrm on purge, which debhelper does for
you).

-- 
see shy jo



Reply to: