zoukankan      html  css  js  c++  java
  • 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" in
      1)
        # 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" in
      0)
        # This is an un-installation.
        service newservice stop
        chkconfig --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!

  • 相关阅读:
    手机精准定位,看好你的男朋友
    顶级分享,三端看片的日子来了
    这样的声音谁受的了呀
    白嫖vip电台,资源随意听
    老板止步!这里全是小姐姐
    粉丝福利。无视墙 来看看全世界的网站吧
    利用自己的服务器搭建专属私有云盘&博客园搬家
    Photoshop 2020 安装教程
    TensorFlow基础——常用函数(一)
    Scala基本语法入门
  • 原文地址:https://www.cnblogs.com/xingmuxin/p/8990255.html
Copyright © 2011-2022 走看看