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