From 3a6565903b8a2c88d0fba389bf628431dca38ff1 Mon Sep 17 00:00:00 2001 From: Mart Frauenlob Date: Wed, 18 Oct 2023 15:13:47 +0200 Subject: [PATCH] Fix dkms installation of deb packages created with Alien. Alien does not seem to honour the %posttrans hook. So move the dkms uninstall/install scripts to the %pre/%post hooks in case of package install/upgrade. In case of package removal, handle that in %preun. Also add more verbose messages about what we are doing. Signed-off-by: Mart Frauenlob --- rpm/generic/zfs-dkms.spec.in | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/rpm/generic/zfs-dkms.spec.in b/rpm/generic/zfs-dkms.spec.in index 23c3ed6ff408..677c0bc4f630 100644 --- a/rpm/generic/zfs-dkms.spec.in +++ b/rpm/generic/zfs-dkms.spec.in @@ -68,9 +68,37 @@ fi %defattr(-,root,root) /usr/src/%{module}-%{version} -%preun -dkms remove -m %{module} -v %{version} --all +%pre +# Uninstall this version of zfs dkms modules before installation of the package. +echo "Running pre installation script: $0" +if [ `dkms status -m zfs -v %{version} | grep -c zfs` -gt 0 ]; then + echo "Removing %{module} dkms modules version %{version} from all kernels." + dkms remove -m %{module} -v %{version} --all +fi + +%post +# After installing the package, dkms install this zfs version +# (if not there yet) for the current kernel. +echo "Running post installation script: $0" +if [ `dkms status -m zfs -v %{version} | grep -c zfs` -eq 0 ]; then + echo "Installing %{module} dkms modules version %{version} for the current kernel." + dkms install -m %{module} -v %{version} +fi -%posttrans -/usr/lib/dkms/common.postinst %{module} %{version} +%preun +# Check if we uninstall the package. In that case remove the dkms modules. +# '0' is the value for the first parameter for rpm packages. +# 'remove' or 'purge' are the possible names for deb packages. +echo "Running pre uninstall script: $0" +if [ "$1" = "0" -o "$1" = "remove" -o "$1" = "purge" ] ; then + echo "Removing %{module} dkms modules version %{version} from all kernels." + dkms remove -m %{module} -v %{version} --all +else + # If the above check fails, i.e. rpm or deb script invocation parameters changed, + # fall back to checking dkms status. + if [ `dkms status -m zfs -v %{version} | grep -c zfs` -gt 0 ]; then + echo "Removing %{module} dkms modules version %{version} from all kernels." + dkms remove -m %{module} -v %{version} --all + fi +fi