File pihole-ftl.spec of Package pihole-ftl
#
# spec file for package pi-hole
#
# 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.
%define ftl_name FTL
%define ftl_system_name pihole-%{ftl_name}
Name: pihole-ftl
Version: 6.6.1
%define real_version %(echo "%{version}" | sed -r 's/v(.*)/\\1/')
Release: 0
Summary: Network-wide ad blocking via your own Linux hardware
License: EUPL-1.1
# TODO: check what group would be better
Group: System/Management
Url: https://pi-hole.net/
Source0: %{ftl_name}-%{version}.tar.gz
Source1: %{name}.service
Source2: %{ftl_system_name}.conf.in
Source3: permissions
Source4: rpmlintrc
Source5: SUSE.readme
Patch1: shared_libraries.patch
# TODO: Probably should be in upstream too?
#Patch2: link_against_readline.patch
Patch3: fortify_source_3.patch
BuildRequires: cmake
BuildRequires: libnettle-devel
BuildRequires: libidn2-devel
BuildRequires: libunistring-devel
BuildRequires: readline-devel
# Instead of vim, xxd is required, but it is inside vim package...
BuildRequires: vim
# Only for /etc/pihole directory ownership.
#BuildRequires: pi-hole
# I don’t remember why this was required run-time, but keeping it to be safe.
#Requires: pi-hole
#Requires(pre): user(pihole)
#Requires(pre): group(pihole)
BuildRoot: %{_tmppath}/%{ftl_name}-%{real_version}-build
%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
%setup -q -n %{ftl_name}-%{real_version}
# Need to link as shared libraries to avoid linker errors.
%patch -P 1 -p1
#%%patch -P 2 -p1
# For Tumbleweed, FORTIFY_SOURCE=3 is defined.
# Make FTL to use that too to avoid a redefinition.
# %%if 0%%{?suse_version} > 1500
# %%patch -P 3 -p1
# %%endif
# Generate own version.h; the Makefile wants to use Git to generate this data...
cat > %{_builddir}/%{ftl_name}-%{real_version}/version.h <<EOL
#define GIT_VERSION "%{version}"
#define GIT_DATE "$(date)"
#define GIT_BRANCH "master"
#define GIT_TAG "%{version}"
#define GIT_HASH ""
EOL
# Remove comments from pihole-FTL.conf to cause pihole bash script behave properly.
sed "/^;/d" %{S:2} > pihole-FTL.conf
%build
%if 0%{?suse_version} > 1500
# As of 5.10.2, malloc suggestion is causing build to fail on Tumbleweed (date: 02.10.2021).
export CFLAGS='%optflags -Wno-error=suggest-attribute=malloc'
%endif
%cmake
%cmake_build
%install
%cmake_install
install -D -m 644 %{S:1} %{buildroot}%{_unitdir}/%{name}.service
install -Dm0644 %{ftl_system_name}.conf %{buildroot}%{_sysconfdir}/pihole/%{ftl_system_name}.conf
install -D -m 0644 %{S:3} %{buildroot}%{_sysconfdir}/permissions.d/%{name}
install -D -m 0644 %{S:5} %{buildroot}%{_docdir}/%{name}/SUSE.readme
mkdir -p %{buildroot}/var/log/pihole
# create tmpfile conf
install -d -m 0755 %{buildroot}/%{_tmpfilesdir}
echo "d /run/pihole 0750 pihole pihole" > %{buildroot}/%{_tmpfilesdir}/%{name}.conf
# SUSE policy wants to have this symlink.
install -d -m 0755 %{buildroot}/%{_sbindir}
ln -s service %{buildroot}/%{_sbindir}/rc%{name}
%posttrans
echo "For new installations, please see included SUSE.readme to finish"
echo "installation of pi-hole."
echo
echo "NOTE: To run pihole-FTL, it wants to have some permissions for itself."
echo "If you have configured it already, remember to run chkstat --system"
%pre
%service_add_pre %{name}.service
%post
%tmpfiles_create %{_tmpfilesdir}/%{name}.conf
%service_add_post %{name}.service
%preun
%service_del_preun %{name}.service
%postun
%service_del_postun %{name}.service
%files
%defattr(-,root,root)
%license LICENSE
%doc SUSE.readme
%dir %{_sysconfdir}/pihole
%verify(not user) %attr(0755, root, root) %{_bindir}/%{ftl_system_name}
%{_unitdir}/%{name}.service
%config(noreplace) %attr(0644, pihole, pihole) %{_sysconfdir}/pihole/%{ftl_system_name}.conf
%attr(0775, pihole, pihole) %dir /var/log/pihole/
%config(noreplace) %{_sysconfdir}/permissions.d/pihole-ftl
%{_tmpfilesdir}/%{name}.conf
# This is suggested in a warning, but just leads to an error, “E: dir-or-file-in-run /run/pihole”
%ghost %dir /run/pihole
%{_sbindir}/rc%{name}
%changelog