1%{?!packager: %define packager Brian Behlendorf <behlendorf1@llnl.gov>}
2
3%if ! 0%{?rhel}%{?fedora}%{?mageia}%{?suse_version}
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:       gcc, make, perl, diffutils
28%if 0%{?rhel}%{?fedora}%{?mageia}%{?suse_version}
29Requires:       kernel-devel
30Obsoletes:      spl-dkms
31%endif
32Provides:       %{module}-kmod = %{version}
33AutoReqProv:    no
34
35%description
36This package contains the dkms ZFS kernel modules.
37
38%prep
39%setup -q -n %{module}-%{version}
40
41%build
42%{mkconf} -n %{module} -v %{version} -f dkms.conf
43
44%install
45if [ "$RPM_BUILD_ROOT" != "/" ]; then
46    rm -rf $RPM_BUILD_ROOT
47fi
48mkdir -p $RPM_BUILD_ROOT/usr/src/
49cp -rf ${RPM_BUILD_DIR}/%{module}-%{version} $RPM_BUILD_ROOT/usr/src/
50
51%clean
52if [ "$RPM_BUILD_ROOT" != "/" ]; then
53    rm -rf $RPM_BUILD_ROOT
54fi
55
56%files
57%defattr(-,root,root)
58/usr/src/%{module}-%{version}
59
60%post
61for POSTINST in /usr/lib/dkms/common.postinst; do
62    if [ -f $POSTINST ]; then
63        $POSTINST %{module} %{version}
64        exit $?
65    fi
66    echo "WARNING: $POSTINST does not exist."
67done
68echo -e "ERROR: DKMS version is too old and %{module} was not"
69echo -e "built with legacy DKMS support."
70echo -e "You must either rebuild %{module} with legacy postinst"
71echo -e "support or upgrade DKMS to a more current version."
72exit 1
73
74%preun
75# Are we doing an upgrade?
76if [ "$1" = "1" -o "$1" = "upgrade" ] ; then
77	# Yes we are.  Are we upgrading to a new ZFS version?
78	NEWEST_VER=$(dkms status zfs | sed 's/,//g' | sort -r -V | awk '/installed/{print $2; exit}')
79	if [ "$NEWEST_VER" != "%{version}" ] ; then
80		# Yes, it's a new ZFS version.  We'll uninstall the old module
81		# later on in this script.
82		true
83	else
84		# No, it's probably an upgrade of the same ZFS version
85		# to a new distro (zfs-dkms-0.7.12.fc28->zfs-dkms-0.7.12.fc29).
86		# Don't remove our modules, since the rebuild for the new
87		# distro will automatically delete the old modules.
88		exit 0
89	fi
90fi
91
92# If we're here then we're doing an uninstall (not upgrade).
93CONFIG_H="/var/lib/dkms/%{module}/%{version}/*/*/%{module}_config.h"
94SPEC_META_ALIAS="@PACKAGE@-@VERSION@-@RELEASE@"
95DKMS_META_ALIAS=`cat $CONFIG_H 2>/dev/null |
96    awk -F'"' '/META_ALIAS\s+"/ { print $2; exit 0 }'`
97if [ "$SPEC_META_ALIAS" = "$DKMS_META_ALIAS" ]; then
98    echo -e
99    echo -e "Uninstall of %{module} module ($SPEC_META_ALIAS) beginning:"
100    dkms remove -m %{module} -v %{version} --all %{!?not_rpm:--rpm_safe_upgrade}
101fi
102exit 0
103