xref: /freebsd/sys/contrib/openzfs/rpm/generic/zfs-dkms.spec.in (revision 718519f4efc71096422fc71dab90b2a3369871ff)
1eda14cbcSMatt Macy%{?!packager: %define packager Brian Behlendorf <behlendorf1@llnl.gov>}
2eda14cbcSMatt Macy
3bb2d13b6SMartin Matuska%if ! 0%{?rhel}%{?fedora}%{?mageia}%{?suse_version}%{?openEuler}
4eda14cbcSMatt Macy%define not_rpm 1
5eda14cbcSMatt Macy%endif
6eda14cbcSMatt Macy
7eda14cbcSMatt Macy# Exclude input files from mangling
8eda14cbcSMatt Macy%global __brp_mangle_shebangs_exclude_from ^/usr/src/.*$
9eda14cbcSMatt Macy
10eda14cbcSMatt Macy%define module  @PACKAGE@
11eda14cbcSMatt Macy%define mkconf  scripts/dkms.mkconf
12eda14cbcSMatt Macy
13eda14cbcSMatt MacyName:           %{module}-dkms
14eda14cbcSMatt Macy
15eda14cbcSMatt MacyVersion:        @VERSION@
16eda14cbcSMatt MacyRelease:        @RELEASE@%{?dist}
17eda14cbcSMatt MacySummary:        Kernel module(s) (dkms)
18eda14cbcSMatt Macy
19eda14cbcSMatt MacyGroup:          System Environment/Kernel
20eda14cbcSMatt MacyLicense:        @ZFS_META_LICENSE@
21180f8225SMatt MacyURL:            https://github.com/openzfs/zfs
22eda14cbcSMatt MacySource0:        %{module}-%{version}.tar.gz
23eda14cbcSMatt MacyBuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
24eda14cbcSMatt MacyBuildArch:      noarch
25eda14cbcSMatt Macy
26eda14cbcSMatt MacyRequires:       dkms >= 2.2.0.3
2714c2e0a0SMartin MatuskaRequires(pre):  dkms >= 2.2.0.3
28681ce946SMartin MatuskaRequires(post): dkms >= 2.2.0.3
29681ce946SMartin MatuskaRequires(preun): dkms >= 2.2.0.3
30eda14cbcSMatt MacyRequires:       gcc, make, perl, diffutils
31681ce946SMartin MatuskaRequires(post): gcc, make, perl, diffutils
32bb2d13b6SMartin Matuska%if 0%{?rhel}%{?fedora}%{?mageia}%{?suse_version}%{?openEuler}
3316038816SMartin MatuskaRequires:       kernel-devel >= @ZFS_META_KVER_MIN@, kernel-devel <= @ZFS_META_KVER_MAX@.999
34681ce946SMartin MatuskaRequires(post): kernel-devel >= @ZFS_META_KVER_MIN@, kernel-devel <= @ZFS_META_KVER_MAX@.999
35*718519f4SMartin MatuskaConflicts:      kernel-devel < @ZFS_META_KVER_MIN@, kernel-devel > @ZFS_META_KVER_MAX@.999
36271171e0SMartin MatuskaObsoletes:      spl-dkms <= %{version}
37eda14cbcSMatt Macy%endif
38eda14cbcSMatt MacyProvides:       %{module}-kmod = %{version}
39eda14cbcSMatt MacyAutoReqProv:    no
40eda14cbcSMatt Macy
41bb2d13b6SMartin Matuska%if (0%{?fedora}%{?suse_version}%{?openEuler}) || (0%{?rhel} && 0%{?rhel} < 9)
423ff01b23SMartin Matuska# We don't directly use it, but if this isn't installed, rpmbuild as root can
433ff01b23SMartin Matuska# crash+corrupt rpmdb
443ff01b23SMartin Matuska# See issue #12071
453ff01b23SMartin MatuskaBuildRequires:  ncompress
463ff01b23SMartin Matuska%endif
473ff01b23SMartin Matuska
48eda14cbcSMatt Macy%description
49eda14cbcSMatt MacyThis package contains the dkms ZFS kernel modules.
50eda14cbcSMatt Macy
51eda14cbcSMatt Macy%prep
52eda14cbcSMatt Macy%setup -q -n %{module}-%{version}
53eda14cbcSMatt Macy
54eda14cbcSMatt Macy%build
55eda14cbcSMatt Macy%{mkconf} -n %{module} -v %{version} -f dkms.conf
56eda14cbcSMatt Macy
57eda14cbcSMatt Macy%install
58eda14cbcSMatt Macyif [ "$RPM_BUILD_ROOT" != "/" ]; then
59eda14cbcSMatt Macy    rm -rf $RPM_BUILD_ROOT
60eda14cbcSMatt Macyfi
61eda14cbcSMatt Macymkdir -p $RPM_BUILD_ROOT/usr/src/
62eda14cbcSMatt Macycp -rf ${RPM_BUILD_DIR}/%{module}-%{version} $RPM_BUILD_ROOT/usr/src/
63eda14cbcSMatt Macy
64eda14cbcSMatt Macy%clean
65eda14cbcSMatt Macyif [ "$RPM_BUILD_ROOT" != "/" ]; then
66eda14cbcSMatt Macy    rm -rf $RPM_BUILD_ROOT
67eda14cbcSMatt Macyfi
68eda14cbcSMatt Macy
69eda14cbcSMatt Macy%files
70eda14cbcSMatt Macy%defattr(-,root,root)
71eda14cbcSMatt Macy/usr/src/%{module}-%{version}
72eda14cbcSMatt Macy
7314c2e0a0SMartin Matuska%pre
7414c2e0a0SMartin Matuskaecho "Running pre installation script: $0. Parameters: $*"
7514c2e0a0SMartin Matuska# We don't want any other versions lingering around in dkms.
7614c2e0a0SMartin Matuska# Tests with 'dnf' showed that in case of reinstall, or upgrade
7714c2e0a0SMartin Matuska#  the preun scriptlet removed the version we are trying to install.
7814c2e0a0SMartin Matuska# Because of this, find all zfs dkms sources in /var/lib/dkms and
7914c2e0a0SMartin Matuska#  remove them, if we find a matching version in dkms.
80eda14cbcSMatt Macy
8114c2e0a0SMartin Matuskadkms_root=/var/lib/dkms
8214c2e0a0SMartin Matuskaif [ -d ${dkms_root}/%{module} ]; then
8314c2e0a0SMartin Matuska    cd ${dkms_root}/%{module}
8414c2e0a0SMartin Matuska    for x in [[:digit:]]*; do
8514c2e0a0SMartin Matuska        [ -d "$x" ] || continue
8614c2e0a0SMartin Matuska        otherver="$x"
8714c2e0a0SMartin Matuska        opath="${dkms_root}/%{module}/${otherver}"
8814c2e0a0SMartin Matuska        if [ "$otherver" != %{version} ]; then
8914c2e0a0SMartin Matuska            # This is a workaround for a broken 'dkms status', we caused in a previous version.
9014c2e0a0SMartin Matuska            # One day it might be not needed anymore, but it does not hurt to keep it.
9114c2e0a0SMartin Matuska            if dkms status -m %{module} -v "$otherver" 2>&1 | grep "${opath}/source/dkms.conf does not exist"
9214c2e0a0SMartin Matuska            then
9314c2e0a0SMartin Matuska                echo "ERROR: dkms status is broken!" >&2
9414c2e0a0SMartin Matuska                if [ -L "${opath}/source" -a ! -d "${opath}/source" ]
9514c2e0a0SMartin Matuska                then
9614c2e0a0SMartin Matuska                    echo "Trying to fix it by removing the symlink: ${opath}/source" >&2
9714c2e0a0SMartin Matuska                    echo "You should manually remove ${opath}" >&2
9814c2e0a0SMartin Matuska                    rm -f "${opath}/source" || echo "Removal failed!" >&2
9914c2e0a0SMartin Matuska                fi
10014c2e0a0SMartin Matuska            fi
10114c2e0a0SMartin Matuska            if [ `dkms status -m %{module} -v "$otherver" | grep -c %{module}` -gt 0 ]; then
10214c2e0a0SMartin Matuska                echo "Removing old %{module} dkms modules version $otherver from all kernels."
10314c2e0a0SMartin Matuska                dkms remove -m %{module} -v "$otherver" --all ||:
10414c2e0a0SMartin Matuska            fi
10514c2e0a0SMartin Matuska        fi
10614c2e0a0SMartin Matuska    done
1072276e539SMartin Matuska    cd ${dkms_root}
10814c2e0a0SMartin Matuskafi
10914c2e0a0SMartin Matuska
11014c2e0a0SMartin Matuska# Uninstall this version of zfs dkms modules before installation of the package.
11114c2e0a0SMartin Matuskaif [ `dkms status -m %{module} -v %{version} | grep -c %{module}` -gt 0 ]; then
11214c2e0a0SMartin Matuska    echo "Removing %{module} dkms modules version %{version} from all kernels."
11314c2e0a0SMartin Matuska    dkms remove -m %{module} -v %{version} --all ||:
11414c2e0a0SMartin Matuskafi
11514c2e0a0SMartin Matuska
11614c2e0a0SMartin Matuska%post
11714c2e0a0SMartin Matuskaecho "Running post installation script: $0. Parameters: $*"
11814c2e0a0SMartin Matuska# Add the module to dkms, as reccommended in the dkms man page.
11914c2e0a0SMartin Matuska# This is generally rpm specfic.
12014c2e0a0SMartin Matuska# But this also may help, if we have a broken 'dkms status'.
12114c2e0a0SMartin Matuska# Because, if the sources are available and only the symlink pointing
12214c2e0a0SMartin Matuska#  to them is missing, this will resolve the situation
12314c2e0a0SMartin Matuskaecho "Adding %{module} dkms modules version %{version} to dkms."
12414c2e0a0SMartin Matuskadkms add -m %{module} -v %{version} %{!?not_rpm:--rpm_safe_upgrade} ||:
12514c2e0a0SMartin Matuska
12614c2e0a0SMartin Matuska# After installing the package, dkms install this zfs version for the current kernel.
12714c2e0a0SMartin Matuska# Force the overwriting of old modules to avoid diff warnings in dkms status.
12814c2e0a0SMartin Matuska# Or in case of a downgrade to overwrite newer versions.
12914c2e0a0SMartin Matuska# Or if some other backed up versions have been restored before.
13014c2e0a0SMartin Matuskaecho "Installing %{module} dkms modules version %{version} for the current kernel."
13114c2e0a0SMartin Matuskadkms install --force -m %{module} -v %{version} ||:
13214c2e0a0SMartin Matuska
13314c2e0a0SMartin Matuska%preun
13414c2e0a0SMartin Matuskadkms_root="/var/lib/dkms/%{module}/%{version}"
13514c2e0a0SMartin Matuskaecho "Running pre uninstall script: $0. Parameters: $*"
13614c2e0a0SMartin Matuska# In case of upgrade we do nothing. See above comment in pre hook.
13714c2e0a0SMartin Matuskaif [ "$1" = "1" -o "$1" = "upgrade" ] ; then
13814c2e0a0SMartin Matuska    echo "This is an upgrade. Skipping pre uninstall action."
13914c2e0a0SMartin Matuska    exit 0
14014c2e0a0SMartin Matuskafi
14114c2e0a0SMartin Matuska
14214c2e0a0SMartin Matuska# Check if we uninstall the package. In that case remove the dkms modules.
14314c2e0a0SMartin Matuska# '0' is the value for the first parameter for rpm packages.
14414c2e0a0SMartin Matuska# 'remove' or 'purge' are the possible names for deb packages.
14514c2e0a0SMartin Matuskaif [ "$1" = "0" -o "$1" = "remove" -o "$1" = "purge" ] ; then
14614c2e0a0SMartin Matuska    if [ `dkms status -m %{module} -v %{version} | grep -c %{module}` -gt 0 ]; then
14714c2e0a0SMartin Matuska        echo "Removing %{module} dkms modules version %{version} from all kernels."
14814c2e0a0SMartin Matuska        dkms remove -m %{module} -v %{version} --all %{!?not_rpm:--rpm_safe_upgrade} && exit 0
14914c2e0a0SMartin Matuska    fi
15014c2e0a0SMartin Matuska    # If removing the modules failed, it might be because of the broken 'dkms status'.
15114c2e0a0SMartin Matuska    if dkms status -m %{module} -v %{version} 2>&1 | grep "${dkms_root}/source/dkms.conf does not exist"
15214c2e0a0SMartin Matuska    then
15314c2e0a0SMartin Matuska        echo "ERROR: dkms status is broken!" >&2
15414c2e0a0SMartin Matuska        echo "You should manually remove ${dkms_root}" >&2
15514c2e0a0SMartin Matuska        echo "WARNING: installed modules in /lib/modules/`uname -r`/extra could not be removed automatically!" >&2
15614c2e0a0SMartin Matuska    fi
15714c2e0a0SMartin Matuskaelse
15814c2e0a0SMartin Matuska    echo "Script parameter $1 did not match any removal condition."
15914c2e0a0SMartin Matuskafi
16014c2e0a0SMartin Matuska
16114c2e0a0SMartin Matuskaexit 0
162da5137abSMartin Matuska
163