More tabs to spaces.

This commit is contained in:
Adam Warner 2016-11-01 10:16:08 +00:00
parent d64e86288c
commit 61140348fe
5 changed files with 298 additions and 297 deletions

View file

@ -26,14 +26,13 @@ listMain=""
listAlt="" listAlt=""
helpFunc() { helpFunc() {
if [[ ${listMain} == ${whitelist} ]]; then
if [[ ${listMain} == ${whitelist} ]]; then letter="w"
letter="w" word="white"
word="white" else
else letter="b"
letter="b" word="black"
word="black" fi
fi
cat << EOM cat << EOM
::: Immediately ${word}lists one or more domains in the hosts file ::: Immediately ${word}lists one or more domains in the hosts file
@ -100,21 +99,22 @@ AddDomain() {
} }
RemoveDomain() { RemoveDomain() {
list="$2" list="$2"
bool=true bool=true
#Is it in the other list? Logic follows that if its whitelisted it should not be blacklisted and vice versa
grep -Ex -q "$1" ${list} > /dev/null 2>&1 || bool=false #Is it in the other list? Logic follows that if its whitelisted it should not be blacklisted and vice versa
if [[ "${bool}" == true ]]; then grep -Ex -q "$1" ${list} > /dev/null 2>&1 || bool=false
# Remove it from the other one if [[ "${bool}" == true ]]; then
echo "::: Removing $1 from $list..." # Remove it from the other one
echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${list} echo "::: Removing $1 from $list..."
reload=true echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${list}
else reload=true
if [[ "${verbose}" == true ]]; then else
echo "::: ${1} does not exist in ${list}, no need to remove!" if [[ "${verbose}" == true ]]; then
fi echo "::: ${1} does not exist in ${list}, no need to remove!"
fi fi
fi
} }
Reload() { Reload() {
@ -123,11 +123,12 @@ Reload() {
} }
Displaylist() { Displaylist() {
if [[ ${listMain} == ${whitelist} ]]; then if [[ ${listMain} == ${whitelist} ]]; then
string="gravity resistant domains" string="gravity resistant domains"
else else
string="domains caught in the sinkhole" string="domains caught in the sinkhole"
fi fi
verbose=false verbose=false
echo -e " Displaying $string \n" echo -e " Displaying $string \n"
count=1 count=1
@ -140,8 +141,8 @@ Displaylist() {
for var in "$@"; do for var in "$@"; do
case "${var}" in case "${var}" in
"-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";; "-w" | "whitelist" ) listMain="${whitelist}"; listAlt="${blacklist}";;
"-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";; "-b" | "blacklist" ) listMain="${blacklist}"; listAlt="${whitelist}";;
"-nr"| "--noreload" ) reload=false;; "-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;; "-d" | "--delmode" ) addmode=false;;
"-f" | "--force" ) force=true;; "-f" | "--force" ) force=true;;

View file

