mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
Merge pull request #3434 from pi-hole/new/os_detect
Change OS Detection in debug script
This commit is contained in:
commit
5f9dac8d2b
2 changed files with 49 additions and 44 deletions
|
@ -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}";;
|
|
||||||
"Ubuntu") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";;
|
|
||||||
"Fedora") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";;
|
|
||||||
"Debian") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";;
|
|
||||||
"CentOS") log_write "${TICK} ${COL_GREEN}${os_to_check}${COL_NC}";;
|
|
||||||
# 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})";
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
get_distro_attributes() {
|
detected_os_pretty=$(cat /etc/*release | grep PRETTY_NAME | cut -d '=' -f2- | tr -d '"')
|
||||||
# Put the current Internal Field Separator into another variable so it can be restored later
|
detected_os="${detected_os_pretty%% *}"
|
||||||
OLD_IFS="$IFS"
|
detected_version=$(cat /etc/*release | grep VERSION_ID | cut -d '=' -f2- | tr -d '"')
|
||||||
# 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
|
IFS=" "; read -r -a supportedOS < <(dig +short -t txt ${remote_os_domain} | tr -d '"')
|
||||||
local distro_attribute
|
|
||||||
# For each line found in an /etc/*release file,
|
for i in "${supportedOS[@]}"
|
||||||
for distro_attribute in "${distro_info[@]}"; do
|
do
|
||||||
# store the key in a variable
|
os_part=$(echo "$i" | cut -d '=' -f1)
|
||||||
local pretty_name_key
|
versions_part=$(echo "$i" | cut -d '=' -f2-)
|
||||||
pretty_name_key=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f1)
|
|
||||||
# we need just the OS PRETTY_NAME,
|
if [[ "${detected_os}" =~ ${os_part} ]]; then
|
||||||
if [[ "${pretty_name_key}" == "PRETTY_NAME" ]]; then
|
valid_os=true
|
||||||
# so save in in a variable when we find it
|
IFS=","; read -r -a supportedVer <<<"${versions_part}"
|
||||||
PRETTY_NAME_VALUE=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f2- | tr -d '"')
|
for x in "${supportedVer[@]}"
|
||||||
# then pass it as an argument that checks if the OS is supported
|
do
|
||||||
is_os_supported "${PRETTY_NAME_VALUE}"
|
if [[ "${detected_version}" =~ $x ]];then
|
||||||
else
|
valid_version=true
|
||||||
# Since we only need the pretty name, we can just skip over anything that is not a match
|
break
|
||||||
:
|
fi
|
||||||
|
done
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# Set the IFS back to what it was
|
|
||||||
IFS="$OLD_IFS"
|
# Display findings back to the user
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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})"
|
||||||
|
|
5
supportedos.txt
Normal file
5
supportedos.txt
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
Raspbian=9,10
|
||||||
|
Ubuntu=16,18
|
||||||
|
Debian=9,10
|
||||||
|
Fedora=31,32
|
||||||
|
CentOS=7,8
|
Loading…
Reference in a new issue