Accessing relocatable rpm install directory prefix from %post script
I found similar questions in several forums (none with answers). So I'm resurrecting this thread with the answer.
Problem:
The default prefix is %{_prefix} but the %post section of the spec file can only use it when the rpm is being built, we need to know the prefix when the rpm is being installed.
Solution:
Use the environment variable $RPM_INSTALL_PREFIX to determine where the package prefix is at install time.
e.g.
Prefix: /usr
%post
#Soft link example
ln -s %{_prefix}/lib/mylib.so $RPM_INSTALL_PREFIX/lib/mylib.so
#Echo example
if [ $RPM_INSTALL_PREFIX == %{_prefix} ]
then
echo "package installed in default location: %{_prefix}"
else
echo "package installed in user-defined location: $RPM_INSTALL_PREFIX"
fi
In the above example %{_prefix} is changed to the default prefix "/usr" when the script is written and the environment variable $RPM_INSTALL_PREFIX is replaced with the one given on the commandline at install time. i.e. rpm -i --prefix /usr/local package.rpm
|