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 1/4] 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 2/4] 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 3/4] 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 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 4/4] 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