mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-02-02 17:48:52 +00:00
Remove unused code from debug log and skip some tests inside containers (#5854)
This commit is contained in:
commit
0f318027fc
2 changed files with 65 additions and 50 deletions
|
@ -44,6 +44,14 @@ fi
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
. /etc/pihole/versions
|
. /etc/pihole/versions
|
||||||
|
|
||||||
|
# Read the value of an FTL config key. The value is printed to stdout.
|
||||||
|
get_ftl_conf_value() {
|
||||||
|
local key=$1
|
||||||
|
|
||||||
|
# Obtain setting from FTL directly
|
||||||
|
pihole-FTL --config "${key}"
|
||||||
|
}
|
||||||
|
|
||||||
# FAQ URLs for use in showing the debug log
|
# FAQ URLs for use in showing the debug log
|
||||||
FAQ_HARDWARE_REQUIREMENTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/${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_PORTS="${COL_CYAN}https://docs.pi-hole.net/main/prerequisites/#ports${COL_NC}"
|
||||||
|
@ -61,10 +69,10 @@ DNSMASQ_D_DIRECTORY="/etc/dnsmasq.d"
|
||||||
PIHOLE_DIRECTORY="/etc/pihole"
|
PIHOLE_DIRECTORY="/etc/pihole"
|
||||||
PIHOLE_SCRIPTS_DIRECTORY="/opt/pihole"
|
PIHOLE_SCRIPTS_DIRECTORY="/opt/pihole"
|
||||||
BIN_DIRECTORY="/usr/local/bin"
|
BIN_DIRECTORY="/usr/local/bin"
|
||||||
RUN_DIRECTORY="/run"
|
|
||||||
LOG_DIRECTORY="/var/log/pihole"
|
LOG_DIRECTORY="/var/log/pihole"
|
||||||
HTML_DIRECTORY="/var/www/html"
|
HTML_DIRECTORY="$(get_ftl_conf_value "webserver.paths.webroot")"
|
||||||
WEB_GIT_DIRECTORY="${HTML_DIRECTORY}/admin"
|
WEBHOME_PATH="$(get_ftl_conf_value "webserver.paths.webhome")"
|
||||||
|
WEB_GIT_DIRECTORY="${HTML_DIRECTORY}${WEBHOME_PATH}"
|
||||||
SHM_DIRECTORY="/dev/shm"
|
SHM_DIRECTORY="/dev/shm"
|
||||||
ETC="/etc"
|
ETC="/etc"
|
||||||
|
|
||||||
|
@ -79,14 +87,6 @@ PIHOLE_FTL_CONF_FILE="${PIHOLE_DIRECTORY}/pihole.toml"
|
||||||
PIHOLE_DNSMASQ_CONF_FILE="${PIHOLE_DIRECTORY}/dnsmasq.conf"
|
PIHOLE_DNSMASQ_CONF_FILE="${PIHOLE_DIRECTORY}/dnsmasq.conf"
|
||||||
PIHOLE_VERSIONS_FILE="${PIHOLE_DIRECTORY}/versions"
|
PIHOLE_VERSIONS_FILE="${PIHOLE_DIRECTORY}/versions"
|
||||||
|
|
||||||
# Read the value of an FTL config key. The value is printed to stdout.
|
|
||||||
get_ftl_conf_value() {
|
|
||||||
local key=$1
|
|
||||||
|
|
||||||
# Obtain setting from FTL directly
|
|
||||||
pihole-FTL --config "${key}"
|
|
||||||
}
|
|
||||||
|
|
||||||
PIHOLE_GRAVITY_DB_FILE="$(get_ftl_conf_value "files.gravity")"
|
PIHOLE_GRAVITY_DB_FILE="$(get_ftl_conf_value "files.gravity")"
|
||||||
|
|
||||||
PIHOLE_FTL_DB_FILE="$(get_ftl_conf_value "files.database")"
|
PIHOLE_FTL_DB_FILE="$(get_ftl_conf_value "files.database")"
|
||||||
|
@ -94,7 +94,7 @@ PIHOLE_FTL_DB_FILE="$(get_ftl_conf_value "files.database")"
|
||||||
PIHOLE_COMMAND="${BIN_DIRECTORY}/pihole"
|
PIHOLE_COMMAND="${BIN_DIRECTORY}/pihole"
|
||||||
PIHOLE_COLTABLE_FILE="${BIN_DIRECTORY}/COL_TABLE"
|
PIHOLE_COLTABLE_FILE="${BIN_DIRECTORY}/COL_TABLE"
|
||||||
|
|
||||||
FTL_PID="${RUN_DIRECTORY}/pihole-FTL.pid"
|
FTL_PID="$(get_ftl_conf_value "files.pid")"
|
||||||
|
|
||||||
PIHOLE_LOG="${LOG_DIRECTORY}/pihole.log"
|
PIHOLE_LOG="${LOG_DIRECTORY}/pihole.log"
|
||||||
PIHOLE_LOG_GZIPS="${LOG_DIRECTORY}/pihole.log.[0-9].*"
|
PIHOLE_LOG_GZIPS="${LOG_DIRECTORY}/pihole.log.[0-9].*"
|
||||||
|
@ -202,7 +202,7 @@ compare_local_version_to_git_version() {
|
||||||
if git status &> /dev/null; then
|
if git status &> /dev/null; then
|
||||||
# The current version the user is on
|
# The current version the user is on
|
||||||
local local_version
|
local local_version
|
||||||
local_version=$(git describe --tags --abbrev=0);
|
local_version=$(git describe --tags --abbrev=0 2> /dev/null);
|
||||||
# What branch they are on
|
# What branch they are on
|
||||||
local local_branch
|
local local_branch
|
||||||
local_branch=$(git rev-parse --abbrev-ref HEAD);
|
local_branch=$(git rev-parse --abbrev-ref HEAD);
|
||||||
|
@ -213,7 +213,13 @@ compare_local_version_to_git_version() {
|
||||||
local local_status
|
local local_status
|
||||||
local_status=$(git status -s)
|
local_status=$(git status -s)
|
||||||
# echo this information out to the user in a nice format
|
# echo this information out to the user in a nice format
|
||||||
log_write "${TICK} Version: ${local_version}"
|
if [ ${local_version} ]; then
|
||||||
|
log_write "${TICK} Version: ${local_version}"
|
||||||
|
elif [ -n "${DOCKER_VERSION}" ]; then
|
||||||
|
log_write "${TICK} Version: Pi-hole Docker Container ${COL_BOLD}${DOCKER_VERSION}${COL_NC}"
|
||||||
|
else
|
||||||
|
log_write "${CROSS} Version: not detected"
|
||||||
|
fi
|
||||||
|
|
||||||
# Print the repo upstreams
|
# Print the repo upstreams
|
||||||
remotes=$(git remote -v)
|
remotes=$(git remote -v)
|
||||||
|
@ -346,6 +352,9 @@ os_check() {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# If it is a docker container, we can assume the OS is supported
|
||||||
|
[ -n "${DOCKER_VERSION}" ] && valid_os=true && valid_version=true
|
||||||
|
|
||||||
local finalmsg
|
local finalmsg
|
||||||
if [ "$valid_os" = true ]; then
|
if [ "$valid_os" = true ]; then
|
||||||
log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}"
|
log_write "${TICK} Distro: ${COL_GREEN}${detected_os^}${COL_NC}"
|
||||||
|
@ -489,13 +498,25 @@ run_and_print_command() {
|
||||||
}
|
}
|
||||||
|
|
||||||
hardware_check() {
|
hardware_check() {
|
||||||
|
# Note: the checks are skipped if Pi-hole is running in a docker container
|
||||||
|
|
||||||
|
local skip_msg="${INFO} Not enough permissions inside Docker container ${COL_YELLOW}(skipped)${COL_NC}"
|
||||||
|
|
||||||
echo_current_diagnostic "System hardware configuration"
|
echo_current_diagnostic "System hardware configuration"
|
||||||
# Store the output of the command in a variable
|
if [ -n "${DOCKER_VERSION}" ]; then
|
||||||
run_and_print_command "lshw -short"
|
log_write "${skip_msg}"
|
||||||
|
else
|
||||||
|
# Store the output of the command in a variable
|
||||||
|
run_and_print_command "lshw -short"
|
||||||
|
fi
|
||||||
|
|
||||||
echo_current_diagnostic "Processor details"
|
echo_current_diagnostic "Processor details"
|
||||||
# Store the output of the command in a variable
|
if [ -n "${DOCKER_VERSION}" ]; then
|
||||||
run_and_print_command "lscpu"
|
log_write "${skip_msg}"
|
||||||
|
else
|
||||||
|
# Store the output of the command in a variable
|
||||||
|
run_and_print_command "lscpu"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
disk_usage() {
|
disk_usage() {
|
||||||
|
@ -808,26 +829,24 @@ dig_at() {
|
||||||
process_status(){
|
process_status(){
|
||||||
# Check to make sure Pi-hole's services are running and active
|
# Check to make sure Pi-hole's services are running and active
|
||||||
echo_current_diagnostic "Pi-hole processes"
|
echo_current_diagnostic "Pi-hole processes"
|
||||||
|
|
||||||
# Local iterator
|
# Local iterator
|
||||||
local i
|
local i
|
||||||
|
|
||||||
# For each process,
|
# For each process,
|
||||||
for i in "${PIHOLE_PROCESSES[@]}"; do
|
for i in "${PIHOLE_PROCESSES[@]}"; do
|
||||||
|
local status_of_process
|
||||||
|
|
||||||
# If systemd
|
# If systemd
|
||||||
if command -v systemctl &> /dev/null; then
|
if command -v systemctl &> /dev/null; then
|
||||||
# get its status via systemctl
|
# get its status via systemctl
|
||||||
local status_of_process
|
|
||||||
status_of_process=$(systemctl is-active "${i}")
|
status_of_process=$(systemctl is-active "${i}")
|
||||||
else
|
else
|
||||||
# Otherwise, use the service command and mock the output of `systemctl is-active`
|
# Otherwise, use the service command and mock the output of `systemctl is-active`
|
||||||
local status_of_process
|
|
||||||
|
|
||||||
# If DOCKER_VERSION is set, the output is slightly different (s6 init system on Docker)
|
# If it is a docker container, there is no systemctl or service. Do nothing.
|
||||||
if [ -n "${DOCKER_VERSION}" ]; then
|
if [ -n "${DOCKER_VERSION}" ]; then
|
||||||
if service "${i}" status | grep -E '^up' &> /dev/null; then
|
:
|
||||||
status_of_process="active"
|
|
||||||
else
|
|
||||||
status_of_process="inactive"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# non-Docker system
|
# non-Docker system
|
||||||
if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then
|
if service "${i}" status | grep -E 'is\srunning' &> /dev/null; then
|
||||||
|
@ -837,8 +856,12 @@ process_status(){
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# and print it out to the user
|
# and print it out to the user
|
||||||
if [[ "${status_of_process}" == "active" ]]; then
|
if [ -n "${DOCKER_VERSION}" ]; then
|
||||||
|
# If it's a Docker container, the test was skipped
|
||||||
|
log_write "${INFO} systemctl/service not installed inside docker container ${COL_YELLOW}(skipped)${COL_NC}"
|
||||||
|
elif [[ "${status_of_process}" == "active" ]]; then
|
||||||
# If it's active, show it in green
|
# If it's active, show it in green
|
||||||
log_write "${TICK} ${COL_GREEN}${i}${COL_NC} daemon is ${COL_GREEN}${status_of_process}${COL_NC}"
|
log_write "${TICK} ${COL_GREEN}${i}${COL_NC} daemon is ${COL_GREEN}${status_of_process}${COL_NC}"
|
||||||
else
|
else
|
||||||
|
@ -855,6 +878,8 @@ ftl_full_status(){
|
||||||
if command -v systemctl &> /dev/null; then
|
if command -v systemctl &> /dev/null; then
|
||||||
FTL_status=$(systemctl status --full --no-pager pihole-FTL.service)
|
FTL_status=$(systemctl status --full --no-pager pihole-FTL.service)
|
||||||
log_write " ${FTL_status}"
|
log_write " ${FTL_status}"
|
||||||
|
elif [ -n "${DOCKER_VERSION}" ]; then
|
||||||
|
log_write "${INFO} systemctl/service not installed inside docker container ${COL_YELLOW}(skipped)${COL_NC}"
|
||||||
else
|
else
|
||||||
log_write "${INFO} systemctl: command not found"
|
log_write "${INFO} systemctl: command not found"
|
||||||
fi
|
fi
|
||||||
|
@ -1317,19 +1342,16 @@ upload_to_tricorder() {
|
||||||
curl_to_tricorder
|
curl_to_tricorder
|
||||||
# If we're not running in automated mode,
|
# If we're not running in automated mode,
|
||||||
else
|
else
|
||||||
# if not being called from the web interface
|
echo ""
|
||||||
if [[ ! "${WEBCALL}" ]]; then
|
# give the user a choice of uploading it or not
|
||||||
echo ""
|
# Users can review the log file locally (or the output of the script since they are the same) and try to self-diagnose their problem
|
||||||
# give the user a choice of uploading it or not
|
read -r -p "[?] Would you like to upload the log? [y/N] " response
|
||||||
# Users can review the log file locally (or the output of the script since they are the same) and try to self-diagnose their problem
|
case ${response} in
|
||||||
read -r -p "[?] Would you like to upload the log? [y/N] " response
|
# If they say yes, run our function for uploading the log
|
||||||
case ${response} in
|
[yY][eE][sS]|[yY]) curl_to_tricorder;;
|
||||||
# If they say yes, run our function for uploading the log
|
# If they choose no, just exit out of the script
|
||||||
[yY][eE][sS]|[yY]) curl_to_tricorder;;
|
*) log_write " * Log will ${COL_GREEN}NOT${COL_NC} be uploaded to tricorder.\\n * A local copy of the debug log can be found at: ${COL_CYAN}${PIHOLE_DEBUG_LOG}${COL_NC}\\n";exit;
|
||||||
# If they choose no, just exit out of the script
|
esac
|
||||||
*) log_write " * Log will ${COL_GREEN}NOT${COL_NC} be uploaded to tricorder.\\n * A local copy of the debug log can be found at: ${COL_CYAN}${PIHOLE_DEBUG_LOG}${COL_NC}\\n";exit;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
# Check if tricorder.pi-hole.net is reachable and provide token
|
# Check if tricorder.pi-hole.net is reachable and provide token
|
||||||
# along with some additional useful information
|
# along with some additional useful information
|
||||||
|
@ -1349,13 +1371,8 @@ upload_to_tricorder() {
|
||||||
# If no token was generated
|
# If no token was generated
|
||||||
else
|
else
|
||||||
# Show an error and some help instructions
|
# Show an error and some help instructions
|
||||||
# Skip this if being called from web interface and automatic mode was not chosen (users opt-out to upload)
|
log_write "${CROSS} ${COL_RED}There was an error uploading your debug log.${COL_NC}"
|
||||||
if [[ "${WEBCALL}" ]] && [[ ! "${AUTOMATED}" ]]; then
|
log_write " * Please try again or contact the Pi-hole team for assistance."
|
||||||
:
|
|
||||||
else
|
|
||||||
log_write "${CROSS} ${COL_RED}There was an error uploading your debug log.${COL_NC}"
|
|
||||||
log_write " * Please try again or contact the Pi-hole team for assistance."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
# Finally, show where the log file is no matter the outcome of the function so users can look at it
|
# Finally, show where the log file is no matter the outcome of the function so users can look at it
|
||||||
log_write " * A local copy of the debug log can be found at: ${COL_CYAN}${PIHOLE_DEBUG_LOG}${COL_NC}\\n"
|
log_write " * A local copy of the debug log can be found at: ${COL_CYAN}${PIHOLE_DEBUG_LOG}${COL_NC}\\n"
|
||||||
|
|
4
pihole
4
pihole
|
@ -73,19 +73,17 @@ listFunc() {
|
||||||
|
|
||||||
debugFunc() {
|
debugFunc() {
|
||||||
local automated
|
local automated
|
||||||
local web
|
|
||||||
local check_database_integrity
|
local check_database_integrity
|
||||||
# Pull off the `debug` leaving passed call augmentation flags in $1
|
# Pull off the `debug` leaving passed call augmentation flags in $1
|
||||||
shift
|
shift
|
||||||
|
|
||||||
for value in "$@"; do
|
for value in "$@"; do
|
||||||
[[ "$value" == *"-a"* ]] && automated="true"
|
[[ "$value" == *"-a"* ]] && automated="true"
|
||||||
[[ "$value" == *"-w"* ]] && web="true"
|
|
||||||
[[ "$value" == *"-c"* ]] && check_database_integrity="true"
|
[[ "$value" == *"-c"* ]] && check_database_integrity="true"
|
||||||
[[ "$value" == *"--check_database"* ]] && check_database_integrity="true"
|
[[ "$value" == *"--check_database"* ]] && check_database_integrity="true"
|
||||||
done
|
done
|
||||||
|
|
||||||
AUTOMATED=${automated:-} WEBCALL=${web:-} CHECK_DATABASE=${check_database_integrity:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh
|
AUTOMATED=${automated:-} CHECK_DATABASE=${check_database_integrity:-} "${PI_HOLE_SCRIPT_DIR}"/piholeDebug.sh
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue