I've created a package that has a postrm
script which removes a user. When running sudo apt-get remove ...
, the postrm
script behaves as expected:
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get -y remove datim4u-auto-cert-updater
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
datim4u-auto-cert-updater
0 upgraded, 0 newly installed, 1 to remove and 32 not upgraded.
After this operation, 18.4 kB disk space will be freed.
(Reading database ... 70225 files and directories currently installed.)
Removing datim4u-auto-cert-updater (1.0.1~trusty) ...
Removing user datim4u_auto_cert_updater and its home directory...
Looking for files to backup/remove ...
Removing files ...
Removing user `datim4u_auto_cert_updater' ...
Warning: group `datim4u_auto_cert_updater' has no more members.
Done.
However, when running sudo apt-get purge ...
, the postrm
script is run twice, resulting in the error /usr/sbin/deluser: The user '...' does not exist.
:
vagrant@vagrant-ubuntu-trusty-64:~$ sudo apt-get -y purge datim4u-auto-cert-updater
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
datim4u-auto-cert-updater*
0 upgraded, 0 newly installed, 1 to remove and 32 not upgraded.
After this operation, 18.4 kB disk space will be freed.
(Reading database ... 70225 files and directories currently installed.)
Removing datim4u-auto-cert-updater (1.0.1~trusty) ...
Removing user datim4u_auto_cert_updater and its home directory...
Looking for files to backup/remove ...
Removing files ...
Removing user `datim4u_auto_cert_updater' ...
Warning: group `datim4u_auto_cert_updater' has no more members.
Done.
Purging configuration files for datim4u-auto-cert-updater (1.0.1~trusty) ...
Removing user datim4u_auto_cert_updater and its home directory...
/usr/sbin/deluser: The user `datim4u_auto_cert_updater' does not exist.
This is expected and usual. Maintainer scripts maybe called multiple times during package configuration, and they are called with an argument indicating which action they are called for. You can see the process in the Debian Wiki page on Maintainer Scripts, including this flowchart for the process of removing and purging (as opposed to a package being first removed and then purged in a different operation):
All your maintainer scripts (
{pre,post}{inst,rm}
) are expected to take note of the arguments passed to them and act accordingly.