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