From 67f04787d6fc687809bc07d2d69e07ac8a265456 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 6 Dec 2022 14:39:06 -0300 Subject: [PATCH 1/6] Only compare OS versions if `dig` was successful Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 67 ++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 3cd782bf..979f5fb3 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -394,41 +394,46 @@ os_check() { # Extract dig response response="${cmdResult%%$'\n'*}" - IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"') - for distro_and_versions in "${supportedOS[@]}" - do - distro_part="${distro_and_versions%%=*}" - versions_part="${distro_and_versions##*=}" - - if [[ "${detected_os^^}" =~ ${distro_part^^} ]]; then - valid_os=true - IFS="," read -r -a supportedVer <<<"${versions_part}" - for version in "${supportedVer[@]}" - do - if [[ "${detected_version}" =~ $version ]]; then - valid_version=true - break - fi - done - break - fi - done - log_write "${INFO} dig return code: ${digReturnCode}" log_write "${INFO} dig response: ${response}" - if [ "$valid_os" = true ]; then - log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}" - - if [ "$valid_version" = true ]; then - log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}" - else - log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" - fi + if [ "${response}" -ne 0 ]; then + log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" + log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" else - log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"') + for distro_and_versions in "${supportedOS[@]}" + do + distro_part="${distro_and_versions%%=*}" + versions_part="${distro_and_versions##*=}" + + if [[ "${detected_os^^}" =~ ${distro_part^^} ]]; then + valid_os=true + IFS="," read -r -a supportedVer <<<"${versions_part}" + for version in "${supportedVer[@]}" + do + if [[ "${detected_version}" =~ $version ]]; then + valid_version=true + break + fi + done + break + fi + done + + if [ "$valid_os" = true ]; then + log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}" + + if [ "$valid_version" = true ]; then + log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}" + else + log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}" + log_write "${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + fi + else + log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" + log_write "${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + fi fi } From b4349b41ce88beeeabadc212cf05dd01bceb6f18 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 6 Dec 2022 15:42:36 -0300 Subject: [PATCH 2/6] Use the correct variable `digReturnCode` also use INFO instead of CROSS, because it's not an error. Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 979f5fb3..17447873 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -397,8 +397,8 @@ os_check() { log_write "${INFO} dig return code: ${digReturnCode}" log_write "${INFO} dig response: ${response}" - if [ "${response}" -ne 0 ]; then - log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" + if [ "${digReturnCode}" -ne 0 ]; then + log_write "${INFO} Distro: ${COL_RED}${detected_os^}${COL_NC}" log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" else IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"') From 8c2f56b0e6b6f65189af942b7fabb78610c49277 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 6 Dec 2022 17:38:38 -0300 Subject: [PATCH 3/6] Imporving the output from `os_check()` function - add red color to dig errors - reorder some output lines - add "Distro and version supported" on success Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 17447873..f370bd9f 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -394,12 +394,11 @@ os_check() { # Extract dig response response="${cmdResult%%$'\n'*}" - log_write "${INFO} dig return code: ${digReturnCode}" - log_write "${INFO} dig response: ${response}" - if [ "${digReturnCode}" -ne 0 ]; then - log_write "${INFO} Distro: ${COL_RED}${detected_os^}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" + log_write "${INFO} Distro: ${detected_os^}" + log_write "${CROSS} dig return code: ${COL_RED}${digReturnCode}${COL_NC}" + log_write "${CROSS} dig response: ${response}" + log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" else IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"') for distro_and_versions in "${supportedOS[@]}" @@ -421,19 +420,26 @@ os_check() { fi done + local finalmsg if [ "$valid_os" = true ]; then log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}" if [ "$valid_version" = true ]; then log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}" + finalmsg="${TICK} ${COL_GREEN}Distro and version supported${COL_NC}" else log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi else log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" - log_write "${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi + + # Print dig response and the final check result + log_write "${INFO} dig return code: ${COL_RED}${digReturnCode}${COL_NC}" + log_write "${INFO} dig response: ${response}" + log_write "${finalmsg}" fi } From a2069802426857b5ef788996d824dd6abcbeb3f4 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Tue, 6 Dec 2022 20:34:18 -0300 Subject: [PATCH 4/6] Fix parenthesis color Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index f370bd9f..c067682b 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -429,11 +429,11 @@ os_check() { finalmsg="${TICK} ${COL_GREEN}Distro and version supported${COL_NC}" else log_write "${CROSS} Version: ${COL_RED}${detected_version}${COL_NC}" - finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is supported but version ${detected_version} is currently unsupported ${COL_NC}(${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi else log_write "${CROSS} Distro: ${COL_RED}${detected_os^}${COL_NC}" - finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" + finalmsg="${CROSS} Error: ${COL_RED}${detected_os^} is not a supported distro ${COL_NC}(${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}" fi # Print dig response and the final check result From 1550f29f06a1925b51d183316f383d52b45e99f6 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Thu, 8 Dec 2022 19:58:00 -0300 Subject: [PATCH 5/6] Use GREEN if dig was successful Signed-off-by: RD WebDesign --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c067682b..9042e718 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -437,7 +437,7 @@ os_check() { fi # Print dig response and the final check result - log_write "${INFO} dig return code: ${COL_RED}${digReturnCode}${COL_NC}" + log_write "${INFO} dig return code: ${COL_GREEN}${digReturnCode}${COL_NC}" log_write "${INFO} dig response: ${response}" log_write "${finalmsg}" fi From fc83883934fab83cb6ec04978f711ef58701ac6e Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sun, 11 Dec 2022 14:31:44 +0000 Subject: [PATCH 6/6] Apply suggestions from code review Co-authored-by: yubiuser Signed-off-by: Adam Warner --- advanced/Scripts/piholeDebug.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 9042e718..c0264d1a 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -396,6 +396,7 @@ os_check() { if [ "${digReturnCode}" -ne 0 ]; then log_write "${INFO} Distro: ${detected_os^}" + log_write "${INFO} Version: ${detected_version}" log_write "${CROSS} dig return code: ${COL_RED}${digReturnCode}${COL_NC}" log_write "${CROSS} dig response: ${response}" log_write "${CROSS} Error: ${COL_RED}dig command failed - Unable to check OS${COL_NC}" @@ -437,7 +438,7 @@ os_check() { fi # Print dig response and the final check result - log_write "${INFO} dig return code: ${COL_GREEN}${digReturnCode}${COL_NC}" + log_write "${TICK} dig return code: ${COL_GREEN}${digReturnCode}${COL_NC}" log_write "${INFO} dig response: ${response}" log_write "${finalmsg}" fi