Skip to content

Commit ee404bd

Browse files
committed
refactor(dns): standardize pihole and unbound modules with docker.io
- Change docker-ce to docker.io and move check to top of both modules - Improve container/image detection with proper filtering - Add already-installed check in install commands - Improve remove commands with better feedback - Add unbound.conf configuration file creation - Update unbound to use alpinelinux/unbound image - Update port mapping to use module_options consistently - Update pi-hole DNS upstream to use unbound on port 5335
1 parent c9ee9ad commit ee404bd

File tree

3 files changed

+63
-20
lines changed

3 files changed

+63
-20
lines changed

tests/unbound.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ENABLED=true
2+
RELEASE="noble"
3+
TESTNAME="Unbound install"
4+
5+
testcase() {(
6+
./bin/armbian-config --api module_unbound purge
7+
./bin/armbian-config --api module_unbound install
8+
./bin/armbian-config --api module_unbound status
9+
)}

tools/modules/software/module_pi-hole.sh

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module_options+=(
88
["module_pi_hole,doc_link"]="https://docs.pi-hole.net/"
99
["module_pi_hole,group"]="DNS"
1010
["module_pi_hole,port"]="8811"
11-
["module_pi_hole,arch"]=""
11+
["module_pi_hole,arch"]="x86-64 arm64"
1212
)
1313
#
1414
# Module Pi-Hole
@@ -17,18 +17,23 @@ function module_pi_hole () {
1717
local title="pihole"
1818
local condition=$(which "$title" 2>/dev/null)
1919

20-
if pkg_installed docker-ce; then
21-
local container=$(docker container ls -a | mawk '/pihole?( |$)/{print $1}')
22-
local image=$(docker image ls -a | mawk '/pihole?( |$)/{print $3}')
23-
fi
20+
pkg_installed docker.io || module_docker install
21+
local container=$(docker container ls -a --filter 'name=^/pihole$' --format '{{.ID}}')
22+
local image=$(docker image ls -a --filter 'reference=pihole/pihole:*' --format '{{.Repository}}:{{.Tag}}' | head -1)
23+
2424
local commands
2525
IFS=' ' read -r -a commands <<< "${module_options["module_pi_hole,example"]}"
2626

2727
PIHOLE_BASE="${SOFTWARE_FOLDER}/pihole"
2828

2929
case "$1" in
3030
"${commands[0]}")
31-
pkg_installed docker-ce || module_docker install
31+
# Check if the module is already installed
32+
if [[ "${container}" && "${image}" ]]; then
33+
echo "Pi-hole container is already installed."
34+
exit 0
35+
fi
36+
3237
if ! docker container ls -a --format '{{.Names}}' | grep -q '^unbound$'; then module_unbound install; fi
3338
local unbound_ip=$(docker inspect --format '{{ .NetworkSettings.Networks.lsio.IPAddress }}' unbound)
3439
[[ -d "$PIHOLE_BASE" ]] || mkdir -p "$PIHOLE_BASE" || { echo "Couldn't create storage directory: $PIHOLE_BASE"; exit 1; }
@@ -50,7 +55,7 @@ function module_pi_hole () {
5055
-e VIRTUAL_HOST="pi.hole" \
5156
-e PROXY_LOCATION="pi.hole" \
5257
-e FTLCONF_LOCAL_IPV4="${LOCALIPADD}" \
53-
-e FTLCONF_dns_upstreams="${unbound_ip}" \
58+
-e FTLCONF_dns_upstreams="unbound#5335" \
5459
pihole/pihole:latest
5560
for i in $(seq 1 20); do
5661
if docker inspect -f '{{ index .Config.Labels "build_version" }}' pihole >/dev/null 2>&1 ; then
@@ -77,8 +82,13 @@ function module_pi_hole () {
7782
${module_options["module_pi_hole,feature"]} ${commands[3]}
7883
;;
7984
"${commands[1]}")
80-
[[ "${container}" ]] && docker container rm -f "$container" >/dev/null
81-
[[ "${image}" ]] && docker image rm "$image" >/dev/null
85+
if [[ "${container}" ]]; then
86+
echo "Removing container: $container"
87+
docker container rm -f "$container"
88+
fi
89+
if [[ "${image}" ]]; then
90+
docker image rm "$image"
91+
fi
8292
# restore DNS settings
8393
if srv_active systemd-resolved; then
8494
mkdir -p /etc/systemd/resolved.conf.d/

tools/modules/software/module_unbound.sh

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module_options+=(
77
["module_unbound,status"]="Active"
88
["module_unbound,doc_link"]="https://unbound.docs.nlnetlabs.nl/en/latest/"
99
["module_unbound,group"]="DNS"
10-
["module_unbound,port"]="8053"
10+
["module_unbound,port"]="5335"
1111
["module_unbound,arch"]="x86-64"
1212
)
1313
#
@@ -17,10 +17,9 @@ function module_unbound () {
1717
local title="unbound"
1818
local condition=$(which "$title" 2>/dev/null)
1919

20-
if pkg_installed docker-ce; then
21-
local container=$(docker container ls -a | mawk '/unbound?( |$)/{print $1}')
22-
local image=$(docker image ls -a | mawk '/unbound?( |$)/{print $3}')
23-
fi
20+
pkg_installed docker.io || module_docker install
21+
local container=$(docker container ls -a --filter "name=unbound" --format '{{.ID}}')
22+
local image=$(docker image ls -a --format '{{.Repository}}:{{.Tag}}' | grep 'alpinelinux/unbound:' | head -1)
2423

2524
local commands
2625
IFS=' ' read -r -a commands <<< "${module_options["module_unbound,example"]}"
@@ -29,17 +28,37 @@ function module_unbound () {
2928

3029
case "$1" in
3130
"${commands[0]}")
32-
pkg_installed docker-ce || module_docker install
31+
# Check if the module is already installed
32+
if [[ "${container}" && "${image}" ]]; then
33+
echo "Unbound container is already installed."
34+
return 0
35+
fi
36+
3337
[[ -d "$UNBOUND_BASE" ]] || mkdir -p "$UNBOUND_BASE" || { echo "Couldn't create storage directory: $UNBOUND_BASE"; exit 1; }
38+
39+
# Create unbound.conf
40+
cat > "${UNBOUND_BASE}/unbound.conf" <<-EOT
41+
server:
42+
interface: 0.0.0.0
43+
port: 5335
44+
access-control: 0.0.0.0/0 allow
45+
do-ip4: yes
46+
do-udp: yes
47+
do-tcp: yes
48+
do-ip6: no
49+
verbosity: 1
50+
EOT
51+
3452
docker run -d \
3553
--net=lsio \
3654
-e PUID=1000 \
3755
-e PGID=1000 \
38-
-p ${module_options["module_unbound,port"]}:53/tcp \
39-
-p ${module_options["module_unbound,port"]}:53/udp \
56+
-p ${module_options["module_unbound,port"]}:${module_options["module_unbound,port"]}/tcp \
57+
-p ${module_options["module_unbound,port"]}:${module_options["module_unbound,port"]}/udp \
58+
-v ${UNBOUND_BASE}/unbound.conf:/etc/unbound/unbound.conf:ro \
4059
--name unbound \
4160
--restart=unless-stopped \
42-
mvance/unbound:latest
61+
alpinelinux/unbound
4362
for i in $(seq 1 20); do
4463
if docker inspect -f '{{ index .Config.Labels "build_version" }}' unbound >/dev/null 2>&1 ; then
4564
break
@@ -53,8 +72,13 @@ function module_unbound () {
5372
done
5473
;;
5574
"${commands[1]}")
56-
[[ "${container}" ]] && docker container rm -f "$container" >/dev/null
57-
[[ "${image}" ]] && docker image rm "$image" >/dev/null
75+
if [[ "${container}" ]]; then
76+
echo "Removing container: $container"
77+
docker container rm -f "$container"
78+
fi
79+
if [[ "${image}" ]]; then
80+
docker image rm "$image"
81+
fi
5882
;;
5983
"${commands[2]}")
6084
${module_options["module_unbound,feature"]} ${commands[1]}

0 commit comments

Comments
 (0)