I structured my debian package in following way
preinst scriptwhich displays EULA to user and ask for choice 'y' or 'n'.
postinst scriptwhich 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
postrm scriptunloads the package if the check in prerm script fails and it update the initrd image.
Now I have the following questions
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 1in 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 packageand 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
prermif 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?