Skip to content

Commit

Permalink
Pi-hole v6 development branch
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Harding <[email protected]>
  • Loading branch information
klutchell committed Aug 19, 2024
1 parent a69dbd1 commit 45390b1
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 76 deletions.
3 changes: 1 addition & 2 deletions balena.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
17 changes: 8 additions & 9 deletions pihole/Dockerfile
Original file line number Diff line number Diff line change
@@ -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'
87 changes: 87 additions & 0 deletions pihole/balena-init.sh
Original file line number Diff line number Diff line change
@@ -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}"
28 changes: 0 additions & 28 deletions pihole/cont-init.d/10-custom.sh

This file was deleted.

Empty file.
Empty file.
5 changes: 0 additions & 5 deletions pihole/s6-overlay/s6-rc.d/padd/finish

This file was deleted.

28 changes: 0 additions & 28 deletions pihole/s6-overlay/s6-rc.d/padd/run

This file was deleted.

1 change: 0 additions & 1 deletion pihole/s6-overlay/s6-rc.d/padd/type

This file was deleted.

Empty file.

0 comments on commit 45390b1

Please sign in to comment.