RPM spec文件找到安装的版本

时间:2016-02-12 08:28:18

标签: rpm rpmbuild rpm-spec

我需要在安装rpm时找到该软件包的先前版本(如果已安装)。我的spec文件如下

在POST中

%post if [ "$1" = "1" ]; then # Perform new install fi elif [ "$1" = "2" ]; then # Perform update     的 # what I need is value for Version if [ $Version = 1.0]; then # do upgrade 1 fi elif [ "$Version" = "2" ]; then #do upgrade 2 fi

fi

在上面的代码中,我如何获得版本的值。我尝试使用执行 rpm-qi | grep <rpm_package> 还有其他方法吗?

1 个答案:

答案 0 :(得分:2)

不要检查版本。检查数据是旧的还是新的。

请参阅: https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Saving_state_between_scriptlets

%pre
grep OLDDATA /etc/myconfig >/dev/null && touch %{_localstatedir}/lib/rpm-state/%{name}.DoSomethingLater

%posttrans
if [ -e %{_localstatedir}/lib/rpm-state/%{name}.DoSomethingLater ]; then
# do some conditional stuff
rm -f %{_localstatedir}/lib/rpm-state/%{name}.DoSomethingLater
fi