Merge pull request #625 from pi-hole/UpdateMethod

Forget all existing attempts at an update method... this is the one.
This commit is contained in:
Dan Schaper 2016-08-30 11:47:36 -07:00 committed by GitHub
commit fdb0e31a78
10 changed files with 662 additions and 597 deletions

View file

@ -47,9 +47,9 @@ fi
#globals #globals
basename=pihole basename=pihole
piholeDir=/etc/$basename piholeDir=/etc/${basename}
adList=$piholeDir/gravity.list adList=${piholeDir}/gravity.list
blacklist=$piholeDir/blacklist.txt blacklist=${piholeDir}/blacklist.txt
reload=true reload=true
addmode=true addmode=true
force=false force=false
@ -61,9 +61,9 @@ domToRemoveList=()
piholeIPfile=/etc/pihole/piholeIP piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6 piholeIPv6file=/etc/pihole/.useIPv6
if [[ -f $piholeIPfile ]];then if [[ -f ${piholeIPfile} ]];then
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
piholeIP=$(cat $piholeIPfile) piholeIP=$(cat ${piholeIPfile})
#rm $piholeIPfile #rm $piholeIPfile
else else
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
@ -75,13 +75,13 @@ fi
modifyHost=false modifyHost=false
# After setting defaults, check if there's local overrides # After setting defaults, check if there's local overrides
if [[ -r $piholeDir/pihole.conf ]];then if [[ -r ${piholeDir}/pihole.conf ]];then
echo "::: Local calibration requested..." echo "::: Local calibration requested..."
. $piholeDir/pihole.conf . ${piholeDir}/pihole.conf
fi fi
if [[ -f $piholeIPv6file ]];then if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer # 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) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi
@ -92,14 +92,14 @@ function HandleOther(){
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})
fi fi
} }
function PopBlacklistFile(){ function 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
@ -113,17 +113,17 @@ function PopBlacklistFile(){
function AddDomain(){ function 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
#domain not found in the blacklist file, add it! #domain not found in the blacklist file, add it!
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 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
@ -132,15 +132,15 @@ function AddDomain(){
function RemoveDomain(){ function 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
#Domain is not in the blacklist file, no need to Remove #Domain is not in the blacklist file, no need to Remove
if $verbose; then if ${verbose}; then
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, add to a temporary array #Domain is in the blacklist file, add to a temporary array
if $verbose; then if ${verbose}; then
echo "::: Un-blacklisting $dom..." echo "::: Un-blacklisting $dom..."
fi fi
domToRemoveList=("${domToRemoveList[@]}" $1) domToRemoveList=("${domToRemoveList[@]}" $1)
@ -149,17 +149,17 @@ function RemoveDomain(){
} }
function ModifyHostFile(){ function ModifyHostFile(){
if $addmode; then if ${addmode}; then
#add domains to the hosts file #add domains to the hosts file
if [[ -r $blacklist ]];then if [[ -r ${blacklist} ]];then
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l)
plural=; [[ "$numberOf" != "1" ]] && plural=s plural=; [[ "$numberOf" != "1" ]] && plural=s
echo ":::" echo ":::"
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
if [[ -n $piholeIPv6 ]];then if [[ -n ${piholeIPv6} ]];then
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList}
else else
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
fi fi
fi fi
else else
@ -169,10 +169,10 @@ function ModifyHostFile(){
#we need to remove the domains from the blacklist file and the host file #we need to remove the domains from the blacklist file and the host file
echo "::: $dom" echo "::: $dom"
echo -n "::: removing from HOSTS file..." echo -n "::: removing from HOSTS file..."
echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' ${adList}
echo " done!" echo " done!"
echo -n "::: removing from blackist.txt..." echo -n "::: removing from blackist.txt..."
echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${blacklist}
echo " done!" echo " done!"
done done
fi fi
@ -185,12 +185,12 @@ function Reload() {
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
if [[ $dnsmasqPid ]]; then if [[ ${dnsmasqPid} ]]; then
# service already running - reload config # service already running - reload config
$SUDO killall -s HUP dnsmasq ${SUDO} killall -s HUP dnsmasq
else else
# service not running, start it up # service not running, start it up
$SUDO service dnsmasq start ${SUDO} service dnsmasq start
fi fi
echo " done!" echo " done!"
} }
@ -223,15 +223,15 @@ done
PopBlacklistFile PopBlacklistFile
if $modifyHost || $force; then if ${modifyHost} || ${force}; then
ModifyHostFile ModifyHostFile
else else
if $verbose; then if ${verbose}; then
echo "::: No changes need to be made" echo "::: No changes need to be made"
fi fi
exit 1 exit 1
fi fi
if $reload; then if ${reload}; then
Reload Reload
fi fi

View file

@ -21,7 +21,7 @@ function 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
@ -43,7 +43,7 @@ function CalcQueriesToday(){
function CalcblockedToday(){ function 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."
fi fi
@ -63,7 +63,7 @@ function CalcPercentBlockedToday(){
function CheckIPv6(){ function CheckIPv6(){
piholeIPv6file="/etc/pihole/.useIPv6" piholeIPv6file="/etc/pihole/.useIPv6"
if [[ -f $piholeIPv6file ]];then if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer # 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) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi

View file

@ -43,75 +43,75 @@ 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}
else else
truncate -s 0 $DEBUG_LOG truncate -s 0 ${DEBUG_LOG}
fi fi
### Private functions exist here ### ### Private functions exist here ###
function versionCheck { function versionCheck {
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "########## Versions Section ###########" >> $DEBUG_LOG echo "########## Versions Section ###########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
TMP=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) TMP=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
echo "Pi-hole Version: $TMP" >> $DEBUG_LOG echo "Pi-hole Version: $TMP" >> ${DEBUG_LOG}
TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0) TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0)
echo "WebUI Version: $TMP" >> $DEBUG_LOG echo "WebUI Version: $TMP" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
function distroCheck { function distroCheck {
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "######## Distribution Section #########" >> $DEBUG_LOG echo "######## Distribution Section #########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
TMP=$(cat /etc/*release || echo "Failed to find release") TMP=$(cat /etc/*release || echo "Failed to find release")
echo "Distribution Version: $TMP" >> $DEBUG_LOG echo "Distribution Version: $TMP" >> ${DEBUG_LOG}
} }
function compareWhitelist { function compareWhitelist {
if [ ! -f "$WHITELISTMATCHES" ]; then if [ ! -f "$WHITELISTMATCHES" ]; then
$SUDO touch $WHITELISTMATCHES ${SUDO} touch ${WHITELISTMATCHES}
$SUDO chmod 644 $WHITELISTMATCHES ${SUDO} chmod 644 ${WHITELISTMATCHES}
$SUDO chown "$USER":root $WHITELISTMATCHES ${SUDO} chown "$USER":root ${WHITELISTMATCHES}
else else
truncate -s 0 $WHITELISTMATCHES truncate -s 0 ${WHITELISTMATCHES}
fi fi
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "######## Whitelist Comparison #########" >> $DEBUG_LOG echo "######## Whitelist Comparison #########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
while read -r line; do while read -r line; do
TMP=$(grep -w ".* $line$" "$GRAVITYFILE") TMP=$(grep -w ".* $line$" "$GRAVITYFILE")
if [ ! -z "$TMP" ]; then if [ ! -z "$TMP" ]; then
echo "$TMP" >> $DEBUG_LOG echo "$TMP" >> ${DEBUG_LOG}
echo "$TMP" >> $WHITELISTMATCHES echo "$TMP" >> ${WHITELISTMATCHES}
fi fi
done < "$WHITELISTFILE" done < "$WHITELISTFILE"
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
function compareBlacklist { function compareBlacklist {
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "######## Blacklist Comparison #########" >> $DEBUG_LOG echo "######## Blacklist Comparison #########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
while read -r line; do while read -r line; do
if [ ! -z "$line" ]; then if [ ! -z "$line" ]; then
grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG grep -w ".* $line$" "$GRAVITYFILE" >> ${DEBUG_LOG}
fi fi
done < "$BLACKLISTFILE" done < "$BLACKLISTFILE"
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
function testNslookup { function testNslookup {
TESTURL="doubleclick.com" TESTURL="doubleclick.com"
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############ NSLookup Test ############" >> $DEBUG_LOG echo "############ NSLookup Test ############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
# Find a blocked url that has not been whitelisted. # Find a blocked url that has not been whitelisted.
if [ -s "$WHITELISTMATCHES" ]; then if [ -s "$WHITELISTMATCHES" ]; then
while read -r line; do while read -r line; do
@ -128,77 +128,77 @@ function testNslookup {
done < "$GRAVITYFILE" done < "$GRAVITYFILE"
fi fi
echo "NSLOOKUP of $TESTURL from PiHole:" >> $DEBUG_LOG echo "NSLOOKUP of $TESTURL from PiHole:" >> ${DEBUG_LOG}
nslookup "$TESTURL" >> $DEBUG_LOG nslookup "$TESTURL" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> $DEBUG_LOG echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG}
nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG nslookup "$TESTURL" 8.8.8.8 >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
function checkProcesses { function checkProcesses {
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "########### Processes Check ###########" >> $DEBUG_LOG echo "########### Processes Check ###########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
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
} }
function debugLighttpd { function debugLighttpd {
echo "::: Writing lighttpd to debug log..." echo "::: Writing lighttpd to debug log..."
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"
fi fi
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
### END FUNCTIONS ### ### END FUNCTIONS ###
### Check Pi internet connections ### ### Check Pi internet connections ###
# Log the IP addresses of this Pi # Log the IP addresses of this Pi
IPADDR=$($SUDO ifconfig | perl -nle 's/dr:(\S+)/print $1/e') IPADDR=$(${SUDO} ifconfig | perl -nle 's/dr:(\S+)/print $1/e')
echo "::: Writing local IPs to debug log" echo "::: Writing local IPs to debug log"
echo "IP Addresses of this Pi:" >> $DEBUG_LOG echo "IP Addresses of this Pi:" >> ${DEBUG_LOG}
echo "$IPADDR" >> $DEBUG_LOG echo "$IPADDR" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
# Check if we can connect to the local gateway # Check if we can connect to the local gateway
GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error) GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error)
echo "Gateway check:" >> $DEBUG_LOG echo "Gateway check:" >> ${DEBUG_LOG}
echo "$GATEWAY_CHECK" >> $DEBUG_LOG echo "$GATEWAY_CHECK" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
versionCheck versionCheck
distroCheck distroCheck
@ -209,109 +209,109 @@ checkProcesses
debugLighttpd debugLighttpd
echo "::: Writing dnsmasq.conf to debug log..." 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}
printf ":::\tNo dnsmasq.conf file found!\n" printf ":::\tNo dnsmasq.conf file found!\n"
fi fi
echo "::: Writing 01-pihole.conf to debug log..." 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}
printf ":::\tNo 01-pihole.conf file found\n" printf ":::\tNo 01-pihole.conf file found\n"
fi fi
echo "::: Writing size of gravity.list to debug log..." 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}
printf ":::\tNo gravity.list file found\n" printf ":::\tNo gravity.list file found\n"
fi fi
# Write the hostname output to compare against entries in /etc/hosts, which is logged next # Write the hostname output to compare against entries in /etc/hosts, which is logged next
echo "Hostname of this pihole is: " >> $DEBUG_LOG echo "Hostname of this pihole is: " >> ${DEBUG_LOG}
hostname >> $DEBUG_LOG hostname >> ${DEBUG_LOG}
echo "::: Writing hosts file to debug log..." echo "::: Writing hosts file to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "################ Hosts ################" >> $DEBUG_LOG echo "################ Hosts ################" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${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}
printf ":::\tNo hosts file found!\n" printf ":::\tNo hosts file found!\n"
fi fi
### PiHole application specific logging ### ### PiHole application specific logging ###
echo "::: Writing whitelist to debug log..." 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}
printf ":::\tNo whitelist.txt file found!\n" printf ":::\tNo whitelist.txt file found!\n"
fi fi
echo "::: Writing blacklist to debug log..." 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}
printf ":::\tNo blacklist.txt file found!\n" printf ":::\tNo blacklist.txt file found!\n"
fi fi
echo "::: Writing adlists.list to debug log..." 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
cat "$ADLISTSFILE" >> $DEBUG_LOG cat "$ADLISTSFILE" >> ${DEBUG_LOG}
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}
printf ":::\tNo adlists.list file found... using adlists.default!\n" printf ":::\tNo adlists.list file found... using adlists.default!\n"
fi fi
@ -320,17 +320,17 @@ fi
function dumpPiHoleLog { function dumpPiHoleLog {
trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT
echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)"
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
echo "No pihole.log file found!" >> $DEBUG_LOG echo "No pihole.log file found!" >> ${DEBUG_LOG}
printf ":::\tNo pihole.log file found!\n" printf ":::\tNo pihole.log file found!\n"
fi fi
} }
@ -340,7 +340,7 @@ function finalWork {
echo "::: Finshed debugging!" echo "::: Finshed debugging!"
echo "::: The degug log can be uploaded to Termbin.com for easier sharing." echo "::: The degug log can be uploaded to Termbin.com for easier sharing."
read -r -p "::: Would you like to upload the log? [y/N] " response read -r -p "::: Would you like to upload the log? [y/N] " response
case $response in case ${response} in
[yY][eE][sS]|[yY]) [yY][eE][sS]|[yY])
TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999)
;; ;;

View file

@ -44,12 +44,12 @@ getInitSys() {
# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285 # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285
autoLoginPiToConsole() { autoLoginPiToConsole() {
if [ -e /etc/init.d/lightdm ]; then if [ -e /etc/init.d/lightdm ]; then
if [ $SYSTEMD -eq 1 ]; then if [ ${SYSTEMD} -eq 1 ]; then
$SUDO systemctl set-default multi-user.target ${SUDO} systemctl set-default multi-user.target
$SUDO ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service ${SUDO} ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
else else
$SUDO update-rc.d lightdm disable 2 ${SUDO} update-rc.d lightdm disable 2
$SUDO 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/" ${SUDO} sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
fi fi
fi fi
} }
@ -66,23 +66,23 @@ echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc
# Set up the LCD screen based on Adafruits instuctions: # Set up the LCD screen based on Adafruits instuctions:
# https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install # https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install
curl -SLs https://apt.adafruit.com/add-pin | $SUDO bash curl -SLs https://apt.adafruit.com/add-pin | ${SUDO} bash
$SUDO apt-get -y install raspberrypi-bootloader ${SUDO} apt-get -y install raspberrypi-bootloader
$SUDO apt-get -y install adafruit-pitft-helper ${SUDO} apt-get -y install adafruit-pitft-helper
$SUDO adafruit-pitft-helper -t 28r ${SUDO} adafruit-pitft-helper -t 28r
# Download the cmdline.txt file that prevents the screen from going blank after a period of time # Download the cmdline.txt file that prevents the screen from going blank after a period of time
$SUDO mv /boot/cmdline.txt /boot/cmdline.orig ${SUDO} mv /boot/cmdline.txt /boot/cmdline.orig
$SUDO curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt ${SUDO} curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt
# Back up the original file and download the new one # Back up the original file and download the new one
$SUDO mv /etc/default/console-setup /etc/default/console-setup.orig ${SUDO} mv /etc/default/console-setup /etc/default/console-setup.orig
$SUDO curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup ${SUDO} curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup
# Instantly apply the font change to the LCD screen # Instantly apply the font change to the LCD screen
$SUDO setupcon ${SUDO} setupcon
$SUDO reboot ${SUDO} reboot
# Start showing the stats on the screen by running the command on another tty: # Start showing the stats on the screen by running the command on another tty:
# http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty # http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty

View file

@ -55,7 +55,7 @@ is_repo() {
# replaces it with the current master branch from github # replaces it with the current master branch from github
make_repo() { make_repo() {
# remove the non-repod interface and clone the interface # remove the non-repod interface and clone the interface
rm -rf $WEB_INTERFACE_DIR rm -rf ${WEB_INTERFACE_DIR}
git clone "$WEB_INTERFACE_GIT_URL" "$WEB_INTERFACE_DIR" git clone "$WEB_INTERFACE_GIT_URL" "$WEB_INTERFACE_DIR"
} }

View file

@ -47,9 +47,9 @@ fi
#globals #globals
basename=pihole basename=pihole
piholeDir=/etc/$basename piholeDir=/etc/${basename}
adList=$piholeDir/gravity.list adList=${piholeDir}/gravity.list
whitelist=$piholeDir/whitelist.txt whitelist=${piholeDir}/whitelist.txt
reload=true reload=true
addmode=true addmode=true
force=false force=false
@ -61,9 +61,9 @@ domToRemoveList=()
piholeIPfile=/etc/pihole/piholeIP piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6 piholeIPv6file=/etc/pihole/.useIPv6
if [[ -f $piholeIPfile ]];then if [[ -f ${piholeIPfile} ]];then
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
piholeIP=$(cat $piholeIPfile) piholeIP=$(cat ${piholeIPfile})
#rm $piholeIPfile #rm $piholeIPfile
else else
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
@ -75,12 +75,12 @@ fi
modifyHost=false modifyHost=false
# After setting defaults, check if there's local overrides # After setting defaults, check if there's local overrides
if [[ -r $piholeDir/pihole.conf ]];then if [[ -r ${piholeDir}/pihole.conf ]];then
echo "::: Local calibration requested..." echo "::: Local calibration requested..."
. $piholeDir/pihole.conf . ${piholeDir}/pihole.conf
fi fi
if [[ -f $piholeIPv6file ]];then if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer # 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) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi
@ -91,18 +91,18 @@ function HandleOther(){
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})
fi fi
} }
function PopWhitelistFile(){ function 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"
@ -114,19 +114,19 @@ function 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
if $bool; then if ${bool}; then
#domain not found in the whitelist file, add it! #domain not found in the whitelist file, add it!
if $verbose; then if ${verbose}; then
echo -n "::: Adding $1 to $whitelist..." echo -n "::: Adding $1 to $whitelist..."
fi fi
echo "$1" >> $whitelist echo "$1" >> ${whitelist}
modifyHost=true modifyHost=true
if $verbose; then if ${verbose}; then
echo " done!" echo " done!"
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
@ -135,10 +135,10 @@ function AddDomain(){
function RemoveDomain(){ function RemoveDomain(){
bool=false bool=false
grep -Ex -q "$1" $whitelist || bool=true grep -Ex -q "$1" ${whitelist} || bool=true
if $bool; then if ${bool}; then
#Domain is not in the whitelist file, no need to Remove #Domain is not in the whitelist file, no need to Remove
if $verbose; then if ${verbose}; then
echo "::: $1 is NOT whitelisted! No need to remove" echo "::: $1 is NOT whitelisted! No need to remove"
fi fi
else else
@ -152,21 +152,21 @@ function RemoveDomain(){
} }
function ModifyHostFile(){ function ModifyHostFile(){
if $addmode; then if ${addmode}; then
#remove domains in from hosts file #remove domains in from hosts file
if [[ -r $whitelist ]];then if [[ -r ${whitelist} ]];then
# Remove whitelist entries # Remove whitelist entries
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l) numberOf=$(cat ${whitelist} | sed '/^\s*$/d' | wc -l)
plural=; [[ "$numberOf" != "1" ]] && plural=s plural=; [[ "$numberOf" != "1" ]] && plural=s
echo ":::" echo ":::"
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp
awk -F':' '{print $1}' $whitelist | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
echo "l" >> /etc/pihole/whitelist.tmp echo "l" >> /etc/pihole/whitelist.tmp
grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
rm $adList rm ${adList}
mv $piholeDir/gravity.tmp $adList mv ${piholeDir}/gravity.tmp ${adList}
rm $piholeDir/whitelist.tmp rm ${piholeDir}/whitelist.tmp
echo " done!" echo " done!"
fi fi
@ -178,18 +178,18 @@ function ModifyHostFile(){
do do
if grep -q "$rdom" /etc/pihole/*.domains; then if grep -q "$rdom" /etc/pihole/*.domains; then
echo "::: AdLists contain $rdom, re-adding block" echo "::: AdLists contain $rdom, re-adding block"
if [[ -n $piholeIPv6 ]];then if [[ -n ${piholeIPv6} ]];then
echo -n "::: Restoring block for $rdom on IPv4 and IPv6..." echo -n "::: Restoring block for $rdom on IPv4 and IPv6..."
echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList}
echo " done!" echo " done!"
else else
echo -n "::: Restoring block for $rdom on IPv4..." echo -n "::: Restoring block for $rdom on IPv4..."
echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
echo " done!" echo " done!"
fi fi
fi fi
echo -n "::: Removing $rdom from $whitelist..." echo -n "::: Removing $rdom from $whitelist..."
echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' ${whitelist}
echo " done!" echo " done!"
done done
fi fi
@ -201,12 +201,12 @@ function Reload() {
echo -n "::: Refresh lists in dnsmasq..." echo -n "::: Refresh lists in dnsmasq..."
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
if [[ $dnsmasqPid ]]; then if [[ ${dnsmasqPid} ]]; then
# service already running - reload config # service already running - reload config
$SUDO killall -s HUP dnsmasq ${SUDO} killall -s HUP dnsmasq
else else
# service not running, start it up # service not running, start it up
$SUDO service dnsmasq start ${SUDO} service dnsmasq start
fi fi
echo " done!" echo " done!"
} }
@ -239,16 +239,16 @@ done
PopWhitelistFile PopWhitelistFile
if $modifyHost || $force; then if ${modifyHost} || ${force}; then
ModifyHostFile ModifyHostFile
else else
if $verbose; then if ${verbose}; then
echo ":::" echo ":::"
echo "::: No changes need to be made" echo "::: No changes need to be made"
fi fi
exit 1 exit 1
fi fi
if $reload; then if ${reload}; then
Reload Reload
fi fi

File diff suppressed because it is too large Load diff

View file

@ -39,7 +39,7 @@ if [ -x "$(command -v rpm)" ];then
rpm -qa | grep ^$1- > /dev/null rpm -qa | grep ^$1- > /dev/null
} }
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
@ -50,8 +50,8 @@ elif [ -x "$(command -v apt-get)" ];then
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"
} }
package_cleanup() { package_cleanup() {
$SUDO $PKG_MANAGER -y autoremove ${SUDO} ${PKG_MANAGER} -y autoremove
$SUDO $PKG_MANAGER -y autoclean ${SUDO} ${PKG_MANAGER} -y autoclean
} }
else else
echo "OS distribution not supported" echo "OS distribution not supported"
@ -66,8 +66,8 @@ spinner()
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
local temp=${spinstr#?} local temp=${spinstr#?}
printf " [%c] " "$spinstr" printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"} local spinstr=${temp}${spinstr%"$temp"}
sleep $delay sleep ${delay}
printf "\b\b\b\b\b\b" printf "\b\b\b\b\b\b"
done done
printf " \b\b\b\b" printf " \b\b\b\b"
@ -77,12 +77,12 @@ function removeAndPurge {
# Purge dependencies # Purge dependencies
echo ":::" echo ":::"
for i in "${PIHOLE_DEPS[@]}"; do for i in "${PIHOLE_DEPS[@]}"; do
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
@ -94,7 +94,7 @@ echo ":::"
# Remove dependency config files # Remove dependency config files
echo "::: Removing dnsmasq config files..." echo "::: Removing dnsmasq config files..."
$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null
# Take care of any additional package cleaning # Take care of any additional package cleaning
printf "::: Auto removing & cleaning remaining dependencies..." printf "::: Auto removing & cleaning remaining dependencies..."
@ -108,14 +108,14 @@ function removeNoPurge {
echo ":::" echo ":::"
# Only web directories/files that are created by pihole should be removed. # Only web directories/files that are created by pihole should be removed.
echo "::: Removing the Pi-hole Web server files..." echo "::: Removing the Pi-hole Web server files..."
$SUDO rm -rf /var/www/html/admin &> /dev/null ${SUDO} rm -rf /var/www/html/admin &> /dev/null
$SUDO rm -rf /var/www/html/pihole &> /dev/null ${SUDO} rm -rf /var/www/html/pihole &> /dev/null
$SUDO rm /var/www/html/index.lighttpd.orig &> /dev/null ${SUDO} rm /var/www/html/index.lighttpd.orig &> /dev/null
# If the web directory is empty after removing these files, then the parent html folder can be removed. # If the web directory is empty after removing these files, then the parent html folder can be removed.
if [ -d "/var/www/html" ]; then if [ -d "/var/www/html" ]; then
if [[ ! "$(ls -A /var/www/html)" ]]; then if [[ ! "$(ls -A /var/www/html)" ]]; then
$SUDO rm -rf /var/www/html &> /dev/null ${SUDO} rm -rf /var/www/html &> /dev/null
fi fi
fi fi
@ -125,36 +125,36 @@ function removeNoPurge {
# preserved. # preserved.
if [[ -f /etc/crontab.orig ]]; then if [[ -f /etc/crontab.orig ]]; then
echo "::: Initial Pi-hole cron detected. Restoring the default system cron..." echo "::: Initial Pi-hole cron detected. Restoring the default system cron..."
$SUDO mv /etc/crontab /etc/crontab.pihole ${SUDO} mv /etc/crontab /etc/crontab.pihole
$SUDO mv /etc/crontab.orig /etc/crontab ${SUDO} mv /etc/crontab.orig /etc/crontab
$SUDO service cron restart ${SUDO} service cron restart
fi fi
# Attempt to preserve backwards compatibility with older versions # Attempt to preserve backwards compatibility with older versions
if [[ -f /etc/cron.d/pihole ]];then if [[ -f /etc/cron.d/pihole ]];then
echo "::: Removing cron.d/pihole..." echo "::: Removing cron.d/pihole..."
$SUDO rm /etc/cron.d/pihole &> /dev/null ${SUDO} rm /etc/cron.d/pihole &> /dev/null
fi fi
echo "::: Removing config files and scripts..." echo "::: Removing config files and scripts..."
package_check $i > /dev/null package_check ${i} > /dev/null
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
$SUDO rm -rf /etc/lighttpd/ &> /dev/null ${SUDO} rm -rf /etc/lighttpd/ &> /dev/null
else else
if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then
$SUDO mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf ${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf
fi fi
fi fi
$SUDO rm /etc/dnsmasq.d/adList.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.d/adList.conf &> /dev/null
$SUDO rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null
$SUDO rm -rf /var/log/*pihole* &> /dev/null ${SUDO} rm -rf /var/log/*pihole* &> /dev/null
$SUDO rm -rf /etc/pihole/ &> /dev/null ${SUDO} rm -rf /etc/pihole/ &> /dev/null
$SUDO rm -rf /etc/.pihole/ &> /dev/null ${SUDO} rm -rf /etc/.pihole/ &> /dev/null
$SUDO rm -rf /opt/pihole/ &> /dev/null ${SUDO} rm -rf /opt/pihole/ &> /dev/null
$SUDO rm /usr/local/bin/pihole &> /dev/null ${SUDO} rm /usr/local/bin/pihole &> /dev/null
$SUDO rm /etc/bash_completion.d/pihole &> /dev/null ${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null
$SUDO rm /etc/sudoers.d/pihole &> /dev/null ${SUDO} rm /etc/sudoers.d/pihole &> /dev/null
echo ":::" echo ":::"
printf "::: Finished removing PiHole from your system. Sorry to see you go!\n" printf "::: Finished removing PiHole from your system. Sorry to see you go!\n"
@ -168,7 +168,7 @@ echo "::: Preparing to remove packages, be sure that each may be safely removed
echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)" echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)"
while true; do while true; do
read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package) [y/n]: " yn read -rp "::: Do you wish to purge PiHole's dependencies from your OS? (You will be prompted for each package) [y/n]: " yn
case $yn in case ${yn} in
[Yy]* ) removeAndPurge; break;; [Yy]* ) removeAndPurge; break;;
[Nn]* ) removeNoPurge; break;; [Nn]* ) removeNoPurge; break;;

View file

@ -47,9 +47,9 @@ adListDefault=/etc/pihole/adlists.default
whitelistScript=/opt/pihole/whitelist.sh whitelistScript=/opt/pihole/whitelist.sh
blacklistScript=/opt/pihole/blacklist.sh blacklistScript=/opt/pihole/blacklist.sh
if [[ -f $piholeIPfile ]];then if [[ -f ${piholeIPfile} ]];then
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script # If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
piholeIP=$(cat $piholeIPfile) piholeIP=$(cat ${piholeIPfile})
#rm $piholeIPfile #rm $piholeIPfile
else else
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
@ -58,7 +58,7 @@ else
piholeIP=${piholeIPCIDR%/*} piholeIP=${piholeIPCIDR%/*}
fi fi
if [[ -f $piholeIPv6file ]];then if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer # 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) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi
@ -66,22 +66,22 @@ fi
# Variables for various stages of downloading and formatting the list # Variables for various stages of downloading and formatting the list
## Nate 3/26/2016 - Commented unused variables ## Nate 3/26/2016 - Commented unused variables
basename=pihole basename=pihole
piholeDir=/etc/$basename piholeDir=/etc/${basename}
adList=$piholeDir/gravity.list adList=${piholeDir}/gravity.list
#blacklist=$piholeDir/blacklist.txt #blacklist=$piholeDir/blacklist.txt
#whitelist=$piholeDir/whitelist.txt #whitelist=$piholeDir/whitelist.txt
#latentWhitelist=$piholeDir/latentWhitelist.txt #latentWhitelist=$piholeDir/latentWhitelist.txt
justDomainsExtension=domains justDomainsExtension=domains
matterandlight=$basename.0.matterandlight.txt matterandlight=${basename}.0.matterandlight.txt
supernova=$basename.1.supernova.txt supernova=${basename}.1.supernova.txt
eventHorizon=$basename.2.eventHorizon.txt eventHorizon=${basename}.2.eventHorizon.txt
accretionDisc=$basename.3.accretionDisc.txt accretionDisc=${basename}.3.accretionDisc.txt
#eyeOfTheNeedle=$basename.4.wormhole.txt #eyeOfTheNeedle=$basename.4.wormhole.txt
# After setting defaults, check if there's local overrides # After setting defaults, check if there's local overrides
if [[ -r $piholeDir/pihole.conf ]];then if [[ -r ${piholeDir}/pihole.conf ]];then
echo "::: Local calibration requested..." echo "::: Local calibration requested..."
. $piholeDir/pihole.conf . ${piholeDir}/pihole.conf
fi fi
########################### ###########################
@ -90,18 +90,18 @@ function gravity_collapse() {
echo "::: Neutrino emissions detected..." echo "::: Neutrino emissions detected..."
echo ":::" echo ":::"
#Decide if we're using a custom ad block list, or defaults. #Decide if we're using a custom ad block list, or defaults.
if [ -f $adListFile ]; then if [ -f ${adListFile} ]; then
#custom file found, use this instead of default #custom file found, use this instead of default
echo -n "::: Custom adList file detected. Reading..." echo -n "::: Custom adList file detected. Reading..."
sources=() sources=()
while read -r line; do while read -r line; do
#Do not read commented out or blank lines #Do not read commented out or blank lines
if [[ $line = \#* ]] || [[ ! $line ]]; then if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then
echo "" > /dev/null echo "" > /dev/null
else else
sources+=($line) sources+=(${line})
fi fi
done < $adListFile done < ${adListFile}
echo " done!" echo " done!"
else else
#no custom file found, use defaults! #no custom file found, use defaults!
@ -109,27 +109,27 @@ function gravity_collapse() {
sources=() sources=()
while read -r line; do while read -r line; do
#Do not read commented out or blank lines #Do not read commented out or blank lines
if [[ $line = \#* ]] || [[ ! $line ]]; then if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then
echo "" > /dev/null echo "" > /dev/null
else else
sources+=($line) sources+=(${line})
fi fi
done < $adListDefault done < ${adListDefault}
echo " done!" echo " done!"
fi fi
# Create the pihole resource directory if it doesn't exist. Future files will be stored here # Create the pihole resource directory if it doesn't exist. Future files will be stored here
if [[ -d $piholeDir ]];then if [[ -d ${piholeDir} ]];then
# Temporary hack to allow non-root access to pihole directory # Temporary hack to allow non-root access to pihole directory
# Will update later, needed for existing installs, new installs should # Will update later, needed for existing installs, new installs should
# create this directory as non-root # create this directory as non-root
$SUDO chmod 777 $piholeDir ${SUDO} chmod 777 ${piholeDir}
echo ":::" echo ":::"
echo "::: Existing pihole directory found" echo "::: Existing pihole directory found"
else else
echo "::: Creating pihole directory..." echo "::: Creating pihole directory..."
mkdir $piholeDir mkdir ${piholeDir}
$SUDO chmod 777 $piholeDir ${SUDO} chmod 777 ${piholeDir}
fi fi
} }
@ -158,13 +158,13 @@ function gravity_transport() {
# tmp file, so we don't have to store the (long!) lists in RAM # tmp file, so we don't have to store the (long!) lists in RAM
patternBuffer=$(mktemp) patternBuffer=$(mktemp)
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"
# Cleanup # Cleanup
@ -182,8 +182,8 @@ function gravity_spinup() {
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}
activeDomains[$i]=$saveLocation activeDomains[$i]=${saveLocation}
agent="Mozilla/10.0" agent="Mozilla/10.0"
@ -213,10 +213,10 @@ function gravity_Schwarzchild() {
echo "::: " echo "::: "
# 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!"
} }
@ -224,7 +224,7 @@ function gravity_Schwarzchild() {
function gravity_Blacklist(){ function gravity_Blacklist(){
# Append blacklist entries if they exist # Append blacklist entries if they exist
echo -n "::: Running blacklist script to update HOSTS file...." echo -n "::: Running blacklist script to update HOSTS file...."
$blacklistScript -f -nr -q > /dev/null ${blacklistScript} -f -nr -q > /dev/null
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt") numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
@ -241,12 +241,12 @@ function gravity_Whitelist() {
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!"
echo -n "::: Running whitelist script to update HOSTS file...." echo -n "::: Running whitelist script to update HOSTS file...."
$whitelistScript -f -nr -q "${urls[@]}" > /dev/null ${whitelistScript} -f -nr -q "${urls[@]}" > /dev/null
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt") numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
echo " $numWhitelisted domain${plural} whitelisted!" echo " $numWhitelisted domain${plural} whitelisted!"
@ -255,9 +255,9 @@ function gravity_Whitelist() {
function gravity_unique() { function gravity_unique() {
# Sort and remove duplicates # Sort and remove duplicates
echo -n "::: Removing duplicate domains...." echo -n "::: Removing duplicate domains...."
sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon}
echo " done!" echo " done!"
numberOf=$(wc -l < $piholeDir/$eventHorizon) numberOf=$(wc -l < ${piholeDir}/${eventHorizon})
echo "::: $numberOf unique domains trapped in the event horizon." echo "::: $numberOf unique domains trapped in the event horizon."
} }
@ -266,25 +266,25 @@ function gravity_hostFormat() {
echo "::: Formatting domains into a HOSTS file..." echo "::: Formatting domains into a HOSTS file..."
hostname=$(</etc/hostname) hostname=$(</etc/hostname)
# If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols # If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols
if [[ -n $piholeIPv6 ]];then if [[ -n ${piholeIPv6} ]];then
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)
echo -e "$piholeIP $hostname\n$piholeIPv6 $hostname\n$piholeIP pi.hole\n$piholeIPv6 pi.hole" > $piholeDir/$accretionDisc echo -e "$piholeIP $hostname\n$piholeIPv6 $hostname\n$piholeIP pi.hole\n$piholeIPv6 pi.hole" > ${piholeDir}/${accretionDisc}
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
else else
# Otherwise, just create gravity.list as normal using IPv4 # Otherwise, just create gravity.list as normal using IPv4
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)
echo -e "$piholeIP $hostname\n$piholeIP pi.hole" > $piholeDir/$accretionDisc echo -e "$piholeIP $hostname\n$piholeIP pi.hole" > ${piholeDir}/${accretionDisc}
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
fi fi
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
cp $piholeDir/$accretionDisc $adList cp ${piholeDir}/${accretionDisc} ${adList}
} }
# blackbody - remove any remnant files from script processes # blackbody - remove any remnant files from script processes
function gravity_blackbody() { function 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
@ -301,10 +301,10 @@ function gravity_advanced() {
# This helps with that and makes it easier to read # This helps with that and makes it easier to read
# It also helps with debugging so each stage of the script can be researched more in depth # It also helps with debugging so each stage of the script can be researched more in depth
echo -n "::: Formatting list of domains to remove comments...." echo -n "::: Formatting list of domains to remove comments...."
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$matterandlight | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' ${piholeDir}/${matterandlight} | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > ${piholeDir}/${supernova}
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
@ -314,7 +314,7 @@ function gravity_reload() {
#Clear no longer needed files... #Clear no longer needed files...
echo ":::" echo ":::"
echo -n "::: Cleaning up un-needed files..." echo -n "::: Cleaning up un-needed files..."
$SUDO rm $piholeDir/pihole.*.txt ${SUDO} rm ${piholeDir}/pihole.*.txt
echo " done!" echo " done!"
# Reload hosts file # Reload hosts file
@ -325,17 +325,17 @@ function gravity_reload() {
#First escape forward slashes in the path: #First escape forward slashes in the path:
adList=${adList//\//\\\/} adList=${adList//\//\\\/}
#Now replace the line in dnsmasq file #Now replace the line in dnsmasq file
$SUDO sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf ${SUDO} sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
find "$piholeDir" -type f -exec $SUDO chmod 666 {} \; find "$piholeDir" -type f -exec ${SUDO} chmod 666 {} \;
if [[ $dnsmasqPid ]]; then if [[ ${dnsmasqPid} ]]; then
# service already running - reload config # service already running - reload config
$SUDO killall -s HUP dnsmasq ${SUDO} killall -s HUP dnsmasq
else else
# service not running, start it up # service not running, start it up
$SUDO service dnsmasq start ${SUDO} service dnsmasq start
fi fi
echo " done!" echo " done!"
} }
@ -344,20 +344,20 @@ function gravity_reload() {
for var in "$@" for var in "$@"
do do
case "$var" in case "$var" in
"-f" | "--force" ) force=true;; "-f" | "--force" ) forceGrav=true;;
"-h" | "--help" ) helpFunc;; "-h" | "--help" ) helpFunc;;
esac esac
done done
#Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list #Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list
if $force; then if [[ ${forceGrav} == true ]]; then
echo -n "::: Deleting exising list cache..." echo -n "::: Deleting exising list cache..."
$SUDO rm /etc/pihole/list.* ${SUDO} rm /etc/pihole/list.*
echo " done!" echo " done!"
fi fi
$SUDO cp /etc/.pihole/adlists.default /etc/pihole/adlists.default ${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
gravity_collapse gravity_collapse
gravity_spinup gravity_spinup
gravity_Schwarzchild gravity_Schwarzchild

36
pihole
View file

@ -27,38 +27,46 @@ fi
function whitelistFunc { function whitelistFunc {
shift shift
$SUDO /opt/pihole/whitelist.sh "$@" ${SUDO} /opt/pihole/whitelist.sh "$@"
exit 1 exit 1
} }
function blacklistFunc { function blacklistFunc {
shift shift
$SUDO /opt/pihole/blacklist.sh "$@" ${SUDO} /opt/pihole/blacklist.sh "$@"
exit 1 exit 1
} }
function debugFunc { function debugFunc {
$SUDO /opt/pihole/piholeDebug.sh ${SUDO} /opt/pihole/piholeDebug.sh
exit 1 exit 1
} }
function flushFunc { function flushFunc {
$SUDO /opt/pihole/piholeLogFlush.sh ${SUDO} /opt/pihole/piholeLogFlush.sh
exit 1 exit 1
} }
function updateDashboardFunc { function updateDashboardFunc {
$SUDO /opt/pihole/updateDashboard.sh ${SUDO} /opt/pihole/updateDashboard.sh
exit 1
}
function updatePiholeFunc {
echo "::: Fetching latest changes from Github..."
cd /etc/.pihole
${SUDO} git pull
${SUDO} /etc/.pihole/automated\ install/basic-install.sh pihole
exit 1 exit 1
} }
function updateGravityFunc { function updateGravityFunc {
$SUDO /opt/pihole/gravity.sh ${SUDO} /opt/pihole/gravity.sh "$@"
exit 1 exit 1
} }
function setupLCDFunction { function setupLCDFunction {
$SUDO /opt/pihole/setupLCD.sh ${SUDO} /opt/pihole/setupLCD.sh
exit 1 exit 1
} }
@ -70,18 +78,18 @@ function queryFunc {
function chronometerFunc { function chronometerFunc {
shift shift
$SUDO /opt/pihole/chronometer.sh "$@" ${SUDO} /opt/pihole/chronometer.sh "$@"
exit 1 exit 1
} }
function uninstallFunc { function uninstallFunc {
$SUDO /opt/pihole/uninstall.sh ${SUDO} /opt/pihole/uninstall.sh
exit 1 exit 1
} }
function versionFunc { function versionFunc {
$SUDO /opt/pihole/version.sh ${SUDO} /opt/pihole/version.sh
exit 1 exit 1
} }
@ -96,7 +104,8 @@ function helpFunc {
echo "::: -b, blacklist Blacklist domains" echo "::: -b, blacklist Blacklist domains"
echo "::: -d, debug Start a debugging session if having trouble" echo "::: -d, debug Start a debugging session if having trouble"
echo "::: -f, flush Flush the pihole.log file" echo "::: -f, flush Flush the pihole.log file"
echo "::: -u, updateDashboard Update the web dashboard manually" echo "::: -ud, updateDashboard Update the web dashboard manually"
echo "::: -up, updatePihole Update Pi-hole"
echo "::: -g, updateGravity Update the list of ad-serving domains" echo "::: -g, updateGravity Update the list of ad-serving domains"
echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it" echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it"
echo "::: -c, chronometer Calculates stats and displays to an LCD" echo "::: -c, chronometer Calculates stats and displays to an LCD"
@ -117,8 +126,9 @@ case "$1" in
"-b" | "blacklist" ) blacklistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";;
"-d" | "debug" ) debugFunc;; "-d" | "debug" ) debugFunc;;
"-f" | "flush" ) flushFunc;; "-f" | "flush" ) flushFunc;;
"-u" | "updateDashboard" ) updateDashboardFunc;; "-ud" | "updateDashboard" ) updateDashboardFunc;;
"-g" | "updateGravity" ) updateGravityFunc;; "-up" | "updatePihole" ) updatePiholeFunc;;
"-g" | "updateGravity" ) updateGravityFunc "$@";;
"-s" | "setupLCD" ) setupLCDFunction;; "-s" | "setupLCD" ) setupLCDFunction;;
"-c" | "chronometer" ) chronometerFunc "$@";; "-c" | "chronometer" ) chronometerFunc "$@";;
"-h" | "help" ) helpFunc;; "-h" | "help" ) helpFunc;;