转载 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.:;;
esac

Good 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:

  1. Run %pre from "software-2".
  2. Place files from "software-2".
  3. Run %post from "software-2".
  4. Run %preun from "software-1".
  5. Delete files unique to "software-1".
  6. Run %postun from "software-1".

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相关推荐

  1. linux编译时开启宏,【spec】Linux上编译安装的spec文件中的常用路径以及宏变量

    我们在Linux上利用 rpmbuild 构建 rpm 安装包时,通过命令rpm --showrc 查看实现代码,另外直接通过 rpm --eval "%{macro}"来查看具体 ...

  2. spec linux,linux – 在RPM包中SPEC文件中1%{?dist}的含义是什么?

    1%{?dist}是什么意思? 这是什么意思? 我没有在任何地方找到这个意思 Name: hello Version: 2.8 Release: 1%{?dist} Summary: The &quo ...

  3. RPM包制作之Spec文件详解

    看这篇文章的人基本都有一个想法,就是:"劳资不想用YUM的安装!不是版本太低就是文件分布太野路子",此时我们需要自己订制软件包的需求,我们会把一些源码包按照我们的需求来做成rpm包 ...

  4. linux rqm包制作 spec文件详解

    看这篇文章的人基本都有一个想法,就是:"不想用YUM的安装!不是版本太低就是文件分布太野路子",此时我们需要自己订制软件包的需求,我们会把一些源码包按照我们的需求来做成rpm包,其 ...

  5. linux安装spec编译器,RPM包制作之Spec文件参数详解

    看这篇文章的人基本都有一个想法,就是:"劳资不想用YUM的安装!不是版本太低就是文件分布太野路子",此时我们需要自己订制软件包的需求,我们会把一些源码包按照我们的需求来做成rpm包 ...

  6. linux spec 脚本,RPM包制作之Spec文件详解

    看这篇文章的人基本都有一个想法,就是:"劳资不想用YUM的安装!不是版本太低就是文件分布太野路子",此时我们需要自己订制软件包的需求,我们会把一些源码包按照我们的需求来做成rpm包 ...

  7. AIX下批量替换文件中的字符串 linux替换包含换行符的内容

    示例:将所有CPP文件中的__cplusplus替换为 __cplusplus_xsz perl -p -i -e "s/__cplusplus/__cplusplus_xsz/g" ...

  8. pythoninstaller打包多个py 文件_Pyinstaller通过spec文件打包py程序(多个py脚本)

    Pyinstaller pyinstaller是python的一个第三方模块,使用它可以将python程序打包为可执行文件,实现打包后的程序在没有python环境的机器上也可以运行.pyinstall ...

  9. RPM包rpmbuild SPEC文件深度说明

    关键字 spec脚本包括很多关键字,主要有: 引用 Name: 软件包的名称,后面可使用%{name}的方式引用 Summary: 软件包的内容概要 Version: 软件的实际版本号,例如:1.0. ...

最新文章

  1. C++拾取——使用stl标准库生成等差、等比数列的方法
  2. SOFAMosn配置模型
  3. linux如何删除符号链接文件夹,在Linux中怎样移除(删除)符号链接
  4. idea.config.path is invalid 问题
  5. YII框架开发一个项目的通用目录结构:
  6. Controller FioriTest.view.LineItem couldn't be instantiated
  7. (转) 假如女人是一种编程语言
  8. matlab计算斜方差_计算一幅图像的信噪比
  9. 【Python学习】 - 关于DataFrame中的applymap函数 和 Series中的map函数
  10. 加速进军自动驾驶领域,福特计划推出自动驾驶出租车服务
  11. 大话西游之程序员做项目
  12. 猎豹移动傅盛:区块链将重塑整个社会关系,CEO恐将职位不保
  13. H3C nqa 配置
  14. 13个不错的jquery图片放大器效果
  15. 基于Renascence架构的SQL查询引擎设计
  16. 自学三个月编写简单走迷宫游戏
  17. JavaScript 实例:点击漫天小星星 (获取整个浏览器窗口的宽高)
  18. 520评论点赞活动开奖
  19. 自制拖把机器人_懒出新境界:可以自己洗拖布的机器人
  20. Fabric-solo on k8s

热门文章

  1. Java学习之模拟纸牌游戏,List的ArrayList,Map的HashMap,重写Collections类的sort方法对指定类进行通过特定属性排序,输入异常处理等的学习...
  2. ★自制社交网站等级称号
  3. 关于Oracle undostat中的2012和ORA-01555问题的自我解答
  4. SSH 中从后台传值到前台JSP,传不过去问题
  5. Linux ifconfig命令
  6. Lync 小技巧-42-动态-IP-统一沟通-环境-IP-变更后-操作
  7. 利用windows优化大师软件卸载一手和清理一招
  8. SQL SERVER 里的 try catch
  9. linux查找文件命令 要查找包含某字符
  10. ireport 找不到子报表:Could not load object from location