File SABnzbd.spec of Package SABnzbd

#
# spec file for package SABnzbd
#
# Copyright (c) 2020 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/
#


# See also http://en.opensuse.org/openSUSE:Specfile_guidelines
%if 0%{?suse_version} < 1500
%define _fillupdir %{_localstatedir}/adm/fillup-templates
%endif

Name:           SABnzbd
Version:        4.x
Release:        0
Summary:        Open-source cross-platform binary newsreader
License:        GPL-2.0-only
Group:          Productivity/Networking/News/Clients
URL:            http://wiki.sabnzbd.org/
Source:         %{name}-%{version}.tar.xz
Source1:        %{name}.service.in
Source2:        %{name}.sysconfig.in
Source3:        %{name}-tmpfiles.conf.in
Source4:        %{name}.ini.in
Source5:        %{name}.desktop
Source6:        %{name}.png
Source7:        %{name}.sh
BuildRequires:  coreutils
BuildRequires:  fdupes
BuildRequires:  python313
BuildRequires:  systemd-rpm-macros
BuildRequires:  apache-rpm-macros
BuildRequires:  python-rpm-macros
BuildRequires:  xz
BuildRequires:  update-desktop-files
Requires:       dbus-1-python3
Requires:       par2cmdline-turbo
Requires:       python313-gobject >= 3.10.2
Requires:       python313-Cheetah3 >= 3.0.0
Requires:       python313-chardet
Requires:       python313-cheroot
Requires:       python313-CherryPy
Requires:       python313-configobj
Requires:       python313-cryptography
Requires:       python313-feedparser >= 6.0.0
Requires:       python313-notify2
Requires:       python313-portend
Requires:       python313-sabctools
Requires:       python313-puremagic
Requires:       python313-guessit
Requires:       python313-setuptools
Requires:       python313-python-socks
Requires:       python313-apprise
Requires:       python313-PySocks
Obsoletes:      python3-Cheetah3
Requires:       unrar
Requires:       unzip
Requires:       p7zip-full
Requires:       user(wwwrun)
Obsoletes:      python-sabyenc3
Requires(postun): %{_sbindir}/groupdel
Requires(postun): %{_sbindir}/userdel
Requires(pre):  %{_bindir}/getent
Requires(pre):  %{_sbindir}/useradd
BuildArch:      noarch
%{?systemd_requires}

%description
SABnzbd is an open-source cross-platform binary newsreader.
It simplifies the process of downloading from Usenet dramatically,
thanks to its friendly web-based user interface and advanced
built-in post-processing options that automatically verify, repair,
extract and clean up posts downloaded from Usenet.
SABnzbd also has a fully customizable user interface,
and offers a complete API for third-party applications to hook into.

%prep
%setup -q -n %{name}-%{version}

%build
export PYTHON="%_bindir/python3.13"
# fix executable python files
find . -type f -name '*.py' -exec sed -i -e 's|/usr/bin/env python3|/usr/bin/python3.13|g' {} \;
find . -type f -name '*.py' -exec sed -i -e 's|/usr/bin/env python|/usr/bin/python3.13|g' {} \;
sed -i 's|/usr/bin/python3|/usr/bin/python3.12|' SABnzbd.py 
find . -type f -name '*.py' -exec grep -l -i %{_bindir}/python3.13 '{}' \; -exec chmod 0755 '{}' \;
find . -type f -name '*.py' -exec grep -l -i %{_bindir}/env '{}' \; -exec chmod 0755 '{}' \;


# Create translation files
$PYTHON tools/make_mo.py

%install
mkdir -p %{buildroot}%{_sysconfdir}/%{name}
mkdir -p %{buildroot}%{_datadir}/%{name}
mkdir -p %{buildroot}%{_sharedstatedir}/%{name}
mkdir -p %{buildroot}%{_sharedstatedir}/%{name}/Downloads/incomplete
mkdir -p %{buildroot}%{_sharedstatedir}/%{name}/Downloads/complete
mkdir -p %{buildroot}%{_localstatedir}/log/%{name}
cp -rp *.py email icons interfaces locale po sabnzbd scripts tools \
   %{buildroot}%{_datadir}/%{name}
