I structured my debian package in following waypreinst 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 questionsLets 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? 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?
How to fail prerm script and preinst script with error message in Debian package
ubuntu;debian
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-1Type: booleanDefault: 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.