debiandeb

How to add uninstall script to debian package


I have created a simple Debian package for my Python program using this post. I am also using a postinst script to setup and populate mysql tables. The package gets installed with following command.

sudo apt install mypackage.deb

I now want to add an uninstall script so that if the package is removed, my uninstall script gets called to cleanup the environment.

How can I incorporate uninstall script with the Debian package?


Solution

  • You probably need to write a postrm script too the same way as you wrote the postinst script. See maintainer scrips flowcharts to understand how these scripts work.

    A quote from the same article:

    "It is possible to supply scripts as part of a package which the package management system will run for you when your package is installed, upgraded or removed.

    These scripts are the control information files preinst, postinst, prerm and postrm. They must be proper executable files; if they are scripts (which is recommended), they must start with the usual #! convention. They should be readable and executable by anyone, and must not be world-writable."