RPM 规范文件查找已安装的版本

RPM spec file find installed version

安装 rpm 时我需要找到以前版本的软件包(如果已经安装)。我的规格文件如下

在POST

%post if [ "" = "1" ]; then # Perform new install fi elif [ "" = "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> 还有其他可用的方法吗?

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

参见: 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