xref: /freebsd/sys/contrib/openzfs/rpm/redhat/zfs-dkms.spec.in (revision ee3960cba1068e12fb032a68c46d74841d9edab3)
1%{?!packager: %define packager Brian Behlendorf <behlendorf1@llnl.gov>}
2
3%if ! 0%{?rhel}%{?fedora}%{?mageia}%{?suse_version}%{?openEuler}
4%define not_rpm 1
5%endif
6
7# Exclude input files from mangling
8%global __brp_mangle_shebangs_exclude_from ^/usr/src/.*$
9
10%define module  @PACKAGE@
11%define mkconf  scripts/dkms.mkconf
12
13Name:           %{module}-dkms
14
15Version:        @VERSION@
16Release:        @RELEASE@%{?dist}
17Summary:        Kernel module(s) (dkms)
18
19Group:          System Environment/Kernel
20License:        @ZFS_META_LICENSE@
21URL:            https://github.com/openzfs/zfs
22Source0:        %{module}-%{version}.tar.gz
23BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
24BuildArch:      noarch
25
26Requires:       dkms >= 2.2.0.3
27Requires(pre):  dkms >= 2.2.0.3
28Requires(post): dkms >= 2.2.0.3
29Requires(preun): dkms >= 2.2.0.3
30Requires:       gcc, make, perl, diffutils
31Requires(post): gcc, make, perl, diffutils
32
33# Hold back kernel upgrades if kernel is not supported by ZFS
34%if 0%{?rhel}%{?fedora}%{?mageia}%{?suse_version}%{?openEuler}
35Requires:       kernel-devel >= @ZFS_META_KVER_MIN@, kernel-devel <= @ZFS_META_KVER_MAX@.999
36Requires(post): kernel-devel >= @ZFS_META_KVER_MIN@, kernel-devel <= @ZFS_META_KVER_MAX@.999
37Conflicts:      kernel-devel < @ZFS_META_KVER_MIN@, kernel-devel > @ZFS_META_KVER_MAX@.999
38Requires:       kernel-uname-r >= @ZFS_META_KVER_MIN@, kernel-uname-r <= @ZFS_META_KVER_MAX@.999
39Requires(post): kernel-uname-r >= @ZFS_META_KVER_MIN@, kernel-uname-r <= @ZFS_META_KVER_MAX@.999
40Conflicts:      kernel-uname-r < @ZFS_META_KVER_MIN@, kernel-uname-r > @ZFS_META_KVER_MAX@.999
41
42Obsoletes:      spl-dkms <= %{version}
43%endif
44Provides:       %{module}-kmod = %{version}
45AutoReqProv:    no
46
47%if (0%{?fedora}%{?suse_version}%{?openEuler}) || (0%{?rhel} && 0%{?rhel} < 9)
48# We don't directly use it, but if this isn't installed, rpmbuild as root can
49# crash+corrupt rpmdb
50# See issue #12071
51BuildRequires:  ncompress
52%endif
53
54%description
55This package contains the dkms ZFS kernel modules.
56
57%prep
58%setup -q -n %{module}-%{version}
59
60%build
61%{mkconf} -n %{module} -v %{version} -f dkms.conf
62
63%install
64if [ "$RPM_BUILD_ROOT" != "/" ]; then
65    rm -rf $RPM_BUILD_ROOT
66fi
67mkdir -p $RPM_BUILD_ROOT/usr/src/
68cp -rf ${RPM_BUILD_DIR}/%{module}-%{version} $RPM_BUILD_ROOT/usr/src/
69
70%clean
71if [ "$RPM_BUILD_ROOT" != "/" ]; then
72    rm -rf $RPM_BUILD_ROOT
73fi
74
75%files
76%defattr(-,root,root)
77/usr/src/%{module}-%{version}
78
79%pre
80echo "Running pre installation script: $0. Parameters: $*"
81# We don't want any other versions lingering around in dkms.
82# Tests with 'dnf' showed that in case of reinstall, or upgrade
83#  the preun scriptlet removed the version we are trying to install.
84# Because of this, find all zfs dkms sources in /var/lib/dkms and
85#  remove them, if we find a matching version in dkms.
86
87dkms_root=/var/lib/dkms
88if [ -d ${dkms_root}/%{module} ]; then
89    cd ${dkms_root}/%{module}
90    for x in [[:digit:]]*; do
91        [ -d "$x" ] || continue
92        otherver="$x"
93        opath="${dkms_root}/%{module}/${otherver}"
94        if [ "$otherver" != %{version} ]; then
95            # This is a workaround for a broken 'dkms status', we caused in a previous version.
96            # One day it might be not needed anymore, but it does not hurt to keep it.
97            if dkms status -m %{module} -v "$otherver" 2>&1 | grep "${opath}/source/dkms.conf does not exist"
98            then
99                echo "ERROR: dkms status is broken!" >&2
100                if [ -L "${opath}/source" -a ! -d "${opath}/source" ]
101                then
102                    echo "Trying to fix it by removing the symlink: ${opath}/source" >&2
103                    echo "You should manually remove ${opath}" >&2
104                    rm -f "${opath}/source" || echo "Removal failed!" >&2
105                fi
106            fi
107            if [ `dkms status -m %{module} -v "$otherver" | grep -c %{module}` -gt 0 ]; then
108                echo "Removing old %{module} dkms modules version $otherver from all kernels."
109                dkms remove -m %{module} -v "$otherver" --all ||:
110            fi
111        fi
112    done
113    cd ${dkms_root}
114fi
115
116# Uninstall this version of zfs dkms modules before installation of the package.
117if [ `dkms status -m %{module} -v %{version} | grep -c %{module}` -gt 0 ]; then
118    echo "Removing %{module} dkms modules version %{version} from all kernels."
119    dkms remove -m %{module} -v %{version} --all ||:
120fi
121
122%post
123echo "Running post installation script: $0. Parameters: $*"
124# Add the module to dkms, as reccommended in the dkms man page.
125# This is generally rpm specfic.
126# But this also may help, if we have a broken 'dkms status'.
127# Because, if the sources are available and only the symlink pointing
128#  to them is missing, this will resolve the situation
129echo "Adding %{module} dkms modules version %{version} to dkms."
130dkms add -m %{module} -v %{version} %{!?not_rpm:--rpm_safe_upgrade} ||:
131
132# After installing the package, dkms install this zfs version for the current kernel.
133# Force the overwriting of old modules to avoid diff warnings in dkms status.
134# Or in case of a downgrade to overwrite newer versions.
135# Or if some other backed up versions have been restored before.
136echo "Installing %{module} dkms modules version %{version} for the current kernel."
137dkms install --force -m %{module} -v %{version} ||:
138
139%preun
140dkms_root="/var/lib/dkms/%{module}/%{version}"
141echo "Running pre uninstall script: $0. Parameters: $*"
142# In case of upgrade we do nothing. See above comment in pre hook.
143if [ "$1" = "1" -o "$1" = "upgrade" ] ; then
144    echo "This is an upgrade. Skipping pre uninstall action."
145    exit 0
146fi
147
148# Check if we uninstall the package. In that case remove the dkms modules.
149# '0' is the value for the first parameter for rpm packages.
150# 'remove' or 'purge' are the possible names for deb packages.
151if [ "$1" = "0" -o "$1" = "remove" -o "$1" = "purge" ] ; then
152    if [ `dkms status -m %{module} -v %{version} | grep -c %{module}` -gt 0 ]; then
153        echo "Removing %{module} dkms modules version %{version} from all kernels."
154        dkms remove -m %{module} -v %{version} --all %{!?not_rpm:--rpm_safe_upgrade} && exit 0
155    fi
156    # If removing the modules failed, it might be because of the broken 'dkms status'.
157    if dkms status -m %{module} -v %{version} 2>&1 | grep "${dkms_root}/source/dkms.conf does not exist"
158    then
159        echo "ERROR: dkms status is broken!" >&2
160        echo "You should manually remove ${dkms_root}" >&2
161        echo "WARNING: installed modules in /lib/modules/`uname -r`/extra could not be removed automatically!" >&2
162    fi
163else
164    echo "Script parameter $1 did not match any removal condition."
165fi
166
167exit 0
168
169