Refactor out some more reudndant code.

This commit is contained in:
Dan Schaper 2016-10-28 06:51:30 -07:00
parent 90ec0a610e
commit 01f10b56e8

View file

@ -107,6 +107,8 @@ lsof_parse() {
fi fi
log_echo -l "by ${user} for ${process} ${match}" log_echo -l "by ${user} for ${process} ${match}"
} }
version_check() { version_check() {
header_write "Installed Package Versions" header_write "Installed Package Versions"
echo "::: Detecting Pi-hole installed versions." echo "::: Detecting Pi-hole installed versions."
@ -126,18 +128,25 @@ files_check() {
header_write "File Check" header_write "File Check"
#Check non-zero length existence of ${1} #Check non-zero length existence of ${1}
echo "::: Detecting existence of ${1}..." log_echo -n "Detecting existence of ${1}:"
local search_file="${1}" local search_file="${1}"
if [[ -s ${search_file} ]]; then if [[ -s ${search_file} ]]; then
log_echo -n "${1} exists" log_echo -l " exists"
source "${search_file}" &> /dev/null && log_echo -l " and successfully was sourced" || log_echo -l " and could not be sourced"
file_parse "${search_file}" file_parse "${search_file}"
return 0
else else
log_echo "${1} not found!" log_echo "${1} not found!"
return 1
fi fi
echo ":::" echo ":::"
} }
source_file() {
local file_found=$(files_check "${1}") \
&& (source "${1}" &> /dev/null && log_echo -l "${file_found} and was successfully sourced") \
|| log_echo -l "${file_found} and could not be sourced"
}
distro_check() { distro_check() {
header_write "Installed OS Distribution" header_write "Installed OS Distribution"
@ -318,38 +327,17 @@ checkProcesses() {
} }
debugLighttpd() { debugLighttpd() {
header_write "lighttpd.conf"
if [ -e "${LIGHTTPDFILE}" ]; then echo "::: Checking for necessary lighttpd files."
while read -r line; do files_check "${LIGHTTPDFILE}"
if [ ! -z "${line}" ]; then files_check "${LIGHTTPDERRFILE}"
[[ "${line}" =~ ^#.*$ ]] && continue echo ":::"
log_write "${line}"
fi
done < "${LIGHTTPDFILE}"
log_write ""
else
log_write "No lighttpd.conf file found!"
printf ":::\tNo lighttpd.conf file found\n"
fi
if [ -e "${LIGHTTPDERRFILE}" ]; then
log_write ""
log_write "::: lighttpd error.log"
log_write ""
cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG}
else
log_write "No lighttpd error.log file found!"
printf ":::\tNo lighttpd error.log file found\n"
fi
log_write ""
} }
### END FUNCTIONS ### ### END FUNCTIONS ###
version_check version_check
files_check "/etc/pihole/setupVars.conf" source_file "/etc/pihole/setupVars.conf"
distro_check distro_check
ip_check ip_check
hostnameCheck hostnameCheck
@ -362,7 +350,6 @@ debugLighttpd
echo "::: Writing dnsmasq.conf to debug log..." echo "::: Writing dnsmasq.conf to debug log..."
header_write "Dnsmasq configuration" header_write "Dnsmasq configuration"
if [ -e "${DNSMASQFILE}" ]; then if [ -e "${DNSMASQFILE}" ]; then
#cat $DNSMASQFILE >> $DEBUG_LOG
while read -r line; do while read -r line; do
if [ ! -z "${line}" ]; then if [ ! -z "${line}" ]; then
[[ "${line}" =~ ^#.*$ ]] && continue [[ "${line}" =~ ^#.*$ ]] && continue