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: 5.18.4
Release: 1.1
Summary: A black hole for Internet advertisements
License: EUPL-1.1
Group: Productivity/Networking/Other
Url: https://pi-hole.net/
# https://github.com/pi-hole/pi-hole
Source0: %{name}-%{version}.tar.gz
Source1: %{name}-logrotate.service
Source2: %{name}-logrotate.timer
Source3: %{name}-updategravity.service
Source4: %{name}-updategravity.timer
Source5: system-user-pihole.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
Source12: pihole_unbound.conf
# https://docs.pi-hole.net/guides/dns/unbound/
Source13: 99-edns.conf
Source14: %{name}.sudo
# https://aur.archlinux.org/cgit/aur.git/tree/mimic_setupVars.conf.sh?h=pi-hole-standalone
Source16: fillup_setupVars.conf.sh
Source17: fillup_01-pihole.conf.sh
BuildRequires: sysuser-tools
BuildRequires: dnsmasq
BuildRequires: sudo
BuildRequires: user(unbound) group(unbound)
BuildRequires: user(lighttpd) group(www)
BuildRequires: xz
%if 0%{?suse_version} > 1500
BuildRequires: -post-build-checks
%endif
Requires: curl
Requires: sqlite3
Requires: bind-utils
Requires: netcat-openbsd
Requires: pi-hole-ftl
Requires: pi-hole-web
Requires: user(pihole) group(pihole)
Requires: group(www)
Requires(post): %fillup_prereq
Requires(post): iproute2
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
Recommends: pi-hole-bash-completition
%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-pihole
Summary: System user and group pihole
%if %{with systemd}
%{?sysusers_requires}
%endif
%description -n system-user-pihole
System user and group used by pi-hole
%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} .
%package config-unbound
Summary: Unbound configuration for %{name}
Group: System/Management
Requires: %{name} = %{version}
Requires: unbound
Supplements: packageand(%{name}:config-unbound)
BuildArch: noarch
%description config-unbound
Unbound configuration if you want to use unbound as DNS for %{name}.
%prep
%autosetup -n %{name}-%{version}
# Move datadir
find . -type f -exec sed -i 's/\/opt\/\pihole/\/usr\/share\/pi-hole/g' {} +
# Fix shebang
find . -type f -exec sed -i 's|#!/bin/sh|#!/bin/bash|g' {} +
find . -type f -exec sed -i 's/\/usr\/bin\/env sh/\/bin\/bash/g' {} +
find . -type f -exec sed -i 's/\/usr\/bin\/env bash/\/bin\/bash/g' {} +
# Move bindir
find . -type f -exec sed -i 's/\/usr\/local\/bin/\/usr\/bin/g' {} +
# Move gitdir
find . -type f -exec sed -i 's/\/etc\/\.pihole/\/usr\/share\/pi-hole/g' {} +
# service to systemctl
sed -i 's|service pihole-FTL restart|systemctl restart pi-hole-ftl|' pihole
# Other path fixes
find . -type f -exec sed -i 's|/automated install/basic-install.sh|/basic-install.sh|' {} +
sed -i 's|advanced/Scripts/database_migration/gravity-db.sh|database_migration/gravity-db.sh|' gravity.sh
sed -i 's|advanced/Templates/gravity.db.sql|database_migration/templates/gravity.db.sql|' gravity.sh
sed -i 's|advanced/Templates/gravity_copy.sql|database_migration/templates/gravity_copy.sql|' gravity.sh
sed -i 's|advanced/Scripts/database_migration/gravity|database_migration/gravity|' advanced/Scripts/database_migration/gravity-db.sh
# Have logs in /var/log/pihole dir.
sed -i "s|log-facility=/var/log/pihole.log|log-facility=/var/log/pihole/pihole.log|" advanced/01-pihole.conf
sed -i "s|/var/log/pihole.log|/var/log/pihole/pihole.log|" advanced/Templates/logrotate
sed -i "s|/var/log/pihole-FTL.log|/var/log/pihole/pihole-FTL.log|" advanced/Templates/logrotate
%build
%sysusers_generate_pre %{SOURCE5} pihole
%install
# Manual install of Pi-hole scripts, configs and man pages
install -Dm0755 pihole %{buildroot}%{_bindir}/pihole
install -d -m0755 %{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 "automated install"/basic-install.sh %{buildroot}%{_datadir}/%{name}/basic-install.sh
install -Dm0755 gravity.sh %{buildroot}%{_datadir}/%{name}/gravity.sh
install -Dm0755 advanced/Scripts/*.sh %{buildroot}%{_datadir}/%{name}/
install -Dm0644 advanced/01-pihole.conf %{buildroot}%{_sysconfdir}/dnsmasq.d/01-pihole.conf
install -Dm0640 advanced/Templates/logrotate %{buildroot}%{_sysconfdir}/pihole/logrotate
install -d -m 0755 %{buildroot}%{_datadir}/%{name}/database_migration/gravity
install -d -m 0755 %{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 -d -m 0755 %{buildroot}/%{_sysconfdir}/sudoers.d/
install -Dm0640 %{S:14} %{buildroot}%{_sysconfdir}/sudoers.d/pihole
install -Dm0640 /dev/null %{buildroot}%{_sysconfdir}/pihole/dhcp.leases
# Bash Completition
install -Dm0644 advanced/bash-completion/pihole %{buildroot}%{_datadir}/bash-completion/completions/pihole
# Unbound Configuration
mkdir -p %{buildroot}%{_sysconfdir}/unbound/conf.d
install -Dm0640 %{S:12} %{buildroot}%{_sysconfdir}/unbound/conf.d/01-pihole.conf
install -Dm0644 %{S:13} %{buildroot}%{_sysconfdir}/dnsmasq.d/
# 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}
# openSUSE/SUSE specific files
install -Dm0644 %{S:6} %{buildroot}%{_sysconfdir}/pihole/setupVars.conf
install -d -m 0755 %{buildroot}%{_sysusersdir}
install -m 644 %{S:5} %{buildroot}%{_sysusersdir}/system-user-pihole.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}-logrotate
ln -s service %{buildroot}/%{_sbindir}/rc%{name}-updategravity
%endif
# Install advertisement list Url file
install -Dm0644 %{S:7} %{buildroot}%{_sysconfdir}/pihole/adlists.list
install -Dm0644 %{S:8} %{buildroot}%{_sysconfdir}/pihole/dns-servers.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
# Setup Config
install -m 0755 %{S:16} %{buildroot}%{_sysconfdir}/pihole/
install -m 0755 %{S:17} %{buildroot}%{_sysconfdir}/pihole/
%pre -n system-user-pihole -f pihole.pre
%pre
%service_add_pre pi-hole-logrotate.service pi-hole-updategravity.service
%post
%fillup_only -n pihole
echo "Updating /etc/pihole/setupVars.conf..."
/etc/pihole/fillup_setupVars.conf.sh
echo "Updating /etc/dnsmasq.d/01-pihole.conf..."
/etc/pihole/fillup_01-pihole.conf.sh
%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
%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-pihole.conf
%attr(0775, pihole, www) %dir %{_sysconfdir}/pihole/
%attr(0664, pihole, www) %{_sysconfdir}/pihole/*
%attr(0775, pihole, pihole) %{_sysconfdir}/pihole/fillup_setupVars.conf.sh
%attr(0775, pihole, pihole) %{_sysconfdir}/pihole/fillup_01-pihole.conf.sh
%attr(0664, pihole, www)%config(noreplace) %{_sysconfdir}/pihole/adlists.list
%attr(0664, pihole, www) %config(noreplace) %{_sysconfdir}/pihole/dns-servers.conf
%attr(0664, pihole, pihole) %config(noreplace) %{_sysconfdir}/pihole/setupVars.conf
%attr(0660, pihole, www) %{_sysconfdir}/pihole/dhcp.leases
%attr(0640, root, root) %config %{_sysconfdir}/pihole/logrotate
%config(noreplace) %attr(0640, root, root) %{_sysconfdir}/sudoers.d/pihole
%{_bindir}/pihole
%{_mandir}/man8/pihole.8%{?ext_man}
%{_mandir}/man8/pihole-FTL.8%{?ext_man}
%attr(0775, pihole, www) %dir %{_datadir}/%{name}
%attr(0775, pihole, www) %{_datadir}/%{name}/*
%ghost %attr(0775, pihole, www) %dir /run/pihole
%ghost %attr(0664, pihole, www) %{_sysconfdir}/pihole/gravity*.db
%if 0%{?suse_version} <= 1600
%{_sbindir}/rc%{name}-logrotate
%{_sbindir}/rc%{name}-updategravity
%endif
%files -n system-user-pihole
%defattr(-,root,root)
%{_sysusersdir}/system-user-pihole.conf
%files bash-completion
%defattr(-,root,root)
%{_datadir}/bash-completion/completions/pihole
%files config-unbound
%defattr(-,unbound,unbound)
%attr(0775, root, unbound) %dir %{_sysconfdir}/unbound/conf.d/
%config(noreplace) %attr(0660, root, unbound) %{_sysconfdir}/unbound/conf.d/01-pihole.conf
%config(noreplace) %attr(0644, root, root) %{_sysconfdir}/dnsmasq.d/99-edns.conf
%changelog