Skip to content

Commit

Permalink
Software title: Pi-hole
Browse files Browse the repository at this point in the history
install / uninstall / set password
  • Loading branch information
igorpecovnik committed Nov 7, 2024
1 parent 19e86ae commit 5a5de0b
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
Binary file added tools/include/images/DNS001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions tools/include/markdown/DNS001-footer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
=== "Access the web interface"

The web interface of Pi-hole can be accessed via:

- URL = `http://<your.IP>/admin`
- Password = 'Set / adjust from armbian-config'

=== "Documentation"

<https://docs.pi-hole.net/>
2 changes: 2 additions & 0 deletions tools/include/markdown/DNS001-header.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Pi-hole is a DNS sinkhole with web interface that will block ads for any device on your network.

30 changes: 30 additions & 0 deletions tools/json/config.software.json
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,36 @@
}
]
},
{
"id": "DNS",
"description": "DNS blockers",
"sub": [
{
"id": "DNS001",
"description": "Install Pi-hole DNS ad blocker",
"command": [ "pi_hole install" ],
"status": "Stable",
"author": "@armbian",
"condition": "! pi_hole status"
},
{
"id": "DNS002",
"description": "Set Pi-hole web admin password",
"command": [ "pi_hole password" ],
"status": "Stable",
"author": "@armbian",
"condition": "pi_hole status"
},
{
"id": "DNS003",
"description": "Remove Pi-hole DNS ad blocker",
"command": [ "pi_hole uninstall" ],
"status": "Stable",
"author": "@armbian",
"condition": "pi_hole status"
}
]
},
{
"id": "DevTools",
"description": "Development",
Expand Down
83 changes: 83 additions & 0 deletions tools/modules/software/install_pi-hole.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module_options+=(
["pi_hole,author"]="@armbian"
["pi_hole,ref_link"]=""
["pi_hole,feature"]="pi_hole"
["pi_hole,desc"]="Install/uninstall/check status of pi-hole container"
["pi_hole,example"]="pi_hole install|uninstall|status|password"
["pi_hole,status"]="Active"
)
#
# Install Pi-Hole DNS blocking
#
function pi_hole () {

if check_if_installed docker-ce; then
local container=$(docker container ls -a | mawk '/pihole?( |$)/{print $1}')
local image=$(docker image ls -a | mawk '/pihole?( |$)/{print $3}')
fi

PIHOLE_BASE=/opt/pihole-storage
PIHOLE_BASE="${PIHOLE_BASE:-$(pwd)}"
[[ -d "$PIHOLE_BASE" ]] || mkdir -p "$PIHOLE_BASE" || { echo "Couldn't create storage directory: $PIHOLE_BASE"; exit 1; }

case "$1" in
install)

check_if_installed docker-ce || install_docker

# disable dns within systemd-resolved
if systemctl is-active --quiet systemd-resolved.service && ! grep -q "^DNSStubListener=no" /etc/systemd/resolved.conf; then
sed -i "s/^#\?DNSStubListener=.*/DNSStubListener=no/" /etc/systemd/resolved.conf
systemctl restart systemd-resolved.service
sleep 3
fi
# disable dns within Network manager
if systemctl is-active --quiet NetworkManager && grep -q "dns=true" /etc/NetworkManager/NetworkManager.conf; then
sed -i "s/dns=.*/dns=false/g" /etc/NetworkManager/NetworkManager.conf
systemctl restart NetworkManager
sleep 3
fi

docker run -d \
--name pihole \
-p 53:53/tcp -p 53:53/udp \
-p 80:80 \
-e TZ="$(cat /etc/timezone)" \
-v "${PIHOLE_BASE}/etc-pihole:/etc/pihole" \
-v "${PIHOLE_BASE}/etc-dnsmasq.d:/etc/dnsmasq.d" \
--dns=9.9.9.9 \
--restart=unless-stopped \
--hostname pi.hole \
-e VIRTUAL_HOST="pi.hole" \
-e PROXY_LOCATION="pi.hole" \
-e FTLCONF_LOCAL_IPV4="${LOCALIPADD}" \
pihole/pihole:latest

for i in $(seq 1 20); do
if [ "$(docker inspect -f "{{.State.Health.Status}}" pihole)" == "healthy" ] ; then
break
else
sleep 3
fi
if [ $i -eq 20 ] ; then
echo -e "\nTimed out waiting for Pi-hole start, consult your container logs for more info (\`docker logs pihole\`)"
exit 1
fi
done
;;

uninstall)
[[ "${container}" ]] && docker container rm -f "$container" >/dev/null
[[ "${image}" ]] && docker image rm "$image" >/dev/null
;;
password)
SELECTED_PASSWORD=$($DIALOG --title "Enter new password for Pi-hole admin" --passwordbox "" 7 50 3>&1 1>&2 2>&3)
if [[ -n $SELECTED_PASSWORD ]]; then
docker exec -it "${container}" sh -c "sudo pihole -a -p ${SELECTED_PASSWORD}" >/dev/null
fi
;;
status)
[[ "${container}" ]] || [[ "${image}" ]] && return 0
;;
esac
}

0 comments on commit 5a5de0b

Please sign in to comment.