File pihole.spec of Package pihole

#
# spec file for package pihole
#
# Copyright (c) 2018 Malcolm J Lewis <malcolmlewis@opensuse.org>
#
# 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/
#

%define         pihole0 pi-hole
%define         pihole0_version 20180805.ddbdb51

%define         pihole1 FTL
%define         pihole1_version 20180805.8493df4

%define         pihole_user pihole
%define         pihole_group pihole

Name:           pihole
Version:        4.0
Release:        0
License:        EUPL-1.2 and GPL-3.0+
Summary:        A black hole for Internet advertisements
Url:            https://pi-hole.net/
Group:          Productivity/Networking/Other
# pihole files pulled from git
Source0:        %{pihole0}-%{version}+%{pihole0_version}.tar.xz
# YaST alternative to /etc/pihole/setupVars.conf
Source1:        sysconfig.setupVars
# The adlists.list file is created from basic-install.sh script
Source2:        adlists.list
# Add our own conf file ponting to /etc/dnsmasq.d directory
Source3:        dnsmasq.conf
# Add our own systemd service file
Source4:        pihole-FTL.service
# Add our own script to be used with systemd file
Source5:        pihole-FTL-service
# Logrotate systemd service and timer
Source6:        pihole-logrotate.service
Source7:        pihole-logrotate.timer
# Ad list update systemd service and timer
Source8:        pihole-updateGravity.service
Source9:        pihole-updateGravity.timer
# pihole-FTL sources pulled from git
Source10:       %{pihole1}-%{version}+%{pihole1_version}.tar.xz
# The version.h file is created by the get_pihole1_from_git.sh script
Source11:       version.h
# Git helper scripts FIXME need to clean up for version numbers and not writing to changes...
Source96:       SUSE.readme
Source97:       get_pihole0_from_git.sh
Source98:       get_pihole1_from_git.sh
# Suppress benign rpmlint warnings
Source99:       pihole-rpmlintrc
#PATCH-FIX-OPENSUSE pihole0-script-cleanups.patch malcolmlewis@opensuse.org -- Various fixes for the bash scripts for use in openSUSE.
Patch0:         pihole0-script-cleanups.patch
#PATCH-FIX-OPENSUSE pihole0-disable-features.patch malcolmlewis@opensuse.org -- Disable pihole features; reconfigure, admin, update, uninstall and checkout.
Patch1:         pihole0-disable-features.patch
#PATCH-FIX-OPENSUSE pihole10-Makefile-changes.patch malcolmlewis@opensuse.org -- Fix libdir path and create our own version.h file as we manually pull from git.
Patch10:        pihole10-Makefile-changes.patch
BuildRequires:  bash-completion
BuildRequires:  dnsmasq
BuildRequires:  fdupes
BuildRequires:  libcap-progs
BuildRequires:  libnettle-devel
BuildRequires:  systemd
Requires(pre):  shadow
Requires(pre):  %fillup_prereq
Requires:       libcap-progs
Requires:       logrotate
Requires:       net-tools-deprecated
Requires:       %{name}-FTL == %{version}
Requires:       %{name}-bash-completion == %{version}
Requires:       openresolv
Requires:       psmisc
Requires:       systemd
Requires:       system-user-nobody
Requires:       yast2-sysconfig
BuildRoot:      %{_tmppath}/%{name}-%{version}-build

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

- 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 FTL
Summary:        Network-wide ad blocking via your own Linux hardware
Group:          System/Management
Requires:       %{name} == %{version}
Requires:       %{name}-bash-completion = %{version}

%description FTL
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.

%package bash-completion
Summary:        Bash Completion for %{name}
Group:          System/Management
Requires:       %{name} = %{version}
Supplements:    packageand(%{name}:bash-completion)
BuildArch:      noarch

%description bash-completion
Bash command line completion support for %{name}.

%prep
%setup -q -c
%setup -q -T -D -a 10
cp %{S:96} .
cd %{pihole0}-%{version}+%{pihole0_version}
%patch0 -p1
%patch1 -p1
cd ../%{pihole1}-%{version}+%{pihole1_version}
%patch10 -p1

%build
# Build FTL binary
cd %{pihole1}-%{version}+%{pihole1_version}
cp %{S:11} .
make LIBDIR="%{_libdir}"

