From 45390b1aa553c84354a7f4a97ff04ed9d27184bc Mon Sep 17 00:00:00 2001 From: Kyle Harding Date: Fri, 1 Dec 2023 12:42:34 -0500 Subject: [PATCH] Pi-hole v6 development branch Signed-off-by: Kyle Harding --- balena.yml | 3 +- docker-compose.yml | 3 - pihole/Dockerfile | 17 ++-- pihole/balena-init.sh | 87 +++++++++++++++++++ pihole/cont-init.d/10-custom.sh | 28 ------ .../s6-rc.d/padd/dependencies.d/lighttpd | 0 .../s6-rc.d/padd/dependencies.d/pihole-FTL | 0 pihole/s6-overlay/s6-rc.d/padd/finish | 5 -- pihole/s6-overlay/s6-rc.d/padd/run | 28 ------ pihole/s6-overlay/s6-rc.d/padd/type | 1 - .../s6-overlay/s6-rc.d/user/contents.d/padd | 0 11 files changed, 96 insertions(+), 76 deletions(-) create mode 100644 pihole/balena-init.sh delete mode 100644 pihole/cont-init.d/10-custom.sh delete mode 100644 pihole/s6-overlay/s6-rc.d/padd/dependencies.d/lighttpd delete mode 100644 pihole/s6-overlay/s6-rc.d/padd/dependencies.d/pihole-FTL delete mode 100644 pihole/s6-overlay/s6-rc.d/padd/finish delete mode 100644 pihole/s6-overlay/s6-rc.d/padd/run delete mode 100644 pihole/s6-overlay/s6-rc.d/padd/type delete mode 100644 pihole/s6-overlay/s6-rc.d/user/contents.d/padd diff --git a/balena.yml b/balena.yml index 9912c0fc..43dbab0b 100644 --- a/balena.yml +++ b/balena.yml @@ -1,6 +1,6 @@ name: "Pi-hole" type: "sw.application" -version: 2024.6.0 +version: 6.0.0 description: "Pi-hole is a Linux network-level advertisement and Internet tracker blocking application!" post-provisioning: >- ## Usage instructions @@ -27,7 +27,6 @@ data: applicationEnvironmentVariables: - WEBPASSWORD: 'balena' - PIHOLE_DNS_: '1.1.1.1;1.0.0.1' - - FBCP_DISPLAY: "" defaultDeviceType: "raspberrypi3" supportedDeviceTypes: - "raspberry-pi2" diff --git a/docker-compose.yml b/docker-compose.yml index 83a42497..42153afa 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,6 @@ services: - NET_ADMIN volumes: - "pihole_config:/etc/pihole" - - "dnsmasq_config:/etc/dnsmasq.d" dns: - "127.0.0.1" - "1.1.1.1" @@ -28,8 +27,6 @@ services: environment: DNSMASQ_LISTENING: all PIHOLE_DNS_: 1.1.1.1;1.0.0.1 - FONTFACE: Terminus - FONTSIZE: 8x14 WEBPASSWORD: balena VIRTUAL_HOST: balena-devices.com WEB_BIND_ADDR: 0.0.0.0 diff --git a/pihole/Dockerfile b/pihole/Dockerfile index 626735d7..b423114b 100644 --- a/pihole/Dockerfile +++ b/pihole/Dockerfile @@ -1,16 +1,15 @@ # https://hub.docker.com/r/pihole/pihole/tags -FROM pihole/pihole:2024.06.0@sha256:5c56e9b2fb9715382ebf49f5487aede1ccd933a0807cab2d6dea9136c084c7e0 +FROM pihole/pihole:development-v6 -ENV DEBIAN_FRONTEND noninteractive +# https://wiki.alpinelinux.org/wiki/Fonts +# hadolint ignore=DL3018 +RUN apk add --no-cache dbus font-terminus kbd -# hadolint ignore=DL3008 -RUN apt-get update && \ - apt-get install --no-install-recommends -y console-setup dbus netcat && \ - apt-get clean && rm -rf /var/lib/apt/lists/* +COPY balena-init.sh / -COPY cont-init.d/ /etc/cont-init.d/ -COPY s6-overlay/ /etc/s6-overlay/ +RUN chmod +x /balena-init.sh -RUN chmod +x /etc/cont-init.d/10-custom.sh +ENTRYPOINT [ "tini", "--", "/balena-init.sh" ] ENV DBUS_SYSTEM_BUS_ADDRESS 'unix:path=/host/run/dbus/system_bus_socket' +ENV CONSOLE_FONT 'ter-u16n' diff --git a/pihole/balena-init.sh b/pihole/balena-init.sh new file mode 100644 index 00000000..96a5b8c5 --- /dev/null +++ b/pihole/balena-init.sh @@ -0,0 +1,87 @@ +#!/usr/bin/env bash + +set -e + +# avoid port conflicts with resin-dns +# https://docs.pi-hole.net/ftldns/interfaces/ +mkdir -p /etc/dnsmasq.d +echo "bind-interfaces" >/etc/dnsmasq.d/90-resin-dns.conf +echo "except-interface=resin-dns" >>/etc/dnsmasq.d/90-resin-dns.conf +# remove deprecated dnsmasq config files if they exist +rm -f /etc/dnsmasq.d/balena.conf /etc/dnsmasq.d/01-pihole.conf + +# Use EDNS_PACKET_MAX=1232 to avoid unbound DNS packet size warnings +# https://docs.pi-hole.net/guides/dns/unbound/ +# https://docs.pi-hole.net/ftldns/dnsmasq_warn/#reducing-dns-packet-size-for-nameserver-address-to-safe_pktsz +if [[ ${EDNS_PACKET_MAX:-} =~ [0-9]+$ ]]; then + echo "Reducing DNS packet size to ${EDNS_PACKET_MAX}..." + echo "edns-packet-max=${EDNS_PACKET_MAX}" >/etc/dnsmasq.d/99-edns.conf +fi + +# source bash functions like setFTLConfigValue +# shellcheck source=/dev/null +# . /usr/bin/bash_functions.sh + +# enable inclusion of dnsmasq.d conf files +# https://github.com/pi-hole/FTL/pull/1734 +pihole-FTL --config misc.etc_dnsmasq_d true + +# update the webpassword if one was provided +pihole setpassword "${WEBPASSWORD:-}" || true + +# execute the Pi-hole entrypoint in the background +/usr/bin/start.sh & +pid=$! + +# quit the plymouth (balena logo) service so that we can see the TTY +echo "Stopping plymouth service..." +dbus-send \ + --system \ + --dest=org.freedesktop.systemd1 \ + --type=method_call \ + --print-reply \ + /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.StartUnit \ + string:"plymouth-quit.service" string:"replace" + +# get the FTL webserver port +webserver_port="$(pihole-FTL --config webserver.port)" +webserver_port="${webserver_port%%,*}" + +is_api_available() { + response="$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${webserver_port}/api/auth")" + case "${response}" in + 200 | 401) return 0 ;; + *) return 1 ;; + esac +} + +# wait for FTL API to be available +# shellcheck disable=SC2310 +while ! is_api_available; do + sleep 2 +done + +console=/dev/tty1 + +# check if console is available +if [[ -e "${console}" ]] && [[ -n "${CONSOLE_FONT}" ]]; then + # https://wiki.alpinelinux.org/wiki/Fonts + # https://www.man7.org/linux/man-pages/man8/setfont.8.html + echo "Setting console font to ${CONSOLE_FONT}..." + setfont -C "${console}" /usr/share/consolefonts/"${CONSOLE_FONT}".psf.gz + + # calculate the size of the target tty rather than the current terminal session + stty_size="$(stty size -F "${console}")" + console_height="$(echo "${stty_size}" | awk '{print $1}')" + console_width="$(echo "${stty_size}" | awk '{print $2}')" + + sed "s|console_height=.*|console_height=${console_height}|" -i /usr/local/bin/padd + sed "s|console_width=.*|console_width=${console_width}|" -i /usr/local/bin/padd + + # start PADD as a background process + echo "Starting PADD..." + /usr/local/bin/padd --secret "${WEBPASSWORD:-}" 2>/dev/null >"${console}" & +fi + +# reattach to the Pi-hole entrypoint process +wait "${pid}" diff --git a/pihole/cont-init.d/10-custom.sh b/pihole/cont-init.d/10-custom.sh deleted file mode 100644 index 1474e190..00000000 --- a/pihole/cont-init.d/10-custom.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/command/with-contenv bash -# shellcheck shell=bash - -set -e - -# avoid port conflicts with resin-dns -# https://docs.pi-hole.net/ftldns/interfaces/ -# these steps must be at runtime because /etc/dnsmasq.d is a user volume -echo "bind-interfaces" > /etc/dnsmasq.d/90-resin-dns.conf -echo "except-interface=resin-dns" >> /etc/dnsmasq.d/90-resin-dns.conf - -if [ -f /etc/dnsmasq.d/balena.conf ] -then - # remove the old config file - rm /etc/dnsmasq.d/balena.conf -fi - -pihole -a -p "${WEBPASSWORD}" || true - -# check if we are using unbound as upstream DNS -if [[ ${PIHOLE_DNS_%;*} =~ ^127\.0\.0\.1#5053$ ]] -then - # https://docs.pi-hole.net/guides/dns/unbound/ - # https://docs.pi-hole.net/ftldns/dnsmasq_warn/#reducing-dns-packet-size-for-nameserver-address-to-safe_pktsz - pkt_size=1232 - echo "Reducing DNS packet size for nameserver ${PIHOLE_DNS_%;*} to ${pkt_size}..." - echo "edns-packet-max=${pkt_size}" > /etc/dnsmasq.d/99-edns.conf -fi diff --git a/pihole/s6-overlay/s6-rc.d/padd/dependencies.d/lighttpd b/pihole/s6-overlay/s6-rc.d/padd/dependencies.d/lighttpd deleted file mode 100644 index e69de29b..00000000 diff --git a/pihole/s6-overlay/s6-rc.d/padd/dependencies.d/pihole-FTL b/pihole/s6-overlay/s6-rc.d/padd/dependencies.d/pihole-FTL deleted file mode 100644 index e69de29b..00000000 diff --git a/pihole/s6-overlay/s6-rc.d/padd/finish b/pihole/s6-overlay/s6-rc.d/padd/finish deleted file mode 100644 index be31ff1b..00000000 --- a/pihole/s6-overlay/s6-rc.d/padd/finish +++ /dev/null @@ -1,5 +0,0 @@ -#!/command/with-contenv bash -# shellcheck shell=bash - -s6-echo "Stopping PADD" -killall -9 padd diff --git a/pihole/s6-overlay/s6-rc.d/padd/run b/pihole/s6-overlay/s6-rc.d/padd/run deleted file mode 100644 index eb912328..00000000 --- a/pihole/s6-overlay/s6-rc.d/padd/run +++ /dev/null @@ -1,28 +0,0 @@ -#!/command/with-contenv bash -# shellcheck shell=bash - -# quit the plymouth (balena logo) service so that we can see the TTY -s6-echo "Stopping plymouth service..." -dbus-send \ - --system \ - --dest=org.freedesktop.systemd1 \ - --type=method_call \ - --print-reply \ - /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.StartUnit \ - string:"plymouth-quit.service" string:"replace" - -s6-echo "Setting console font to ${FONTFACE} ${FONTSIZE}..." -sed -i "s/^FONTFACE.*/FONTFACE=\"${FONTFACE}\"/" /etc/default/console-setup -sed -i "s/^FONTSIZE.*/FONTSIZE=\"${FONTSIZE}\"/" /etc/default/console-setup -dpkg-reconfigure console-setup 2> /dev/null > /dev/tty1 - -# see https://github.com/klutchell/balena-pihole/issues/187 -s6-echo "Detecting screen size..." -console_height="$(stty size -F /dev/tty1 | awk '{print $1}')" -console_width="$(stty size -F /dev/tty1 | awk '{print $2}')" - -sed "s|console_height=.*|console_height=$console_height|" -i /usr/local/bin/padd -sed "s|console_width=.*|console_width=$console_width|" -i /usr/local/bin/padd - -s6-echo "Starting PADD..." -/usr/local/bin/padd 2> /dev/null > /dev/tty1 diff --git a/pihole/s6-overlay/s6-rc.d/padd/type b/pihole/s6-overlay/s6-rc.d/padd/type deleted file mode 100644 index 1780f9f4..00000000 --- a/pihole/s6-overlay/s6-rc.d/padd/type +++ /dev/null @@ -1 +0,0 @@ -longrun \ No newline at end of file diff --git a/pihole/s6-overlay/s6-rc.d/user/contents.d/padd b/pihole/s6-overlay/s6-rc.d/user/contents.d/padd deleted file mode 100644 index e69de29b..00000000