@ -82,12 +82,12 @@ header_write() {
file_parse() { file_parse() {
while read -r line; do while read -r line; do
if [ ! -z "${line}" ]; then if [ ! -z "${line}" ]; then
[[ "${line}" =~ ^#.*$ || ! "${line}" ]] && continue [[ "${line}" =~ ^#.*$ || ! "${line}" ]] && continue
log_write "${line}" log_write "${line}"
fi fi
done < "${1}" done < "${1}"
log_write "" log_write ""
} }
block_parse() { block_parse() {
@ -114,15 +114,15 @@ version_check() {
local error_found local error_found
error_found=0 error_found=0
local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \ local pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \
&& log_echo -r "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1) && log_echo -r "Pi-hole: $pi_hole_ver" || (log_echo "Pi-hole git repository not detected." && error_found=1)
local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \ local admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \
&& log_echo -r "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1) && log_echo -r "WebUI: $admin_ver" || (log_echo "Pi-hole Admin Pages git repository not detected." && error_found=1)
local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \ local light_ver="$(lighttpd -v |& head -n1 | cut -d " " -f1)" \
&& log_echo -r "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1) && log_echo -r "${light_ver}" || (log_echo "lighttpd not installed." && error_found=1)
local php_ver="$(php -v |& head -n1)" \ local php_ver="$(php -v |& head -n1)" \
&& log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1) && log_echo -r "${php_ver}" || (log_echo "PHP not installed." && error_found=1)
return "${error_found}" return "${error_found}"
} }
files_check() { files_check() {
@ -133,7 +133,7 @@ files_check() {
echo "::: File exists" echo "::: File exists"
file_parse "${search_file}" file_parse "${search_file}"
return 0 return 0
else else
log_echo "${1} not found!" log_echo "${1} not found!"
return 1 return 1
fi fi
@ -150,8 +150,8 @@ distro_check() {
local soft_fail local soft_fail
header_write "Detecting installed OS Distribution" header_write "Detecting installed OS Distribution"
soft_fail=0 soft_fail=0
local distro="$(cat /etc/*release)" && block_parse "${distro}" || (log_echo "Distribution details not found." && soft_fail=1) local distro="$(cat /etc/*release)" && block_parse "${distro}" || (log_echo "Distribution details not found." && soft_fail=1)
return "${soft_fail}" return "${soft_fail}"
} }
processor_check() { processor_check() {
@ -171,22 +171,22 @@ ipv6_check() {
ip_check() { ip_check() {
header_write "IP Address Information" header_write "IP Address Information"
# Get the current interface for Internet traffic # Get the current interface for Internet traffic
# Check if IPv6 enabled # Check if IPv6 enabled
local IPv6_interface local IPv6_interface
local IPv4_interface local IPv4_interface
ipv6_check && IPv6_interface=${piholeInterface:-$(ip -6 r | grep default | cut -d ' ' -f 5)} ipv6_check && IPv6_interface=${piholeInterface:-$(ip -6 r | grep default | cut -d ' ' -f 5)}
# If declared in setupVars.conf use it, otherwise defer to default # If declared in setupVars.conf use it, otherwise defer to default
# http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash # http://stackoverflow.com/questions/2013547/assigning-default-values-to-shell-variables-with-a-single-command-in-bash
IPv4_interface=${piholeInterface:-$(ip r | grep default | cut -d ' ' -f 5)} IPv4_interface=${piholeInterface:-$(ip r | grep default | cut -d ' ' -f 5)}
if [[ IPV6_READY ]]; then if [[ IPV6_READY ]]; then
local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ local IPv6_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \
&& (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") \ && (log_write "${IPv6_addr_list}" && echo "::: IPv6 addresses located") \
|| log_echo "No IPv6 addresses found." || log_echo "No IPv6 addresses found."
local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3) local IPv6_def_gateway=$(ip -6 r | grep default | cut -d ' ' -f 3)
if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then if [[ $? = 0 ]] && [[ -n ${IPv6_def_gateway} ]]; then
@ -206,23 +206,23 @@ ip_check() {
fi fi
local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \ local IPv4_addr_list="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" \
&& (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\ && (block_parse "${IPv4_addr_list}" && echo "::: IPv4 addresses located")\
|| log_echo "No IPv4 addresses found." || log_echo "No IPv4 addresses found."
local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3) local IPv4_def_gateway=$(ip r | grep default | cut -d ' ' -f 3)
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
echo -n "::: Pinging default IPv4 gateway: " echo -n "::: Pinging default IPv4 gateway: "
local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" -I "${IPv4_interface}" | tail -n3)" \ local IPv4_def_gateway_check="$(ping -q -w 3 -c 3 -n "${IPv4_def_gateway}" -I "${IPv4_interface}" | tail -n3)" \
&& echo "Gateway responded." \ && echo "Gateway responded." \
|| echo "Gateway did not respond." || echo "Gateway did not respond."
block_parse "${IPv4_def_gateway_check}" block_parse "${IPv4_def_gateway_check}"
echo -n "::: Pinging Internet via IPv4: " echo -n "::: Pinging Internet via IPv4: "
local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 -I "${IPv4_interface}" | tail -n3)" \ local IPv4_inet_check="$(ping -q -w 5 -c 3 -n 8.8.8.8 -I "${IPv4_interface}" | tail -n3)" \
&& echo "Query responded." \ && echo "Query responded." \
|| echo "Query did not respond." || echo "Query did not respond."
block_parse "${IPv4_inet_check}" block_parse "${IPv4_inet_check}"
fi fi
fi fi
} }
@ -237,76 +237,76 @@ port_check() {
daemon_check() { daemon_check() {
# Check for daemon ${1} on port ${2} # Check for daemon ${1} on port ${2}
header_write "Daemon Process Information" header_write "Daemon Process Information"
echo "::: Checking ${2} port for ${1} listener." echo "::: Checking ${2} port for ${1} listener."
if [[ ${IPV6_READY} ]]; then if [[ ${IPV6_READY} ]]; then
port_check 6 "${2}" "${1}" port_check 6 "${2}" "${1}"
fi fi
lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \ lsof_value=$(lsof -i 4:${2} -FcL | tr '\n' ' ') \
port_check 4 "${2}" "${1}" port_check 4 "${2}" "${1}"
} }
testResolver() { testResolver() {
header_write "Resolver Functions Check" header_write "Resolver Functions Check"
# Find a blocked url that has not been whitelisted. # Find a blocked url that has not been whitelisted.
TESTURL="doubleclick.com" TESTURL="doubleclick.com"
if [ -s "${WHITELISTMATCHES}" ]; then if [ -s "${WHITELISTMATCHES}" ]; then
while read -r line; do while read -r line; do
CUTURL=${line#*" "} CUTURL=${line#*" "}
if [ "${CUTURL}" != "Pi-Hole.IsWorking.OK" ]; then if [ "${CUTURL}" != "Pi-Hole.IsWorking.OK" ]; then
while read -r line2; do while read -r line2; do
CUTURL2=${line2#*" "} CUTURL2=${line2#*" "}
if [ "${CUTURL}" != "${CUTURL2}" ]; then if [ "${CUTURL}" != "${CUTURL2}" ]; then
TESTURL="${CUTURL}" TESTURL="${CUTURL}"
break 2 break 2
fi fi
done < "${WHITELISTMATCHES}" done < "${WHITELISTMATCHES}"
fi fi
done < "${GRAVITYFILE}" done < "${GRAVITYFILE}"
fi fi
log_write "Resolution of ${TESTURL} from Pi-hole:" log_write "Resolution of ${TESTURL} from Pi-hole:"
LOCALDIG=$(dig "${TESTURL}" @127.0.0.1) LOCALDIG=$(dig "${TESTURL}" @127.0.0.1)
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
log_write "${LOCALDIG}" log_write "${LOCALDIG}"
else else
log_write "Failed to resolve ${TESTURL} on Pi-hole" log_write "Failed to resolve ${TESTURL} on Pi-hole"
fi fi
log_write "" log_write ""
log_write "Resolution of ${TESTURL} from 8.8.8.8:" log_write "Resolution of ${TESTURL} from 8.8.8.8:"
REMOTEDIG=$(dig "${TESTURL}" @8.8.8.8) REMOTEDIG=$(dig "${TESTURL}" @8.8.8.8)
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
log_write "${REMOTEDIG}" log_write "${REMOTEDIG}"
else else
log_write "Failed to resolve ${TESTURL} on 8.8.8.8" log_write "Failed to resolve ${TESTURL} on 8.8.8.8"
fi fi
log_write "" log_write ""
log_write "Pi-hole dnsmasq specific records lookups" log_write "Pi-hole dnsmasq specific records lookups"
log_write "Cache Size:" log_write "Cache Size:"
dig +short chaos txt cachesize.bind >> ${DEBUG_LOG} dig +short chaos txt cachesize.bind >> ${DEBUG_LOG}
log_write "Upstream Servers:" log_write "Upstream Servers:"
dig +short chaos txt servers.bind >> ${DEBUG_LOG} dig +short chaos txt servers.bind >> ${DEBUG_LOG}
log_write "" log_write ""
} }
checkProcesses() { checkProcesses() {
header_write "Processes Check" header_write "Processes Check"
echo "::: Logging status of lighttpd and dnsmasq..." echo "::: Logging status of lighttpd and dnsmasq..."
PROCESSES=( lighttpd dnsmasq ) PROCESSES=( lighttpd dnsmasq )
for i in "${PROCESSES[@]}"; do for i in "${PROCESSES[@]}"; do
log_write "" log_write ""
log_write "${i}" log_write "${i}"
log_write " processes status:" log_write " processes status:"
systemctl -l status "${i}" >> "${DEBUG_LOG}" systemctl -l status "${i}" >> "${DEBUG_LOG}"
done done
log_write "" log_write ""
} }
debugLighttpd() { debugLighttpd() {
@ -344,50 +344,50 @@ files_check "${ADLISTFILE}"
header_write "Analyzing gravity.list" header_write "Analyzing gravity.list"
gravity_length=$(wc -l "${GRAVITYFILE}") \ gravity_length=$(wc -l "${GRAVITYFILE}") \
&& log_write "${GRAVITYFILE} is ${gravity_length} lines long." \ && log_write "${GRAVITYFILE} is ${gravity_length} lines long." \
|| log_echo "Warning: No gravity.list file found!" || log_echo "Warning: No gravity.list file found!"
# Continuously append the pihole.log file to the pihole_debug.log file # Continuously append the pihole.log file to the pihole_debug.log file
dumpPiHoleLog() { dumpPiHoleLog() {
trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT
echo "::: " echo "::: "
echo "::: --= User Action Required =--" echo "::: --= User Action Required =--"
echo -e "::: Try loading a site that you are having trouble with now from a client web browser.. \n:::\t(Press CTRL+C to finish logging.)" echo -e "::: Try loading a site that you are having trouble with now from a client web browser.. \n:::\t(Press CTRL+C to finish logging.)"
header_write "pihole.log" header_write "pihole.log"
if [ -e "${PIHOLELOG}" ]; then if [ -e "${PIHOLELOG}" ]; then
while true; do while true; do
tail -f "${PIHOLELOG}" >> ${DEBUG_LOG} tail -f "${PIHOLELOG}" >> ${DEBUG_LOG}
log_write "" log_write ""
done done
else else
log_write "No pihole.log file found!" log_write "No pihole.log file found!"
printf ":::\tNo pihole.log file found!\n" printf ":::\tNo pihole.log file found!\n"
fi fi
} }
# Anything to be done after capturing of pihole.log terminates # Anything to be done after capturing of pihole.log terminates
finalWork() { finalWork() {
local tricorder local tricorder
echo "::: Finshed debugging!" echo "::: Finshed debugging!"
echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." echo "::: The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only."
read -r -p "::: Would you like to upload the log? [y/N] " response read -r -p "::: Would you like to upload the log? [y/N] " response
case ${response} in case ${response} in
[yY][eE][sS]|[yY]) [yY][eE][sS]|[yY])
tricorder=$(cat /var/log/pihole_debug.log | nc tricorder.pi-hole.net 9999) tricorder=$(cat /var/log/pihole_debug.log | nc tricorder.pi-hole.net 9999)
;; ;;
*) *)
echo "::: Log will NOT be uploaded to tricorder." echo "::: Log will NOT be uploaded to tricorder."
;; ;;
esac esac
# Check if tricorder.pi-hole.net is reachable and provide token. # Check if tricorder.pi-hole.net is reachable and provide token.
if [ -n "${tricorder}" ]; then if [ -n "${tricorder}" ]; then
echo "::: Your debug token is : ${tricorder}" echo "::: Your debug token is : ${tricorder}"
echo "::: Please contact the Pi-hole team with your token to being assistance." echo "::: Please contact the Pi-hole team with your token to being assistance."
echo "::: Thank you." echo "::: Thank you."
fi fi
echo "::: Debug log can be found at : /var/log/pihole_debug.log" echo "::: Debug log can be found at : /var/log/pihole_debug.log"
} }
trap finalWork EXIT trap finalWork EXIT

View file

@ -15,28 +15,28 @@
# Borrowed from adafruit-pitft-helper < borrowed from raspi-config # Borrowed from adafruit-pitft-helper < borrowed from raspi-config
# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L324-L334 # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L324-L334
getInitSys() { getInitSys() {
if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
SYSTEMD=1 SYSTEMD=1
elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
SYSTEMD=0 SYSTEMD=0
else else
echo "Unrecognised init system" echo "Unrecognised init system"
return 1 return 1
fi fi
} }
# Borrowed from adafruit-pitft-helper: # Borrowed from adafruit-pitft-helper:
# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285 # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285
autoLoginPiToConsole() { autoLoginPiToConsole() {
if [ -e /etc/init.d/lightdm ]; then if [ -e /etc/init.d/lightdm ]; then
if [ ${SYSTEMD} -eq 1 ]; then if [ ${SYSTEMD} -eq 1 ]; then
systemctl set-default multi-user.target systemctl set-default multi-user.target
ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
else else
update-rc.d lightdm disable 2 update-rc.d lightdm disable 2
sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
fi fi
fi fi
} }
######### SCRIPT ########### ######### SCRIPT ###########

View file

@ -18,64 +18,64 @@ piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
piholeFilesDir="/etc/.pihole" piholeFilesDir="/etc/.pihole"
spinner() { spinner() {
local pid=${1} local pid=${1}
local delay=0.50 local delay=0.50
local spinstr='/-\|' local spinstr='/-\|'
while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do
local temp=${spinstr#?} local temp=${spinstr#?}
printf " [%c] " "${spinstr}" printf " [%c] " "${spinstr}"
local spinstr=${temp}${spinstr%"$temp"} local spinstr=${temp}${spinstr%"$temp"}
sleep ${delay} sleep ${delay}
printf "\b\b\b\b\b\b" printf "\b\b\b\b\b\b"
done done
printf " \b\b\b\b" printf " \b\b\b\b"
} }
getGitFiles() { getGitFiles() {
# Setup git repos for directory and repository passed # Setup git repos for directory and repository passed
# as arguments 1 and 2 # as arguments 1 and 2
echo ":::" echo ":::"
echo "::: Checking for existing repository..." echo "::: Checking for existing repository..."
if is_repo "${1}"; then if is_repo "${1}"; then
update_repo "${1}" update_repo "${1}"
else else
make_repo "${1}" "${2}" make_repo "${1}" "${2}"
fi fi
} }
is_repo() { is_repo() {
# Use git to check if directory is currently under VCS # Use git to check if directory is currently under VCS
echo -n "::: Checking $1 is a repo..." echo -n "::: Checking $1 is a repo..."
cd "${1}" &> /dev/null || return 1 cd "${1}" &> /dev/null || return 1
git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1 git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1
} }
make_repo() { make_repo() {
# Remove the non-repod interface and clone the interface # Remove the non-repod interface and clone the interface
echo -n "::: Cloning $2 into $1..." echo -n "::: Cloning $2 into $1..."
rm -rf "${1}" rm -rf "${1}"
git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $! git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $!
echo " done!" echo " done!"
} }
update_repo() { update_repo() {
# Pull the latest commits # Pull the latest commits
echo -n "::: Updating repo in $1..." echo -n "::: Updating repo in $1..."
cd "${1}" || exit 1 cd "${1}" || exit 1
git stash -q > /dev/null & spinner $! git stash -q > /dev/null & spinner $!
git pull -q > /dev/null & spinner $! git pull -q > /dev/null & spinner $!
echo " done!" echo " done!"
} }
if [ ! -d "/etc/.pihole" ]; then #This is unlikely if [ ! -d "/etc/.pihole" ]; then #This is unlikely
echo "::: Critical Error: Pi-Hole repo missing from system!" echo "::: Critical Error: Pi-Hole repo missing from system!"
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
exit 1; exit 1;
fi fi
if [ ! -d "/var/www/html/admin" ]; then #This is unlikely if [ ! -d "/var/www/html/admin" ]; then #This is unlikely
echo "::: Critical Error: Pi-Hole repo missing from system!" echo "::: Critical Error: Pi-Hole repo missing from system!"
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole" echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
exit 1; exit 1;
fi fi
echo "::: Checking for updates..." echo "::: Checking for updates..."
@ -105,38 +105,38 @@ echo ":::"
if [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then if [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then
echo "::: Everything is up to date!" echo "::: Everything is up to date!"
echo "" echo ""
exit 0 exit 0
elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then
echo "::: Pi-hole Web Admin files out of date" echo "::: Pi-hole Web Admin files out of date"
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl}
echo ":::" echo ":::"
webVersion=$(pihole -v -a -c) webVersion=$(pihole -v -a -c)
echo "::: Web Admin version is now at ${webVersion}" echo "::: Web Admin version is now at ${webVersion}"
echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'" echo "::: If you had made any changes in '/var/www/html/admin', they have been stashed using 'git stash'"
echo "" echo ""
elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then
echo "::: Pi-hole core files out of date" echo "::: Pi-hole core files out of date"
getGitFiles ${piholeFilesDir} ${piholeGitUrl} getGitFiles ${piholeFilesDir} ${piholeGitUrl}
/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended /etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended
echo ":::" echo ":::"
piholeVersion=$(pihole -v -p -c) piholeVersion=$(pihole -v -p -c)
echo "::: Pi-hole version is now at ${piholeVersion}" echo "::: Pi-hole version is now at ${piholeVersion}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo "" echo ""
elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then
echo "::: Updating Everything" echo "::: Updating Everything"
getGitFiles ${piholeFilesDir} ${piholeGitUrl} getGitFiles ${piholeFilesDir} ${piholeGitUrl}
/etc/.pihole/automated\ install/basic-install.sh --unattended /etc/.pihole/automated\ install/basic-install.sh --unattended
webVersion=$(pihole -v -a -c) webVersion=$(pihole -v -a -c)
piholeVersion=$(pihole -v -p -c) piholeVersion=$(pihole -v -p -c)
echo ":::" echo ":::"
echo "::: Pi-hole version is now at ${piholeVersion}" echo "::: Pi-hole version is now at ${piholeVersion}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo ":::" echo ":::"
echo "::: Pi-hole version is now at ${piholeVersion}" echo "::: Pi-hole version is now at ${piholeVersion}"
echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'" echo "::: If you had made any changes in '/etc/.pihole', they have been stashed using 'git stash'"
echo "" echo ""
fi fi

View file

@ -15,62 +15,62 @@ latest=false
current=false current=false
normalOutput() { normalOutput() {
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest})" echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest})"
echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest})" echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest})"
} }
webOutput() { webOutput() {
for var in "$@"; do for var in "$@"; do
case "${var}" in case "${var}" in
"-l" | "--latest" ) latest=true;; "-l" | "--latest" ) latest=true;;
"-c" | "--current" ) current=true;; "-c" | "--current" ) current=true;;
* ) echo "::: Invalid Option!"; exit 1; * ) echo "::: Invalid Option!"; exit 1;
esac esac
done done
if [[ "${latest}" == true && "${current}" == false ]]; then if [[ "${latest}" == true && "${current}" == false ]]; then
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
echo ${webVersionLatest} echo ${webVersionLatest}
elif [[ "${latest}" == false && "${current}" == true ]]; then elif [[ "${latest}" == false && "${current}" == true ]]; then
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
echo ${webVersion} echo ${webVersion}
else else
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0) webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)" echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)"
fi fi
} }
coreOutput() { coreOutput() {
for var in "$@"; do for var in "$@"; do
case "${var}" in case "${var}" in
"-l" | "--latest" ) latest=true;; "-l" | "--latest" ) latest=true;;
"-c" | "--current" ) current=true;; "-c" | "--current" ) current=true;;
* ) echo "::: Invalid Option!"; exit 1; * ) echo "::: Invalid Option!"; exit 1;
esac esac
done done
if [[ "${latest}" == true && "${current}" == false ]]; then if [[ "${latest}" == true && "${current}" == false ]]; then
piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
echo ${piholeVersionLatest} echo ${piholeVersionLatest}
elif [[ "${latest}" == false && "${current}" == true ]]; then elif [[ "${latest}" == false && "${current}" == true ]]; then
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
echo ${piholeVersion} echo ${piholeVersion}
else else
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//') piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)" echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
fi fi
} }
helpFunc() { helpFunc() {
cat << EOM cat << EOM
::: :::
::: Show Pi-hole/Web Admin versions ::: Show Pi-hole/Web Admin versions
::: :::
@ -84,17 +84,17 @@ helpFunc() {
::: -h, --help Show this help dialog ::: -h, --help Show this help dialog
::: :::
EOM EOM
exit 1 exit 1
} }
if [[ $# = 0 ]]; then if [[ $# = 0 ]]; then
normalOutput normalOutput
fi fi
for var in "$@"; do for var in "$@"; do
case "${var}" in case "${var}" in
"-a" | "--admin" ) shift; webOutput "$@";; "-a" | "--admin" ) shift; webOutput "$@";;
"-p" | "--pihole" ) shift; coreOutput "$@" ;; "-p" | "--pihole" ) shift; coreOutput "$@" ;;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;
esac esac
done done