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
%{?sle15_python_module_pythons}
Name:           SABnzbd
Version:        4.4.1
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:         https://github.com/sabnzbd/sabnzbd/archive/%{version}.tar.gz
Source1:        %{name}.service.in
Source2:        %{name}.sysconfig.in
Source3:        %{name}-tmpfiles.conf.in
Source4:        %{name}.ini.in
BuildRequires:  coreutils
BuildRequires:  fdupes
BuildRequires:  %{python_module base >= 3.8}
BuildRequires:  systemd-rpm-macros
BuildRequires:  apache-rpm-macros
Requires:       dbus-1-python3
###Requires:        python3-Cheetah
###Requires:        python3-pyOpenSSL
###Requires:        python3-yenc
Requires:       par2cmdline
Requires:       python >= 3.8
Requires:       python-gobject >= 3.10.2
Requires:       python-Cheetah3 >= 3.0.0
Requires:       python-chardet
Requires:       python-cheroot < 8.4.3
Requires:       python-CherryPy
Requires:       python-configobj
Requires:       python-cryptography
Requires:       python-feedparser >= 6.0.0
Requires:       python-notify2
Requires:       python-portend
Requires:       python-sabyenc3 >= 4.0.0
Requires:       unzip
Recommends:     unrar
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 sabnzbd-%{version}

%build
# fix executable python files
find . -type f -name '*.py' -exec sed -i -e 's|\/usr\/bin\/python3|\/usr\/bin\/python%python_bin_suffix|g' {} \;
find . -type f -name '*.py' -exec sed -i -e 's|\/usr\/bin\/env python3|\/usr\/bin\/python%python_bin_suffix|g' {} \;
find . -type f -name '*.py' -exec sed -i -e 's|\/usr\/bin\/env python|\/usr\/bin\/python%python_bin_suffix|g' {} \;
find . -type f -name '*.py' -exec grep -l -i %{_bindir}/python3 '{}' \; -exec chmod 0755 '{}' \;
find . -type f -name '*.py' -exec grep -l -i %{_bindir}/env '{}' \; -exec chmod 0755 '{}' \;
# Create translation files
python%python_bin_suffix 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 /var/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@:%{_localstatedir}/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

%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

%postun
%service_del_postun SABnzbd.service

# we don't mark init.txt as a config file because
# the script copies that version to the local user's dir
%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
#%%ghost %%attr(700,%%{wwwrun},%%{www}) %%verify(not user group) /var/run/%%{name}
%{_prefix}/lib/tmpfiles.d/%{name}.conf

%changelog
openSUSE Build Service is sponsored by