spec文件中的 %pre %post %preun %postun
轉載 http://meinit.nl/rpm-spec-prepostpreunpostun-argument-values
RPM has 4 parts where (shell) scripts can be used:
- %pre - Executed before installation.
- %preun - Executed before un-installation.
- %post - Executed after installation.
- %postun - Executed after un-installation.
In all these parts or sections the variable "$1" can be checked to see what's being done:
- Initial installation
- Upgrade
- Un-installation
This table show the values of "$1" per section related to the action.
| ? | %pre | %preun | %post | %postun |
| Initial installation | 1 | not applicable | 1 | not applicable |
| Upgrade | 2 | 1 | 2 | 1 |
| Un-installation | not applicable | 0 | not applicable | 0 |
This can be used for example when registering new services:
%post case "$1" in1)# This is an initial install.chkconfig --add newservice;;2)# This is an upgrade.# First delete the registered service.chkconfig --del newservice# Then add the registered service. In case run levels changed in the init script, the service will be correctly re-added.chkconfig --add newservice;; esac%preun case "$1" in0)# This is an un-installation.service newservice stopchkconfig --del newservice;;1)# This is an upgrade.# Do nothing.:;; esacGood to know; this is the order for certain RPM actions:
| install | upgrade | un-install |
| %pre ($1=1) | %pre ($1=2) | %preun ($1=0) |
| copy files | copy files | remove files |
| %post ($1=1) | %post ($1=2) | %postun ($1=0) |
| ? | %preun ($1=1) from?old?RPM. | ? |
| ? | delete files only found in old package | ? |
| ? | %postun ($1=1) from?old?RPM. | ? |
So when upgrading the exemplary package "software" from version 1 to version 2, this is the script (%post and %postun) order:
This means there are cases where "software-1" has incorrect scripts, and there is no way to upgrade. In that case the RPM can be uninstalled, which might execute different commands because $1 equals 0 (un-install) instead of 1 (upgrade).
When the RPM uninstall scripts fail, the only way to fix things is to manually execute the intended commands... RPM is not perfect, but it's pretty well thought through!
轉載于:https://www.cnblogs.com/xingmuxin/p/8990255.html
總結
以上是生活随笔為你收集整理的spec文件中的 %pre %post %preun %postun的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 代码生成平台Xxl-Code-Gener
- 下一篇: 10_1_网络