如何仅在重新安装rpm时在rpm规范的post部分中执行操作

时间:2016-03-18 17:12:32

标签: rpm rpm-spec

我有一个用例,我想在rpm规范的post部分执行特定命令,只有在已经安装了相同版本的rpm时。将使用以下选项调用Rpm:

rpm -Uvh --replacefiles --replacepkgs rpm_file_name

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

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

1 个答案:

答案 0 :(得分:0)

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

%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