]>
Commit | Line | Data |
---|---|---|
866c1623 BB |
1 | %{?!packager: %define packager Brian Behlendorf <behlendorf1@llnl.gov>} |
2 | ||
6712c771 | 3 | %if ! 0%{?rhel}%{?fedora}%{?mageia}%{?suse_version}%{?openEuler} |
7670f721 NG |
4 | %define not_rpm 1 |
5 | %endif | |
6 | ||
5ad61b5b AS |
7 | # Exclude input files from mangling |
8 | %global __brp_mangle_shebangs_exclude_from ^/usr/src/.*$ | |
ecd3728b | 9 | |
f3757573 BB |
10 | %define module @PACKAGE@ |
11 | %define mkconf scripts/dkms.mkconf | |
12 | ||
13 | Name: %{module}-dkms | |
14 | ||
15 | Version: @VERSION@ | |
16 | Release: @RELEASE@%{?dist} | |
17 | Summary: Kernel module(s) (dkms) | |
18 | ||
19 | Group: System Environment/Kernel | |
20 | License: @ZFS_META_LICENSE@ | |
d0249a4b | 21 | URL: https://github.com/openzfs/zfs |
f3757573 BB |
22 | Source0: %{module}-%{version}.tar.gz |
23 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) | |
24 | BuildArch: noarch | |
25 | ||
7670f721 | 26 | Requires: dkms >= 2.2.0.3 |
9ce567c6 | 27 | Requires(pre): dkms >= 2.2.0.3 |
4a5b6ced TM |
28 | Requires(post): dkms >= 2.2.0.3 |
29 | Requires(preun): dkms >= 2.2.0.3 | |
1e427f2e | 30 | Requires: gcc, make, perl, diffutils |
4a5b6ced | 31 | Requires(post): gcc, make, perl, diffutils |
6712c771 | 32 | %if 0%{?rhel}%{?fedora}%{?mageia}%{?suse_version}%{?openEuler} |
6465e590 | 33 | Requires: kernel-devel >= @ZFS_META_KVER_MIN@, kernel-devel <= @ZFS_META_KVER_MAX@.999 |
4a5b6ced | 34 | Requires(post): kernel-devel >= @ZFS_META_KVER_MIN@, kernel-devel <= @ZFS_META_KVER_MAX@.999 |
677ca1e8 | 35 | Obsoletes: spl-dkms <= %{version} |
7670f721 | 36 | %endif |
f3757573 | 37 | Provides: %{module}-kmod = %{version} |
12954494 | 38 | AutoReqProv: no |
f3757573 | 39 | |
6712c771 | 40 | %if (0%{?fedora}%{?suse_version}%{?openEuler}) || (0%{?rhel} && 0%{?rhel} < 9) |
1a345d64 RE |
41 | # We don't directly use it, but if this isn't installed, rpmbuild as root can |
42 | # crash+corrupt rpmdb | |
43 | # See issue #12071 | |
44 | BuildRequires: ncompress | |
45 | %endif | |
46 | ||
f3757573 BB |
47 | %description |
48 | This package contains the dkms ZFS kernel modules. | |
49 | ||
50 | %prep | |
51 | %setup -q -n %{module}-%{version} | |
52 | ||
53 | %build | |
54 | %{mkconf} -n %{module} -v %{version} -f dkms.conf | |
55 | ||
56 | %install | |
57 | if [ "$RPM_BUILD_ROOT" != "/" ]; then | |
58 | rm -rf $RPM_BUILD_ROOT | |
59 | fi | |
60 | mkdir -p $RPM_BUILD_ROOT/usr/src/ | |
61 | cp -rf ${RPM_BUILD_DIR}/%{module}-%{version} $RPM_BUILD_ROOT/usr/src/ | |
62 | ||
63 | %clean | |
64 | if [ "$RPM_BUILD_ROOT" != "/" ]; then | |
65 | rm -rf $RPM_BUILD_ROOT | |
66 | fi | |
67 | ||
68 | %files | |
69 | %defattr(-,root,root) | |
70 | /usr/src/%{module}-%{version} | |
71 | ||
9ce567c6 MF |
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 | |
95b68eb6 | 106 | cd ${dkms_root} |
9ce567c6 MF |
107 | fi |
108 | ||
109 | # Uninstall this version of zfs dkms modules before installation of the package. | |
110 | if [ `dkms status -m %{module} -v %{version} | grep -c %{module}` -gt 0 ]; then | |
111 | echo "Removing %{module} dkms modules version %{version} from all kernels." | |
112 | dkms remove -m %{module} -v %{version} --all ||: | |
113 | fi | |
114 | ||
115 | %post | |
116 | echo "Running post installation script: $0. Parameters: $*" | |
117 | # Add the module to dkms, as reccommended in the dkms man page. | |
118 | # This is generally rpm specfic. | |
119 | # But this also may help, if we have a broken 'dkms status'. | |
120 | # Because, if the sources are available and only the symlink pointing | |
121 | # to them is missing, this will resolve the situation | |
122 | echo "Adding %{module} dkms modules version %{version} to dkms." | |
123 | dkms add -m %{module} -v %{version} %{!?not_rpm:--rpm_safe_upgrade} ||: | |
124 | ||
125 | # After installing the package, dkms install this zfs version for the current kernel. | |
126 | # Force the overwriting of old modules to avoid diff warnings in dkms status. | |
127 | # Or in case of a downgrade to overwrite newer versions. | |
128 | # Or if some other backed up versions have been restored before. | |
129 | echo "Installing %{module} dkms modules version %{version} for the current kernel." | |
130 | dkms install --force -m %{module} -v %{version} ||: | |
131 | ||
f3757573 | 132 | %preun |
9ce567c6 MF |
133 | dkms_root="/var/lib/dkms/%{module}/%{version}" |
134 | echo "Running pre uninstall script: $0. Parameters: $*" | |
135 | # In case of upgrade we do nothing. See above comment in pre hook. | |
136 | if [ "$1" = "1" -o "$1" = "upgrade" ] ; then | |
137 | echo "This is an upgrade. Skipping pre uninstall action." | |
138 | exit 0 | |
139 | fi | |
140 | ||
141 | # Check if we uninstall the package. In that case remove the dkms modules. | |
142 | # '0' is the value for the first parameter for rpm packages. | |
143 | # 'remove' or 'purge' are the possible names for deb packages. | |
144 | if [ "$1" = "0" -o "$1" = "remove" -o "$1" = "purge" ] ; then | |
145 | if [ `dkms status -m %{module} -v %{version} | grep -c %{module}` -gt 0 ]; then | |
146 | echo "Removing %{module} dkms modules version %{version} from all kernels." | |
147 | dkms remove -m %{module} -v %{version} --all %{!?not_rpm:--rpm_safe_upgrade} && exit 0 | |
148 | fi | |
149 | # If removing the modules failed, it might be because of the broken 'dkms status'. | |
150 | if dkms status -m %{module} -v %{version} 2>&1 | grep "${dkms_root}/source/dkms.conf does not exist" | |
151 | then | |
152 | echo "ERROR: dkms status is broken!" >&2 | |
153 | echo "You should manually remove ${dkms_root}" >&2 | |
154 | echo "WARNING: installed modules in /lib/modules/`uname -r`/extra could not be removed automatically!" >&2 | |
155 | fi | |
156 | else | |
157 | echo "Script parameter $1 did not match any removal condition." | |
158 | fi | |
063c83a8 | 159 | |
9ce567c6 | 160 | exit 0 |
21e000ad | 161 |