From 4567f264b4b8002d58a9b57c4a10165d543afe91 Mon Sep 17 00:00:00 2001 From: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> Date: Mon, 11 Jul 2022 11:45:09 -0700 Subject: [PATCH 01/39] Fix errors in README.md Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dbe91972..4cca6d44 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,11 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. -- **Easy-to-install**: our versatile installer walks you through the process and takes less than ten minutes +- **Easy-to-install**: our versatile installer walks you through the installation process that takes less than ten minutes - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) -- **Robust**: a command line interface that is quality assured for interoperability +- **Robust**: a command-line interface that is quality assured for interoperability - **Insightful**: a beautiful responsive Web Interface dashboard to view and control your Pi-hole - **Versatile**: can optionally function as a [DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026), ensuring *all* your devices are protected automatically - **Scalable**: [capable of handling hundreds of millions of queries](https://pi-hole.net/2017/05/24/how-much-traffic-can-pi-hole-handle/) when installed on server-grade hardware @@ -58,7 +58,7 @@ Please refer to the [Pi-hole docker repo](https://github.com/pi-hole/docker-pi-h ## [Post-install: Make your network take advantage of Pi-hole](https://docs.pi-hole.net/main/post-install/) -Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245) which ensures that all devices connecting to your network will have content blocked without any further intervention. +Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245). This router configuration ensures that all devices connecting to your network will have content blocked without any further intervention. If your router does not support setting the DNS server, you can [use Pi-hole's built-in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026); be sure to disable DHCP on your router first (if it has that feature available). @@ -68,7 +68,7 @@ As a last resort, you can manually set each device to use Pi-hole as their DNS s ## Pi-hole is free but powered by your support -There are many reoccurring costs involved with maintaining free, open source, and privacy-respecting software; expenses which [our volunteer developers](https://github.com/orgs/pi-hole/people) pitch in to cover out-of-pocket. This is just one example of how strongly we feel about our software and the importance of keeping it maintained. +There are many reoccurring costs involved with maintaining free, open-source, and privacy-respecting software; expenses which [our volunteer developers](https://github.com/orgs/pi-hole/people) pitch in to cover out-of-pocket. This is just one example of how strongly we feel about our software and the importance of keeping it maintained. Make no mistake: **your support is absolutely vital to help keep us innovating!** @@ -130,9 +130,9 @@ Some of the statistics you can integrate include: Access the API via [`telnet`](https://github.com/pi-hole/FTL), the Web (`admin/api.php`) and Command Line (`pihole -c -j`). You can find out [more details over here](https://discourse.pi-hole.net/t/pi-hole-api/1863). -### The Command Line Interface +### The Command-Line Interface -The [pihole](https://docs.pi-hole.net/core/pihole-command/) command has all the functionality necessary to fully administer the Pi-hole, without the need of the Web Interface. It's fast, user-friendly, and auditable by anyone with an understanding of `bash`. +The [pihole](https://docs.pi-hole.net/core/pihole-command/) command has all the functionality necessary to fully administer the Pi-hole, without the need for the Web Interface. It's fast, user-friendly, and auditable by anyone with an understanding of `bash`. Some notable features include: From 3a226576450f6d652a529f016cca9a01866e7a28 Mon Sep 17 00:00:00 2001 From: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> Date: Mon, 11 Jul 2022 14:54:19 -0700 Subject: [PATCH 02/39] Update README.md Co-authored-by: Adam Warner Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cca6d44..a8eff739 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ Please refer to the [Pi-hole docker repo](https://github.com/pi-hole/docker-pi-h ## [Post-install: Make your network take advantage of Pi-hole](https://docs.pi-hole.net/main/post-install/) -Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245). This router configuration ensures that all devices connecting to your network will have content blocked without any further intervention. +Once the installer has been run, you will need to [configure your router to have **DHCP clients use Pi-hole as their DNS server**](https://discourse.pi-hole.net/t/how-do-i-configure-my-devices-to-use-pi-hole-as-their-dns-server/245). This router configuration will ensure that all devices connecting to your network will have content blocked without any further intervention. If your router does not support setting the DNS server, you can [use Pi-hole's built-in DHCP server](https://discourse.pi-hole.net/t/how-do-i-use-pi-holes-built-in-dhcp-server-and-why-would-i-want-to/3026); be sure to disable DHCP on your router first (if it has that feature available). From 7ab96642557e367b784cb7a2b31cc0226ff2b8f8 Mon Sep 17 00:00:00 2001 From: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> Date: Mon, 11 Jul 2022 14:55:15 -0700 Subject: [PATCH 03/39] Update README.md Co-authored-by: Adam Warner Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8eff739..e4141d43 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. -- **Easy-to-install**: our versatile installer walks you through the installation process that takes less than ten minutes +- **Easy-to-install**: our versatile installer walks you through the installation process, and takes less than ten minutes - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) From c90d8284efb256d0c285fed7cc8e13e0edd1df59 Mon Sep 17 00:00:00 2001 From: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> Date: Tue, 12 Jul 2022 16:20:17 -0700 Subject: [PATCH 04/39] Update README.md Signed-off-by: Rauf Shimarov <55862995+Rauf00@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e4141d43..c95df263 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. -- **Easy-to-install**: our versatile installer walks you through the installation process, and takes less than ten minutes +- **Easy-to-install**: our dialogs walk you through simple installation process in less than ten minutes - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) From 56527e5dd94d3878bf0b467abef7c4bbe9c5491d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 5 Oct 2022 23:13:25 +0200 Subject: [PATCH 05/39] Add get_remote_version() to updatechecker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index a9d7523e..32e41880 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -20,6 +20,10 @@ function get_local_version() { git describe --long --dirty --tags 2> /dev/null || return 1 } +function get_remote_version() { + curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1 +} + # Source the setupvars config file # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf @@ -52,19 +56,19 @@ if [[ "$2" == "remote" ]]; then sleep 30 fi - GITHUB_CORE_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" + GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - GITHUB_WEB_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/AdminLTE/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" + GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" fi - GITHUB_FTL_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/FTL/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" + GITHUB_FTL_VERSION="$(get_remote_version FTL)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" if [[ "${DOCKER_TAG}" ]]; then - GITHUB_DOCKER_VERSION="$(curl -s 'https://api.github.com/repos/pi-hole/docker-pi-hole/releases/latest' 2> /dev/null | jq --raw-output .tag_name)" + GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi From 18d28533eb30b15e0a1b8a99af2cdc8fc13567a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 12:36:17 +0200 Subject: [PATCH 06/39] Update local and remote versions at the same time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeCheckout.sh | 13 ++---- advanced/Scripts/update.sh | 3 +- advanced/Scripts/updatecheck.sh | 75 +++++++++++++++--------------- advanced/Templates/pihole.cron | 6 +-- automated install/basic-install.sh | 3 +- 5 files changed, 47 insertions(+), 53 deletions(-) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 8c4c6db3..cf57800c 100755 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -42,11 +42,6 @@ warning1() { esac } -updateCheckFunc() { - /opt/pihole/updatecheck.sh - /opt/pihole/updatecheck.sh x remote -} - checkout() { local corebranches local webbranches @@ -169,8 +164,8 @@ checkout() { exit 1 fi checkout_pull_branch "${webInterfaceDir}" "${2}" - # Force an update of the updatechecker - updateCheckFunc + # Update local and remote versions via updatechecker + /opt/pihole/updatecheck.sh elif [[ "${1}" == "ftl" ]] ; then local path local oldbranch @@ -185,8 +180,8 @@ checkout() { FTLinstall "${binary}" restart_service pihole-FTL enable_service pihole-FTL - # Force an update of the updatechecker - updateCheckFunc + # Update local and remote versions via updatechecker + /opt/pihole/updatecheck.sh else echo " ${CROSS} Requested branch \"${2}\" is not available" ftlbranches=( $(git ls-remote https://github.com/pi-hole/ftl | grep 'heads' | sed 's/refs\/heads\///;s/ //g' | awk '{print $2}') ) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 609a054b..c41c9232 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -216,9 +216,8 @@ main() { fi if [[ "${FTL_update}" == true || "${core_update}" == true || "${web_update}" == true ]]; then - # Force an update of the updatechecker + # Update local and remote versions via updatechecker /opt/pihole/updatecheck.sh - /opt/pihole/updatecheck.sh x remote echo -e " ${INFO} Local version file information updated." fi diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 32e41880..64f1e7ef 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -28,7 +28,7 @@ function get_remote_version() { # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf -# Source the utils file +# Source the utils file for addOrEditKeyValPair() # shellcheck disable=SC1091 . /opt/pihole/utils.sh @@ -50,54 +50,55 @@ if [[ ! "${DOCKER_TAG}" =~ $regex ]]; then unset DOCKER_TAG fi -if [[ "$2" == "remote" ]]; then - - if [[ "$3" == "reboot" ]]; then +# used in cronjob +if [[ "$1" == "reboot" ]]; then sleep 30 - fi +fi + + +# get local versions - GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" - addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" +CORE_BRANCH="$(get_local_branch /etc/.pihole)" +addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" - addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" - fi +if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + WEB_BRANCH="$(get_local_branch /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" +fi - GITHUB_FTL_VERSION="$(get_remote_version FTL)" - addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" +FTL_BRANCH="$(pihole-FTL branch)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" - if [[ "${DOCKER_TAG}" ]]; then - GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" - addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" - fi +CORE_VERSION="$(get_local_version /etc/.pihole)" +addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" -else +if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + WEB_VERSION="$(get_local_version /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}" +fi - CORE_BRANCH="$(get_local_branch /etc/.pihole)" - addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" +FTL_VERSION="$(pihole-FTL version)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - WEB_BRANCH="$(get_local_branch /var/www/html/admin)" - addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" - fi +if [[ "${DOCKER_TAG}" ]]; then + addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" +fi - FTL_BRANCH="$(pihole-FTL branch)" - addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" - CORE_VERSION="$(get_local_version /etc/.pihole)" - addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" +# get remote versions - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - WEB_VERSION="$(get_local_version /var/www/html/admin)" - addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}" - fi +GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" - FTL_VERSION="$(pihole-FTL version)" - addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" +if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" +fi - if [[ "${DOCKER_TAG}" ]]; then - addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" - fi +GITHUB_FTL_VERSION="$(get_remote_version FTL)" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" +if [[ "${DOCKER_TAG}" ]]; then + GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi diff --git a/advanced/Templates/pihole.cron b/advanced/Templates/pihole.cron index 336a66fe..c62d31ab 100644 --- a/advanced/Templates/pihole.cron +++ b/advanced/Templates/pihole.cron @@ -28,6 +28,6 @@ @reboot root /usr/sbin/logrotate --state /var/lib/logrotate/pihole /etc/pihole/logrotate -# Pi-hole: Grab remote version every 24 hours -59 17 * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote -@reboot root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker remote reboot +# Pi-hole: Grab remote and local version every 24 hours +59 17 * * * root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker +@reboot root PATH="$PATH:/usr/sbin:/usr/local/bin/" pihole updatechecker reboot diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f3df72e6..f128a7c9 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2694,9 +2694,8 @@ main() { # Download and compile the aggregated block list runGravity - # Force an update of the updatechecker + # Update local and remote versions via updatechecker /opt/pihole/updatecheck.sh - /opt/pihole/updatecheck.sh x remote if [[ "${useUpdateVars}" == false ]]; then displayFinalMessage "${pw}" From 888e44e53d81f505f958322f411cfcc96269f4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 14:17:28 +0200 Subject: [PATCH 07/39] Add hash functions to updatecheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 64f1e7ef..85bba45d 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -15,15 +15,25 @@ function get_local_branch() { } function get_local_version() { - # Return active branch + # Return active version cd "${1}" 2> /dev/null || return 1 git describe --long --dirty --tags 2> /dev/null || return 1 } +function get_local_hash() { + cd "${1}" 2> /dev/null || return 1 + git rev-parse --short HEAD || return 1 +} + function get_remote_version() { curl -s "https://api.github.com/repos/pi-hole/${1}/releases/latest" 2> /dev/null | jq --raw-output .tag_name || return 1 } + +function get_remote_hash(){ + git ls-remote "https://github.com/pi-hole/${1}" --tags "${2}" | awk '{print substr($0, 0,9);}' || return 1 +} + # Source the setupvars config file # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf @@ -61,14 +71,23 @@ fi CORE_BRANCH="$(get_local_branch /etc/.pihole)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" +CORE_HASH="$(get_local_hash /etc/.pihole)" +addOrEditKeyValPair "${VERSION_FILE}" "CORE_HASH" "${CORE_HASH}" + if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then WEB_BRANCH="$(get_local_branch /var/www/html/admin)" addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" + + WEB_HASH="$(get_local_hash /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" fi FTL_BRANCH="$(pihole-FTL branch)" addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" +FTL_HASH="$(pihole-FTL -v | cut -d "-" -f2)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}" + CORE_VERSION="$(get_local_version /etc/.pihole)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" @@ -90,14 +109,23 @@ fi GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" +GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}" + if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" + + GITHUB_WEB_HASH="$(get_remote_hash AdminLTE "${WEB_BRANCH}")" + addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_HASH" "${GITHUB_WEB_HASH}" fi GITHUB_FTL_VERSION="$(get_remote_version FTL)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" +GITHUB_FTL_HASH="$(get_remote_hash FTL "${FTL_BRANCH}")" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_HASH" "${GITHUB_FTL_HASH}" + if [[ "${DOCKER_TAG}" ]]; then GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" From d7f7ef99652c5b91a3b6fc3c9134d6c4e9fe55bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 14:37:56 +0200 Subject: [PATCH 08/39] Only create VERSION_FILE if it does not exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 85bba45d..7241cddb 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -49,8 +49,10 @@ rm -f "/etc/pihole/localversions" # Create new versions file if it does not exist VERSION_FILE="/etc/pihole/versions" -touch "${VERSION_FILE}" -chmod 644 "${VERSION_FILE}" +if [ ! -f ${VERSION_FILE} ]; then + touch "${VERSION_FILE}" + chmod 644 "${VERSION_FILE}" +fi # if /pihole.docker.tag file exists, we will use it's value later in this script DOCKER_TAG=$(cat /pihole.docker.tag 2>/dev/null) From 2dc599f266d06ac2ec11af77c307da1504041078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 17:58:58 +0200 Subject: [PATCH 09/39] Simplify version.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 175 ++++++++++-------------------------- 1 file changed, 47 insertions(+), 128 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 7f44d35e..72bfd632 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -8,140 +8,63 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -# Variables -DEFAULT="-1" -COREGITDIR="/etc/.pihole/" -WEBGITDIR="/var/www/html/admin/" - # Source the setupvars config file # shellcheck disable=SC1091 source /etc/pihole/setupVars.conf -getLocalVersion() { - # FTL requires a different method - if [[ "$1" == "FTL" ]]; then - pihole-FTL version - return 0 - fi +# Sourece the versions file poupulated by updatechecker.sh +cachedVersions="/etc/pihole/versions" - # Get the tagged version of the local repository - local directory="${1}" - local version +if [ -f ${cachedVersions} ]; then + # shellcheck disable=SC1090 + . "$cachedVersions" +else + echo "Could not find /etc/pihole/versons. Exiting." + exit 1 +fi - cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } - version=$(git describe --tags --always || echo "$DEFAULT") - if [[ "${version}" =~ ^v ]]; then - echo "${version}" - elif [[ "${version}" == "${DEFAULT}" ]]; then - echo "ERROR" - return 1 - else - echo "Untagged" - fi +getLocalVersion() { + case ${1} in + "pi-hole" ) echo "${CORE_VERSION}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_VERSION}";; + "FTL" ) echo "${FTL_VERSION}";; + esac return 0 } getLocalHash() { - # Local FTL hash does not exist on filesystem - if [[ "$1" == "FTL" ]]; then - echo "N/A" - return 0 - fi - - # Get the short hash of the local repository - local directory="${1}" - local hash - - cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } - hash=$(git rev-parse --short HEAD || echo "$DEFAULT") - if [[ "${hash}" == "${DEFAULT}" ]]; then - echo "ERROR" - return 1 - else - echo "${hash}" - fi + case ${1} in + "pi-hole" ) echo "${CORE_HASH}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_HASH}";; + "FTL" ) echo "${FTL_HASH}";; + esac return 0 } getRemoteHash(){ - # Remote FTL hash is not applicable - if [[ "$1" == "FTL" ]]; then - echo "N/A" - return 0 - fi - - local daemon="${1}" - local branch="${2}" - - hash=$(git ls-remote --heads "https://github.com/pi-hole/${daemon}" | \ - awk -v bra="$branch" '$0~bra {print substr($0,0,8);exit}') - if [[ -n "$hash" ]]; then - echo "$hash" - else - echo "ERROR" - return 1 - fi + case ${1} in + "pi-hole" ) echo "${GITHUB_CORE_HASH}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_HASH}";; + "FTL" ) echo "${GITHUB_FTL_HASH}";; + esac return 0 } getRemoteVersion(){ - # Get the version from the remote origin - local daemon="${1}" - local version - local cachedVersions - cachedVersions="/etc/pihole/versions" - - #If the above file exists, then we can read from that. Prevents overuse of GitHub API - if [[ -f "$cachedVersions" ]]; then - - # shellcheck disable=SC1090 - . "$cachedVersions" - - case $daemon in - "pi-hole" ) echo "${GITHUB_CORE_VERSION}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";; - "FTL" ) echo "${GITHUB_FTL_VERSION}";; - esac - - return 0 - fi - - version=$(curl --silent --fail "https://api.github.com/repos/pi-hole/${daemon}/releases/latest" | \ - awk -F: '$1 ~/tag_name/ { print $2 }' | \ - tr -cd '[[:alnum:]]._-') - if [[ "${version}" =~ ^v ]]; then - echo "${version}" - else - echo "ERROR" - return 1 - fi + case ${1} in + "pi-hole" ) echo "${GITHUB_CORE_VERSION}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";; + "FTL" ) echo "${GITHUB_FTL_VERSION}";; + esac return 0 } getLocalBranch(){ - # Get the checked out branch of the local directory - local directory="${1}" - local branch - - # Local FTL btranch is stored in /etc/pihole/ftlbranch - if [[ "$1" == "FTL" ]]; then - branch="$(pihole-FTL branch)" - else - cd "${directory}" 2> /dev/null || { echo "${DEFAULT}"; return 1; } - branch=$(git rev-parse --abbrev-ref HEAD || echo "$DEFAULT") - fi - if [[ ! "${branch}" =~ ^v ]]; then - if [[ "${branch}" == "master" ]]; then - echo "" - elif [[ "${branch}" == "HEAD" ]]; then - echo "in detached HEAD state at " - else - echo "${branch} " - fi - else - # Branch started in "v" - echo "release " - fi + case ${1} in + "pi-hole" ) echo "${CORE_BRANCH}";; + "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_BRANCH}";; + "FTL" ) echo "${FTL_BRANCH}";; + esac return 0 } @@ -151,30 +74,26 @@ versionOutput() { return 1 fi - [[ "$1" == "pi-hole" ]] && GITDIR=$COREGITDIR - [[ "$1" == "AdminLTE" ]] && GITDIR=$WEBGITDIR - [[ "$1" == "FTL" ]] && GITDIR="FTL" - - [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion $GITDIR) && branch=$(getLocalBranch $GITDIR) - [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "$1") + [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}") + [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "${1}") if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then - [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "$GITDIR") && branch=$(getLocalBranch $GITDIR) - [[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "$1" "$(cd "$GITDIR" 2> /dev/null && git rev-parse --abbrev-ref HEAD)") + [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") + [[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "${1}") fi if [[ -n "$current" ]] && [[ -n "$latest" ]]; then - output="${1^} version is $branch$current (Latest: $latest)" + output="${1^} version is $branch $current (Latest: $latest)" elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then - output="Current ${1^} version is $branch$current" + output="Current ${1^} version is $branch $current (Latest: N/A)" elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then - output="Latest ${1^} version is $latest" - elif [[ "$curHash" == "N/A" ]] || [[ "$latHash" == "N/A" ]]; then - output="${1^} hash is not applicable" + output="Latest ${1^} version is $latest (Current: N/A)" + elif [[ -z "$curHash" ]] && [[ -z "$latHash" ]]; then + output="No hash info available" elif [[ -n "$curHash" ]] && [[ -n "$latHash" ]]; then - output="${1^} hash is $curHash (Latest: $latHash)" + output="Local ${1^} hash of branch $branch is $curHash (Remote: $latHash)" elif [[ -n "$curHash" ]] && [[ -z "$latHash" ]]; then - output="Current ${1^} hash is $curHash" + output="Current local ${1^} hash of branch $branch is $curHash (Remote: N/A)" elif [[ -z "$curHash" ]] && [[ -n "$latHash" ]]; then - output="Latest ${1^} hash is $latHash" + output="Latest remote ${1^} hash of branch $branch is $latHash (Local: N/A)" else errorOutput return 1 From a478f2460b33d3298d0ee1d9f5bf564c0fc68e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 21:50:07 +0200 Subject: [PATCH 10/39] POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 79 +++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 42 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 72bfd632..e91a66e5 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Pi-hole: A black hole for Internet advertisements # (c) 2017 Pi-hole, LLC (https://pi-hole.net) # Network-wide ad blocking via your own hardware. @@ -10,7 +10,7 @@ # Source the setupvars config file # shellcheck disable=SC1091 -source /etc/pihole/setupVars.conf +. /etc/pihole/setupVars.conf # Sourece the versions file poupulated by updatechecker.sh cachedVersions="/etc/pihole/versions" @@ -25,81 +25,76 @@ fi getLocalVersion() { case ${1} in - "pi-hole" ) echo "${CORE_VERSION}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_VERSION}";; + "Pi-hole" ) echo "${CORE_VERSION}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION}";; "FTL" ) echo "${FTL_VERSION}";; esac - return 0 } getLocalHash() { case ${1} in - "pi-hole" ) echo "${CORE_HASH}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_HASH}";; + "Pi-hole" ) echo "${CORE_HASH}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH}";; "FTL" ) echo "${FTL_HASH}";; esac - return 0 } getRemoteHash(){ case ${1} in - "pi-hole" ) echo "${GITHUB_CORE_HASH}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_HASH}";; + "Pi-hole" ) echo "${GITHUB_CORE_HASH}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH}";; "FTL" ) echo "${GITHUB_FTL_HASH}";; esac - return 0 } getRemoteVersion(){ case ${1} in - "pi-hole" ) echo "${GITHUB_CORE_VERSION}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${GITHUB_WEB_VERSION}";; + "Pi-hole" ) echo "${GITHUB_CORE_VERSION}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION}";; "FTL" ) echo "${GITHUB_FTL_VERSION}";; esac - return 0 } getLocalBranch(){ case ${1} in - "pi-hole" ) echo "${CORE_BRANCH}";; - "AdminLTE" ) [[ "${INSTALL_WEB_INTERFACE}" == true ]] && echo "${WEB_BRANCH}";; + "Pi-hole" ) echo "${CORE_BRANCH}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH}";; "FTL" ) echo "${FTL_BRANCH}";; esac - return 0 } versionOutput() { - if [[ "$1" == "AdminLTE" && "${INSTALL_WEB_INTERFACE}" != true ]]; then + if [ "$1" = "AdminLTE" ] && [ "${INSTALL_WEB_INTERFACE}" != true ]; then echo " WebAdmin not installed" return 1 fi - [[ "$2" == "-c" ]] || [[ "$2" == "--current" ]] || [[ -z "$2" ]] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}") - [[ "$2" == "-l" ]] || [[ "$2" == "--latest" ]] || [[ -z "$2" ]] && latest=$(getRemoteVersion "${1}") - if [[ "$2" == "-h" ]] || [[ "$2" == "--hash" ]]; then - [[ "$3" == "-c" ]] || [[ "$3" == "--current" ]] || [[ -z "$3" ]] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") - [[ "$3" == "-l" ]] || [[ "$3" == "--latest" ]] || [[ -z "$3" ]] && latHash=$(getRemoteHash "${1}") + [ "$2" = "-c" ] || [ "$2" = "--current" ] || [ -z "$2" ] && current=$(getLocalVersion "${1}") && branch=$(getLocalBranch "${1}") + [ "$2" = "-l" ] || [ "$2" = "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "${1}") + if [ "$2" = "--hash" ]; then + [ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") + [ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") fi - if [[ -n "$current" ]] && [[ -n "$latest" ]]; then - output="${1^} version is $branch $current (Latest: $latest)" - elif [[ -n "$current" ]] && [[ -z "$latest" ]]; then - output="Current ${1^} version is $branch $current (Latest: N/A)" - elif [[ -z "$current" ]] && [[ -n "$latest" ]]; then - output="Latest ${1^} version is $latest (Current: N/A)" - elif [[ -z "$curHash" ]] && [[ -z "$latHash" ]]; then - output="No hash info available" - elif [[ -n "$curHash" ]] && [[ -n "$latHash" ]]; then - output="Local ${1^} hash of branch $branch is $curHash (Remote: $latHash)" - elif [[ -n "$curHash" ]] && [[ -z "$latHash" ]]; then - output="Current local ${1^} hash of branch $branch is $curHash (Remote: N/A)" - elif [[ -z "$curHash" ]] && [[ -n "$latHash" ]]; then - output="Latest remote ${1^} hash of branch $branch is $latHash (Local: N/A)" + if [ -n "$current" ] && [ -n "$latest" ]; then + output="${1} version is $branch $current (Latest: $latest)" + elif [ -n "$current" ] && [ -z "$latest" ]; then + output="Current ${1} version is $branch $current" + elif [ -z "$current" ] && [ -n "$latest" ]; then + output="Latest ${1} version is $latest" + elif [ -n "$curHash" ] && [ -n "$latHash" ]; then + output="Local ${1} hash of branch $branch is $curHash (Remote: $latHash)" + elif [ -n "$curHash" ] && [ -z "$latHash" ]; then + output="Current local ${1} hash of branch $branch is $curHash" + elif [ -z "$curHash" ] && [ -n "$latHash" ]; then + output="Latest remote ${1} hash of branch $branch is $latHash" + elif [ -z "$curHash" ] && [ -z "$latHash" ]; then + output="Hashes for ${1} not available" else errorOutput return 1 fi - [[ -n "$output" ]] && echo " $output" + [ -n "$output" ] && echo " $output" } errorOutput() { @@ -108,9 +103,9 @@ errorOutput() { } defaultOutput() { - versionOutput "pi-hole" "$@" + versionOutput "Pi-hole" "$@" - if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + if [ "${INSTALL_WEB_INTERFACE}" = true ]; then versionOutput "AdminLTE" "$@" fi @@ -118,7 +113,7 @@ defaultOutput() { } helpFunc() { - echo "Usage: pihole -v [repo | option] [option] + echo "Usage: piho && lle -v [repo | option] [option] Example: 'pihole -v -p -l' Show Pi-hole, Admin Console & FTL versions @@ -136,7 +131,7 @@ Options: } case "${1}" in - "-p" | "--pihole" ) shift; versionOutput "pi-hole" "$@";; + "-p" | "--pihole" ) shift; versionOutput "Pi-hole" "$@";; "-a" | "--admin" ) shift; versionOutput "AdminLTE" "$@";; "-f" | "--ftl" ) shift; versionOutput "FTL" "$@";; "-h" | "--help" ) helpFunc;; From 79c0b446e194c4d7f2be249a9e250be987e7601b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 21:55:49 +0200 Subject: [PATCH 11/39] Set missing data to N/A MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index e91a66e5..1044d63f 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -25,41 +25,41 @@ fi getLocalVersion() { case ${1} in - "Pi-hole" ) echo "${CORE_VERSION}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION}";; - "FTL" ) echo "${FTL_VERSION}";; + "Pi-hole" ) echo "${CORE_VERSION:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_VERSION:=N/A}";; + "FTL" ) echo "${FTL_VERSION:=N/A}";; esac } getLocalHash() { case ${1} in - "Pi-hole" ) echo "${CORE_HASH}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH}";; - "FTL" ) echo "${FTL_HASH}";; + "Pi-hole" ) echo "${CORE_HASH:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_HASH:=N/A}";; + "FTL" ) echo "${FTL_HASH:=N/A}";; esac } getRemoteHash(){ case ${1} in - "Pi-hole" ) echo "${GITHUB_CORE_HASH}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH}";; - "FTL" ) echo "${GITHUB_FTL_HASH}";; + "Pi-hole" ) echo "${GITHUB_CORE_HASH:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_HASH:=N/A}";; + "FTL" ) echo "${GITHUB_FTL_HASH:=N/A}";; esac } getRemoteVersion(){ case ${1} in - "Pi-hole" ) echo "${GITHUB_CORE_VERSION}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION}";; - "FTL" ) echo "${GITHUB_FTL_VERSION}";; + "Pi-hole" ) echo "${GITHUB_CORE_VERSION:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${GITHUB_WEB_VERSION:=N/A}";; + "FTL" ) echo "${GITHUB_FTL_VERSION:=N/A}";; esac } getLocalBranch(){ case ${1} in - "Pi-hole" ) echo "${CORE_BRANCH}";; - "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH}";; - "FTL" ) echo "${FTL_BRANCH}";; + "Pi-hole" ) echo "${CORE_BRANCH:=N/A}";; + "AdminLTE" ) [ "${INSTALL_WEB_INTERFACE}" = true ] && echo "${WEB_BRANCH:=N/A}";; + "FTL" ) echo "${FTL_BRANCH:=N/A}";; esac } @@ -73,7 +73,7 @@ versionOutput() { [ "$2" = "-l" ] || [ "$2" = "--latest" ] || [ -z "$2" ] && latest=$(getRemoteVersion "${1}") if [ "$2" = "--hash" ]; then [ "$3" = "-c" ] || [ "$3" = "--current" ] || [ -z "$3" ] && curHash=$(getLocalHash "${1}") && branch=$(getLocalBranch "${1}") - [ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") + [ "$3" = "-l" ] || [ "$3" = "--latest" ] || [ -z "$3" ] && latHash=$(getRemoteHash "${1}") && branch=$(getLocalBranch "${1}") fi if [ -n "$current" ] && [ -n "$latest" ]; then output="${1} version is $branch $current (Latest: $latest)" From 9471c69882ff549598f4f92735bd031532991ccd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 6 Oct 2022 22:08:57 +0200 Subject: [PATCH 12/39] Fix spelling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index 1044d63f..cef2132a 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -12,14 +12,14 @@ # shellcheck disable=SC1091 . /etc/pihole/setupVars.conf -# Sourece the versions file poupulated by updatechecker.sh +# Source the versions file poupulated by updatechecker.sh cachedVersions="/etc/pihole/versions" if [ -f ${cachedVersions} ]; then # shellcheck disable=SC1090 . "$cachedVersions" else - echo "Could not find /etc/pihole/versons. Exiting." + echo "Could not find /etc/pihole/versions. Exiting." exit 1 fi @@ -113,7 +113,7 @@ defaultOutput() { } helpFunc() { - echo "Usage: piho && lle -v [repo | option] [option] + echo "Usage: pihole -v [repo | option] [option] Example: 'pihole -v -p -l' Show Pi-hole, Admin Console & FTL versions From 9c51050283cc357543cc26df82a6596f5dc3dfdf Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 13 Sep 2022 00:58:10 +0000 Subject: [PATCH 13/39] basic-install.sh: Use `grep -E` instead of `egrep` Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d4c1ce77..99fac2cf 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -358,7 +358,7 @@ package_manager_detect() { # These variable names match the ones for apt-get. See above for an explanation of what they are for. PKG_INSTALL=("${PKG_MANAGER}" install -y) # CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting. - PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" + PKG_COUNT="${PKG_MANAGER} check-update | grep -E '(.i686|.x86|.noarch|.arm|.src)' | wc -l || true" OS_CHECK_DEPS=(grep bind-utils) INSTALLER_DEPS=(git dialog iproute newt procps-ng which chkconfig ca-certificates) PIHOLE_DEPS=(cronie curl findutils sudo unzip libidn2 psmisc libcap nmap-ncat jq) From e3db5fc601fe2536b818032cb4d3cbc59760200d Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 13 Sep 2022 00:20:01 +0000 Subject: [PATCH 14/39] basic-install.sh: Use `command -v` instead of `which` `command -v` is the standardized version of `which` and doesn't require any extra packages Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 99fac2cf..a29f3bd1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2267,7 +2267,7 @@ get_binary_name() { local rev rev=$(uname -m | sed "s/[^0-9]//g;") local lib - lib=$(ldd "$(which sh)" | grep -E '^\s*/lib' | awk '{ print $1 }') + lib=$(ldd "$(command -v sh)" | grep -E '^\s*/lib' | awk '{ print $1 }') if [[ "${lib}" == "/lib/ld-linux-aarch64.so.1" ]]; then printf "%b %b Detected AArch64 (64 Bit ARM) processor\\n" "${OVER}" "${TICK}" # set the binary to be used From e5695f862f52de00723ea87a875c9a2de2ce9971 Mon Sep 17 00:00:00 2001 From: a1346054 <36859588+a1346054@users.noreply.github.com> Date: Tue, 11 Oct 2022 14:35:11 +0000 Subject: [PATCH 15/39] test_any_automated_install.py: Use `command -v` instead of `which` Signed-off-by: a1346054 <36859588+a1346054@users.noreply.github.com> --- test/test_any_automated_install.py | 32 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 0fd80f7e..56c492da 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -619,8 +619,8 @@ def test_FTL_detect_aarch64_no_errors(host): """ # mock uname to return aarch64 platform mock_command("uname", {"-m": ("aarch64", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with aarch64 shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0")}, host) detectPlatform = host.run( @@ -647,8 +647,8 @@ def test_FTL_detect_armv4t_no_errors(host): """ # mock uname to return armv4t platform mock_command("uname", {"-m": ("armv4t", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with armv4t shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) detectPlatform = host.run( @@ -675,8 +675,8 @@ def test_FTL_detect_armv5te_no_errors(host): """ # mock uname to return armv5te platform mock_command("uname", {"-m": ("armv5te", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) detectPlatform = host.run( @@ -704,8 +704,8 @@ def test_FTL_detect_armv6l_no_errors(host): # mock uname to return armv6l platform mock_command("uname", {"-m": ("armv6l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( """ @@ -734,8 +734,8 @@ def test_FTL_detect_armv7l_no_errors(host): # mock uname to return armv7l platform mock_command("uname", {"-m": ("armv7l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( """ @@ -763,8 +763,8 @@ def test_FTL_detect_armv8a_no_errors(host): """ # mock uname to return armv8a platform mock_command("uname", {"-m": ("armv8a", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) detectPlatform = host.run( @@ -789,8 +789,8 @@ def test_FTL_detect_x86_64_no_errors(host): """ confirms only x86_64 package is downloaded for FTL engine """ - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -813,8 +813,8 @@ def test_FTL_detect_unknown_no_errors(host): """confirms only generic package is downloaded for FTL engine""" # mock uname to return generic platform mock_command("uname", {"-m": ("mips", "0")}, host) - # mock `which sh` to return `/bin/sh` - mock_command("which", {"sh": ("/bin/sh", "0")}, host) + # mock `command -v sh` to return `/bin/sh` + mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh From 5c090d25e1df555a8723347916fd305f5c0f6a6c Mon Sep 17 00:00:00 2001 From: MichaIng Date: Tue, 11 Oct 2022 22:18:31 +0200 Subject: [PATCH 16/39] Fix ldd sh mock in tests Since "command" is a shell internal, it cannot be mocked, done via /usr/local/bin override. Since Debian containers ship without /bin => /usr/bin symlink, while all other containers do, the "ldd" mock needs to be applied for both paths, then. Signed-off-by: MichaIng --- test/test_any_automated_install.py | 70 ++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 56c492da..e6673bb5 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -619,10 +619,15 @@ def test_FTL_detect_aarch64_no_errors(host): """ # mock uname to return aarch64 platform mock_command("uname", {"-m": ("aarch64", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with aarch64 shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0"), + "/usr/bin/sh": ("/lib/ld-linux-aarch64.so.1", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -647,10 +652,15 @@ def test_FTL_detect_armv4t_no_errors(host): """ # mock uname to return armv4t platform mock_command("uname", {"-m": ("armv4t", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with armv4t shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -675,10 +685,15 @@ def test_FTL_detect_armv5te_no_errors(host): """ # mock uname to return armv5te platform mock_command("uname", {"-m": ("armv5te", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -704,9 +719,14 @@ def test_FTL_detect_armv6l_no_errors(host): # mock uname to return armv6l platform mock_command("uname", {"-m": ("armv6l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -734,9 +754,14 @@ def test_FTL_detect_armv7l_no_errors(host): # mock uname to return armv7l platform mock_command("uname", {"-m": ("armv7l", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -763,10 +788,15 @@ def test_FTL_detect_armv8a_no_errors(host): """ # mock uname to return armv8a platform mock_command("uname", {"-m": ("armv8a", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) # mock ldd to respond with ld-linux-armhf shared library - mock_command("ldd", {"/bin/sh": ("/lib/ld-linux-armhf.so.3", "0")}, host) + mock_command( + "ldd", + { + "/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + "/usr/bin/sh": ("/lib/ld-linux-armhf.so.3", "0"), + }, + host, + ) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -789,8 +819,6 @@ def test_FTL_detect_x86_64_no_errors(host): """ confirms only x86_64 package is downloaded for FTL engine """ - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh @@ -813,8 +841,6 @@ def test_FTL_detect_unknown_no_errors(host): """confirms only generic package is downloaded for FTL engine""" # mock uname to return generic platform mock_command("uname", {"-m": ("mips", "0")}, host) - # mock `command -v sh` to return `/bin/sh` - mock_command("command", {"-v sh": ("/bin/sh", "0")}, host) detectPlatform = host.run( """ source /opt/pihole/basic-install.sh From 4c0a94d2b987016df3b80f1533046c9a8ade7e3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 13 Oct 2022 14:16:56 +0200 Subject: [PATCH 17/39] Don't rely on pihole -v output but query github to get the lastest versions in debug script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 51 +++++++++++++++++---------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index dbf56709..d2b1cc3c 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -242,12 +242,12 @@ compare_local_version_to_git_version() { local pihole_component="${2}" # If we are checking the Core versions, if [[ "${pihole_component}" == "Core" ]]; then - # We need to search for "Pi-hole" when using pihole -v - local search_term="Pi-hole" + # set the github repo name + local repo_name="pi-hole" elif [[ "${pihole_component}" == "Web" ]]; then - # We need to search for "AdminLTE" so store it in a variable as well + # set the github repo name #shellcheck disable=2034 - local search_term="AdminLTE" + local repo_name="adminlte" fi # Display what we are checking echo_current_diagnostic "${pihole_component} version" @@ -261,26 +261,28 @@ compare_local_version_to_git_version() { log_write "${COL_RED}Could not cd into ${git_dir}$COL_NC" if git status &> /dev/null; then # The current version the user is on - local remote_version - remote_version=$(git describe --tags --abbrev=0); + local local_version + local_version=$(git describe --tags --abbrev=0); # What branch they are on - local remote_branch - remote_branch=$(git rev-parse --abbrev-ref HEAD); + local local_branch + local_branch=$(git rev-parse --abbrev-ref HEAD); # The commit they are on - local remote_commit - remote_commit=$(git describe --long --dirty --tags --always) + local local_commit + local_commit=$(git describe --long --dirty --tags --always) # Status of the repo local local_status local_status=$(git status -s) + local remote_version + remote_version=$(curl -s "https://api.github.com/repos/pi-hole/${repo_name}/releases/latest" 2> /dev/null | jq --raw-output .tag_name) # echo this information out to the user in a nice format - # If the current version matches what pihole -v produces, the user is up-to-date - if [[ "${remote_version}" == "$(pihole -v | awk '/${search_term}/ {print $6}' | cut -d ')' -f1)" ]]; then - log_write "${TICK} ${pihole_component}: ${COL_GREEN}${remote_version}${COL_NC}" + # If the current version matches the lastest tag, the user is up-to-date + if [[ "${local_version}" == "${remote_version}" ]]; then + log_write "${TICK} Version: ${COL_GREEN}${local_version}${COL_NC} [Latest: ${remote_version}]" # If not, else # echo the current version in yellow, signifying it's something to take a look at, but not a critical error # Also add a URL to an FAQ - log_write "${INFO} ${pihole_component}: ${COL_YELLOW}${remote_version:-Untagged}${COL_NC} (${FAQ_UPDATE_PI_HOLE})" + log_write "${INFO} Version: ${COL_YELLOW}${local_version:-Untagged}${COL_NC} [Latest: ${remote_version}] (${FAQ_UPDATE_PI_HOLE})" fi # Print the repo upstreams @@ -288,16 +290,16 @@ compare_local_version_to_git_version() { log_write "${INFO} Remotes: ${remotes//$'\n'/'\n '}" # If the repo is on the master branch, they are on the stable codebase - if [[ "${remote_branch}" == "master" ]]; then + if [[ "${local_branch}" == "master" ]]; then # so the color of the text is green - log_write "${INFO} Branch: ${COL_GREEN}${remote_branch}${COL_NC}" + log_write "${INFO} Branch: ${COL_GREEN}${local_branch}${COL_NC}" # If it is any other branch, they are in a development branch else # So show that in yellow, signifying it's something to take a look at, but not a critical error - log_write "${INFO} Branch: ${COL_YELLOW}${remote_branch:-Detached}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" + log_write "${INFO} Branch: ${COL_YELLOW}${local_branch:-Detached}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" fi # echo the current commit - log_write "${INFO} Commit: ${remote_commit}" + log_write "${INFO} Commit: ${local_commit}" # if `local_status` is non-null, then the repo is not clean, display details here if [[ ${local_status} ]]; then # Replace new lines in the status with 12 spaces to make the output cleaner @@ -331,21 +333,22 @@ compare_local_version_to_git_version() { } check_ftl_version() { - local ftl_name="FTL" - local FTL_VERSION FTL_COMMIT FTL_BRANCH - echo_current_diagnostic "${ftl_name} version" + local FTL_VERSION FTL_COMMIT FTL_BRANCH remote_version + echo_current_diagnostic "FTL version" # Use the built in command to check FTL's version FTL_VERSION=$(pihole-FTL -vv | grep -m 1 Version | awk '{printf $2}') FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') + remote_version=$(curl -s 'https://api.github.com/repos/pi-hole/ftl/releases/latest' 2> /dev/null | jq --raw-output .tag_name) + # Compare the current FTL version to the remote version - if [[ "${FTL_VERSION}" == "$(pihole -v | awk '/FTL/ {print $6}' | cut -d ')' -f1)" ]]; then + if [[ "${FTL_VERSION}" == "${remote_version}" ]]; then # If they are the same, FTL is up-to-date - log_write "${TICK} ${ftl_name}: ${COL_GREEN}${FTL_VERSION}${COL_NC}" + log_write "${TICK} Version: ${COL_GREEN}${FTL_VERSION}${COL_NC} [Latest: ${remote_version}]" else # If not, show it in yellow, signifying there is an update - log_write "${INFO} ${ftl_name}: ${COL_YELLOW}${FTL_VERSION}${COL_NC} (${FAQ_UPDATE_PI_HOLE})" + log_write "${INFO} Version: ${COL_YELLOW}${FTL_VERSION}${COL_NC} [Latest: ${remote_version}] (${FAQ_UPDATE_PI_HOLE})" fi # If they use the master branch, they are on the stable codebase From 5c61f6cb65e32c2d96d10bdf31efe5440b1e01cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 08:43:39 +0200 Subject: [PATCH 18/39] Remove checkout hint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index d2b1cc3c..3799448b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -48,7 +48,6 @@ OBFUSCATED_PLACEHOLDER="" # FAQ URLs for use in showing the debug log FAQ_UPDATE_PI_HOLE="${COL_CYAN}https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249${COL_NC}" -FAQ_CHECKOUT_COMMAND="${COL_CYAN}https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#checkout${COL_NC}" FAQ_HARDWARE_REQUIREMENTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#ports${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}" @@ -73,7 +72,6 @@ WEB_SERVER_LOG_DIRECTORY="/var/log/lighttpd" WEB_SERVER_CONFIG_DIRECTORY="/etc/lighttpd" HTML_DIRECTORY="/var/www/html" WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin" -#BLOCK_PAGE_DIRECTORY="${HTML_DIRECTORY}/pihole" SHM_DIRECTORY="/dev/shm" ETC="/etc" @@ -275,7 +273,7 @@ compare_local_version_to_git_version() { local remote_version remote_version=$(curl -s "https://api.github.com/repos/pi-hole/${repo_name}/releases/latest" 2> /dev/null | jq --raw-output .tag_name) # echo this information out to the user in a nice format - # If the current version matches the lastest tag, the user is up-to-date + # If the current version matches the latest tag, the user is up-to-date if [[ "${local_version}" == "${remote_version}" ]]; then log_write "${TICK} Version: ${COL_GREEN}${local_version}${COL_NC} [Latest: ${remote_version}]" # If not, @@ -296,7 +294,7 @@ compare_local_version_to_git_version() { # If it is any other branch, they are in a development branch else # So show that in yellow, signifying it's something to take a look at, but not a critical error - log_write "${INFO} Branch: ${COL_YELLOW}${local_branch:-Detached}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" + log_write "${INFO} Branch: ${COL_YELLOW}${local_branch:-Detached}${COL_NC}" fi # echo the current commit log_write "${INFO} Commit: ${local_commit}" @@ -358,7 +356,7 @@ check_ftl_version() { # If it is any other branch, they are in a development branch else # So show that in yellow, signifying it's something to take a look at, but not a critical error - log_write "${INFO} Branch: ${COL_YELLOW}${FTL_BRANCH}${COL_NC} (${FAQ_CHECKOUT_COMMAND})" + log_write "${INFO} Branch: ${COL_YELLOW}${FTL_BRANCH}${COL_NC}" fi # echo the current commit From d85982dc515282da985f87f60ca0dd36ae51e3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 10:29:14 +0200 Subject: [PATCH 19/39] Use versions file instead of github api to get latest version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3799448b..59b2af8b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -238,14 +238,19 @@ compare_local_version_to_git_version() { local git_dir="${1}" # The named component of the project (Core or Web) local pihole_component="${2}" + # If we are checking the Core versions, if [[ "${pihole_component}" == "Core" ]]; then - # set the github repo name - local repo_name="pi-hole" + local remote_version + # remote version is taken from /etc/pihole/versions (sourced above) + remote_version="${GITHUB_CORE_VERSION}" elif [[ "${pihole_component}" == "Web" ]]; then - # set the github repo name - #shellcheck disable=2034 - local repo_name="adminlte" + local remote_version + # remote version is taken from /etc/pihole/versions (sourced above) + remote_version="${GITHUB_WEB_VERSION}" + fi + if [ -z "${remote_version}" ]; then + remote_version="N/A" fi # Display what we are checking echo_current_diagnostic "${pihole_component} version" @@ -270,8 +275,6 @@ compare_local_version_to_git_version() { # Status of the repo local local_status local_status=$(git status -s) - local remote_version - remote_version=$(curl -s "https://api.github.com/repos/pi-hole/${repo_name}/releases/latest" 2> /dev/null | jq --raw-output .tag_name) # echo this information out to the user in a nice format # If the current version matches the latest tag, the user is up-to-date if [[ "${local_version}" == "${remote_version}" ]]; then @@ -338,7 +341,11 @@ check_ftl_version() { FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') - remote_version=$(curl -s 'https://api.github.com/repos/pi-hole/ftl/releases/latest' 2> /dev/null | jq --raw-output .tag_name) + # remote version is taken from /etc/pihole/versions (sourced above) + remote_version="${GITHUB_FTL_VERSION}" + if [ -z "${remote_version}" ]; then + remote_version="N/A" + fi # Compare the current FTL version to the remote version if [[ "${FTL_VERSION}" == "${remote_version}" ]]; then From c84be5de61210f9466552d2b6b6c25afd9797fb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 13:18:12 +0200 Subject: [PATCH 20/39] Reorganize by component rather then source MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/updatecheck.sh | 67 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/advanced/Scripts/updatecheck.sh b/advanced/Scripts/updatecheck.sh index 7241cddb..938be6cd 100755 --- a/advanced/Scripts/updatecheck.sh +++ b/advanced/Scripts/updatecheck.sh @@ -49,10 +49,8 @@ rm -f "/etc/pihole/localversions" # Create new versions file if it does not exist VERSION_FILE="/etc/pihole/versions" -if [ ! -f ${VERSION_FILE} ]; then - touch "${VERSION_FILE}" - chmod 644 "${VERSION_FILE}" -fi +touch "${VERSION_FILE}" +chmod 644 "${VERSION_FILE}" # if /pihole.docker.tag file exists, we will use it's value later in this script DOCKER_TAG=$(cat /pihole.docker.tag 2>/dev/null) @@ -68,7 +66,10 @@ if [[ "$1" == "reboot" ]]; then fi -# get local versions +# get Core versions + +CORE_VERSION="$(get_local_version /etc/.pihole)" +addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" CORE_BRANCH="$(get_local_branch /etc/.pihole)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" @@ -76,59 +77,57 @@ addOrEditKeyValPair "${VERSION_FILE}" "CORE_BRANCH" "${CORE_BRANCH}" CORE_HASH="$(get_local_hash /etc/.pihole)" addOrEditKeyValPair "${VERSION_FILE}" "CORE_HASH" "${CORE_HASH}" -if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then - WEB_BRANCH="$(get_local_branch /var/www/html/admin)" - addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" - - WEB_HASH="$(get_local_hash /var/www/html/admin)" - addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" -fi +GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" -FTL_BRANCH="$(pihole-FTL branch)" -addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" +GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")" +addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}" -FTL_HASH="$(pihole-FTL -v | cut -d "-" -f2)" -addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}" -CORE_VERSION="$(get_local_version /etc/.pihole)" -addOrEditKeyValPair "${VERSION_FILE}" "CORE_VERSION" "${CORE_VERSION}" +# get Web versions if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then + WEB_VERSION="$(get_local_version /var/www/html/admin)" addOrEditKeyValPair "${VERSION_FILE}" "WEB_VERSION" "${WEB_VERSION}" -fi - -FTL_VERSION="$(pihole-FTL version)" -addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" - -if [[ "${DOCKER_TAG}" ]]; then - addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" -fi - - -# get remote versions -GITHUB_CORE_VERSION="$(get_remote_version pi-hole)" -addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_VERSION" "${GITHUB_CORE_VERSION}" + WEB_BRANCH="$(get_local_branch /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_BRANCH" "${WEB_BRANCH}" -GITHUB_CORE_HASH="$(get_remote_hash pi-hole "${CORE_BRANCH}")" -addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_CORE_HASH" "${GITHUB_CORE_HASH}" + WEB_HASH="$(get_local_hash /var/www/html/admin)" + addOrEditKeyValPair "${VERSION_FILE}" "WEB_HASH" "${WEB_HASH}" -if [[ "${INSTALL_WEB_INTERFACE}" == true ]]; then GITHUB_WEB_VERSION="$(get_remote_version AdminLTE)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_VERSION" "${GITHUB_WEB_VERSION}" GITHUB_WEB_HASH="$(get_remote_hash AdminLTE "${WEB_BRANCH}")" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_WEB_HASH" "${GITHUB_WEB_HASH}" + fi +# get FTL versions + +FTL_VERSION="$(pihole-FTL version)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_VERSION" "${FTL_VERSION}" + +FTL_BRANCH="$(pihole-FTL branch)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_BRANCH" "${FTL_BRANCH}" + +FTL_HASH="$(pihole-FTL -v | cut -d "-" -f2)" +addOrEditKeyValPair "${VERSION_FILE}" "FTL_HASH" "${FTL_HASH}" + GITHUB_FTL_VERSION="$(get_remote_version FTL)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_VERSION" "${GITHUB_FTL_VERSION}" GITHUB_FTL_HASH="$(get_remote_hash FTL "${FTL_BRANCH}")" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_FTL_HASH" "${GITHUB_FTL_HASH}" + +# get Docker versions + if [[ "${DOCKER_TAG}" ]]; then + addOrEditKeyValPair "${VERSION_FILE}" "DOCKER_VERSION" "${DOCKER_TAG}" + GITHUB_DOCKER_VERSION="$(get_remote_version docker-pi-hole)" addOrEditKeyValPair "${VERSION_FILE}" "GITHUB_DOCKER_VERSION" "${GITHUB_DOCKER_VERSION}" fi From 52283478c842c03301d737ccc0da177d6f84bf14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 14 Oct 2022 13:21:31 +0200 Subject: [PATCH 21/39] Run pihole updatechecker if versions file is not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/version.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh index cef2132a..5c74fa05 100755 --- a/advanced/Scripts/version.sh +++ b/advanced/Scripts/version.sh @@ -19,8 +19,10 @@ if [ -f ${cachedVersions} ]; then # shellcheck disable=SC1090 . "$cachedVersions" else - echo "Could not find /etc/pihole/versions. Exiting." - exit 1 + echo "Could not find /etc/pihole/versions. Running update now." + pihole updatechecker + # shellcheck disable=SC1090 + . "$cachedVersions" fi getLocalVersion() { From d737948f64f9f638a5c0d7d58330f3065699c446 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 14 Oct 2022 14:11:19 -0300 Subject: [PATCH 22/39] Add `versions` file to the REQUIRED_FILES list Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index dbf56709..51994dc7 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -91,6 +91,7 @@ PIHOLE_LOGROTATE_FILE="${PIHOLE_DIRECTORY}/logrotate" PIHOLE_SETUP_VARS_FILE="${PIHOLE_DIRECTORY}/setupVars.conf" PIHOLE_FTL_CONF_FILE="${PIHOLE_DIRECTORY}/pihole-FTL.conf" PIHOLE_CUSTOM_HOSTS_FILE="${PIHOLE_DIRECTORY}/custom.list" +PIHOLE_VERSIONS_FILE="${PIHOLE_DIRECTORY}/versions" # Read the value of an FTL config key. The value is printed to stdout. # @@ -162,7 +163,8 @@ REQUIRED_FILES=("${PIHOLE_CRON_FILE}" "${PIHOLE_WEB_SERVER_ERROR_LOG_FILE}" "${RESOLVCONF}" "${DNSMASQ_CONF}" -"${PIHOLE_CUSTOM_HOSTS_FILE}") +"${PIHOLE_CUSTOM_HOSTS_FILE}" +"${PIHOLE_VERSIONS_FILE}") DISCLAIMER="This process collects information from your Pi-hole, and optionally uploads it to a unique and random directory on tricorder.pi-hole.net. From 235673dac8433a5ce2ffa0ac13b5f281a9745f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 13 Oct 2022 21:21:40 +0200 Subject: [PATCH 23/39] Remove unused possibility to obfuscate pihole.log MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 60 ++------------------------------- 1 file changed, 2 insertions(+), 58 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index dbf56709..7f4c5eb0 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -44,8 +44,6 @@ fi # shellcheck disable=SC1091 . /etc/pihole/versions -OBFUSCATED_PLACEHOLDER="" - # FAQ URLs for use in showing the debug log FAQ_UPDATE_PI_HOLE="${COL_CYAN}https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249${COL_NC}" FAQ_CHECKOUT_COMMAND="${COL_CYAN}https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738#checkout${COL_NC}" @@ -54,7 +52,6 @@ FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prereq FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}" FAQ_GATEWAY="${COL_CYAN}https://discourse.pi-hole.net/t/why-is-a-default-gateway-important-for-pi-hole/3546${COL_NC}" FAQ_FTL_COMPATIBILITY="${COL_CYAN}https://github.com/pi-hole/FTL#compatibility-list${COL_NC}" -FAQ_BAD_ADDRESS="${COL_CYAN}https://discourse.pi-hole.net/t/why-do-i-see-bad-address-at-in-pihole-log/3972${COL_NC}" # Other URLs we may use FORUMS_URL="${COL_CYAN}https://discourse.pi-hole.net${COL_NC}" @@ -1381,49 +1378,8 @@ spinner(){ fi } -obfuscated_pihole_log() { - local pihole_log=("$@") - local line - local error_to_check_for - local line_to_obfuscate - local obfuscated_line - for line in "${pihole_log[@]}"; do - # A common error in the pihole.log is when there is a non-hosts formatted file - # that the DNS server is attempting to read. Since it's not formatted - # correctly, there will be an entry for "bad address at line n" - # So we can check for that here and highlight it in red so the user can see it easily - error_to_check_for=$(echo "${line}" | grep 'bad address at') - # Some users may not want to have the domains they visit sent to us - # To that end, we check for lines in the log that would contain a domain name - line_to_obfuscate=$(echo "${line}" | grep ': query\|: forwarded\|: reply') - # If the variable contains a value, it found an error in the log - if [[ -n ${error_to_check_for} ]]; then - # So we can print it in red to make it visible to the user - log_write " ${CROSS} ${COL_RED}${line}${COL_NC} (${FAQ_BAD_ADDRESS})" - else - # If the variable does not a value (the current default behavior), so do not obfuscate anything - if [[ -z ${OBFUSCATE} ]]; then - log_write " ${line}" - # Otherwise, a flag was passed to this command to obfuscate domains in the log - else - # So first check if there are domains in the log that should be obfuscated - if [[ -n ${line_to_obfuscate} ]]; then - # If there are, we need to use awk to replace only the domain name (the 6th field in the log) - # so we substitute the domain for the placeholder value - obfuscated_line=$(echo "${line_to_obfuscate}" | awk -v placeholder="${OBFUSCATED_PLACEHOLDER}" '{sub($6,placeholder); print $0}') - log_write " ${obfuscated_line}" - else - log_write " ${line}" - fi - fi - fi - done -} - analyze_pihole_log() { echo_current_diagnostic "Pi-hole log" - local pihole_log_head=() - local pihole_log_tail=() local pihole_log_permissions local logging_enabled @@ -1433,22 +1389,10 @@ analyze_pihole_log() { log_write "${INFO} Query logging is disabled" log_write "" fi - # Put the current Internal Field Separator into another variable so it can be restored later - OLD_IFS="$IFS" - # Get the lines that are in the file(s) and store them in an array for parsing later - IFS=$'\r\n' + pihole_log_permissions=$(ls -lhd "${PIHOLE_LOG}") log_write "${COL_GREEN}${pihole_log_permissions}${COL_NC}" - mapfile -t pihole_log_head < <(head -n 20 ${PIHOLE_LOG}) - log_write " ${COL_CYAN}-----head of $(basename ${PIHOLE_LOG})------${COL_NC}" - obfuscated_pihole_log "${pihole_log_head[@]}" - log_write "" - mapfile -t pihole_log_tail < <(tail -n 20 ${PIHOLE_LOG}) - log_write " ${COL_CYAN}-----tail of $(basename ${PIHOLE_LOG})------${COL_NC}" - obfuscated_pihole_log "${pihole_log_tail[@]}" - log_write "" - # Set the IFS back to what it was - IFS="$OLD_IFS" + head_tail_log "${PIHOLE_LOG}" 20 } curl_to_tricorder() { From 4c9401175c6273085e7c8d3e960a4fffaab28b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 15 Oct 2022 09:06:57 +0200 Subject: [PATCH 24/39] Remove check for latest version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 40 +++------------------------------ 1 file changed, 3 insertions(+), 37 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 59b2af8b..22406af1 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -47,7 +47,6 @@ fi OBFUSCATED_PLACEHOLDER="" # FAQ URLs for use in showing the debug log -FAQ_UPDATE_PI_HOLE="${COL_CYAN}https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249${COL_NC}" FAQ_HARDWARE_REQUIREMENTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#ports${COL_NC}" FAQ_HARDWARE_REQUIREMENTS_FIREWALLD="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#firewalld${COL_NC}" @@ -239,19 +238,6 @@ compare_local_version_to_git_version() { # The named component of the project (Core or Web) local pihole_component="${2}" - # If we are checking the Core versions, - if [[ "${pihole_component}" == "Core" ]]; then - local remote_version - # remote version is taken from /etc/pihole/versions (sourced above) - remote_version="${GITHUB_CORE_VERSION}" - elif [[ "${pihole_component}" == "Web" ]]; then - local remote_version - # remote version is taken from /etc/pihole/versions (sourced above) - remote_version="${GITHUB_WEB_VERSION}" - fi - if [ -z "${remote_version}" ]; then - remote_version="N/A" - fi # Display what we are checking echo_current_diagnostic "${pihole_component} version" # Store the error message in a variable in case we want to change and/or reuse it @@ -276,15 +262,7 @@ compare_local_version_to_git_version() { local local_status local_status=$(git status -s) # echo this information out to the user in a nice format - # If the current version matches the latest tag, the user is up-to-date - if [[ "${local_version}" == "${remote_version}" ]]; then - log_write "${TICK} Version: ${COL_GREEN}${local_version}${COL_NC} [Latest: ${remote_version}]" - # If not, - else - # echo the current version in yellow, signifying it's something to take a look at, but not a critical error - # Also add a URL to an FAQ - log_write "${INFO} Version: ${COL_YELLOW}${local_version:-Untagged}${COL_NC} [Latest: ${remote_version}] (${FAQ_UPDATE_PI_HOLE})" - fi + log_write "${TICK} Version: ${local_version}" # Print the repo upstreams remotes=$(git remote -v) @@ -334,27 +312,15 @@ compare_local_version_to_git_version() { } check_ftl_version() { - local FTL_VERSION FTL_COMMIT FTL_BRANCH remote_version + local FTL_VERSION FTL_COMMIT FTL_BRANCH echo_current_diagnostic "FTL version" # Use the built in command to check FTL's version FTL_VERSION=$(pihole-FTL -vv | grep -m 1 Version | awk '{printf $2}') FTL_BRANCH=$(pihole-FTL -vv | grep -m 1 Branch | awk '{printf $2}') FTL_COMMIT=$(pihole-FTL -vv | grep -m 1 Commit | awk '{printf $2}') - # remote version is taken from /etc/pihole/versions (sourced above) - remote_version="${GITHUB_FTL_VERSION}" - if [ -z "${remote_version}" ]; then - remote_version="N/A" - fi - # Compare the current FTL version to the remote version - if [[ "${FTL_VERSION}" == "${remote_version}" ]]; then - # If they are the same, FTL is up-to-date - log_write "${TICK} Version: ${COL_GREEN}${FTL_VERSION}${COL_NC} [Latest: ${remote_version}]" - else - # If not, show it in yellow, signifying there is an update - log_write "${INFO} Version: ${COL_YELLOW}${FTL_VERSION}${COL_NC} [Latest: ${remote_version}] (${FAQ_UPDATE_PI_HOLE})" - fi + log_write "${TICK} Version: ${FTL_VERSION}" # If they use the master branch, they are on the stable codebase if [[ "${FTL_BRANCH}" == "master" ]]; then From 429510e168ef585f22b5b63e3f21f5ca5150f291 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 15 Oct 2022 15:03:35 +0100 Subject: [PATCH 25/39] Update README.md Signed-off-by: Adam Warner --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c95df263..9e0503ba 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The Pi-hole® is a [DNS sinkhole](https://en.wikipedia.org/wiki/DNS_Sinkhole) that protects your devices from unwanted content without installing any client-side software. -- **Easy-to-install**: our dialogs walk you through simple installation process in less than ten minutes +- **Easy-to-install**: our dialogs walk you through the simple installation process in less than ten minutes - **Resolute**: content is blocked in _non-browser locations_, such as ad-laden mobile apps and smart TVs - **Responsive**: seamlessly speeds up the feel of everyday browsing by caching DNS queries - **Lightweight**: runs smoothly with [minimal hardware and software requirements](https://docs.pi-hole.net/main/prerequisites/) From 8b98fd06ed2be16dafb283b42810ec7171e81e4f Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Sun, 16 Oct 2022 15:54:24 -0300 Subject: [PATCH 26/39] Remove unused old code Signed-off-by: RD WebDesign --- gravity.sh | 86 +++++++++++++----------------------------------------- 1 file changed, 20 insertions(+), 66 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7c831b22..ea3160fe 100755 --- a/gravity.sh +++ b/gravity.sh @@ -720,72 +720,26 @@ gravity_DownloadBlocklistFromUrl() { # Parse source files into domains format gravity_ParseFileIntoDomains() { - local src="${1}" destination="${2}" firstLine - - # Determine if we are parsing a consolidated list - #if [[ "${src}" == "${piholeDir}/${matterAndLight}" ]]; then - # Remove comments and print only the domain name - # Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous - # This helps with that and makes it easier to read - # It also helps with debugging so each stage of the script can be researched more in depth - # 1) Remove carriage returns - # 2) Convert all characters to lowercase - # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) - # 4) Remove lines containing "/" - # 5) Remove leading tabs, spaces, etc. - # 6) Delete lines not matching domain names - < "${src}" tr -d '\r' | \ - tr '[:upper:]' '[:lower:]' | \ - sed 's/\s*#.*//g' | \ - sed -r '/(\/).*$/d' | \ - sed -r 's/^.*\s+//g' | \ - sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}" - chmod 644 "${destination}" - return 0 - #fi - - # Individual file parsing: Keep comments, while parsing domains from each line - # We keep comments to respect the list maintainer's licensing - read -r firstLine < "${src}" - - # Determine how to parse individual source file formats - if [[ "${firstLine,,}" =~ (adblock|ublock|^!) ]]; then - # Compare $firstLine against lower case words found in Adblock lists - echo -e " ${CROSS} Format: Adblock (list type not supported)" - elif grep -q "^address=/" "${src}" &> /dev/null; then - # Parse Dnsmasq format lists - echo -e " ${CROSS} Format: Dnsmasq (list type not supported)" - elif grep -q -E "^https?://" "${src}" &> /dev/null; then - # Parse URL list if source file contains "http://" or "https://" - # Scanning for "^IPv4$" is too slow with large (1M) lists on low-end hardware - echo -ne " ${INFO} Format: URL" - - awk ' - # Remove URL scheme, optional "username:password@", and ":?/;" - # The scheme must be matched carefully to avoid blocking the wrong URL - # in cases like: - # http://www.evil.com?http://www.good.com - # See RFC 3986 section 3.1 for details. - /[:?\/;]/ { gsub(/(^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(.*:.*@)?|[:?\/;].*)/, "", $0) } - # Skip lines which are only IPv4 addresses - /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/ { next } - # Print if nonempty - length { print } - ' "${src}" 2> /dev/null > "${destination}" - chmod 644 "${destination}" - - echo -e "${OVER} ${TICK} Format: URL" - else - # Default: Keep hosts/domains file in same format as it was downloaded - output=$( { mv "${src}" "${destination}"; } 2>&1 ) - chmod 644 "${destination}" - - if [[ ! -e "${destination}" ]]; then - echo -e "\\n ${CROSS} Unable to move tmp file to ${piholeDir} - ${output}" - gravity_Cleanup "error" - fi - fi + local src="${1}" destination="${2}" + + # Remove comments and print only the domain name + # Most of the lists downloaded are already in hosts file format but the spacing/formatting is not contiguous + # This helps with that and makes it easier to read + # It also helps with debugging so each stage of the script can be researched more in depth + # 1) Remove carriage returns + # 2) Convert all characters to lowercase + # 3) Remove comments (text starting with "#", include possible spaces before the hash sign) + # 4) Remove lines containing "/" + # 5) Remove leading tabs, spaces, etc. + # 6) Delete lines not matching domain names + < "${src}" tr -d '\r' | \ + tr '[:upper:]' '[:lower:]' | \ + sed 's/\s*#.*//g' | \ + sed -r '/(\/).*$/d' | \ + sed -r 's/^.*\s+//g' | \ + sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}" + chmod 644 "${destination}" + return 0 } # Report number of entries in a table From 528abc9c97b343bbfeba924b9b72bec560d11907 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Sun, 16 Oct 2022 19:36:56 -0300 Subject: [PATCH 27/39] Adding CentOS Stream 9 tests Signed-off-by: RD WebDesign --- .github/workflows/test.yml | 1 + test/_centos_9.Dockerfile | 18 ++++++++++++++++++ test/tox.centos_9.ini | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/_centos_9.Dockerfile create mode 100644 test/tox.centos_9.ini diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d1709bbf..daa18c85 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,6 +54,7 @@ jobs: ubuntu_20, ubuntu_22, centos_8, + centos_9, fedora_35, fedora_36, ] diff --git a/test/_centos_9.Dockerfile b/test/_centos_9.Dockerfile new file mode 100644 index 00000000..befa1584 --- /dev/null +++ b/test/_centos_9.Dockerfile @@ -0,0 +1,18 @@ +FROM quay.io/centos/centos:stream9 +RUN yum install -y git initscripts + +ENV GITDIR /etc/.pihole +ENV SCRIPTDIR /opt/pihole + +RUN mkdir -p $GITDIR $SCRIPTDIR /etc/pihole +ADD . $GITDIR +RUN cp $GITDIR/advanced/Scripts/*.sh $GITDIR/gravity.sh $GITDIR/pihole $GITDIR/automated\ install/*.sh $SCRIPTDIR/ +ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$SCRIPTDIR + +RUN true && \ + chmod +x $SCRIPTDIR/* + +ENV SKIP_INSTALL true +ENV OS_CHECK_DOMAIN_NAME dev-supportedos.pi-hole.net + +#sed '/# Start the installer/Q' /opt/pihole/basic-install.sh > /opt/pihole/stub_basic-install.sh && \ diff --git a/test/tox.centos_9.ini b/test/tox.centos_9.ini new file mode 100644 index 00000000..633fc5c4 --- /dev/null +++ b/test/tox.centos_9.ini @@ -0,0 +1,8 @@ +[tox] +envlist = py3 + +[testenv] +allowlist_externals = docker +deps = -rrequirements.txt +commands = docker build -f _centos_9.Dockerfile -t pytest_pihole:test_container ../ + pytest {posargs:-vv -n auto} ./test_any_automated_install.py ./test_any_utils.py ./test_centos_fedora_common_support.py ./test_centos_common_support.py From 85ffbcf05ee0083347d0ab1ce87cfdc19942c70f Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 17 Oct 2022 14:58:42 -0300 Subject: [PATCH 28/39] Allow replacing conflicting existing packages from testing image Signed-off-by: RD WebDesign --- test/_centos_9.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/_centos_9.Dockerfile b/test/_centos_9.Dockerfile index befa1584..6ccd18b6 100644 --- a/test/_centos_9.Dockerfile +++ b/test/_centos_9.Dockerfile @@ -1,5 +1,5 @@ FROM quay.io/centos/centos:stream9 -RUN yum install -y git initscripts +RUN yum install -y --allowerasing curl git initscripts ENV GITDIR /etc/.pihole ENV SCRIPTDIR /opt/pihole From 090727b1d34d485906c540442be2ebcad1904a6d Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 17 Oct 2022 15:24:49 -0300 Subject: [PATCH 29/39] Remove unnecessary return Signed-off-by: RD WebDesign --- gravity.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index ea3160fe..14732f31 100755 --- a/gravity.sh +++ b/gravity.sh @@ -739,7 +739,6 @@ gravity_ParseFileIntoDomains() { sed -r 's/^.*\s+//g' | \ sed -r '/([^\.]+\.)+[^\.]{2,}/!d' > "${destination}" chmod 644 "${destination}" - return 0 } # Report number of entries in a table From 21be1bd58e6e378ac0f5b8cd4069d78a68e4d836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 20 Oct 2022 06:53:13 +0200 Subject: [PATCH 30/39] Prevent CNAME loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e02e03f9..2dc2d4c5 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -729,7 +729,12 @@ AddCustomCNAMERecord() { if [[ -n "${validDomain}" ]]; then validTarget="$(checkDomain "${target}")" if [[ -n "${validTarget}" ]]; then - echo "cname=${validDomain},${validTarget}" >> "${dnscustomcnamefile}" + if [ "${validDomain}" = "${validTarget}" ]; then + echo " ${CROSS} Domain and target are the same!" + exit 1 + else + echo "cname=${validDomain},${validTarget}" >> "${dnscustomcnamefile}" + fi else echo " ${CROSS} Invalid Target Passed!" exit 1 From c322458dcb568604c94b6c359863b21fd88dc13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 21 Oct 2022 12:25:23 +0200 Subject: [PATCH 31/39] Escape dots in local DNS records/CNAMES before removing them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index e02e03f9..f4a452fe 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -627,6 +627,12 @@ checkDomain() echo "${validDomain}" } +escapeDots() +{ + escaped=$(sed 's/\./\\./g' <<< "$1" ) + echo "${escaped}" +} + addAudit() { shift # skip "-a" @@ -702,6 +708,7 @@ RemoveCustomDNSAddress() { validHost="$(checkDomain "${host}")" if [[ -n "${validHost}" ]]; then if valid_ip "${ip}" || valid_ip6 "${ip}" ; then + validHost=$(escapeDots "${validHost}") sed -i "/^${ip} ${validHost}$/Id" "${dnscustomfile}" else echo -e " ${CROSS} Invalid IP has been passed" @@ -755,7 +762,9 @@ RemoveCustomCNAMERecord() { if [[ -n "${validDomain}" ]]; then validTarget="$(checkDomain "${target}")" if [[ -n "${validTarget}" ]]; then - sed -i "/cname=${validDomain},${validTarget}$/Id" "${dnscustomcnamefile}" + validDomain=$(escapeDots "${validDomain}") + validTarget=$(escapeDots "${validTarget}") + sed -i "/^cname=${validDomain},${validTarget}$/Id" "${dnscustomcnamefile}" else echo " ${CROSS} Invalid Target Passed!" exit 1 From df3e9e5f5108636404e3dea80201868f02fc739c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 21 Oct 2022 14:31:16 +0200 Subject: [PATCH 32/39] Disable shellcheck as it suggests a bashism MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index f4a452fe..7c112d00 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -629,6 +629,8 @@ checkDomain() escapeDots() { + # shellcheck disable=SC2001 + # SH suggest bashism ${variable//search/replace} escaped=$(sed 's/\./\\./g' <<< "$1" ) echo "${escaped}" } From 128a3ab1becbdd4815a85a35ebeefeec1f7f6e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 22 Oct 2022 22:37:05 +0200 Subject: [PATCH 33/39] Go POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 7c112d00..53d631cd 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -629,9 +629,9 @@ checkDomain() escapeDots() { + # SC suggest bashism ${variable//search/replace} # shellcheck disable=SC2001 - # SH suggest bashism ${variable//search/replace} - escaped=$(sed 's/\./\\./g' <<< "$1" ) + escaped=$(echo "$1" | sed 's/\./\\./g') echo "${escaped}" } From c8c6533440126a4abf0dc4e2e1f4316e3ceb7d20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 29 Oct 2022 15:09:14 +0200 Subject: [PATCH 34/39] Add small explanation. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/webpage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/webpage.sh b/advanced/Scripts/webpage.sh index 2dc2d4c5..aec8917e 100755 --- a/advanced/Scripts/webpage.sh +++ b/advanced/Scripts/webpage.sh @@ -730,7 +730,7 @@ AddCustomCNAMERecord() { validTarget="$(checkDomain "${target}")" if [[ -n "${validTarget}" ]]; then if [ "${validDomain}" = "${validTarget}" ]; then - echo " ${CROSS} Domain and target are the same!" + echo " ${CROSS} Domain and target are the same. This would cause a DNS loop." exit 1 else echo "cname=${validDomain},${validTarget}" >> "${dnscustomcnamefile}" From 06cf7afbc2646706186f74694d223c392135824a Mon Sep 17 00:00:00 2001 From: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com> Date: Sat, 29 Oct 2022 17:52:24 +0200 Subject: [PATCH 35/39] Fix static IP not set Signed-off-by: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com> --- automated install/basic-install.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d4c1ce77..0fda391d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -828,8 +828,11 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Configure networking via dhcpcd setDHCPCD() { - # Check if the IP is already in the file - if grep -q "${IPV4_ADDRESS}" /etc/dhcpcd.conf; then + # Regex for matching a non-commented static ip address setting + local regex="^[ \t]*static ip_address[ \t]*=[ \t]*${IPV4_ADDRESS}[ \t]*$" + + # Check if static IP is already set in file + if grep -xq "${regex}" /etc/dhcpcd.conf; then printf " %b Static IP already configured\\n" "${INFO}" # If it's not, else From 122bc6b927faded08757e603f33ba560dbb2c8b5 Mon Sep 17 00:00:00 2001 From: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com> Date: Wed, 2 Nov 2022 22:35:39 +0100 Subject: [PATCH 36/39] Fix static IP not set because of in-line comment Signed-off-by: Stephan Pillhofer <43667664+StephanPillhofer@users.noreply.github.com> --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0fda391d..8edd4936 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -829,10 +829,10 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Configure networking via dhcpcd setDHCPCD() { # Regex for matching a non-commented static ip address setting - local regex="^[ \t]*static ip_address[ \t]*=[ \t]*${IPV4_ADDRESS}[ \t]*$" + local regex="^[ \t]*static ip_address[ \t]*=[ \t]*${IPV4_ADDRESS}" # Check if static IP is already set in file - if grep -xq "${regex}" /etc/dhcpcd.conf; then + if grep -q "${regex}" /etc/dhcpcd.conf; then printf " %b Static IP already configured\\n" "${INFO}" # If it's not, else From 2fd5b944ad4294d7894ff93a23f18db6baa12e2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 3 Nov 2022 22:01:37 +0100 Subject: [PATCH 37/39] Touch setupVars before writing to it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8edd4936..ea7052f3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1785,6 +1785,9 @@ create_pihole_user() { finalExports() { # set or update the variables in the file + # create the file if it does not exist + touch "${setupVars}" + addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}" From 67385b7ed43a2c68bc851b3329c72c838849beea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 9 Nov 2022 21:25:09 +0100 Subject: [PATCH 38/39] Touch files before addKey or addOrEditKeyValPair MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/utils.sh | 6 ++++++ automated install/basic-install.sh | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 1174fa62..37516472 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -31,6 +31,9 @@ addOrEditKeyValPair() { local key="${2}" local value="${3}" + # touch file to prevent grep error if file does not exist yet + touch "${file}" + if grep -q "^${key}=" "${file}"; then # Key already exists in file, modify the value sed -i "/^${key}=/c\\${key}=${value}" "${file}" @@ -51,6 +54,9 @@ addKey(){ local file="${1}" local key="${2}" + # touch file to prevent grep error if file does not exist yet + touch "${file}" + if ! grep -q "^${key}" "${file}"; then # Key does not exist, add it. echo "${key}" >> "${file}" diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index ea7052f3..8edd4936 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1785,9 +1785,6 @@ create_pihole_user() { finalExports() { # set or update the variables in the file - # create the file if it does not exist - touch "${setupVars}" - addOrEditKeyValPair "${setupVars}" "PIHOLE_INTERFACE" "${PIHOLE_INTERFACE}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_1" "${PIHOLE_DNS_1}" addOrEditKeyValPair "${setupVars}" "PIHOLE_DNS_2" "${PIHOLE_DNS_2}" From 7536c312ee7148734a520254f30c01050d04b416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 13 Nov 2022 21:53:59 +0100 Subject: [PATCH 39/39] Correctly identify process status in debug script on docker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 99ab6cbe..7ad92412 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -925,10 +925,21 @@ process_status(){ else # Otherwise, use the service command and mock the output of `systemctl is-active` local status_of_process - if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then - status_of_process="active" + + # If DOCKER_VERSION is set, the output is slightly different (s6 init system on Docker) + if [ -n "${DOCKER_VERSION}" ]; then + if service "${i}" status | grep -E '^up' &> /dev/null; then + status_of_process="active" + else + status_of_process="inactive" + fi else - status_of_process="inactive" + # non-Docker system + if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then + status_of_process="active" + else + status_of_process="inactive" + fi fi fi # and print it out to the user