Skip to content

Commit f4df694

Browse files
AllKindjcferretti
authored andcommitted
Fix dkms installation of deb packages created with Alien.
Alien does not 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. Add removal of all old dkms modules. Add checking for broken 'dkms status'. Handle that as good as possible and warn the user about it. Also add more verbose messages about what we are doing. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Mart Frauenlob <[email protected]> Closes openzfs#15415
1 parent 7964d55 commit f4df694

File tree

1 file changed

+87
-3
lines changed

1 file changed

+87
-3
lines changed

rpm/generic/zfs-dkms.spec.in

+87-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
2424
BuildArch: noarch
2525

2626
Requires: dkms >= 2.2.0.3
27+
Requires(pre): dkms >= 2.2.0.3
2728
Requires(post): dkms >= 2.2.0.3
2829
Requires(preun): dkms >= 2.2.0.3
2930
Requires: gcc, make, perl, diffutils
@@ -68,9 +69,92 @@ fi
6869
%defattr(-,root,root)
6970
/usr/src/%{module}-%{version}
7071

72+
%pre
73+
echo "Running pre installation script: $0. Parameters: $*"
74+
# We don't want any other versions lingering around in dkms.
75+
# Tests with 'dnf' showed that in case of reinstall, or upgrade
76+
# the preun scriptlet removed the version we are trying to install.
77+
# Because of this, find all zfs dkms sources in /var/lib/dkms and
78+
# remove them, if we find a matching version in dkms.
79+
80+
dkms_root=/var/lib/dkms
81+
if [ -d ${dkms_root}/%{module} ]; then
82+
cd ${dkms_root}/%{module}
83+
for x in [[:digit:]]*; do
84+
[ -d "$x" ] || continue
85+
otherver="$x"
86+
opath="${dkms_root}/%{module}/${otherver}"
87+
if [ "$otherver" != %{version} ]; then
88+
# This is a workaround for a broken 'dkms status', we caused in a previous version.
89+
# One day it might be not needed anymore, but it does not hurt to keep it.
90+
if dkms status -m %{module} -v "$otherver" 2>&1 | grep "${opath}/source/dkms.conf does not exist"
91+
then
92+
echo "ERROR: dkms status is broken!" >&2
93+
if [ -L "${opath}/source" -a ! -d "${opath}/source" ]
94+
then
95+
echo "Trying to fix it by removing the symlink: ${opath}/source" >&2
96+
echo "You should manually remove ${opath}" >&2
97+
rm -f "${opath}/source" || echo "Removal failed!" >&2
98+
fi
99+
fi
100+
if [ `dkms status -m %{module} -v "$otherver" | grep -c %{module}` -gt 0 ]; then
101+
echo "Removing old %{module} dkms modules version $otherver from all kernels."
102+
dkms remove -m %{module} -v "$otherver" --all ||:
103+
fi
104+
fi
105+
done
106+
fi
107+
108+
# Uninstall this version of zfs dkms modules before installation of the package.
109+
if [ `dkms status -m %{module} -v %{version} | grep -c %{module}` -gt 0 ]; then
110+
echo "Removing %{module} dkms modules version %{version} from all kernels."
111+
dkms remove -m %{module} -v %{version} --all ||:
112+
fi
113+
114+
%post
115+
echo "Running post installation script: $0. Parameters: $*"
116+
# Add the module to dkms, as reccommended in the dkms man page.
117+
# This is generally rpm specfic.
118+
# But this also may help, if we have a broken 'dkms status'.
119+
# Because, if the sources are available and only the symlink pointing
120+
# to them is missing, this will resolve the situation
121+
echo "Adding %{module} dkms modules version %{version} to dkms."
122+
dkms add -m %{module} -v %{version} %{!?not_rpm:--rpm_safe_upgrade} ||:
123+
124+
# After installing the package, dkms install this zfs version for the current kernel.
125+
# Force the overwriting of old modules to avoid diff warnings in dkms status.
126+
# Or in case of a downgrade to overwrite newer versions.
127+
# Or if some other backed up versions have been restored before.
128+
echo "Installing %{module} dkms modules version %{version} for the current kernel."
129+
dkms install --force -m %{module} -v %{version} ||:
130+
71131
%preun
72-
dkms remove -m %{module} -v %{version} --all
132+
dkms_root="/var/lib/dkms/%{module}/%{version}"
133+
echo "Running pre uninstall script: $0. Parameters: $*"
134+
# In case of upgrade we do nothing. See above comment in pre hook.
135+
if [ "$1" = "1" -o "$1" = "upgrade" ] ; then
136+
echo "This is an upgrade. Skipping pre uninstall action."
137+
exit 0
138+
fi
139+
140+
# Check if we uninstall the package. In that case remove the dkms modules.
141+
# '0' is the value for the first parameter for rpm packages.
142+
# 'remove' or 'purge' are the possible names for deb packages.
143+
if [ "$1" = "0" -o "$1" = "remove" -o "$1" = "purge" ] ; then
144+
if [ `dkms status -m %{module} -v %{version} | grep -c %{module}` -gt 0 ]; then
145+
echo "Removing %{module} dkms modules version %{version} from all kernels."
146+
dkms remove -m %{module} -v %{version} --all %{!?not_rpm:--rpm_safe_upgrade} && exit 0
147+
fi
148+
# If removing the modules failed, it might be because of the broken 'dkms status'.
149+
if dkms status -m %{module} -v %{version} 2>&1 | grep "${dkms_root}/source/dkms.conf does not exist"
150+
then
151+
echo "ERROR: dkms status is broken!" >&2
152+
echo "You should manually remove ${dkms_root}" >&2
153+
echo "WARNING: installed modules in /lib/modules/`uname -r`/extra could not be removed automatically!" >&2
154+
fi
155+
else
156+
echo "Script parameter $1 did not match any removal condition."
157+
fi
73158

74-
%posttrans
75-
/usr/lib/dkms/common.postinst %{module} %{version}
159+
exit 0
76160

0 commit comments

Comments
 (0)