File pi-hole-ftl.spec of Package pi-hole-ftl

#
# spec file for package pi-hole-ftl
#
# Copyright (c) 2020 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#

# This package has used https://build.opensuse.org/package/show/home:alarrosa:branches:home:malcolmlewis:SLES12-SP2-RPI-Extra/pihole as a guide.

Name:           pi-hole-ftl
Version:        5.25.2
Release:        1.1
Summary:        Network-wide ad blocking via your own Linux hardware
License:        EUPL-1.1
Group:          System/Management
Url:            https://pi-hole.net/
# https://github.com/pi-hole/FTL
Source0:        FTL-%{version}.tar.gz
Source1:        pihole-ftl.service
Source2:        pihole-FTL.conf.in
Source3:        permissions
Source4:        rpmlintrc
Source6:        override.conf
Patch1:         001_%{name}_fix_warnings_as_errors.patch
Patch2:         002_%{name}_fix_shared_libraries.patch
Patch3:         003_%{name}_version.patch 
BuildRequires:  cmake
BuildRequires:  libnettle-devel
BuildRequires:  libidn-devel
BuildRequires:  readline-devel
BuildRequires:  sqlite3-devel
BuildRequires:  gmp-devel
BuildRequires:  systemd-rpm-macros
BuildRequires:  xz
# Does not work: systemctl - command not found :-(
BuildRequires:  -post-build-checks
PreReq:         permissions
Requires:       pi-hole
Requires:       user(pihole) group(pihole)
Requires:       group(www)
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
%systemd_requires

%description
FTLDNS™ (pihole-FTL) provides an interactive API and also generates statistics for Pi-hole®'s Web interface.

* Fast: stats are read directly from memory by coupling our codebase closely with dnsmasq
* Versatile: upstream changes to dnsmasq can quickly be merged in without much conflict
* Lightweight: runs smoothly with minimal hardware and software requirements such as Raspberry Pi Zero
* Interactive: our API can be used to interface with your projects
* Insightful: stats normally reserved inside of dnsmasq are made available so you can see what's really happening on your network

%prep
%autosetup -p1 -n FTL-%{version}

# Remove comments from pihole-FTL.conf to cause pihole bash script behave properly.
sed "/^;/d" %{S:2} > pihole-FTL.conf

%build
%cmake

%cmake_build

%install
%cmake_install

install -D -m 0644 %{S:1} %{buildroot}%{_unitdir}/%{name}.service
install -D -m 0644 pihole-FTL.conf %{buildroot}%{_sysconfdir}/pihole/pihole-FTL.conf
install -D -m 0644 %{S:3} %{buildroot}%{_sysconfdir}/permissions.d/%{name}

install -d -m 0775 %{buildroot}/var/log/pihole

# create tmpfile conf
install -d -m 0755 %{buildroot}/%{_tmpfilesdir}
echo "d /run/pihole 0750 pihole pihole" > %{buildroot}/%{_tmpfilesdir}/%{name}.conf

%if 0%{?suse_version} <= 1600
# SUSE policy wants to have this symlink.
install -d -m 0755 %{buildroot}/%{_sbindir}
ln -s service %{buildroot}/%{_sbindir}/rc%{name}
%endif

# Nice-Level
install -d -m 0755 %{buildroot}/%{_unitdir}/%{name}.service.d
install -m 0644 %{SOURCE6} %{buildroot}/%{_unitdir}/%{name}.service.d

%pre
%service_add_pre %{name}.service

%post
%tmpfiles_create %{_tmpfilesdir}/%{name}.conf
%service_add_post %{name}.service
%set_permissions /usr/bin/pihole-FTL 
# Systemd-resolved's DNSStubListener and dnsmasq can't share port 53.
echo "Testing if systemd-resolved is enabled"
if ( grep -E '#?DNSStubListener=yes' /etc/systemd/resolved.conf &> /dev/null ); then
  # Disable the DNSStubListener to unbind it from port 53
  # Note that this breaks dns functionality on host until dnsmasq/ftl are up and running
  echo "Disabling systemd-resolved DNSStubListener"
  # Make a backup of the original /etc/systemd/resolved.conf
  # (This will need to be restored on uninstallation)
  sed -r -i.orig 's/#?DNSStubListener=yes/DNSStubListener=no/g' /etc/systemd/resolved.conf
  echo "Restarting systemd-resolved"
  systemctl reload-or-restart systemd-resolved
else
  echo "Systemd-resolved does not need to be restarted"
fi
echo "Creating/updating pihole gravity database..."
/usr/bin/pihole -g
/bin/chown pihole:www /etc/pihole/list* && /bin/chmod 664 /etc/pihole/list*
/bin/chown pihole:www /etc/pihole/gravity*.db && /bin/chmod 664 /etc/pihole/gravity*.db
systemctl restart pi-hole-ftl

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%verifyscript
%verify_permissions -e /usr/bin/pihole-FTL

%files
%defattr(-,root,root)
%license LICENSE
%verify(not user) %attr(0755, root, root) %{_bindir}/pihole-FTL
%{_unitdir}/%{name}.service
%dir %{_unitdir}/%{name}.service.d
%{_unitdir}/%{name}.service.d/override.conf
%config %attr(0644, pihole, www) %{_sysconfdir}/pihole/pihole-FTL.conf
%attr(0775, pihole, www) %dir /var/log/pihole/
%config %{_sysconfdir}/permissions.d/pi-hole-ftl
%{_tmpfilesdir}/%{name}.conf
%if 0%{?suse_version} <= 1600
%{_sbindir}/rc%{name}
%endif

%changelog
openSUSE Build Service is sponsored by