I structured my debian package in following way

  • preinst script which displays EULA to user and ask for choice 'y' or 'n'.
  • postinst script which install the package and updates the initrd image.
  • prerm script ,before uninstalling package checks for a condition if the condition matches then it exits from prerm with exit 1.
  • postrm script unloads the package if the check in prerm script fails and it update the initrd image.

Now I have the following questions

  1. Lets say package is already installed on machine and user is trying to reinstall or upgrade it .Now if user says 'yes' to EULA, what debian will do? I observed it simply -uninstall previously installed package and reinstall it which is perfectly fine.But if user says 'n' to EULA how would I exit from uninstallation process? I did it adding exit 1 in preinst script but its not working.I observed that if you say dpkg -i package ,debian first checks if package is already installed, If package is already installed then it unpacks the package even before calling preinst script(`checked it using lsmod) so if you say 'n' to EULA it starts rolling back the changes i.e reinstalling unpacked package by calling postinst script which looks like weird behaviour to end user as user has already said 'n' to EULA.I tried adding a check if module is present the do not re install it but as I said whenever you say dpkg -i package ,debian first removes the module and fails my check.So how can avoid reinstalling package if user says no to EULA?

  2. If I say dpkg -r package and my prerm script fails and exits with status 1 .Here the same thing happens as above.If you say dpkg -r package ,debian unloads the package before calling prerm script then it checks for the condition in prerm if it matches it exits from it and starts rolling back the changes by calling postinst script which is once again weird behaviour.

I know it's the default behavior of Debian but what if I want to override default behaviour?

  • I don't understand the question. If the prerm script fails, the removal is aborted and the postrm script is never executed. – Gilles Jul 5 '13 at 23:09
  • Are you sure that a post-removal script is executed? The output mentions "post-installation script" only. – Hauke Laging Jul 5 '13 at 23:41
  • Have you seen Chapter 6 of the Debian Policy Manual? Also, "unload" isn't a term that dpkg uses; do you mean "unpack"? – derobert Jul 8 '13 at 8:40
  • @captain It sounds like you're saying its calling postinst with the abort-upgrade argument (§6.6, step 3). You can't change that. You can only have your postinst script handle that case differently (by looking at the argument). But I'm not entirely sure I'm understanding what you're asking... – derobert Jul 8 '13 at 15:38
  • @derobert this is what I am trying to convince you.Its calling post inst script which I want to avoid doing.Is there any way to handle it? – Dipak Ingole Jul 8 '13 at 15:43

This kind of thing should not be done in (pre|post)|(inst|rm) scripts. (pre|post)|(inst|rm) scripts should be idempotent and noninteractive.

Instead, what you want to do is provide a debconf template which requires the questions be answered in order for the package to be fully installed.

If you want an example, look at the sun-java* packages. You can view the debconf template here: dlj.templates.

The sun-java* packages specifically present a license that must be approved before Java will be installed.

Here's a different example question from the template (because the license one is too long to reproduce here):

Template: shared/accepted-sun-dlj-v1-1
Type: boolean
Default: false
_Description: Do you accept the DLJ license terms?
 In order to install this package, you must accept the license terms, the
 "Operating System Distributor License for Java" (DLJ), v1.1. Not accepting
 will cancel the installation.
  • Template is the object's name in the debconf database. It must be unique.
  • Type is the type of value. In this case it's a boolean meaning that debconf will ask a yes/no question.
  • Default gives the initially selected response when presented to the user (or the response automatically chosen if the priority is not high enough for the question to be seen).
  • _Description is the title of the dialog.
  • The remaining is the text presented in the dialog. It must be indented with a single space.
  • Templates are separated by empty lines (i.e., \n\n)

For more information see Debian's debconf specification documentation and the Developer's Reference section 6.5.

  • can I get a chance to look at some sample code done using debconf ? I did not find any good example to implement it.I read debconf documentation but did not understand how to implement it.Plz do me a favour if you can – Dipak Ingole Jul 24 '13 at 12:29
  • Download the sun-java* packages and unpack them (dpkg --unpack). They come with debconf templates. You can use those to model templates of your own. The templates define which questions debconf will ask during installation and which values are stored in the database. – bahamat Jul 25 '13 at 8:57
  • I completely new to this.I dont know how to explore package unpacking it.I unpacked it but I did not find package traces anywhere.Can you please give me idea where I should I do it? – Dipak Ingole Jul 25 '13 at 9:17
  • Updated with a little more information. I can't really help you more than that. I'm not going to do it for you and I can't learn for you. You need to do some learning on your own from here. – bahamat Jul 25 '13 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.