%global debug_package %{nil}


%define dotnet_configuration Release
%define dotnet_framework     net8.0
%define dotnet_arch          x64
%define dotnet_runtime       linux-%{dotnet_arch}


Name:           jackett
Version:        0.22.1096
Release:        1%{?dist}
Summary:        API Support for your favorite torrent trackers
License:        GPL-2.0-only
URL:            https://github.com/Jackett/Jackett
Source0:        https://github.com/Jackett/Jackett/archive/refs/tags/v%{version}.tar.gz
Source1:        %{name}.sysusers
Source2:        %{name}.service


ExclusiveArch: x86_64


BuildRequires:  systemd-rpm-macros
BuildRequires:  dotnet-sdk-8.0


%{?systemd_requires}
%{?sysusers_requires_compat}
Requires: dotnet-runtime-8.0
Requires: aspnetcore-runtime-8.0


%description
API Support for your favorite torrent trackers.


%prep
%autosetup -n Jackett-%{version}


%build
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
pushd src
dotnet publish \
  --framework %{dotnet_framework} \
  --configuration %{dotnet_configuration} \
  --runtime %{dotnet_runtime} \
  --self-contained false \
  "--property:DebugSymbols=false;DebugType=none;Version=%{version}" \
  Jackett.Server
popd


%install
mkdir -p %{buildroot}%{_libdir}
cp -rp src/Jackett.Server/bin/%{dotnet_configuration}/%{dotnet_framework}/%{dotnet_runtime}/publish %{buildroot}%{_libdir}/jackett
chmod 644 %{buildroot}%{_libdir}/jackett/*.dll
chmod 644 %{buildroot}%{_libdir}/jackett/*.so
mkdir -p %{buildroot}%{_bindir}
tee %{buildroot}%{_bindir}/jackett << EOF
#!/usr/bin/sh
exec env DOTNET_CLI_TELEMETRY_OPTOUT=1 %{_libdir}/jackett/jackett --NoUpdates \${@}
EOF
chmod +x %{buildroot}%{_bindir}/jackett
install --preserve-timestamps --mode=0644 -D %{SOURCE1} %{buildroot}%{_sysusersdir}/jackett.conf
install --preserve-timestamps --mode=0644 -D %{SOURCE2} %{buildroot}%{_unitdir}/jackett.service
install --directory --mode=0750 %{buildroot}%{_sharedstatedir}/jackett


%check
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
pushd src
dotnet test \
  --framework %{dotnet_framework} \
  --configuration %{dotnet_configuration} \
  --runtime %{dotnet_runtime} \
  Jackett.Test
popd


%files
%doc README.md
%license LICENSE
%{_bindir}/jackett
%{_libdir}/jackett/
%{_sysusersdir}/jackett.conf
%{_unitdir}/jackett.service
%defattr(-, jackett, jackett, -)
%config %{_sharedstatedir}/jackett


%pre
%sysusers_create_compat %{SOURCE1}


%post
%systemd_post jackett.service


%preun
%systemd_preun jackett.service


%postun
%systemd_postun_with_restart jackett.service


%changelog
%autochangelog