chmod -x %{buildroot}%{_datadir}/%{name}/interfaces/Glitter/templates/static/javascripts/*.js
chmod -x %{buildroot}%{_datadir}/%{name}/interfaces/Glitter/templates/static/javascripts/momentjs_locale/*.js

install -dm700 %{buildroot}%{_sharedstatedir}/%{name}

# Install systemd service
install -dm755 %{buildroot}%{_unitdir}/
sed \
    -e 's:@SABNZBD_HOME@:%{_datadir}/%{name}:g' \
    -e 's:@SABNZBD_USER@:wwwrun:g' \
    -e 's:@SABNZBD_GROUP@:www:g' \
    %{SOURCE1} >%{buildroot}%{_unitdir}/%{name}.service
chmod 0644 %{buildroot}%{_unitdir}/%{name}.service
install -d -m0755 %{buildroot}/%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}/%{_sbindir}/rc%{name}

# Install sysconfig file
install -dm755 %{buildroot}%{_fillupdir}/
sed \
    -e 's:@SABNZBD_HOME@:%{_datadir}/%{name}:g'  \
    -e 's:@SABNZBD_CONFIG@:%{_sysconfdir}/%{name}/%{name}.ini:g'  \
    -e 's:@USER@:wwwrun:g' \
    -e 's:@GROUP@:www:g' \
    %{SOURCE2} >%{buildroot}%{_fillupdir}/sysconfig.%{name}
chmod 0644 %{buildroot}%{_fillupdir}/sysconfig.%{name}

# Install dir /run/SABnzbd
install -d -m 0755 %{buildroot}%{_prefix}/lib/tmpfiles.d/
install -m 0644 %{SOURCE3} %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf
sed -i \
    -e 's:@USER@:wwwrun:g' \
    -e 's:@GROUP@:www:g' \
    -e 's:@RUNDIR@:/run/%{name}:g' \
    %{buildroot}%{_prefix}/lib/tmpfiles.d/%{name}.conf

# Install sabnzbd.ini file
sed \
    -e 's:@SABNZBD_LOG_DIR@:%{_localstatedir}/log/%{name}:g'  \
    -e 's:@SABNZBD_DOWNLOAD_DIR@:%{_sharedstatedir}/%{name}/Downloads/incomplete:g'  \
    -e 's:@SABNZBD_COMPLETE_DIR@:%{_sharedstatedir}/%{name}/Downloads/complete:g'  \
    %{SOURCE4} >%{buildroot}%{_sysconfdir}/%{name}/%{name}.ini

# Remove empty files that aren't module markers
find %{buildroot} -type f -empty \! -name '__init__.py' -delete

# Install desktop menu
mkdir -p %{buildroot}%{_bindir}
install -D -m 0755 %{SOURCE7} %{buildroot}/%{_bindir}/%{name}
mkdir -p %{buildroot}%{_datadir}/pixmaps/
install -D -m 0644 %{SOURCE6} %{buildroot}%{_datadir}/pixmaps/
mkdir -p %{buildroot}%{_datadir}/applications/
install -D -m 0644 %{SOURCE5} %{buildroot}%{_datadir}/applications/

%fdupes %{buildroot}/%{_datadir}/%{name}
%find_lang %{name}

%pre
%service_add_pre SABnzbd.service

%post
# create /var/run/SABnzbd
%if 0%{?suse_version} <= 1320
systemd-tmpfiles --create %{_prefix}/lib/tmpfiles.d/%{name}.conf
%else
%tmpfiles_create %{_prefix}/lib/tmpfiles.d/%{name}.conf
%endif
#
%if 0%{?suse_version} >= 1210
%{fillup_only -n SABnzbd }
%service_add_post SABnzbd.service
%else
%if 0%{?suse_version}
%fillup_and_insserv SABnzbd
%else
/sbin/chkconfig --add SABnzbd
%endif
%endif

%preun
%service_del_preun SABnzbd.service
%stop_on_removal SABnzbd.service

%postun
%service_del_postun SABnzbd.service

%files -f %{name}.lang
%license licenses/
%license COPYRIGHT.txt GPL2.txt GPL3.txt LICENSE.txt
%doc ISSUES.txt README.md
%dir %{_prefix}/lib/tmpfiles.d/
%dir %attr(775,root,%{apache_group}) %{_localstatedir}/log/%{name}
%dir %attr(775,root,%{apache_group}) %{_sharedstatedir}/%{name}
%dir %attr(775,root,%{apache_group}) %{_sysconfdir}/%{name}
%dir %attr(775,root,%{apache_group}) %{_datadir}/%{name}
%{_datadir}/%{name}
%{_sysconfdir}/%{name}
%{_unitdir}/%{name}.service
%{_sbindir}/rc%{name}
%config %{_fillupdir}/sysconfig.%{name}
%config(noreplace) %attr(664,%{apache_user},%{apache_group}) %{_sysconfdir}/%{name}/%{name}.ini
%{_prefix}/lib/tmpfiles.d/%{name}.conf
%{_datadir}/pixmaps/%{name}.png
%{_datadir}/applications/%{name}.desktop
%{_bindir}/%{name}
%ghost /run/%{name}

%changelog
openSUSE Build Service is sponsored by