mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Merge pull request #3702 from pi-hole/tweak/os_check_output
Display more meaningful exit message if `dig` command fails during os_check
This commit is contained in:
commit
b81cbaa088
2 changed files with 52 additions and 14 deletions
|
@ -396,14 +396,20 @@ check_critical_program_versions() {
|
|||
os_check() {
|
||||
# This function gets a list of supported OS versions from a TXT record at versions.pi-hole.net
|
||||
# and determines whether or not the script is running on one of those systems
|
||||
local remote_os_domain valid_os valid_version detected_os detected_version
|
||||
local remote_os_domain valid_os valid_version detected_os detected_version cmdResult digReturnCode response
|
||||
remote_os_domain="versions.pi-hole.net"
|
||||
|
||||
detected_os=$(grep "\bID\b" /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
|
||||
IFS=" " read -r -a supportedOS < <(dig +short -t txt ${remote_os_domain} @ns1.pi-hole.net | tr -d '"')
|
||||
cmdResult="$(dig +short -t txt ${remote_os_domain} @ns1.pi-hole.net 2>&1; echo $?)"
|
||||
#Get the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
# 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%%=*}"
|
||||
|
@ -423,7 +429,9 @@ os_check() {
|
|||
fi
|
||||
done
|
||||
|
||||
# Display findings back to the user
|
||||
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}"
|
||||
|
||||
|
|
|
@ -182,18 +182,27 @@ os_check() {
|
|||
if [ "$PIHOLE_SKIP_OS_CHECK" != true ]; then
|
||||
# This function gets a list of supported OS versions from a TXT record at versions.pi-hole.net
|
||||
# and determines whether or not the script is running on one of those systems
|
||||
local remote_os_domain valid_os valid_version detected_os detected_version display_warning
|
||||
local remote_os_domain valid_os valid_version valid_response detected_os detected_version display_warning cmdResult digReturnCode response
|
||||
remote_os_domain="versions.pi-hole.net"
|
||||
|
||||
detected_os=$(grep "\bID\b" /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
detected_version=$(grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"')
|
||||
|
||||
IFS=" " read -r -a supportedOS < <(dig +short -t txt ${remote_os_domain} @ns1.pi-hole.net | tr -d '"')
|
||||
cmdResult="$(dig +short -t txt ${remote_os_domain} @ns1.pi-hole.net 2>&1; echo $?)"
|
||||
#Get the return code of the previous command (last line)
|
||||
digReturnCode="${cmdResult##*$'\n'}"
|
||||
|
||||
if [ ${#supportedOS[@]} -eq 0 ]; then
|
||||
printf " %b %bRetrieval of supported OS failed. Please contact support. %b\\n" "${CROSS}" "${COL_LIGHT_RED}" "${COL_NC}"
|
||||
exit 1
|
||||
if [ ! "${digReturnCode}" == "0" ]; then
|
||||
valid_response=false
|
||||
else
|
||||
# Dig returned 0 code, so get the actual response, and loop through it to determine if the detected variables above are valid
|
||||
response="${cmdResult%%$'\n'*}"
|
||||
# If the value of ${result} is a single 0, then this is the return code, not the response. Response is blank
|
||||
if [ "${response}" == 0 ]; then
|
||||
valid_response=false
|
||||
fi
|
||||
|
||||
IFS=" " read -r -a supportedOS < <(echo "${response}" | tr -d '"')
|
||||
for distro_and_versions in "${supportedOS[@]}"
|
||||
do
|
||||
distro_part="${distro_and_versions%%=*}"
|
||||
|
@ -214,23 +223,44 @@ os_check() {
|
|||
done
|
||||
fi
|
||||
|
||||
if [ "$valid_os" = true ] && [ "$valid_version" = true ]; then
|
||||
if [ "$valid_os" = true ] && [ "$valid_version" = true ] && [ ! "$valid_response" = false ]; then
|
||||
display_warning=false
|
||||
fi
|
||||
|
||||
if [ "$display_warning" != false ]; then
|
||||
printf " %b %bUnsupported OS detected: %s %s%b\\n" "${CROSS}" "${COL_LIGHT_RED}" "${detected_os^}" "${detected_version}" "${COL_NC}"
|
||||
printf " https://docs.pi-hole.net/main/prerequesites/#supported-operating-systems\\n"
|
||||
if [ "$valid_response" = false ]; then
|
||||
|
||||
if [ "${digReturnCode}" -eq 0 ]; then
|
||||
errStr="dig succeeded, but response was blank. Please contact support"
|
||||
else
|
||||
errStr="dig failed with return code ${digReturnCode}"
|
||||
fi
|
||||
printf " %b %bRetrieval of supported OS list failed. %s. %b\\n" "${CROSS}" "${COL_LIGHT_RED}" "${errStr}" "${COL_NC}"
|
||||
printf " %bUnable to determine if the detected OS (%s %s) is supported%b\\n" "${COL_LIGHT_RED}" "${detected_os^}" "${detected_version}" "${COL_NC}"
|
||||
printf " Possible causes for this include:\\n"
|
||||
printf " - Firewall blocking certain DNS lookups from Pi-hole device\\n"
|
||||
printf " - ns1.pi-hole.net being blocked (required to obtain TXT record from versions.pi-hole.net containing supported operating systems)\\n"
|
||||
printf " - Other internet connectivity issues\\n"
|
||||
else
|
||||
printf " %b %bUnsupported OS detected: %s %s%b\\n" "${CROSS}" "${COL_LIGHT_RED}" "${detected_os^}" "${detected_version}" "${COL_NC}"
|
||||
printf " If you are seeing this message and you do have a supported OS, please contact support.\\n"
|
||||
fi
|
||||
printf "\\n"
|
||||
printf " %bhttps://docs.pi-hole.net/main/prerequesites/#supported-operating-systems%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
printf "\\n"
|
||||
printf " If you wish to attempt to continue anyway, you can try one of the following commands to skip this check:\\n"
|
||||
printf "\\n"
|
||||
printf " e.g: If you are seeing this message on a fresh install, you can run:\\n"
|
||||
printf " 'curl -sSL https://install.pi-hole.net | PIHOLE_SKIP_OS_CHECK=true sudo -E bash'\\n"
|
||||
printf " %bcurl -sSL https://install.pi-hole.net | PIHOLE_SKIP_OS_CHECK=true sudo -E bash%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
printf "\\n"
|
||||
printf " If you are seeing this message after having run pihole -up:\\n"
|
||||
printf " 'PIHOLE_SKIP_OS_CHECK=true sudo -E pihole -r'\\n"
|
||||
printf " %bPIHOLE_SKIP_OS_CHECK=true sudo -E pihole -r%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
printf " (In this case, your previous run of pihole -up will have already updated the local repository)\\n"
|
||||
printf "\\n"
|
||||
printf " It is possible that the installation will still fail at this stage due to an unsupported configuration.\\n"
|
||||
printf " If that is the case, you can feel free to ask the community on Discourse with the %bCommunity Help%b category:\\n" "${COL_LIGHT_RED}" "${COL_NC}"
|
||||
printf " https://discourse.pi-hole.net/c/bugs-problems-issues/community-help/\\n"
|
||||
printf " %bhttps://discourse.pi-hole.net/c/bugs-problems-issues/community-help/%b\\n" "${COL_LIGHT_GREEN}" "${COL_NC}"
|
||||
printf "\\n"
|
||||
exit 1
|
||||
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue