mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-24 07:03:43 +00:00
Merge remote-tracking branch 'refs/remotes/jacobsalmela/master' into patch-1
Conflicts: automated install/basic-install.sh gravity.sh
This commit is contained in:
commit
c4c304d4b2
5 changed files with 259 additions and 142 deletions
|
@ -63,5 +63,6 @@ This script will work for other UNIX-like systems with some slight **modificatio
|
||||||
|
|
||||||
### Examples Of The Pi-hole On Other Operating Systems
|
### Examples Of The Pi-hole On Other Operating Systems
|
||||||
- [Sky-Hole](http://dlaa.me/blog/post/skyhole)
|
- [Sky-Hole](http://dlaa.me/blog/post/skyhole)
|
||||||
|
- [Pi-hole in the Cloud!](http://blog.codybunch.com/2015/07/28/Pi-Hole-in-the-cloud/)
|
||||||
|
|
||||||
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "AdminLTE Presentation")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate")
|
[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "AdminLTE Presentation")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate")
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
whitelist=/etc/pihole/whitelist.txt
|
||||||
|
adList=/etc/pihole/gravity.list
|
||||||
|
if [[ ! -f $whitelist ]];then
|
||||||
|
touch $whitelist
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $# = 0 ]; then
|
if [[ $# = 0 ]]; then
|
||||||
echo "Immediately whitelists one or more domains."
|
echo "Immediately whitelists one or more domains."
|
||||||
echo "Usage: whitelist.sh domain1 [domain2 ...]"
|
echo "Usage: whitelist.sh domain1 [domain2 ...]"
|
||||||
fi
|
fi
|
||||||
|
@ -15,19 +20,19 @@ do
|
||||||
# Construct basic pattern to match domain name.
|
# Construct basic pattern to match domain name.
|
||||||
basicpattern=$(echo $var | awk -F '[# \t]' 'NF>0&&$1!="" {print ""$1""}' | sed 's/\./\\./g')
|
basicpattern=$(echo $var | awk -F '[# \t]' 'NF>0&&$1!="" {print ""$1""}' | sed 's/\./\\./g')
|
||||||
|
|
||||||
if [ "$basicpattern" != "" ]; then
|
if [[ "$basicpattern" != "" ]]; then
|
||||||
# Add to the combination pattern that will be used below
|
# Add to the combination pattern that will be used below
|
||||||
if [ "$combopattern" != "" ]; then combopattern="$combopattern|"; fi
|
if [[ "$combopattern" != "" ]]; then combopattern="$combopattern|"; fi
|
||||||
combopattern="$combopattern$basicpattern"
|
combopattern="$combopattern$basicpattern"
|
||||||
|
|
||||||
# Also add the domain to the whitelist but only if it's not already present
|
# Also add the domain to the whitelist but only if it's not already present
|
||||||
grep -E -q "^$basicpattern$" /etc/pihole/whitelist.txt \
|
grep -E -q "^$basicpattern$" $whitelist \
|
||||||
|| echo "$var" >> /etc/pihole/whitelist.txt
|
|| echo "$var" >> $whitelist
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Now report on and remove matched domains
|
# Now report on and remove matched domains
|
||||||
if [ "$combopattern" != "" ]; then
|
if [[ "$combopattern" != "" ]]; then
|
||||||
echo "Modifying hosts file..."
|
echo "Modifying hosts file..."
|
||||||
|
|
||||||
# Construct pattern to match entry in hosts file.
|
# Construct pattern to match entry in hosts file.
|
||||||
|
@ -35,8 +40,8 @@ if [ "$combopattern" != "" ]; then
|
||||||
pattern=$(echo $combopattern | awk -F '[# \t]' '{printf "%s", "^(([0-9]+\.){3}[0-9]+ +)+("$1")$"}')
|
pattern=$(echo $combopattern | awk -F '[# \t]' '{printf "%s", "^(([0-9]+\.){3}[0-9]+ +)+("$1")$"}')
|
||||||
|
|
||||||
# Output what will be removed and then actually remove
|
# Output what will be removed and then actually remove
|
||||||
sed -r -n 's/'"$pattern"'/ Removed: \3/p' /etc/pihole/gravity.list
|
sed -r -n 's/'"$pattern"'/ Removed: \3/p' $adList
|
||||||
sed -r -i '/'"$pattern"'/d' /etc/pihole/gravity.list
|
sed -r -i '/'"$pattern"'/d' $adList
|
||||||
|
|
||||||
echo "** $# domain(s) whitelisted."
|
echo "** $# domain(s) whitelisted."
|
||||||
# Force dnsmasq to reload /etc/pihole/gravity.list
|
# Force dnsmasq to reload /etc/pihole/gravity.list
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
# Pi-hole: A black hole for Internet advertisements
|
# Pi-hole: A black hole for Internet advertisements
|
||||||
# by Jacob Salmela
|
# by Jacob Salmela
|
||||||
# Network-wide ad blocking via your Raspberry Pi
|
# Network-wide ad blocking via your Raspberry Pi
|
||||||
|
@ -24,9 +24,11 @@ columns=$(stty -a | tr \; \\012 | egrep 'columns' | cut -d' ' -f3)
|
||||||
r=$(( rows / 2 ))
|
r=$(( rows / 2 ))
|
||||||
c=$(( columns / 2 ))
|
c=$(( columns / 2 ))
|
||||||
|
|
||||||
IPv4addr=$(ip -4 addr show | awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/); ip = substr($0,RSTART,RLENGTH); print ip}' | sed '/^\s*$/d' | grep -v "127.0.0.1")
|
# Find IP used to route to outside world
|
||||||
IPv4mask=$(ifconfig | awk -F':' '/inet addr/ && !/127.0.0.1/ {print $4}')
|
IPv4info=$(ip route get 8.8.8.8)
|
||||||
IPv4gw=$(ip route show | awk '/default\ via/ {print $3}')
|
IPv4dev=$(echo $IPv4info| awk '{print $5}')
|
||||||
|
IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}')
|
||||||
|
IPv4gw=$(echo $IPv4info | awk '{print $3}')
|
||||||
|
|
||||||
# IPv6 support to be added later
|
# IPv6 support to be added later
|
||||||
#IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1)
|
#IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1)
|
||||||
|
@ -195,7 +197,6 @@ getStaticIPv4Settings()
|
||||||
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
|
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
|
||||||
|
|
||||||
IP address: $IPv4addr
|
IP address: $IPv4addr
|
||||||
Subnet mask: $IPv4mask
|
|
||||||
Gateway: $IPv4gw" $r $c) then
|
Gateway: $IPv4gw" $r $c) then
|
||||||
# If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict.
|
# If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict.
|
||||||
whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that.
|
whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict" "It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that.
|
||||||
|
@ -205,8 +206,6 @@ if (whiptail --backtitle "Calibrating network interface" --title "Static IP Addr
|
||||||
It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." $r $c
|
It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address." $r $c
|
||||||
# Nothing else to do since the variables are already set above
|
# Nothing else to do since the variables are already set above
|
||||||
else
|
else
|
||||||
# Since a custom address will be used, restart at the end of the script to apply the new changes
|
|
||||||
rebootNeeded=true
|
|
||||||
# Otherwise, we need to ask the user to input their desired settings.
|
# Otherwise, we need to ask the user to input their desired settings.
|
||||||
# Start by getting the IPv4 address (pre-filling it with info gathered from DHCP)
|
# Start by getting the IPv4 address (pre-filling it with info gathered from DHCP)
|
||||||
# Start a loop to let the user enter their information with the chance to go back and edit it if necessary
|
# Start a loop to let the user enter their information with the chance to go back and edit it if necessary
|
||||||
|
@ -216,10 +215,6 @@ else
|
||||||
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
|
if [[ $? = 0 ]];then
|
||||||
echo "Your static IPv4 address: $IPv4addr"
|
echo "Your static IPv4 address: $IPv4addr"
|
||||||
# Ask for the subnet mask
|
|
||||||
IPv4mask=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 netmask" --inputbox "Enter your desired IPv4 subnet mask" $r $c $IPv4mask 3>&1 1>&2 2>&3)
|
|
||||||
if [[ $? = 0 ]];then
|
|
||||||
echo "Your static IPv4 netmask: $IPv4mask"
|
|
||||||
# Ask for the gateway
|
# Ask for the gateway
|
||||||
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c $IPv4gw 3>&1 1>&2 2>&3)
|
IPv4gw=$(whiptail --backtitle "Calibrating network interface" --title "IPv4 gateway (router)" --inputbox "Enter your desired IPv4 default gateway" $r $c $IPv4gw 3>&1 1>&2 2>&3)
|
||||||
if [[ $? = 0 ]];then
|
if [[ $? = 0 ]];then
|
||||||
|
@ -227,11 +222,10 @@ else
|
||||||
# Give the user a chance to review their settings before moving on
|
# Give the user a chance to review their settings before moving on
|
||||||
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
|
if (whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
|
||||||
IP address: $IPv4addr
|
IP address: $IPv4addr
|
||||||
Subnet mask: $IPv4mask
|
|
||||||
Gateway: $IPv4gw" $r $c)then
|
Gateway: $IPv4gw" $r $c)then
|
||||||
# If the settings are correct, then we need to set the piholeIP
|
# 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
|
# Saving it to a temporary file us to retrieve it later when we run the gravity.sh script
|
||||||
echo $IPv4addr > /tmp/piholeIP
|
echo ${IPv4addr%/*} > /tmp/piholeIP
|
||||||
# After that's done, the loop ends and we move on
|
# After that's done, the loop ends and we move on
|
||||||
ipSettingsCorrect=True
|
ipSettingsCorrect=True
|
||||||
else
|
else
|
||||||
|
@ -244,12 +238,6 @@ else
|
||||||
echo "User canceled."
|
echo "User canceled."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Cancelling subnet mask settings window
|
|
||||||
ipSettingsCorrect=False
|
|
||||||
echo "User canceled."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# Cancelling IPv4 settings window
|
# Cancelling IPv4 settings window
|
||||||
ipSettingsCorrect=False
|
ipSettingsCorrect=False
|
||||||
|
@ -266,9 +254,10 @@ setStaticIPv4()
|
||||||
{
|
{
|
||||||
# Append these lines to /etc/dhcpcd.conf to enable a static IP
|
# Append these lines to /etc/dhcpcd.conf to enable a static IP
|
||||||
echo "interface $piholeInterface
|
echo "interface $piholeInterface
|
||||||
static ip_address=$IPv4addr/24
|
static ip_address=$IPv4addr
|
||||||
static routers=$IPv4gw
|
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
|
||||||
|
sudo ip addr replace dev $piholeInterface $IPv4addr
|
||||||
}
|
}
|
||||||
|
|
||||||
installPihole()
|
installPihole()
|
||||||
|
@ -358,10 +347,11 @@ sudo mv $tmpLog $instalLogLoc
|
||||||
|
|
||||||
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using this IP: $IPv4addr.
|
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!" "Configure your devices to use the Pi-hole as their DNS server using this IP: $IPv4addr.
|
||||||
|
|
||||||
If you didn't use DHCP settings as your new static address, the Pi will restart after this dialog. If you are using SSH, you may need to reconnect using the IP address above.
|
If you set a new IP address, it should work fine, but you may want to reboot the Pi at some point.
|
||||||
|
|
||||||
The install log is in /etc/pihole." $r $c
|
The install log is in /etc/pihole." $r $c
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
# If a custom address was set, restart
|
# If a custom address was set, restart
|
||||||
if [[ "$rebootNeeded" = true ]];then
|
if [[ "$rebootNeeded" = true ]];then
|
||||||
# Restart to apply the new static IP address
|
# Restart to apply the new static IP address
|
||||||
|
@ -372,3 +362,7 @@ else
|
||||||
sudo service lighttpd start
|
sudo service lighttpd start
|
||||||
fi
|
fi
|
||||||
>>>>>>> refs/remotes/jacobsalmela/master
|
>>>>>>> refs/remotes/jacobsalmela/master
|
||||||
|
=======
|
||||||
|
sudo service dnsmasq start
|
||||||
|
sudo service lighttpd start
|
||||||
|
>>>>>>> refs/remotes/jacobsalmela/master
|
||||||
|
|
19
automated install/uninstall.sh
Normal file
19
automated install/uninstall.sh
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Completely uninstalls the Pi-hole
|
||||||
|
|
||||||
|
######### 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/
|
284
gravity.sh
284
gravity.sh
|
@ -1,6 +1,10 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
# Pi-hole: A black hole for Internet advertisements
|
||||||
|
# (c) 2015 by Jacob Salmela GPL 2.0
|
||||||
|
# Network-wide ad blocking via your Raspberry Pi
|
||||||
# http://pi-hole.net
|
# http://pi-hole.net
|
||||||
# Compiles a list of ad-serving domains by downloading them from multiple sources
|
# Compiles a list of ad-serving domains by downloading them from multiple sources
|
||||||
|
|
||||||
piholeIPfile=/tmp/piholeIP
|
piholeIPfile=/tmp/piholeIP
|
||||||
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
|
||||||
|
@ -8,7 +12,9 @@ if [[ -f $piholeIPfile ]];then
|
||||||
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
|
||||||
piholeIP=$(ip -4 addr show | awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/); ip = substr($0,RSTART,RLENGTH); print ip}' | sed '/^\s*$/d' | grep -v "127.0.0.1")
|
IPv4dev=$(ip route get 8.8.8.8 | awk '{print $5}')
|
||||||
|
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}')
|
||||||
|
piholeIP=${piholeIPCIDR%/*}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Checks if the script is being run as root and sets sudo accordingly
|
#Checks if the script is being run as root and sets sudo accordingly
|
||||||
|
@ -22,7 +28,8 @@ exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ad-list sources--one per line in single quotes
|
# Ad-list sources--one per line in single quotes
|
||||||
# The mahakala source is commented out due to many users having issues with it blocking legitimate domains. Uncomment at your own risk
|
# The mahakala source is commented out due to many users having issues with it blocking legitimate domains.
|
||||||
|
# Uncomment at your own risk
|
||||||
sources=('https://adaway.org/hosts.txt'
|
sources=('https://adaway.org/hosts.txt'
|
||||||
'http://adblock.gjtech.net/?format=unix-hosts'
|
'http://adblock.gjtech.net/?format=unix-hosts'
|
||||||
#'http://adblock.mahakala.is/'
|
#'http://adblock.mahakala.is/'
|
||||||
|
@ -33,23 +40,24 @@ sources=('https://adaway.org/hosts.txt'
|
||||||
'http://winhelp2002.mvps.org/hosts.txt')
|
'http://winhelp2002.mvps.org/hosts.txt')
|
||||||
|
|
||||||
# Variables for various stages of downloading and formatting the list
|
# Variables for various stages of downloading and formatting the list
|
||||||
adList=/etc/pihole/gravity.list
|
basename=pihole
|
||||||
origin=/etc/pihole
|
piholeDir=/etc/$basename
|
||||||
piholeDir=/etc/pihole
|
adList=$piholeDir/gravity.list
|
||||||
justDomainsExtension=domains
|
|
||||||
matter=pihole.0.matter.txt
|
|
||||||
andLight=pihole.1.andLight.txt
|
|
||||||
supernova=pihole.2.supernova.txt
|
|
||||||
eventHorizon=pihole.3.eventHorizon.txt
|
|
||||||
accretionDisc=pihole.4.accretionDisc.txt
|
|
||||||
eyeOfTheNeedle=pihole.5.wormhole.txt
|
|
||||||
blacklist=$piholeDir/blacklist.txt
|
blacklist=$piholeDir/blacklist.txt
|
||||||
whitelist=$piholeDir/whitelist.txt
|
whitelist=$piholeDir/whitelist.txt
|
||||||
latentWhitelist=$origin/latentWhitelist.txt
|
latentWhitelist=$piholeDir/latentWhitelist.txt
|
||||||
|
justDomainsExtension=domains
|
||||||
|
matter=$basename.0.matter.txt
|
||||||
|
andLight=$basename.1.andLight.txt
|
||||||
|
supernova=$basename.2.supernova.txt
|
||||||
|
eventHorizon=$basename.3.eventHorizon.txt
|
||||||
|
accretionDisc=$basename.4.accretionDisc.txt
|
||||||
|
eyeOfTheNeedle=$basename.5.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..."
|
||||||
|
<<<<<<< HEAD
|
||||||
. $piholeDir/pihole.conf
|
. $piholeDir/pihole.conf
|
||||||
fi
|
fi
|
||||||
echo "** Neutrino emissions detected..."
|
echo "** Neutrino emissions detected..."
|
||||||
|
@ -60,100 +68,129 @@ if [[ -d $piholeDir ]];then
|
||||||
else
|
else
|
||||||
echo "** Creating pihole directory..."
|
echo "** Creating pihole directory..."
|
||||||
$SUDO mkdir $piholeDir
|
$SUDO mkdir $piholeDir
|
||||||
|
=======
|
||||||
|
. $piholeDir/pihole.conf
|
||||||
|
>>>>>>> refs/remotes/jacobsalmela/master
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and blank lines
|
###########################
|
||||||
for ((i = 0; i < "${#sources[@]}"; i++))
|
# collapse - begin formation of pihole
|
||||||
do
|
function gravity_collapse() {
|
||||||
|
echo "** Neutrino emissions detected..."
|
||||||
|
|
||||||
|
# Create the pihole resource directory if it doesn't exist. Future files will be stored here
|
||||||
|
if [[ -d $piholeDir ]];then
|
||||||
|
# Temporary hack to allow non-root access to pihole directory
|
||||||
|
# Will update later, needed for existing installs, new installs should
|
||||||
|
# create this directory as non-root
|
||||||
|
sudo chmod 777 $piholeDir
|
||||||
|
find "$piholeDir" -type f -exec sudo chmod 666 {} \;
|
||||||
|
else
|
||||||
|
echo "** Creating pihole directory..."
|
||||||
|
mkdir $piholeDir
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# patternCheck - check to see if curl downloaded any new files.
|
||||||
|
function gravity_patternCheck() {
|
||||||
|
patternBuffer=$1
|
||||||
|
# check if the patternbuffer is a non-zero length file
|
||||||
|
if [[ -s "$patternBuffer" ]];then
|
||||||
|
# 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
|
||||||
|
echo "List updated, transport successful..."
|
||||||
|
else
|
||||||
|
# curl didn't download any host files, probably because of the date check
|
||||||
|
echo "No changes detected, transport skipped..."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# transport - curl the specified url with any needed command extentions
|
||||||
|
function gravity_transport() {
|
||||||
|
url=$1
|
||||||
|
cmd_ext=$2
|
||||||
|
agent=$3
|
||||||
|
|
||||||
|
# tmp file, so we don't have to store the (long!) lists in RAM
|
||||||
|
patternBuffer=$(mktemp)
|
||||||
|
heisenbergCompensator=""
|
||||||
|
if [[ -r $saveLocation ]]; then
|
||||||
|
# if domain has been saved, add file for date check to only download newer
|
||||||
|
heisenbergCompensator="-z $saveLocation"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Silently curl url
|
||||||
|
curl -s $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer
|
||||||
|
# Check for list updates
|
||||||
|
gravity_patternCheck $patternBuffer
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -f $patternBuffer
|
||||||
|
}
|
||||||
|
|
||||||
|
# spinup - main gravity function
|
||||||
|
function gravity_spinup() {
|
||||||
|
|
||||||
|
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and # blank lines
|
||||||
|
for ((i = 0; i < "${#sources[@]}"; i++))
|
||||||
|
do
|
||||||
url=${sources[$i]}
|
url=${sources[$i]}
|
||||||
# Get just the domain from the URL
|
# Get just the domain from the URL
|
||||||
domain=$(echo "$url" | cut -d'/' -f3)
|
domain=$(echo "$url" | cut -d'/' -f3)
|
||||||
|
|
||||||
# Save the file as list.#.domain
|
# Save the file as list.#.domain
|
||||||
saveLocation=$origin/list.$i.$domain.$justDomainsExtension
|
saveLocation=$piholeDir/list.$i.$domain.$justDomainsExtension
|
||||||
|
activeDomains[$i]=$saveLocation
|
||||||
|
|
||||||
agent="Mozilla/10.0"
|
agent="Mozilla/10.0"
|
||||||
|
|
||||||
echo -n "Getting $domain list... "
|
echo -n " Getting $domain list: "
|
||||||
|
|
||||||
# Use a case statement to download lists that need special cURL commands
|
# Use a case statement to download lists that need special cURL commands
|
||||||
# to complete properly and reset the user agent when required
|
# to complete properly and reset the user agent when required
|
||||||
case "$domain" in
|
case "$domain" in
|
||||||
"adblock.mahakala.is")
|
"adblock.mahakala.is")
|
||||||
agent='Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0'
|
agent='Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0'
|
||||||
cmd="curl -e http://forum.xda-developers.com/"
|
cmd_ext="-e http://forum.xda-developers.com/"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"pgl.yoyo.org")
|
"pgl.yoyo.org")
|
||||||
cmd="curl -d mimetype=plaintext -d hostformat=hosts"
|
cmd_ext="-d mimetype=plaintext -d hostformat=hosts"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# Default is a simple curl request
|
# Default is a simple request
|
||||||
*) cmd="curl"
|
*) cmd_ext=""
|
||||||
esac
|
esac
|
||||||
|
gravity_transport $url $cmd_ext $agent
|
||||||
# tmp file, so we don't have to store the (long!) lists in RAM
|
done
|
||||||
patternBuffer=$(mktemp)
|
|
||||||
heisenbergCompensator=""
|
|
||||||
if [[ -r $saveLocation ]]; then
|
|
||||||
heisenbergCompensator="-z $saveLocation"
|
|
||||||
fi
|
|
||||||
CMD="$cmd -s $heisenbergCompensator -A '$agent' $url > $patternBuffer"
|
|
||||||
$cmd -s $heisenbergCompensator -A "$agent" $url > $patternBuffer
|
|
||||||
|
|
||||||
|
|
||||||
if [[ -s "$patternBuffer" ]];then
|
|
||||||
# Remove comments and print only the domain name
|
|
||||||
# Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious
|
|
||||||
# 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
|
|
||||||
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $patternBuffer | \
|
|
||||||
sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $saveLocation
|
|
||||||
echo "Done."
|
|
||||||
else
|
|
||||||
echo "Skipping pattern because transporter logic detected no changes..."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Cleanup
|
|
||||||
rm -f $patternBuffer
|
|
||||||
done
|
|
||||||
|
|
||||||
# Find all files with the .domains extension and compile them into one file and remove CRs
|
|
||||||
echo "** Aggregating list of domains..."
|
|
||||||
find $origin/ -type f -name "*.$justDomainsExtension" -exec cat {} \; | tr -d '\r' > $origin/$matter
|
|
||||||
|
|
||||||
# Append blacklist entries if they exist
|
|
||||||
if [[ -r $blacklist ]];then
|
|
||||||
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
|
||||||
echo "** Blacklisting $numberOf domain(s)..."
|
|
||||||
cat $blacklist >> $origin/$matter
|
|
||||||
fi
|
|
||||||
|
|
||||||
###########################
|
|
||||||
function gravity_advanced() {
|
|
||||||
|
|
||||||
numberOf=$(wc -l < $origin/$andLight)
|
|
||||||
echo "** $numberOf domains being pulled in by gravity..."
|
|
||||||
|
|
||||||
# Remove carriage returns and preceding whitespace
|
|
||||||
# not really needed anymore?
|
|
||||||
cp $origin/$andLight $origin/$supernova
|
|
||||||
|
|
||||||
# Sort and remove duplicates
|
|
||||||
sort -u $origin/$supernova > $origin/$eventHorizon
|
|
||||||
numberOf=$(wc -l < $origin/$eventHorizon)
|
|
||||||
echo "** $numberOf unique domains trapped in the event horizon."
|
|
||||||
|
|
||||||
# Format domain list as "192.168.x.x domain.com"
|
|
||||||
echo "** Formatting domains into a HOSTS file..."
|
|
||||||
cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"' " $0}' > $origin/$accretionDisc
|
|
||||||
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
|
||||||
$SUDO cp $origin/$accretionDisc $adList
|
|
||||||
kill -HUP $(pidof dnsmasq)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Whitelist (if applicable) then remove duplicates and format for dnsmasq
|
# Schwarzchild - aggregate domains to one list and add blacklisted domains
|
||||||
if [[ -r $whitelist ]];then
|
function gravity_Schwarzchild() {
|
||||||
|
|
||||||
|
# Find all active domains and compile them into one file and remove CRs
|
||||||
|
echo "** Aggregating list of domains..."
|
||||||
|
truncate -s 0 $piholeDir/$matter
|
||||||
|
for i in "${activeDomains[@]}"
|
||||||
|
do
|
||||||
|
cat $i |tr -d '\r' >> $piholeDir/$matter
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Pulsar - White/blacklist application
|
||||||
|
function gravity_pulsar() {
|
||||||
|
|
||||||
|
# Append blacklist entries if they exist
|
||||||
|
if [[ -r $blacklist ]];then
|
||||||
|
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l)
|
||||||
|
echo "** Blacklisting $numberOf domain(s)..."
|
||||||
|
cat $blacklist >> $piholeDir/$matter
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Whitelist (if applicable) domains
|
||||||
|
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
|
||||||
|
@ -163,19 +200,80 @@ if [[ -r $whitelist ]];then
|
||||||
# replace "." with "\." of each line to turn each entry into a
|
# replace "." with "\." of each line to turn each entry into a
|
||||||
# regexp so it can be parsed out with grep -x
|
# regexp so it can be parsed out with grep -x
|
||||||
awk -F '[# \t]' 'NF>0&&$1!="" {print "^"$1"$"}' $whitelist | sed 's/\./\\./g' > $latentWhitelist
|
awk -F '[# \t]' 'NF>0&&$1!="" {print "^"$1"$"}' $whitelist | sed 's/\./\\./g' > $latentWhitelist
|
||||||
else
|
else
|
||||||
rm $latentWhitelist
|
rm $latentWhitelist
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prevent our sources from being pulled into the hole
|
# 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}..."
|
echo "** Whitelisting ${#sources[@]} ad list source${plural}..."
|
||||||
for url in ${sources[@]}
|
for url in ${sources[@]}
|
||||||
do
|
do
|
||||||
echo "$url" | awk -F '/' '{print "^"$3"$"}' | sed 's/\./\\./g' >> $latentWhitelist
|
echo "$url" | awk -F '/' '{print "^"$3"$"}' | sed 's/\./\\./g' >> $latentWhitelist
|
||||||
done
|
done
|
||||||
|
|
||||||
# Remove whitelist entries from deduped list
|
# Remove whitelist entries from list
|
||||||
grep -vxf $latentWhitelist $origin/$matter > $origin/$andLight
|
grep -vxf $latentWhitelist $piholeDir/$matter > $piholeDir/$andLight
|
||||||
|
}
|
||||||
|
|
||||||
|
function gravity_unique() {
|
||||||
|
# Sort and remove duplicates
|
||||||
|
sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon
|
||||||
|
numberOf=$(wc -l < $piholeDir/$eventHorizon)
|
||||||
|
echo "** $numberOf unique domains trapped in the event horizon."
|
||||||
|
}
|
||||||
|
|
||||||
|
function gravity_hostFormat() {
|
||||||
|
# Format domain list as "192.168.x.x domain.com"
|
||||||
|
echo "** Formatting domains into a HOSTS file..."
|
||||||
|
cat $piholeDir/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"' " $0}' > $piholeDir/$accretionDisc
|
||||||
|
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
||||||
|
<<<<<<< HEAD
|
||||||
|
$SUDO cp $origin/$accretionDisc $adList
|
||||||
|
kill -HUP $(pidof dnsmasq)
|
||||||
|
=======
|
||||||
|
cp $piholeDir/$accretionDisc $adList
|
||||||
|
>>>>>>> refs/remotes/jacobsalmela/master
|
||||||
|
}
|
||||||
|
|
||||||
|
# blackbody - remove any remnant files from script processes
|
||||||
|
function gravity_blackbody() {
|
||||||
|
# Loop through list files
|
||||||
|
for file in $piholeDir/*.$justDomainsExtension
|
||||||
|
do
|
||||||
|
# If list is in active array then leave it (noop) else rm the list
|
||||||
|
if [[ " ${activeDomains[@]} " =~ " ${file} " ]]; then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
rm -f $file
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function gravity_advanced() {
|
||||||
|
# Remove comments and print only the domain name
|
||||||
|
# Most of the lists downloaded are already in hosts file format but the spacing/formating is not contigious
|
||||||
|
# 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
|
||||||
|
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$andLight | \
|
||||||
|
sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova
|
||||||
|
|
||||||
|
numberOf=$(wc -l < $piholeDir/$supernova)
|
||||||
|
echo "** $numberOf domains being pulled in by gravity..."
|
||||||
|
|
||||||
|
gravity_unique
|
||||||
|
|
||||||
|
sudo kill -HUP $(pidof dnsmasq)
|
||||||
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
gravity_advanced
|
gravity_advanced
|
||||||
|
=======
|
||||||
|
gravity_collapse
|
||||||
|
gravity_spinup
|
||||||
|
gravity_Schwarzchild
|
||||||
|
gravity_pulsar
|
||||||
|
gravity_hostFormat
|
||||||
|
gravity_advanced
|
||||||
|
gravity_blackbody
|
||||||
|
>>>>>>> refs/remotes/jacobsalmela/master
|
||||||
|
|
Loading…
Reference in a new issue