mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-22 23:30:13 +00:00
Merge branch 'development' of https://github.com/airencracken/pi-hole into airencracken-dev
This commit is contained in:
commit
d0826b2c33
13 changed files with 949 additions and 961 deletions
|
@ -48,58 +48,87 @@ HandleOther(){
|
|||
if [ -z "$validDomain" ]; then
|
||||
echo "::: $1 is not a valid argument or domain name"
|
||||
else
|
||||
domList=("${domList[@]}" ${validDomain})
|
||||
domList=("${domList[@]}" ${validDomain})
|
||||
fi
|
||||
}
|
||||
|
||||
PopBlacklistFile() {
|
||||
#check blacklist file exists, and if not, create it
|
||||
if [[ ! -f ${blacklist} ]];then
|
||||
touch ${blacklist}
|
||||
if [[ ! -f ${blacklist} ]]; then
|
||||
touch ${blacklist}
|
||||
fi
|
||||
for dom in "${domList[@]}"; do
|
||||
if "$addmode"; then
|
||||
AddDomain "$dom"
|
||||
else
|
||||
RemoveDomain "$dom"
|
||||
fi
|
||||
if "${addmode}"; then
|
||||
AddDomain "${dom}"
|
||||
else
|
||||
RemoveDomain "${dom}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
AddDomain() {
|
||||
#| sed 's/\./\\./g'
|
||||
#| sed 's/\./\\./g'
|
||||
bool=false
|
||||
grep -Ex -q "$1" ${blacklist} || bool=true
|
||||
if ${bool}; then
|
||||
#domain not found in the blacklist file, add it!
|
||||
if ${verbose}; then
|
||||
echo -n "::: Adding $1 to blacklist file..."
|
||||
fi
|
||||
echo "$1" >> ${blacklist}
|
||||
#domain not found in the blacklist file, add it!
|
||||
if ${verbose}; then
|
||||
echo -n "::: Adding $1 to blacklist file..."
|
||||
fi
|
||||
echo "${1}" >> ${blacklist}
|
||||
modifyHost=true
|
||||
echo " done!"
|
||||
else
|
||||
if ${verbose}; then
|
||||
echo "::: $1 already exists in $blacklist! No need to add"
|
||||
echo "::: ${1} already exists in ${blacklist}! No need to add"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
RemoveDomain() {
|
||||
bool=false
|
||||
grep -Ex -q "$1" ${blacklist} || bool=true
|
||||
if ${bool}; then
|
||||
#Domain is not in the blacklist file, no need to Remove
|
||||
if ${verbose}; then
|
||||
echo "::: $1 is NOT blacklisted! No need to remove"
|
||||
fi
|
||||
else
|
||||
#Domain is in the blacklist file, remove it
|
||||
if ${verbose}; then
|
||||
echo "::: Un-blacklisting ${dom}..."
|
||||
fi
|
||||
echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
|
||||
fi
|
||||
}
|
||||
|
||||
bool=false
|
||||
grep -Ex -q "$1" ${blacklist} || bool=true
|
||||
if ${bool}; then
|
||||
#Domain is not in the blacklist file, no need to Remove
|
||||
if ${verbose}; then
|
||||
echo "::: $1 is NOT blacklisted! No need to remove"
|
||||
fi
|
||||
else
|
||||
#Domain is in the blacklist file,remove it
|
||||
if ${verbose}; then
|
||||
echo "::: Un-blacklisting $dom..."
|
||||
fi
|
||||
echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
|
||||
fi
|
||||
ModifyHostFile() {
|
||||
if ${addmode}; then
|
||||
#add domains to the hosts file
|
||||
if [[ -r ${blacklist} ]]; then
|
||||
numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l)
|
||||
plural=; [[ "${numberOf}" != "1" ]] && plural=s
|
||||
echo ":::"
|
||||
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
|
||||
if [[ -n ${piholeIPv6} ]]; then
|
||||
cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList}
|
||||
else
|
||||
cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo ":::"
|
||||
for dom in "${domToRemoveList[@]}"; do
|
||||
#we need to remove the domains from the blacklist file and the host file
|
||||
echo "::: ${dom}"
|
||||
echo -n "::: removing from HOSTS file..."
|
||||
echo "${dom}" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' ${adList}
|
||||
echo " done!"
|
||||
echo -n "::: removing from blackist.txt..."
|
||||
echo "${dom}" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
|
||||
echo " done!"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
Reload() {
|
||||
|
@ -110,25 +139,23 @@ DisplayBlist() {
|
|||
verbose=false
|
||||
echo -e " Displaying Gravity Affected Domains \n"
|
||||
count=1
|
||||
while IFS= read -r AD
|
||||
do
|
||||
echo "${count}: $AD"
|
||||
while IFS= read -r AD; do
|
||||
echo "${count}: ${AD}"
|
||||
count=$((count+1))
|
||||
done < "$blacklist"
|
||||
done < "${blacklist}"
|
||||
}
|
||||
|
||||
###################################################
|
||||
|
||||
for var in "$@"
|
||||
do
|
||||
case "$var" in
|
||||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-q" | "--quiet" ) verbose=false;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-l" | "--list" ) DisplayBlist;;
|
||||
* ) HandleOther "$var";;
|
||||
esac
|
||||
for var in "$@"; do
|
||||
case "$var" in
|
||||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-q" | "--quiet" ) verbose=false;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-l" | "--list" ) DisplayBlist;;
|
||||
* ) HandleOther "$var";;
|
||||
esac
|
||||
done
|
||||
|
||||
PopBlacklistFile
|
||||
|
|
|
@ -19,9 +19,9 @@ today=$(date "+%b %e")
|
|||
|
||||
CalcBlockedDomains() {
|
||||
CheckIPv6
|
||||
if [ -e "$gravity" ]; then
|
||||
if [ -e "${gravity}" ]; then
|
||||
#Are we IPV6 or IPV4?
|
||||
if [[ -n ${piholeIPv6} ]];then
|
||||
if [[ -n ${piholeIPv6} ]]; then
|
||||
#We are IPV6
|
||||
blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}')
|
||||
else
|
||||
|
@ -34,15 +34,15 @@ CalcBlockedDomains() {
|
|||
}
|
||||
|
||||
CalcQueriesToday() {
|
||||
if [ -e "$piLog" ];then
|
||||
queriesToday=$(cat "$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l)
|
||||
if [ -e "${piLog}" ]; then
|
||||
queriesToday=$(cat "${piLog}" | grep "${today}" | awk '/query/ {print $6}' | wc -l)
|
||||
else
|
||||
queriesToday="Err."
|
||||
fi
|
||||
}
|
||||
|
||||
CalcblockedToday() {
|
||||
if [ -e "$piLog" ] && [ -e "$gravity" ];then
|
||||
if [ -e "${piLog}" ] && [ -e "${gravity}" ];then
|
||||
blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l)
|
||||
else
|
||||
blockedToday="Err."
|
||||
|
@ -50,11 +50,11 @@ CalcblockedToday() {
|
|||
}
|
||||
|
||||
CalcPercentBlockedToday() {
|
||||
if [ "$queriesToday" != "Err." ] && [ "$blockedToday" != "Err." ]; then
|
||||
if [ "$queriesToday" != 0 ]; then #Fixes divide by zero error :)
|
||||
#scale 2 rounds the number down, so we'll do scale 4 and then trim the last 2 zeros
|
||||
percentBlockedToday=$(echo "scale=4; $blockedToday/$queriesToday*100" | bc)
|
||||
percentBlockedToday=$(sed 's/.\{2\}$//' <<< "$percentBlockedToday")
|
||||
if [ "${queriesToday}" != "Err." ] && [ "${blockedToday}" != "Err." ]; then
|
||||
if [ "${queriesToday}" != 0 ]; then #Fixes divide by zero error :)
|
||||
#scale 2 rounds the number down, so we'll do scale 4 and then trim the last 2 zeros
|
||||
percentBlockedToday=$(echo "scale=4; ${blockedToday}/${queriesToday}*100" | bc)
|
||||
percentBlockedToday=$(sed 's/.\{2\}$//' <<< "${percentBlockedToday}")
|
||||
else
|
||||
percentBlockedToday=0
|
||||
fi
|
||||
|
@ -64,8 +64,8 @@ CalcPercentBlockedToday() {
|
|||
CheckIPv6() {
|
||||
piholeIPv6file="/etc/pihole/.useIPv6"
|
||||
if [[ -f ${piholeIPv6file} ]];then
|
||||
# If the file exists, then the user previously chose to use IPv6 in the automated installer
|
||||
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||
# If the file exists, then the user previously chose to use IPv6 in the automated installer
|
||||
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,7 @@ outputJSON() {
|
|||
}
|
||||
|
||||
normalChrono() {
|
||||
for (( ; ; ))
|
||||
do
|
||||
for (( ; ; )); do
|
||||
clear
|
||||
# Displays a colorful Pi-hole logo
|
||||
echo " [0;1;35;95m_[0;1;31;91m__[0m [0;1;33;93m_[0m [0;1;34;94m_[0m [0;1;36;96m_[0m"
|
||||
|
@ -111,11 +110,11 @@ normalChrono() {
|
|||
|
||||
CalcBlockedDomains
|
||||
|
||||
echo "Blocking: $blockedDomainsTotal"
|
||||
echo "Blocking: ${blockedDomainsTotal}"
|
||||
#below commented line does not add up to todaysQueryCount
|
||||
#echo "Queries: $todaysQueryCountV4 / $todaysQueryCountV6"
|
||||
echo "Queries: $queriesToday" #same total calculation as dashboard
|
||||
echo "Pi-holed: $blockedToday ($percentBlockedToday%)"
|
||||
echo "Queries: ${queriesToday}" #same total calculation as dashboard
|
||||
echo "Pi-holed: ${blockedToday} (${percentBlockedToday}%)"
|
||||
|
||||
sleep 5
|
||||
done
|
||||
|
@ -139,11 +138,10 @@ if [[ $# = 0 ]]; then
|
|||
normalChrono
|
||||
fi
|
||||
|
||||
for var in "$@"
|
||||
do
|
||||
case "$var" in
|
||||
"-j" | "--json" ) outputJSON;;
|
||||
"-h" | "--help" ) displayHelp;;
|
||||
* ) exit 1;;
|
||||
esac
|
||||
for var in "$@"; do
|
||||
case "$var" in
|
||||
"-j" | "--json" ) outputJSON;;
|
||||
"-h" | "--help" ) displayHelp;;
|
||||
* ) exit 1;;
|
||||
esac
|
||||
done
|
||||
|
|
|
@ -39,7 +39,7 @@ EOM
|
|||
|
||||
######## FIRST CHECK ########
|
||||
# Must be root to debug
|
||||
if [[ "$EUID" -eq 0 ]]; then
|
||||
if [[ "${EUID}" -eq 0 ]]; then
|
||||
echo "::: Script is executing as root user..."
|
||||
else
|
||||
echo "::: Non-root user detected..."
|
||||
|
@ -54,7 +54,7 @@ else
|
|||
fi
|
||||
|
||||
# Ensure the file exists, create if not, clear if exists.
|
||||
if [ ! -f "$DEBUG_LOG" ]; then
|
||||
if [ ! -f "${DEBUG_LOG}" ]; then
|
||||
${SUDO} touch ${DEBUG_LOG}
|
||||
${SUDO} chmod 644 ${DEBUG_LOG}
|
||||
${SUDO} chown "$USER":root ${DEBUG_LOG}
|
||||
|
@ -64,25 +64,25 @@ fi
|
|||
|
||||
### Private functions exist here ###
|
||||
log_write() {
|
||||
echo "$1" >> "${DEBUG_LOG}"
|
||||
echo "${1}" >> "${DEBUG_LOG}"
|
||||
}
|
||||
|
||||
version_check() {
|
||||
log_write "############################################################"
|
||||
log_write "########## Installed Versions ##########"
|
||||
log_write "############################################################"
|
||||
log_write "############################################################"
|
||||
log_write "########## Installed Versions ##########"
|
||||
log_write "############################################################"
|
||||
|
||||
echo "::: Detecting Pi-hole installed versions."
|
||||
pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \
|
||||
&& log_write "Pi-hole Version: $pi_hole_ver" || log_write "Pi-hole git repository not detected."
|
||||
admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \
|
||||
&& log_write "WebUI Version: $admin_ver" || log_write "Pi-hole Admin Pages git repository not detected."
|
||||
echo "::: Detecting Pi-hole installed versions."
|
||||
pi_hole_ver="$(cd /etc/.pihole/ && git describe --tags --abbrev=0)" \
|
||||
&& log_write "Pi-hole Version: $pi_hole_ver" || log_write "Pi-hole git repository not detected."
|
||||
admin_ver="$(cd /var/www/html/admin && git describe --tags --abbrev=0)" \
|
||||
&& log_write "WebUI Version: $admin_ver" || log_write "Pi-hole Admin Pages git repository not detected."
|
||||
|
||||
echo "::: Writing lighttpd version to logfile."
|
||||
light_ver="$(lighttpd -v |& head -n1)" && log_write "${light_ver}" || log_write "lighttpd not installed."
|
||||
echo "::: Writing lighttpd version to logfile."
|
||||
light_ver="$(lighttpd -v |& head -n1)" && log_write "${light_ver}" || log_write "lighttpd not installed."
|
||||
|
||||
echo "::: Writing PHP version to logfile."
|
||||
php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed."
|
||||
echo "::: Writing PHP version to logfile."
|
||||
php_ver="$(php -v |& head -n1)" && log_write "${php_ver}" || log_write "PHP not installed."
|
||||
}
|
||||
|
||||
distro_check() {
|
||||
|
@ -94,7 +94,7 @@ distro_check() {
|
|||
TMP=$(cat /etc/*release || echo "Failed to find release")
|
||||
|
||||
echo "::: Writing OS Distribution release to logfile."
|
||||
echo "$TMP" >> ${DEBUG_LOG}
|
||||
echo "${TMP}" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
|
@ -103,103 +103,96 @@ ip_check() {
|
|||
echo "######## IP Address Information #########" >> ${DEBUG_LOG}
|
||||
echo "############################################################" >> ${DEBUG_LOG}
|
||||
|
||||
echo "::: Writing local IPs to logfile"
|
||||
IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')"
|
||||
echo "$IPADDR" >> ${DEBUG_LOG}
|
||||
echo "::: Writing local IPs to logfile"
|
||||
IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')"
|
||||
echo "${IPADDR}" >> ${DEBUG_LOG}
|
||||
|
||||
IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \
|
||||
&& echo "$IP6ADDR" >> ${DEBUG_LOG} || echo "No IPv6 addresses found." >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \
|
||||
&& echo "${IP6ADDR}" >> ${DEBUG_LOG} || echo "No IPv6 addresses found." >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
|
||||
echo "::: Locating default gateway and checking connectivity"
|
||||
GATEWAY=$(ip r | grep default | cut -d ' ' -f 3)
|
||||
if [[ $? = 0 ]]
|
||||
then
|
||||
echo "::: Pinging default IPv4 gateway..."
|
||||
GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3)
|
||||
if [[ $? = 0 ]]
|
||||
then
|
||||
echo "IPv4 Gateway check:" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG}
|
||||
fi
|
||||
echo "$GATEWAY_CHECK" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
echo "::: Locating default gateway and checking connectivity"
|
||||
GATEWAY=$(ip r | grep default | cut -d ' ' -f 3)
|
||||
if [[ $? = 0 ]]; then
|
||||
echo "::: Pinging default IPv4 gateway..."
|
||||
GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3)
|
||||
if [[ $? = 0 ]]; then
|
||||
echo "IPv4 Gateway check:" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG}
|
||||
fi
|
||||
echo "${GATEWAY_CHECK}" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
|
||||
echo "::: Pinging Internet via IPv4..."
|
||||
INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)
|
||||
if [[ $? = 0 ]]
|
||||
then
|
||||
echo "IPv4 Internet check:" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "IPv4 Internet check failed:" >> ${DEBUG_LOG}
|
||||
fi
|
||||
echo "$INET_CHECK" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
fi
|
||||
echo "::: Pinging Internet via IPv4..."
|
||||
INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)
|
||||
if [[ $? = 0 ]]; then
|
||||
echo "IPv4 Internet check:" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "IPv4 Internet check failed:" >> ${DEBUG_LOG}
|
||||
fi
|
||||
echo "${INET_CHECK}" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
fi
|
||||
|
||||
GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3)
|
||||
if [[ $? = 0 ]]
|
||||
then
|
||||
echo "::: Pinging default IPv6 gateway..."
|
||||
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3)
|
||||
if [[ $? = 0 ]]
|
||||
then
|
||||
echo "IPv6 Gateway check:" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG}
|
||||
fi
|
||||
GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3)
|
||||
if [[ $? = 0 ]]; then
|
||||
echo "::: Pinging default IPv6 gateway..."
|
||||
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3)
|
||||
if [[ $? = 0 ]]; then
|
||||
echo "IPv6 Gateway check:" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG}
|
||||
fi
|
||||
|
||||
echo "::: Pinging Internet via IPv6..."
|
||||
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3)
|
||||
if [[ $? = 0 ]]
|
||||
then
|
||||
echo "IPv6 Internet check:" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "IPv6 Internet check failed:" >> ${DEBUG_LOG}
|
||||
fi
|
||||
echo "::: Pinging Internet via IPv6..."
|
||||
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3)
|
||||
if [[ $? = 0 ]]; then
|
||||
echo "IPv6 Internet check:" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "IPv6 Internet check failed:" >> ${DEBUG_LOG}
|
||||
fi
|
||||
|
||||
else
|
||||
GATEWAY_CHECK="No IPv6 Gateway Detected"
|
||||
fi
|
||||
echo "$GATEWAY_CHECK" >> ${DEBUG_LOG}
|
||||
else
|
||||
GATEWAY_CHECK="No IPv6 Gateway Detected"
|
||||
fi
|
||||
echo "${GATEWAY_CHECK}" >> ${DEBUG_LOG}
|
||||
|
||||
|
||||
echo >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
hostnameCheck() {
|
||||
echo "############################################################" >> ${DEBUG_LOG}
|
||||
echo "############################################################" >> ${DEBUG_LOG}
|
||||
echo "######## Hostname Information #########" >> ${DEBUG_LOG}
|
||||
echo "############################################################" >> ${DEBUG_LOG}
|
||||
|
||||
echo "::: Writing locally configured hostnames to logfile"
|
||||
# Write the hostname output to compare against entries in /etc/hosts, which is logged next
|
||||
echo "This Pi-hole is: $(hostname)" >> ${DEBUG_LOG}
|
||||
echo "::: Writing locally configured hostnames to logfile"
|
||||
# Write the hostname output to compare against entries in /etc/hosts, which is logged next
|
||||
echo "This Pi-hole is: $(hostname)" >> ${DEBUG_LOG}
|
||||
|
||||
echo "::: Writing hosts file to debug log..."
|
||||
echo "### Hosts ###" >> ${DEBUG_LOG}
|
||||
echo "::: Writing hosts file to debug log..."
|
||||
echo "### Hosts ###" >> ${DEBUG_LOG}
|
||||
|
||||
if [ -e "$HOSTSFILE" ]
|
||||
then
|
||||
cat "$HOSTSFILE" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No hosts file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo hosts file found!\n"
|
||||
fi
|
||||
if [ -e "${HOSTSFILE}" ]; then
|
||||
cat "${HOSTSFILE}" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No hosts file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo hosts file found!\n"
|
||||
fi
|
||||
}
|
||||
|
||||
portCheck() {
|
||||
echo "############################################################" >> ${DEBUG_LOG}
|
||||
echo "############################################################" >> ${DEBUG_LOG}
|
||||
echo "######## Open Port Information #########" >> ${DEBUG_LOG}
|
||||
echo "############################################################" >> ${DEBUG_LOG}
|
||||
|
||||
echo "::: Detecting local server port 80 and 53 processes."
|
||||
echo "::: Detecting local server port 80 and 53 processes."
|
||||
|
||||
${SUDO} lsof -i :80 >> ${DEBUG_LOG}
|
||||
${SUDO} lsof -i :53 >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
${SUDO} lsof -i :80 >> ${DEBUG_LOG}
|
||||
${SUDO} lsof -i :53 >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
testResolver() {
|
||||
|
@ -209,59 +202,57 @@ testResolver() {
|
|||
|
||||
|
||||
# Find a blocked url that has not been whitelisted.
|
||||
TESTURL="doubleclick.com"
|
||||
if [ -s "$WHITELISTMATCHES" ]; then
|
||||
TESTURL="doubleclick.com"
|
||||
if [ -s "${WHITELISTMATCHES}" ]; then
|
||||
while read -r line; do
|
||||
CUTURL=${line#*" "}
|
||||
if [ "$CUTURL" != "Pi-Hole.IsWorking.OK" ]; then
|
||||
if [ "${CUTURL}" != "Pi-Hole.IsWorking.OK" ]; then
|
||||
while read -r line2; do
|
||||
CUTURL2=${line2#*" "}
|
||||
if [ "$CUTURL" != "$CUTURL2" ]; then
|
||||
TESTURL="$CUTURL"
|
||||
if [ "${CUTURL}" != "${CUTURL2}" ]; then
|
||||
TESTURL="${CUTURL}"
|
||||
break 2
|
||||
fi
|
||||
done < "$WHITELISTMATCHES"
|
||||
done < "${WHITELISTMATCHES}"
|
||||
fi
|
||||
done < "$GRAVITYFILE"
|
||||
done < "${GRAVITYFILE}"
|
||||
fi
|
||||
|
||||
echo "Resolution of $TESTURL from Pi-hole:" >> ${DEBUG_LOG}
|
||||
LOCALDIG=$(dig "$TESTURL" @127.0.0.1)
|
||||
if [[ $? = 0 ]]
|
||||
then
|
||||
echo "$LOCALDIG" >> ${DEBUG_LOG}
|
||||
echo "Resolution of ${TESTURL} from Pi-hole:" >> ${DEBUG_LOG}
|
||||
LOCALDIG=$(dig "${TESTURL}" @127.0.0.1)
|
||||
if [[ $? = 0 ]]; then
|
||||
echo "${LOCALDIG}" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "Failed to resolve $TESTURL on Pi-hole" >> ${DEBUG_LOG}
|
||||
echo "Failed to resolve ${TESTURL} on Pi-hole" >> ${DEBUG_LOG}
|
||||
fi
|
||||
echo >> ${DEBUG_LOG}
|
||||
|
||||
|
||||
echo "Resolution of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG}
|
||||
REMOTEDIG=$(dig "$TESTURL" @8.8.8.8)
|
||||
if [[ $? = 0 ]]
|
||||
then
|
||||
echo "$REMOTEDIG" >> ${DEBUG_LOG}
|
||||
echo "Resolution of ${TESTURL} from 8.8.8.8:" >> ${DEBUG_LOG}
|
||||
REMOTEDIG=$(dig "${TESTURL}" @8.8.8.8)
|
||||
if [[ $? = 0 ]]; then
|
||||
echo "${REMOTEDIG}" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "Failed to resolve $TESTURL on 8.8.8.8" >> ${DEBUG_LOG}
|
||||
echo "Failed to resolve ${TESTURL} on 8.8.8.8" >> ${DEBUG_LOG}
|
||||
fi
|
||||
echo >> ${DEBUG_LOG}
|
||||
|
||||
echo "Pi-hole dnsmasq specific records lookups" >> ${DEBUG_LOG}
|
||||
echo "Cache Size:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt cachesize.bind >> ${DEBUG_LOG}
|
||||
echo "Insertions count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt insertions.bind >> ${DEBUG_LOG}
|
||||
echo "Evictions count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt evictions.bind >> ${DEBUG_LOG}
|
||||
echo "Misses count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt misses.bind >> ${DEBUG_LOG}
|
||||
echo "Hits count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt hits.bind >> ${DEBUG_LOG}
|
||||
echo "Auth count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt auth.bind >> ${DEBUG_LOG}
|
||||
echo "Upstream Servers:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt servers.bind >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
echo "Cache Size:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt cachesize.bind >> ${DEBUG_LOG}
|
||||
echo "Insertions count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt insertions.bind >> ${DEBUG_LOG}
|
||||
echo "Evictions count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt evictions.bind >> ${DEBUG_LOG}
|
||||
echo "Misses count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt misses.bind >> ${DEBUG_LOG}
|
||||
echo "Hits count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt hits.bind >> ${DEBUG_LOG}
|
||||
echo "Auth count:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt auth.bind >> ${DEBUG_LOG}
|
||||
echo "Upstream Servers:" >> ${DEBUG_LOG}
|
||||
dig +short chaos txt servers.bind >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
||||
checkProcesses() {
|
||||
|
@ -271,12 +262,11 @@ checkProcesses() {
|
|||
echo ":::"
|
||||
echo "::: Logging status of lighttpd and dnsmasq..."
|
||||
PROCESSES=( lighttpd dnsmasq )
|
||||
for i in "${PROCESSES[@]}"
|
||||
do
|
||||
for i in "${PROCESSES[@]}"; do
|
||||
echo "" >> ${DEBUG_LOG}
|
||||
echo -n "$i" >> "$DEBUG_LOG"
|
||||
echo -n "${i}" >> "${DEBUG_LOG}"
|
||||
echo " processes status:" >> ${DEBUG_LOG}
|
||||
${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG"
|
||||
${SUDO} systemctl -l status "${i}" >> "${DEBUG_LOG}"
|
||||
done
|
||||
echo >> ${DEBUG_LOG}
|
||||
}
|
||||
|
@ -286,26 +276,24 @@ debugLighttpd() {
|
|||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############ lighttpd.conf ############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$LIGHTTPDFILE" ]
|
||||
then
|
||||
if [ -e "${LIGHTTPDFILE}" ]; then
|
||||
while read -r line; do
|
||||
if [ ! -z "$line" ]; then
|
||||
[[ "$line" =~ ^#.*$ ]] && continue
|
||||
echo "$line" >> ${DEBUG_LOG}
|
||||
if [ ! -z "${line}" ]; then
|
||||
[[ "${line}" =~ ^#.*$ ]] && continue
|
||||
echo "${line}" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "$LIGHTTPDFILE"
|
||||
done < "${LIGHTTPDFILE}"
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No lighttpd.conf file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo lighttpd.conf file found\n"
|
||||
fi
|
||||
|
||||
if [ -e "$LIGHTTPDERRFILE" ]
|
||||
then
|
||||
if [ -e "${LIGHTTPDERRFILE}" ]; then
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
cat "$LIGHTTPDERRFILE" >> ${DEBUG_LOG}
|
||||
cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No lighttpd error.log file found!" >> ${DEBUG_LOG}
|
||||
printf ":::\tNo lighttpd error.log file found\n"
|
||||
|
@ -328,15 +316,14 @@ echo "::: Writing dnsmasq.conf to debug log..."
|
|||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############### Dnsmasq ###############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$DNSMASQFILE" ]
|
||||
then
|
||||
if [ -e "${DNSMASQFILE}" ]; then
|
||||
#cat $DNSMASQFILE >> $DEBUG_LOG
|
||||
while read -r line; do
|
||||
if [ ! -z "$line" ]; then
|
||||
[[ "$line" =~ ^#.*$ ]] && continue
|
||||
echo "$line" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "$DNSMASQFILE"
|
||||
if [ ! -z "${line}" ]; then
|
||||
[[ "${line}" =~ ^#.*$ ]] && continue
|
||||
echo "${line}" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "${DNSMASQFILE}"
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG}
|
||||
|
@ -347,14 +334,13 @@ echo "::: Writing 01-pihole.conf to debug log..."
|
|||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$PIHOLECONFFILE" ]
|
||||
then
|
||||
if [ -e "${PIHOLECONFFILE}" ]; then
|
||||
while read -r line; do
|
||||
if [ ! -z "$line" ]; then
|
||||
[[ "$line" =~ ^#.*$ ]] && continue
|
||||
echo "$line" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "$PIHOLECONFFILE"
|
||||
if [ ! -z "${line}" ]; then
|
||||
[[ "${line}" =~ ^#.*$ ]] && continue
|
||||
echo "${line}" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "${PIHOLECONFFILE}"
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No 01-pihole.conf file found!" >> ${DEBUG_LOG}
|
||||
|
@ -365,9 +351,8 @@ echo "::: Writing size of gravity.list to debug log..."
|
|||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############ gravity.list #############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$GRAVITYFILE" ]
|
||||
then
|
||||
wc -l "$GRAVITYFILE" >> ${DEBUG_LOG}
|
||||
if [ -e "${GRAVITYFILE}" ]; then
|
||||
wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No gravity.list file found!" >> ${DEBUG_LOG}
|
||||
|
@ -380,9 +365,8 @@ echo "::: Writing whitelist to debug log..."
|
|||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############## Whitelist ##############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$WHITELISTFILE" ]
|
||||
then
|
||||
cat "$WHITELISTFILE" >> ${DEBUG_LOG}
|
||||
if [ -e "${WHITELISTFILE}" ]; then
|
||||
cat "${WHITELISTFILE}" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No whitelist.txt file found!" >> ${DEBUG_LOG}
|
||||
|
@ -393,9 +377,8 @@ echo "::: Writing blacklist to debug log..."
|
|||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############## Blacklist ##############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$BLACKLISTFILE" ]
|
||||
then
|
||||
cat "$BLACKLISTFILE" >> ${DEBUG_LOG}
|
||||
if [ -e "${BLACKLISTFILE}" ]; then
|
||||
cat "${BLACKLISTFILE}" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No blacklist.txt file found!" >> ${DEBUG_LOG}
|
||||
|
@ -406,14 +389,13 @@ echo "::: Writing adlists.list to debug log..."
|
|||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############ adlists.list #############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$ADLISTSFILE" ]
|
||||
then
|
||||
while read -r line; do
|
||||
if [ ! -z "$line" ]; then
|
||||
[[ "$line" =~ ^#.*$ ]] && continue
|
||||
echo "$line" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "$ADLISTSFILE"
|
||||
if [ -e "${ADLISTSFILE}" ]; then
|
||||
while read -r line; do
|
||||
if [ ! -z "${line}" ]; then
|
||||
[[ "${line}" =~ ^#.*$ ]] && continue
|
||||
echo "${line}" >> ${DEBUG_LOG}
|
||||
fi
|
||||
done < "${ADLISTSFILE}"
|
||||
echo >> ${DEBUG_LOG}
|
||||
else
|
||||
echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG}
|
||||
|
@ -428,10 +410,9 @@ dumpPiHoleLog() {
|
|||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
echo "############# pihole.log ##############" >> ${DEBUG_LOG}
|
||||
echo "#######################################" >> ${DEBUG_LOG}
|
||||
if [ -e "$PIHOLELOG" ]
|
||||
then
|
||||
if [ -e "${PIHOLELOG}" ]; then
|
||||
while true; do
|
||||
tail -f "$PIHOLELOG" >> ${DEBUG_LOG}
|
||||
tail -f "${PIHOLELOG}" >> ${DEBUG_LOG}
|
||||
echo >> ${DEBUG_LOG}
|
||||
done
|
||||
else
|
||||
|
@ -442,25 +423,24 @@ dumpPiHoleLog() {
|
|||
|
||||
# Anything to be done after capturing of pihole.log terminates
|
||||
finalWork() {
|
||||
echo "::: Finshed debugging!"
|
||||
echo "::: The debug log can be uploaded to Termbin.com for easier sharing."
|
||||
read -r -p "::: Would you like to upload the log? [y/N] " response
|
||||
case ${response} in
|
||||
[yY][eE][sS]|[yY])
|
||||
TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999)
|
||||
;;
|
||||
*)
|
||||
echo "::: Log will NOT be uploaded to Termbin."
|
||||
;;
|
||||
esac
|
||||
echo "::: Finshed debugging!"
|
||||
echo "::: The debug log can be uploaded to Termbin.com for easier sharing."
|
||||
read -r -p "::: Would you like to upload the log? [y/N] " response
|
||||
case ${response} in
|
||||
[yY][eE][sS]|[yY])
|
||||
TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999)
|
||||
;;
|
||||
*)
|
||||
echo "::: Log will NOT be uploaded to Termbin."
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check if termbin.com is reachable. When it's not, point to local log instead
|
||||
if [ -n "$TERMBIN" ]
|
||||
then
|
||||
echo "::: Debug log can be found at : $TERMBIN"
|
||||
else
|
||||
echo "::: Debug log can be found at : /var/log/pihole_debug.log"
|
||||
fi
|
||||
# Check if termbin.com is reachable. When it's not, point to local log instead
|
||||
if [ -n "${TERMBIN}" ]; then
|
||||
echo "::: Debug log can be found at : ${TERMBIN}"
|
||||
else
|
||||
echo "::: Debug log can be found at : /var/log/pihole_debug.log"
|
||||
fi
|
||||
}
|
||||
|
||||
trap finalWork EXIT
|
||||
|
|
|
@ -15,28 +15,28 @@
|
|||
# Borrowed from adafruit-pitft-helper < borrowed from raspi-config
|
||||
# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L324-L334
|
||||
getInitSys() {
|
||||
if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
|
||||
SYSTEMD=1
|
||||
elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
|
||||
SYSTEMD=0
|
||||
else
|
||||
echo "Unrecognised init system"
|
||||
return 1
|
||||
fi
|
||||
if command -v systemctl > /dev/null && systemctl | grep -q '\-\.mount'; then
|
||||
SYSTEMD=1
|
||||
elif [ -f /etc/init.d/cron ] && [ ! -h /etc/init.d/cron ]; then
|
||||
SYSTEMD=0
|
||||
else
|
||||
echo "Unrecognised init system"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Borrowed from adafruit-pitft-helper:
|
||||
# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285
|
||||
autoLoginPiToConsole() {
|
||||
if [ -e /etc/init.d/lightdm ]; then
|
||||
if [ ${SYSTEMD} -eq 1 ]; then
|
||||
systemctl set-default multi-user.target
|
||||
ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
|
||||
else
|
||||
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/"
|
||||
fi
|
||||
fi
|
||||
if [ -e /etc/init.d/lightdm ]; then
|
||||
if [ ${SYSTEMD} -eq 1 ]; then
|
||||
systemctl set-default multi-user.target
|
||||
ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
|
||||
else
|
||||
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/"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
######### SCRIPT ###########
|
||||
|
|
|
@ -18,17 +18,17 @@ piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
|
|||
piholeFilesDir="/etc/.pihole"
|
||||
|
||||
spinner() {
|
||||
local pid=$1
|
||||
local delay=0.50
|
||||
local spinstr='/-\|'
|
||||
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
||||
local pid=${1}
|
||||
local delay=0.50
|
||||
local spinstr='/-\|'
|
||||
while [ "$(ps a | awk '{print $1}' | grep "${pid}")" ]; do
|
||||
local temp=${spinstr#?}
|
||||
printf " [%c] " "$spinstr"
|
||||
local spinstr=${temp}${spinstr%"$temp"}
|
||||
sleep ${delay}
|
||||
printf "\b\b\b\b\b\b"
|
||||
done
|
||||
printf " \b\b\b\b"
|
||||
printf " [%c] " "${spinstr}"
|
||||
local spinstr=${temp}${spinstr%"$temp"}
|
||||
sleep ${delay}
|
||||
printf "\b\b\b\b\b\b"
|
||||
done
|
||||
printf " \b\b\b\b"
|
||||
}
|
||||
|
||||
getGitFiles() {
|
||||
|
@ -37,45 +37,45 @@ getGitFiles() {
|
|||
echo ":::"
|
||||
echo "::: Checking for existing repository..."
|
||||
if is_repo "${1}"; then
|
||||
update_repo "${1}"
|
||||
update_repo "${1}"
|
||||
else
|
||||
make_repo "${1}" "${2}"
|
||||
fi
|
||||
make_repo "${1}" "${2}"
|
||||
fi
|
||||
}
|
||||
|
||||
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..."
|
||||
cd "${1}" &> /dev/null || return 1
|
||||
git status &> /dev/null && echo " OK!"; return 0 || echo " not found!"; return 1
|
||||
}
|
||||
|
||||
make_repo() {
|
||||
# Remove the non-repod interface and clone the interface
|
||||
echo -n "::: Cloning $2 into $1..."
|
||||
rm -rf "${1}"
|
||||
git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
# Remove the non-repod interface and clone the interface
|
||||
echo -n "::: Cloning $2 into $1..."
|
||||
rm -rf "${1}"
|
||||
git clone -q --depth 1 "${2}" "${1}" > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
update_repo() {
|
||||
# Pull the latest commits
|
||||
echo -n "::: Updating repo in $1..."
|
||||
cd "${1}" || exit 1
|
||||
git stash -q > /dev/null & spinner $!
|
||||
git pull -q > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
# Pull the latest commits
|
||||
echo -n "::: Updating repo in $1..."
|
||||
cd "${1}" || exit 1
|
||||
git stash -q > /dev/null & spinner $!
|
||||
git pull -q > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
}
|
||||
|
||||
if [ ! -d "/etc/.pihole" ]; then #This is unlikely
|
||||
echo "::: Critical Error: Pi-Hole repo missing from system!"
|
||||
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||
exit 1;
|
||||
echo "::: Critical Error: Pi-Hole repo missing from system!"
|
||||
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||
exit 1;
|
||||
fi
|
||||
if [ ! -d "/var/www/html/admin" ]; then #This is unlikely
|
||||
echo "::: Critical Error: Pi-Hole repo missing from system!"
|
||||
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||
exit 1;
|
||||
echo "::: Critical Error: Pi-Hole repo missing from system!"
|
||||
echo "::: Please re-run install script from https://github.com/pi-hole/pi-hole"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "::: Checking for updates..."
|
||||
|
@ -105,40 +105,38 @@ echo ":::"
|
|||
|
||||
|
||||
if [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then
|
||||
echo "::: Everything is up to date!"
|
||||
echo ""
|
||||
exit 0
|
||||
echo "::: Everything is up to date!"
|
||||
echo ""
|
||||
exit 0
|
||||
|
||||
elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then
|
||||
echo "::: Pi-hole Web Admin files out of date"
|
||||
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl}
|
||||
echo ":::"
|
||||
webVersion=$(pihole -v -a -c)
|
||||
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 ""
|
||||
|
||||
echo "::: Pi-hole Web Admin files out of date"
|
||||
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl}
|
||||
echo ":::"
|
||||
webVersion=$(pihole -v -a -c)
|
||||
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 ""
|
||||
elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVersionLatest} ]]; then
|
||||
echo "::: Pi-hole core files out of date"
|
||||
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
|
||||
/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended
|
||||
echo ":::"
|
||||
piholeVersion=$(pihole -v -p -c)
|
||||
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 ""
|
||||
|
||||
echo "::: Pi-hole core files out of date"
|
||||
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
|
||||
/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended
|
||||
echo ":::"
|
||||
piholeVersion=$(pihole -v -p -c)
|
||||
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 ""
|
||||
elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} != ${webVersionLatest} ]]; then
|
||||
echo "::: Updating Everything"
|
||||
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
|
||||
/etc/.pihole/automated\ install/basic-install.sh --unattended
|
||||
webVersion=$(pihole -v -a -c)
|
||||
piholeVersion=$(pihole -v -p -c)
|
||||
echo ":::"
|
||||
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 ":::"
|
||||
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 ""
|
||||
echo "::: Updating Everything"
|
||||
getGitFiles ${piholeFilesDir} ${piholeGitUrl}
|
||||
/etc/.pihole/automated\ install/basic-install.sh --unattended
|
||||
webVersion=$(pihole -v -a -c)
|
||||
piholeVersion=$(pihole -v -p -c)
|
||||
echo ":::"
|
||||
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 ":::"
|
||||
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 ""
|
||||
fi
|
||||
|
|
|
@ -15,60 +15,58 @@ latest=false
|
|||
current=false
|
||||
|
||||
normalOutput() {
|
||||
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
||||
webVersion=$(cd /var/www/html/admin/ && 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)
|
||||
|
||||
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/",$//')
|
||||
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/",$//')
|
||||
|
||||
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
|
||||
echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)"
|
||||
echo "::: Pi-hole version is ${piholeVersion} (Latest version is ${piholeVersionLatest})"
|
||||
echo "::: Web-Admin version is ${webVersion} (Latest version is ${webVersionLatest})"
|
||||
}
|
||||
|
||||
webOutput() {
|
||||
for var in "$@"
|
||||
do
|
||||
case "$var" in
|
||||
"-l" | "--latest" ) latest=true;;
|
||||
"-c" | "--current" ) current=true;;
|
||||
* ) echo "::: Invalid Option!"; exit 1;
|
||||
esac
|
||||
done
|
||||
for var in "$@"; do
|
||||
case "${var}" in
|
||||
"-l" | "--latest" ) latest=true;;
|
||||
"-c" | "--current" ) current=true;;
|
||||
* ) echo "::: Invalid Option!"; exit 1;
|
||||
esac
|
||||
done
|
||||
|
||||
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/",$//')
|
||||
echo ${webVersionLatest}
|
||||
elif [[ "${latest}" == false && "${current}" == true ]]; then
|
||||
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
||||
echo ${webVersion}
|
||||
else
|
||||
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/",$//')
|
||||
echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)"
|
||||
fi
|
||||
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/",$//')
|
||||
echo ${webVersionLatest}
|
||||
elif [[ "${latest}" == false && "${current}" == true ]]; then
|
||||
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
|
||||
echo ${webVersion}
|
||||
else
|
||||
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/",$//')
|
||||
echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)"
|
||||
fi
|
||||
}
|
||||
|
||||
coreOutput() {
|
||||
for var in "$@"
|
||||
do
|
||||
case "$var" in
|
||||
"-l" | "--latest" ) latest=true;;
|
||||
"-c" | "--current" ) current=true;;
|
||||
* ) echo "::: Invalid Option!"; exit 1;
|
||||
esac
|
||||
done
|
||||
for var in "$@"; do
|
||||
case "${var}" in
|
||||
"-l" | "--latest" ) latest=true;;
|
||||
"-c" | "--current" ) current=true;;
|
||||
* ) echo "::: Invalid Option!"; exit 1;
|
||||
esac
|
||||
done
|
||||
|
||||
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/",$//')
|
||||
echo ${piholeVersionLatest}
|
||||
elif [[ "${latest}" == false && "${current}" == true ]]; then
|
||||
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
||||
echo ${piholeVersion}
|
||||
else
|
||||
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/",$//')
|
||||
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
|
||||
fi
|
||||
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/",$//')
|
||||
echo ${piholeVersionLatest}
|
||||
elif [[ "${latest}" == false && "${current}" == true ]]; then
|
||||
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
|
||||
echo ${piholeVersion}
|
||||
else
|
||||
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/",$//')
|
||||
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
|
||||
fi
|
||||
}
|
||||
|
||||
helpFunc() {
|
||||
|
@ -93,11 +91,10 @@ if [[ $# = 0 ]]; then
|
|||
normalOutput
|
||||
fi
|
||||
|
||||
for var in "$@"
|
||||
do
|
||||
case "$var" in
|
||||
"-a" | "--admin" ) shift; webOutput "$@";;
|
||||
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
esac
|
||||
for var in "$@"; do
|
||||
case "${var}" in
|
||||
"-a" | "--admin" ) shift; webOutput "$@";;
|
||||
"-p" | "--pihole" ) shift; coreOutput "$@" ;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
esac
|
||||
done
|
||||
|
|
|
@ -46,30 +46,29 @@ domToRemoveList=()
|
|||
HandleOther(){
|
||||
#check validity of domain
|
||||
validDomain=$(echo "$1" | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/')
|
||||
if [ -z "$validDomain" ]; then
|
||||
if [ -z "${validDomain}" ]; then
|
||||
echo "::: $1 is not a valid argument or domain name"
|
||||
else
|
||||
domList=("${domList[@]}" ${validDomain})
|
||||
domList=("${domList[@]}" ${validDomain})
|
||||
fi
|
||||
}
|
||||
|
||||
PopWhitelistFile() {
|
||||
#check whitelist file exists, and if not, create it
|
||||
if [[ ! -f ${whitelist} ]];then
|
||||
touch ${whitelist}
|
||||
if [[ ! -f ${whitelist} ]]; then
|
||||
touch ${whitelist}
|
||||
fi
|
||||
for dom in "${domList[@]}"
|
||||
do
|
||||
if ${addmode}; then
|
||||
AddDomain "$dom"
|
||||
else
|
||||
RemoveDomain "$dom"
|
||||
fi
|
||||
for dom in "${domList[@]}"; do
|
||||
if ${addmode}; then
|
||||
AddDomain "${dom}"
|
||||
else
|
||||
RemoveDomain "${dom}"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
AddDomain() {
|
||||
#| sed 's/\./\\./g'
|
||||
#| sed 's/\./\\./g'
|
||||
bool=false
|
||||
|
||||
grep -Ex -q "$1" ${whitelist} || bool=true
|
||||
|
@ -84,7 +83,7 @@ AddDomain() {
|
|||
fi
|
||||
else
|
||||
if ${verbose}; then
|
||||
echo "::: $1 already exists in $whitelist, no need to add!"
|
||||
echo "::: ${1} already exists in ${whitelist}, no need to add!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -112,25 +111,24 @@ DisplayWlist() {
|
|||
verbose=false
|
||||
echo -e " Displaying Gravity Resistant Domains \n"
|
||||
count=1
|
||||
while IFS= read -r RD
|
||||
do
|
||||
echo "${count}: $RD"
|
||||
while IFS= read -r RD; do
|
||||
echo "${count}: ${RD}"
|
||||
count=$((count+1))
|
||||
done < "$whitelist"
|
||||
done < "${whitelist}"
|
||||
}
|
||||
|
||||
###################################################
|
||||
|
||||
for var in "$@"
|
||||
do
|
||||
case "$var" in
|
||||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-q" | "--quiet" ) verbose=false;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-l" | "--list" ) DisplayWlist;;
|
||||
* ) HandleOther "$var";;
|
||||
esac
|
||||
for var in "$@"; do
|
||||
case "${var}" in
|
||||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-f" | "--force" ) force=true;;
|
||||
"-q" | "--quiet" ) verbose=false;;
|
||||
"-h" | "--help" ) helpFunc;;
|
||||
"-l" | "--list" ) DisplayWlist;;
|
||||
* ) HandleOther "${var}";;
|
||||
esac
|
||||
done
|
||||
|
||||
PopWhitelistFile
|
||||
|
@ -138,6 +136,3 @@ PopWhitelistFile
|
|||
if ${reload}; then
|
||||
Reload
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
_pihole()
|
||||
{
|
||||
local cur prev opts
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="blacklist chronometer debug flush help query reconfigure setupLCD uninstall updateGravity updatePihole version whitelist"
|
||||
_pihole() {
|
||||
local cur prev opts
|
||||
COMPREPLY=()
|
||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||
opts="blacklist chronometer debug flush help query reconfigure setupLCD uninstall updateGravity updatePihole version whitelist"
|
||||
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||
return 0
|
||||
}
|
||||
complete -F _pihole pihole
|
||||
complete -F _pihole pihole
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This file is under source-control of the Pi-hole installation and update
|
||||
# scripts, any changes made to this file will be overwritten when the softare
|
||||
# is updated or re-installed. Please make any changes to the appropriate crontab
|
||||
# or other cron file snippets.
|
||||
|
||||
# Pi-hole: Update the ad sources once a week on Sunday at 01:59
|
||||
# Download any updates from the adlists
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue