mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-23 21:30:17 +00:00
Merge branch 'ScriptCleanup'
Conflicts: README.md advanced/Scripts/blacklist.sh advanced/Scripts/whitelist.sh automated install/basic-install.sh gravity.sh
This commit is contained in:
commit
8ef4c12f97
8 changed files with 336 additions and 142 deletions
22
README.md
22
README.md
|
@ -1,14 +1,19 @@
|
|||
<<<<<<< HEAD
|
||||
# Automated Install
|
||||
##### Designed For Raspberry Pi A+, B, B+, 2, Zero (with an Ethernet adapter), and also works on most Debian based distros!
|
||||
=======
|
||||
# Automated Install
|
||||
##### Designed For Raspberry Pi A+, B, B+, 2, and Zero (with an Ethernet/Wi-Fi adapter)
|
||||
>>>>>>> ScriptCleanup
|
||||
|
||||
1. Install Raspbian on Raspberry Pi variants or a Debian based distribution on other hardware or virtual machines
|
||||
2. Run the command below
|
||||
|
||||
### ```curl -L install.pi-hole.net | bash```
|
||||
### ```curl -L https://install.pi-hole.net | bash```
|
||||
|
||||
#### Alternative Semi-Automated install ####
|
||||
```
|
||||
wget -O basic-install.sh install.pi-hole.net
|
||||
wget -O basic-install.sh https://install.pi-hole.net
|
||||
chmod +x basic-install.sh
|
||||
./basic-install.sh
|
||||
```
|
||||
|
@ -18,13 +23,20 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei
|
|||
## Pi-hole Is Free, But Powered By Your Donations
|
||||
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "Free, but powered by donations")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate")
|
||||
|
||||
## Catch us out on the net:
|
||||
Twitter: [@The_Pi_Hole](https://twitter.com/The_Pi_Hole)
|
||||
|
||||
reddit: [/r/pihole](https://www.reddit.com/r/pihole/)
|
||||
|
||||
## How Does It Work?
|
||||
**Watch the 60-second video below to get a quick overview**
|
||||
|
||||
[![Pi-hole exlplained](http://i.imgur.com/qNybJDX.png)](https://vimeo.com/135965232)
|
||||
|
||||
## Pi-hole Projects
|
||||
- [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html)
|
||||
- [x86 Docker container that runs Pi-hole](https://hub.docker.com/r/diginc/pi-hole/)
|
||||
- [Splunk: Pi-hole Visualizser](https://splunkbase.splunk.com/app/3023/)
|
||||
- [Pi-hole Chrome extension](https://chrome.google.com/webstore/detail/pi-hole-list-editor/hlnoeoejkllgkjbnnnhfolapllcnaglh) ([open source](https://github.com/packtloss/pihole-extension))
|
||||
- [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037)
|
||||
- [Sky-Hole](http://dlaa.me/blog/post/skyhole)
|
||||
|
@ -34,7 +46,7 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei
|
|||
- [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole)
|
||||
|
||||
## Coverage
|
||||
- [Splunk: Pi-hole Visualizser](https://splunkbase.splunk.com/app/3023/)
|
||||
- [Pi-hole on Adafruit's blog](https://blog.adafruit.com/2016/03/04/pi-hole-is-a-black-hole-for-internet-ads-piday-raspberrypi-raspberry_pi/)
|
||||
- [The Defrag Show - MSDN/Channel 9](https://channel9.msdn.com/Shows/The-Defrag-Show/Defrag-Endoscope-USB-Camera-The-Final-HoloLens-Vote-Adblock-Pi-and-more?WT.mc_id=dlvr_twitter_ch9#time=20m39s)
|
||||
- [MacObserver Podcast 585](http://www.macobserver.com/tmo/podcast/macgeekgab-585)
|
||||
- [Medium: Block All Ads For $53](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d)
|
||||
|
@ -67,6 +79,8 @@ The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashb
|
|||
|
||||
`http://192.168.1.x/admin/index.php`
|
||||
|
||||
![Pi-hole Advanced Stats Dashboard](http://i.imgur.com/rTlLYPh.png)
|
||||
|
||||
### API
|
||||
|
||||
A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON:
|
||||
|
@ -92,4 +106,4 @@ You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-
|
|||
- There is also an [FAQ section on pi-hole.net](http://pi-hole.net)
|
||||
|
||||
## Other Operating Systems
|
||||
This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install only works for a clean install of Raspiban right now since that is how the project originated.
|
||||
This script will work for other UNIX-like systems with some slight **modifications**. As long as you can install `dnsmasq` and a Webserver, it should work OK. The automated install is only for a clean install of a Debian based system, such as the Raspberry Pi.
|
||||
|
|
|
@ -25,6 +25,7 @@ https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt
|
|||
http://hosts-file.net/ad_servers.txt
|
||||
|
||||
# Mahakala list. Has been known to block legitimage domains including the entire .com range.
|
||||
# Warning: Due to the sheer size of this list, the web admin console will be unresponsive.
|
||||
#http://adblock.mahakala.is/
|
||||
|
||||
# ADZHOSTS list. Has been known to block legitimate domains
|
||||
|
|
|
@ -33,13 +33,11 @@ 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}')
|
||||
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')
|
||||
piholeIP=${piholeIPCIDR%/*}
|
||||
|
||||
modifyHost=false
|
||||
|
@ -53,11 +51,19 @@ fi
|
|||
|
||||
function HandleOther(){
|
||||
#check validity of domain
|
||||
<<<<<<< HEAD
|
||||
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
|
||||
=======
|
||||
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
|
||||
>>>>>>> ScriptCleanup
|
||||
domList=("${domList[@]}" $validDomain)
|
||||
fi
|
||||
}
|
||||
|
@ -68,11 +74,17 @@ function PopBlacklistFile(){
|
|||
touch $blacklist
|
||||
fi
|
||||
for dom in "${domList[@]}"
|
||||
<<<<<<< HEAD
|
||||
do
|
||||
if $addmode; then
|
||||
AddDomain $dom
|
||||
=======
|
||||
do
|
||||
if "$addmode"; then
|
||||
AddDomain "$dom"
|
||||
>>>>>>> ScriptCleanup
|
||||
else
|
||||
RemoveDomain $dom
|
||||
RemoveDomain "$dom"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -86,7 +98,7 @@ function AddDomain(){
|
|||
if $versbose; then
|
||||
echo -n "::: Adding $1 to blacklist file..."
|
||||
fi
|
||||
echo $1 >> $blacklist
|
||||
echo "$1" >> $blacklist
|
||||
modifyHost=true
|
||||
echo " done!"
|
||||
else
|
||||
|
@ -119,9 +131,10 @@ function ModifyHostFile(){
|
|||
if $addmode; then
|
||||
#add domains to the hosts file
|
||||
if [[ -r $blacklist ]];then
|
||||
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
||||
numberOf=$($blacklist | sed '/^\s*$/d' | wc -l)
|
||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||
echo ":::"
|
||||
<<<<<<< HEAD
|
||||
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
|
||||
|
@ -129,6 +142,15 @@ function ModifyHostFile(){
|
|||
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
||||
fi
|
||||
|
||||
=======
|
||||
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
$blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
|
||||
else
|
||||
$blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
|
||||
fi
|
||||
|
||||
>>>>>>> ScriptCleanup
|
||||
fi
|
||||
else
|
||||
|
||||
|
@ -138,10 +160,14 @@ function ModifyHostFile(){
|
|||
#we need to remove the domains from the blacklist file and the host file
|
||||
echo "::: $dom"
|
||||
echo -n "::: removing from HOSTS file..."
|
||||
<<<<<<< HEAD
|
||||
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
|
||||
>>>>>>> ScriptCleanup
|
||||
echo " done!"
|
||||
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!"
|
||||
done
|
||||
fi
|
||||
|
@ -157,7 +183,7 @@ function Reload() {
|
|||
|
||||
if [[ $dnsmasqPid ]]; then
|
||||
# service already running - reload config
|
||||
sudo kill -HUP $dnsmasqPid
|
||||
sudo kill -HUP "$dnsmasqPid"
|
||||
else
|
||||
# service not running, start it up
|
||||
sudo service dnsmasq start
|
||||
|
@ -173,8 +199,13 @@ do
|
|||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-f" | "--force" ) force=true;;
|
||||
<<<<<<< HEAD
|
||||
"-q" | "--quiet" ) versbose=false;;
|
||||
* ) HandleOther $var;;
|
||||
=======
|
||||
"-q" | "--quiet" ) versbose=false;;
|
||||
* ) HandleOther "$var";;
|
||||
>>>>>>> ScriptCleanup
|
||||
esac
|
||||
done
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ function CalcBlockedDomains(){
|
|||
|
||||
function CalcQueriesToday(){
|
||||
if [ -e "$piLog" ];then
|
||||
queriesToday=$(cat "$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l)
|
||||
queriesToday=$("$piLog" | grep "$today" | awk '/query/ {print $6}' | wc -l)
|
||||
else
|
||||
queriesToday="Err."
|
||||
fi
|
||||
|
@ -43,7 +43,7 @@ function CalcQueriesToday(){
|
|||
|
||||
function CalcblockedToday(){
|
||||
if [ -e "$piLog" ] && [ -e "$gravity" ];then
|
||||
blockedToday=$(cat $piLog | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l)
|
||||
blockedToday=$($piLog | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l)
|
||||
else
|
||||
blockedToday="Err."
|
||||
fi
|
||||
|
|
|
@ -33,12 +33,11 @@ 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}')
|
||||
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')
|
||||
piholeIP=${piholeIPCIDR%/*}
|
||||
|
||||
modifyHost=false
|
||||
|
@ -52,8 +51,13 @@ fi
|
|||
|
||||
function HandleOther(){
|
||||
#check validity of domain
|
||||
<<<<<<< HEAD
|
||||
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/')
|
||||
|
||||
>>>>>>> ScriptCleanup
|
||||
if [ -z "$validDomain" ]; then
|
||||
echo "::: $1 is not a valid argument or domain name"
|
||||
else
|
||||
|
@ -69,9 +73,9 @@ function PopWhitelistFile(){
|
|||
for dom in "${domList[@]}"
|
||||
do
|
||||
if $addmode; then
|
||||
AddDomain $dom
|
||||
AddDomain "$dom"
|
||||
else
|
||||
RemoveDomain $dom
|
||||
RemoveDomain "$dom"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -86,7 +90,7 @@ function AddDomain(){
|
|||
if $versbose; then
|
||||
echo -n "::: Adding $1 to whitelist.txt..."
|
||||
fi
|
||||
echo $1 >> $whitelist
|
||||
echo "$1" >> $whitelist
|
||||
modifyHost=true
|
||||
if $versbose; then
|
||||
echo " done!"
|
||||
|
@ -122,12 +126,12 @@ function ModifyHostFile(){
|
|||
#remove domains in from hosts file
|
||||
if [[ -r $whitelist ]];then
|
||||
# Remove whitelist entries
|
||||
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
||||
numberOf=$($whitelist | sed '/^\s*$/d' | wc -l)
|
||||
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||
echo ":::"
|
||||
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
|
||||
awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIP $line"; done > /etc/pihole/whitelist.tmp
|
||||
awk -F':' '{print $1}' $whitelist | while read line; do echo "$piholeIPv6 $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
|
||||
echo "l" >> /etc/pihole/whitelist.tmp
|
||||
grep -F -x -v -f /etc/pihole/whitelist.tmp /etc/pihole/gravity.list > /etc/pihole/gravity.tmp
|
||||
rm /etc/pihole/gravity.list
|
||||
|
@ -144,15 +148,15 @@ function ModifyHostFile(){
|
|||
do
|
||||
if [[ -n $piholeIPv6 ]];then
|
||||
echo -n "::: Un-whitelisting $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!"
|
||||
else
|
||||
echo -n "::: Un-whitelisting $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!"
|
||||
fi
|
||||
echo -n "::: Removing $rdom from whitelist.txt..."
|
||||
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!"
|
||||
done
|
||||
fi
|
||||
|
@ -166,7 +170,7 @@ function Reload() {
|
|||
|
||||
if [[ $dnsmasqPid ]]; then
|
||||
# service already running - reload config
|
||||
sudo kill -HUP $dnsmasqPid
|
||||
sudo kill -HUP "$dnsmasqPid"
|
||||
else
|
||||
# service not running, start it up
|
||||
sudo service dnsmasq start
|
||||
|
@ -182,8 +186,13 @@ do
|
|||
"-nr"| "--noreload" ) reload=false;;
|
||||
"-d" | "--delmode" ) addmode=false;;
|
||||
"-f" | "--force" ) force=true;;
|
||||
<<<<<<< HEAD
|
||||
"-q" | "--quiet" ) versbose=false;;
|
||||
* ) HandleOther $var;;
|
||||
=======
|
||||
"-q" | "--quiet" ) versbose=false;;
|
||||
* ) HandleOther "$var";;
|
||||
>>>>>>> ScriptCleanup
|
||||
esac
|
||||
done
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ c=$(( columns / 2 ))
|
|||
# Find IP used to route to outside world
|
||||
|
||||
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
|
||||
IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
|
||||
IPv4addr=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')
|
||||
IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}')
|
||||
|
||||
availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1)
|
||||
|
@ -63,28 +63,28 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ -d "/etc/pihole" ]; then
|
||||
# Likely an existing install
|
||||
upgrade=true
|
||||
else
|
||||
upgrade=false
|
||||
fi
|
||||
### Nate 3/26/2016 - Why are we declaring upgrade here? It isn't global (nor is it used anywhere else)
|
||||
# if [ -d "/etc/pihole" ]; then
|
||||
# # Likely an existing install
|
||||
# upgrade=true
|
||||
# else
|
||||
# upgrade=false
|
||||
# fi
|
||||
|
||||
####### FUNCTIONS ##########
|
||||
###All credit for the below function goes to http://fitnr.com/showing-a-bash-spinner.html
|
||||
spinner() {
|
||||
local pid=$1
|
||||
|
||||
spin='-\|/'
|
||||
i=0
|
||||
while $SUDO kill -0 $pid 2>/dev/null
|
||||
do
|
||||
i=$(( (i+1) %4 ))
|
||||
printf "\b${spin:$i:1}"
|
||||
sleep .1
|
||||
done
|
||||
printf "\b"
|
||||
spinner()
|
||||
{
|
||||
local pid=$1
|
||||
local delay=0.50
|
||||
local spinstr='|/-\'
|
||||
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
||||
local temp=${spinstr#?}
|
||||
printf " [%c] " "$spinstr"
|
||||
local spinstr=$temp${spinstr%"$temp"}
|
||||
sleep $delay
|
||||
printf "\b\b\b\b\b\b"
|
||||
done
|
||||
printf " \b\b\b\b"
|
||||
}
|
||||
|
||||
backupLegacyPihole() {
|
||||
|
@ -92,12 +92,17 @@ 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 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")"
|
||||
if [ ! -d /opt/pihole ]; then
|
||||
$SUDO mkdir /opt/pihole
|
||||
$SUDO chown "$USER":root /opt/pihole
|
||||
$SUDO chmod 1766 /opt/pihole
|
||||
fi
|
||||
$SUDO mv /opt/pihole/gravity.sh /etc/pihole/original/gravity.sh."$(date "+%Y-%m-%d")"
|
||||
else
|
||||
:
|
||||
fi
|
||||
|
@ -119,10 +124,17 @@ welcomeDialogs() {
|
|||
verifyFreeDiskSpace() {
|
||||
# 25MB is the minimum space needed (20MB install + 5MB one day of logs.)
|
||||
requiredFreeBytes=51200
|
||||
<<<<<<< HEAD
|
||||
|
||||
existingFreeBytes=`df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1`
|
||||
if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then
|
||||
existingFreeBytes=`df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1`
|
||||
=======
|
||||
|
||||
existingFreeBytes=$(df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1)
|
||||
if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then
|
||||
existingFreeBytes=$(df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1)
|
||||
>>>>>>> ScriptCleanup
|
||||
fi
|
||||
|
||||
if [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then
|
||||
|
@ -158,7 +170,7 @@ chooseInterface() {
|
|||
do
|
||||
piholeInterface=$desiredInterface
|
||||
echo "::: Using interface: $piholeInterface"
|
||||
echo ${piholeInterface} > /tmp/piholeINT
|
||||
echo "${piholeInterface}" > /tmp/piholeINT
|
||||
done
|
||||
else
|
||||
echo "::: Cancel selected, exiting...."
|
||||
|
@ -169,7 +181,7 @@ chooseInterface() {
|
|||
|
||||
cleanupIPv6() {
|
||||
# Removes IPv6 indicator file if we are not using IPv6
|
||||
if [ -f "/etc/pihole/.useIPv6" ] && [ ! $useIPv6 ]; then
|
||||
if [ -f "/etc/pihole/.useIPv6" ] && [ ! "$useIPv6" ]; then
|
||||
rm /etc/pihole/.useIPv6
|
||||
fi
|
||||
}
|
||||
|
@ -244,11 +256,11 @@ getStaticIPv4Settings() {
|
|||
until [[ $ipSettingsCorrect = True ]]
|
||||
do
|
||||
# Ask for the IPv4 address
|
||||
IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c $IPv4addr 3>&1 1>&2 2>&3)
|
||||
IPv4addr=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 address" --inputbox "Enter your desired IPv4 address" $r $c "$IPv4addr" 3>&1 1>&2 2>&3)
|
||||
if [[ $? = 0 ]];then
|
||||
echo "::: Your static IPv4 address: $IPv4addr"
|
||||
# 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
|
||||
echo "::: Your static IPv4 gateway: $IPv4gw"
|
||||
# Give the user a chance to review their settings before moving on
|
||||
|
@ -257,8 +269,8 @@ getStaticIPv4Settings() {
|
|||
Gateway: $IPv4gw" $r $c)then
|
||||
# If the settings are correct, then we need to set the piholeIP
|
||||
# Saving it to a temporary file us to retrieve it later when we run the gravity.sh script
|
||||
echo ${IPv4addr%/*} > /tmp/piholeIP
|
||||
echo $piholeInterface > /tmp/piholeINT
|
||||
echo "${IPv4addr%/*}" > /tmp/piholeIP
|
||||
echo "$piholeInterface" > /tmp/piholeINT
|
||||
# After that's done, the loop ends and we move on
|
||||
ipSettingsCorrect=True
|
||||
else
|
||||
|
@ -292,12 +304,12 @@ setDHCPCD() {
|
|||
|
||||
setStaticIPv4() {
|
||||
# Tries to set the IPv4 address
|
||||
if grep -q $IPv4addr $dhcpcdFile; then
|
||||
if grep -q "$IPv4addr" $dhcpcdFile; then
|
||||
# address already set, noop
|
||||
:
|
||||
else
|
||||
setDHCPCD
|
||||
$SUDO ip addr replace dev $piholeInterface $IPv4addr
|
||||
$SUDO ip addr replace dev "$piholeInterface" "$IPv4addr"
|
||||
echo ":::"
|
||||
echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
|
||||
echo ":::"
|
||||
|
@ -377,6 +389,7 @@ setDNS(){
|
|||
|
||||
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
|
||||
<<<<<<< HEAD
|
||||
piholeDNS1=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
|
||||
piholeDNS2=$(echo $piholeDNS | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
|
||||
|
||||
|
@ -385,6 +398,16 @@ setDNS(){
|
|||
fi
|
||||
|
||||
if ! valid_ip $piholeDNS2 && [ $piholeDNS2 ]; 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
|
||||
fi
|
||||
|
||||
if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then
|
||||
>>>>>>> ScriptCleanup
|
||||
piholeDNS2=$strInvalid
|
||||
fi
|
||||
|
||||
|
@ -392,6 +415,7 @@ setDNS(){
|
|||
echo "::: Cancel selected, exiting...."
|
||||
exit 1
|
||||
fi
|
||||
<<<<<<< HEAD
|
||||
|
||||
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
|
||||
|
@ -401,6 +425,17 @@ setDNS(){
|
|||
fi
|
||||
|
||||
if [[ $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
|
||||
|
||||
if [[ $piholeDNS1 == "$strInvalid" ]]; then
|
||||
piholeDNS1=""
|
||||
fi
|
||||
|
||||
if [[ $piholeDNS2 == "$strInvalid" ]]; then
|
||||
>>>>>>> ScriptCleanup
|
||||
piholeDNS2=""
|
||||
fi
|
||||
|
||||
|
@ -470,14 +505,23 @@ versionCheckDNSmasq(){
|
|||
installScripts() {
|
||||
# Install the scripts from /etc/.pihole to their various locations
|
||||
$SUDO echo ":::"
|
||||
$SUDO echo -n "::: Installing scripts..."
|
||||
$SUDO cp /etc/.pihole/gravity.sh /usr/local/bin/gravity.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/chronometer.sh /usr/local/bin/chronometer.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/whitelist.sh /usr/local/bin/whitelist.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /usr/local/bin/blacklist.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /usr/local/bin/piholeLogFlush.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /usr/local/bin/updateDashboard.sh
|
||||
$SUDO chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard}.sh
|
||||
$SUDO echo -n "::: Installing scripts to /opt/pihole..."
|
||||
if [ ! -d /opt/pihole ]; then
|
||||
$SUDO mkdir /opt/pihole
|
||||
$SUDO chown "$USER":root /opt/pihole
|
||||
$SUDO chmod 1766 /opt/pihole
|
||||
fi
|
||||
$SUDO cp /etc/.pihole/gravity.sh /opt/pihole/gravity.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/chronometer.sh /opt/pihole/chronometer.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/bin/blacklist.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /opt/pihole/piholeLogFlush.sh
|
||||
$SUDO cp /etc/.pihole/advanced/Scripts/updateDashboard.sh /opt/pihole/updateDashboard.sh
|
||||
$SUDO cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh
|
||||
$SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall}.sh
|
||||
for f in /opt/pihole/*; do
|
||||
$SUDO ln -s /opt/pihole/"$f" /usr/local/bin/"$f"
|
||||
done
|
||||
$SUDO echo " done."
|
||||
}
|
||||
|
||||
|
@ -486,7 +530,11 @@ installConfigs() {
|
|||
$SUDO echo ":::"
|
||||
$SUDO echo "::: Installing configs..."
|
||||
versionCheckDNSmasq
|
||||
$SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
|
||||
if [ ! -d "/etc/lighttpd" ]; then
|
||||
$SUDO mkdir /etc/lighttpd
|
||||
$SUDO chown "$USER":root /etc/lighttpd
|
||||
$SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
|
||||
fi
|
||||
$SUDO cp /etc/.pihole/advanced/lighttpd.conf /etc/lighttpd/lighttpd.conf
|
||||
}
|
||||
|
||||
|
@ -509,7 +557,7 @@ checkForDependencies() {
|
|||
# it needs to have been run at least once on new installs!
|
||||
|
||||
timestamp=$(stat -c %Y /var/cache/apt/)
|
||||
timestampAsDate=$(date -d @$timestamp "+%b %e")
|
||||
timestampAsDate=$(date -d @"$timestamp" "+%b %e")
|
||||
today=$(date "+%b %e")
|
||||
|
||||
if [ ! "$today" == "$timestampAsDate" ]; then
|
||||
|
@ -539,9 +587,9 @@ checkForDependencies() {
|
|||
do
|
||||
:
|
||||
echo -n "::: Checking for $i..."
|
||||
if [ $(dpkg-query -W -f='${Status}' $i 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
|
||||
if [ "$(dpkg-query -W -f='${Status}' "$i" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
|
||||
echo -n " Not found! Installing...."
|
||||
$SUDO apt-get -y -qq install $i > /dev/null & spinner $!
|
||||
$SUDO apt-get -y -qq install "$i" > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
else
|
||||
echo " already installed!"
|
||||
|
@ -582,7 +630,7 @@ is_repo() {
|
|||
make_repo() {
|
||||
# Remove the non-repod interface and clone the interface
|
||||
echo -n "::: Cloning $2 into $1..."
|
||||
$SUDO rm -rf $1
|
||||
$SUDO rm -rf "$1"
|
||||
$SUDO git clone -q "$2" "$1" > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
}
|
||||
|
@ -590,7 +638,7 @@ make_repo() {
|
|||
update_repo() {
|
||||
# Pull the latest commits
|
||||
echo -n "::: Updating repo in $1..."
|
||||
cd "$1"
|
||||
cd "$1" || exit
|
||||
$SUDO git pull -q > /dev/null & spinner $!
|
||||
echo " done!"
|
||||
}
|
||||
|
@ -618,9 +666,13 @@ installPiholeWeb() {
|
|||
$SUDO echo " Existing page detected, not overwriting"
|
||||
else
|
||||
$SUDO mkdir /var/www/html/pihole
|
||||
$SUDO mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig
|
||||
if [ -f /var/www/html/index.lighttpd.html ]; then
|
||||
$SUDO mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig
|
||||
else
|
||||
printf "\n:::\tNo default index.lighttpd.html file found... not backing up"
|
||||
fi
|
||||
$SUDO cp /etc/.pihole/advanced/index.html /var/www/html/pihole/index.html
|
||||
$SUDO echo " done!"
|
||||
$SUDO echo "::: done!"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -642,7 +694,6 @@ runGravity() {
|
|||
fi
|
||||
#Don't run as SUDO, this was causing issues
|
||||
echo "::: Running gravity.sh"
|
||||
echo ":::"
|
||||
|
||||
/usr/local/bin/gravity.sh
|
||||
}
|
||||
|
@ -677,6 +728,9 @@ installPihole() {
|
|||
stopServices
|
||||
setUser
|
||||
$SUDO mkdir -p /etc/pihole/
|
||||
if [ ! -d "/var/www/html" ]; then
|
||||
$SUDO mkdir /var/www/html
|
||||
fi
|
||||
$SUDO chown www-data:www-data /var/www/html
|
||||
$SUDO chmod 775 /var/www/html
|
||||
$SUDO usermod -a -G www-data pihole
|
||||
|
|
159
automated install/uninstall.sh
Normal file → Executable file
159
automated install/uninstall.sh
Normal file → Executable file
|
@ -12,62 +12,131 @@
|
|||
|
||||
# Must be root to uninstall
|
||||
if [[ $EUID -eq 0 ]];then
|
||||
echo "You are root."
|
||||
echo "::: You are root."
|
||||
else
|
||||
echo "sudo will be used for the install."
|
||||
echo "::: Sudo will be used for the uninstall."
|
||||
# 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."
|
||||
echo "::: Please install sudo or run this as root."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
spinner()
|
||||
{
|
||||
local pid=$1
|
||||
local delay=0.50
|
||||
local spinstr='|/-\'
|
||||
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
|
||||
local temp=${spinstr#?}
|
||||
printf " [%c] " "$spinstr"
|
||||
local spinstr=$temp${spinstr%"$temp"}
|
||||
sleep $delay
|
||||
printf "\b\b\b\b\b\b"
|
||||
done
|
||||
printf " \b\b\b\b"
|
||||
}
|
||||
|
||||
function removeAndPurge {
|
||||
# Purge dependencies
|
||||
echo ":::"
|
||||
# Nate 3/28/2016 - Removed `php5-cgi` and `php5` as they are removed with php5-common
|
||||
dependencies=( dnsutils bc toilet figlet dnsmasq lighttpd php5-common git curl unzip wget )
|
||||
for i in "${dependencies[@]}"; do
|
||||
if [ "$(dpkg-query -W --showformat='${Status}\n' "$i" 2> /dev/null | grep -c "ok installed")" -eq 1 ]; then
|
||||
while true; do
|
||||
read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn
|
||||
case $yn in
|
||||
[Yy]* ) printf ":::\tRemoving %s..." "$i"; $SUDO apt-get -y remove --purge "$i" &> /dev/null & spinner $!; printf "DONE!\n"; break;;
|
||||
[Nn]* ) printf ":::\tSkipping %s" "$i"; break;;
|
||||
* ) printf "::: You must answer yes or no!";;
|
||||
esac
|
||||
done
|
||||
else
|
||||
printf ":::\tPackage %s not installed... Not removing.\n" "$i"
|
||||
fi
|
||||
done
|
||||
|
||||
# Remove dependency config files
|
||||
echo "::: Removing dnsmasq config files..."
|
||||
$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null
|
||||
|
||||
# Take care of any additional package cleaning
|
||||
printf "::: Auto removing remaining dependencies"
|
||||
$SUDO apt-get -y autoremove &> /dev/null & spinner $!; printf "DONE!\n";
|
||||
printf "::: Auto cleaning remaining dependencies"
|
||||
$SUDO apt-get -y autoclean &> /dev/null & spinner $!; printf "DONE!\n";
|
||||
|
||||
# Call removeNoPurge to remove PiHole specific files
|
||||
removeNoPurge
|
||||
}
|
||||
|
||||
function removeNoPurge {
|
||||
echo ":::"
|
||||
# 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 &> /dev/null
|
||||
$SUDO rm -rf /var/www/html/pihole &> /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 [ -d "/var/www/html" ]; then
|
||||
if [[ ! "$(ls -A /var/www/html)" ]]; then
|
||||
$SUDO rm -rf /var/www/html &> /dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
# 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 &> /dev/null
|
||||
fi
|
||||
|
||||
echo "::: Removing config files and scripts..."
|
||||
$SUDO rm -rf /etc/lighttpd/ &> /dev/null
|
||||
$SUDO rm /var/log/pihole.log &> /dev/null
|
||||
$SUDO rm /usr/local/bin/gravity.sh &> /dev/null
|
||||
$SUDO rm /usr/local/bin/chronometer.sh &> /dev/null
|
||||
$SUDO rm /usr/local/bin/whitelist.sh &> /dev/null
|
||||
$SUDO rm /usr/local/bin/piholeLogFlush.sh &> /dev/null
|
||||
$SUDO rm /usr/local/bin/piholeDebug.sh &> /dev/null
|
||||
$SUDO rm /etc/dnsmasq.d/adList.conf &> /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 /opt/pihole/ &> /dev/null
|
||||
|
||||
echo ":::"
|
||||
printf "::: Finished removing PiHole from your system. Sorry to see you go!\n"
|
||||
printf "::: Reach out to us at https://github.com/pi-hole/pi-hole/issues if you need help\n"
|
||||
printf "::: Reinstall by simpling running\n:::\n:::\tcurl -L install.pi-hole.net | bash\n:::\n::: at any time!\n:::\n"
|
||||
printf "::: PLEASE RESET YOUR DNS ON YOUR ROUTER/CLIENTS TO RESTORE INTERNET CONNECTIVITY!/n"
|
||||
}
|
||||
|
||||
######### 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
|
||||
echo "::: Preparing to remove packages, be sure that each may be safely removed depending on your operating system."
|
||||
echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)"
|
||||
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
|
||||
case $yn in
|
||||
[Yy]* ) removeAndPurge; break;;
|
||||
|
||||
[Nn]* ) removeNoPurge; break;;
|
||||
esac
|
||||
done
|
||||
|
||||
# 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/
|
||||
|
|
54
gravity.sh
54
gravity.sh
|
@ -41,7 +41,7 @@ if [[ -f $piholeIPfile ]];then
|
|||
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
|
||||
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}')
|
||||
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')
|
||||
piholeIP=${piholeIPCIDR%/*}
|
||||
fi
|
||||
|
||||
|
@ -54,18 +54,19 @@ fi
|
|||
|
||||
|
||||
# Variables for various stages of downloading and formatting the list
|
||||
## Nate 3/26/2016 - Commented unused variables
|
||||
basename=pihole
|
||||
piholeDir=/etc/$basename
|
||||
adList=$piholeDir/gravity.list
|
||||
blacklist=$piholeDir/blacklist.txt
|
||||
whitelist=$piholeDir/whitelist.txt
|
||||
latentWhitelist=$piholeDir/latentWhitelist.txt
|
||||
#blacklist=$piholeDir/blacklist.txt
|
||||
#whitelist=$piholeDir/whitelist.txt
|
||||
#latentWhitelist=$piholeDir/latentWhitelist.txt
|
||||
justDomainsExtension=domains
|
||||
matterandlight=$basename.0.matterandlight.txt
|
||||
supernova=$basename.1.supernova.txt
|
||||
eventHorizon=$basename.2.eventHorizon.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
|
||||
if [[ -r $piholeDir/pihole.conf ]];then
|
||||
|
@ -76,19 +77,18 @@ fi
|
|||
|
||||
spinner(){
|
||||
local pid=$1
|
||||
local delay=0.001
|
||||
local spinstr='/-\|'
|
||||
|
||||
spin='-\|/'
|
||||
i=0
|
||||
while $SUDO kill -0 $pid 2>/dev/null
|
||||
while $SUDO kill -0 "$pid" 2>/dev/null
|
||||
do
|
||||
i=$(( (i+1) %4 ))
|
||||
printf "\b${spin:$i:1}"
|
||||
printf "\b%s" "${spin:$i:1}"
|
||||
sleep .1
|
||||
done
|
||||
printf "\b"
|
||||
}
|
||||
|
||||
###########################
|
||||
# collapse - begin formation of pihole
|
||||
function gravity_collapse() {
|
||||
|
@ -99,7 +99,7 @@ function gravity_collapse() {
|
|||
#custom file found, use this instead of default
|
||||
echo -n "::: Custom adList file detected. Reading..."
|
||||
sources=()
|
||||
while read -a line; do
|
||||
while read -r line; do
|
||||
#Do not read commented out or blank lines
|
||||
if [[ $line = \#* ]] || [[ ! $line ]]; then
|
||||
echo "" > /dev/null
|
||||
|
@ -112,7 +112,7 @@ function gravity_collapse() {
|
|||
#no custom file found, use defaults!
|
||||
echo -n "::: No custom adlist file detected, reading from default file..."
|
||||
sources=()
|
||||
while read -a line; do
|
||||
while read -r line; do
|
||||
#Do not read commented out or blank lines
|
||||
if [[ $line = \#* ]] || [[ ! $line ]]; then
|
||||
echo "" > /dev/null
|
||||
|
@ -146,7 +146,7 @@ function gravity_patternCheck() {
|
|||
# Some of the blocklists are copyright, they need to be downloaded
|
||||
# and stored as is. They can be processed for content after they
|
||||
# have been saved.
|
||||
cp $patternBuffer $saveLocation
|
||||
cp "$patternBuffer" "$saveLocation"
|
||||
echo " List updated, transport successful!"
|
||||
else
|
||||
# curl didn't download any host files, probably because of the date check
|
||||
|
@ -169,12 +169,18 @@ function gravity_transport() {
|
|||
fi
|
||||
|
||||
# Silently curl url
|
||||
<<<<<<< HEAD
|
||||
curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer
|
||||
# Check for list updates
|
||||
gravity_patternCheck $patternBuffer
|
||||
=======
|
||||
curl -s "$cmd_ext" "$heisenbergCompensator" -A "$agent" "$url" > "$patternBuffer"
|
||||
# Check for list updates
|
||||
gravity_patternCheck "$patternBuffer"
|
||||
>>>>>>> ScriptCleanup
|
||||
|
||||
# Cleanup
|
||||
rm -f $patternBuffer
|
||||
rm -f "$patternBuffer"
|
||||
}
|
||||
|
||||
# spinup - main gravity function
|
||||
|
@ -222,7 +228,7 @@ function gravity_Schwarzchild() {
|
|||
truncate -s 0 $piholeDir/$matterandlight & spinner $!
|
||||
for i in "${activeDomains[@]}"
|
||||
do
|
||||
cat $i |tr -d '\r' >> $piholeDir/$matterandlight
|
||||
"$i" |tr -d '\r' >> $piholeDir/$matterandlight
|
||||
done
|
||||
echo " done!"
|
||||
|
||||
|
@ -249,7 +255,7 @@ function gravity_Whitelist() {
|
|||
echo -n "::: Adding ${#sources[@]} ad list source${plural} to the whitelist..."
|
||||
|
||||
urls=()
|
||||
for url in ${sources[@]}
|
||||
for url in "${sources[@]}"
|
||||
do
|
||||
tmp=$(echo "$url" | awk -F '/' '{print $3}')
|
||||
urls=("${urls[@]}" $tmp)
|
||||
|
@ -257,8 +263,13 @@ function gravity_Whitelist() {
|
|||
echo " done!"
|
||||
|
||||
echo -n "::: Running whitelist script to update HOSTS file...."
|
||||
<<<<<<< HEAD
|
||||
$whitelistScript -f -nr -q ${urls[@]} > /dev/null & spinner $!
|
||||
|
||||
=======
|
||||
$whitelistScript -f -nr -q "${urls[@]}" > /dev/null & spinner $!
|
||||
|
||||
>>>>>>> ScriptCleanup
|
||||
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
|
||||
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
|
||||
echo " $numWhitelisted domain${plural} whitelisted!"
|
||||
|
@ -283,13 +294,18 @@ function gravity_hostFormat() {
|
|||
if [[ -n $piholeIPv6 ]];then
|
||||
#Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain!
|
||||
echo -e "$piholeIP Pi-Hole.IsWorking.OK \n$piholeIPv6 Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc
|
||||
<<<<<<< HEAD
|
||||
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc
|
||||
|
||||
=======
|
||||
$piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc
|
||||
|
||||
>>>>>>> ScriptCleanup
|
||||
else
|
||||
# Otherwise, just create gravity.list as normal using IPv4
|
||||
#Add dummy domain Pi-Hole.IsWorking.OK to the top of gravity.list to make ping result return a friendlier looking domain!
|
||||
echo -e "$piholeIP Pi-Hole.IsWorking.OK" > $piholeDir/$accretionDisc
|
||||
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc
|
||||
$piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc
|
||||
fi
|
||||
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
||||
cp $piholeDir/$accretionDisc $adList
|
||||
|
@ -301,10 +317,10 @@ function gravity_blackbody() {
|
|||
for file in $piholeDir/*.$justDomainsExtension
|
||||
do
|
||||
# If list is in active array then leave it (noop) else rm the list
|
||||
if [[ " ${activeDomains[@]} " =~ " ${file} " ]]; then
|
||||
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
|
||||
:
|
||||
else
|
||||
rm -f $file
|
||||
rm -f "$file"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -343,7 +359,7 @@ function gravity_reload() {
|
|||
|
||||
if [[ $dnsmasqPid ]]; then
|
||||
# service already running - reload config
|
||||
$SUDO kill -HUP $dnsmasqPid & spinner $!
|
||||
$SUDO kill -HUP "$dnsmasqPid" & spinner $!
|
||||
else
|
||||
# service not running, start it up
|
||||
$SUDO service dnsmasq start & spinner $!
|
||||
|
|
Loading…
Reference in a new issue