Search code examples
rpmrhelrpm-spec

why does rpm reinstall executes %postun after %post section


I have a sample rpm spec file like

Name:           helloworld
Version:        2.0
Release:        2%{?dist}
Summary:        Simple Hello World rpm
License:        Internal
Source0:        helloworld-src.tar.bz2

%description

%prep
%setup -c -q -T -D -a 0

%build

%install
echo "Install command ..."

%post
echo "post command..."

%postun
echo "postun command..."


%files
%doc
%changelog

When I execute rpm -i helloworld.rpm, the output is

post command...

But when I execute rpm --reinstall helloworld, the output is

post command...
postun command...

Whys is this so? I was expecting postun to be called before post would be called. Where can I find which scriplets will be called during rpm --reinstall ?


Solution

  • It's because reinstall is like an upgrade; the new one gets installed and the old one is uninstalled, triggering the %postun. The full sequence, from Fedora's excellent packaging guidelines, shows you are hitting steps 4 and 11:

    1. %pretrans of new package
    2. %pre of new package
    3. (package install)
    4. %post of new package
    5. %triggerin of other packages (set off by installing new package)
    6. %triggerin of new package (if any are true)
    7. %triggerun of old package (if it’s set off by uninstalling the old package)
    8. %triggerun of other packages (set off by uninstalling old package)
    9. %preun of old package
    10. (removal of old package)
    11. %postun of old package
    12. %triggerpostun of old package (if it’s set off by uninstalling the old package)
    13. %triggerpostun of other packages (if they’re set off by uninstalling the old package)
    14. %posttrans of new package