【问题标题】:How to perform an operation in post section of rpm spec only when reinstalling the rpm仅在重新安装 rpm 时如何在 rpm 规范的 post 部分执行操作
【发布时间】:2016-03-18 17:12:31
【问题描述】:

我有一个用例,我希望仅在已安装相同版本的 rpm 时才在 rpm 规范的 post 部分执行特定命令。 RPM 将使用以下选项调用:

rpm -Uvh --replacefiles --replacepkgs rpm_file_name

条件if [ "$1" = "2" ]; 在这里没有用,因为它也适用于升级。

如何在规范中检测重装案例?

【问题讨论】:

  • 不是$1 设置为1 用于重新安装,因为最后只会安装一个版本的软件包吗?这对您没有直接帮助,因为它只是颠倒了问题,这意味着您无法区分安装和重新安装,但它会改变您需要区分的内容。
  • 是的。没错。那么我们需要一些方法来区分安装和重装。
  • %post的末尾创建一个文件?但是你在这里的实际目标是什么?为什么需要这样做?
  • 我唯一能想到的就是在文件中的某处解析version.txt 文件。就像您说的那样,计数对升级与重新安装等没有帮助。正如 Etan 所问,为什么?一个不错的钩子是%verify,如果你解释它是什么,这可能会更好地满足你的需要......

标签: rpm rpm-spec


【解决方案1】:

这是一个非常奇特的需求。对此没有直接的解决方案,但有一种解决方法:

%post
if [ $1 -eq 2 ]
then
    # this means the package is being updated; not being installed for the first time
    if [ $(rpm -q %{name} | wc -l) == 1 ]
    then
        # normally the "old" and the "new" version are both installed at this point. If only one is installed, that means we are reinstalling the exact same package
    fi
fi

【讨论】:

  • 我会试试这个。一个问题:我认为我们在从规范文件中运行“rpm”命令时受到限制。 RPM 会设置一些锁定,这可能会导致一些问题。这会是个问题吗?
  • 我也预料到了这个问题,但事实并非如此。 Rpm 只在真正需要时才加锁。我已经在 opensuse 13.1 上测试了我的提议,它运行良好。
猜你喜欢
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 2019-06-14
  • 2011-09-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-23
相关资源
最近更新 更多