Merge pull request #639 from pi-hole/development

2.9
This commit is contained in:
Adam Warner 2016-08-30 21:46:04 +01:00 committed by GitHub
commit ec6ecf0d60
14 changed files with 899 additions and 716 deletions

14
.pullapprove.yml Normal file
View file

@ -0,0 +1,14 @@
approve_by_comment: true
approve_regex: '^(Approved|:shipit:|:\+1:)'
reject_regex: '^(Rejected|:-1:)'
reset_on_push: true
author_approval: required
reviewers:
members:
- brantje
- dschaper
- jacobsalmela
- Mcat12
- PromoFaux
name: pullapprove
required: 3

View file

@ -1,20 +1,24 @@
[![Bountysource](https://www.bountysource.com/badge/tracker?tracker_id=3011939)](https://www.bountysource.com/trackers/3011939-pi-hole-pi-hole?utm_source=3011939&utm_medium=shield&utm_campaign=TRACKER_BADGE)
# Automated Install # Automated Install
##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) (Works on most Debian distributions!)
Designed For Raspberry Pi A+, B, B+, 2, 3B, and Zero (with an Ethernet/Wi-Fi adapter)
Works on most Debian and CentOS/RHEL based distributions!
1. Install Raspbian 1. Install Raspbian
2. Run the command below (downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!) 2. Run the command below (downloads [this script](https://github.com/pi-hole/pi-hole/blob/master/automated%20install/basic-install.sh) in case you want to read over it first!)
### ```curl -L https://install.pi-hole.net | bash``` ## `curl -L https://install.pi-hole.net | bash`
#### Alternative Semi-Automated install #### ### Alternative Semi-Automated install
```
```bash
wget -O basic-install.sh https://install.pi-hole.net wget -O basic-install.sh https://install.pi-hole.net
chmod +x basic-install.sh chmod +x basic-install.sh
./basic-install.sh ./basic-install.sh
``` ```
If you wish to read over the script before running it, then after the `wget` command, do `nano basic-install.sh` to open a text viewer
If you wish to read over the script before running it, then after the `wget` command, do `nano basic-install.sh` to open a text viewer
Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](http://pi-hole.net/faq/can-i-set-the-pi-hole-to-be-the-dns-server-at-my-router-so-i-dont-have-to-change-settings-for-my-devices/) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to [use the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/). Once installed, [configure your router to have **DHCP clients use the Pi as their DNS server**](http://pi-hole.net/faq/can-i-set-the-pi-hole-to-be-the-dns-server-at-my-router-so-i-dont-have-to-change-settings-for-my-devices/) and then any device that connects to your network will have ads blocked without any further configuration. Alternatively, you can manually set each device to [use the Raspberry Pi as its DNS server](http://pi-hole.net/faq/how-do-i-use-the-pi-hole-as-my-dns-server/).
@ -22,18 +26,19 @@ Once installed, [configure your router to have **DHCP clients use the Pi as thei
[![60-second install tutorial](http://i.imgur.com/5TEc3a6.png)](https://www.youtube.com/watch?v=TzFLJqUeirA) [![60-second install tutorial](http://i.imgur.com/5TEc3a6.png)](https://www.youtube.com/watch?v=TzFLJqUeirA)
## How Does It Work? ## How It Works
**Watch the 60-second video below to get a quick overview** **Watch the 60-second video below to get a quick overview**
[![Pi-hole exlplained](http://i.imgur.com/pG1m937.png)](https://youtu.be/9Eti3xibiho) [![Pi-hole exlplained](http://i.imgur.com/pG1m937.png)](https://youtu.be/9Eti3xibiho)
## Pi-hole Is Free, But Powered By Your Donations ## Pi-hole Is Free, But Powered By Your Donations
Send a one-time donation or sign up for Optimal.com's service using our link below to provide us with a small portion of the montly fee.
* ![Paypal](http://i.imgur.com/3muNfxu.png) : [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY)
* ![Flattr](http://i.imgur.com/ZFceFRu.png) : [Donate](https://flattr.com/submit/auto?user_id=jacobsalmela&url=https://github.com/pi-hole/pi-hole)
* ![Bitcoin](http://i.imgur.com/FIlmOMG.png) : 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL
* ![Optimal.com](http://i.imgur.com/d4EAYrw.png) : [Optimal.com](http://api.optimal.com/partner/v1.0/bmV0d29ya3xkbnN8OlJhc3BiZXJyeSBQaS1Ib2xl/subscribe?redirect=https%3A%2F%2Fpi-hole.net%2Fthank-you%2F) (we get a small comission)
Send a one-time donation or sign up for Optimal.com's service using our link below to provide us with a small portion of the monthly fee.
- ![Paypal](http://i.imgur.com/3muNfxu.png) : [Donate](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY)
- ![Flattr](http://i.imgur.com/ZFceFRu.png) : [Donate](https://flattr.com/submit/auto?user_id=jacobsalmela&url=https://github.com/pi-hole/pi-hole)
- ![Bitcoin](http://i.imgur.com/FIlmOMG.png) : 1GKnevUnVaQM2pQieMyeHkpr8DXfkpfAtL
## Get Help Or Connect With Us On The Web ## Get Help Or Connect With Us On The Web
@ -49,9 +54,11 @@ Send a one-time donation or sign up for Optimal.com's service using our link bel
The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. You can also [replace ads with any image you want](http://pi-hole.net/faq/is-it-possible-to-change-the-blank-page-that-takes-place-of-the-ads-to-something-else/) since it is just a simple Webpage taking place of the ads. The Pi-hole is an **advertising-aware DNS/Web server**. If an ad domain is queried, a small Web page or GIF is delivered in place of the advertisement. You can also [replace ads with any image you want](http://pi-hole.net/faq/is-it-possible-to-change-the-blank-page-that-takes-place-of-the-ads-to-something-else/) since it is just a simple Webpage taking place of the ads.
### Gravity ### Gravity
The [gravity.sh](https://github.com/pi-hole/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) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)). The [gravity.sh](https://github.com/pi-hole/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) (if you decide to use the [mahakala list](https://github.com/pi-hole/pi-hole/commit/963eacfe0537a7abddf30441c754c67ca1e40965)).
## Web Interface ## Web Interface
The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashboard) will be installed automatically so you can view stats and change settings. You can find it at: The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashboard) will be installed automatically so you can view stats and change settings. You can find it at:
`http://192.168.1.x/admin/index.php` or `http://pi.hole/admin` `http://192.168.1.x/admin/index.php` or `http://pi.hole/admin`
@ -60,13 +67,13 @@ The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashb
### Whitelist and blacklist ### Whitelist and blacklist
Domains can be whitelisted and blacklisted using two pre-installed scripts. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details Domains can be whitelisted and blacklisted using two pre-installed scripts. See [the wiki page](https://github.com/pi-hole/pi-hole/wiki/Whitelisting-and-Blacklisting) for more details ![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png)
![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png)
## API ## API
A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON:
```JSON
```json
{ {
"domains_being_blocked": "136708", "domains_being_blocked": "136708",
"dns_queries_today": "18108", "dns_queries_today": "18108",
@ -74,14 +81,15 @@ A basic read-only API can be accessed at `/admin/api.php`. It returns the follow
"ads_percentage_today": "80.89" "ads_percentage_today": "80.89"
} }
``` ```
The same output can be acheived on the CLI by running `chronometer.sh -j`
The same output can be achieved on the CLI by running `chronometer.sh -j`
## Real-time Statistics ## Real-time Statistics
You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-monitor-chronometer/) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-monitor-chronometer/) via `ssh` or on an [2.8" LCD screen](http://amzn.to/1P0q1Fj). This is accomplished via [`chronometer.sh`](https://github.com/pi-hole/pi-hole/blob/master/advanced/Scripts/chronometer.sh). ![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg)
![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg)
## Pi-hole Projects ## Pi-hole Projects
- [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py) - [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py)
- [Get LED alerts for each blocked ad](http://www.stinebaugh.info/get-led-alerts-for-each-blocked-ad-using-pi-hole/) - [Get LED alerts for each blocked ad](http://www.stinebaugh.info/get-led-alerts-for-each-blocked-ad-using-pi-hole/)
- [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html) - [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html)
@ -94,8 +102,10 @@ You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-
- [unRaid-hole](https://github.com/spants/unraidtemplates/blob/master/Spants/unRaid-hole.xml#L13)--[Repo and more info](http://lime-technology.com/forum/index.php?PHPSESSID=c0eae3e5ef7e521f7866034a3336489d&topic=38486.0) - [unRaid-hole](https://github.com/spants/unraidtemplates/blob/master/Spants/unRaid-hole.xml#L13)--[Repo and more info](http://lime-technology.com/forum/index.php?PHPSESSID=c0eae3e5ef7e521f7866034a3336489d&topic=38486.0)
- [Pi-hole on/off button](http://thetimmy.silvernight.org/pages/endisbutton/) - [Pi-hole on/off button](http://thetimmy.silvernight.org/pages/endisbutton/)
- [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) - [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole)
- [Windows Tray Stat Application](https://github.com/goldbattle/copernicus)
## Coverage ## Coverage
- [Adafruit livestream install](https://www.youtube.com/watch?v=eg4u2j1HYlI) - [Adafruit livestream install](https://www.youtube.com/watch?v=eg4u2j1HYlI)
- [TekThing: 5 fun, easy projects for a Raspberry Pi](https://youtu.be/QwrKlyC2kdM?t=1m42s) - [TekThing: 5 fun, easy projects for a Raspberry Pi](https://youtu.be/QwrKlyC2kdM?t=1m42s)
- [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/) - [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/)
@ -111,4 +121,5 @@ You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd-
- [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) - [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/)
## Other Operating Systems ## 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 is only for a clean install of a Debian based system, such as the Raspberry Pi. 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.

View file

@ -47,9 +47,9 @@ fi
#globals #globals
basename=pihole basename=pihole
piholeDir=/etc/$basename piholeDir=/etc/${basename}
adList=$piholeDir/gravity.list adList=${piholeDir}/gravity.list
blacklist=$piholeDir/blacklist.txt blacklist=${piholeDir}/blacklist.txt
reload=true reload=true
addmode=true addmode=true
force=false force=false
@ -61,9 +61,9 @@ domToRemoveList=()
piholeIPfile=/etc/pihole/piholeIP piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6 piholeIPv6file=/etc/pihole/.useIPv6
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
piholeIP=$(cat $piholeIPfile) piholeIP=$(cat ${piholeIPfile})
#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
@ -75,13 +75,13 @@ fi
modifyHost=false modifyHost=false
# 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..."
. $piholeDir/pihole.conf . ${piholeDir}/pihole.conf
fi fi
if [[ -f $piholeIPv6file ]];then if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer # If the file exists, then the user previously chose to use IPv6 in the automated installer
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi
@ -92,14 +92,14 @@ function HandleOther(){
if [ -z "$validDomain" ]; then if [ -z "$validDomain" ]; then
echo "::: $1 is not a valid argument or domain name" echo "::: $1 is not a valid argument or domain name"
else else
domList=("${domList[@]}" $validDomain) domList=("${domList[@]}" ${validDomain})
fi fi
} }
function PopBlacklistFile(){ function PopBlacklistFile(){
#check blacklist file exists, and if not, create it #check blacklist file exists, and if not, create it
if [[ ! -f $blacklist ]];then if [[ ! -f ${blacklist} ]];then
touch $blacklist touch ${blacklist}
fi fi
for dom in "${domList[@]}"; do for dom in "${domList[@]}"; do
if "$addmode"; then if "$addmode"; then
@ -113,17 +113,17 @@ function PopBlacklistFile(){
function AddDomain(){ function AddDomain(){
#| sed 's/\./\\./g' #| sed 's/\./\\./g'
bool=false bool=false
grep -Ex -q "$1" $blacklist || bool=true grep -Ex -q "$1" ${blacklist} || bool=true
if $bool; then if ${bool}; then
#domain not found in the blacklist file, add it! #domain not found in the blacklist file, add it!
if $verbose; then if ${verbose}; then
echo -n "::: Adding $1 to blacklist file..." echo -n "::: Adding $1 to blacklist file..."
fi fi
echo "$1" >> $blacklist echo "$1" >> ${blacklist}
modifyHost=true modifyHost=true
echo " done!" echo " done!"
else else
if $verbose; then if ${verbose}; then
echo "::: $1 already exists in $blacklist! No need to add" echo "::: $1 already exists in $blacklist! No need to add"
fi fi
fi fi
@ -132,15 +132,15 @@ function AddDomain(){
function RemoveDomain(){ function RemoveDomain(){
bool=false bool=false
grep -Ex -q "$1" $blacklist || bool=true grep -Ex -q "$1" ${blacklist} || bool=true
if $bool; then if ${bool}; then
#Domain is not in the blacklist file, no need to Remove #Domain is not in the blacklist file, no need to Remove
if $verbose; then if ${verbose}; then
echo "::: $1 is NOT blacklisted! No need to remove" echo "::: $1 is NOT blacklisted! No need to remove"
fi fi
else else
#Domain is in the blacklist file, add to a temporary array #Domain is in the blacklist file, add to a temporary array
if $verbose; then if ${verbose}; then
echo "::: Un-blacklisting $dom..." echo "::: Un-blacklisting $dom..."
fi fi
domToRemoveList=("${domToRemoveList[@]}" $1) domToRemoveList=("${domToRemoveList[@]}" $1)
@ -149,17 +149,17 @@ function RemoveDomain(){
} }
function ModifyHostFile(){ function ModifyHostFile(){
if $addmode; then if ${addmode}; then
#add domains to the hosts file #add domains to the hosts file
if [[ -r $blacklist ]];then if [[ -r ${blacklist} ]];then
numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l)
plural=; [[ "$numberOf" != "1" ]] && plural=s plural=; [[ "$numberOf" != "1" ]] && plural=s
echo ":::" echo ":::"
echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..."
if [[ -n $piholeIPv6 ]];then if [[ -n ${piholeIPv6} ]];then
cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList}
else else
cat $blacklist | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList cat ${blacklist} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>${adList}
fi fi
fi fi
else else
@ -169,10 +169,10 @@ function ModifyHostFile(){
#we need to remove the domains from the blacklist file and the host file #we need to remove the domains from the blacklist file and the host file
echo "::: $dom" echo "::: $dom"
echo -n "::: removing from HOSTS file..." echo -n "::: removing from HOSTS file..."
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}
echo " done!" echo " done!"
echo -n "::: removing from blackist.txt..." 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!" echo " done!"
done done
fi fi
@ -185,12 +185,12 @@ function Reload() {
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
if [[ $dnsmasqPid ]]; then if [[ ${dnsmasqPid} ]]; then
# service already running - reload config # service already running - reload config
$SUDO killall -s HUP dnsmasq ${SUDO} killall -s HUP dnsmasq
else else
# service not running, start it up # service not running, start it up
$SUDO service dnsmasq start ${SUDO} service dnsmasq start
fi fi
echo " done!" echo " done!"
} }
@ -223,15 +223,15 @@ done
PopBlacklistFile PopBlacklistFile
if $modifyHost || $force; then if ${modifyHost} || ${force}; then
ModifyHostFile ModifyHostFile
else else
if $verbose; then if ${verbose}; then
echo "::: No changes need to be made" echo "::: No changes need to be made"
fi fi
exit 1 exit 1
fi fi
if $reload; then if ${reload}; then
Reload Reload
fi fi

View file

@ -21,7 +21,7 @@ function CalcBlockedDomains(){
CheckIPv6 CheckIPv6
if [ -e "$gravity" ]; then if [ -e "$gravity" ]; then
#Are we IPV6 or IPV4? #Are we IPV6 or IPV4?
if [[ -n $piholeIPv6 ]];then if [[ -n ${piholeIPv6} ]];then
#We are IPV6 #We are IPV6
blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}') blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}')
else else
@ -43,7 +43,7 @@ function CalcQueriesToday(){
function CalcblockedToday(){ function CalcblockedToday(){
if [ -e "$piLog" ] && [ -e "$gravity" ];then if [ -e "$piLog" ] && [ -e "$gravity" ];then
blockedToday=$(cat $piLog | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l) blockedToday=$(cat ${piLog} | awk '/\/etc\/pihole\/gravity.list/ && !/address/ {print $6}' | wc -l)
else else
blockedToday="Err." blockedToday="Err."
fi fi
@ -63,7 +63,7 @@ function CalcPercentBlockedToday(){
function CheckIPv6(){ function CheckIPv6(){
piholeIPv6file="/etc/pihole/.useIPv6" piholeIPv6file="/etc/pihole/.useIPv6"
if [[ -f $piholeIPv6file ]];then if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer # If the file exists, then the user previously chose to use IPv6 in the automated installer
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi

View file

@ -10,9 +10,6 @@
# the Free Software Foundation, either version 2 of the License, or # the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version. # (at your option) any later version.
# Nate Brandeburg
# nate@ubiquisoft.com
# 3/24/2016
######## GLOBAL VARS ######## ######## GLOBAL VARS ########
DEBUG_LOG="/var/log/pihole_debug.log" DEBUG_LOG="/var/log/pihole_debug.log"
@ -46,75 +43,75 @@ fi
# Ensure the file exists, create if not, clear if exists. # Ensure the file exists, create if not, clear if exists.
if [ ! -f "$DEBUG_LOG" ]; then if [ ! -f "$DEBUG_LOG" ]; then
$SUDO touch $DEBUG_LOG ${SUDO} touch ${DEBUG_LOG}
$SUDO chmod 644 $DEBUG_LOG ${SUDO} chmod 644 ${DEBUG_LOG}
$SUDO chown "$USER":root $DEBUG_LOG ${SUDO} chown "$USER":root ${DEBUG_LOG}
else else
truncate -s 0 $DEBUG_LOG truncate -s 0 ${DEBUG_LOG}
fi fi
### Private functions exist here ### ### Private functions exist here ###
function versionCheck { function versionCheck {
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "########## Versions Section ###########" >> $DEBUG_LOG echo "########## Versions Section ###########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
TMP=$(cd /etc/.pihole/ && git describe --tags --abbrev=0) TMP=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
echo "Pi-hole Version: $TMP" >> $DEBUG_LOG echo "Pi-hole Version: $TMP" >> ${DEBUG_LOG}
TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0) TMP=$(cd /var/www/html/admin && git describe --tags --abbrev=0)
echo "WebUI Version: $TMP" >> $DEBUG_LOG echo "WebUI Version: $TMP" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
function distroCheck { function distroCheck {
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "######## Distribution Section #########" >> $DEBUG_LOG echo "######## Distribution Section #########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
TMP=$(cat /etc/*release/ || echo "Failed to find release") TMP=$(cat /etc/*release || echo "Failed to find release")
echo "Distribution Version: $TMP" >> $DEBUG_LOG echo "Distribution Version: $TMP" >> ${DEBUG_LOG}
} }
function compareWhitelist { function compareWhitelist {
if [ ! -f "$WHITELISTMATCHES" ]; then if [ ! -f "$WHITELISTMATCHES" ]; then
$SUDO touch $WHITELISTMATCHES ${SUDO} touch ${WHITELISTMATCHES}
$SUDO chmod 644 $WHITELISTMATCHES ${SUDO} chmod 644 ${WHITELISTMATCHES}
$SUDO chown "$USER":root $WHITELISTMATCHES ${SUDO} chown "$USER":root ${WHITELISTMATCHES}
else else
truncate -s 0 $WHITELISTMATCHES truncate -s 0 ${WHITELISTMATCHES}
fi fi
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "######## Whitelist Comparison #########" >> $DEBUG_LOG echo "######## Whitelist Comparison #########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
while read -r line; do while read -r line; do
TMP=$(grep -w ".* $line$" "$GRAVITYFILE") TMP=$(grep -w ".* $line$" "$GRAVITYFILE")
if [ ! -z "$TMP" ]; then if [ ! -z "$TMP" ]; then
echo "$TMP" >> $DEBUG_LOG echo "$TMP" >> ${DEBUG_LOG}
echo "$TMP" >> $WHITELISTMATCHES echo "$TMP" >> ${WHITELISTMATCHES}
fi fi
done < "$WHITELISTFILE" done < "$WHITELISTFILE"
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
function compareBlacklist { function compareBlacklist {
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "######## Blacklist Comparison #########" >> $DEBUG_LOG echo "######## Blacklist Comparison #########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
while read -r line; do while read -r line; do
if [ ! -z "$line" ]; then if [ ! -z "$line" ]; then
grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG grep -w ".* $line$" "$GRAVITYFILE" >> ${DEBUG_LOG}
fi fi
done < "$BLACKLISTFILE" done < "$BLACKLISTFILE"
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
function testNslookup { function testNslookup {
TESTURL="doubleclick.com" TESTURL="doubleclick.com"
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############ NSLookup Test ############" >> $DEBUG_LOG echo "############ NSLookup Test ############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
# Find a blocked url that has not been whitelisted. # Find a blocked url that has not been whitelisted.
if [ -s "$WHITELISTMATCHES" ]; then if [ -s "$WHITELISTMATCHES" ]; then
while read -r line; do while read -r line; do
@ -131,77 +128,77 @@ function testNslookup {
done < "$GRAVITYFILE" done < "$GRAVITYFILE"
fi fi
echo "NSLOOKUP of $TESTURL from PiHole:" >> $DEBUG_LOG echo "NSLOOKUP of $TESTURL from PiHole:" >> ${DEBUG_LOG}
nslookup "$TESTURL" >> $DEBUG_LOG nslookup "$TESTURL" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> $DEBUG_LOG echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG}
nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG nslookup "$TESTURL" 8.8.8.8 >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
function checkProcesses { function checkProcesses {
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "########### Processes Check ###########" >> $DEBUG_LOG echo "########### Processes Check ###########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo ":::" echo ":::"
echo "::: Logging status of lighttpd and dnsmasq..." echo "::: Logging status of lighttpd and dnsmasq..."
PROCESSES=( lighttpd dnsmasq ) PROCESSES=( lighttpd dnsmasq )
for i in "${PROCESSES[@]}" for i in "${PROCESSES[@]}"
do do
echo "" >> $DEBUG_LOG echo "" >> ${DEBUG_LOG}
echo -n "$i" >> "$DEBUG_LOG" echo -n "$i" >> "$DEBUG_LOG"
echo " processes status:" >> $DEBUG_LOG echo " processes status:" >> ${DEBUG_LOG}
$SUDO systemctl -l status "$i" >> "$DEBUG_LOG" ${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG"
done done
} }
function debugLighttpd { function debugLighttpd {
echo "::: Writing lighttpd to debug log..." echo "::: Writing lighttpd to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############ lighttpd.conf ############" >> $DEBUG_LOG echo "############ lighttpd.conf ############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$LIGHTTPDFILE" ] if [ -e "$LIGHTTPDFILE" ]
then then
while read -r line; do while read -r line; do
if [ ! -z "$line" ]; then if [ ! -z "$line" ]; then
[[ "$line" =~ ^#.*$ ]] && continue [[ "$line" =~ ^#.*$ ]] && continue
echo "$line" >> $DEBUG_LOG echo "$line" >> ${DEBUG_LOG}
fi fi
done < "$LIGHTTPDFILE" done < "$LIGHTTPDFILE"
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
else else
echo "No lighttpd.conf file found!" >> $DEBUG_LOG echo "No lighttpd.conf file found!" >> ${DEBUG_LOG}
printf ":::\tNo lighttpd.conf file found\n" printf ":::\tNo lighttpd.conf file found\n"
fi fi
if [ -e "$LIGHTTPDERRFILE" ] if [ -e "$LIGHTTPDERRFILE" ]
then then
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "######### lighttpd error.log ##########" >> $DEBUG_LOG echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
cat "$LIGHTTPDERRFILE" >> $DEBUG_LOG cat "$LIGHTTPDERRFILE" >> ${DEBUG_LOG}
else else
echo "No lighttpd error.log file found!" >> $DEBUG_LOG echo "No lighttpd error.log file found!" >> ${DEBUG_LOG}
printf ":::\tNo lighttpd error.log file found\n" printf ":::\tNo lighttpd error.log file found\n"
fi fi
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
} }
### END FUNCTIONS ### ### END FUNCTIONS ###
### Check Pi internet connections ### ### Check Pi internet connections ###
# Log the IP addresses of this Pi # Log the IP addresses of this Pi
IPADDR=$($SUDO ifconfig | perl -nle 's/dr:(\S+)/print $1/e') IPADDR=$(${SUDO} ifconfig | perl -nle 's/dr:(\S+)/print $1/e')
echo "::: Writing local IPs to debug log" echo "::: Writing local IPs to debug log"
echo "IP Addresses of this Pi:" >> $DEBUG_LOG echo "IP Addresses of this Pi:" >> ${DEBUG_LOG}
echo "$IPADDR" >> $DEBUG_LOG echo "$IPADDR" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
# Check if we can connect to the local gateway # Check if we can connect to the local gateway
GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error) GATEWAY_CHECK=$(ping -q -w 1 -c 1 "$(ip r | grep default | cut -d ' ' -f 3)" > /dev/null && echo ok || echo error)
echo "Gateway check:" >> $DEBUG_LOG echo "Gateway check:" >> ${DEBUG_LOG}
echo "$GATEWAY_CHECK" >> $DEBUG_LOG echo "$GATEWAY_CHECK" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
versionCheck versionCheck
distroCheck distroCheck
@ -212,109 +209,109 @@ checkProcesses
debugLighttpd debugLighttpd
echo "::: Writing dnsmasq.conf to debug log..." echo "::: Writing dnsmasq.conf to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############### Dnsmasq ###############" >> $DEBUG_LOG echo "############### Dnsmasq ###############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$DNSMASQFILE" ] if [ -e "$DNSMASQFILE" ]
then then
#cat $DNSMASQFILE >> $DEBUG_LOG #cat $DNSMASQFILE >> $DEBUG_LOG
while read -r line; do while read -r line; do
if [ ! -z "$line" ]; then if [ ! -z "$line" ]; then
[[ "$line" =~ ^#.*$ ]] && continue [[ "$line" =~ ^#.*$ ]] && continue
echo "$line" >> $DEBUG_LOG echo "$line" >> ${DEBUG_LOG}
fi fi
done < "$DNSMASQFILE" done < "$DNSMASQFILE"
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
else else
echo "No dnsmasq.conf file found!" >> $DEBUG_LOG echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG}
printf ":::\tNo dnsmasq.conf file found!\n" printf ":::\tNo dnsmasq.conf file found!\n"
fi fi
echo "::: Writing 01-pihole.conf to debug log..." echo "::: Writing 01-pihole.conf to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "########### 01-pihole.conf ############" >> $DEBUG_LOG echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$PIHOLECONFFILE" ] if [ -e "$PIHOLECONFFILE" ]
then then
while read -r line; do while read -r line; do
if [ ! -z "$line" ]; then if [ ! -z "$line" ]; then
[[ "$line" =~ ^#.*$ ]] && continue [[ "$line" =~ ^#.*$ ]] && continue
echo "$line" >> $DEBUG_LOG echo "$line" >> ${DEBUG_LOG}
fi fi
done < "$PIHOLECONFFILE" done < "$PIHOLECONFFILE"
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
else else
echo "No 01-pihole.conf file found!" >> $DEBUG_LOG echo "No 01-pihole.conf file found!" >> ${DEBUG_LOG}
printf ":::\tNo 01-pihole.conf file found\n" printf ":::\tNo 01-pihole.conf file found\n"
fi fi
echo "::: Writing size of gravity.list to debug log..." echo "::: Writing size of gravity.list to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############ gravity.list #############" >> $DEBUG_LOG echo "############ gravity.list #############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$GRAVITYFILE" ] if [ -e "$GRAVITYFILE" ]
then then
wc -l "$GRAVITYFILE" >> $DEBUG_LOG wc -l "$GRAVITYFILE" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
else else
echo "No gravity.list file found!" >> $DEBUG_LOG echo "No gravity.list file found!" >> ${DEBUG_LOG}
printf ":::\tNo gravity.list file found\n" printf ":::\tNo gravity.list file found\n"
fi fi
# Write the hostname output to compare against entries in /etc/hosts, which is logged next # Write the hostname output to compare against entries in /etc/hosts, which is logged next
echo "Hostname of this pihole is: " >> $DEBUG_LOG echo "Hostname of this pihole is: " >> ${DEBUG_LOG}
hostname >> $DEBUG_LOG hostname >> ${DEBUG_LOG}
echo "::: Writing hosts file to debug log..." echo "::: Writing hosts file to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "################ Hosts ################" >> $DEBUG_LOG echo "################ Hosts ################" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$HOSTSFILE" ] if [ -e "$HOSTSFILE" ]
then then
cat "$HOSTSFILE" >> $DEBUG_LOG cat "$HOSTSFILE" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
else else
echo "No hosts file found!" >> $DEBUG_LOG echo "No hosts file found!" >> ${DEBUG_LOG}
printf ":::\tNo hosts file found!\n" printf ":::\tNo hosts file found!\n"
fi fi
### PiHole application specific logging ### ### PiHole application specific logging ###
echo "::: Writing whitelist to debug log..." echo "::: Writing whitelist to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############## Whitelist ##############" >> $DEBUG_LOG echo "############## Whitelist ##############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$WHITELISTFILE" ] if [ -e "$WHITELISTFILE" ]
then then
cat "$WHITELISTFILE" >> $DEBUG_LOG cat "$WHITELISTFILE" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
else else
echo "No whitelist.txt file found!" >> $DEBUG_LOG echo "No whitelist.txt file found!" >> ${DEBUG_LOG}
printf ":::\tNo whitelist.txt file found!\n" printf ":::\tNo whitelist.txt file found!\n"
fi fi
echo "::: Writing blacklist to debug log..." echo "::: Writing blacklist to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############## Blacklist ##############" >> $DEBUG_LOG echo "############## Blacklist ##############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$BLACKLISTFILE" ] if [ -e "$BLACKLISTFILE" ]
then then
cat "$BLACKLISTFILE" >> $DEBUG_LOG cat "$BLACKLISTFILE" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
else else
echo "No blacklist.txt file found!" >> $DEBUG_LOG echo "No blacklist.txt file found!" >> ${DEBUG_LOG}
printf ":::\tNo blacklist.txt file found!\n" printf ":::\tNo blacklist.txt file found!\n"
fi fi
echo "::: Writing adlists.list to debug log..." echo "::: Writing adlists.list to debug log..."
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############ adlists.list #############" >> $DEBUG_LOG echo "############ adlists.list #############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$ADLISTSFILE" ] if [ -e "$ADLISTSFILE" ]
then then
cat "$ADLISTSFILE" >> $DEBUG_LOG cat "$ADLISTSFILE" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
else else
echo "No adlists.list file found... using adlists.default!" >> $DEBUG_LOG echo "No adlists.list file found... using adlists.default!" >> ${DEBUG_LOG}
printf ":::\tNo adlists.list file found... using adlists.default!\n" printf ":::\tNo adlists.list file found... using adlists.default!\n"
fi fi
@ -323,17 +320,17 @@ fi
function dumpPiHoleLog { function dumpPiHoleLog {
trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT trap '{ echo -e "\n::: Finishing debug write from interrupt... Quitting!" ; exit 1; }' INT
echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)" echo -e "::: Writing current pihole traffic to debug log...\n:::\tTry loading any/all sites that you are having trouble with now... \n:::\t(Press ctrl+C to finish)"
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
echo "############# pihole.log ##############" >> $DEBUG_LOG echo "############# pihole.log ##############" >> ${DEBUG_LOG}
echo "#######################################" >> $DEBUG_LOG echo "#######################################" >> ${DEBUG_LOG}
if [ -e "$PIHOLELOG" ] if [ -e "$PIHOLELOG" ]
then then
while true; do while true; do
tail -f "$PIHOLELOG" >> $DEBUG_LOG tail -f "$PIHOLELOG" >> ${DEBUG_LOG}
echo >> $DEBUG_LOG echo >> ${DEBUG_LOG}
done done
else else
echo "No pihole.log file found!" >> $DEBUG_LOG echo "No pihole.log file found!" >> ${DEBUG_LOG}
printf ":::\tNo pihole.log file found!\n" printf ":::\tNo pihole.log file found!\n"
fi fi
} }
@ -341,7 +338,16 @@ function dumpPiHoleLog {
# Anything to be done after capturing of pihole.log terminates # Anything to be done after capturing of pihole.log terminates
function finalWork { function finalWork {
echo "::: Finshed debugging!" echo "::: Finshed debugging!"
echo "::: The degug log can be uploaded to Termbin.com for easier sharing."
read -r -p "::: Would you like to upload the log? [y/N] " response
case ${response} in
[yY][eE][sS]|[yY])
TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999)
;;
*)
echo "::: Log will NOT be uploaded to Termbin."
;;
esac
# Check if termbin.com is reachable. When it's not, point to local log instead # Check if termbin.com is reachable. When it's not, point to local log instead
if [ -n "$TERMBIN" ] if [ -n "$TERMBIN" ]
@ -351,6 +357,7 @@ function finalWork {
echo "::: Debug log can be found at : /var/log/pihole_debug.log" echo "::: Debug log can be found at : /var/log/pihole_debug.log"
fi fi
} }
trap finalWork EXIT trap finalWork EXIT
### Method calls for additional logging ### ### Method calls for additional logging ###

View file

@ -44,12 +44,12 @@ getInitSys() {
# https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285 # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285
autoLoginPiToConsole() { autoLoginPiToConsole() {
if [ -e /etc/init.d/lightdm ]; then if [ -e /etc/init.d/lightdm ]; then
if [ $SYSTEMD -eq 1 ]; then if [ ${SYSTEMD} -eq 1 ]; then
$SUDO systemctl set-default multi-user.target ${SUDO} systemctl set-default multi-user.target
$SUDO ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service ${SUDO} ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service
else else
$SUDO update-rc.d lightdm disable 2 ${SUDO} update-rc.d lightdm disable 2
$SUDO sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/" ${SUDO} sed /etc/inittab -i -e "s/1:2345:respawn:\/sbin\/getty --noclear 38400 tty1/1:2345:respawn:\/bin\/login -f pi tty1 <\/dev\/tty1 >\/dev\/tty1 2>&1/"
fi fi
fi fi
} }
@ -66,23 +66,23 @@ echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc
# Set up the LCD screen based on Adafruits instuctions: # Set up the LCD screen based on Adafruits instuctions:
# https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install # https://learn.adafruit.com/adafruit-pitft-28-inch-resistive-touchscreen-display-raspberry-pi/easy-install
curl -SLs https://apt.adafruit.com/add-pin | $SUDO bash curl -SLs https://apt.adafruit.com/add-pin | ${SUDO} bash
$SUDO apt-get -y install raspberrypi-bootloader ${SUDO} apt-get -y install raspberrypi-bootloader
$SUDO apt-get -y install adafruit-pitft-helper ${SUDO} apt-get -y install adafruit-pitft-helper
$SUDO adafruit-pitft-helper -t 28r ${SUDO} adafruit-pitft-helper -t 28r
# Download the cmdline.txt file that prevents the screen from going blank after a period of time # Download the cmdline.txt file that prevents the screen from going blank after a period of time
$SUDO mv /boot/cmdline.txt /boot/cmdline.orig ${SUDO} mv /boot/cmdline.txt /boot/cmdline.orig
$SUDO curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt ${SUDO} curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt
# Back up the original file and download the new one # Back up the original file and download the new one
$SUDO mv /etc/default/console-setup /etc/default/console-setup.orig ${SUDO} mv /etc/default/console-setup /etc/default/console-setup.orig
$SUDO curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup ${SUDO} curl -o /etc/default/console-setup https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/console-setup
# Instantly apply the font change to the LCD screen # Instantly apply the font change to the LCD screen
$SUDO setupcon ${SUDO} setupcon
$SUDO reboot ${SUDO} reboot
# Start showing the stats on the screen by running the command on another tty: # Start showing the stats on the screen by running the command on another tty:
# http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty # http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty

View file

@ -55,7 +55,7 @@ is_repo() {
# replaces it with the current master branch from github # replaces it with the current master branch from github
make_repo() { make_repo() {
# remove the non-repod interface and clone the interface # remove the non-repod interface and clone the interface
rm -rf $WEB_INTERFACE_DIR rm -rf ${WEB_INTERFACE_DIR}
git clone "$WEB_INTERFACE_GIT_URL" "$WEB_INTERFACE_DIR" git clone "$WEB_INTERFACE_GIT_URL" "$WEB_INTERFACE_DIR"
} }

View file

@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Pi-hole: A black hole for Internet advertisements
# (c) 2015, 2016 by Jacob Salmela
# Network-wide ad blocking via your Raspberry Pi
# http://pi-hole.net
# Whitelists domains
#
# Pi-hole is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
piholeVersion=$(cd /etc/.pihole/ && git describe --tags --abbrev=0)
webVersion=$(cd /var/www/html/admin/ && git describe --tags --abbrev=0)
piholeVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/pi-hole/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
webVersionLatest=$(curl -s https://api.github.com/repos/pi-hole/AdminLTE/releases/latest | grep -Po '"tag_name":.*?[^\\]",' | perl -pe 's/"tag_name": "//; s/^"//; s/",$//')
echo "::: Pi-hole version is $piholeVersion (Latest version is $piholeVersionLatest)"
echo "::: Web-Admin version is $webVersion (Latest version is $webVersionLatest)"

View file

@ -47,9 +47,9 @@ fi
#globals #globals
basename=pihole basename=pihole
piholeDir=/etc/$basename piholeDir=/etc/${basename}
adList=$piholeDir/gravity.list adList=${piholeDir}/gravity.list
whitelist=$piholeDir/whitelist.txt whitelist=${piholeDir}/whitelist.txt
reload=true reload=true
addmode=true addmode=true
force=false force=false
@ -61,9 +61,9 @@ domToRemoveList=()
piholeIPfile=/etc/pihole/piholeIP piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6 piholeIPv6file=/etc/pihole/.useIPv6
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
piholeIP=$(cat $piholeIPfile) piholeIP=$(cat ${piholeIPfile})
#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
@ -75,12 +75,12 @@ fi
modifyHost=false modifyHost=false
# 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..."
. $piholeDir/pihole.conf . ${piholeDir}/pihole.conf
fi fi
if [[ -f $piholeIPv6file ]];then if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer # If the file exists, then the user previously chose to use IPv6 in the automated installer
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi
@ -91,18 +91,18 @@ function HandleOther(){
if [ -z "$validDomain" ]; then if [ -z "$validDomain" ]; then
echo "::: $1 is not a valid argument or domain name" echo "::: $1 is not a valid argument or domain name"
else else
domList=("${domList[@]}" $validDomain) domList=("${domList[@]}" ${validDomain})
fi fi
} }
function PopWhitelistFile(){ function PopWhitelistFile(){
#check whitelist file exists, and if not, create it #check whitelist file exists, and if not, create it
if [[ ! -f $whitelist ]];then if [[ ! -f ${whitelist} ]];then
touch $whitelist touch ${whitelist}
fi fi
for dom in "${domList[@]}" for dom in "${domList[@]}"
do do
if $addmode; then if ${addmode}; then
AddDomain "$dom" AddDomain "$dom"
else else
RemoveDomain "$dom" RemoveDomain "$dom"
@ -114,19 +114,19 @@ function AddDomain(){
#| sed 's/\./\\./g' #| sed 's/\./\\./g'
bool=false bool=false
grep -Ex -q "$1" $whitelist || bool=true grep -Ex -q "$1" ${whitelist} || bool=true
if $bool; then if ${bool}; then
#domain not found in the whitelist file, add it! #domain not found in the whitelist file, add it!
if $verbose; then if ${verbose}; then
echo -n "::: Adding $1 to $whitelist..." echo -n "::: Adding $1 to $whitelist..."
fi fi
echo "$1" >> $whitelist echo "$1" >> ${whitelist}
modifyHost=true modifyHost=true
if $verbose; then if ${verbose}; then
echo " done!" echo " done!"
fi fi
else else
if $verbose; then if ${verbose}; then
echo "::: $1 already exists in $whitelist, no need to add!" echo "::: $1 already exists in $whitelist, no need to add!"
fi fi
fi fi
@ -135,10 +135,10 @@ function AddDomain(){
function RemoveDomain(){ function RemoveDomain(){
bool=false bool=false
grep -Ex -q "$1" $whitelist || bool=true grep -Ex -q "$1" ${whitelist} || bool=true
if $bool; then if ${bool}; then
#Domain is not in the whitelist file, no need to Remove #Domain is not in the whitelist file, no need to Remove
if $verbose; then if ${verbose}; then
echo "::: $1 is NOT whitelisted! No need to remove" echo "::: $1 is NOT whitelisted! No need to remove"
fi fi
else else
@ -152,21 +152,21 @@ function RemoveDomain(){
} }
function ModifyHostFile(){ function ModifyHostFile(){
if $addmode; then if ${addmode}; then
#remove domains in from hosts file #remove domains in from hosts file
if [[ -r $whitelist ]];then 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
echo ":::" echo ":::"
echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..." echo -n "::: Modifying HOSTS file to whitelist $numberOf domain${plural}..."
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 "$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 awk -F':' '{print $1}' ${whitelist} | while read -r line; do echo "$piholeIPv6 $line"; done >> /etc/pihole/whitelist.tmp
echo "l" >> /etc/pihole/whitelist.tmp echo "l" >> /etc/pihole/whitelist.tmp
grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp
rm $adList rm ${adList}
mv $piholeDir/gravity.tmp $adList mv ${piholeDir}/gravity.tmp ${adList}
rm $piholeDir/whitelist.tmp rm ${piholeDir}/whitelist.tmp
echo " done!" echo " done!"
fi fi
@ -176,17 +176,20 @@ function ModifyHostFile(){
echo "::: Modifying HOSTS file to un-whitelist domains..." echo "::: Modifying HOSTS file to un-whitelist domains..."
for rdom in "${domToRemoveList[@]}" for rdom in "${domToRemoveList[@]}"
do do
if [[ -n $piholeIPv6 ]];then if grep -q "$rdom" /etc/pihole/*.domains; then
echo -n "::: Un-whitelisting $rdom on IPv4 and IPv6..." echo "::: AdLists contain $rdom, re-adding block"
echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList if [[ -n ${piholeIPv6} ]];then
echo -n "::: Restoring block for $rdom on IPv4 and IPv6..."
echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList}
echo " done!" echo " done!"
else else
echo -n "::: Un-whitelisting $rdom on IPv4" echo -n "::: Restoring block for $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!" echo " done!"
fi fi
fi
echo -n "::: Removing $rdom from $whitelist..." echo -n "::: Removing $rdom from $whitelist..."
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!" echo " done!"
done done
fi fi
@ -198,12 +201,12 @@ function Reload() {
echo -n "::: Refresh lists in dnsmasq..." echo -n "::: Refresh lists in dnsmasq..."
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
if [[ $dnsmasqPid ]]; then if [[ ${dnsmasqPid} ]]; then
# service already running - reload config # service already running - reload config
$SUDO killall -s HUP dnsmasq ${SUDO} killall -s HUP dnsmasq
else else
# service not running, start it up # service not running, start it up
$SUDO service dnsmasq start ${SUDO} service dnsmasq start
fi fi
echo " done!" echo " done!"
} }
@ -236,16 +239,16 @@ done
PopWhitelistFile PopWhitelistFile
if $modifyHost || $force; then if ${modifyHost} || ${force}; then
ModifyHostFile ModifyHostFile
else else
if $verbose; then if ${verbose}; then
echo ":::" echo ":::"
echo "::: No changes need to be made" echo "::: No changes need to be made"
fi fi
exit 1 exit 1
fi fi
if $reload; then if ${reload}; then
Reload Reload
fi fi

View file

@ -1,4 +1,7 @@
<html> <html>
<head>
<script>window.close();</script>
</head>
<body> <body>
</body> </body>
</html> </html>

View file

@ -19,14 +19,17 @@
######## VARIABLES ######### ######## VARIABLES #########
tmpLog=/tmp/pihole-install.log tmpLog=/tmp/pihole-install.log
instalLogLoc=/etc/pihole/install.log instalLogLoc=/etc/pihole/install.log
setupVars=/etc/pihole/setupVars.conf
webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git"
webInterfaceDir="/var/www/html/admin" webInterfaceDir="/var/www/html/admin"
piholeGitUrl="https://github.com/pi-hole/pi-hole.git" piholeGitUrl="https://github.com/pi-hole/pi-hole.git"
piholeFilesDir="/etc/.pihole" piholeFilesDir="/etc/.pihole"
useUpdateVars=false
# Find the rows and columns # Find the rows and columns
rows=$(tput lines) rows=$(tput lines)
@ -53,7 +56,7 @@ else
fi fi
fi fi
# Compatability # Compatibility
if [ -x "$(command -v rpm)" ];then if [ -x "$(command -v rpm)" ];then
# Fedora Family # Fedora Family
if [ -x "$(command -v dnf)" ];then if [ -x "$(command -v dnf)" ];then
@ -67,7 +70,7 @@ if [ -x "$(command -v rpm)" ];then
PKG_INSTALL="$PKG_MANAGER install -y" PKG_INSTALL="$PKG_MANAGER install -y"
PKG_COUNT="$PKG_MANAGER check-update | grep -v ^Last | grep -c ^[a-zA-Z0-9]" PKG_COUNT="$PKG_MANAGER check-update | grep -v ^Last | grep -c ^[a-zA-Z0-9]"
INSTALLER_DEPS=( iproute net-tools procps-ng newt ) INSTALLER_DEPS=( iproute net-tools procps-ng newt )
PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php git curl unzip wget findutils cronie sudo netcat ) PIHOLE_DEPS=( epel-release bind-utils bc dnsmasq lighttpd lighttpd-fastcgi php-common php-cli php git curl unzip wget findutils cronie sudo nmap-ncat )
LIGHTTPD_USER="lighttpd" LIGHTTPD_USER="lighttpd"
LIGHTTPD_GROUP="lighttpd" LIGHTTPD_GROUP="lighttpd"
LIGHTTPD_CFG="lighttpd.conf.fedora" LIGHTTPD_CFG="lighttpd.conf.fedora"
@ -104,8 +107,8 @@ spinner()
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
local temp=${spinstr#?} local temp=${spinstr#?}
printf " [%c] " "$spinstr" printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"} local spinstr=${temp}${spinstr%"$temp"}
sleep $delay sleep ${delay}
printf "\b\b\b\b\b\b" printf "\b\b\b\b\b\b"
done done
printf " \b\b\b\b" printf " \b\b\b\b"
@ -119,69 +122,64 @@ findIPRoute() {
availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1 | cut -d'@' -f1) availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1 | cut -d'@' -f1)
} }
backupLegacyPihole() {
# This function detects and backups the pi-hole v1 files. It will not do anything to the current version files.
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")"
if [ ! -d /opt/pihole ]; then
$SUDO mkdir /opt/pihole
$SUDO chown "$USER":root /opt/pihole
$SUDO chmod u+srwx /opt/pihole
fi
$SUDO mv /opt/pihole/gravity.sh /etc/pihole/original/gravity.sh."$(date "+%Y-%m-%d")"
else
:
fi
}
welcomeDialogs() { welcomeDialogs() {
# Display the welcome dialog # Display the welcome dialog
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" $r $c whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer" "This installer will transform your Raspberry Pi into a network-wide ad blocker!" ${r} ${c}
# Support for a part-time dev # Support for a part-time dev
whiptail --msgbox --backtitle "Plea" --title "Free and open source" "The Pi-hole is free, but powered by your donations: http://pi-hole.net/donate" $r $c whiptail --msgbox --backtitle "Plea" --title "Free and open source" "The Pi-hole is free, but powered by your donations: http://pi-hole.net/donate" ${r} ${c}
# Explain the need for a static address # Explain the need for a static address
whiptail --msgbox --backtitle "Initating network interface" --title "Static IP Needed" "The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly. whiptail --msgbox --backtitle "Initiating network interface" --title "Static IP Needed" "The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them." $r $c In the next section, you can choose to use your current network settings (DHCP) or to manually edit them." ${r} ${c}
} }
verifyFreeDiskSpace() { verifyFreeDiskSpace() {
# 50MB is the minimum space needed (45MB install (includes web admin bootstrap/jquery libraries etc) + 5MB one day of logs.)
requiredFreeBytes=51200
existingFreeBytes=$(df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1) # 50MB is the minimum space needed (45MB install (includes web admin bootstrap/jquery libraries etc) + 5MB one day of logs.)
if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then # - Fourdee: Local ensures the variable is only created, and accessible within this function/void. Generally considered a "good" coding practice for non-global variables.
existingFreeBytes=$(df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1) local required_free_kilobytes=51200
local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}')
# - Unknown free disk space , not a integer
if ! [[ "$existing_free_kilobytes" =~ ^([0-9])+$ ]]; then
whiptail --title "Unknown free disk space" --yesno "We were unable to determine available free disk space on this system.\n\nYou may override this check and force the installation, however, it is not recommended.\n\nWould you like to continue with the installation?" --defaultno --backtitle "Pi-hole" ${r} ${c}
local choice=$?
if (( $choice != 0 )); then
echo "non-integer value from existing_free_kilobytes ($existing_free_kilobytes)"
echo "Unknown free space, user aborted, exiting..."
exit 1
fi fi
if [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then # - Insufficient free disk space
whiptail --msgbox --backtitle "Insufficient Disk Space" --title "Insufficient Disk Space" "\nYour system appears to be low on disk space. pi-hole recomends a minimum of $requiredFreeBytes Bytes.\nYou only have $existingFreeBytes Free.\n\nIf this is a new install you may need to expand your disk.\n\nTry running:\n 'sudo raspi-config'\nChoose the 'expand file system option'\n\nAfter rebooting, run this installation again.\n\ncurl -L install.pi-hole.net | bash\n" $r $c elif [[ $existing_free_kilobytes -lt $required_free_kilobytes ]]; then
echo "$existingFreeBytes is less than $requiredFreeBytes"
whiptail --msgbox --backtitle "Insufficient Disk Space" --title "Insufficient Disk Space" "\nYour system appears to be low on disk space. pi-hole recomends a minimum of $required_free_kilobytes KiloBytes.\nYou only have $existing_free_kilobytes KiloBytes free.\n\nIf this is a new install you may need to expand your disk.\n\nTry running:\n 'sudo raspi-config'\nChoose the 'expand file system option'\n\nAfter rebooting, run this installation again.\n\ncurl -L install.pi-hole.net | bash\n" $r $c
echo "$existing_free_kilobytes is less than $required_free_kilobytes"
echo "Insufficient free space, exiting..." echo "Insufficient free space, exiting..."
exit 1 exit 1
fi fi
} }
chooseInterface() { chooseInterface() {
# Turn the available interfaces into an array so it can be used with a whiptail dialog # Turn the available interfaces into an array so it can be used with a whiptail dialog
interfacesArray=() interfacesArray=()
firstloop=1 firstLoop=1
while read -r line while read -r line
do do
mode="OFF" mode="OFF"
if [[ $firstloop -eq 1 ]]; then if [[ ${firstLoop} -eq 1 ]]; then
firstloop=0 firstLoop=0
mode="ON" mode="ON"
fi fi
interfacesArray+=("$line" "available" "$mode") interfacesArray+=("$line" "available" "$mode")
@ -189,12 +187,12 @@ chooseInterface() {
# Find out how many interfaces are available to choose from # Find out how many interfaces are available to choose from
interfaceCount=$(echo "$availableInterfaces" | wc -l) interfaceCount=$(echo "$availableInterfaces" | wc -l)
chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface" $r $c $interfaceCount) chooseInterfaceCmd=(whiptail --separate-output --radiolist "Choose An Interface" ${r} ${c} ${interfaceCount})
chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty) chooseInterfaceOptions=$("${chooseInterfaceCmd[@]}" "${interfacesArray[@]}" 2>&1 >/dev/tty)
if [[ $? = 0 ]]; then if [[ $? = 0 ]]; then
for desiredInterface in $chooseInterfaceOptions for desiredInterface in ${chooseInterfaceOptions}
do do
piholeInterface=$desiredInterface piholeInterface=${desiredInterface}
echo "::: Using interface: $piholeInterface" echo "::: Using interface: $piholeInterface"
echo "${piholeInterface}" > /tmp/piholeINT echo "${piholeInterface}" > /tmp/piholeINT
done done
@ -214,38 +212,38 @@ cleanupIPv6() {
use4andor6() { use4andor6() {
# Let use select IPv4 and/or IPv6 # Let use select IPv4 and/or IPv6
cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" $r $c 2) cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)" ${r} ${c} 2)
options=(IPv4 "Block ads over IPv4" on options=(IPv4 "Block ads over IPv4" on
IPv6 "Block ads over IPv6" off) IPv6 "Block ads over IPv6" off)
choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
if [[ $? = 0 ]];then if [[ $? = 0 ]];then
for choice in $choices for choice in ${choices}
do do
case $choice in case ${choice} in
IPv4 ) useIPv4=true;; IPv4 ) useIPv4=true;;
IPv6 ) useIPv6=true;; IPv6 ) useIPv6=true;;
esac esac
done done
if [ $useIPv4 ] && [ ! $useIPv6 ]; then if [ ${useIPv4} ] && [ ! ${useIPv6} ]; then
getStaticIPv4Settings getStaticIPv4Settings
setStaticIPv4 setStaticIPv4
echo "::: Using IPv4 on $IPv4addr" echo "::: Using IPv4 on $IPv4addr"
echo "::: IPv6 will NOT be used." echo "::: IPv6 will NOT be used."
fi fi
if [ ! $useIPv4 ] && [ $useIPv6 ]; then if [ ! ${useIPv4} ] && [ ${useIPv6} ]; then
useIPv6dialog useIPv6dialog
echo "::: IPv4 will NOT be used." echo "::: IPv4 will NOT be used."
echo "::: Using IPv6 on $piholeIPv6" echo "::: Using IPv6 on $piholeIPv6"
fi fi
if [ $useIPv4 ] && [ $useIPv6 ]; then if [ ${useIPv4} ] && [ ${useIPv6} ]; then
getStaticIPv4Settings getStaticIPv4Settings
setStaticIPv4 setStaticIPv4
useIPv6dialog useIPv6dialog
echo "::: Using IPv4 on $IPv4addr" echo "::: Using IPv4 on $IPv4addr"
echo "::: Using IPv6 on $piholeIPv6" echo "::: Using IPv6 on $piholeIPv6"
fi fi
if [ ! $useIPv4 ] && [ ! $useIPv6 ]; then if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then
echo "::: Cannot continue, neither IPv4 or IPv6 selected" echo "::: Cannot continue, neither IPv4 or IPv6 selected"
echo "::: Exiting" echo "::: Exiting"
exit 1 exit 1
@ -260,41 +258,41 @@ use4andor6() {
useIPv6dialog() { useIPv6dialog() {
# Show the IPv6 address used for blocking # Show the IPv6 address used for blocking
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." $r $c whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." ${r} ${c}
$SUDO touch /etc/pihole/.useIPv6 ${SUDO} touch /etc/pihole/.useIPv6
} }
getStaticIPv4Settings() { getStaticIPv4Settings() {
# Ask if the user wants to use DHCP settings as their static IP # Ask if the user wants to use DHCP settings as their static IP
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
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.
If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want. If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.
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}
#piholeIP is saved to a permanent file so gravity.sh can use it when updating #piholeIP is saved to a permanent file so gravity.sh can use it when updating
$SUDO echo "${IPv4addr%/*}" > /etc/pihole/piholeIP ${SUDO} echo "${IPv4addr%/*}" > /etc/pihole/piholeIP
# Nothing else to do since the variables are already set above # Nothing else to do since the variables are already set above
else else
# 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
until [[ $ipSettingsCorrect = True ]] until [[ ${ipSettingsCorrect} = True ]]
do do
# Ask for the IPv4 address # 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 if [[ $? = 0 ]];then
echo "::: Your static IPv4 address: $IPv4addr" echo "::: Your static IPv4 address: $IPv4addr"
# 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
echo "::: Your static IPv4 gateway: $IPv4gw" echo "::: Your static IPv4 gateway: $IPv4gw"
# 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
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. piholeIP is saved to a permanent file so gravity.sh can use it when updating # Saving it to a temporary file us to retrieve it later when we run the gravity.sh script. piholeIP is saved to a permanent file so gravity.sh can use it when updating
$SUDO echo "${IPv4addr%/*}" > /etc/pihole/piholeIP $SUDO echo "${IPv4addr%/*}" > /etc/pihole/piholeIP
@ -324,10 +322,10 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
setDHCPCD() { setDHCPCD() {
# Append these lines to dhcpcd.conf to enable a static IP # Append these lines to dhcpcd.conf to enable a static IP
echo "::: interface $piholeInterface echo "## interface $piholeInterface
static ip_address=$IPv4addr static ip_address=$IPv4addr
static routers=$IPv4gw static routers=$IPv4gw
static domain_name_servers=$IPv4gw" | $SUDO tee -a /etc/dhcpcd.conf >/dev/null static domain_name_servers=$IPv4gw" | ${SUDO} tee -a /etc/dhcpcd.conf >/dev/null
} }
setStaticIPv4() { setStaticIPv4() {
@ -337,33 +335,33 @@ setStaticIPv4() {
echo "::: Static IP already configured" echo "::: Static IP already configured"
else else
setDHCPCD setDHCPCD
$SUDO ip addr replace dev "$piholeInterface" "$IPv4addr" ${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr"
echo ":::" echo ":::"
echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
echo ":::" echo ":::"
fi fi
elif [[ -f /etc/sysconfig/network-scripts/ifcfg-$piholeInterface ]];then elif [[ -f /etc/sysconfig/network-scripts/ifcfg-${piholeInterface} ]];then
# Fedora Family # Fedora Family
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-$piholeInterface IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${piholeInterface}
if grep -q "$IPv4addr" $IFCFG_FILE; then if grep -q "$IPv4addr" ${IFCFG_FILE}; then
echo "::: Static IP already configured" echo "::: Static IP already configured"
else else
IPADDR=$(echo $IPv4addr | cut -f1 -d/) IPADDR=$(echo ${IPv4addr} | cut -f1 -d/)
CIDR=$(echo $IPv4addr | cut -f2 -d/) CIDR=$(echo ${IPv4addr} | cut -f2 -d/)
# Backup existing interface configuration: # Backup existing interface configuration:
cp $IFCFG_FILE $IFCFG_FILE.backup-$(date +%Y-%m-%d-%H%M%S) cp ${IFCFG_FILE} ${IFCFG_FILE}.backup-$(date +%Y-%m-%d-%H%M%S)
# Build Interface configuration file: # Build Interface configuration file:
$SUDO echo "# Configured via Pi-Hole installer" > $IFCFG_FILE ${SUDO} echo "# Configured via Pi-Hole installer" > ${IFCFG_FILE}
$SUDO echo "DEVICE=$piholeInterface" >> $IFCFG_FILE ${SUDO} echo "DEVICE=$piholeInterface" >> ${IFCFG_FILE}
$SUDO echo "BOOTPROTO=none" >> $IFCFG_FILE ${SUDO} echo "BOOTPROTO=none" >> ${IFCFG_FILE}
$SUDO echo "ONBOOT=yes" >> $IFCFG_FILE ${SUDO} echo "ONBOOT=yes" >> ${IFCFG_FILE}
$SUDO echo "IPADDR=$IPADDR" >> $IFCFG_FILE ${SUDO} echo "IPADDR=$IPADDR" >> ${IFCFG_FILE}
$SUDO echo "PREFIX=$CIDR" >> $IFCFG_FILE ${SUDO} echo "PREFIX=$CIDR" >> ${IFCFG_FILE}
$SUDO echo "USERCTL=no" >> $IFCFG_FILE ${SUDO} echo "USERCTL=no" >> ${IFCFG_FILE}
$SUDO ip addr replace dev "$piholeInterface" "$IPv4addr" ${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr"
if [ -x "$(command -v nmcli)" ];then if [ -x "$(command -v nmcli)" ];then
# Tell NetworkManager to read our new sysconfig file # Tell NetworkManager to read our new sysconfig file
$SUDO nmcli con load $IFCFG_FILE > /dev/null ${SUDO} nmcli con load ${IFCFG_FILE} > /dev/null
fi fi
echo ":::" echo ":::"
echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
@ -381,20 +379,20 @@ function valid_ip()
local ip=$1 local ip=$1
local stat=1 local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then if [[ ${ip} =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS OIFS=$IFS
IFS='.' IFS='.'
ip=($ip) ip=(${ip})
IFS=$OIFS IFS=${OIFS}
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$? stat=$?
fi fi
return $stat return ${stat}
} }
setDNS(){ setDNS(){
DNSChoseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." $r $c 6) DNSChoseCmd=(whiptail --separate-output --radiolist "Select Upstream DNS Provider. To use your own, select Custom." ${r} ${c} 6)
DNSChooseOptions=(Google "" on DNSChooseOptions=(Google "" on
OpenDNS "" off OpenDNS "" off
Level3 "" off Level3 "" off
@ -403,7 +401,7 @@ setDNS(){
Custom "" off) Custom "" off)
DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty)
if [[ $? = 0 ]];then if [[ $? = 0 ]];then
case $DNSchoices in case ${DNSchoices} in
Google) Google)
echo "::: Using Google DNS servers." echo "::: Using Google DNS servers."
piholeDNS1="8.8.8.8" piholeDNS1="8.8.8.8"
@ -430,45 +428,45 @@ setDNS(){
piholeDNS2="8.20.247.20" piholeDNS2="8.20.247.20"
;; ;;
Custom) Custom)
until [[ $DNSSettingsCorrect = True ]] until [[ ${DNSSettingsCorrect} = True ]]
do do
strInvalid="Invalid" strInvalid="Invalid"
if [ ! $piholeDNS1 ]; then if [ ! ${piholeDNS1} ]; then
if [ ! $piholeDNS2 ]; then if [ ! ${piholeDNS2} ]; then
prePopulate="" prePopulate=""
else else
prePopulate=", $piholeDNS2" prePopulate=", $piholeDNS2"
fi fi
elif [ $piholeDNS1 ] && [ ! $piholeDNS2 ]; then elif [ ${piholeDNS1} ] && [ ! ${piholeDNS2} ]; then
prePopulate="$piholeDNS1" prePopulate="$piholeDNS1"
elif [ $piholeDNS1 ] && [ $piholeDNS2 ]; then elif [ ${piholeDNS1} ] && [ ${piholeDNS2} ]; then
prePopulate="$piholeDNS1, $piholeDNS2" prePopulate="$piholeDNS1, $piholeDNS2"
fi fi
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) 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 if [[ $? = 0 ]];then
piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}')
piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}')
if ! valid_ip "$piholeDNS1" || [ ! "$piholeDNS1" ]; then if ! valid_ip "$piholeDNS1" || [ ! "$piholeDNS1" ]; then
piholeDNS1=$strInvalid piholeDNS1=${strInvalid}
fi fi
if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then
piholeDNS2=$strInvalid piholeDNS2=${strInvalid}
fi fi
else else
echo "::: Cancel selected, exiting...." echo "::: Cancel selected, exiting...."
exit 1 exit 1
fi fi
if [[ $piholeDNS1 == "$strInvalid" ]] || [[ $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 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 if [[ ${piholeDNS1} == "$strInvalid" ]]; then
piholeDNS1="" piholeDNS1=""
fi fi
if [[ $piholeDNS2 == "$strInvalid" ]]; then if [[ ${piholeDNS2} == "$strInvalid" ]]; then
piholeDNS2="" piholeDNS2=""
fi fi
DNSSettingsCorrect=False DNSSettingsCorrect=False
else else
if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" $r $c) then if (whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2" ${r} ${c}); then
DNSSettingsCorrect=True DNSSettingsCorrect=True
else else
# If the settings are wrong, the loop continues # If the settings are wrong, the loop continues
@ -493,105 +491,106 @@ versionCheckDNSmasq(){
newFileToInstall="/etc/.pihole/advanced/01-pihole.conf" newFileToInstall="/etc/.pihole/advanced/01-pihole.conf"
newFileFinalLocation="/etc/dnsmasq.d/01-pihole.conf" newFileFinalLocation="/etc/dnsmasq.d/01-pihole.conf"
if [ -f $dnsFile1 ]; then if [ -f ${dnsFile1} ]; then
echo -n "::: Existing dnsmasq.conf found..." echo -n "::: Existing dnsmasq.conf found..."
if grep -q $dnsSearch $dnsFile1; then if grep -q ${dnsSearch} ${dnsFile1}; then
echo " it is from a previous pi-hole install." echo " it is from a previous pi-hole install."
echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..." echo -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..."
$SUDO mv -f $dnsFile1 $dnsFile2 ${SUDO} mv -f ${dnsFile1} ${dnsFile2}
echo " done." echo " done."
echo -n "::: Restoring default dnsmasq.conf..." echo -n "::: Restoring default dnsmasq.conf..."
$SUDO cp $defaultFile $dnsFile1 ${SUDO} cp ${defaultFile} ${dnsFile1}
echo " done." echo " done."
else else
echo " it is not a pi-hole file, leaving alone!" echo " it is not a pi-hole file, leaving alone!"
fi fi
else else
echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..." echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..."
$SUDO cp $defaultFile $dnsFile1 ${SUDO} cp ${defaultFile} ${dnsFile1}
echo " done." echo " done."
fi fi
echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..." echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..."
$SUDO cp $newFileToInstall $newFileFinalLocation ${SUDO} cp ${newFileToInstall} ${newFileFinalLocation}
echo " done." echo " done."
$SUDO sed -i "s/@INT@/$piholeInterface/" $newFileFinalLocation ${SUDO} sed -i "s/@INT@/$piholeInterface/" ${newFileFinalLocation}
if [[ "$piholeDNS1" != "" ]]; then if [[ "$piholeDNS1" != "" ]]; then
$SUDO sed -i "s/@DNS1@/$piholeDNS1/" $newFileFinalLocation ${SUDO} sed -i "s/@DNS1@/$piholeDNS1/" ${newFileFinalLocation}
else else
$SUDO sed -i '/^server=@DNS1@/d' $newFileFinalLocation ${SUDO} sed -i '/^server=@DNS1@/d' ${newFileFinalLocation}
fi fi
if [[ "$piholeDNS2" != "" ]]; then if [[ "$piholeDNS2" != "" ]]; then
$SUDO sed -i "s/@DNS2@/$piholeDNS2/" $newFileFinalLocation ${SUDO} sed -i "s/@DNS2@/$piholeDNS2/" ${newFileFinalLocation}
else else
$SUDO sed -i '/^server=@DNS2@/d' $newFileFinalLocation ${SUDO} sed -i '/^server=@DNS2@/d' ${newFileFinalLocation}
fi fi
$SUDO sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' $dnsFile1 ${SUDO} sed -i 's/^#conf-dir=\/etc\/dnsmasq.d$/conf-dir=\/etc\/dnsmasq.d/' ${dnsFile1}
} }
installScripts() { installScripts() {
# Install the scripts from /etc/.pihole to their various locations # Install the scripts from /etc/.pihole to their various locations
$SUDO echo ":::" ${SUDO} echo ":::"
$SUDO echo -n "::: Installing scripts to /opt/pihole..." ${SUDO} echo -n "::: Installing scripts to /opt/pihole..."
if [ ! -d /opt/pihole ]; then if [ ! -d /opt/pihole ]; then
$SUDO mkdir /opt/pihole ${SUDO} mkdir /opt/pihole
$SUDO chown "$USER":root /opt/pihole ${SUDO} chown "$USER":root /opt/pihole
$SUDO chmod u+srwx /opt/pihole ${SUDO} chmod u+srwx /opt/pihole
fi fi
$SUDO cp /etc/.pihole/gravity.sh /opt/pihole/gravity.sh ${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/chronometer.sh /opt/pihole/chronometer.sh
$SUDO cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/whitelist.sh /opt/pihole/whitelist.sh
$SUDO cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/blacklist.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/blacklist.sh /opt/pihole/blacklist.sh
$SUDO cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /opt/pihole/piholeDebug.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/piholeDebug.sh /opt/pihole/piholeDebug.sh
$SUDO cp /etc/.pihole/advanced/Scripts/piholeLogFlush.sh /opt/pihole/piholeLogFlush.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/advanced/Scripts/updateDashboard.sh /opt/pihole/updateDashboard.sh
$SUDO cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh ${SUDO} cp /etc/.pihole/automated\ install/uninstall.sh /opt/pihole/uninstall.sh
$SUDO cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh
$SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall,setupLCD}.sh ${SUDO} cp /etc/.pihole/advanced/Scripts/version.sh /opt/pihole/version.sh
$SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole ${SUDO} chmod 755 /opt/pihole/gravity.sh /opt/pihole/chronometer.sh /opt/pihole/whitelist.sh /opt/pihole/blacklist.sh /opt/pihole/piholeLogFlush.sh /opt/pihole/updateDashboard.sh /opt/pihole/uninstall.sh /opt/pihole/setupLCD.sh /opt/pihole/version.sh
$SUDO chmod 755 /usr/local/bin/pihole ${SUDO} cp /etc/.pihole/pihole /usr/local/bin/pihole
$SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole ${SUDO} chmod 755 /usr/local/bin/pihole
${SUDO} cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole
. /etc/bash_completion.d/pihole . /etc/bash_completion.d/pihole
#Tidy up /usr/local/bin directory if installing over previous install. #Tidy up /usr/local/bin directory if installing over previous install.
oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug)
for i in "${oldFiles[@]}"; do for i in "${oldFiles[@]}"; do
if [ -f "/usr/local/bin/$i.sh" ]; then if [ -f "/usr/local/bin/$i.sh" ]; then
$SUDO rm /usr/local/bin/"$i".sh ${SUDO} rm /usr/local/bin/"$i".sh
fi fi
done done
$SUDO echo " done." ${SUDO} echo " done."
} }
installConfigs() { installConfigs() {
# Install the configs from /etc/.pihole to their various locations # Install the configs from /etc/.pihole to their various locations
$SUDO echo ":::" ${SUDO} echo ":::"
$SUDO echo "::: Installing configs..." ${SUDO} echo "::: Installing configs..."
versionCheckDNSmasq versionCheckDNSmasq
if [ ! -d "/etc/lighttpd" ]; then if [ ! -d "/etc/lighttpd" ]; then
$SUDO mkdir /etc/lighttpd ${SUDO} mkdir /etc/lighttpd
$SUDO chown "$USER":root /etc/lighttpd ${SUDO} chown "$USER":root /etc/lighttpd
$SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig ${SUDO} mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig
fi fi
$SUDO cp /etc/.pihole/advanced/$LIGHTTPD_CFG /etc/lighttpd/lighttpd.conf ${SUDO} cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf
$SUDO mkdir -p /var/run/lighttpd ${SUDO} mkdir -p /var/run/lighttpd
$SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/run/lighttpd ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd
$SUDO mkdir -p /var/cache/lighttpd/compress ${SUDO} mkdir -p /var/cache/lighttpd/compress
$SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/cache/lighttpd/compress ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress
} }
stopServices() { stopServices() {
# Stop dnsmasq and lighttpd # Stop dnsmasq and lighttpd
$SUDO echo ":::" ${SUDO} echo ":::"
$SUDO echo -n "::: Stopping services..." ${SUDO} echo -n "::: Stopping services..."
#$SUDO service dnsmasq stop & spinner $! || true #$SUDO service dnsmasq stop & spinner $! || true
if [ -x "$(command -v systemctl)" ]; then if [ -x "$(command -v systemctl)" ]; then
$SUDO systemctl stop lighttpd & spinner $! || true ${SUDO} systemctl stop lighttpd & spinner $! || true
else else
$SUDO service lighttpd stop & spinner $! || true ${SUDO} service lighttpd stop & spinner $! || true
fi fi
$SUDO echo " done." ${SUDO} echo " done."
} }
installerDependencies() { installerDependencies() {
@ -601,7 +600,7 @@ installerDependencies() {
# if so, advise the user to run apt-get update/upgrade at their own discretion # if so, advise the user to run apt-get update/upgrade at their own discretion
#Check to see if apt-get update has already been run today #Check to see if apt-get update has already been run today
# it needs to have been run at least once on new installs! # it needs to have been run at least once on new installs!
timestamp=$(stat -c %Y $PKG_CACHE) timestamp=$(stat -c %Y ${PKG_CACHE})
timestampAsDate=$(date -d @"$timestamp" "+%b %e") timestampAsDate=$(date -d @"$timestamp" "+%b %e")
today=$(date "+%b %e") today=$(date "+%b %e")
@ -609,15 +608,15 @@ installerDependencies() {
#update package lists #update package lists
echo ":::" echo ":::"
echo -n "::: $PKG_MANAGER update has not been run today. Running now..." echo -n "::: $PKG_MANAGER update has not been run today. Running now..."
$SUDO $UPDATE_PKG_CACHE > /dev/null 2>&1 ${SUDO} ${UPDATE_PKG_CACHE} > /dev/null 2>&1
echo " done!" echo " done!"
fi fi
echo ":::" echo ":::"
echo -n "::: Checking $PKG_MANAGER for upgraded packages...." echo -n "::: Checking $PKG_MANAGER for upgraded packages...."
updatesToInstall=$(eval "$SUDO $PKG_COUNT") updatesToInstall=$(eval "${SUDO} ${PKG_COUNT}")
echo " done!" echo " done!"
echo ":::" echo ":::"
if [[ $updatesToInstall -eq "0" ]]; then if [[ ${updatesToInstall} -eq "0" ]]; then
echo "::: Your pi is up to date! Continuing with pi-hole installation..." echo "::: Your pi is up to date! Continuing with pi-hole installation..."
else else
echo "::: There are $updatesToInstall updates availible for your pi!" echo "::: There are $updatesToInstall updates availible for your pi!"
@ -628,10 +627,10 @@ installerDependencies() {
echo "::: Checking installer dependencies..." echo "::: Checking installer dependencies..."
for i in "${INSTALLER_DEPS[@]}"; do for i in "${INSTALLER_DEPS[@]}"; do
echo -n "::: Checking for $i..." echo -n "::: Checking for $i..."
package_check $i > /dev/null package_check ${i} > /dev/null
if ! [ $? -eq 0 ]; then if ! [ $? -eq 0 ]; then
echo -n " Not found! Installing...." echo -n " Not found! Installing...."
$SUDO $PKG_INSTALL "$i" > /dev/null 2>&1 ${SUDO} ${PKG_INSTALL} "$i" > /dev/null 2>&1
echo " done!" echo " done!"
else else
echo " already installed!" echo " already installed!"
@ -645,10 +644,10 @@ checkForDependencies() {
for i in "${PIHOLE_DEPS[@]}"; do for i in "${PIHOLE_DEPS[@]}"; do
echo -n "::: Checking for $i..." echo -n "::: Checking for $i..."
package_check $i > /dev/null package_check ${i} > /dev/null
if ! [ $? -eq 0 ]; then if ! [ $? -eq 0 ]; then
echo -n " Not found! Installing...." echo -n " Not found! Installing...."
$SUDO $PKG_INSTALL "$i" > /dev/null & spinner $! ${SUDO} ${PKG_INSTALL} "$i" > /dev/null & spinner $!
echo " done!" echo " done!"
else else
echo " already installed!" echo " already installed!"
@ -660,18 +659,18 @@ getGitFiles() {
# Setup git repos for base files and web admin # Setup git repos for base files and web admin
echo ":::" echo ":::"
echo "::: Checking for existing base files..." echo "::: Checking for existing base files..."
if is_repo $piholeFilesDir; then if is_repo ${piholeFilesDir}; then
make_repo $piholeFilesDir $piholeGitUrl make_repo ${piholeFilesDir} ${piholeGitUrl}
else else
update_repo $piholeFilesDir update_repo ${piholeFilesDir}
fi fi
echo ":::" echo ":::"
echo "::: Checking for existing web interface..." echo "::: Checking for existing web interface..."
if is_repo $webInterfaceDir; then if is_repo ${webInterfaceDir}; then
make_repo $webInterfaceDir $webInterfaceGitUrl make_repo ${webInterfaceDir} ${webInterfaceGitUrl}
else else
update_repo $webInterfaceDir update_repo ${webInterfaceDir}
fi fi
} }
@ -689,8 +688,8 @@ is_repo() {
make_repo() { make_repo() {
# Remove the non-repod interface and clone the interface # Remove the non-repod interface and clone the interface
echo -n "::: Cloning $2 into $1..." echo -n "::: Cloning $2 into $1..."
$SUDO rm -rf "$1" ${SUDO} rm -rf "$1"
$SUDO git clone -q "$2" "$1" > /dev/null & spinner $! ${SUDO} git clone -q "$2" "$1" > /dev/null & spinner $!
echo " done!" echo " done!"
} }
@ -698,7 +697,7 @@ update_repo() {
# Pull the latest commits # Pull the latest commits
echo -n "::: Updating repo in $1..." echo -n "::: Updating repo in $1..."
cd "$1" || exit cd "$1" || exit
$SUDO git pull -q > /dev/null & spinner $! ${SUDO} git pull -q > /dev/null & spinner $!
echo " done!" echo " done!"
} }
@ -706,59 +705,59 @@ update_repo() {
CreateLogFile() { CreateLogFile() {
# Create logfiles if necessary # Create logfiles if necessary
echo ":::" echo ":::"
$SUDO echo -n "::: Creating log file and changing owner to dnsmasq..." ${SUDO} echo -n "::: Creating log file and changing owner to dnsmasq..."
if [ ! -f /var/log/pihole.log ]; then if [ ! -f /var/log/pihole.log ]; then
$SUDO touch /var/log/pihole.log ${SUDO} touch /var/log/pihole.log
$SUDO chmod 644 /var/log/pihole.log ${SUDO} chmod 644 /var/log/pihole.log
$SUDO chown dnsmasq:root /var/log/pihole.log ${SUDO} chown dnsmasq:root /var/log/pihole.log
$SUDO echo " done!" ${SUDO} echo " done!"
else else
$SUDO echo " already exists!" ${SUDO} echo " already exists!"
fi fi
} }
installPiholeWeb() { installPiholeWeb() {
# Install the web interface # Install the web interface
$SUDO echo ":::" ${SUDO} echo ":::"
$SUDO echo -n "::: Installing pihole custom index page..." ${SUDO} echo -n "::: Installing pihole custom index page..."
if [ -d "/var/www/html/pihole" ]; then if [ -d "/var/www/html/pihole" ]; then
$SUDO echo " Existing page detected, not overwriting" ${SUDO} echo " Existing page detected, not overwriting"
else else
$SUDO mkdir /var/www/html/pihole ${SUDO} mkdir /var/www/html/pihole
if [ -f /var/www/html/index.lighttpd.html ]; then if [ -f /var/www/html/index.lighttpd.html ]; then
$SUDO mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig ${SUDO} mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig
else else
printf "\n:::\tNo default index.lighttpd.html file found... not backing up" printf "\n:::\tNo default index.lighttpd.html file found... not backing up"
fi fi
$SUDO cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. ${SUDO} cp /etc/.pihole/advanced/index.* /var/www/html/pihole/.
$SUDO echo " done!" ${SUDO} echo " done!"
fi fi
# Install Sudoer file # Install Sudoer file
echo -n "::: Installing sudoer file..." echo -n "::: Installing sudoer file..."
$SUDO mkdir -p /etc/sudoers.d/ ${SUDO} mkdir -p /etc/sudoers.d/
$SUDO cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole ${SUDO} cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole
$SUDO chmod 0440 /etc/sudoers.d/pihole ${SUDO} chmod 0440 /etc/sudoers.d/pihole
echo " done!" echo " done!"
} }
installCron() { installCron() {
# Install the cron job # Install the cron job
$SUDO echo ":::" ${SUDO} echo ":::"
$SUDO echo -n "::: Installing latest Cron script..." ${SUDO} echo -n "::: Installing latest Cron script..."
$SUDO cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole ${SUDO} cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole
$SUDO echo " done!" ${SUDO} echo " done!"
} }
runGravity() { runGravity() {
# Rub gravity.sh to build blacklists # Rub gravity.sh to build blacklists
$SUDO echo ":::" ${SUDO} echo ":::"
$SUDO echo "::: Preparing to run gravity.sh to refresh hosts..." ${SUDO} echo "::: Preparing to run gravity.sh to refresh hosts..."
if ls /etc/pihole/list* 1> /dev/null 2>&1; then if ls /etc/pihole/list* 1> /dev/null 2>&1; then
echo "::: Cleaning up previous install (preserving whitelist/blacklist)" echo "::: Cleaning up previous install (preserving whitelist/blacklist)"
$SUDO rm /etc/pihole/list.* ${SUDO} rm /etc/pihole/list.*
fi fi
echo "::: Running gravity.sh" echo "::: Running gravity.sh"
$SUDO /opt/pihole/gravity.sh ${SUDO} /opt/pihole/gravity.sh
} }
setUser(){ setUser(){
@ -768,45 +767,58 @@ setUser(){
echo "::: User 'pihole' already exists" echo "::: User 'pihole' already exists"
else else
echo "::: User 'pihole' doesn't exist. Creating..." echo "::: User 'pihole' doesn't exist. Creating..."
$SUDO useradd -r -s /usr/sbin/nologin pihole ${SUDO} useradd -r -s /usr/sbin/nologin pihole
fi fi
} }
configureFirewall() { configureFirewall() {
# Allow HTTP and DNS traffic # Allow HTTP and DNS traffic
if [ -x "$(command -v firewall-cmd)" ]; then if [ -x "$(command -v firewall-cmd)" ]; then
$SUDO firewall-cmd --state > /dev/null ${SUDO} firewall-cmd --state > /dev/null
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
$SUDO echo "::: Configuring firewalld for httpd and dnsmasq.." ${SUDO} echo "::: Configuring firewalld for httpd and dnsmasq.."
$SUDO firewall-cmd --permanent --add-port=80/tcp ${SUDO} firewall-cmd --permanent --add-port=80/tcp
$SUDO firewall-cmd --permanent --add-port=53/tcp ${SUDO} firewall-cmd --permanent --add-port=53/tcp
$SUDO firewall-cmd --permanent --add-port=53/udp ${SUDO} firewall-cmd --permanent --add-port=53/udp
$SUDO firewall-cmd --reload ${SUDO} firewall-cmd --reload
fi fi
elif [ -x "$(command -v iptables)" ]; then elif [ -x "$(command -v iptables)" ]; then
$SUDO echo "::: Configuring iptables for httpd and dnsmasq.." ${SUDO} echo "::: Configuring iptables for httpd and dnsmasq.."
$SUDO iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT ${SUDO} iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
$SUDO iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT ${SUDO} iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
$SUDO iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT ${SUDO} iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT
else else
$SUDO echo "::: No firewall detected.. skipping firewall configuration." ${SUDO} echo "::: No firewall detected.. skipping firewall configuration."
fi fi
} }
finalExports() {
#If it already exists, lets overwrite it with the new values.
if [[ -f ${setupVars} ]];then
${SUDO} rm ${setupVars}
fi
${SUDO} echo "piholeInterface=${piholeInterface}" >> ${setupVars}
${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars}
${SUDO} echo "piholeIPv6=${piholeIPv6}" >> ${setupVars}
${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars}
${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars}
}
installPihole() { installPihole() {
# Install base files and web interface # Install base files and web interface
checkForDependencies # done checkForDependencies # done
stopServices stopServices
setUser setUser
$SUDO mkdir -p /etc/pihole/ ${SUDO} mkdir -p /etc/pihole/
if [ ! -d "/var/www/html" ]; then if [ ! -d "/var/www/html" ]; then
$SUDO mkdir -p /var/www/html ${SUDO} mkdir -p /var/www/html
fi fi
$SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/www/html ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html
$SUDO chmod 775 /var/www/html ${SUDO} chmod 775 /var/www/html
$SUDO usermod -a -G $LIGHTTPD_GROUP pihole ${SUDO} usermod -a -G ${LIGHTTPD_GROUP} pihole
if [ -x "$(command -v lighty-enable-mod)" ]; then if [ -x "$(command -v lighty-enable-mod)" ]; then
$SUDO lighty-enable-mod fastcgi fastcgi-php > /dev/null ${SUDO} lighty-enable-mod fastcgi fastcgi-php > /dev/null
else else
printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n"
fi fi
@ -814,6 +826,24 @@ installPihole() {
getGitFiles getGitFiles
installScripts installScripts
installConfigs installConfigs
installConfigs
CreateLogFile
configureSelinux
installPiholeWeb
installCron
runGravity
configureFirewall
finalExports
}
updatePihole() {
# Install base files and web interface
checkForDependencies # done
stopServices
getGitFiles
installScripts
installConfigs
installConfigs
CreateLogFile CreateLogFile
configureSelinux configureSelinux
installPiholeWeb installPiholeWeb
@ -829,22 +859,22 @@ configureSelinux() {
package_check "selinux-policy-devel" > /dev/null package_check "selinux-policy-devel" > /dev/null
if ! [ $? -eq 0 ]; then if ! [ $? -eq 0 ]; then
echo -n " Not found! Installing...." echo -n " Not found! Installing...."
$SUDO $PKG_INSTALL "selinux-policy-devel" > /dev/null & spinner $! ${SUDO} ${PKG_INSTALL} "selinux-policy-devel" > /dev/null & spinner $!
echo " done!" echo " done!"
else else
echo " already installed!" echo " already installed!"
fi fi
printf "::: Enabling httpd server side includes (SSI).. " printf "::: Enabling httpd server side includes (SSI).. "
$SUDO setsebool -P httpd_ssi_exec on ${SUDO} setsebool -P httpd_ssi_exec on
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo -n "Success\n" echo -n "Success\n"
fi fi
printf ":::\tCompiling Pi-Hole SELinux policy..\n" printf ":::\tCompiling Pi-Hole SELinux policy..\n"
$SUDO checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te ${SUDO} checkmodule -M -m -o /etc/pihole/pihole.mod /etc/.pihole/advanced/selinux/pihole.te
$SUDO semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod ${SUDO} semodule_package -o /etc/pihole/pihole.pp -m /etc/pihole/pihole.mod
$SUDO semodule -i /etc/pihole/pihole.pp ${SUDO} semodule -i /etc/pihole/pihole.pp
$SUDO rm -f /etc/pihole/pihole.mod ${SUDO} rm -f /etc/pihole/pihole.mod
$SUDO semodule -l | grep pihole > /dev/null ${SUDO} semodule -l | grep pihole > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
printf "::: Successfully installed Pi-Hole SELinux policy\n" printf "::: Successfully installed Pi-Hole SELinux policy\n"
else else
@ -863,61 +893,102 @@ IPv6: $piholeIPv6
If you set a new IP address, you should restart the Pi. If you set a new IP address, you should restart the Pi.
The install log is in /etc/pihole. The install log is in /etc/pihole.
View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" $r $c View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" ${r} ${c}
}
updateDialogs(){
UpdateCmd=(whiptail --separate-output --radiolist "We have detected an existing install.\n\n Selecting Update will retain settings from the existing install.\n\n Selecting Install will allow you to enter new settings.\n\n(Highlight desired option, and press space to select!)" ${r} ${c} 2)
UpdateChoices=(Update "" on
Install "" off)
UpdateChoice=$("${UpdateCmd[@]}" "${UpdateChoices[@]}" 2>&1 >/dev/tty)
if [[ $? = 0 ]];then
case ${UpdateChoice} in
Update)
echo "::: Updating existing install"
useUpdateVars=true
;;
Install)
echo "::: Running complete install script"
useUpdateVars=false
;;
esac
else
echo "::: Cancel selected. Exiting..."
exit 1
fi
} }
######## SCRIPT ############ ######## SCRIPT ############
# Start the installer if [[ -f ${setupVars} ]];then
$SUDO mkdir -p /etc/pihole/ . ${setupVars}
if [ "$1" == "pihole" ]; then
useUpdateVars=true
else
updateDialogs
fi
fi
# Start the installer
# Install packages used by this installation script # Install packages used by this installation script
installerDependencies installerDependencies
welcomeDialogs if [[ ${useUpdateVars} == false ]]; then
welcomeDialogs
# Verify there is enough disk space for the install
verifyFreeDiskSpace
${SUDO} mkdir -p /etc/pihole/
# Verify there is enough disk space for the install # Find IP used to route to outside world
verifyFreeDiskSpace findIPRoute
# Find interfaces and let the user choose one
# Just back up the original Pi-hole right away since it won't take long and it gets it out of the way chooseInterface
backupLegacyPihole # Let the user decide if they want to block ads over IPv4 and/or IPv6
# Find IP used to route to outside world use4andor6
findIPRoute # Decide what upstream DNS Servers to use
# Find interfaces and let the user choose one setDNS
chooseInterface # Install and log everything to a file
# Let the user decide if they want to block ads over IPv4 and/or IPv6 installPihole | tee ${tmpLog}
use4andor6 else
updatePihole | tee ${tmpLog}
# Decide what upstream DNS Servers to use fi
setDNS
# Install and log everything to a file
installPihole | tee $tmpLog
# Move the log file into /etc/pihole for storage # Move the log file into /etc/pihole for storage
$SUDO mv $tmpLog $instalLogLoc ${SUDO} mv ${tmpLog} ${instalLogLoc}
displayFinalMessage if [[ ${useUpdateVars} == false ]]; then
displayFinalMessage
fi
echo -n "::: Restarting services..." echo -n "::: Restarting services..."
# Start services # Start services
if [ -x "$(command -v systemctl)" ]; then if [ -x "$(command -v systemctl)" ]; then
$SUDO systemctl enable dnsmasq ${SUDO} systemctl enable dnsmasq
$SUDO systemctl restart dnsmasq ${SUDO} systemctl restart dnsmasq
$SUDO systemctl enable lighttpd ${SUDO} systemctl enable lighttpd
$SUDO systemctl start lighttpd ${SUDO} systemctl start lighttpd
else else
$SUDO service dnsmasq restart ${SUDO} service dnsmasq restart
$SUDO service lighttpd start ${SUDO} service lighttpd start
fi fi
echo " done." echo " done."
echo ":::" echo ":::"
echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" if [[ ${useUpdateVars} == false ]]; then
echo "::: ${IPv4addr%/*}" echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
echo "::: $piholeIPv6" echo "::: ${IPv4addr%/*}"
echo ":::" echo "::: $piholeIPv6"
echo "::: If you set a new IP address, you should restart the Pi." echo ":::"
echo "::: If you set a new IP address, you should restart the Pi."
else
echo "::: Update complete!"
fi
echo ":::" echo ":::"
echo "::: The install log is located at: /etc/pihole/install.log" echo "::: The install log is located at: /etc/pihole/install.log"
echo "::: View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" echo "::: View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin"

View file

@ -39,7 +39,7 @@ if [ -x "$(command -v rpm)" ];then
rpm -qa | grep ^$1- > /dev/null rpm -qa | grep ^$1- > /dev/null
} }
package_cleanup() { package_cleanup() {
$SUDO $PKG_MANAGER -y autoremove ${SUDO} ${PKG_MANAGER} -y autoremove
} }
elif [ -x "$(command -v apt-get)" ];then elif [ -x "$(command -v apt-get)" ];then
# Debian Family # Debian Family
@ -50,8 +50,8 @@ elif [ -x "$(command -v apt-get)" ];then
dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed" dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"
} }
package_cleanup() { package_cleanup() {
$SUDO $PKG_MANAGER -y autoremove ${SUDO} ${PKG_MANAGER} -y autoremove
$SUDO $PKG_MANAGER -y autoclean ${SUDO} ${PKG_MANAGER} -y autoclean
} }
else else
echo "OS distribution not supported" echo "OS distribution not supported"
@ -66,8 +66,8 @@ spinner()
while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do
local temp=${spinstr#?} local temp=${spinstr#?}
printf " [%c] " "$spinstr" printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"} local spinstr=${temp}${spinstr%"$temp"}
sleep $delay sleep ${delay}
printf "\b\b\b\b\b\b" printf "\b\b\b\b\b\b"
done done
printf " \b\b\b\b" printf " \b\b\b\b"
@ -77,12 +77,12 @@ function removeAndPurge {
# Purge dependencies # Purge dependencies
echo ":::" echo ":::"
for i in "${PIHOLE_DEPS[@]}"; do for i in "${PIHOLE_DEPS[@]}"; do
package_check $i > /dev/null package_check ${i} > /dev/null
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
while true; do while true; do
read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn
case $yn in case ${yn} in
[Yy]* ) printf ":::\tRemoving %s..." "$i"; $SUDO $PKG_REMOVE "$i" &> /dev/null & spinner $!; printf "done!\n"; break;; [Yy]* ) printf ":::\tRemoving %s..." "$i"; ${SUDO} ${PKG_REMOVE} "$i" &> /dev/null & spinner $!; printf "done!\n"; break;;
[Nn]* ) printf ":::\tSkipping %s" "$i\n"; break;; [Nn]* ) printf ":::\tSkipping %s" "$i\n"; break;;
* ) printf "::: You must answer yes or no!\n";; * ) printf "::: You must answer yes or no!\n";;
esac esac
@ -94,7 +94,7 @@ echo ":::"
# Remove dependency config files # Remove dependency config files
echo "::: Removing dnsmasq config files..." echo "::: Removing dnsmasq config files..."
$SUDO rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.conf /etc/dnsmasq.conf.orig /etc/dnsmasq.d/01-pihole.conf &> /dev/null
# Take care of any additional package cleaning # Take care of any additional package cleaning
printf "::: Auto removing & cleaning remaining dependencies..." printf "::: Auto removing & cleaning remaining dependencies..."
@ -108,14 +108,14 @@ function removeNoPurge {
echo ":::" echo ":::"
# Only web directories/files that are created by pihole should be removed. # Only web directories/files that are created by pihole should be removed.
echo "::: Removing the Pi-hole Web server files..." echo "::: Removing the Pi-hole Web server files..."
$SUDO rm -rf /var/www/html/admin &> /dev/null ${SUDO} rm -rf /var/www/html/admin &> /dev/null
$SUDO rm -rf /var/www/html/pihole &> /dev/null ${SUDO} rm -rf /var/www/html/pihole &> /dev/null
$SUDO rm /var/www/html/index.lighttpd.orig &> /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 the web directory is empty after removing these files, then the parent html folder can be removed.
if [ -d "/var/www/html" ]; then if [ -d "/var/www/html" ]; then
if [[ ! "$(ls -A /var/www/html)" ]]; then if [[ ! "$(ls -A /var/www/html)" ]]; then
$SUDO rm -rf /var/www/html &> /dev/null ${SUDO} rm -rf /var/www/html &> /dev/null
fi fi
fi fi
@ -125,36 +125,36 @@ function removeNoPurge {
# preserved. # preserved.
if [[ -f /etc/crontab.orig ]]; then if [[ -f /etc/crontab.orig ]]; then
echo "::: Initial Pi-hole cron detected. Restoring the default system cron..." echo "::: Initial Pi-hole cron detected. Restoring the default system cron..."
$SUDO mv /etc/crontab /etc/crontab.pihole ${SUDO} mv /etc/crontab /etc/crontab.pihole
$SUDO mv /etc/crontab.orig /etc/crontab ${SUDO} mv /etc/crontab.orig /etc/crontab
$SUDO service cron restart ${SUDO} service cron restart
fi fi
# Attempt to preserve backwards compatibility with older versions # Attempt to preserve backwards compatibility with older versions
if [[ -f /etc/cron.d/pihole ]];then if [[ -f /etc/cron.d/pihole ]];then
echo "::: Removing cron.d/pihole..." echo "::: Removing cron.d/pihole..."
$SUDO rm /etc/cron.d/pihole &> /dev/null ${SUDO} rm /etc/cron.d/pihole &> /dev/null
fi fi
echo "::: Removing config files and scripts..." echo "::: Removing config files and scripts..."
package_check $i > /dev/null package_check ${i} > /dev/null
if [ $? -eq 1 ]; then if [ $? -eq 1 ]; then
$SUDO rm -rf /etc/lighttpd/ &> /dev/null ${SUDO} rm -rf /etc/lighttpd/ &> /dev/null
else else
if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then if [ -f /etc/lighttpd/lighttpd.conf.orig ]; then
$SUDO mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf ${SUDO} mv /etc/lighttpd/lighttpd.conf.orig /etc/lighttpd/lighttpd.conf
fi fi
fi fi
$SUDO rm /etc/dnsmasq.d/adList.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.d/adList.conf &> /dev/null
$SUDO rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null ${SUDO} rm /etc/dnsmasq.d/01-pihole.conf &> /dev/null
$SUDO rm -rf /var/log/*pihole* &> /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 /etc/.pihole/ &> /dev/null ${SUDO} rm -rf /etc/.pihole/ &> /dev/null
$SUDO rm -rf /opt/pihole/ &> /dev/null ${SUDO} rm -rf /opt/pihole/ &> /dev/null
$SUDO rm /usr/local/bin/pihole &> /dev/null ${SUDO} rm /usr/local/bin/pihole &> /dev/null
$SUDO rm /etc/bash_completion.d/pihole &> /dev/null ${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null
$SUDO rm /etc/sudoers.d/pihole &> /dev/null ${SUDO} rm /etc/sudoers.d/pihole &> /dev/null
echo ":::" echo ":::"
printf "::: Finished removing PiHole from your system. Sorry to see you go!\n" printf "::: Finished removing PiHole from your system. Sorry to see you go!\n"
@ -168,7 +168,7 @@ echo "::: Preparing to remove packages, be sure that each may be safely removed
echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)" echo "::: (SAFE TO REMOVE ALL ON RASPBIAN)"
while true; do 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 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 case ${yn} in
[Yy]* ) removeAndPurge; break;; [Yy]* ) removeAndPurge; break;;
[Nn]* ) removeNoPurge; break;; [Nn]* ) removeNoPurge; break;;

View file

@ -27,6 +27,18 @@ else
fi fi
fi fi
function helpFunc()
{
echo "::: Pull in domains from adlists"
echo ":::"
echo "::: Usage: pihole -g"
echo ":::"
echo "::: Options:"
echo "::: -f, --force Force lists to be downloaded, even if they don't need updating."
echo "::: -h, --help Show this help dialog"
exit 1
}
piholeIPfile=/etc/pihole/piholeIP piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6 piholeIPv6file=/etc/pihole/.useIPv6
@ -35,9 +47,9 @@ adListDefault=/etc/pihole/adlists.default
whitelistScript=/opt/pihole/whitelist.sh whitelistScript=/opt/pihole/whitelist.sh
blacklistScript=/opt/pihole/blacklist.sh blacklistScript=/opt/pihole/blacklist.sh
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
piholeIP=$(cat $piholeIPfile) piholeIP=$(cat ${piholeIPfile})
#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
@ -46,7 +58,7 @@ else
piholeIP=${piholeIPCIDR%/*} piholeIP=${piholeIPCIDR%/*}
fi fi
if [[ -f $piholeIPv6file ]];then if [[ -f ${piholeIPv6file} ]];then
# If the file exists, then the user previously chose to use IPv6 in the automated installer # If the file exists, then the user previously chose to use IPv6 in the automated installer
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
fi fi
@ -54,22 +66,22 @@ fi
# Variables for various stages of downloading and formatting the list # Variables for various stages of downloading and formatting the list
## Nate 3/26/2016 - Commented unused variables ## Nate 3/26/2016 - Commented unused variables
basename=pihole basename=pihole
piholeDir=/etc/$basename piholeDir=/etc/${basename}
adList=$piholeDir/gravity.list adList=${piholeDir}/gravity.list
#blacklist=$piholeDir/blacklist.txt #blacklist=$piholeDir/blacklist.txt
#whitelist=$piholeDir/whitelist.txt #whitelist=$piholeDir/whitelist.txt
#latentWhitelist=$piholeDir/latentWhitelist.txt #latentWhitelist=$piholeDir/latentWhitelist.txt
justDomainsExtension=domains justDomainsExtension=domains
matterandlight=$basename.0.matterandlight.txt matterandlight=${basename}.0.matterandlight.txt
supernova=$basename.1.supernova.txt supernova=${basename}.1.supernova.txt
eventHorizon=$basename.2.eventHorizon.txt eventHorizon=${basename}.2.eventHorizon.txt
accretionDisc=$basename.3.accretionDisc.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 # 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..."
. $piholeDir/pihole.conf . ${piholeDir}/pihole.conf
fi fi
########################### ###########################
@ -78,18 +90,18 @@ function gravity_collapse() {
echo "::: Neutrino emissions detected..." echo "::: Neutrino emissions detected..."
echo ":::" echo ":::"
#Decide if we're using a custom ad block list, or defaults. #Decide if we're using a custom ad block list, or defaults.
if [ -f $adListFile ]; then if [ -f ${adListFile} ]; then
#custom file found, use this instead of default #custom file found, use this instead of default
echo -n "::: Custom adList file detected. Reading..." echo -n "::: Custom adList file detected. Reading..."
sources=() sources=()
while read -r line; do while read -r line; do
#Do not read commented out or blank lines #Do not read commented out or blank lines
if [[ $line = \#* ]] || [[ ! $line ]]; then if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then
echo "" > /dev/null echo "" > /dev/null
else else
sources+=($line) sources+=(${line})
fi fi
done < $adListFile done < ${adListFile}
echo " done!" echo " done!"
else else
#no custom file found, use defaults! #no custom file found, use defaults!
@ -97,27 +109,27 @@ function gravity_collapse() {
sources=() sources=()
while read -r line; do while read -r line; do
#Do not read commented out or blank lines #Do not read commented out or blank lines
if [[ $line = \#* ]] || [[ ! $line ]]; then if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then
echo "" > /dev/null echo "" > /dev/null
else else
sources+=($line) sources+=(${line})
fi fi
done < $adListDefault done < ${adListDefault}
echo " done!" echo " done!"
fi fi
# 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
if [[ -d $piholeDir ]];then if [[ -d ${piholeDir} ]];then
# Temporary hack to allow non-root access to pihole directory # Temporary hack to allow non-root access to pihole directory
# Will update later, needed for existing installs, new installs should # Will update later, needed for existing installs, new installs should
# create this directory as non-root # create this directory as non-root
$SUDO chmod 777 $piholeDir ${SUDO} chmod 777 ${piholeDir}
echo ":::" echo ":::"
echo "::: Existing pihole directory found" echo "::: Existing pihole directory found"
else else
echo "::: Creating pihole directory..." echo "::: Creating pihole directory..."
mkdir $piholeDir mkdir ${piholeDir}
$SUDO chmod 777 $piholeDir ${SUDO} chmod 777 ${piholeDir}
fi fi
} }
@ -146,13 +158,13 @@ function gravity_transport() {
# tmp file, so we don't have to store the (long!) lists in RAM # tmp file, so we don't have to store the (long!) lists in RAM
patternBuffer=$(mktemp) patternBuffer=$(mktemp)
heisenbergCompensator="" heisenbergCompensator=""
if [[ -r $saveLocation ]]; then if [[ -r ${saveLocation} ]]; then
# if domain has been saved, add file for date check to only download newer # if domain has been saved, add file for date check to only download newer
heisenbergCompensator="-z $saveLocation" heisenbergCompensator="-z $saveLocation"
fi fi
# Silently curl url # Silently curl url
curl -s -L $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer curl -s -L ${cmd_ext} ${heisenbergCompensator} -A "$agent" ${url} > ${patternBuffer}
# Check for list updates # Check for list updates
gravity_patternCheck "$patternBuffer" gravity_patternCheck "$patternBuffer"
# Cleanup # Cleanup
@ -170,8 +182,8 @@ function gravity_spinup() {
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=$piholeDir/list.$i.$domain.$justDomainsExtension saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension}
activeDomains[$i]=$saveLocation activeDomains[$i]=${saveLocation}
agent="Mozilla/10.0" agent="Mozilla/10.0"
@ -201,10 +213,10 @@ function gravity_Schwarzchild() {
echo "::: " echo "::: "
# Find all active domains and compile them into one file and remove CRs # Find all active domains and compile them into one file and remove CRs
echo -n "::: Aggregating list of domains..." echo -n "::: Aggregating list of domains..."
truncate -s 0 $piholeDir/$matterandlight truncate -s 0 ${piholeDir}/${matterandlight}
for i in "${activeDomains[@]}" for i in "${activeDomains[@]}"
do do
cat "$i" | tr -d '\r' >> $piholeDir/$matterandlight cat "$i" | tr -d '\r' >> ${piholeDir}/${matterandlight}
done done
echo " done!" echo " done!"
} }
@ -212,7 +224,7 @@ function gravity_Schwarzchild() {
function gravity_Blacklist(){ function gravity_Blacklist(){
# Append blacklist entries if they exist # Append blacklist entries if they exist
echo -n "::: Running blacklist script to update HOSTS file...." echo -n "::: Running blacklist script to update HOSTS file...."
$blacklistScript -f -nr -q > /dev/null ${blacklistScript} -f -nr -q > /dev/null
numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt") numBlacklisted=$(wc -l < "/etc/pihole/blacklist.txt")
plural=; [[ "$numBlacklisted" != "1" ]] && plural=s plural=; [[ "$numBlacklisted" != "1" ]] && plural=s
@ -229,12 +241,12 @@ function gravity_Whitelist() {
for url in "${sources[@]}" for url in "${sources[@]}"
do do
tmp=$(echo "$url" | awk -F '/' '{print $3}') tmp=$(echo "$url" | awk -F '/' '{print $3}')
urls=("${urls[@]}" $tmp) urls=("${urls[@]}" ${tmp})
done done
echo " done!" echo " done!"
echo -n "::: Running whitelist script to update HOSTS file...." echo -n "::: Running whitelist script to update HOSTS file...."
$whitelistScript -f -nr -q "${urls[@]}" > /dev/null ${whitelistScript} -f -nr -q "${urls[@]}" > /dev/null
numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt") numWhitelisted=$(wc -l < "/etc/pihole/whitelist.txt")
plural=; [[ "$numWhitelisted" != "1" ]] && plural=s plural=; [[ "$numWhitelisted" != "1" ]] && plural=s
echo " $numWhitelisted domain${plural} whitelisted!" echo " $numWhitelisted domain${plural} whitelisted!"
@ -243,9 +255,9 @@ function gravity_Whitelist() {
function gravity_unique() { function gravity_unique() {
# Sort and remove duplicates # Sort and remove duplicates
echo -n "::: Removing duplicate domains...." echo -n "::: Removing duplicate domains...."
sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon}
echo " done!" echo " done!"
numberOf=$(wc -l < $piholeDir/$eventHorizon) numberOf=$(wc -l < ${piholeDir}/${eventHorizon})
echo "::: $numberOf unique domains trapped in the event horizon." echo "::: $numberOf unique domains trapped in the event horizon."
} }
@ -254,25 +266,25 @@ function gravity_hostFormat() {
echo "::: Formatting domains into a HOSTS file..." echo "::: Formatting domains into a HOSTS file..."
hostname=$(</etc/hostname) hostname=$(</etc/hostname)
# If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols # If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols
if [[ -n $piholeIPv6 ]];then if [[ -n ${piholeIPv6} ]];then
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)
echo -e "$piholeIP $hostname\n$piholeIPv6 $hostname\n$piholeIP pi.hole\n$piholeIPv6 pi.hole" > $piholeDir/$accretionDisc echo -e "$piholeIP $hostname\n$piholeIPv6 $hostname\n$piholeIP pi.hole\n$piholeIPv6 pi.hole" > ${piholeDir}/${accretionDisc}
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $piholeDir/$accretionDisc cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
else else
# Otherwise, just create gravity.list as normal using IPv4 # Otherwise, just create gravity.list as normal using IPv4
# Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin) # Add hostname and dummy domain to the top of gravity.list to make ping result return a friendlier looking domain! Also allows for an easy way to access the Pi-hole admin console (pi.hole/admin)
echo -e "$piholeIP $hostname\n$piholeIP pi.hole" > $piholeDir/$accretionDisc echo -e "$piholeIP $hostname\n$piholeIP pi.hole" > ${piholeDir}/${accretionDisc}
cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $piholeDir/$accretionDisc cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
fi fi
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
cp $piholeDir/$accretionDisc $adList cp ${piholeDir}/${accretionDisc} ${adList}
} }
# blackbody - remove any remnant files from script processes # blackbody - remove any remnant files from script processes
function gravity_blackbody() { function gravity_blackbody() {
# Loop through list files # Loop through list files
for file in $piholeDir/*.$justDomainsExtension for file in ${piholeDir}/*.${justDomainsExtension}
do do
# If list is in active array then leave it (noop) else rm the list # If list is in active array then leave it (noop) else rm the list
if [[ " ${activeDomains[@]} " =~ ${file} ]]; then if [[ " ${activeDomains[@]} " =~ ${file} ]]; then
@ -289,10 +301,10 @@ function gravity_advanced() {
# 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 -n "::: Formatting list of domains to remove comments...." echo -n "::: Formatting list of domains to remove comments...."
awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' $piholeDir/$matterandlight | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > $piholeDir/$supernova awk '($1 !~ /^#/) { if (NF>1) {print $2} else {print $1}}' ${piholeDir}/${matterandlight} | sed -nr -e 's/\.{2,}/./g' -e '/\./p' > ${piholeDir}/${supernova}
echo " done!" echo " done!"
numberOf=$(wc -l < $piholeDir/$supernova) numberOf=$(wc -l < ${piholeDir}/${supernova})
echo "::: $numberOf domains being pulled in by gravity..." echo "::: $numberOf domains being pulled in by gravity..."
gravity_unique gravity_unique
@ -302,7 +314,7 @@ function gravity_reload() {
#Clear no longer needed files... #Clear no longer needed files...
echo ":::" echo ":::"
echo -n "::: Cleaning up un-needed files..." echo -n "::: Cleaning up un-needed files..."
$SUDO rm $piholeDir/pihole.*.txt ${SUDO} rm ${piholeDir}/pihole.*.txt
echo " done!" echo " done!"
# Reload hosts file # Reload hosts file
@ -313,22 +325,39 @@ function gravity_reload() {
#First escape forward slashes in the path: #First escape forward slashes in the path:
adList=${adList//\//\\\/} adList=${adList//\//\\\/}
#Now replace the line in dnsmasq file #Now replace the line in dnsmasq file
$SUDO sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf ${SUDO} sed -i "s/^addn-hosts.*/addn-hosts=$adList/" /etc/dnsmasq.d/01-pihole.conf
dnsmasqPid=$(pidof dnsmasq) dnsmasqPid=$(pidof dnsmasq)
find "$piholeDir" -type f -exec $SUDO chmod 666 {} \; find "$piholeDir" -type f -exec ${SUDO} chmod 666 {} \;
if [[ $dnsmasqPid ]]; then if [[ ${dnsmasqPid} ]]; then
# service already running - reload config # service already running - reload config
$SUDO killall -s HUP dnsmasq ${SUDO} killall -s HUP dnsmasq
else else
# service not running, start it up # service not running, start it up
$SUDO service dnsmasq start ${SUDO} service dnsmasq start
fi fi
echo " done!" echo " done!"
} }
$SUDO cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
for var in "$@"
do
case "$var" in
"-f" | "--force" ) forceGrav=true;;
"-h" | "--help" ) helpFunc;;
esac
done
#Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list
if [[ ${forceGrav} == true ]]; then
echo -n "::: Deleting exising list cache..."
${SUDO} rm /etc/pihole/list.*
echo " done!"
fi
${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default
gravity_collapse gravity_collapse
gravity_spinup gravity_spinup
gravity_Schwarzchild gravity_Schwarzchild

51
pihole
View file

@ -27,50 +27,69 @@ fi
function whitelistFunc { function whitelistFunc {
shift shift
$SUDO /opt/pihole/whitelist.sh "$@" ${SUDO} /opt/pihole/whitelist.sh "$@"
exit 1 exit 1
} }
function blacklistFunc { function blacklistFunc {
shift shift
$SUDO /opt/pihole/blacklist.sh "$@" ${SUDO} /opt/pihole/blacklist.sh "$@"
exit 1 exit 1
} }
function debugFunc { function debugFunc {
$SUDO /opt/pihole/piholeDebug.sh ${SUDO} /opt/pihole/piholeDebug.sh
exit 1 exit 1
} }
function flushFunc { function flushFunc {
$SUDO /opt/pihole/piholeLogFlush.sh ${SUDO} /opt/pihole/piholeLogFlush.sh
exit 1 exit 1
} }
function updateDashboardFunc { function updateDashboardFunc {
$SUDO /opt/pihole/updateDashboard.sh ${SUDO} /opt/pihole/updateDashboard.sh
exit 1
}
function updatePiholeFunc {
echo "::: Fetching latest changes from Github..."
cd /etc/.pihole
${SUDO} git pull
${SUDO} /etc/.pihole/automated\ install/basic-install.sh pihole
exit 1 exit 1
} }
function updateGravityFunc { function updateGravityFunc {
$SUDO /opt/pihole/gravity.sh ${SUDO} /opt/pihole/gravity.sh "$@"
exit 1 exit 1
} }
function setupLCDFunction { function setupLCDFunction {
$SUDO /opt/pihole/setupLCD.sh ${SUDO} /opt/pihole/setupLCD.sh
exit 1
}
function queryFunc {
domain=$2
for list in /etc/pihole/list.*;do echo $list;grep ${domain} $list;done
exit 1 exit 1
} }
function chronometerFunc { function chronometerFunc {
shift shift
$SUDO /opt/pihole/chronometer.sh "$@" ${SUDO} /opt/pihole/chronometer.sh "$@"
exit 1 exit 1
} }
function uninstallFunc { function uninstallFunc {
$SUDO /opt/pihole/uninstall.sh ${SUDO} /opt/pihole/uninstall.sh
exit 1
}
function versionFunc {
${SUDO} /opt/pihole/version.sh
exit 1 exit 1
} }
@ -85,12 +104,15 @@ function helpFunc {
echo "::: -b, blacklist Blacklist domains" echo "::: -b, blacklist Blacklist domains"
echo "::: -d, debug Start a debugging session if having trouble" echo "::: -d, debug Start a debugging session if having trouble"
echo "::: -f, flush Flush the pihole.log file" echo "::: -f, flush Flush the pihole.log file"
echo "::: -u, updateDashboard Update the web dashboard manually" echo "::: -ud, updateDashboard Update the web dashboard manually"
echo "::: -up, updatePihole Update Pi-hole"
echo "::: -g, updateGravity Update the list of ad-serving domains" echo "::: -g, updateGravity Update the list of ad-serving domains"
echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it" echo "::: -s, setupLCD Automatically configures the Pi to use the 2.8 LCD screen to display stats on it"
echo "::: -c, chronometer Calculates stats and displays to an LCD" echo "::: -c, chronometer Calculates stats and displays to an LCD"
echo "::: -h, help Show this help dialog" echo "::: -h, help Show this help dialog"
echo "::: uninstall Uninstall Pi-Hole from your system!" echo "::: -v, version Show current versions"
echo "::: -q, query Query the adlists for a specific domain"
echo "::: uninstall Uninstall Pi-Hole from your system :(!"
exit 1 exit 1
} }
@ -104,11 +126,14 @@ case "$1" in
"-b" | "blacklist" ) blacklistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";;
"-d" | "debug" ) debugFunc;; "-d" | "debug" ) debugFunc;;
"-f" | "flush" ) flushFunc;; "-f" | "flush" ) flushFunc;;
"-u" | "updateDashboard" ) updateDashboardFunc;; "-ud" | "updateDashboard" ) updateDashboardFunc;;
"-g" | "updateGravity" ) updateGravityFunc;; "-up" | "updatePihole" ) updatePiholeFunc;;
"-g" | "updateGravity" ) updateGravityFunc "$@";;
"-s" | "setupLCD" ) setupLCDFunction;; "-s" | "setupLCD" ) setupLCDFunction;;
"-c" | "chronometer" ) chronometerFunc "$@";; "-c" | "chronometer" ) chronometerFunc "$@";;
"-h" | "help" ) helpFunc;; "-h" | "help" ) helpFunc;;
"-v" | "version" ) versionFunc;;
"-q" | "query" ) queryFunc "$@";;
"uninstall" ) uninstallFunc;; "uninstall" ) uninstallFunc;;
* ) helpFunc;; * ) helpFunc;;
esac esac