I'm creating an RPM package (let's call it package A). I need to react if another package (package B) is reinstalled or updated. So I created a trigger inside package B specfile:

%triggerin -- B

Unfortunately trigger is activated even when I install or update package A and package B is already in the system. I need to execute trigger code only if package A is installed and package B is reinstalled or updated. How can I differentiate between these two types of activation?


%triggerin gets executed after your RPM is installed if the target is already installed, and after the target gets installed while your RPM is installed

%triggerun gets executed before your RPM is uninstalled if the target is installed, and before the target gets uninstalled while your RPM is installed

%triggerpostun gets executed after the target is uninstalled while your RPM is installed, but does not run if your RPM is uninstalled

That said you could use %triggerin with a conditional to avoid executing the code when you install A. You could achieve this by assigning a value to a variable in the %pre section.

something like this:

%define install_ed %(rpm -qa | grep A)


if [ $install_ed ne "A" ]; then ...

I am not on a rpm based machine now so I cannot test the solution, but it should work

  • Great solution! I've already did it creating a temporary file in %pre, that I'm checking in %triggerin but using %define is far more elegant. – user318972 May 15 '14 at 10:43

Can you try checking for the %{installtime:date} in your trigger. Only do things if it is recent enough.

  • This is an ugly solution. If I will be forced to use something like that I rather create a temp file in preinst and don't run the code in trigger if file exist (and then delete the file). But I hope that there is more elegant solution. – user318972 Apr 28 '14 at 15:49
  • I agree with it being an ugly solution, I was just throwing an idea out there. – DavidG Apr 28 '14 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.