mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-12-25 14:20:18 +00:00
Merge branch 'master' into development
This commit is contained in:
commit
8f3bbadf73
3 changed files with 59 additions and 32 deletions
|
@ -23,7 +23,7 @@ A more detailed explanation of the installation can be found [here](http://jacob
|
||||||
[![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")
|
||||||
|
|
||||||
## Gravity
|
## Gravity
|
||||||
The [gravity.sh](https://github.com/jacobsalmela/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 900,000 entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0).
|
The [gravity.sh](https://github.com/jacobsalmela/pi-hole/blob/master/gravity.sh) does most of the magic. The script pulls in ad domains from many sources and compiles them into a single list of [over 1.6 million entries](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0).
|
||||||
|
|
||||||
## Whitelist and blacklist
|
## Whitelist and blacklist
|
||||||
You can add a `whitelist.txt` or `blacklist.txt` in `/etc/pihole/` and the script will apply those files automatically.
|
You can add a `whitelist.txt` or `blacklist.txt` in `/etc/pihole/` and the script will apply those files automatically.
|
||||||
|
|
|
@ -27,12 +27,12 @@ read
|
||||||
if [[ -f /etc/dnsmasq.d/adList.conf ]];then
|
if [[ -f /etc/dnsmasq.d/adList.conf ]];then
|
||||||
echo "Original Pi-hole detected. Initiating sub space transport..."
|
echo "Original Pi-hole detected. Initiating sub space transport..."
|
||||||
sudo mkdir -p /etc/pihole/original/
|
sudo mkdir -p /etc/pihole/original/
|
||||||
mv /etc/dnsmasq.d/adList.conf /etc/pihole/original/adList.conf.$(date "+%Y-%m-%d")
|
sudo mv /etc/dnsmasq.d/adList.conf /etc/pihole/original/adList.conf.$(date "+%Y-%m-%d")
|
||||||
mv /etc/dnsmasq.conf /etc/pihole/original/dnsmasq.conf.$(date "+%Y-%m-%d")
|
sudo mv /etc/dnsmasq.conf /etc/pihole/original/dnsmasq.conf.$(date "+%Y-%m-%d")
|
||||||
mv /etc/resolv.conf /etc/pihole/original/resolv.conf.$(date "+%Y-%m-%d")
|
sudo mv /etc/resolv.conf /etc/pihole/original/resolv.conf.$(date "+%Y-%m-%d")
|
||||||
mv /etc/lighttpd/lighttpd.conf /etc/pihole/original/lighttpd.conf.$(date "+%Y-%m-%d")
|
sudo mv /etc/lighttpd/lighttpd.conf /etc/pihole/original/lighttpd.conf.$(date "+%Y-%m-%d")
|
||||||
mv /var/www/pihole/index.html /etc/pihole/original/index.html.$(date "+%Y-%m-%d")
|
sudo mv /var/www/pihole/index.html /etc/pihole/original/index.html.$(date "+%Y-%m-%d")
|
||||||
mv /usr/local/bin/gravity.sh /etc/pihole/original/gravity.sh.$(date "+%Y-%m-%d")
|
sudo mv /usr/local/bin/gravity.sh /etc/pihole/original/gravity.sh.$(date "+%Y-%m-%d")
|
||||||
else
|
else
|
||||||
:
|
:
|
||||||
fi
|
fi
|
||||||
|
@ -41,6 +41,11 @@ echo "Updating the Pi..."
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get -y upgrade
|
sudo apt-get -y upgrade
|
||||||
|
|
||||||
|
echo "Installing tools..."
|
||||||
|
sudo apt-get -y install dnsutils
|
||||||
|
sudo apt-get -y install bc
|
||||||
|
sudo apt-get -y install toilet
|
||||||
|
|
||||||
echo "Installing DNS..."
|
echo "Installing DNS..."
|
||||||
sudo apt-get -y install dnsmasq
|
sudo apt-get -y install dnsmasq
|
||||||
sudo update-rc.d dnsmasq enable
|
sudo update-rc.d dnsmasq enable
|
||||||
|
|
62
gravity.sh
62
gravity.sh
|
@ -19,9 +19,6 @@ sources=('https://adaway.org/hosts.txt'
|
||||||
adList=/etc/pihole/gravity.list
|
adList=/etc/pihole/gravity.list
|
||||||
origin=/etc/pihole
|
origin=/etc/pihole
|
||||||
piholeDir=/etc/pihole
|
piholeDir=/etc/pihole
|
||||||
if [[ -f $piholeDir/pihole.conf ]];then
|
|
||||||
. $piholeDir/pihole.conf
|
|
||||||
fi
|
|
||||||
justDomainsExtension=domains
|
justDomainsExtension=domains
|
||||||
matter=pihole.0.matter.txt
|
matter=pihole.0.matter.txt
|
||||||
andLight=pihole.1.andLight.txt
|
andLight=pihole.1.andLight.txt
|
||||||
|
@ -34,6 +31,13 @@ latentBlacklist=$origin/latentBlacklist.txt
|
||||||
whitelist=$piholeDir/whitelist.txt
|
whitelist=$piholeDir/whitelist.txt
|
||||||
latentWhitelist=$origin/latentWhitelist.txt
|
latentWhitelist=$origin/latentWhitelist.txt
|
||||||
|
|
||||||
|
# After setting defaults, check if there's local overrides
|
||||||
|
if [[ -r $piholeDir/pihole.conf ]];then
|
||||||
|
echo "** Local calibration requested..."
|
||||||
|
. $piholeDir/pihole.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo "** Neutrino emissions detected..."
|
echo "** Neutrino emissions detected..."
|
||||||
|
|
||||||
# Create the pihole resource directory if it doesn't exist. Future files will be stored here
|
# Create the pihole resource directory if it doesn't exist. Future files will be stored here
|
||||||
|
@ -55,7 +59,11 @@ function createSwapFile()
|
||||||
sudo dphys-swapfile swapon
|
sudo dphys-swapfile swapon
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ -f /etc/dphys-swapfile ]];then
|
|
||||||
|
if [[ -n "$noSwap" ]]; then
|
||||||
|
# if $noSwap is set, don't do anything
|
||||||
|
:
|
||||||
|
elif [[ -f /etc/dphys-swapfile ]];then
|
||||||
swapSize=$(cat /etc/dphys-swapfile | grep -m1 CONF_SWAPSIZE | cut -d'=' -f2)
|
swapSize=$(cat /etc/dphys-swapfile | grep -m1 CONF_SWAPSIZE | cut -d'=' -f2)
|
||||||
if [[ $swapSize != 500 ]];then
|
if [[ $swapSize != 500 ]];then
|
||||||
mv /etc/dphys-swapfile /etc/dphys-swapfile.orig
|
mv /etc/dphys-swapfile /etc/dphys-swapfile.orig
|
||||||
|
@ -72,30 +80,33 @@ fi
|
||||||
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and blank lines
|
# Loop through domain list. Download each one and remove commented lines (lines beginning with '# 'or '/') and blank lines
|
||||||
for ((i = 0; i < "${#sources[@]}"; i++))
|
for ((i = 0; i < "${#sources[@]}"; i++))
|
||||||
do
|
do
|
||||||
|
url=${sources[$i]}
|
||||||
# Get just the domain from the URL
|
# Get just the domain from the URL
|
||||||
domain=$(echo "${sources[$i]}" | 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"
|
saveLocation=$origin/list.$i.$domain.$justDomainsExtension
|
||||||
|
|
||||||
|
echo -n "Getting $domain list... "
|
||||||
# Use a case statement to download lists that need special cURL commands to complete properly
|
# Use a case statement to download lists that need special cURL commands to complete properly
|
||||||
case "$domain" in
|
case "$domain" in
|
||||||
"adblock.mahakala.is") data=$(curl -s -A 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' -e http://forum.xda-developers.com/ -z $saveLocation."$justDomainsExtension" "${sources[$i]}");;
|
"adblock.mahakala.is") data=$(curl -s -A 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' -e http://forum.xda-developers.com/ -z $saveLocation $url);;
|
||||||
|
|
||||||
"pgl.yoyo.org") data=$(curl -s -d mimetype=plaintext -d hostformat=hosts -z $saveLocation."$justDomainsExtension" "${sources[$i]}");;
|
"pgl.yoyo.org") data=$(curl -s -d mimetype=plaintext -d hostformat=hosts -z $saveLocation $url);;
|
||||||
|
|
||||||
*) data=$(curl -s -z $saveLocation."$justDomainsExtension" -A "Mozilla/10.0" "${sources[$i]}");;
|
*) data=$(curl -s -z $saveLocation -A "Mozilla/10.0" $url);;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ -n "$data" ]];then
|
if [[ -n "$data" ]];then
|
||||||
echo "Getting $domain list..."
|
|
||||||
# Remove comments and print only the domain name
|
# 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
|
# 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
|
# This helps with that and makes it easier to read
|
||||||
# It also helps with debugging so each stage of the script can be researched more in depth
|
# It also helps with debugging so each stage of the script can be researched more in depth
|
||||||
echo "$data" | awk 'NF {if ($1 !~ "#") { if (NF>1) {print $2} else {print $1}}}' > $saveLocation."$justDomainsExtension"
|
echo "$data" | awk 'NF {if ($1 !~ "#") { if (NF>1) {print $2} else {print $1}}}' | \
|
||||||
|
sed -e 's/^[. \t]*//' -e 's/\.\.\+/./g' -e 's/[. \t]*$//' | grep "\." > $saveLocation
|
||||||
|
echo "Done."
|
||||||
else
|
else
|
||||||
echo "Skipping $domain list because it does not have any new entries..."
|
echo "Skipping list because it does not have any new entries."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -135,13 +146,24 @@ function gravity_advanced()
|
||||||
if [[ -f $whitelist ]];then
|
if [[ -f $whitelist ]];then
|
||||||
# Remove whitelist entries
|
# Remove whitelist entries
|
||||||
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l)
|
||||||
echo "** Whitelisting $numberOf domain(s)..."
|
plural=; [[ "$numberOf" != "1" ]] && plural=s
|
||||||
# Append a "$" to the end of each line so it can be parsed out with grep -w
|
echo "** Whitelisting $numberOf domain${plural}..."
|
||||||
echo -n "^$" > $latentWhitelist
|
# Append a "$" to the end, prepend a "^" to the beginning, and
|
||||||
awk -F '[# \t]' 'NF>0&&$1!="" {print $1"$"}' $whitelist > $latentWhitelist
|
# replace "." with "\." of each line to turn each entry into a
|
||||||
cat $origin/$matter | grep -vwf $latentWhitelist > $origin/$andLight
|
# regexp so it can be parsed out with grep -x
|
||||||
gravity_advanced
|
awk -F '[# \t]' 'NF>0&&$1!="" {print "^"$1"$"}' $whitelist | sed 's/\./\\./g' > $latentWhitelist
|
||||||
else
|
else
|
||||||
cat $origin/$matter > $origin/$andLight
|
rm $latentWhitelist
|
||||||
gravity_advanced
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Prevent our sources from being pulled into the hole
|
||||||
|
plural=; [[ "${#sources[@]}" != "1" ]] && plural=s
|
||||||
|
echo "** Whitelisting ${#sources[@]} ad list source${plural}..."
|
||||||
|
for url in ${sources[@]}
|
||||||
|
do
|
||||||
|
echo "$url" | awk -F '/' '{print "^"$3"$"}' | sed 's/\./\\./g' >> $latentWhitelist
|
||||||
|
done
|
||||||
|
|
||||||
|
grep -vxf $latentWhitelist $origin/$matter > $origin/$andLight
|
||||||
|
|
||||||
|
gravity_advanced
|
||||||
|
|
Loading…
Reference in a new issue