1

I have a Debian package say XYZ.deb which copies some file on installation.

As per Debian package policy on package uninstallation only those files will be removed which were copied during installation. Also Debian doesn't remove conf files either.

XYZ package installs some Python scripts which on execution creates .pyc file. Now on de-installation I want to remove all the files. What would be the postrm script to cleanly remove package?

  • 1
    To be clear, is this a Debian package you are creating (or have created)? "copies some file" in the first line is confusing terminology. I think you are referring to the normal installation of a Debian package, which (among other things) writes the files contained to the relevant filesystems. Is that correct? – Faheem Mitha Dec 11 '13 at 10:26
7

With regard to your first question:

XYZ package installs some python scripts which on execution creates .pyc file.Now On uninstallation I want to remove all the files.What would be the postrm script to cleanly remove package?

In general a suitable postrm script is (I believe) generated automatically by debhelper and friends. See the man page for dh_python. In particular, this man page says

If some modules need to be byte-compiled at install time, appropriate postinst and prerm scripts will be generated. If already byte-compiled modules are found, they are removed.

With regard to your second question,

Also XYZ is configured using debconf file which on package installation prompts user to accepts EULA. How do I exit if user says no to the EULA?

I don't know the answer offhand, but take a look at the debconf templates for some of the proprietary software included in Debian. Sun Java is an example that has (had?) a EULA which was bought up by debconf.

ADDENDUM:

Since the OP appears unconvinced, here is a verbatim copy of the prerm script for a package called python-corrmodel. I wrote the software and also the Debian packaging. However, I didn't write the postinst and prerm scripts, and in fact had not looked at them till this moment. Notice that the prerm script calls the pyclean utility, which is part of Python. The help says:

pyclean - removes .pyc and .pyo files

Notice also that the script says the code was generated by dh_python2.

One final note: I recommend using dh, which is relatively new compared to old school debhelper, but is growing rapidly in popularity. Basically, dh by default invokes all the debhelper rules in default mode in some specific order. If you want to customize the behavior of a particular debhelper command, you can override it. Here is a description of dh overrides by Joey Hess, the author of debhelper. The big advantage is that your rules file is much less cluttered, and you can be sure all the commands are called in the right order.

Here is the prerm script.

#!/bin/sh
set -e

# Automatically added by dh_python2:
if which pyclean >/dev/null 2>&1; then
        pyclean -p python-corrmodel 
else
        dpkg -L python-corrmodel | grep \.py$ | while read file
        do
                rm -f "${file}"[co] >/dev/null
        done
fi

# End automatically added section

ADDENDUM 2:

Since I advertised dh, I'll add my rules file below. This is not the complete rules file, but this line contains the main logic. This basically has debhelper hand off the build to a setup.py script, which then does the heavy lifting.

%:
        dh $@ --with python2 --buildsystem=python_distutils --install-layout=deb
  • Thanks for kind help..as mentioned in your ans postrm script is (I believe) generated automatically by debhelper and friends. In my case it doesnt seems to happen anyway..may be there could be some other option. – Dipak Ingole Dec 11 '13 at 10:47
  • @captain If you can make your software public, I suggest you post the Debian package sources online. Then people can take a look directly. The postinst script for the *.pyc files should not require manual handling. There are many packages in Debian using Python, and none of them do this manually. – Faheem Mitha Dec 11 '13 at 12:02
  • Much appreciated...If I could have a chance I would have given you a bounty of billions. +1 for answer to first question.Can you please help me solving second question as well.And one more question what does debian python policy which I posted below stands for then? – Dipak Ingole Dec 12 '13 at 6:25
  • @captain: Note that asking 2 questions in one as you have done here is not good form. Did you look at some other debconf templates as I suggested? If so, did it not answer your questions? I don't understand your question about debian python policy. Policy just says that rules should be follows. It doesn't say anything about how to accomplish them. – Faheem Mitha Dec 13 '13 at 12:27
  • Sorry about that Faheem..I looked at sun java debconf template .I couldn't figured out how to exit from maintainer scripts. – Dipak Ingole Dec 13 '13 at 12:37
0

Referring to

debian python policy(2.6)

If a binary package provides any binary-independent modules (foo.py files), the corresponding byte-compiled modules (foo.pyc files) and optimized modules (foo.pyo files) must not ship in the package. Instead, they should be generated in the package's postinst, and removed in the package's prerm. The package's prerm has to make sure that both foo.pyc and foo.pyo are removed.

It means that byte compiled files(.pyc/pyo) should be removed in prerm phase.

So I got ans to first my question .Not marking this as correct .Needs more attention on this.

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.