2016-10-23 21:15:10 +00:00
|
|
|
#!/usr/bin/env bash
|
2016-03-20 01:32:11 +00:00
|
|
|
# Pi-hole: A black hole for Internet advertisements
|
2017-02-22 17:55:20 +00:00
|
|
|
# (c) 2017 Pi-hole, LLC (https://pi-hole.net)
|
|
|
|
# Network-wide ad blocking via your own hardware.
|
|
|
|
#
|
2016-09-27 01:06:31 +00:00
|
|
|
# Generates pihole_debug.log to be used for troubleshooting.
|
2016-03-20 01:32:11 +00:00
|
|
|
#
|
2017-02-22 17:55:20 +00:00
|
|
|
# This file is copyright under the latest version of the EUPL.
|
|
|
|
# Please see LICENSE file for your rights under this license.
|
|
|
|
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
# causes a pipeline to produce a failure return code if any command errors.
|
|
|
|
# Normally, pipelines only return a failure if the last command errors.
|
|
|
|
# In combination with set -e, this will make your script exit if any command in a pipeline errors.
|
2016-09-28 02:30:37 +00:00
|
|
|
set -o pipefail
|
2016-03-20 01:32:11 +00:00
|
|
|
|
|
|
|
######## GLOBAL VARS ########
|
2016-10-28 21:52:08 +00:00
|
|
|
VARSFILE="/etc/pihole/setupVars.conf"
|
2016-03-20 01:32:11 +00:00
|
|
|
DEBUG_LOG="/var/log/pihole_debug.log"
|
2016-03-24 21:21:29 +00:00
|
|
|
DNSMASQFILE="/etc/dnsmasq.conf"
|
2017-02-10 16:42:37 +00:00
|
|
|
DNSMASQCONFDIR="/etc/dnsmasq.d/*"
|
2016-03-24 21:21:29 +00:00
|
|
|
LIGHTTPDFILE="/etc/lighttpd/lighttpd.conf"
|
2016-04-11 23:35:44 +00:00
|
|
|
LIGHTTPDERRFILE="/var/log/lighttpd/error.log"
|
2016-03-24 21:21:29 +00:00
|
|
|
GRAVITYFILE="/etc/pihole/gravity.list"
|
|
|
|
WHITELISTFILE="/etc/pihole/whitelist.txt"
|
|
|
|
BLACKLISTFILE="/etc/pihole/blacklist.txt"
|
2016-10-28 21:52:08 +00:00
|
|
|
ADLISTFILE="/etc/pihole/adlists.list"
|
2016-03-24 21:21:29 +00:00
|
|
|
PIHOLELOG="/var/log/pihole.log"
|
2017-03-05 01:54:38 +00:00
|
|
|
PIHOLEGITDIR="/etc/.pihole/"
|
|
|
|
ADMINGITDIR="/var/www/html/admin/"
|
2016-03-25 21:42:17 +00:00
|
|
|
WHITELISTMATCHES="/tmp/whitelistmatches.list"
|
2017-05-02 07:18:58 +00:00
|
|
|
readonly FTLLOG="/var/log/pihole-FTL.log"
|
2017-05-20 06:34:13 +00:00
|
|
|
coltable=/opt/pihole/COL_TABLE
|
|
|
|
|
|
|
|
if [[ -f ${coltable} ]]; then
|
|
|
|
source ${coltable}
|
|
|
|
else
|
|
|
|
COL_NC='\e[0m' # No Color
|
|
|
|
COL_YELLOW='\e[1;33m'
|
|
|
|
COL_LIGHT_PURPLE='\e[1;35m'
|
|
|
|
COL_CYAN='\e[0;36m'
|
|
|
|
TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]"
|
|
|
|
CROSS="[${COL_LIGHT_RED}✗${COL_NC}]"
|
|
|
|
INFO="[i]"
|
|
|
|
DONE="${COL_LIGHT_GREEN} done!${COL_NC}"
|
|
|
|
OVER="\r\033[K"
|
|
|
|
fi
|
2016-03-24 21:21:29 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
echo_succes_or_fail() {
|
|
|
|
local message="${1}"
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo -e " ${TICK} ${message}"
|
2017-02-10 16:42:37 +00:00
|
|
|
else
|
2017-05-20 06:34:13 +00:00
|
|
|
echo -e " ${CROSS} ${message}"
|
2016-10-26 02:53:00 +00:00
|
|
|
fi
|
2016-10-28 13:51:30 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
initiate_debug() {
|
|
|
|
# Clear the screen so the debug log is readable
|
|
|
|
clear
|
|
|
|
echo -e "${COL_LIGHT_PURPLE}*** [ INITIALIZING ]${COL_NC}"
|
|
|
|
echo -e " ${INFO} $(date "+%Y-%m-%d:%H:%M:%S") debug log has been initiated."
|
2016-10-28 21:52:08 +00:00
|
|
|
}
|
2016-09-27 01:06:31 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
# This is a function for visually displaying the curent test that is being run.
|
|
|
|
# Accepts one variable: the name of what is being diagnosed
|
|
|
|
echo_current_diagnostic() {
|
|
|
|
# Colors are used for visually distinguishing each test in the output
|
|
|
|
echo -e "\n${COL_LIGHT_PURPLE}*** [ DIAGNOSING ]:${COL_NC} ${1}"
|
2016-09-27 01:06:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
if_file_exists() {
|
|
|
|
local file_to_test="${1}"
|
|
|
|
# If the file is readable
|
|
|
|
if [[ -r "${file_to_test}" ]]; then
|
|
|
|
# Return success
|
2016-10-26 19:22:20 +00:00
|
|
|
return 0
|
|
|
|
else
|
2017-05-20 06:34:13 +00:00
|
|
|
# Otherwise, return a failure
|
2016-10-26 19:22:20 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
get_distro_attributes() {
|
|
|
|
# Put the current Internal Field Separator into another variable so it can be restored later
|
|
|
|
OLD_IFS="$IFS"
|
|
|
|
# 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
|
|
|
|
IFS=$'\r\n' command eval 'distro_info=( $(cat /etc/*release) )'
|
2016-10-28 22:53:18 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
local distro_attribute
|
|
|
|
for distro_attribute in "${distro_info[@]}"; do
|
2017-05-20 07:01:56 +00:00
|
|
|
# Display the information with the ${INFO} icon (we need just the OS PRETTY_NAME)
|
|
|
|
pretty_name_key=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f1)
|
|
|
|
if [[ "${pretty_name_key}" == "PRETTY_NAME" ]]; then
|
|
|
|
PRETTY_NAME=$(echo "${distro_attribute}" | grep "PRETTY_NAME" | cut -d '=' -f2- | tr -d '"')
|
|
|
|
echo " ${INFO} ${PRETTY_NAME}"
|
|
|
|
else
|
|
|
|
:
|
|
|
|
fi
|
2017-05-20 06:34:13 +00:00
|
|
|
done
|
|
|
|
# Set the IFS back to what it was
|
|
|
|
IFS="$OLD_IFS"
|
2016-10-26 21:33:47 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
diagnose_operating_system() {
|
|
|
|
# Display the current test that is running
|
|
|
|
echo_current_diagnostic "Operating system"
|
2016-10-26 18:38:19 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
# If there is a /etc/*release file, it's probably a supported operating system, so we can
|
|
|
|
if_file_exists /etc/*release && \
|
|
|
|
# display the attributes to the user
|
|
|
|
get_distro_attributes || \
|
|
|
|
# If it doesn't exist, it's not a system we currently support
|
|
|
|
echo -e " ${CROSS} ${COL_LIGHT_RED}Distribution unknown -- most likely you are on an unsupported platform and may run into issues.${COL_NC}
|
|
|
|
${INFO} ${COL_LIGHT_RED}Please see${COL_NC}: ${COL_CYAN}https://discourse.pi-hole.net/t/hardware-software-requirements/273${COL_NC}"
|
2016-09-27 03:39:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
parse_file() {
|
|
|
|
local filename="${1}"
|
|
|
|
OLD_IFS="$IFS"
|
|
|
|
IFS=$'\r\n' command eval 'file_info=( $(cat "${filename}") )'
|
2017-03-04 19:34:34 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
local file_lines
|
|
|
|
for file_lines in "${file_info[@]}"; do
|
|
|
|
# Display the information with the ${INFO} icon
|
|
|
|
# No need to show the support URLs so they are grepped out
|
|
|
|
echo " ${INFO} ${file_lines}"
|
|
|
|
done
|
|
|
|
# Set the IFS back to what it was
|
|
|
|
IFS="$OLD_IFS"
|
2017-03-04 23:06:34 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
diagnose_setup_variables() {
|
|
|
|
# Display the current test that is running
|
|
|
|
echo_current_diagnostic "Setup variables"
|
2016-09-28 17:14:47 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
# If the variable file exists,
|
|
|
|
if_file_exists "${VARSFILE}" && \
|
|
|
|
# source it
|
|
|
|
echo -e " ${INFO} Sourcing ${VARSFILE}...";
|
|
|
|
source ${VARSFILE};
|
|
|
|
# and display a green check mark with ${DONE}
|
|
|
|
echo_succes_or_fail "${VARSFILE} is readable and has been sourced." || \
|
|
|
|
# Othwerwise, error out
|
|
|
|
echo_succes_or_fail "${VARSFILE} is not readable.
|
|
|
|
${INFO} $(ls -l ${VARSFILE} 2>/dev/null)";
|
|
|
|
parse_file "${VARSFILE}"
|
2016-04-04 05:59:24 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
dir_check() {
|
|
|
|
local directory="${1}"
|
|
|
|
echo_current_diagnostic "contents of ${directory}"
|
|
|
|
for filename in "${directory}"*; do
|
|
|
|
if_file_exists "${filename}" && \
|
|
|
|
echo_succes_or_fail "Files detected" || \
|
|
|
|
echo_succes_or_fail "directory does not exist"
|
|
|
|
done
|
2016-04-11 23:35:44 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
list_files_in_dir() {
|
|
|
|
local dir_to_parse="${1}"
|
|
|
|
local filename
|
|
|
|
files_found=( $(ls "${dir_to_parse}") )
|
|
|
|
for each_file in "${files_found[@]}"; do
|
|
|
|
# Display the information with the ${INFO} icon
|
|
|
|
echo " ${INFO} ${each_file}"
|
2016-11-18 21:27:06 +00:00
|
|
|
done
|
2017-01-22 20:38:09 +00:00
|
|
|
|
2016-03-20 01:32:11 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
check_dnsmasq_d() {
|
|
|
|
local directory=/etc/dnsmasq.d
|
|
|
|
dir_check "${directory}"
|
|
|
|
list_files_in_dir "${directory}"
|
2016-03-20 01:32:11 +00:00
|
|
|
}
|
2016-08-01 20:43:13 +00:00
|
|
|
|
2017-05-20 06:34:13 +00:00
|
|
|
initiate_debug
|
|
|
|
diagnose_operating_system
|
|
|
|
diagnose_setup_variables
|
|
|
|
check_dnsmasq_d
|