Improve detection and display of supported/unsupported OS in debug script

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
pull/3434/head
Adam Warner 4 years ago
parent ee172cd6e9
commit 58724a38a9
No known key found for this signature in database
GPG Key ID: 872950F3ECF2B173

@ -393,53 +393,53 @@ check_critical_program_versions() {
get_program_version "php" get_program_version "php"
} }
is_os_supported() { os_check() {
local os_to_check="${1}" # This function gets a list of supported OS versions from a TXT record at versions.pi-hole.net
# Strip just the base name of the system using sed # and determines whether or not the script is running on one of those systems
# shellcheck disable=SC2001 local remote_os_domain valid_os valid_version detected_os_pretty detected_os detected_version
the_os=$(echo "${os_to_check}" | sed 's/ .*//') remote_os_domain="versions.pi-hole.net"
# If the variable is one of our supported OSes, valid_os=false
case "${the_os}" in valid_version=false
# Print it in green
"Raspbian") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";; detected_os_pretty=$(cat /etc/*release | grep PRETTY_NAME | cut -d '=' -f2- | tr -d '"')
"Ubuntu") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";; detected_os="${detected_os_pretty%% *}"
"Fedora") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";; detected_version=$(cat /etc/*release | grep VERSION_ID | cut -d '=' -f2- | tr -d '"')
"Debian") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";;
"CentOS") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";; mapfile -t supportedOS < <(dig +short -t txt ${remote_os_domain} | tr -d '"' | tr ' ' '\n')
# If not, show it in red and link to our software requirements page
*) log_write "${CROSS} ${COL_RED}${os_to_check}${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS})"; for i in "${supportedOS[@]}"
esac do
} os_part=$(echo "$i" | cut -d '=' -f1)
versions_part=$(echo "$i" | cut -d '=' -f2-)
if [[ "${detected_os}" =~ ${os_part} ]]; then
valid_os=true
mapfile -t supportedVer < <(echo "${versions_part}" | tr ',' '\n')
for x in "${supportedVer[@]}"
do
if [[ "${detected_version}" =~ $x ]];then
valid_version=true
break
fi
done
break
fi
done
get_distro_attributes() { # Display findings back to the user
# Put the current Internal Field Separator into another variable so it can be restored later if [ "$valid_os" = true ]; then
OLD_IFS="$IFS" log_write "${TICK} Distro: ${COL_GREEN}${detected_os}${COL_NC}"
# Store the distro info in an array and make it global since the OS won't change,
# but we'll keep it within the function for better unit testing
local distro_info
#shellcheck disable=SC2016
IFS=$'\r\n' command eval 'distro_info=( $(cat /etc/*release) )'
# Set a named variable for better readability if [ "$valid_version" = true ]; then
local distro_attribute log_write "${TICK} Version: ${COL_GREEN}${detected_version}${COL_NC}"
# For each line found in an /etc/*release file,
for distro_attribute in "${distro_info[@]}"; do
# store the key in a variable
local pretty_name_key
pretty_name_key=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f1)
# we need just the OS PRETTY_NAME,
if [[ "${pretty_name_key}" == "PRETTY_NAME" ]]; then
# so save in in a variable when we find it
PRETTY_NAME_VALUE=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f2- | tr -d '"')
# then pass it as an argument that checks if the OS is supported
is_os_supported "${PRETTY_NAME_VALUE}"
else else
# Since we only need the pretty name, we can just skip over anything that is not a match 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 fi
done else
# Set the IFS back to what it was log_write "${CROSS} Distro: ${COL_RED}${detected_os}${COL_NC}"
IFS="$OLD_IFS" log_write "${CROSS} Error: ${COL_RED}${detected_os} is not a supported distro (${FAQ_HARDWARE_REQUIREMENTS})${COL_NC}"
fi
} }
diagnose_operating_system() { diagnose_operating_system() {
@ -451,7 +451,7 @@ diagnose_operating_system() {
# If there is a /etc/*release file, it's probably a supported operating system, so we can # If there is a /etc/*release file, it's probably a supported operating system, so we can
if ls /etc/*release 1> /dev/null 2>&1; then if ls /etc/*release 1> /dev/null 2>&1; then
# display the attributes to the user from the function made earlier # display the attributes to the user from the function made earlier
get_distro_attributes os_check
else else
# If it doesn't exist, it's not a system we currently support and link to FAQ # If it doesn't exist, it's not a system we currently support and link to FAQ
log_write "${CROSS} ${COL_RED}${error_msg}${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS})" log_write "${CROSS} ${COL_RED}${error_msg}${COL_NC} (${FAQ_HARDWARE_REQUIREMENTS})"

@ -0,0 +1,5 @@
Raspbian=9,10
Ubuntu=16,18
Debian=9,10
Fedora=31,32
CentOS=7,8
Loading…
Cancel
Save