3

I need to find the previous version of the package (if installed already) when installing rpm. My spec file as follows

In 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

In the above code, how can i obtain value for the Version. I tried using executing rpm-qi | grep <rpm_package> is there any other methods available?

  • 1
    `rpm -qi` would probably not work because the RPM DB is locked for your transaction. I think you would need your upgrade logic to be smart enough to figure out what version it was based on file formats, etc. IMHO, that upgrade logic would be better in the application itself instead of being RPM-specific. – Aaron D. Marasco Feb 13 '16 at 19:31

1 Answers1

3

Do not check version. Check if the data are old or new.

See: 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
msuchy
  • 5,162
  • 1
  • 14
  • 26