diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index bc158777..d96e1330 100644 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -1,3 +1,4 @@ +<<<<<<< HEAD #!/usr/bin/env bash # (c) 2015 by Jacob Salmela # This file is part of Pi-hole. @@ -39,3 +40,187 @@ if $boolA; then else echo "No need to update Hosts list, given domains already in blacklist" fi +======= +#!/usr/bin/env bash +# (c) 2015 by Jacob Salmela +# This file is part of Pi-hole. +# +# Pi-hole is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +if [[ $# = 0 ]]; then + echo "Immediately blacklists one or more domains in the hosts file" + echo " " + echo "Usage: blacklist.sh domain1 [domain2 ...]" + echo " " + echo "Options:" + echo " -d, --delmode Remove domains from the blacklist" + echo " -nr, --noreload Update blacklist without refreshing dnsmasq" + echo " -f, --force Force updating of the hosts files, even if there are no changes" + echo " -q, --quiet output is less verbose" + exit 1 +fi + +#globals +blacklist=/etc/pihole/blacklist.txt +adList=/etc/pihole/gravity.list +reload=true +addmode=true +force=false +versbose=true +domList=() +domToRemoveList=() + + +piholeIPfile=/tmp/piholeIP +piholeIPv6file=/etc/pihole/.useIPv6 + +# 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 +IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') +piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') +piholeIP=${piholeIPCIDR%/*} + +modifyHost=false + + +if [[ -f $piholeIPv6file ]];then + # If the file exists, then the user previously chose to use IPv6 in the automated installer + piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') +fi + + +function HandleOther(){ + #check validity of domain + validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') + + if [ -z "$validDomain" ]; then + echo $1 is not a valid argument or domain name + else + domList=("${domList[@]}" $validDomain) + fi +} + +function PopBlacklistFile(){ + #check blacklist file exists, and if not, create it + if [[ ! -f $blacklist ]];then + touch $blacklist + fi + for dom in "${domList[@]}" + do + if $addmode; then + AddDomain $dom + else + RemoveDomain $dom + fi + done +} + +function AddDomain(){ +#| sed 's/\./\\./g' + bool=false + grep -Ex -q "$1" $blacklist || bool=true + if $bool; then + #domain not found in the blacklist file, add it! + if $versbose; then + echo "** Adding $1 to blacklist file" + fi + echo $1 >> $blacklist + modifyHost=true + else + if $versbose; then + echo "** $1 already blacklisted! No need to add" + fi + fi +} + +function RemoveDomain(){ + + bool=false + grep -Ex -q "$1" $blacklist || bool=true + if $bool; then + #Domain is not in the blacklist file, no need to Remove + if $versbose; then + echo "** $1 is NOT blacklisted! No need to remove" + fi + else + #Domain is in the blacklist file, add to a temporary array + if $versbose; then + echo "** Un-blacklisting $dom..." + fi + domToRemoveList=("${domToRemoveList[@]}" $1) + modifyHost=true + fi +} + +function 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 "** blacklisting a total of $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 + + for dom in "${domToRemoveList[@]}" + do + #we need to remove the domains from the blacklist file and the host 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 /'{}'(?!.)/;' $blacklist + done + fi + +} + +function Reload() { + # Reload hosts file + echo "** Refresh lists in dnsmasq..." + + dnsmasqPid=$(pidof dnsmasq) + + if [[ $dnsmasqPid ]]; then + # service already running - reload config + sudo kill -HUP $dnsmasqPid + else + # service not running, start it up + sudo service dnsmasq start + fi +} + +################################################### + +for var in "$@" +do + case "$var" in + "-nr"| "--noreload" ) reload=false;; + "-d" | "--delmode" ) addmode=false;; + "-f" | "--force" ) force=true;; + "-q" | "--quiet" ) versbose=false;; + * ) HandleOther $var;; + esac +done + +PopBlacklistFile + +if $modifyHost || $force; then + echo "** Modifying Hosts File" + ModifyHostFile +else + if $versbose; then + echo "** No changes need to be made" + fi + exit 1 +fi + +if $reload; then + Reload +fi +>>>>>>> upstream/master diff --git a/automated install/webinterface.sh b/advanced/Scripts/updateDashboard.sh similarity index 100% rename from automated install/webinterface.sh rename to advanced/Scripts/updateDashboard.sh diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 43dce7a2..ca95ffbc 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -7,18 +7,55 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +<<<<<<< HEAD whiteList=/etc/pihole/whitelist.txt adList=/etc/pihole/gravity.list latentWhitelist=/etc/pihole/latentWhitelist.txt if [[ ! -f $whiteList ]];then touch $whiteList fi - +======= if [[ $# = 0 ]]; then - echo "Immediately whitelists one or more domains." + echo "Immediately whitelists one or more domains in the hosts file" + echo " " echo "Usage: whitelist.sh domain1 [domain2 ...]" + echo " " + echo "Options:" + echo " -d, --delmode Remove domains from the whitelist" + echo " -nr, --noreload Update Whitelist without refreshing dnsmasq" + echo " -f, --force Force updating of the hosts files, even if there are no changes" + echo " -q, --quiet output is less verbose" + exit 1 fi +#globals +whitelist=/etc/pihole/whitelist.txt +adList=/etc/pihole/gravity.list +reload=true +addmode=true +force=false +versbose=true +domList=() +domToRemoveList=() +>>>>>>> upstream/master + +piholeIPfile=/tmp/piholeIP +piholeIPv6file=/etc/pihole/.useIPv6 + +# 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 +IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') +piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') +piholeIP=${piholeIPCIDR%/*} + +modifyHost=false + + +if [[ -f $piholeIPv6file ]];then + # If the file exists, then the user previously chose to use IPv6 in the automated installer + piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') +fi + +<<<<<<< HEAD latentPattern="" boolA=false boolB=false @@ -44,4 +81,137 @@ if $boolA; then /usr/local/bin/gravity.sh else echo "No need to update Hosts list, given domains already in whitelist" +======= + +function HandleOther(){ + #check validity of domain + validDomain=$(echo $1 | perl -ne'print if /\b((?=[a-z0-9-]{1,63}\.)(xn--)?[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,63}\b/') + + if [ -z "$validDomain" ]; then + echo $1 is not a valid argument or domain name + else + domList=("${domList[@]}" $validDomain) + fi +} + +function PopWhitelistFile(){ + #check whitelist file exists, and if not, create it + if [[ ! -f $whitelist ]];then + touch $whitelist + fi + for dom in "${domList[@]}" + do + if $addmode; then + AddDomain $dom + else + RemoveDomain $dom + fi + done +} + +function AddDomain(){ +#| sed 's/\./\\./g' + bool=false + grep -Ex -q "$1" $whitelist || bool=true + if $bool; then + #domain not found in the whitelist file, add it! + if $versbose; then + echo "** Adding $1 to whitelist file" + fi + echo $1 >> $whitelist + modifyHost=true + else + if $versbose; then + echo "** $1 already whitelisted! No need to add" + fi + fi +} + +function RemoveDomain(){ + + bool=false + grep -Ex -q "$1" $whitelist || bool=true + if $bool; then + #Domain is not in the whitelist file, no need to Remove + if $versbose; then + echo "** $1 is NOT whitelisted! No need to remove" + fi + else + #Domain is in the whitelist file, add to a temporary array and remove from whitelist file + if $versbose; then + echo "** Un-whitelisting $dom..." + fi + domToRemoveList=("${domToRemoveList[@]}" $1) + modifyHost=true + fi +} + +function ModifyHostFile(){ + if $addmode; then + #remove domains in from hosts file + if [[ -r $whitelist ]];then + # Remove whitelist entries + numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l) + plural=; [[ "$numberOf" != "1" ]] && plural=s + echo "** Whitelisting a total of $numberOf domain${plural}..." + awk -F':' '{ print $1 }' $whitelist | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList + fi + else + #we need to add the removed domains to the hosts file + for rdom in "${domToRemoveList[@]}" + do + if [[ -n $piholeIPv6 ]];then + echo "**Blacklisting $rdom on IPv4 and IPv6" + echo $rdom | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList + else + echo "**Blacklisting $rdom on IPv4" + echo $rdom | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList + fi + echo $rdom| sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist + done + fi +} + +function Reload() { + # Reload hosts file + echo "** Refresh lists in dnsmasq..." + dnsmasqPid=$(pidof dnsmasq) + + if [[ $dnsmasqPid ]]; then + # service already running - reload config + sudo kill -HUP $dnsmasqPid + else + # service not running, start it up + sudo service dnsmasq start + fi +} + +################################################### + +for var in "$@" +do + case "$var" in + "-nr"| "--noreload" ) reload=false;; + "-d" | "--delmode" ) addmode=false;; + "-f" | "--force" ) force=true;; + "-q" | "--quiet" ) versbose=false;; + * ) HandleOther $var;; + esac +done + +PopWhitelistFile + +if $modifyHost || $force; then + echo "** Modifying Hosts File" + ModifyHostFile +else + if $versbose; then + echo "** No changes need to be made" + exit 1 + fi +fi + +if $reload; then + Reload +>>>>>>> upstream/master fi diff --git a/advanced/pihole.cron b/advanced/pihole.cron index 0a11a6d6..57f1c10c 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -1,22 +1,11 @@ -# /etc/crontab: system-wide crontab -# Unlike any other crontab you don't have to run the `crontab' -# command to install the new version when you edit this file -# and files in /etc/cron.d. These files also have username fields, -# that none of the other crontabs do. - -SHELL=/bin/sh -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin - -# m h dom mon dow user command -17 * * * * root cd / && run-parts --report /etc/cron.hourly -25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) -47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly ) -52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly ) - # Pi-hole: Update the ad sources once a week on Sunday at 01:59 # Download any updates from the ad lists 59 1 * * 7 root /usr/local/bin/gravity.sh +# Pi-hole: Update the Web interface shortly after gravity runs +# This should also update the version number if it is changed in the dashboard repo +30 2 * * 7 root /usr/local/bin/updateDashboard.sh + # Pi-hole: Parse the log file before it is flushed and save the stats to a database # This will be used for a historical view of your Pi-hole's performance #50 23 * * * root /usr/local/bin/dailyLog.sh diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 20570f22..f5cf2a23 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -17,6 +17,22 @@ # curl -L install.pi-hole.net | bash ######## VARIABLES ######### +# Must be root to install +if [[ $EUID -eq 0 ]];then + echo "You are root." +else + echo "sudo will be used for the install." + # Check if it is actually installed + # If it isn't, exit because the install cannot complete + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + else + echo "Please install sudo or run this as root." + exit 1 + fi +fi + + tmpLog=/tmp/pihole-install.log instalLogLoc=/etc/pihole/install.log @@ -41,13 +57,13 @@ backupLegacyPihole() { if [[ -f /etc/dnsmasq.d/adList.conf ]];then echo "Original Pi-hole detected. Initiating sub space transport" - sudo mkdir -p /etc/pihole/original/ - sudo mv /etc/dnsmasq.d/adList.conf /etc/pihole/original/adList.conf.$(date "+%Y-%m-%d") - sudo mv /etc/dnsmasq.conf /etc/pihole/original/dnsmasq.conf.$(date "+%Y-%m-%d") - sudo mv /etc/resolv.conf /etc/pihole/original/resolv.conf.$(date "+%Y-%m-%d") - sudo mv /etc/lighttpd/lighttpd.conf /etc/pihole/original/lighttpd.conf.$(date "+%Y-%m-%d") - sudo mv /var/www/pihole/index.html /etc/pihole/original/index.html.$(date "+%Y-%m-%d") - sudo mv /usr/local/bin/gravity.sh /etc/pihole/original/gravity.sh.$(date "+%Y-%m-%d") + $SUDO mkdir -p /etc/pihole/original/ + $SUDO mv /etc/dnsmasq.d/adList.conf /etc/pihole/original/adList.conf.$(date "+%Y-%m-%d") + $SUDO mv /etc/dnsmasq.conf /etc/pihole/original/dnsmasq.conf.$(date "+%Y-%m-%d") + $SUDO mv /etc/resolv.conf /etc/pihole/original/resolv.conf.$(date "+%Y-%m-%d") + $SUDO mv /etc/lighttpd/lighttpd.conf /etc/pihole/original/lighttpd.conf.$(date "+%Y-%m-%d") + $SUDO mv /var/www/pihole/index.html /etc/pihole/original/index.html.$(date "+%Y-%m-%d") + $SUDO mv /usr/local/bin/gravity.sh /etc/pihole/original/gravity.sh.$(date "+%Y-%m-%d") else : fi @@ -121,8 +137,8 @@ useIPv6dialog() { piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." $r $c -sudo mkdir -p /etc/pihole/ -sudo touch /etc/pihole/.useIPv6 +$SUDO mkdir -p /etc/pihole/ +$SUDO touch /etc/pihole/.useIPv6 } getStaticIPv4Settings() @@ -189,7 +205,7 @@ setDHCPCD(){ echo "interface $piholeInterface static ip_address=$IPv4addr static routers=$IPv4gw -static domain_name_servers=$IPv4gw" | sudo tee -a $dhcpcdFile >/dev/null +static domain_name_servers=$IPv4gw" | $SUDO tee -a $dhcpcdFile >/dev/null } setStaticIPv4(){ @@ -198,76 +214,86 @@ if grep -q $IPv4addr $dhcpcdFile; then : else setDHCPCD - sudo ip addr replace dev $piholeInterface $IPv4addr + $SUDO ip addr replace dev $piholeInterface $IPv4addr echo "Setting IP to $IPv4addr. You may need to restart after the install is complete." fi } installScripts(){ +<<<<<<< HEAD sudo curl -o /usr/local/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh sudo curl -o /usr/local/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh sudo curl -o /usr/local/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh sudo curl -o /usr/local/bin/blacklist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/blacklist.sh sudo curl -o /usr/local/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh sudo chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush}.sh +======= +$SUDO curl -o /usr/local/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh +$SUDO curl -o /usr/local/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh +$SUDO curl -o /usr/local/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh +$SUDO curl -o /usr/local/bin/blacklist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/blacklist.sh +$SUDO curl -o /usr/local/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh +$SUDO curl -o /usr/local/bin/updateDashboard.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/updateDashboard.sh +$SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh +>>>>>>> upstream/master } installConfigs(){ -sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig -sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig -sudo curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf -sudo curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf -sudo sed -i "s/@INT@/$piholeInterface/" /etc/dnsmasq.conf +$SUDO mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig +$SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig +$SUDO curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf +$SUDO curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf +$SUDO sed -i "s/@INT@/$piholeInterface/" /etc/dnsmasq.conf } stopServices(){ -sudo service dnsmasq stop || true -sudo service lighttpd stop || true +$SUDO service dnsmasq stop || true +$SUDO service lighttpd stop || true } installDependencies(){ -sudo apt-get update -sudo apt-get -y upgrade -sudo apt-get -y install dnsutils bc toilet -sudo apt-get -y install dnsmasq -sudo apt-get -y install lighttpd php5-common php5-cgi php5 +$SUDO apt-get update +$SUDO apt-get -y upgrade +$SUDO apt-get -y install dnsutils bc toilet figlet +$SUDO apt-get -y install dnsmasq +$SUDO apt-get -y install lighttpd php5-common php5-cgi php5 +$SUDO apt-get -y install git } installWebAdmin(){ -sudo wget https://github.com/jacobsalmela/AdminLTE/archive/master.zip -O /var/www/master.zip -sudo unzip -oq /var/www/master.zip -d /var/www/html/ -sudo mv /var/www/html/AdminLTE-master /var/www/html/admin -sudo rm /var/www/master.zip 2>/dev/null -sudo touch /var/log/pihole.log -sudo chmod 644 /var/log/pihole.log -sudo chown dnsmasq:root /var/log/pihole.log +$SUDO wget https://github.com/jacobsalmela/AdminLTE/archive/master.zip -O /var/www/master.zip +$SUDO unzip -oq /var/www/master.zip -d /var/www/html/ +$SUDO mv /var/www/html/AdminLTE-master /var/www/html/admin +$SUDO rm /var/www/master.zip 2>/dev/null +$SUDO touch /var/log/pihole.log +$SUDO chmod 644 /var/log/pihole.log +$SUDO chown dnsmasq:root /var/log/pihole.log } installPiholeWeb(){ -sudo mkdir /var/www/html/pihole -sudo mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig -sudo curl -o /var/www/html/pihole/index.html https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html +$SUDO mkdir /var/www/html/pihole +$SUDO mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig +$SUDO curl -o /var/www/html/pihole/index.html https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html } installCron(){ -sudo mv /etc/crontab /etc/crontab.orig -sudo curl -o /etc/crontab https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron +$SUDO curl -o /etc/cron.d/pihole https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron } installPihole() { installDependencies stopServices -sudo chown www-data:www-data /var/www/html -sudo chmod 775 /var/www/html -sudo usermod -a -G www-data pi -sudo lighty-enable-mod fastcgi fastcgi-php +$SUDO chown www-data:www-data /var/www/html +$SUDO chmod 775 /var/www/html +$SUDO usermod -a -G www-data pi +$SUDO lighty-enable-mod fastcgi fastcgi-php installScripts installConfigs installWebAdmin installPiholeWeb installCron -sudo /usr/local/bin/gravity.sh +$SUDO /usr/local/bin/gravity.sh } displayFinalMessage(){ @@ -318,9 +344,9 @@ fi installPihole | tee $tmpLog # Move the log file into /etc/pihole for storage -sudo mv $tmpLog $instalLogLoc +$SUDO mv $tmpLog $instalLogLoc displayFinalMessage -sudo service dnsmasq start -sudo service lighttpd start +$SUDO service dnsmasq start +$SUDO service lighttpd start diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 563d8d07..59eca67b 100644 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -8,20 +8,64 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. +# Must be root to uninstall +if [[ $EUID -eq 0 ]];then + echo "You are root." +else + echo "sudo will be used for the install." + # Check if it is actually installed + # If it isn't, exit because the unnstall cannot complete + if [[ $(dpkg-query -s sudo) ]];then + export SUDO="sudo" + else + echo "Please install sudo or run this as root." + exit 1 + fi +fi + ######### SCRIPT ########### -sudo apt-get -y remove --purge dnsutils bc toilet -sudo apt-get -y remove --purge dnsmasq -sudo apt-get -y remove --purge lighttpd php5-common php5-cgi php5 -sudo rm -rf /var/www/html -sudo rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig -sudo rm /etc/crontab -sudo mv /etc/crontab.orig /etc/crontab -sudo rm /etc/dnsmasq.conf -sudo rm -rf /etc/lighttpd/ -sudo rm /var/log/pihole.log -sudo rm /usr/local/bin/gravity.sh -sudo rm /usr/local/bin/chronometer.sh -sudo rm /usr/local/bin/whitelist.sh -sudo rm /usr/local/bin/piholeLogFlush.sh -sudo rm -rf /etc/pihole/ +$SUDO apt-get -y remove --purge dnsutils bc toilet +$SUDO apt-get -y remove --purge dnsmasq +$SUDO apt-get -y remove --purge lighttpd php5-common php5-cgi php5 + +# Only web directories/files that are created by pihole should be removed. +echo "Removing the Pi-hole Web server files..." +$SUDO rm -rf /var/www/html/admin +$SUDO rm -rf /var/www/html/pihole +$SUDO rm /var/www/html/index.lighttpd.orig + +# If the web directory is empty after removing these files, then the parent html folder can be removed. +if [[ ! "$(ls -A /var/www/html)" ]]; then + $SUDO rm -rf /var/www/html +fi + +echo "Removing dnsmasq config files..." +$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig + +# Attempt to preserve backwards compatibility with older versions +# to guarantee no additional changes were made to /etc/crontab after +# the installation of pihole, /etc/crontab.pihole should be permanently +# preserved. +if [[ -f /etc/crontab.orig ]]; then + echo "Initial Pi-hole cron detected. Restoring the default system cron..." + $SUDO mv /etc/crontab /etc/crontab.pihole + $SUDO mv /etc/crontab.orig /etc/crontab + $SUDO service cron restart +fi + +# Attempt to preserve backwards compatibility with older versions +if [[ -f /etc/cron.d/pihole ]];then + echo "Removing cron.d/pihole..." + $SUDO rm /etc/cron.d/pihole +fi + +echo "Removing config files and scripts..." +$SUDO rm /etc/dnsmasq.conf +$SUDO rm -rf /etc/lighttpd/ +$SUDO rm /var/log/pihole.log +$SUDO rm /usr/local/bin/gravity.sh +$SUDO rm /usr/local/bin/chronometer.sh +$SUDO rm /usr/local/bin/whitelist.sh +$SUDO rm /usr/local/bin/piholeLogFlush.sh +$SUDO rm -rf /etc/pihole/ diff --git a/gravity.sh b/gravity.sh index 5083bca5..40824a89 100755 --- a/gravity.sh +++ b/gravity.sh @@ -169,6 +169,7 @@ function gravity_Schwarzchild() { function gravity_Blacklist(){ # Append blacklist entries if they exist +<<<<<<< HEAD if [[ -r $blacklist ]];then numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) echo "** Blacklisting $numberOf domain(s)..." @@ -191,11 +192,18 @@ function gravity_Whitelist() { else rm $latentWhitelist 2>/dev/null fi +======= + blacklist.sh -f -nr -q +} +>>>>>>> upstream/master + +function gravity_Whitelist() { # Prevent our sources from being pulled into the hole - plural=; [[ "${#sources[@]}" != "1" ]] && plural=s + plural=; [[ "${sources[@]}" != "1" ]] && plural=s echo "** Whitelisting ${#sources[@]} ad list source${plural}..." +<<<<<<< HEAD for url in ${sources[@]} do echo "$url" | awk -F '/' '{print $3}' | sed 's/\./\\./g' >> $latentWhitelist @@ -203,6 +211,17 @@ function gravity_Whitelist() { #remove whitelist entries from gravity.list awk -F':' '{ print $1 }' $latentWhitelist | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList +======= + urls=() + for url in ${sources[@]} + do + tmp=$(echo "$url" | awk -F '/' '{print $3}') + urls=("${urls[@]}" $tmp) + done + + whitelist.sh -f -nr -q ${urls[@]} + +>>>>>>> upstream/master } @@ -259,7 +278,6 @@ function gravity_advanced() { function gravity_reload() { # Reload hosts file echo "** Refresh lists in dnsmasq..." - dnsmasqPid=$(pidof dnsmasq) if [[ $dnsmasqPid ]]; then @@ -275,9 +293,16 @@ function gravity_reload() { gravity_collapse gravity_spinup gravity_Schwarzchild +<<<<<<< HEAD gravity_Blacklist +======= +>>>>>>> upstream/master gravity_advanced gravity_hostFormat gravity_blackbody gravity_Whitelist +<<<<<<< HEAD +======= +gravity_Blacklist +>>>>>>> upstream/master gravity_reload