mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-28 09:03:17 +00:00
check for a static IP from tmp file
Using the new installation script, if a user wants a static IP address, it is temporarily stored in /tmp/piholeIP. This file needs to be read so the value can be used in the gravity script.
This commit is contained in:
parent
08d6b8a67a
commit
5d66f0ede1
1 changed files with 18 additions and 11 deletions
29
gravity.sh
29
gravity.sh
|
@ -1,11 +1,18 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# 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
|
||||||
# This script should only be run after you have a static IP address set on the Pi
|
if [[ -f $piholeIPfile ]];then
|
||||||
piholeIP=$(hostname -I)
|
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
|
||||||
|
piholeIP=$(cat $piholeIPfile)
|
||||||
|
rm $piholeIPfile
|
||||||
|
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
|
||||||
|
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")
|
||||||
|
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
|
||||||
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/'
|
||||||
|
@ -58,7 +65,7 @@ function createSwapFile()
|
||||||
sudo dphys-swapfile setup
|
sudo dphys-swapfile setup
|
||||||
sudo dphys-swapfile swapon
|
sudo dphys-swapfile swapon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if [[ -n "$noSwap" ]]; then
|
if [[ -n "$noSwap" ]]; then
|
||||||
# if $noSwap is set, don't do anything
|
# if $noSwap is set, don't do anything
|
||||||
|
@ -83,20 +90,20 @@ 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=$origin/list.$i.$domain.$justDomainsExtension
|
||||||
|
|
||||||
echo -n "Getting $domain list... "
|
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 $url);;
|
"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 $url);;
|
"pgl.yoyo.org") data=$(curl -s -d mimetype=plaintext -d hostformat=hosts -z $saveLocation $url);;
|
||||||
|
|
||||||
*) data=$(curl -s -z $saveLocation -A "Mozilla/10.0" $url);;
|
*) data=$(curl -s -z $saveLocation -A "Mozilla/10.0" $url);;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ -n "$data" ]];then
|
if [[ -n "$data" ]];then
|
||||||
# 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
|
||||||
|
@ -127,7 +134,7 @@ function gravity_advanced()
|
||||||
###########################
|
###########################
|
||||||
{
|
{
|
||||||
numberOf=$(cat $origin/$andLight | sed '/^\s*$/d' | wc -l)
|
numberOf=$(cat $origin/$andLight | sed '/^\s*$/d' | wc -l)
|
||||||
echo "** $numberOf domains being pulled in by gravity..."
|
echo "** $numberOf domains being pulled in by gravity..."
|
||||||
# Remove carriage returns and preceding whitespace
|
# Remove carriage returns and preceding whitespace
|
||||||
cat $origin/$andLight | sed $'s/\r$//' | sed '/^\s*$/d' > $origin/$supernova
|
cat $origin/$andLight | sed $'s/\r$//' | sed '/^\s*$/d' > $origin/$supernova
|
||||||
# Sort and remove duplicates
|
# Sort and remove duplicates
|
||||||
|
@ -141,7 +148,7 @@ function gravity_advanced()
|
||||||
sudo cp $origin/$accretionDisc $adList
|
sudo cp $origin/$accretionDisc $adList
|
||||||
kill -HUP $(pidof dnsmasq)
|
kill -HUP $(pidof dnsmasq)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Whitelist (if applicable) then remove duplicates and format for dnsmasq
|
# Whitelist (if applicable) then remove duplicates and format for dnsmasq
|
||||||
if [[ -f $whitelist ]];then
|
if [[ -f $whitelist ]];then
|
||||||
# Remove whitelist entries
|
# Remove whitelist entries
|
||||||
|
|
Loading…
Reference in a new issue