Running a script after a dnf update in Fedora 41 / dnf5

Is there an equivalent to python3-dnf-plugin-post-transaction-actions for DNF5? Should this be working with the old package? What do I need to do to run a script after dnf update runs with dnf5?

Here’s the story. I have one installation of Fedora 41 that has begun having problems after a reboot when a new kernel is installed. It’s a hard crash on reboot. This is fixed by running after running grub2-mkconfig -o /boot/grub2/grub.cfg after the install. I’m not trying to address the kernel update problem here (that might be a bug report). I use automatic updates, so just a script that contains both commands is out.

What I’m trying to do is to run the grub2-mkconfig commnad after installing the kernel packages with the dnf post-transactions-actions plug in DNF post-transaction-actions Plugin — dnf-plugins-core 4.4.2-1 documentation. Based on the results below, this isn’t working.

I’m guessing this is didn’t work because of DNF5 using a different structure. So, I look at Actions Plugin — dnf5 documentation. There isn’t a actions.d directory, and I can’t find an equivalent to the python3-dnf-plugin-post-transaction-actions for DNF5.

Here’s what I’ve done for DNF (as root):

echo "*::::touch /tmp/post-transaction-action.run" > /etc/dnf/plugins/post-transaction-actions.d/post-transaction.action
dnf install alpine
ls /tmp/post-transaction-action.run
ls: cannot access '/tmp/post-transaction-action.run': No such file or directory

Then for DNF5 (as root):

echo "post_transaction::::touch /tmp/post-transaction-action.run" > /etc/dnf/dnf5-plugins/actions.d/post-transaction.action
dnf install alpine
ls /tmp/post-transaction-action.run
ls: cannot access '/tmp/post-transaction-action.run': No such file or directory```

If you need a script to run after a kernel is installed, you could drop one under /etc/kernel/install.d. Name it something like 99-post-kernel-transaction.install if you want to be sure it runs after the other scripts that are shipped by the distro and stored under /usr/lib/kernel/install.d.

1 Like

I remember spotting that in this discussion, but I’m not sure why I abandoned the idea. How do I make the system automatically run a script after a kernel update? | Nvidia Driver Build. I can see that I tried copying 99-grub-mkconfig.install to /etc/kernel/install.d/ and editing it there, but it came up short. Since you suggested it as well, I changed tactics and made a /etc/kernel/install.d/999-grub2-mkconfig.install script and that is working now.

Thank you for that.

It still leaves the question of how to run a post dnf5 script for other situations, and that there doesn’t seem to be a dnf5 equivalent to python3-dnf-plugin-post-transaction-actions. I’m still curious just to try and get parity between dnf and dnf5.

I’ll leave it unsolved for a bit to see if anyone wants to answer the dnf5 parity question.

I don’t know the situation with those plugins, but you could always write a wrapper script and drop it in your ~/bin directory. Have your script run command -p dnf "$@" and then follow that with whatever you want to happen afterward with appropriate checks to be sure the previous dnf command succeeded ([[ $? -eq 0 ]]) and that the first non-option argument in $@ is “update” or whatever.

Wrapper scripts run into a problem with the gui update client and using the dnf5-plugin-automatic package (which is how I wound up with this issue in the first place). Those won’t call the wrapper. (It might work to replace /usr/bin/dnf, but I don’t want to mess with core system files.)

Ah, I see. Yeah, I think the GUI uses PackageKit which calls libdnf directly (I don’t think it runs /usr/bin/dnf, so even replacing that system file would be unlikely to work.)