Skip to content

Commit 6d9fbe8

Browse files
committed
Merge pull request #392 from pi-hole/development
Pi-hole v2.6
2 parents b94a8da + 849185d commit 6d9fbe8

20 files changed

+1063
-532
lines changed

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Changes proposed in this pull request:
88

99
-
1010

11-
@pihole/gravity
11+
@pi-hole/gravity

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Automated Install
2-
##### Designed For Raspberry Pi A+, B, B+, 2, and Zero (with an Ethernet/Wi-Fi adapter)
2+
##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) (Works on most Debian distributions!)
3+
34

45
[![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
56

67
1. Install Raspbian
8+
79
2. Run the command below
810

911
### ```curl -L https://install.pi-hole.net | bash```

adlists.default

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
# 2. run `nano /etc/pihole/adlists.list` #
66
# 3. Uncomment or comment any of the below lists #
77
# #
8-
# Know of any other lists? Feel free to let us know about them, or add them #
8+
# Know of any other lists? Feel free to let us know about them, or add them #
99
# to this file! #
1010
################################################################################
1111

12-
# The below list amalgamates several lists we used previously.
12+
# The below list amalgamates several lists we used previously.
1313
# See `https://github.com/StevenBlack/hosts` for details
1414
https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
1515

@@ -31,15 +31,18 @@ http://hosts-file.net/ad_servers.txt
3131
# ADZHOSTS list. Has been known to block legitimate domains
3232
#http://optimate.dl.sourceforge.net/project/adzhosts/HOSTS.txt
3333

34-
# Windows 10 telemetry list - warning this one may block windows update
35-
#https://raw.githubusercontent.com/crazy-max/HostsWindowsBlocker/master/hosts.txt
34+
# Windows 10 telemetry list
35+
#https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/hostsBlockWindowsSpy.txt
3636

3737
# Securemecca.com list - Also blocks "adult" sites (pornography/gambling etc)
3838
#http://securemecca.com/Downloads/hosts.txt
3939

4040
# Quidsup's tracker list
4141
https://raw.githubusercontent.com/quidsup/notrack/master/trackers.txt
4242

43+
# Block the BBC News website Breaking News banner
44+
#https://raw.githubusercontent.com/BreakingTheNews/BreakingTheNews.github.io/master/hosts
45+
4346

4447
# Untested Lists:
4548
#https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt

advanced/Scripts/blacklist.sh

100644100755
+56-54
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,58 @@
1111
# (at your option) any later version.
1212

1313
if [[ $# = 0 ]]; then
14-
echo "Immediately blacklists one or more domains in the hosts file"
15-
echo " "
16-
echo "Usage: blacklist.sh domain1 [domain2 ...]"
17-
echo " "
18-
echo "Options:"
19-
echo " -d, --delmode Remove domains from the blacklist"
20-
echo " -nr, --noreload Update blacklist without refreshing dnsmasq"
21-
echo " -f, --force Force updating of the hosts files, even if there are no changes"
22-
echo " -q, --quiet output is less verbose"
14+
echo "::: Immediately blacklists one or more domains in the hosts file"
15+
echo ":::"
16+
echo "::: Usage: sudo pihole.sh -b domain1 [domain2 ...]"
17+
echo ":::"
18+
echo "::: Options:"
19+
echo "::: -d, --delmode Remove domains from the blacklist"
20+
echo "::: -nr, --noreload Update blacklist without refreshing dnsmasq"
21+
echo "::: -f, --force Force updating of the hosts files, even if there are no changes"
22+
echo "::: -q, --quiet output is less verbose"
2323
exit 1
2424
fi
2525

2626
#globals
27-
blacklist=/etc/pihole/blacklist.txt
28-
adList=/etc/pihole/gravity.list
27+
basename=pihole
28+
piholeDir=/etc/$basename
29+
adList=$piholeDir/gravity.list
30+
blacklist=$piholeDir/blacklist.txt
2931
reload=true
3032
addmode=true
3133
force=false
3234
versbose=true
35+
3336
domList=()
3437
domToRemoveList=()
3538

36-
37-
piholeIPfile=/tmp/piholeIP
3839
piholeIPv6file=/etc/pihole/.useIPv6
3940

4041
# 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
4142
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
42-
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
43+
piholeIPCIDR=$(ip -o -f inet addr show dev "$IPv4dev" | awk '{print $4}' | awk 'END {print}')
4344
piholeIP=${piholeIPCIDR%/*}
4445

4546
modifyHost=false
4647

48+
# After setting defaults, check if there's local overrides
49+
if [[ -r $piholeDir/pihole.conf ]];then
50+
echo "::: Local calibration requested..."
51+
. $piholeDir/pihole.conf
52+
fi
53+
4754

4855
if [[ -f $piholeIPv6file ]];then
4956
# If the file exists, then the user previously chose to use IPv6 in the automated installer
5057
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
5158
fi
5259

5360

54-
function HandleOther(){
61+
function HandleOther(){
5562
#check validity of domain
56-
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/')
57-
63+
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/')
5864
if [ -z "$validDomain" ]; then
59-
echo $1 is not a valid argument or domain name
65+
echo "::: $1 is not a valid argument or domain name"
6066
else
6167
domList=("${domList[@]}" $validDomain)
6268
fi
@@ -66,13 +72,12 @@ function PopBlacklistFile(){
6672
#check blacklist file exists, and if not, create it
6773
if [[ ! -f $blacklist ]];then
6874
touch $blacklist
69-
fi
70-
for dom in "${domList[@]}"
71-
do
72-
if $addmode; then
73-
AddDomain $dom
75+
fi
76+
for dom in "${domList[@]}"; do
77+
if "$addmode"; then
78+
AddDomain "$dom"
7479
else
75-
RemoveDomain $dom
80+
RemoveDomain "$dom"
7681
fi
7782
done
7883
}
@@ -86,18 +91,18 @@ function AddDomain(){
8691
if $versbose; then
8792
echo -n "::: Adding $1 to blacklist file..."
8893
fi
89-
echo $1 >> $blacklist
94+
echo "$1" >> $blacklist
9095
modifyHost=true
9196
echo " done!"
9297
else
9398
if $versbose; then
94-
echo "::: $1 already exists in blacklist.txt! No need to add"
99+
echo "::: $1 already exists in $blacklist! No need to add"
95100
fi
96101
fi
97102
}
98103

99104
function RemoveDomain(){
100-
105+
101106
bool=false
102107
grep -Ex -q "$1" $blacklist || bool=true
103108
if $bool; then
@@ -110,12 +115,12 @@ function RemoveDomain(){
110115
if $versbose; then
111116
echo "::: Un-blacklisting $dom..."
112117
fi
113-
domToRemoveList=("${domToRemoveList[@]}" $1)
114-
modifyHost=true
115-
fi
118+
domToRemoveList=("${domToRemoveList[@]}" $1)
119+
modifyHost=true
120+
fi
116121
}
117122

118-
function ModifyHostFile(){
123+
function ModifyHostFile(){
119124
if $addmode; then
120125
#add domains to the hosts file
121126
if [[ -r $blacklist ]];then
@@ -124,28 +129,25 @@ function ModifyHostFile(){
124129
echo ":::"
125130
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
126131
if [[ -n $piholeIPv6 ]];then
127-
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
128-
else
129-
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
130-
fi
131-
132+
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList
133+
else
134+
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList
135+
fi
132136
fi
133137
else
134-
135138
echo ":::"
136-
for dom in "${domToRemoveList[@]}"
137-
do
138-
#we need to remove the domains from the blacklist file and the host file
139-
echo "::: $dom"
140-
echo -n "::: removing from HOSTS file..."
141-
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
142-
echo " done!"
143-
echo -n "::: removing from blackist.txt..."
144-
echo $dom | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist
145-
echo " done!"
146-
done
147-
fi
148-
139+
for dom in "${domToRemoveList[@]}"
140+
do
141+
#we need to remove the domains from the blacklist file and the host file
142+
echo "::: $dom"
143+
echo -n "::: removing from HOSTS file..."
144+
echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /[^.]'{}'(?!.)/;' $adList
145+
echo " done!"
146+
echo -n "::: removing from blackist.txt..."
147+
echo "$dom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $blacklist
148+
echo " done!"
149+
done
150+
fi
149151
}
150152

151153
function Reload() {
@@ -157,7 +159,7 @@ function Reload() {
157159

158160
if [[ $dnsmasqPid ]]; then
159161
# service already running - reload config
160-
sudo kill -HUP $dnsmasqPid
162+
sudo kill -HUP "$dnsmasqPid"
161163
else
162164
# service not running, start it up
163165
sudo service dnsmasq start
@@ -170,17 +172,17 @@ function Reload() {
170172
for var in "$@"
171173
do
172174
case "$var" in
173-
"-nr"| "--noreload" ) reload=false;;
175+
"-nr"| "--noreload" ) reload=false;;
174176
"-d" | "--delmode" ) addmode=false;;
175177
"-f" | "--force" ) force=true;;
176178
"-q" | "--quiet" ) versbose=false;;
177-
* ) HandleOther $var;;
179+
* ) HandleOther "$var";;
178180
esac
179181
done
180182

181183
PopBlacklistFile
182184

183-
if $modifyHost || $force; then
185+
if $modifyHost || $force; then
184186
ModifyHostFile
185187
else
186188
if $versbose; then

advanced/Scripts/chronometer.sh

+20-19
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ function outputJSON(){
7373
CalcQueriesToday
7474
CalcblockedToday
7575
CalcPercentBlockedToday
76-
76+
7777
CalcBlockedDomains
78-
78+
7979
printf '{"domains_being_blocked":"%s","dns_queries_today":"%s","ads_blocked_today":"%s","ads_percentage_today":"%s"}\n' "$blockedDomainsTotal" "$queriesToday" "$blockedToday" "$percentBlockedToday"
8080
}
8181

@@ -88,44 +88,45 @@ function normalChrono(){
8888
echo " $(ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -d':' -f2)"
8989
echo ""
9090
uptime | cut -d' ' -f11-
91-
uptime -p
91+
#uptime -p #Doesn't work on all versions of uptime
92+
uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes."}'
9293
echo "-------------------------------"
9394
# Uncomment to continually read the log file and display the current domain being blocked
9495
#tail -f /var/log/pihole.log | awk '/\/etc\/pihole\/gravity.list/ {if ($7 != "address" && $7 != "name" && $7 != "/etc/pihole/gravity.list") print $7; else;}'
95-
96+
9697
#uncomment next 4 lines to use original query count calculation
9798
#today=$(date "+%b %e")
9899
#todaysQueryCount=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ {print $7}' | wc -l)
99100
#todaysQueryCountV4=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[A\]/ {print $7}' | wc -l)
100101
#todaysQueryCountV6=$(cat /var/log/pihole.log | grep "$today" | awk '/query/ && /\[AAAA\]/ {print $7}' | wc -l)
101-
102-
102+
103+
103104
CalcQueriesToday
104105
CalcblockedToday
105106
CalcPercentBlockedToday
106-
107+
107108
CalcBlockedDomains
108-
109+
109110
echo "Blocking: $blockedDomainsTotal"
110111
#below commented line does not add up to todaysQueryCount
111112
#echo "Queries: $todaysQueryCountV4 / $todaysQueryCountV6"
112113
echo "Queries: $queriesToday" #same total calculation as dashboard
113114
echo "Pi-holed: $blockedToday ($percentBlockedToday%)"
114-
115+
115116
sleep 5
116117
done
117118
}
118119

119120
function displayHelp(){
120-
echo "Displays stats about your piHole!"
121-
echo " "
122-
echo "Usage: chronometer.sh [optional:-j]"
123-
echo "Note: If no option is passed, then stats are displayed on screen, updated every 5 seconds"
124-
echo " "
125-
echo "Options:"
126-
echo " -j, --json output stats as JSON formatted string"
127-
echo " -h, --help display this help text"
128-
121+
echo "::: Displays stats about your piHole!"
122+
echo ":::"
123+
echo "::: Usage: sudo pihole.sh -c [optional:-j]"
124+
echo "::: Note: If no option is passed, then stats are displayed on screen, updated every 5 seconds"
125+
echo ":::"
126+
echo "::: Options:"
127+
echo "::: -j, --json output stats as JSON formatted string"
128+
echo "::: -h, --help display this help text"
129+
129130
exit 1
130131
}
131132

@@ -137,7 +138,7 @@ for var in "$@"
137138
do
138139
case "$var" in
139140
"-j" | "--json" ) outputJSON;;
140-
"-h" | "--help" ) displayHelp;;
141+
"-h" | "--help" ) displayHelp;;
141142
* ) exit 1;;
142143
esac
143144
done

0 commit comments

Comments
 (0)