Issue
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?
Solution
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
Answered By - msuchy Answer Checked By - Terry (WPSolving Volunteer)