I have a Debian package which has to update some files. These files will exist after a uninstallation of the Debian package. I want to remove them together with my package, when i call apt-get remove.
If i add the updated files to
/var/lib/dpkg/info/<package>.list
they will be removed.
Update: I'll remove the folder in the postrm.debhelper script with
rm -rf folder
But it feels not right. ;)
First, I would say that this sounds like somewhat improper behavior for a package, deleting files on uninstall that existed before install, and I'd strongly recommend against doing anything of the sort in a package meant for use by the general public. However, if it's for private use, and the relevant people understand what it does, it should be fine.
Removing the files in the prerm or postrm sounds like the best answer. But be sure you don't perform the rm
unconditionally; the prerm and postrm can be called in several circumstances other than total package removal.
The postrm is preferable over the prerm, unless you want to make completely sure that the files will be removed before the package's own contents are removed from the filesystem.
In a postrm, I would suggest doing something like
case "$1" in
purge|disappear)
rm -rf $your_folder
esac
You could add remove
to purge
and disappear
there, if you want the files to be removed even when the package is "removed" as opposed to "purged" ("remove" means the package's configuration files will be kept; this usually implies a chance of the package being installed again later).
A postrm will also be called on a normal package upgrade, or when an upgrade or initial install fails (actions upgrade
, failed-upgrade
, abort-install
, and abort-upgrade
). See Debian Policy for a detailed description of how and when those are used. You almost definitely don't want to perform the rm
in those cases.