![为什么 postrm 在清除时运行两次?](https://linux22.com/image/1001213/%E4%B8%BA%E4%BB%80%E4%B9%88%20postrm%20%E5%9C%A8%E6%B8%85%E9%99%A4%E6%97%B6%E8%BF%90%E8%A1%8C%E4%B8%A4%E6%AC%A1%EF%BC%9F.png)
我创建了一个包含postrm
删除用户的脚本的包。运行时sudo apt-get remove ...
,该postrm
脚本的行为符合预期:
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.
但是,在运行时sudo apt-get purge ...
,postrm
脚本运行了两次,导致错误/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.
答案1
这是意料之中的,也是正常的。维护者脚本可能在包配置期间被多次调用,并且它们被调用时带有一个参数,指示它们被调用的操作。你可以在Debian Wiki 页面中的维护者脚本,包括此流程图移除和清除(与首先删除然后在不同操作中清除的包相反):
全部您的维护脚本({pre,post}{inst,rm}
)应该注意传递给它们的参数并采取相应的行动。