Issue
I Create some file in %post script of rpm as follow
--spec file version 1.1 --
%post
echo %{version} `date` > /var/info
Above script is not present old rpm (i.e version <= 1.0). /var/info file is created when new (version 1.1) rpm is installed
I downgrade package as follow
rpm -Uvh --oldpackage myrpm-1.0.rpm
I want remove /var/info file when downgrade rpm.
if I include following script as follow then it remove file on uninstall but not upgrade. --- spec file---
%postun
if [ $1 =="0" ]
rm /var/info
fi
Can you please help me to remove file if I downgrade to version < 1.1
Solution
I don't believe you can do this using scriptlets only. That being said creating files like this using scriptlets is a bad idea (for exactly this sort of reason).
What you want for this is:
As we mentioned in the Section called The %files List, if a file is specified in the %files list, that file will automatically be included in the package. There are times when a file should be owned by the package but not installed - log files and state files are good examples of cases you might desire this to happen.
The way to achieve this, is to use the %ghost directive. By adding this directive to the line containing a file, RPM will know about the ghosted file, but will not add it to the package. However it still needs to be in the buildroot. Here's an example of %ghost in action.
The blather-1.0 package logs to /var/log/blather.log in it's default config. In the spec file, the /var/log/blather.log file is included in the %files list. We can see that blather.log belongs to the package, and it is removed when the package is.
%install
touch $RPM_BUILD_ROOT%{_localstatedir}/log/blather.log
…
%files
…
%ghost %{_localstatedir}/log/blather.log
…
# rpm -qf /var/log/blather.log
blather-1.0-1
# rpm -ql blather | grep blather.log
# rpm -e blather && ls /var/log/blather.log
ls: /var/log/blather.log: No such file or directoryThere file touched in the %install stage will not be installed to /var/log/blather.log although it will be added to the rpm database, as we can see from querying the file, however it is not visible from a package listing, but as it is owned by the package it will be removed when the package is removed. In addition it is possible to use setperms to fix the permissions on a %ghost file.
# ls -al /var/log/blather.log
-rw-r--r-- 1 root root 3448 Jun 18 17:00 /var/log/blather.log
#chmod 666 /var/log/blather.log
# ls -al /var/log/blather.log
-rw-rw-rw- 1 root root 3448 Jun 18 17:00 /var/log/blather.log
#rpm --setperms blather
# ls -al /var/log/blather.log
-rw-r--r-- 1 root root 3448 Jun 18 17:00 /var/log/blather.log
Answered By - Etan Reisner Answer Checked By - Mildred Charles (WPSolving Admin)