File bcachefs-tools.spec of Package test

#
# spec file for package bcachefs-tools
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

%global pkg_name bcachefs-tools
%define modname  bcachefs

Name:           %{pkg_name}
Version:        0
Release:        0
Summary:        Configuration utilities for bcachefs
Group:          System/Filesystems
License:        GPL-2.0-or-later
URL:            https://bcachefs.org/
Source:         %{pkg_name}-%{version}.tar.xz
Source1:        vendor.tar.xz
Source98:       dkms-bcachefs.rpmlintrc
Source99:       cargo.config
BuildRequires:  cargo >= 1.77
BuildRequires:  clang-devel
BuildRequires:  jq
BuildRequires:  libaio-devel >= 0.3.111
BuildRequires:  pkg-config
BuildRequires:  zstd
BuildRequires:  pkgconfig(blkid)
BuildRequires:  pkgconfig(libkeyutils)
BuildRequires:  pkgconfig(liblz4)
BuildRequires:  pkgconfig(libsodium)
BuildRequires:  pkgconfig(libudev)
BuildRequires:  pkgconfig(liburcu) >= 0.15
BuildRequires:  pkgconfig(libzstd)
BuildRequires:  pkgconfig(udev)
BuildRequires:  pkgconfig(uuid)
BuildRequires:  pkgconfig(zlib)

%description
Bcachefs is a filesystem for Linux, with an emphasis on reliability
and robustness.

* Copy on write (COW) like zfs or btrfs
* Full data and metadata checksumming
* Multiple devices
* Replication
* Erasure coding
* Caching
* Compression
* Encryption
* Snapshots

This package contains utilities for creating and mounting bcachefs.

%package -n dkms-bcachefs
Summary:   bcachefs DKMS kernel module
Group:     System/Kernel
BuildArch: noarch
Requires:  %{pkg_name} = %{version}
Requires:  binutils
Requires:  gcc
Requires:  make
Requires(pre): dkms
Requires(posttrans): dkms
Requires(preun):  dkms
%if 0%{?mdkversion}
Requires:  dkms-minimal
%else
Requires:  dkms
%endif

%description -n dkms-bcachefs
Bcachefs DKMS kernel module

%prep
export CARGO_ARGS="--frozen"
rm -rf .cargo
mkdir -p .cargo
cp %{_sourcedir}/cargo.config .cargo/config.toml
tar -xf %{_sourcedir}/vendor.tar.xz --directory .
%autosetup -p1

%build
export CARGO_ARGS="--frozen"
%make_build PREFIX="%_prefix" ROOT_SBINDIR="%_sbindir"

%install
export CARGO_ARGS="--frozen"
%make_install PREFIX="%_prefix" ROOT_SBINDIR="%_sbindir"
%make_build install_dkms DESTDIR="%{?buildroot}" PREFIX="%_prefix" ROOT_SBINDIR="%_sbindir"
mv %{?buildroot}/%{_usrsrc}/%{modname}-* %{?buildroot}/%{_usrsrc}/%{modname}-%{version}
# this ain't no debian
rm -Rf "%buildroot/etc/initramfs-tools" "%buildroot/%_datadir/initramfs-tools"

%pre
%service_add_pre bcachefsck_all.service bcachefsck_all_fail.service

%post
%service_add_post bcachefsck_all.service bcachefsck_all_fail.service

%preun
%service_del_preun bcachefsck_all.service bcachefsck_all_fail.service

%postun
%service_del_postun bcachefsck_all.service bcachefsck_all_fail.service

%preun -n dkms-bcachefs
if [ -x %{_sbindir}/dkms ] && [ -n "`%{_sbindir}/dkms status -m %{modname} -v %{version}`" ] ; then
  %{_sbindir}/dkms remove -m %{modname} -v %{version} --all
  exit 0
fi

%posttrans -n dkms-bcachefs
if [ -x %{_sbindir}/dkms ] && [ -z "`%{_sbindir}/dkms status -m %{modname} -v %{version}`" ] ; then
  %{_sbindir}/dkms add -m %{modname} -v %{version}
fi
exit 0

%files -n bcachefs-tools
%_sbindir/*bcache*
%_unitdir/bcachefsck*
%_unitdir/system-bcachefsck*
%_libexecdir/bcachefsck*
%_udevrulesdir/64-bcachefs.rules
%_mandir/man8/*.8*
%license COPYING
%doc doc/bcachefs-principles-of-operation.tex

%files -n dkms-bcachefs
%defattr(-,root,root)
%dir %{_usrsrc}/%{modname}-%{version}
%{_usrsrc}/%{modname}-%{version}
openSUSE Build Service is sponsored by