%install
# Binary manual install
cd %{pihole1}-%{version}+%{pihole1_version}
install -Dm0755 pihole-FTL %{buildroot}%{_bindir}/pihole-FTL
# Manual install of pihole scripts, configs and man pages
cd ../%{pihole0}-%{version}+%{pihole0_version}
install -Dm0755 pihole %{buildroot}%{_bindir}/pihole
install -Dm0644 advanced/bash-completion/pihole %{buildroot}%{_datadir}/bash-completion/completions/pihole
mkdir -p %{buildroot}%{_datadir}/%{name}
install -Dm0644 advanced/Scripts/COL_TABLE %{buildroot}%{_datadir}/%{name}/COL_TABLE
install -Dm0755 advanced/Scripts/chronometer.sh %{buildroot}%{_datadir}/%{name}/chronometer.sh
install -Dm0755 gravity.sh %{buildroot}%{_datadir}/%{name}/gravity.sh
install -Dm0755 advanced/Scripts/list.sh %{buildroot}%{_datadir}/%{name}/list.sh
install -Dm0755 advanced/Scripts/piholeDebug.sh %{buildroot}%{_datadir}/%{name}/piholeDebug.sh
install -Dm0755 advanced/Scripts/piholeLogFlush.sh %{buildroot}%{_datadir}/%{name}/piholeLogFlush.sh
install -Dm0755 advanced/Scripts/query.sh %{buildroot}%{_datadir}/%{name}/query.sh
install -Dm0755 advanced/Scripts/wildcard_regex_converter.sh %{buildroot}%{_datadir}/%{name}/wildcard_regex_converter.sh
install -Dm0644 advanced/01-pihole.conf %{buildroot}%{_sysconfdir}/dnsmasq.d/01-pihole.conf
install -Dm0644 advanced/Templates/logrotate %{buildroot}%{_sysconfdir}/%{name}/logrotate
install -Dm0644 advanced/Templates/pihole-FTL.conf %{buildroot}%{_sysconfdir}/%{name}/pihole-FTL.conf
# Install man pages
install -Dm0644 manpages/pihole.8 %{buildroot}%{_mandir}/man8/pihole.8%{?ext_man}
install -Dm0644 manpages/pihole-FTL.8 %{buildroot}%{_mandir}/man8/pihole-FTL.8%{?ext_man}
install -Dm0644 manpages/pihole-FTL.conf.5 %{buildroot}%{_mandir}/man5/pihole-FTL.conf.5%{?ext_man}
# openSUSE/SUSE specific files
# Install sysconfig file(s)
cd ..
install -Dm0644 %{S:1} %{buildroot}%{_fillupdir}/sysconfig.setupVars
# Install advertisment list Url file
install -Dm0644 %{S:2} %{buildroot}%{_sysconfdir}/%{name}/adlists.list
install -Dm0644 %{S:3} %{buildroot}%{_sysconfdir}/dnsmasq.conf
# Install systemd service
install -Dm0644 %{S:4} %{buildroot}%{_unitdir}/pihole-FTL.service
# Install systemd service/pihole-FTL helper script
install -Dm0755 %{S:5} %{buildroot}%{_sbindir}/pihole-FTL-service
# Install logrotate systemd service and timer
install -Dm0644 %{S:6} %{buildroot}%{_unitdir}/pihole-logrotate.service
install -Dm0644 %{S:7} %{buildroot}%{_unitdir}/pihole-logrotate.timer
# Install Ad list update systemd service and timer
install -Dm0644 %{S:8} %{buildroot}%{_unitdir}/pihole-updateGravity.service
install -Dm0644 %{S:9} %{buildroot}%{_unitdir}/pihole-updateGravity.timer
pushd %{buildroot}%{_sbindir}
ln -s service rcpihole-FTL
ln -s service rcpihole-logrotate
ln -s service rcpihole-updateGravity
popd

%pre
%service_add_pre pihole-FTL.service pihole-logrotate.service pihole-logrotate.timer pihole-updateGravity.service pihole-updateGravity.timer

%post
# Add the pihole system group and system user
getent group %{pihole_group} >/dev/null 2>&1 || groupadd -r %{pihole_group}
useradd -r -g %{pihole_user} -s /usr/sbin/nologin -c "pihole user" \
        %{pihole_user} >/dev/null 2>&1 || :
# Add sysconfig file(s)
%{fillup_only -n setupVars}
%service_add_post pihole-FTL.service pihole-logrotate.service pihole-logrotate.timer pihole-updateGravity.service pihole-updateGravity.timer

%preun
%service_del_preun pihole-FTL.service pihole-logrotate.service pihole-logrotate.timer pihole-updateGravity.service pihole-updateGravity.timer

%postun
%service_del_postun pihole-FTL.service pihole-logrotate.service pihole-logrotate.timer pihole-updateGravity.service pihole-updateGravity.timer

%post FTL
# Set pihole-FTL file capabilities
setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN+eip %{_bindir}/pihole-FTL

%files
%defattr(-,root,root,-)
%doc %{pihole0}-%{version}+%{pihole0_version}/CONTRIBUTING.md
%doc SUSE.readme
%license %{pihole0}-%{version}+%{pihole0_version}/LICENSE
%{_unitdir}/pihole-FTL.service
%{_unitdir}/pihole-logrotate.service
%{_unitdir}/pihole-logrotate.timer
%{_unitdir}/pihole-updateGravity.service
%{_unitdir}/pihole-updateGravity.timer
%{_sbindir}/pihole-FTL-service
%{_sbindir}/rcpihole-FTL
%{_sbindir}/rcpihole-logrotate
%{_sbindir}/rcpihole-updateGravity
%config %{_sysconfdir}/dnsmasq.d/01-pihole.conf
%{_fillupdir}/sysconfig.setupVars
%config %{_sysconfdir}/dnsmasq.conf
%attr(0755, pihole, pihole) %dir %{_sysconfdir}/%{name}/
%config %{_sysconfdir}/%{name}/adlists.list
%config %{_sysconfdir}/%{name}/pihole-FTL.conf
%config %{_sysconfdir}/%{name}/logrotate
%{_bindir}/pihole
%{_mandir}/man8/pihole.8%{?ext_man}
%{_datadir}/%{name}

%files FTL
%defattr(-,root,root,-)
%license %{pihole1}-%{version}+%{pihole1_version}/LICENSE
%{_bindir}/pihole-FTL
%{_mandir}/man8/pihole-FTL.8%{?ext_man}
%{_mandir}/man5/pihole-FTL.conf.5%{?ext_man}

%files bash-completion
%defattr(-,root,root)
%{_datadir}/bash-completion/completions/pihole

%changelog
openSUSE Build Service is sponsored by