Compare commits

..

14 Commits

Author SHA1 Message Date
Christian König
f3183dc95f Source directly, no intermediate variables
Some checks are pending
CodeQL / Analyze (pull_request) Waiting to run
Test Supported Distributions / smoke-tests (pull_request) Waiting to run
Test Supported Distributions / distro-test (centos_10) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (centos_9) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_11) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (debian_12) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_40) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_41) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (fedora_42) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_20) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_22) (pull_request) Blocked by required conditions
Test Supported Distributions / distro-test (ubuntu_24) (pull_request) Blocked by required conditions
Signed-off-by: Christian König <github@yubiuser.dev>
2025-06-01 15:10:14 +02:00
Christian König
18d4aef37c Add forgotten PI_HOLE_FILES_DIR
Signed-off-by: Christian König <github@yubiuser.dev>
2025-05-31 08:49:01 +02:00
yubiuser
cad0d0bf1f Allow to get API URL from local.api.ftl even if DNS port has changed (#6252) 2025-05-30 21:57:23 +02:00
Dan Schaper
42aba32ceb Use PID1 to determine which command to use when toggeling services (#6245) 2025-05-30 12:24:09 -07:00
Christian König
6f429d82b4 Allow to get API URL from local.api.ftl even if DNS port has changed
Signed-off-by: Christian König <github@yubiuser.dev>
2025-05-30 21:05:08 +02:00
Christian König
fd40fa6f39 Test need adjustment to long arument syntax
Signed-off-by: Christian König <github@yubiuser.dev>
2025-05-30 20:52:37 +02:00
yubiuser
d177c4c776 Add useful comment
Co-authored-by: Dan Schaper <dan.schaper@pi-hole.net>
Signed-off-by: yubiuser <github@yubiuser.dev>
2025-05-30 19:03:12 +02:00
Christian König
888556278e Add gwak to Fedorea 42 test image as other tests also rely on awk
Signed-off-by: Christian König <github@yubiuser.dev>
2025-05-28 20:47:55 +02:00
Christian König
69473a7b54 Add awk to meta package dependencie (is missing on Fedora 42 by default) and order dependencies alphabetically
Signed-off-by: Christian König <github@yubiuser.dev>
2025-05-28 19:54:44 +02:00
Christian König
f3166d7a78 Adjust test to mock PID1 to be systemd
Signed-off-by: Christian König <github@yubiuser.dev>
2025-05-27 23:52:46 +02:00
Christian König
137338e6a8 Use service wrappers in all scripts
Signed-off-by: Christian König <github@yubiuser.dev>
2025-05-27 21:23:56 +02:00
Christian König
b707890f10 Use PID1 to determine which command to use when toggeling services
Signed-off-by: Christian König <github@yubiuser.dev>
2025-05-27 20:09:59 +02:00
Dominik
822e677c5c Use a more general method to determine whether systemd is the init system (#6043) 2025-05-27 19:33:57 +02:00
DL6ER
bef8227cbd Use a more general method to determine whether systemd is the init system
Signed-off-by: DL6ER <dl6er@dl6er.de>
2025-03-03 20:16:07 +01:00
13 changed files with 74 additions and 48 deletions

View File

@@ -19,13 +19,18 @@
TestAPIAvailability() {
local chaos_api_list authResponse authStatus authData apiAvailable DNSport
# as we are running locally, we can get the port value from FTL directly
local chaos_api_list authResponse authStatus authData apiAvailable
# shellcheck source=./advanced/Scripts/utils.sh
. "/opt/pihole/utils.sh"
DNSport=$(getFTLConfigValue dns.port)
# Query the API URLs from FTL using CHAOS TXT local.api.ftl
# The result is a space-separated enumeration of full URLs
# e.g., "http://localhost:80/api/" "https://localhost:443/api/"
chaos_api_list="$(dig +short chaos txt local.api.ftl @127.0.0.1)"
chaos_api_list="$(dig +short -p "${DNSport}" chaos txt local.api.ftl @127.0.0.1)"
# If the query was not successful, the variable is empty
if [ -z "${chaos_api_list}" ]; then

View File

@@ -15,10 +15,14 @@ if [[ -f ${coltable} ]]; then
source ${coltable}
fi
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
# shellcheck source=./advanced/Scripts/utils.sh
source "${utilsfile}"
source "/opt/pihole/utils.sh"
SKIP_INSTALL="true"
# shellcheck source="./automated install/basic-install.sh"
source "/etc/.pihole/automated install/basic-install.sh"
# stop_service() is defined in basic-install.sh
# restart_service() is defined in basic-install.sh
# Determine database location
DBFILE=$(getFTLConfigValue "files.database")
@@ -33,7 +37,7 @@ flushARP(){
fi
# Stop FTL to prevent database access
if ! output=$(service pihole-FTL stop 2>&1); then
if ! output=$(stop_service pihole-FTL 2>&1); then
echo -e "${OVER} ${CROSS} Failed to stop FTL"
echo " Output: ${output}"
return 1
@@ -65,7 +69,7 @@ flushARP(){
fi
# Start FTL again
if ! output=$(service pihole-FTL restart 2>&1); then
if ! output=$(restart_service pihole-FTL 2>&1); then
echo -e "${OVER} ${CROSS} Failed to restart FTL"
echo " Output: ${output}"
return 1

View File

@@ -12,10 +12,14 @@ colfile="/opt/pihole/COL_TABLE"
# shellcheck source="./advanced/Scripts/COL_TABLE"
source ${colfile}
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
# shellcheck source="./advanced/Scripts/utils.sh"
source "${utilsfile}"
source "/opt/pihole/utils.sh"
SKIP_INSTALL="true"
# shellcheck source="./automated install/basic-install.sh"
source "/etc/.pihole/automated install/basic-install.sh"
# stop_service() is defined in basic-install.sh
# restart_service() is defined in basic-install.sh
# In case we're running at the same time as a system logrotate, use a
# separate logrotate state file to prevent stepping on each other's
@@ -104,13 +108,14 @@ else
fi
# Stop FTL to make sure it doesn't write to the database while we're deleting data
service pihole-FTL stop
stop_service pihole-FTL >/dev/null
# Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history)
deleted=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM query_storage WHERE timestamp >= strftime('%s','now')-86400; select changes() from query_storage limit 1")
# Restart FTL
service pihole-FTL restart
restart_service pihole-FTL >/dev/null
if [[ "$*" != *"quiet"* ]]; then
echo -e "${OVER} ${TICK} Deleted ${deleted} queries from long-term query database"
fi

View File

@@ -57,9 +57,9 @@ start() {
stop() {
if is_running; then
kill "${FTL_PID}"
# Give FTL 120 seconds to gracefully stop
# Give FTL 60 seconds to gracefully stop
i=1
while [ "${i}" -le 120 ]; do
while [ "${i}" -le 60 ]; do
if ! is_running; then
break
fi

View File

@@ -28,7 +28,7 @@ ExecReload=/bin/kill -HUP $MAINPID
ExecStopPost=/opt/pihole/pihole-FTL-poststop.sh
# Use graceful shutdown with a reasonable timeout
TimeoutStopSec=120s
TimeoutStopSec=60s
# Make /usr, /boot, /etc and possibly some more folders read-only...
ProtectSystem=full

View File

@@ -116,11 +116,11 @@ c=70
PIHOLE_META_PACKAGE_CONTROL_APT=$(
cat <<EOM
Package: pihole-meta
Version: 0.3
Version: 0.4
Maintainer: Pi-hole team <adblock@pi-hole.net>
Architecture: all
Description: Pi-hole dependency meta package
Depends: grep,dnsutils,binutils,git,iproute2,dialog,ca-certificates,cron | cron-daemon,curl,iputils-ping,psmisc,sudo,unzip,libcap2-bin,dns-root-data,libcap2,netcat-openbsd,procps,jq,lshw,bash-completion
Depends: awk,bash-completion,binutils,ca-certificates,cron|cron-daemon,curl,dialog,dnsutils,dns-root-data,git,grep,iproute2,iputils-ping,jq,libcap2,libcap2-bin,lshw,netcat-openbsd,procps,psmisc,sudo,unzip
Section: contrib/metapackages
Priority: optional
EOM
@@ -130,12 +130,12 @@ EOM
PIHOLE_META_PACKAGE_CONTROL_RPM=$(
cat <<EOM
Name: pihole-meta
Version: 0.1
Version: 0.2
Release: 1
License: EUPL
BuildArch: noarch
Summary: Pi-hole dependency meta package
Requires: grep,curl,psmisc,sudo, unzip,jq,git,dialog,ca-certificates, bind-utils, iproute, procps-ng, chkconfig, binutils, cronie, findutils, libcap, nmap-ncat, lshw, bash-completion
Requires: bash-completion,bind-utils,binutils,ca-certificates,chkconfig,cronie,curl,dialog,findutils,gawk,git,grep,iproute,jq,libcap,lshw,nmap-ncat,procps-ng,psmisc,sudo,unzip
%description
Pi-hole dependency meta package
%prep
@@ -143,6 +143,9 @@ Pi-hole dependency meta package
%files
%install
%changelog
* Wed May 28 2025 Pi-hole Team - 0.2
- Add gawk to the list of dependencies
* Sun Sep 29 2024 Pi-hole Team - 0.1
- First version being packaged
EOM
@@ -228,6 +231,15 @@ is_command() {
command -v "${check_command}" >/dev/null 2>&1
}
is_pid1() {
# Checks to see if the given command runs as PID 1
local is_pid1="$1"
# select PID 1, format output to show only CMD column without header
# quietly grep for a match on the function passed parameter
ps --pid 1 --format comm= | grep -q "${is_pid1}"
}
# Compatibility
package_manager_detect() {
@@ -1152,8 +1164,7 @@ installConfigs() {
fi
# Install pihole-FTL systemd or init.d service, based on whether systemd is the init system or not
# Follow debhelper logic, which checks for /run/systemd/system to derive whether systemd is the init system
if [[ -d '/run/systemd/system' ]]; then
if is_pid1 systemd; then
install -T -m 0644 "${PI_HOLE_LOCAL_REPO}/advanced/Templates/pihole-FTL.systemd" '/etc/systemd/system/pihole-FTL.service'
# Remove init.d service if present
@@ -1221,9 +1232,12 @@ stop_service() {
# Can softfail, as process may not be installed when this is called
local str="Stopping ${1} service"
printf " %b %s..." "${INFO}" "${str}"
if is_command systemctl; then
# If systemd is PID 1,
if is_pid1 systemd; then
# use that to restart the service
systemctl -q stop "${1}" || true
else
# Otherwise, fall back to the service command
service "${1}" stop >/dev/null || true
fi
printf "%b %b %s...\\n" "${OVER}" "${TICK}" "${str}"
@@ -1234,8 +1248,8 @@ restart_service() {
# Local, named variables
local str="Restarting ${1} service"
printf " %b %s..." "${INFO}" "${str}"
# If systemctl exists,
if is_command systemctl; then
# If systemd is PID 1,
if is_pid1 systemd; then
# use that to restart the service
systemctl -q restart "${1}"
else
@@ -1250,8 +1264,8 @@ enable_service() {
# Local, named variables
local str="Enabling ${1} service to start on reboot"
printf " %b %s..." "${INFO}" "${str}"
# If systemctl exists,
if is_command systemctl; then
# If systemd is PID1,
if is_pid1 systemd; then
# use that to enable the service
systemctl -q enable "${1}"
else
@@ -1266,8 +1280,8 @@ disable_service() {
# Local, named variables
local str="Disabling ${1} service"
printf " %b %s..." "${INFO}" "${str}"
# If systemctl exists,
if is_command systemctl; then
# If systemd is PID1,
if is_pid1 systemd; then
# use that to disable the service
systemctl -q disable "${1}"
else
@@ -1278,8 +1292,8 @@ disable_service() {
}
check_service_active() {
# If systemctl exists,
if is_command systemctl; then
# If systemd is PID1,
if is_pid1 systemd; then
# use that to check the status of the service
systemctl -q is-enabled "${1}" 2>/dev/null
else

View File

@@ -45,7 +45,7 @@ readonly PI_HOLE_FILES_DIR="/etc/.pihole"
SKIP_INSTALL="true"
# shellcheck source="./automated install/basic-install.sh"
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
# stop_service() is defined in basic-install.sh
# package_manager_detect() sourced from basic-install.sh
package_manager_detect
@@ -102,11 +102,7 @@ removePiholeFiles() {
# Remove FTL
if command -v pihole-FTL &> /dev/null; then
echo -ne " ${INFO} Removing pihole-FTL..."
if [[ -x "$(command -v systemctl)" ]]; then
systemctl stop pihole-FTL
else
service pihole-FTL stop
fi
stop_service pihole-FTL
${SUDO} rm -f /etc/systemd/system/pihole-FTL.service
if [[ -d '/etc/systemd/system/pihole-FTL.service.d' ]]; then
read -rp " ${QST} FTL service override directory /etc/systemd/system/pihole-FTL.service.d detected. Do you wish to remove this from your system? [y/N] " answer

View File

@@ -1,7 +1,7 @@
FROM quay.io/centos/centos:stream10
# Disable SELinux
RUN echo "SELINUX=disabled" > /etc/selinux/config
RUN yum install -y --allowerasing curl git initscripts
RUN yum install -y --allowerasing curl git
ENV GITDIR=/etc/.pihole
ENV SCRIPTDIR=/opt/pihole

View File

@@ -1,7 +1,7 @@
FROM quay.io/centos/centos:stream9
# Disable SELinux
RUN echo "SELINUX=disabled" > /etc/selinux/config
RUN yum install -y --allowerasing curl git initscripts
RUN yum install -y --allowerasing curl git
ENV GITDIR=/etc/.pihole
ENV SCRIPTDIR=/opt/pihole

View File

@@ -1,5 +1,5 @@
FROM fedora:40
RUN dnf install -y git initscripts
RUN dnf install -y git
ENV GITDIR=/etc/.pihole
ENV SCRIPTDIR=/opt/pihole

View File

@@ -1,5 +1,5 @@
FROM fedora:41
RUN dnf install -y git initscripts
RUN dnf install -y git
ENV GITDIR=/etc/.pihole
ENV SCRIPTDIR=/opt/pihole

View File

@@ -1,5 +1,5 @@
FROM fedora:42
RUN dnf install -y git initscripts
RUN dnf install -y git gawk
ENV GITDIR=/etc/.pihole
ENV SCRIPTDIR=/opt/pihole

View File

@@ -66,6 +66,14 @@ def test_installPihole_fresh_install_readableFiles(host):
mock_command("dialog", {"*": ("", "0")}, host)
# mock git pull
mock_command_passthrough("git", {"pull": ("", "0")}, host)
# mock PID 1 to pretend to be systemd
mock_command_2(
"ps",
{
"--pid 1": ("systemd", "0"),
},
host,
)
# mock systemctl to not start FTL
mock_command_2(
"systemctl",
@@ -73,6 +81,7 @@ def test_installPihole_fresh_install_readableFiles(host):
"enable pihole-FTL": ("", "0"),
"restart pihole-FTL": ("", "0"),
"start pihole-FTL": ("", "0"),
"stop pihole-FTL": ("", "0"),
"*": ('echo "systemctl call with $@"', "0"),
},
host,
@@ -131,13 +140,6 @@ def test_installPihole_fresh_install_readableFiles(host):
check_macvendor = test_cmd.format("r", "/etc/pihole/macvendor.db", piholeuser)
actual_rc = host.run(check_macvendor).rc
assert exit_status_success == actual_rc
# check readable and executable /etc/init.d/pihole-FTL
check_init = test_cmd.format("x", "/etc/init.d/pihole-FTL", piholeuser)
actual_rc = host.run(check_init).rc
assert exit_status_success == actual_rc
check_init = test_cmd.format("r", "/etc/init.d/pihole-FTL", piholeuser)
actual_rc = host.run(check_init).rc
assert exit_status_success == actual_rc
# check readable and executable manpages
if maninstalled is True:
check_man = test_cmd.format("x", "/usr/local/share/man", piholeuser)