Merge branch 'development' of https://github.com/airencracken/pi-hole into airencracken-dev

pull/814/head
Promofaux 8 years ago
commit d0826b2c33

@ -54,20 +54,20 @@ HandleOther(){
PopBlacklistFile() { PopBlacklistFile() {
#check blacklist file exists, and if not, create it #check blacklist file exists, and if not, create it
if [[ ! -f ${blacklist} ]];then if [[ ! -f ${blacklist} ]]; then
touch ${blacklist} touch ${blacklist}
fi fi
for dom in "${domList[@]}"; do for dom in "${domList[@]}"; do
if "$addmode"; then if "${addmode}"; then
AddDomain "$dom" AddDomain "${dom}"
else else
RemoveDomain "$dom" RemoveDomain "${dom}"
fi fi
done done
} }
AddDomain() { AddDomain() {
#| sed 's/\./\\./g' #| sed 's/\./\\./g'
bool=false bool=false
grep -Ex -q "$1" ${blacklist} || bool=true grep -Ex -q "$1" ${blacklist} || bool=true
if ${bool}; then if ${bool}; then
@ -75,17 +75,17 @@ AddDomain() {
if ${verbose}; then if ${verbose}; then
echo -n "::: Adding $1 to blacklist file..." echo -n "::: Adding $1 to blacklist file..."
fi fi
echo "$1" >> ${blacklist} echo "${1}" >> ${blacklist}
modifyHost=true
echo " done!" echo " done!"
else else
if ${verbose}; then 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
fi fi
} }
RemoveDomain() { RemoveDomain() {
bool=false bool=false
grep -Ex -q "$1" ${blacklist} || bool=true grep -Ex -q "$1" ${blacklist} || bool=true
if ${bool}; then if ${bool}; then
@ -94,14 +94,43 @@ RemoveDomain() {
echo "::: $1 is NOT blacklisted! No need to remove" echo "::: $1 is NOT blacklisted! No need to remove"
fi fi
else else
#Domain is in the blacklist file,remove it #Domain is in the blacklist file, remove it
if ${verbose}; then if ${verbose}; then
echo "::: Un-blacklisting $dom..." echo "::: Un-blacklisting ${dom}..."
fi fi
echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist} echo "$1" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
fi 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() { Reload() {
pihole -g -sd pihole -g -sd
} }
@ -110,17 +139,15 @@ DisplayBlist() {
verbose=false verbose=false
echo -e " Displaying Gravity Affected Domains \n" echo -e " Displaying Gravity Affected Domains \n"
count=1 count=1
while IFS= read -r AD while IFS= read -r AD; do
do echo "${count}: ${AD}"
echo "${count}: $AD"
count=$((count+1)) count=$((count+1))
done < "$blacklist" done < "${blacklist}"
} }
################################################### ###################################################
for var in "$@" for var in "$@"; do
do
case "$var" in case "$var" in
"-nr"| "--noreload" ) reload=false;; "-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;; "-d" | "--delmode" ) addmode=false;;

@ -19,9 +19,9 @@ today=$(date "+%b %e")
CalcBlockedDomains() { CalcBlockedDomains() {
CheckIPv6 CheckIPv6
if [ -e "$gravity" ]; then if [ -e "${gravity}" ]; then
#Are we IPV6 or IPV4? #Are we IPV6 or IPV4?
if [[ -n ${piholeIPv6} ]];then if [[ -n ${piholeIPv6} ]]; then
#We are IPV6 #We are IPV6
blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}') blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}')
else else
@ -34,15 +34,15 @@ CalcBlockedDomains() {
} }
CalcQueriesToday() { CalcQueriesToday() {
if [ -e "$piLog" ];then if [ -e "${piLog}" ]; then
queriesToday=$(cat "$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l) queriesToday=$(cat "${piLog}" | grep "${today}" | awk '/query/ {print $6}' | wc -l)
else else
queriesToday="Err." queriesToday="Err."
fi fi
} }
CalcblockedToday() { 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) blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l)
else else
blockedToday="Err." blockedToday="Err."
@ -50,11 +50,11 @@ CalcblockedToday() {
} }
CalcPercentBlockedToday() { CalcPercentBlockedToday() {
if [ "$queriesToday" != "Err." ] && [ "$blockedToday" != "Err." ]; then if [ "${queriesToday}" != "Err." ] && [ "${blockedToday}" != "Err." ]; then
if [ "$queriesToday" != 0 ]; then #Fixes divide by zero error :) 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 #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=$(echo "scale=4; ${blockedToday}/${queriesToday}*100" | bc)
percentBlockedToday=$(sed 's/.\{2\}$//' <<< "$percentBlockedToday") percentBlockedToday=$(sed 's/.\{2\}$//' <<< "${percentBlockedToday}")
else else
percentBlockedToday=0 percentBlockedToday=0
fi fi
@ -80,8 +80,7 @@ outputJSON() {
} }
normalChrono() { normalChrono() {
for (( ; ; )) for (( ; ; )); do
do
clear clear
# Displays a colorful Pi-hole logo # Displays a colorful Pi-hole logo
echo " ___ _ _ _" echo " ___ _ _ _"
@ -111,11 +110,11 @@ normalChrono() {
CalcBlockedDomains CalcBlockedDomains
echo "Blocking: $blockedDomainsTotal" echo "Blocking: ${blockedDomainsTotal}"
#below commented line does not add up to todaysQueryCount #below commented line does not add up to todaysQueryCount
#echo "Queries: $todaysQueryCountV4 / $todaysQueryCountV6" #echo "Queries: $todaysQueryCountV4 / $todaysQueryCountV6"
echo "Queries: $queriesToday" #same total calculation as dashboard echo "Queries: ${queriesToday}" #same total calculation as dashboard
echo "Pi-holed: $blockedToday ($percentBlockedToday%)" echo "Pi-holed: ${blockedToday} (${percentBlockedToday}%)"
sleep 5 sleep 5
done done
@ -139,8 +138,7 @@ if [[ $# = 0 ]]; then
normalChrono normalChrono
fi fi
for var in "$@" for var in "$@"; do
do
case "$var" in case "$var" in
"-j" | "--json" ) outputJSON;; "-j" | "--json" ) outputJSON;;
"-h" | "--help" ) displayHelp;; "-h" | "--help" ) displayHelp;;

@ -39,7 +39,7 @@ EOM
######## FIRST CHECK ######## ######## FIRST CHECK ########
# Must be root to debug # Must be root to debug
if [[ "$EUID" -eq 0 ]]; then if [[ "${EUID}" -eq 0 ]]; then
echo "::: Script is executing as root user..." echo "::: Script is executing as root user..."
else else
echo "::: Non-root user detected..." echo "::: Non-root user detected..."
@ -54,7 +54,7 @@ else
fi fi
# Ensure the file exists, create if not, clear if exists. # 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} touch ${DEBUG_LOG}
${SUDO} chmod 644 ${DEBUG_LOG} ${SUDO} chmod 644 ${DEBUG_LOG}
${SUDO} chown "$USER":root ${DEBUG_LOG} ${SUDO} chown "$USER":root ${DEBUG_LOG}
@ -64,7 +64,7 @@ fi
### Private functions exist here ### ### Private functions exist here ###
log_write() { log_write() {
echo "$1" >> "${DEBUG_LOG}" echo "${1}" >> "${DEBUG_LOG}"
} }
version_check() { version_check() {
@ -94,7 +94,7 @@ distro_check() {
TMP=$(cat /etc/*release || echo "Failed to find release") TMP=$(cat /etc/*release || echo "Failed to find release")
echo "::: Writing OS Distribution release to logfile." echo "::: Writing OS Distribution release to logfile."
echo "$TMP" >> ${DEBUG_LOG} echo "${TMP}" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
} }
@ -105,46 +105,41 @@ ip_check() {
echo "::: Writing local IPs to logfile" echo "::: Writing local IPs to logfile"
IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')" IPADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet") print $(i+1) }')"
echo "$IPADDR" >> ${DEBUG_LOG} echo "${IPADDR}" >> ${DEBUG_LOG}
IP6ADDR="$(ip a | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "inet6") print $(i+1) }')" \ 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 "${IP6ADDR}" >> ${DEBUG_LOG} || echo "No IPv6 addresses found." >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
echo "::: Locating default gateway and checking connectivity" echo "::: Locating default gateway and checking connectivity"
GATEWAY=$(ip r | grep default | cut -d ' ' -f 3) GATEWAY=$(ip r | grep default | cut -d ' ' -f 3)
if [[ $? = 0 ]] if [[ $? = 0 ]]; then
then
echo "::: Pinging default IPv4 gateway..." echo "::: Pinging default IPv4 gateway..."
GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3) GATEWAY_CHECK=$(ping -q -w 3 -c 3 -n "${GATEWAY}" | tail -n3)
if [[ $? = 0 ]] if [[ $? = 0 ]]; then
then
echo "IPv4 Gateway check:" >> ${DEBUG_LOG} echo "IPv4 Gateway check:" >> ${DEBUG_LOG}
else else
echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG} echo "IPv4 Gateway check failed:" >> ${DEBUG_LOG}
fi fi
echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} echo "${GATEWAY_CHECK}" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
echo "::: Pinging Internet via IPv4..." echo "::: Pinging Internet via IPv4..."
INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3) INET_CHECK=$(ping -q -w 5 -c 3 -n 8.8.8.8 | tail -n3)
if [[ $? = 0 ]] if [[ $? = 0 ]]; then
then
echo "IPv4 Internet check:" >> ${DEBUG_LOG} echo "IPv4 Internet check:" >> ${DEBUG_LOG}
else else
echo "IPv4 Internet check failed:" >> ${DEBUG_LOG} echo "IPv4 Internet check failed:" >> ${DEBUG_LOG}
fi fi
echo "$INET_CHECK" >> ${DEBUG_LOG} echo "${INET_CHECK}" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
fi fi
GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3) GATEWAY6=$(ip -6 r | grep default | cut -d ' ' -f 3)
if [[ $? = 0 ]] if [[ $? = 0 ]]; then
then
echo "::: Pinging default IPv6 gateway..." echo "::: Pinging default IPv6 gateway..."
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3) GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n "${GATEWAY6}" | tail -n3)
if [[ $? = 0 ]] if [[ $? = 0 ]]; then
then
echo "IPv6 Gateway check:" >> ${DEBUG_LOG} echo "IPv6 Gateway check:" >> ${DEBUG_LOG}
else else
echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG} echo "IPv6 Gateway check failed:" >> ${DEBUG_LOG}
@ -152,8 +147,7 @@ ip_check() {
echo "::: Pinging Internet via IPv6..." echo "::: Pinging Internet via IPv6..."
GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3) GATEWAY6_CHECK=$(ping6 -q -w 3 -c 3 -n 2001:4860:4860::8888 | tail -n3)
if [[ $? = 0 ]] if [[ $? = 0 ]]; then
then
echo "IPv6 Internet check:" >> ${DEBUG_LOG} echo "IPv6 Internet check:" >> ${DEBUG_LOG}
else else
echo "IPv6 Internet check failed:" >> ${DEBUG_LOG} echo "IPv6 Internet check failed:" >> ${DEBUG_LOG}
@ -162,7 +156,7 @@ ip_check() {
else else
GATEWAY_CHECK="No IPv6 Gateway Detected" GATEWAY_CHECK="No IPv6 Gateway Detected"
fi fi
echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} echo "${GATEWAY_CHECK}" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
@ -180,9 +174,8 @@ hostnameCheck() {
echo "::: Writing hosts file to debug log..." echo "::: Writing hosts file to debug log..."
echo "### Hosts ###" >> ${DEBUG_LOG} echo "### Hosts ###" >> ${DEBUG_LOG}
if [ -e "$HOSTSFILE" ] if [ -e "${HOSTSFILE}" ]; then
then cat "${HOSTSFILE}" >> ${DEBUG_LOG}
cat "$HOSTSFILE" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
else else
echo "No hosts file found!" >> ${DEBUG_LOG} echo "No hosts file found!" >> ${DEBUG_LOG}
@ -210,39 +203,37 @@ testResolver() {
# 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
echo "Resolution of $TESTURL from Pi-hole:" >> ${DEBUG_LOG} echo "Resolution of ${TESTURL} from Pi-hole:" >> ${DEBUG_LOG}
LOCALDIG=$(dig "$TESTURL" @127.0.0.1) LOCALDIG=$(dig "${TESTURL}" @127.0.0.1)
if [[ $? = 0 ]] if [[ $? = 0 ]]; then
then echo "${LOCALDIG}" >> ${DEBUG_LOG}
echo "$LOCALDIG" >> ${DEBUG_LOG}
else else
echo "Failed to resolve $TESTURL on Pi-hole" >> ${DEBUG_LOG} echo "Failed to resolve ${TESTURL} on Pi-hole" >> ${DEBUG_LOG}
fi fi
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
echo "Resolution of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG} echo "Resolution of ${TESTURL} from 8.8.8.8:" >> ${DEBUG_LOG}
REMOTEDIG=$(dig "$TESTURL" @8.8.8.8) REMOTEDIG=$(dig "${TESTURL}" @8.8.8.8)
if [[ $? = 0 ]] if [[ $? = 0 ]]; then
then echo "${REMOTEDIG}" >> ${DEBUG_LOG}
echo "$REMOTEDIG" >> ${DEBUG_LOG}
else 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 fi
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
@ -271,12 +262,11 @@ checkProcesses() {
echo ":::" echo ":::"
echo "::: Logging status of lighttpd and dnsmasq..." echo "::: Logging status of lighttpd and dnsmasq..."
PROCESSES=( lighttpd dnsmasq ) PROCESSES=( lighttpd dnsmasq )
for i in "${PROCESSES[@]}" for i in "${PROCESSES[@]}"; do
do
echo "" >> ${DEBUG_LOG} echo "" >> ${DEBUG_LOG}
echo -n "$i" >> "$DEBUG_LOG" echo -n "${i}" >> "${DEBUG_LOG}"
echo " processes status:" >> ${DEBUG_LOG} echo " processes status:" >> ${DEBUG_LOG}
${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG" ${SUDO} systemctl -l status "${i}" >> "${DEBUG_LOG}"
done done
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
} }
@ -286,26 +276,24 @@ debugLighttpd() {
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
echo "############ lighttpd.conf ############" >> ${DEBUG_LOG} echo "############ lighttpd.conf ############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$LIGHTTPDFILE" ] if [ -e "${LIGHTTPDFILE}" ]; then
then
while read -r line; do while read -r line; do
if [ ! -z "$line" ]; then if [ ! -z "${line}" ]; then
[[ "$line" =~ ^#.*$ ]] && continue [[ "${line}" =~ ^#.*$ ]] && continue
echo "$line" >> ${DEBUG_LOG} echo "${line}" >> ${DEBUG_LOG}
fi fi
done < "$LIGHTTPDFILE" done < "${LIGHTTPDFILE}"
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
else else
echo "No lighttpd.conf file found!" >> ${DEBUG_LOG} echo "No lighttpd.conf file found!" >> ${DEBUG_LOG}
printf ":::\tNo lighttpd.conf file found\n" printf ":::\tNo lighttpd.conf file found\n"
fi fi
if [ -e "$LIGHTTPDERRFILE" ] if [ -e "${LIGHTTPDERRFILE}" ]; then
then
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG} echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
cat "$LIGHTTPDERRFILE" >> ${DEBUG_LOG} cat "${LIGHTTPDERRFILE}" >> ${DEBUG_LOG}
else else
echo "No lighttpd error.log file found!" >> ${DEBUG_LOG} echo "No lighttpd error.log file found!" >> ${DEBUG_LOG}
printf ":::\tNo lighttpd error.log file found\n" printf ":::\tNo lighttpd error.log file found\n"
@ -328,15 +316,14 @@ echo "::: Writing dnsmasq.conf to debug log..."
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
echo "############### Dnsmasq ###############" >> ${DEBUG_LOG} echo "############### Dnsmasq ###############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$DNSMASQFILE" ] if [ -e "${DNSMASQFILE}" ]; then
then
#cat $DNSMASQFILE >> $DEBUG_LOG #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
echo "$line" >> ${DEBUG_LOG} echo "${line}" >> ${DEBUG_LOG}
fi fi
done < "$DNSMASQFILE" done < "${DNSMASQFILE}"
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
else else
echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG} echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG}
@ -347,14 +334,13 @@ echo "::: Writing 01-pihole.conf to debug log..."
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG} echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$PIHOLECONFFILE" ] if [ -e "${PIHOLECONFFILE}" ]; then
then
while read -r line; do while read -r line; do
if [ ! -z "$line" ]; then if [ ! -z "${line}" ]; then
[[ "$line" =~ ^#.*$ ]] && continue [[ "${line}" =~ ^#.*$ ]] && continue
echo "$line" >> ${DEBUG_LOG} echo "${line}" >> ${DEBUG_LOG}
fi fi
done < "$PIHOLECONFFILE" done < "${PIHOLECONFFILE}"
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
else else
echo "No 01-pihole.conf file found!" >> ${DEBUG_LOG} 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 "#######################################" >> ${DEBUG_LOG}
echo "############ gravity.list #############" >> ${DEBUG_LOG} echo "############ gravity.list #############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$GRAVITYFILE" ] if [ -e "${GRAVITYFILE}" ]; then
then wc -l "${GRAVITYFILE}" >> ${DEBUG_LOG}
wc -l "$GRAVITYFILE" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
else else
echo "No gravity.list file found!" >> ${DEBUG_LOG} echo "No gravity.list file found!" >> ${DEBUG_LOG}
@ -380,9 +365,8 @@ echo "::: Writing whitelist to debug log..."
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
echo "############## Whitelist ##############" >> ${DEBUG_LOG} echo "############## Whitelist ##############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$WHITELISTFILE" ] if [ -e "${WHITELISTFILE}" ]; then
then cat "${WHITELISTFILE}" >> ${DEBUG_LOG}
cat "$WHITELISTFILE" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
else else
echo "No whitelist.txt file found!" >> ${DEBUG_LOG} echo "No whitelist.txt file found!" >> ${DEBUG_LOG}
@ -393,9 +377,8 @@ echo "::: Writing blacklist to debug log..."
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
echo "############## Blacklist ##############" >> ${DEBUG_LOG} echo "############## Blacklist ##############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$BLACKLISTFILE" ] if [ -e "${BLACKLISTFILE}" ]; then
then cat "${BLACKLISTFILE}" >> ${DEBUG_LOG}
cat "$BLACKLISTFILE" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
else else
echo "No blacklist.txt file found!" >> ${DEBUG_LOG} echo "No blacklist.txt file found!" >> ${DEBUG_LOG}
@ -406,14 +389,13 @@ echo "::: Writing adlists.list to debug log..."
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
echo "############ adlists.list #############" >> ${DEBUG_LOG} echo "############ adlists.list #############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$ADLISTSFILE" ] if [ -e "${ADLISTSFILE}" ]; then
then
while read -r line; do while read -r line; do
if [ ! -z "$line" ]; then if [ ! -z "${line}" ]; then
[[ "$line" =~ ^#.*$ ]] && continue [[ "${line}" =~ ^#.*$ ]] && continue
echo "$line" >> ${DEBUG_LOG} echo "${line}" >> ${DEBUG_LOG}
fi fi
done < "$ADLISTSFILE" done < "${ADLISTSFILE}"
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
else else
echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG} echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG}
@ -428,10 +410,9 @@ dumpPiHoleLog() {
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
echo "############# pihole.log ##############" >> ${DEBUG_LOG} echo "############# pihole.log ##############" >> ${DEBUG_LOG}
echo "#######################################" >> ${DEBUG_LOG} echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$PIHOLELOG" ] if [ -e "${PIHOLELOG}" ]; then
then
while true; do while true; do
tail -f "$PIHOLELOG" >> ${DEBUG_LOG} tail -f "${PIHOLELOG}" >> ${DEBUG_LOG}
echo >> ${DEBUG_LOG} echo >> ${DEBUG_LOG}
done done
else else
@ -455,9 +436,8 @@ finalWork() {
esac esac
# Check if termbin.com is reachable. When it's not, point to local log instead # Check if termbin.com is reachable. When it's not, point to local log instead
if [ -n "$TERMBIN" ] if [ -n "${TERMBIN}" ]; then
then echo "::: Debug log can be found at : ${TERMBIN}"
echo "::: Debug log can be found at : $TERMBIN"
else else
echo "::: Debug log can be found at : /var/log/pihole_debug.log" echo "::: Debug log can be found at : /var/log/pihole_debug.log"
fi fi

@ -18,12 +18,12 @@ 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"
@ -59,7 +59,7 @@ make_repo() {
} }
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 $!
@ -117,7 +117,6 @@ elif [[ ${piholeVersion} == ${piholeVersionLatest} && ${webVersion} != ${webVers
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}
@ -127,7 +126,6 @@ elif [[ ${piholeVersion} != ${piholeVersionLatest} && ${webVersion} == ${webVers
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}

@ -21,14 +21,13 @@ normalOutput() {
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 "$@" for var in "$@"; do
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;
@ -49,9 +48,8 @@ webOutput() {
} }
coreOutput() { coreOutput() {
for var in "$@" for var in "$@"; do
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;
@ -93,9 +91,8 @@ if [[ $# = 0 ]]; then
normalOutput normalOutput
fi fi
for var in "$@" for var in "$@"; do
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;;

@ -46,7 +46,7 @@ domToRemoveList=()
HandleOther(){ HandleOther(){
#check validity of domain #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/') 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" echo "::: $1 is not a valid argument or domain name"
else else
domList=("${domList[@]}" ${validDomain}) domList=("${domList[@]}" ${validDomain})
@ -55,21 +55,20 @@ HandleOther(){
PopWhitelistFile() { PopWhitelistFile() {
#check whitelist file exists, and if not, create it #check whitelist file exists, and if not, create it
if [[ ! -f ${whitelist} ]];then if [[ ! -f ${whitelist} ]]; then
touch ${whitelist} touch ${whitelist}
fi fi
for dom in "${domList[@]}" for dom in "${domList[@]}"; do
do
if ${addmode}; then if ${addmode}; then
AddDomain "$dom" AddDomain "${dom}"
else else
RemoveDomain "$dom" RemoveDomain "${dom}"
fi fi
done done
} }
AddDomain() { AddDomain() {
#| sed 's/\./\\./g' #| sed 's/\./\\./g'
bool=false bool=false
grep -Ex -q "$1" ${whitelist} || bool=true grep -Ex -q "$1" ${whitelist} || bool=true
@ -84,7 +83,7 @@ AddDomain() {
fi fi
else else
if ${verbose}; then 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
fi fi
} }
@ -112,24 +111,23 @@ DisplayWlist() {
verbose=false verbose=false
echo -e " Displaying Gravity Resistant Domains \n" echo -e " Displaying Gravity Resistant Domains \n"
count=1 count=1
while IFS= read -r RD while IFS= read -r RD; do
do echo "${count}: ${RD}"
echo "${count}: $RD"
count=$((count+1)) count=$((count+1))
done < "$whitelist" done < "${whitelist}"
} }
################################################### ###################################################
for var in "$@" for var in "$@"; do
do case "${var}" in
case "$var" in
"-nr"| "--noreload" ) reload=false;; "-nr"| "--noreload" ) reload=false;;
"-d" | "--delmode" ) addmode=false;; "-d" | "--delmode" ) addmode=false;;
"-f" | "--force" ) force=true;;
"-q" | "--quiet" ) verbose=false;; "-q" | "--quiet" ) verbose=false;;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;
"-l" | "--list" ) DisplayWlist;; "-l" | "--list" ) DisplayWlist;;
* ) HandleOther "$var";; * ) HandleOther "${var}";;
esac esac
done done
@ -138,6 +136,3 @@ PopWhitelistFile
if ${reload}; then if ${reload}; then
Reload Reload
fi fi

@ -1,5 +1,4 @@
_pihole() _pihole() {
{
local cur prev opts local cur prev opts
COMPREPLY=() COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"

@ -8,6 +8,11 @@
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or # the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version. # (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 # Pi-hole: Update the ad sources once a week on Sunday at 01:59
# Download any updates from the adlists # Download any updates from the adlists

@ -48,7 +48,7 @@ runUnattended=false
######## FIRST CHECK ######## ######## FIRST CHECK ########
# Must be root to install # Must be root to install
echo ":::" echo ":::"
if [[ $EUID -eq 0 ]];then if [[ ${EUID} -eq 0 ]]; then
echo "::: You are root." echo "::: You are root."
else else
echo "::: Script called with non-root privileges. The Pi-hole installs server packages and configures" echo "::: Script called with non-root privileges. The Pi-hole installs server packages and configures"
@ -56,7 +56,8 @@ else
echo "::: any concerns with this requirement. Please be sure to download this script from a trusted source." echo "::: any concerns with this requirement. Please be sure to download this script from a trusted source."
echo ":::" echo ":::"
echo "::: Detecting the presence of the sudo utility for continuation of this install..." echo "::: Detecting the presence of the sudo utility for continuation of this install..."
if [ -x "$(command -v sudo)" ];then
if [ -x "$(command -v sudo)" ]; then
echo "::: Utility sudo located." echo "::: Utility sudo located."
exec curl -sSL https://install.pi-hole.net | sudo bash "$@" exec curl -sSL https://install.pi-hole.net | sudo bash "$@"
exit $? exit $?
@ -68,7 +69,7 @@ fi
# Compatibility # Compatibility
if [ -x "$(command -v apt-get)" ];then if [ -x "$(command -v apt-get)" ]; then
#Debian Family #Debian Family
#Decide if php should be `php5` or just `php` (Fixes issues with Ubuntu 16.04 LTS) #Decide if php should be `php5` or just `php` (Fixes issues with Ubuntu 16.04 LTS)
phpVer="php5" phpVer="php5"
@ -76,11 +77,11 @@ if [ -x "$(command -v apt-get)" ];then
############################################# #############################################
PKG_MANAGER="apt-get" PKG_MANAGER="apt-get"
PKG_CACHE="/var/lib/apt/lists/" PKG_CACHE="/var/lib/apt/lists/"
UPDATE_PKG_CACHE="$PKG_MANAGER update" UPDATE_PKG_CACHE="${PKG_MANAGER} update"
PKG_UPDATE="$PKG_MANAGER upgrade" PKG_UPDATE="${PKG_MANAGER} upgrade"
PKG_INSTALL="$PKG_MANAGER --yes --fix-missing install" PKG_INSTALL="${PKG_MANAGER} --yes --fix-missing install"
# grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE # grep -c will return 1 retVal on 0 matches, block this throwing the set -e with an OR TRUE
PKG_COUNT="$PKG_MANAGER -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true"
INSTALLER_DEPS=( apt-utils whiptail git dhcpcd5) INSTALLER_DEPS=( apt-utils whiptail git dhcpcd5)
PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi curl unzip wget sudo netcat cron iproute2 ) PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd ${phpVer}-common ${phpVer}-cgi curl unzip wget sudo netcat cron iproute2 )
LIGHTTPD_USER="www-data" LIGHTTPD_USER="www-data"
@ -88,20 +89,20 @@ if [ -x "$(command -v apt-get)" ];then
LIGHTTPD_CFG="lighttpd.conf.debian" LIGHTTPD_CFG="lighttpd.conf.debian"
DNSMASQ_USER="dnsmasq" DNSMASQ_USER="dnsmasq"
package_check_install() { package_check_install() {
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "$1" dpkg-query -W -f='${Status}' "${1}" 2>/dev/null | grep -c "ok installed" || ${PKG_INSTALL} "${1}"
} }
elif [ -x "$(command -v rpm)" ];then elif [ -x "$(command -v rpm)" ]; then
# Fedora Family # Fedora Family
if [ -x "$(command -v dnf)" ];then if [ -x "$(command -v dnf)" ]; then
PKG_MANAGER="dnf" PKG_MANAGER="dnf"
else else
PKG_MANAGER="yum" PKG_MANAGER="yum"
fi fi
PKG_CACHE="/var/cache/$PKG_MANAGER" PKG_CACHE="/var/cache/${PKG_MANAGER}"
UPDATE_PKG_CACHE="$PKG_MANAGER check-update" UPDATE_PKG_CACHE="${PKG_MANAGER} check-update"
PKG_UPDATE="$PKG_MANAGER update -y" PKG_UPDATE="${PKG_MANAGER} update -y"
PKG_INSTALL="$PKG_MANAGER install -y" PKG_INSTALL="${PKG_MANAGER} install -y"
PKG_COUNT="$PKG_MANAGER check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l"
INSTALLER_DEPS=( iproute net-tools procps-ng newt git ) INSTALLER_DEPS=( iproute net-tools procps-ng newt git )
PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php curl unzip wget findutils cronie sudo nmap-ncat ) PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php curl unzip wget findutils cronie sudo nmap-ncat )
if grep -q 'Fedora' /etc/redhat-release; then if grep -q 'Fedora' /etc/redhat-release; then
@ -113,7 +114,7 @@ elif [ -x "$(command -v rpm)" ];then
LIGHTTPD_CFG="lighttpd.conf.fedora" LIGHTTPD_CFG="lighttpd.conf.fedora"
DNSMASQ_USER="nobody" DNSMASQ_USER="nobody"
package_check_install() { package_check_install() {
rpm -qa | grep ^"$1"- > /dev/null || ${PKG_INSTALL} "$1" rpm -qa | grep ^"${1}"- > /dev/null || ${PKG_INSTALL} "${1}"
} }
else else
echo "OS distribution not supported" echo "OS distribution not supported"
@ -125,9 +126,9 @@ 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"
@ -170,7 +171,7 @@ verifyFreeDiskSpace() {
local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}')
# - Unknown free disk space , not a integer # - Unknown free disk space , not a integer
if ! [[ "$existing_free_kilobytes" =~ ^([0-9])+$ ]]; then if ! [[ "${existing_free_kilobytes}" =~ ^([0-9])+$ ]]; then
echo "::: Unknown free disk space!" echo "::: Unknown free disk space!"
echo "::: We were unable to determine available free disk space on this system." echo "::: We were unable to determine available free disk space on this system."
echo "::: You may override this check and force the installation, however, it is not recommended" echo "::: You may override this check and force the installation, however, it is not recommended"
@ -181,7 +182,7 @@ verifyFreeDiskSpace() {
elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then elif [[ ${existing_free_kilobytes} -lt ${required_free_kilobytes} ]]; then
echo "::: Insufficient Disk Space!" echo "::: Insufficient Disk Space!"
echo "::: Your system appears to be low on disk space. pi-hole recommends a minimum of $required_free_kilobytes KiloBytes." echo "::: Your system appears to be low on disk space. pi-hole recommends a minimum of $required_free_kilobytes KiloBytes."
echo "::: You only have $existing_free_kilobytes KiloBytes free." echo "::: You only have ${existing_free_kilobytes} KiloBytes free."
echo "::: If this is a new install you may need to expand your disk." echo "::: If this is a new install you may need to expand your disk."
echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'" echo "::: Try running 'sudo raspi-config', and choose the 'expand file system option'"
echo "::: After rebooting, run this installation again. (curl -L https://install.pi-hole.net | bash)" echo "::: After rebooting, run this installation again. (curl -L https://install.pi-hole.net | bash)"
@ -206,23 +207,21 @@ chooseInterface() {
# Loop sentinel variable # Loop sentinel variable
local firstLoop=1 local firstLoop=1
while read -r line while read -r line; do
do
mode="OFF" mode="OFF"
if [[ ${firstLoop} -eq 1 ]]; then if [[ ${firstLoop} -eq 1 ]]; then
firstLoop=0 firstLoop=0
mode="ON" mode="ON"
fi fi
interfacesArray+=("$line" "available" "$mode") interfacesArray+=("${line}" "available" "${mode}")
done <<< "$availableInterfaces" done <<< "${availableInterfaces}"
# Find out how many interfaces are available to choose from # Find out how many interfaces are available to choose from
interfaceCount=$(echo "$availableInterfaces" | wc -l) interfaceCount=$(echo "${availableInterfaces}" | wc -l)
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount}) chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface (press space to select)" ${r} ${c} ${interfaceCount})
chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty)
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
for desiredInterface in ${chooseInterfaceOptions} for desiredInterface in ${chooseInterfaceOptions}; do
do
piholeInterface=${desiredInterface} piholeInterface=${desiredInterface}
echo "::: Using interface: $piholeInterface" echo "::: Using interface: $piholeInterface"
done done
@ -279,8 +278,8 @@ use4andor6() {
getStaticIPv4Settings() { getStaticIPv4Settings() {
# Ask if the user wants to use DHCP settings as their static IP # Ask if the user wants to use DHCP settings as their static IP
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address? if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
IP address: $IPv4_address IP address: ${IPv4_address}
Gateway: $IPv4gw" ${r} ${c}); then Gateway: ${IPv4gw}" ${r} ${c}); then
# If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict. # If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict.
whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that. whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that.
If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.
@ -290,20 +289,19 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
# Otherwise, we need to ask the user to input their desired settings. # Otherwise, we need to ask the user to input their desired settings.
# Start by getting the IPv4 address (pre-filling it with info gathered from DHCP) # Start by getting the IPv4 address (pre-filling it with info gathered from DHCP)
# Start a loop to let the user enter their information with the chance to go back and edit it if necessary # Start a loop to let the user enter their information with the chance to go back and edit it if necessary
until [[ ${ipSettingsCorrect} = True ]] until [[ ${ipSettingsCorrect} = True ]]; do
do
# Ask for the IPv4 address # Ask for the IPv4 address
IPv4_address=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "$IPv4_address" 3>&1 1>&2 2>&3) IPv4_address=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" ${r} ${c} "${IPv4_address}" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]];then if [[ $? = 0 ]]; then
echo "::: Your static IPv4 address: $IPv4_address" echo "::: Your static IPv4 address: ${IPv4_address}"
# Ask for the gateway # Ask for the gateway
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "$IPv4gw" 3>&1 1>&2 2>&3) IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" ${r} ${c} "${IPv4gw}" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]];then if [[ $? = 0 ]]; then
echo "::: Your static IPv4 gateway: $IPv4gw" echo "::: Your static IPv4 gateway: ${IPv4gw}"
# Give the user a chance to review their settings before moving on # Give the user a chance to review their settings before moving on
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct? if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
IP address: $IPv4_address IP address: ${IPv4_address}
Gateway: $IPv4gw" ${r} ${c}); then Gateway: ${IPv4gw}" ${r} ${c}); then
# After that's done, the loop ends and we move on # After that's done, the loop ends and we move on
ipSettingsCorrect=True ipSettingsCorrect=True
else else
@ -329,31 +327,31 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
setDHCPCD() { setDHCPCD() {
# Append these lines to dhcpcd.conf to enable a static IP # Append these lines to dhcpcd.conf to enable a static IP
echo "## interface $piholeInterface echo "## interface ${piholeInterface}
static ip_address=$IPv4_address static ip_address=${IPv4_address}
static routers=$IPv4gw static routers=${IPv4gw}
static domain_name_servers=$IPv4gw" | tee -a /etc/dhcpcd.conf >/dev/null static domain_name_servers=${IPv4gw}" | tee -a /etc/dhcpcd.conf >/dev/null
} }
setStaticIPv4() { setStaticIPv4() {
local IFCFG_FILE local IFCFG_FILE
local IPADDR local IPADDR
local CIDR local CIDR
if [[ -f /etc/dhcpcd.conf ]];then if [[ -f /etc/dhcpcd.conf ]]; then
# Debian Family # Debian Family
if grep -q "$IPv4_address" /etc/dhcpcd.conf; then if grep -q "${IPv4_address}" /etc/dhcpcd.conf; then
echo "::: Static IP already configured" echo "::: Static IP already configured"
else else
setDHCPCD setDHCPCD
ip addr replace dev "$piholeInterface" "$IPv4_address" ip addr replace dev "${piholeInterface}" "${IPv4_address}"
echo ":::" echo ":::"
echo "::: Setting IP to $IPv4_address. You may need to restart after the install is complete." echo "::: Setting IP to ${IPv4_address}. You may need to restart after the install is complete."
echo ":::" echo ":::"
fi fi
elif [[ -f /etc/sysconfig/network-scripts/ifcfg-${piholeInterface} ]];then elif [[ -f /etc/sysconfig/network-scripts/ifcfg-${piholeInterface} ]];then
# Fedora Family # Fedora Family
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${piholeInterface} IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${piholeInterface}
if grep -q "$IPv4_address" "${IFCFG_FILE}"; then if grep -q "${IPv4_address}" "${IFCFG_FILE}"; then
echo "::: Static IP already configured" echo "::: Static IP already configured"
else else
IPADDR=$(echo "${IPv4_address}" | cut -f1 -d/) IPADDR=$(echo "${IPv4_address}" | cut -f1 -d/)
@ -373,7 +371,7 @@ setStaticIPv4() {
echo "DNS2=$piholeDNS2" echo "DNS2=$piholeDNS2"
echo "USERCTL=no" echo "USERCTL=no"
}>> "${IFCFG_FILE}" }>> "${IFCFG_FILE}"
ip addr replace dev "$piholeInterface" "$IPv4_address" ip addr replace dev "${piholeInterface}" "${IPv4_address}"
if [ -x "$(command -v nmcli)" ];then if [ -x "$(command -v nmcli)" ];then
# Tell NetworkManager to read our new sysconfig file # Tell NetworkManager to read our new sysconfig file
nmcli con load "${IFCFG_FILE}" > /dev/null nmcli con load "${IFCFG_FILE}" > /dev/null
@ -389,7 +387,7 @@ setStaticIPv4() {
} }
valid_ip() { valid_ip() {
local ip=$1 local ip=${1}
local stat=1 local stat=1
if [[ ${ip} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then if [[ ${ip} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
@ -441,45 +439,45 @@ setDNS() {
piholeDNS2="8.20.247.20" piholeDNS2="8.20.247.20"
;; ;;
Custom) Custom)
until [[ ${DNSSettingsCorrect} = True ]] until [[ ${DNSSettingsCorrect} = True ]]; do
do
strInvalid="Invalid" strInvalid="Invalid"
if [ ! ${piholeDNS1} ]; then if [ ! ${piholeDNS1} ]; then
if [ ! ${piholeDNS2} ]; then if [ ! ${piholeDNS2} ]; then
prePopulate="" prePopulate=""
else else
prePopulate=", $piholeDNS2" prePopulate=", ${piholeDNS2}"
fi fi
elif [ ${piholeDNS1} ] && [ ! ${piholeDNS2} ]; then elif [ ${piholeDNS1} ] && [ ! ${piholeDNS2} ]; then
prePopulate="$piholeDNS1" prePopulate="${piholeDNS1}"
elif [ ${piholeDNS1} ] && [ ${piholeDNS2} ]; then elif [ ${piholeDNS1} ] && [ ${piholeDNS2} ]; then
prePopulate="$piholeDNS1, $piholeDNS2" prePopulate="${piholeDNS1}, ${piholeDNS2}"
fi fi
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "$prePopulate" 3>&1 1>&2 2>&3)
if [[ $? = 0 ]];then piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'" ${r} ${c} "${prePopulate}" 3>&1 1>&2 2>&3)
piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') if [[ $? = 0 ]]; then
if ! valid_ip "$piholeDNS1" || [ ! "$piholeDNS1" ]; then piholeDNS1=$(echo "${piholeDNS}" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
piholeDNS2=$(echo "${piholeDNS}" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
if ! valid_ip "${piholeDNS1}" || [ ! "${piholeDNS1}" ]; then
piholeDNS1=${strInvalid} piholeDNS1=${strInvalid}
fi fi
if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then if ! valid_ip "${piholeDNS2}" && [ "${piholeDNS2}" ]; then
piholeDNS2=${strInvalid} piholeDNS2=${strInvalid}
fi fi
else else
echo "::: Cancel selected, exiting...." echo "::: Cancel selected, exiting...."
exit 1 exit 1
fi fi
if [[ ${piholeDNS1} == "$strInvalid" ]] || [[ ${piholeDNS2} == "$strInvalid" ]]; then if [[ ${piholeDNS1} == "${strInvalid}" ]] || [[ ${piholeDNS2} == "${strInvalid}" ]]; then
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" ${r} ${c} whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP" "One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: ${piholeDNS2}" ${r} ${c} if [[ ${piholeDNS1} == "${strInvalid}" ]]; then
if [[ ${piholeDNS1} == "$strInvalid" ]]; then
piholeDNS1="" piholeDNS1=""
fi fi
if [[ ${piholeDNS2} == "$strInvalid" ]]; then if [[ ${piholeDNS2} == "${strInvalid}" ]]; then
piholeDNS2="" piholeDNS2=""
fi fi
DNSSettingsCorrect=False DNSSettingsCorrect=False
else else
if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" ${r} ${c}); then if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: ${piholeDNS2}" ${r} ${c}); then
DNSSettingsCorrect=True DNSSettingsCorrect=True
else else
# If the settings are wrong, the loop continues # If the settings are wrong, the loop continues
@ -527,12 +525,12 @@ version_check_dnsmasq() {
cp ${dnsmasq_pihole_01_snippet} ${dnsmasq_pihole_01_location} cp ${dnsmasq_pihole_01_snippet} ${dnsmasq_pihole_01_location}
echo " done." echo " done."
sed -i "s/@INT@/$piholeInterface/" ${dnsmasq_pihole_01_location} sed -i "s/@INT@/$piholeInterface/" ${dnsmasq_pihole_01_location}
if [[ "$piholeDNS1" != "" ]]; then if [[ "${piholeDNS1}" != "" ]]; then
sed -i "s/@DNS1@/$piholeDNS1/" ${dnsmasq_pihole_01_location} sed -i "s/@DNS1@/$piholeDNS1/" ${dnsmasq_pihole_01_location}
else else
sed -i '/^server=@DNS1@/d' ${dnsmasq_pihole_01_location} sed -i '/^server=@DNS1@/d' ${dnsmasq_pihole_01_location}
fi fi
if [[ "$piholeDNS2" != "" ]]; then if [[ "${piholeDNS2}" != "" ]]; then
sed -i "s/@DNS2@/$piholeDNS2/" ${dnsmasq_pihole_01_location} sed -i "s/@DNS2@/$piholeDNS2/" ${dnsmasq_pihole_01_location}
else else
sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location} sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location}
@ -573,7 +571,7 @@ installConfigs() {
version_check_dnsmasq version_check_dnsmasq
if [ ! -d "/etc/lighttpd" ]; then if [ ! -d "/etc/lighttpd" ]; then
mkdir /etc/lighttpd mkdir /etc/lighttpd
chown "$USER":root /etc/lighttpd chown "${USER}":root /etc/lighttpd
mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
fi fi
cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf
@ -628,13 +626,13 @@ update_pacakge_cache() {
#Check to see if apt-get update has already been run today #Check to see if apt-get update has already been run today
#it needs to have been run at least once on new installs! #it needs to have been run at least once on new installs!
timestamp=$(stat -c %Y ${PKG_CACHE}) timestamp=$(stat -c %Y ${PKG_CACHE})
timestampAsDate=$(date -d @"$timestamp" "+%b %e") timestampAsDate=$(date -d @"${timestamp}" "+%b %e")
today=$(date "+%b %e") today=$(date "+%b %e")
if [ ! "$today" == "$timestampAsDate" ]; then if [ ! "${today}" == "${timestampAsDate}" ]; then
#update package lists #update package lists
echo ":::" echo ":::"
echo -n "::: $PKG_MANAGER update has not been run today. Running now..." echo -n "::: ${PKG_MANAGER} update has not been run today. Running now..."
${UPDATE_PKG_CACHE} &> /dev/null & spinner $! ${UPDATE_PKG_CACHE} &> /dev/null & spinner $!
echo " done!" echo " done!"
fi fi
@ -644,15 +642,15 @@ notify_package_updates_available() {
# Let user know if they have outdated packages on their system and # Let user know if they have outdated packages on their system and
# advise them to run a package update at soonest possible. # advise them to run a package update at soonest possible.
echo ":::" echo ":::"
echo -n "::: Checking $PKG_MANAGER for upgraded packages...." echo -n "::: Checking ${PKG_MANAGER} for upgraded packages...."
updatesToInstall=$(eval "${PKG_COUNT}") updatesToInstall=$(eval "${PKG_COUNT}")
echo " done!" echo " done!"
echo ":::" echo ":::"
if [[ ${updatesToInstall} -eq "0" ]]; then if [[ ${updatesToInstall} -eq "0" ]]; then
echo "::: Your system is up to date! Continuing with Pi-hole installation..." echo "::: Your system is up to date! Continuing with Pi-hole installation..."
else else
echo "::: There are $updatesToInstall updates available for your system!" echo "::: There are ${updatesToInstall} updates available for your system!"
echo "::: We recommend you run '$PKG_UPDATE' after installing Pi-Hole! " echo "::: We recommend you run '${PKG_UPDATE}' after installing Pi-Hole! "
echo ":::" echo ":::"
fi fi
} }
@ -786,7 +784,7 @@ configureFirewall() {
finalExports() { finalExports() {
#If it already exists, lets overwrite it with the new values. #If it already exists, lets overwrite it with the new values.
if [[ -f ${setupVars} ]];then if [[ -f ${setupVars} ]]; then
rm ${setupVars} rm ${setupVars}
fi fi
{ {
@ -798,7 +796,6 @@ finalExports() {
}>> "${setupVars}" }>> "${setupVars}"
} }
installPihole() { installPihole() {
# Install base files and web interface # Install base files and web interface
create_pihole_user create_pihole_user
@ -866,7 +863,7 @@ displayFinalMessage() {
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using: whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using:
IPv4: ${IPv4_address%/*} IPv4: ${IPv4_address%/*}
IPv6: $IPv6_address IPv6: ${IPv6_address}
If you set a new IP address, you should restart the Pi. If you set a new IP address, you should restart the Pi.
@ -876,7 +873,7 @@ View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admi
update_dialogs() { update_dialogs() {
# reconfigure # reconfigure
if [ "$reconfigure" = true ]; then if [ "${reconfigure}" = true ]; then
opt1a="Repair" opt1a="Repair"
opt1b="This will retain existing settings" opt1b="This will retain existing settings"
strAdd="You will remain on the same version" strAdd="You will remain on the same version"
@ -889,17 +886,17 @@ update_dialogs() {
opt2b="This will allow you to enter new settings" opt2b="This will allow you to enter new settings"
UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \ UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options: \n($strAdd)" ${r} ${c} 2 \
"$opt1a" "$opt1b" \ "${opt1a}" "${opt1b}" \
"$opt2a" "$opt2b" 3>&2 2>&1 1>&3) "${opt2a}" "${opt2b}" 3>&2 2>&1 1>&3)
if [[ $? = 0 ]];then if [[ $? = 0 ]];then
case ${UpdateCmd} in case ${UpdateCmd} in
${opt1a}) ${opt1a})
echo "::: $opt1a option selected." echo "::: ${opt1a} option selected."
useUpdateVars=true useUpdateVars=true
;; ;;
${opt2a}) ${opt2a})
echo "::: $opt2a option selected" echo "::: ${opt2a} option selected"
useUpdateVars=false useUpdateVars=false
;; ;;
esac esac
@ -912,53 +909,52 @@ update_dialogs() {
main() { main() {
# Check arguments for the undocumented flags # Check arguments for the undocumented flags
for var in "$@" for var in "$@"; do
do
case "$var" in case "$var" in
"--reconfigure" ) reconfigure=true;; "--reconfigure" ) reconfigure=true;;
"--i_do_not_follow_recommendations" ) skipSpaceCheck=false;; "--i_do_not_follow_recommendations" ) skipSpaceCheck=false;;
"--unattended" ) runUnattended=true;; "--unattended" ) runUnattended=true;;
esac esac
done done
if [[ -f ${setupVars} ]];then if [[ -f ${setupVars} ]]; then
if [[ "${runUnattended}" == true ]]; then if [[ "${runUnattended}" == true ]]; then
echo "::: --unattended passed to install script, no whiptail dialogs will be displayed" echo "::: --unattended passed to install script, no whiptail dialogs will be displayed"
useUpdateVars=true useUpdateVars=true
else else
update_dialogs update_dialogs
fi fi
fi fi
# Start the installer # Start the installer
# Verify there is enough disk space for the install # Verify there is enough disk space for the install
if [[ "${skipSpaceCheck}" == true ]]; then if [[ "${skipSpaceCheck}" == true ]]; then
echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!" echo "::: --i_do_not_follow_recommendations passed to script, skipping free disk space verification!"
else else
verifyFreeDiskSpace verifyFreeDiskSpace
fi fi
# Update package cache # Update package cache
update_pacakge_cache update_pacakge_cache
# Notify user of package availability # Notify user of package availability
notify_package_updates_available notify_package_updates_available
# Install packages used by this installation script # Install packages used by this installation script
install_dependent_packages INSTALLER_DEPS[@] install_dependent_packages INSTALLER_DEPS[@]
# Install packages used by the Pi-hole # Install packages used by the Pi-hole
install_dependent_packages PIHOLE_DEPS[@] install_dependent_packages PIHOLE_DEPS[@]
if [[ "${reconfigure}" == true ]]; then if [[ "${reconfigure}" == true ]]; then
echo "::: --reconfigure passed to install script. Not downloading/updating local repos" echo "::: --reconfigure passed to install script. Not downloading/updating local repos"
else else
# Get Git files for Core and Admin # Get Git files for Core and Admin
getGitFiles ${piholeFilesDir} ${piholeGitUrl} getGitFiles ${piholeFilesDir} ${piholeGitUrl}
getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl} getGitFiles ${webInterfaceDir} ${webInterfaceGitUrl}
fi fi
if [[ ${useUpdateVars} == false ]]; then if [[ ${useUpdateVars} == false ]]; then
# Display welcome dialogs # Display welcome dialogs
welcomeDialogs welcomeDialogs
# Create directory for Pi-hole storage # Create directory for Pi-hole storage
@ -978,39 +974,39 @@ if [[ ${useUpdateVars} == false ]]; then
setDNS setDNS
# Install and log everything to a file # Install and log everything to a file
installPihole | tee ${tmpLog} installPihole | tee ${tmpLog}
else else
updatePihole | tee ${tmpLog} updatePihole | tee ${tmpLog}
fi fi
# Move the log file into /etc/pihole for storage # Move the log file into /etc/pihole for storage
mv ${tmpLog} ${instalLogLoc} mv ${tmpLog} ${instalLogLoc}
if [[ "${useUpdateVars}" == false ]]; then if [[ "${useUpdateVars}" == false ]]; then
displayFinalMessage displayFinalMessage
fi fi
echo "::: Restarting services..." echo "::: Restarting services..."
# Start services # Start services
start_service dnsmasq start_service dnsmasq
enable_service dnsmasq enable_service dnsmasq
start_service lighttpd start_service lighttpd
enable_service lighttpd enable_service lighttpd
echo "::: done." echo "::: done."
echo ":::" echo ":::"
if [[ "${useUpdateVars}" == false ]]; then if [[ "${useUpdateVars}" == false ]]; then
echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
echo "::: ${IPv4_address%/*}" echo "::: ${IPv4_address%/*}"
echo "::: $IPv6_address" echo "::: ${IPv6_address}"
echo ":::" echo ":::"
echo "::: If you set a new IP address, you should restart the Pi." echo "::: If you set a new IP address, you should restart the Pi."
else else
echo "::: Update complete!" echo "::: Update complete!"
fi fi
echo ":::" echo ":::"
echo "::: The install log is located at: /etc/pihole/install.log" echo "::: The install log is located at: /etc/pihole/install.log"
echo "::: View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admin" echo "::: View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admin"
} }
main "$@" main "$@"

@ -11,13 +11,13 @@
# (at your option) any later version. # (at your option) any later version.
# Must be root to uninstall # Must be root to uninstall
if [[ $EUID -eq 0 ]];then if [[ ${EUID} -eq 0 ]]; then
echo "::: You are root." echo "::: You are root."
else else
echo "::: Sudo will be used for the uninstall." echo "::: Sudo will be used for the uninstall."
# Check if it is actually installed # Check if it is actually installed
# If it isn't, exit because the unnstall cannot complete # If it isn't, exit because the unnstall cannot complete
if [ -x "$(command -v sudo)" ];then if [ -x "$(command -v sudo)" ]; then
export SUDO="sudo" export SUDO="sudo"
else else
echo "::: Please install sudo or run this as root." echo "::: Please install sudo or run this as root."
@ -26,14 +26,14 @@ else
fi fi
# Compatability # Compatability
if [ -x "$(command -v rpm)" ];then if [ -x "$(command -v rpm)" ]; then
# Fedora Family # Fedora Family
if [ -x "$(command -v dnf)" ];then if [ -x "$(command -v dnf)" ]; then
PKG_MANAGER="dnf" PKG_MANAGER="dnf"
else else
PKG_MANAGER="yum" PKG_MANAGER="yum"
fi fi
PKG_REMOVE="$PKG_MANAGER remove -y" PKG_REMOVE="${PKG_MANAGER} remove -y"
PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common git curl unzip wget findutils ) PIHOLE_DEPS=( bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common git curl unzip wget findutils )
package_check() { package_check() {
rpm -qa | grep ^$1- > /dev/null rpm -qa | grep ^$1- > /dev/null
@ -41,10 +41,10 @@ if [ -x "$(command -v rpm)" ];then
package_cleanup() { package_cleanup() {
${SUDO} ${PKG_MANAGER} -y autoremove ${SUDO} ${PKG_MANAGER} -y autoremove
} }
elif [ -x "$(command -v apt-get)" ];then elif [ -x "$(command -v apt-get)" ]; then
# Debian Family # Debian Family
PKG_MANAGER="apt-get" PKG_MANAGER="apt-get"
PKG_REMOVE="$PKG_MANAGER -y remove --purge" PKG_REMOVE="${PKG_MANAGER} -y remove --purge"
PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd php5-common git curl unzip wget ) PIHOLE_DEPS=( dnsutils bc dnsmasq lighttpd php5-common git curl unzip wget )
package_check() { package_check() {
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"
@ -62,10 +62,10 @@ 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
@ -79,15 +79,15 @@ removeAndPurge() {
package_check ${i} > /dev/null package_check ${i} > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
while true; do while true; do
read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn read -rp "::: Do you wish to remove ${i} from your system? [y/n]: " yn
case ${yn} in case ${yn} in
[Yy]* ) printf ":::\tRemoving %s..." "$i"; ${SUDO} ${PKG_REMOVE} "$i" &> /dev/null & spinner $!; printf "done!\n"; break;; [Yy]* ) printf ":::\tRemoving %s..." "${i}"; ${SUDO} ${PKG_REMOVE} "${i}" &> /dev/null & spinner $!; printf "done!\n"; break;;
[Nn]* ) printf ":::\tSkipping %s" "$i\n"; break;; [Nn]* ) printf ":::\tSkipping %s" "${i}\n"; break;;
* ) printf "::: You must answer yes or no!\n";; * ) printf "::: You must answer yes or no!\n";;
esac esac
done done
else else
printf ":::\tPackage %s not installed... Not removing.\n" "$i" printf ":::\tPackage %s not installed... Not removing.\n" "${i}"
fi fi
done done

@ -61,7 +61,7 @@ accretionDisc=${basename}.3.accretionDisc.txt
skipDownload=false skipDownload=false
# Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it) # Warn users still using pihole.conf that it no longer has any effect (I imagine about 2 people use it)
if [[ -r ${piholeDir}/pihole.conf ]];then if [[ -r ${piholeDir}/pihole.conf ]]; then
echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored." echo "::: pihole.conf file no longer supported. Over-rides in this file are ignored."
fi fi
@ -104,11 +104,11 @@ gravity_collapse() {
gravity_patternCheck() { gravity_patternCheck() {
patternBuffer=$1 patternBuffer=$1
# check if the patternbuffer is a non-zero length file # check if the patternbuffer is a non-zero length file
if [[ -s "$patternBuffer" ]];then if [[ -s "${patternBuffer}" ]]; then
# Some of the blocklists are copyright, they need to be downloaded # Some of the blocklists are copyright, they need to be downloaded
# and stored as is. They can be processed for content after they # and stored as is. They can be processed for content after they
# have been saved. # have been saved.
mv "$patternBuffer" "$saveLocation" mv "${patternBuffer}" "${saveLocation}"
echo " List updated, transport successful!" echo " List updated, transport successful!"
else else
# curl didn't download any host files, probably because of the date check # curl didn't download any host files, probably because of the date check
@ -127,24 +127,23 @@ gravity_transport() {
heisenbergCompensator="" heisenbergCompensator=""
if [[ -r ${saveLocation} ]]; then if [[ -r ${saveLocation} ]]; then
# if domain has been saved, add file for date check to only download newer # if domain has been saved, add file for date check to only download newer
heisenbergCompensator="-z $saveLocation" heisenbergCompensator="-z ${saveLocation}"
fi fi
# Silently curl url # Silently curl url
curl -s -L ${cmd_ext} ${heisenbergCompensator} -A "$agent" ${url} > ${patternBuffer} curl -s -L ${cmd_ext} ${heisenbergCompensator} -A "${agent}" ${url} > ${patternBuffer}
# Check for list updates # Check for list updates
gravity_patternCheck "$patternBuffer" gravity_patternCheck "${patternBuffer}"
} }
# spinup - main gravity function # spinup - main gravity function
gravity_spinup() { gravity_spinup() {
echo ":::" echo ":::"
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines # Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines
for ((i = 0; i < "${#sources[@]}"; i++)) for ((i = 0; i < "${#sources[@]}"; i++)); do
do
url=${sources[$i]} url=${sources[$i]}
# Get just the domain from the URL # Get just the domain from the URL
domain=$(echo "$url" | cut -d'/' -f3) domain=$(echo "${url}" | cut -d'/' -f3)
# Save the file as list.#.domain # Save the file as list.#.domain
saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension} saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension}
@ -152,11 +151,9 @@ gravity_spinup() {
agent="Mozilla/10.0" agent="Mozilla/10.0"
# Use a case statement to download lists that need special cURL commands # Use a case statement to download lists that need special cURL commands
# to complete properly and reset the user agent when required # to complete properly and reset the user agent when required
case "$domain" in case "${domain}" in
"adblock.mahakala.is") "adblock.mahakala.is")
agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36' agent='Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
cmd_ext="-e http://forum.xda-developers.com/" cmd_ext="-e http://forum.xda-developers.com/"
@ -182,9 +179,8 @@ gravity_Schwarzchild() {
# Find all active domains and compile them into one file and remove CRs # Find all active domains and compile them into one file and remove CRs
echo -n "::: Aggregating list of domains..." echo -n "::: Aggregating list of domains..."
truncate -s 0 ${piholeDir}/${matterAndLight} truncate -s 0 ${piholeDir}/${matterAndLight}
for i in "${activeDomains[@]}" for i in "${activeDomains[@]}"; do
do cat "${i}" | tr -d '\r' >> ${piholeDir}/${matterAndLight}
cat "$i" | tr -d '\r' >> ${piholeDir}/${matterAndLight}
done done
echo " done!" echo " done!"
} }
@ -207,9 +203,8 @@ gravity_Whitelist() {
echo -n "::: Adding adlist source${plural} to the whitelist..." echo -n "::: Adding adlist source${plural} to the whitelist..."
urls=() urls=()
for url in "${sources[@]}" for url in "${sources[@]}"; do
do tmp=$(echo "${url}" | awk -F '/' '{print $3}')
tmp=$(echo "$url" | awk -F '/' '{print $3}')
urls=("${urls[@]}" ${tmp}) urls=("${urls[@]}" ${tmp})
done done
echo " done!" echo " done!"
@ -276,13 +271,12 @@ gravity_hostFormat() {
# blackbody - remove any remnant files from script processes # blackbody - remove any remnant files from script processes
gravity_blackbody() { gravity_blackbody() {
# Loop through list files # Loop through list files
for file in ${piholeDir}/*.${justDomainsExtension} for file in ${piholeDir}/*.${justDomainsExtension}; do
do
# If list is in active array then leave it (noop) else rm the list # If list is in active array then leave it (noop) else rm the list
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
: :
else else
rm -f "$file" rm -f "${file}"
fi fi
done done
} }
@ -300,7 +294,7 @@ gravity_advanced() {
echo " done!" echo " done!"
numberOf=$(wc -l < ${piholeDir}/${supernova}) numberOf=$(wc -l < ${piholeDir}/${supernova})
echo "::: $numberOf domains being pulled in by gravity..." echo "::: ${numberOf} domains being pulled in by gravity..."
gravity_unique gravity_unique
} }
@ -325,9 +319,8 @@ gravity_reload() {
pihole restartdns pihole restartdns
} }
for var in "$@" for var in "$@"; do
do case "${var}" in
case "$var" in
"-f" | "--force" ) forceGrav=true;; "-f" | "--force" ) forceGrav=true;;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;
"-sd" | "--skip-download" ) skipDownload=true;; "-sd" | "--skip-download" ) skipDownload=true;;

@ -66,8 +66,7 @@ setupLCDFunction() {
queryFunc() { queryFunc() {
domain=$2 domain=$2
for list in /etc/pihole/list.* for list in /etc/pihole/list.*; do
do
count=$(grep ${domain} $list | wc -l) count=$(grep ${domain} $list | wc -l)
echo "::: ${list} (${count} results)" echo "::: ${list} (${count} results)"
if [[ ${count} > 0 ]]; then if [[ ${count} > 0 ]]; then
@ -156,29 +155,31 @@ piholeStatus() {
helpFunc() { helpFunc() {
echo "::: Control all PiHole specific functions!" cat << EOM
echo ":::" ::: Control all PiHole specific functions!
echo "::: Usage: pihole [options]" :::
echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" ::: Usage: pihole [options]
echo ":::" ::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage
echo "::: Options:" :::
echo "::: -w, whitelist Whitelist domains" ::: Options:
echo "::: -b, blacklist Blacklist domains" ::: -w, whitelist Whitelist domains
echo "::: -d, debug Start a debugging session if having trouble" ::: -b, blacklist Blacklist domains
echo "::: -f, flush Flush the pihole.log file" ::: -d, debug Start a debugging session if having trouble
echo "::: -up, updatePihole Update Pi-hole" ::: -f, flush Flush the pihole.log file
echo "::: -g, updateGravity Update the list of ad-serving domains" ::: -up, updatePihole Update Pi-hole
echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it" ::: -g, updateGravity Update the list of ad-serving domains
echo "::: -c, chronometer Calculates stats and displays to an LCD" ::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it
echo "::: -h, help Show this help dialog" ::: -c, chronometer Calculates stats and displays to an LCD
echo "::: -v, version Show current versions" ::: -h, help Show this help dialog
echo "::: -q, query Query the adlists for a specific domain" ::: -v, version Show current versions
echo "::: uninstall Uninstall Pi-Hole from your system :(!" ::: -q, query Query the adlists for a specific domain
echo "::: status Is Pi-Hole Enabled or Disabled" ::: uninstall Uninstall Pi-Hole from your system :(!
echo "::: enable Enable Pi-Hole DNS Blocking" ::: status Is Pi-Hole Enabled or Disabled
echo "::: disable Disable Pi-Hole DNS Blocking" ::: enable Enable Pi-Hole DNS Blocking
echo "::: restartdns Restart dnsmasq" ::: disable Disable Pi-Hole DNS Blocking
exit 0 ::: restartdns Restart dnsmasq
EOM
exit 1
} }
if [[ $# = 0 ]]; then if [[ $# = 0 ]]; then
@ -186,24 +187,23 @@ if [[ $# = 0 ]]; then
fi fi
# Handle redirecting to specific functions based on arguments # Handle redirecting to specific functions based on arguments
case "$1" in case "${1}" in
"-w" | "whitelist" ) whitelistFunc "$@";; "-w" | "whitelist" ) whitelistFunc "$@";;
"-b" | "blacklist" ) blacklistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";;
"-d" | "debug" ) debugFunc;; "-d" | "debug" ) debugFunc;;
"-f" | "flush" ) flushFunc;; "-f" | "flush" ) flushFunc;;
"-up" | "updatePihole" ) updatePiholeFunc;; "-up" | "updatePihole" ) updatePiholeFunc;;
"-r" | "reconfigure" ) reconfigurePiholeFunc;; "-r" | "reconfigure" ) reconfigurePiholeFunc;;
"-g" | "updateGravity" ) updateGravityFunc "$@";; "-g" | "updateGravity" ) updateGravityFunc "$@";;
"-s" | "setupLCD" ) setupLCDFunction;; "-s" | "setupLCD" ) setupLCDFunction;;
"-c" | "chronometer" ) chronometerFunc "$@";; "-c" | "chronometer" ) chronometerFunc "$@";;
"-h" | "help" ) helpFunc;; "-h" | "help" ) helpFunc;;
"-v" | "version" ) versionFunc "$@";; "-v" | "version" ) versionFunc "$@";;
"-q" | "query" ) queryFunc "$@";; "-q" | "query" ) queryFunc "$@";;
"uninstall" ) uninstallFunc;; "uninstall" ) uninstallFunc;;
"enable" ) piholeEnable 1;; "enable" ) piholeEnable 1;;
"disable" ) piholeEnable 0;; "disable" ) piholeEnable 0;;
"status" ) piholeStatus "$2";; "status" ) piholeStatus "$2";;
"restartdns" ) restartDNS;; "restartdns" ) restartDNS;;
* ) helpFunc;;
* ) helpFunc;;
esac esac

Loading…
Cancel
Save