File pi-hole.spec of Package pi-hole

#
# 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/
#

# TODO: There is systemd service to use /etc/pihole/logrotate file, but probably it should just be copied to /etc/logrotate.d?

Name:           pi-hole
Version:        6.4.2
%define         real_name pihole
#%%define         real_version 5.2.1
%define         real_version %(echo "%{version}" | sed -r 's/v(.*)/\\1/')
%define         real_nameversion %{name}-%{real_version}
Release:        0
Summary:        A black hole for Internet advertisements
License:        EUPL-1.1
# TODO: check what group would be better
Group:          Productivity/Networking/Other
Url:            https://pi-hole.net/
Source0:        %{name}-%{version}.tar.gz
Source1:        %{name}-logrotate.service
Source2:        %{name}-logrotate.timer
Source3:        %{name}-updategravity.service
Source4:        %{name}-updategravity.timer
Source5:        system-user-%{real_name}.conf
# Instead of generating the config with basic-install.sh, just allow user to configure it as needed.
Source6:        setupVars.conf
# The adlists.list file is created from basic-install.sh script
Source7:        adlists.list
# dns-servers.conf seems to be needed at least by AdminLTE, for configuration.
Source8:        dns-servers.conf
Source9:        sysconfig.pihole
Source10:       config.pihole.rb
Source11:       dnsmasq.conf
#PATCH-FIX-OPENSUSE pihole-script-cleanups.patch -- Various fixes for the bash scripts for use in openSUSE.
Patch0:         %{real_name}-script-cleanups.patch
#PATCH-FIX-OPENSUSE pihole-disable-features.patch -- Disable pihole features: reconfigure, admin, update, uninstall and checkout.
Patch1:         %{real_name}-disable-features.patch
# NOTE: This probably isn’t necessary any more, but keeping here just in case.
#Patch6:         disable-sudo-need.patch
Patch9:         gravity_database.patch
BuildRequires:  sysuser-tools
# gravity.sh database.
Requires:       sqlite3
Requires(post): %fillup_prereq
Requires:       user(%{real_name})
# TODO: add requires for group too?
BuildRoot:      %{_tmppath}/%{name}-%{real_version}-build
BuildArch:      noarch

%description
The Pi-hole® is a DNS sinkhole that protects your devices from unwanted content, without installing any client-side software.

* Easy-to-install: our versatile installer walks you through the process, and takes less than ten minutes
* Resolute: content is blocked in non-browser locations, such as ad-laden mobile apps and smart TVs
* Responsive: seamlessly speeds up the feel of everyday browsing by caching DNS queries
* Lightweight: runs smoothly with minimal hardware and software requirements
* Robust: a command line interface that is quality assured for interoperability
* Insightful: a beautiful responsive Web Interface dashboard to view and control your Pi-hole
* Versatile: can optionally function as a DHCP server, ensuring all your devices are protected automatically
* Scalable: capable of handling hundreds of millions of queries when installed on server-grade hardware
* Modern: blocks ads over both IPv4 and IPv6
* Free: open source software which helps ensure you are the sole person in control of your privacy

%package -n system-user-%{real_name}
Summary:        System user and group %{real_name}
%if %{with systemd}
%{?sysusers_requires}
%endif

%description -n system-user-%{real_name}
System user and group used by pi-hole

%prep
%setup -q -n %{real_nameversion}
%patch -P 0 -p1
%patch -P 1 -p1
#%%patch -P 6 -p1
%patch -P 9 -p1

# Have logs in /var/log/pihole dir.
#sed -i "s|log-facility=/var/log/pihole.log|log-facility=/var/log/pihole/dnsmasq.log|" advanced/01-%%{real_name}.conf
sed -i "s|/var/log/pihole.log|/var/log/pihole/dnsmasq.log|" advanced/Templates/logrotate
sed -i "s|/var/log/pihole-FTL.log|/var/log/pihole/pihole-FTL.log|" advanced/Templates/logrotate

sed -i "s|#!/usr/bin/env bash|#!/bin/bash|" pihole

sed -i "s|#!/usr/bin/env sh|#!/bin/sh|" advanced/Scripts/utils.sh

%build
%sysusers_generate_pre %{SOURCE5} %{real_name}

%pre -n system-user-%{real_name} -f %{real_name}.pre

%pre
%service_add_pre pi-hole-logrotate.service pi-hole-updategravity.service

%post
%fillup_only -n pihole

%service_add_post pi-hole-logrotate.service pi-hole-updategravity.service

%preun
%service_del_preun pi-hole-logrotate.service pi-hole-updategravity.service

%postun
%service_del_postun pi-hole-logrotate.service pi-hole-updategravity.service

%install

# Manual install of Pi-hole scripts, configs and man pages
install -Dm0755 %{real_name} %{buildroot}%{_bindir}/%{real_name}
install -Dm0755 %{S:10} %{buildroot}%{_bindir}/config.%{real_name}

mkdir -p %{buildroot}%{_datadir}/%{name}
install -Dm0644 advanced/Scripts/COL_TABLE %{buildroot}%{_datadir}/%{name}/COL_TABLE
install -Dm0755 gravity.sh %{buildroot}%{_datadir}/%{name}/gravity.sh
install -Dm0755 advanced/Scripts/list.sh %{buildroot}%{_datadir}/%{name}/list.sh
install -Dm0755 advanced/Scripts/%{real_name}Debug.sh %{buildroot}%{_datadir}/%{name}/%{real_name}Debug.sh
install -Dm0755 advanced/Scripts/%{real_name}LogFlush.sh %{buildroot}%{_datadir}/%{name}/%{real_name}LogFlush.sh
install -Dm0755 advanced/Scripts/query.sh %{buildroot}%{_datadir}/%{name}/query.sh
install -Dm0755 advanced/Scripts/utils.sh %{buildroot}%{_datadir}/%{name}/utils.sh
#install -Dm0644 advanced/01-%%{real_name}.conf %%{buildroot}%%{_sysconfdir}/dnsmasq.d/01-%%{real_name}.conf
install -Dm0644 advanced/Templates/logrotate %{buildroot}%{_sysconfdir}/%{real_name}/logrotate

install -d m0755 %{buildroot}%{_datadir}/%{name}/database_migration/gravity
install -d m0755 %{buildroot}%{_datadir}/%{name}/database_migration/templates
install -Dm0755 advanced/Scripts/database_migration/gravity-db.sh %{buildroot}%{_datadir}/%{name}/database_migration/gravity-db.sh
install -Dm0644 advanced/Scripts/database_migration/gravity/*.sql %{buildroot}%{_datadir}/%{name}/database_migration/gravity/
install -Dm0644 advanced/Templates/*.sql %{buildroot}%{_datadir}/%{name}/database_migration/templates/

# Install man pages
install -Dm0644 manpages/%{real_name}.8 %{buildroot}%{_mandir}/man8/%{real_name}.8%{?ext_man}

# openSUSE/SUSE specific files
install -Dm0644 %{S:6} %{buildroot}%{_sysconfdir}/%{real_name}/setupVars.conf

# Install advertisement list Url file
install -Dm0644 %{S:7} %{buildroot}%{_sysconfdir}/%{real_name}/adlists.list
install -Dm0644 %{S:8} %{buildroot}%{_sysconfdir}/%{real_name}/dns-servers.conf
install -Dm0644 %{S:11} %{buildroot}%{_sysconfdir}/dnsmasq.conf

# Install logrotate systemd service and timer
install -Dm0644 %{S:1} %{buildroot}%{_unitdir}/pi-hole-logrotate.service
install -Dm0644 %{S:2} %{buildroot}%{_unitdir}/pi-hole-logrotate.timer

# Install Ad list update systemd service and timer
install -Dm0644 %{S:3} %{buildroot}%{_unitdir}/pi-hole-updategravity.service
install -Dm0644 %{S:4} %{buildroot}%{_unitdir}/pi-hole-updategravity.timer

mkdir -p %{buildroot}%{_sysusersdir}
install -m 644 %{S:5} %{buildroot}%{_sysusersdir}/system-user-%{real_name}.conf

install -Dm0644 %{S:9} %{buildroot}%{_fillupdir}/sysconfig.pihole

# SUSE policy wants to have this symlink.
install -d -m 0755 %{buildroot}/%{_sbindir}
ln -s service %{buildroot}/%{_sbindir}/rc%{name}-logrotate
ln -s service %{buildroot}/%{_sbindir}/rc%{name}-updategravity

%files
%defattr(-,root,root,-)

%doc CONTRIBUTING.md
%license LICENSE

%{_unitdir}/pi-hole-logrotate.service
%{_unitdir}/pi-hole-logrotate.timer
%{_unitdir}/pi-hole-updategravity.service
%{_unitdir}/pi-hole-updategravity.timer

#%%dir %%{_sysconfdir}/dnsmasq.d
#%%config(noreplace) %%{_sysconfdir}/dnsmasq.d/01-%%{real_name}.conf
%config(noreplace) %{_sysconfdir}/dnsmasq.conf
%attr(0775, pihole, pihole) %dir %{_sysconfdir}/%{real_name}/
%config(noreplace) %{_sysconfdir}/%{real_name}/adlists.list
%config(noreplace) %{_sysconfdir}/%{real_name}/dns-servers.conf
%config(noreplace) %{_sysconfdir}/%{real_name}/setupVars.conf
%config(noreplace) %{_sysconfdir}/%{real_name}/logrotate

%{_bindir}/%{real_name}
%{_bindir}/config.%{real_name}

%{_mandir}/man8/%{real_name}.8%{?ext_man}

%{_datadir}/%{name}

%{_fillupdir}/sysconfig.pihole

%{_sbindir}/rc%{name}-logrotate
%{_sbindir}/rc%{name}-updategravity

%files -n system-user-%{real_name}
%defattr(-,root,root)
%{_sysusersdir}/system-user-%{real_name}.conf

%changelog