From f0a2248c81a790c72f9ccc927627f5fcd8c4eb6a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 15 Jul 2016 10:27:40 -0700 Subject: [PATCH 01/53] Change comment to hash Change format of comment to hash/octothorpe to clearly delineate that it's a comment. Looks better than `:::` which causes confusion. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9474d729..6424f828 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -324,7 +324,7 @@ It is also possible to use a DHCP reservation, but if you are going to do that, setDHCPCD() { # Append these lines to dhcpcd.conf to enable a static IP - echo "::: interface $piholeInterface + echo "## interface $piholeInterface static ip_address=$IPv4addr static routers=$IPv4gw static domain_name_servers=$IPv4gw" | $SUDO tee -a /etc/dhcpcd.conf >/dev/null From 61ff12e8d42f7a473180c7331ed55c0c2379c7dd Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 15 Jul 2016 21:17:16 +0100 Subject: [PATCH 02/53] Change header to match the rest of the scripts. --- advanced/Scripts/piholeDebug.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index e22a36aa..c5b52daf 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -10,9 +10,6 @@ # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# Nate Brandeburg -# nate@ubiquisoft.com -# 3/24/2016 ######## GLOBAL VARS ######## DEBUG_LOG="/var/log/pihole_debug.log" From a32ad0dbf2240fe876f226506556d11db70b323f Mon Sep 17 00:00:00 2001 From: bcambl Date: Fri, 15 Jul 2016 21:43:23 -0600 Subject: [PATCH 03/53] fix centos nc dependency --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bd6722ee..4df009bc 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -67,7 +67,7 @@ if [ -x "$(command -v rpm)" ];then PKG_INSTALL="$PKG_MANAGER install -y" PKG_COUNT="$PKG_MANAGER check-update | grep -v ^Last | grep -c ^[a-zA-Z0-9]" 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_GROUP="lighttpd" LIGHTTPD_CFG="lighttpd.conf.fedora" From ce8f07750f04409bbc6354cb46dd604688dfa01b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 15 Jul 2016 22:46:21 -0700 Subject: [PATCH 04/53] Remove trailing slash on os-release check Fixes #CLOSED Remove trailing slash that would cause an os-check to always fail out. --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index c5b52daf..36ae15bc 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -69,7 +69,7 @@ function distroCheck { echo "######## Distribution Section #########" >> $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 } From 3affa73257bcd7cb711a1448019d8e6fc6f0cb0d Mon Sep 17 00:00:00 2001 From: diginc Date: Wed, 20 Jul 2016 12:43:30 -0500 Subject: [PATCH 05/53] Only re-block whitelist deletions if in adlists * Prevent blocking benign/untracked domains deleted off whitelist * Issue #581 --- advanced/Scripts/whitelist.sh | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 266ac49e..d43f2e45 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -175,20 +175,23 @@ function ModifyHostFile(){ echo ":::" echo "::: Modifying HOSTS file to un-whitelist domains..." for rdom in "${domToRemoveList[@]}" - do - if [[ -n $piholeIPv6 ]];then - echo -n "::: Un-whitelisting $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!" - else - echo -n "::: Un-whitelisting $rdom on IPv4" - echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList - echo " done!" - fi - echo -n "::: Removing $rdom from $whitelist..." - echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist - echo " done!" - done + do + if grep -q "$rdom" /etc/pihole/*.domains; then + echo "::: AdLists contain $rdom, re-adding block" + 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!" + else + echo -n "::: Restoring block for $rdom on IPv4" + echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList + echo " done!" + fi + fi + echo -n "::: Removing $rdom from $whitelist..." + echo "$rdom" | sed 's/\./\\./g' | xargs -I {} perl -i -ne'print unless /'{}'(?!.)/;' $whitelist + echo " done!" + done fi } From 5fb6c5b01209fe7c99e3e6e271e814272c44a270 Mon Sep 17 00:00:00 2001 From: diginc Date: Wed, 20 Jul 2016 12:53:31 -0500 Subject: [PATCH 06/53] Making the whitelist re-block echo consistent with other WL/BL echos --- advanced/Scripts/whitelist.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index d43f2e45..5195aa83 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -183,7 +183,7 @@ function ModifyHostFile(){ echo "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList echo " done!" else - echo -n "::: Restoring block for $rdom on IPv4" + echo -n "::: Restoring block for $rdom on IPv4..." echo "$rdom" | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >>$adList echo " done!" fi From 941525d1e0fe2916cf8d4ee74a51ecd65eeff758 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 22 Jul 2016 11:54:17 +0100 Subject: [PATCH 07/53] Development out of sync with master. (#588) * adding links to optimal.com Also added image of Pi-hole's stats from Optimal.com and a bitcoin donation address per some user requests. * simplified and new additions I tried to simplify the readme page a bit. I also added some new links to some helper videos and added some screenshots of the whitelist editor. * updated dashboard pic * Update README.md * simplified donation section * forgot to remove the old donation stuff * Hosts-file.net moved to https * removed pihole berry from images also added adafruit livestream video * Update README.md update "How does it work" video --- README.md | 119 +++++++++++++++++++++++++----------------------- adlists.default | 2 +- 2 files changed, 62 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index 940fe636..deea666e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,9 @@ # Automated Install ##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) (Works on most Debian distributions!) - -[![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - 1. Install Raspbian -2. Run the command below +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``` @@ -16,21 +13,73 @@ wget -O basic-install.sh https://install.pi-hole.net chmod +x 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 + 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/). -## Pi-hole Is Free, But Powered By Your Donations -[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "Free, but powered by donations")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate") +## How To Install Pi-hole -## Catch us out on the net: -Twitter: [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) - -reddit: [/r/pihole](https://www.reddit.com/r/pihole/) +[![60-second install tutorial](http://i.imgur.com/5TEc3a6.png)](https://www.youtube.com/watch?v=TzFLJqUeirA) ## How Does It Work? **Watch the 60-second video below to get a quick overview** -[![Pi-hole exlplained](http://i.imgur.com/qNybJDX.png)](https://vimeo.com/135965232) +[![Pi-hole exlplained](http://i.imgur.com/pG1m937.png)](https://youtu.be/9Eti3xibiho) + +## 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) + + +## Get Help Or Connect With Us On The Web + +- [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) +- [/r/pihole](https://www.reddit.com/r/pihole/) +- [Pi-hole YouTube channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w) +- [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) +- [FAQs](https://pi-hole.net/help/) +- [![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + +## Technical Details + +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 +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 +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` + +![Pi-hole Advanced Stats Dashboard](http://i.imgur.com/gTq2GbS.png) + +### 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 +![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png) + +## API + +A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: +```JSON +{ + "domains_being_blocked": "136708", + "dns_queries_today": "18108", + "ads_blocked_today": "14648", + "ads_percentage_today": "80.89" +} +``` +The same output can be acheived on the CLI by running `chronometer.sh -j` + +## 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). +![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) ## Pi-hole Projects - [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py) @@ -47,6 +96,7 @@ reddit: [/r/pihole](https://www.reddit.com/r/pihole/) - [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) ## Coverage +- [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) - [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/) - [The Defrag Show - MSDN/Channel 9](https://channel9.msdn.com/Shows/The-Defrag-Show/Defrag-Endoscope-USB-Camera-The-Final-HoloLens-Vote-Adblock-Pi-and-more?WT.mc_id=dlvr_twitter_ch9#time=20m39s) @@ -60,52 +110,5 @@ reddit: [/r/pihole](https://www.reddit.com/r/pihole/) - [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/) - [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) -## Partnering With Optimal.com - -Pi-hole will be teaming up with [Rob Leathern's subscription service to avoid ads](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d). This service is unique and will help content-creators and publishers [still make money from visitors who are using an ad ablocker](http://techcrunch.com/2015/12/17/the-new-optimal/). - -## Technical Details - -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. - -A more detailed explanation of the installation can be found [here](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0). - -## 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)). - -## 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 - -## 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: - -`http://192.168.1.x/admin/index.php` - -![Pi-hole Advanced Stats Dashboard](http://i.imgur.com/rTlLYPh.png) - -### API - -A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: -```JSON -{ - "domains_being_blocked": "136708", - "dns_queries_today": "18108", - "ads_blocked_today": "14648", - "ads_percentage_today": "80.89" -} -``` -The same output can be acheived on the CLI by running `chronometer.sh -j` - -![Web](http://i.imgur.com/m114SCn.png) - -## 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). -![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) - -## Help -- See the [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) entry for more details -- There is also an [FAQ section on pi-hole.net](http://pi-hole.net) - ## 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. diff --git a/adlists.default b/adlists.default index d2b5e798..2c171e87 100644 --- a/adlists.default +++ b/adlists.default @@ -22,7 +22,7 @@ https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt # hosts-file.net list. Updated frequently, but has been known to block legitimate sites. -http://hosts-file.net/ad_servers.txt +https://hosts-file.net/ad_servers.txt # Mahakala list. Has been known to block legitimage domains including the entire .com range. # Warning: Due to the sheer size of this list, the web admin console will be unresponsive. From 51dcc2bc0f07fbe472d7280bb2ec0484e90c505d Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 22 Jul 2016 11:56:54 +0100 Subject: [PATCH 08/53] Update README.md Add badge for bountysource to show avtive bounties. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index deea666e..3d849a9d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![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 ##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) (Works on most Debian distributions!) From 60aad3f19b910734ae22683f358d951a72b1e2d0 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 22 Jul 2016 11:59:19 +0100 Subject: [PATCH 09/53] Revert "Development out of sync with master." --- README.md | 119 +++++++++++++++++++++++------------------------- adlists.default | 2 +- 2 files changed, 59 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index deea666e..940fe636 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # Automated Install ##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) (Works on most Debian distributions!) + +[![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + 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 ### ```curl -L https://install.pi-hole.net | bash``` @@ -13,73 +16,21 @@ wget -O basic-install.sh https://install.pi-hole.net chmod +x 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 - 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/). -## How To Install Pi-hole +## Pi-hole Is Free, But Powered By Your Donations +[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "Free, but powered by donations")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate") -[![60-second install tutorial](http://i.imgur.com/5TEc3a6.png)](https://www.youtube.com/watch?v=TzFLJqUeirA) +## Catch us out on the net: +Twitter: [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) + +reddit: [/r/pihole](https://www.reddit.com/r/pihole/) ## How Does It Work? **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 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) - - -## Get Help Or Connect With Us On The Web - -- [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) -- [/r/pihole](https://www.reddit.com/r/pihole/) -- [Pi-hole YouTube channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w) -- [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) -- [FAQs](https://pi-hole.net/help/) -- [![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -## Technical Details - -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 -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 -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` - -![Pi-hole Advanced Stats Dashboard](http://i.imgur.com/gTq2GbS.png) - -### 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 -![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png) - -## API - -A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: -```JSON -{ - "domains_being_blocked": "136708", - "dns_queries_today": "18108", - "ads_blocked_today": "14648", - "ads_percentage_today": "80.89" -} -``` -The same output can be acheived on the CLI by running `chronometer.sh -j` - -## 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). -![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) +[![Pi-hole exlplained](http://i.imgur.com/qNybJDX.png)](https://vimeo.com/135965232) ## Pi-hole Projects - [Pi-hole stats in your Mac's menu bar](https://getbitbar.com/plugins/Network/pi-hole.1m.py) @@ -96,7 +47,6 @@ You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd- - [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) ## Coverage -- [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) - [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/) - [The Defrag Show - MSDN/Channel 9](https://channel9.msdn.com/Shows/The-Defrag-Show/Defrag-Endoscope-USB-Camera-The-Final-HoloLens-Vote-Adblock-Pi-and-more?WT.mc_id=dlvr_twitter_ch9#time=20m39s) @@ -110,5 +60,52 @@ You can view [real-time stats](http://pi-hole.net/faq/install-the-real-time-lcd- - [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/) - [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) +## Partnering With Optimal.com + +Pi-hole will be teaming up with [Rob Leathern's subscription service to avoid ads](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d). This service is unique and will help content-creators and publishers [still make money from visitors who are using an ad ablocker](http://techcrunch.com/2015/12/17/the-new-optimal/). + +## Technical Details + +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. + +A more detailed explanation of the installation can be found [here](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0). + +## 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)). + +## 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 + +## 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: + +`http://192.168.1.x/admin/index.php` + +![Pi-hole Advanced Stats Dashboard](http://i.imgur.com/rTlLYPh.png) + +### API + +A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: +```JSON +{ + "domains_being_blocked": "136708", + "dns_queries_today": "18108", + "ads_blocked_today": "14648", + "ads_percentage_today": "80.89" +} +``` +The same output can be acheived on the CLI by running `chronometer.sh -j` + +![Web](http://i.imgur.com/m114SCn.png) + +## 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). +![Pi-hole LCD](http://i.imgur.com/nBEqycp.jpg) + +## Help +- See the [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) entry for more details +- There is also an [FAQ section on pi-hole.net](http://pi-hole.net) + ## 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. diff --git a/adlists.default b/adlists.default index 2c171e87..d2b5e798 100644 --- a/adlists.default +++ b/adlists.default @@ -22,7 +22,7 @@ https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt # hosts-file.net list. Updated frequently, but has been known to block legitimate sites. -https://hosts-file.net/ad_servers.txt +http://hosts-file.net/ad_servers.txt # Mahakala list. Has been known to block legitimage domains including the entire .com range. # Warning: Due to the sheer size of this list, the web admin console will be unresponsive. From 8550b76e23540be096ea67aac22bf233f4c25103 Mon Sep 17 00:00:00 2001 From: bcambl Date: Sun, 24 Jul 2016 22:42:06 -0600 Subject: [PATCH 10/53] add gateway to interface configuration --- automated install/basic-install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 29e3237f..55206faf 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -359,6 +359,7 @@ setStaticIPv4() { $SUDO echo "ONBOOT=yes" >> $IFCFG_FILE $SUDO echo "IPADDR=$IPADDR" >> $IFCFG_FILE $SUDO echo "PREFIX=$CIDR" >> $IFCFG_FILE + $SUDO echo "GATEWAY=$IPv4gw" >> $IFCFG_FILE $SUDO echo "USERCTL=no" >> $IFCFG_FILE $SUDO ip addr replace dev "$piholeInterface" "$IPv4addr" if [ -x "$(command -v nmcli)" ];then From 02c4669e95e0dc3d2762231ca2b529cf0bbef9e7 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Tue, 26 Jul 2016 20:46:43 -0700 Subject: [PATCH 11/53] Typo/Linter fix Fix a few typo's, run through linter for format corrections. --- README.md | 129 +++++++++++++++++++++++++++++------------------------- 1 file changed, 69 insertions(+), 60 deletions(-) diff --git a/README.md b/README.md index deea666e..d8990967 100644 --- a/README.md +++ b/README.md @@ -1,58 +1,64 @@ -# Automated Install -##### Designed For Raspberry Pi A+, B, B+, 2, Zero, and 3B (with an Ethernet/Wi-Fi adapter) (Works on most Debian distributions!) +# Automated Install -1. Install Raspbian +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! -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!) +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!) -### ```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 chmod +x 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 - -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/). ## How To Install Pi-hole [![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** [![Pi-hole exlplained](http://i.imgur.com/pG1m937.png)](https://youtu.be/9Eti3xibiho) ## 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 +- ![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 commission) ## Get Help Or Connect With Us On The Web -- [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) -- [/r/pihole](https://www.reddit.com/r/pihole/) -- [Pi-hole YouTube channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w) -- [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) -- [FAQs](https://pi-hole.net/help/) -- [![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +- [@The_Pi_Hole](https://twitter.com/The_Pi_Hole) +- [/r/pihole](https://www.reddit.com/r/pihole/) +- [Pi-hole YouTube channel](https://www.youtube.com/channel/UCT5kq9w0wSjogzJb81C9U0w) +- [Wiki](https://github.com/pi-hole/pi-hole/wiki/Customization) +- [FAQs](https://pi-hole.net/help/) +- [![Join the chat at https://gitter.im/pi-hole/pi-hole](https://badges.gitter.im/pi-hole/pi-hole.svg)](https://gitter.im/pi-hole/pi-hole?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) ## Technical Details -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 -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 -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` @@ -60,55 +66,58 @@ The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashb ### 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 -![Whitelist editor in the Web interface](http://i.imgur.com/ogu2ewg.png) +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) ## API A basic read-only API can be accessed at `/admin/api.php`. It returns the following JSON: -```JSON + +```json { - "domains_being_blocked": "136708", - "dns_queries_today": "18108", - "ads_blocked_today": "14648", - "ads_percentage_today": "80.89" + "domains_being_blocked": "136708", + "dns_queries_today": "18108", + "ads_blocked_today": "14648", + "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 -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) +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 Projects -- [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/) -- [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html) -- [x86 Docker container that runs Pi-hole](https://hub.docker.com/r/diginc/pi-hole/) -- [Splunk: Pi-hole Visualizser](https://splunkbase.splunk.com/app/3023/) -- [Pi-hole Chrome extension](https://chrome.google.com/webstore/detail/pi-hole-list-editor/hlnoeoejkllgkjbnnnhfolapllcnaglh) ([open source](https://github.com/packtloss/pihole-extension)) -- [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037) -- [Sky-Hole](http://dlaa.me/blog/post/skyhole) -- [Pi-hole in the Cloud!](http://blog.codybunch.com/2015/07/28/Pi-Hole-in-the-cloud/) -- [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/) -- [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) + +- [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/) +- [Pi-hole on Ubuntu 14.04 on VirtualBox](http://hbalagtas.blogspot.com/2016/02/adblocking-with-pi-hole-and-ubuntu-1404.html) +- [x86 Docker container that runs Pi-hole](https://hub.docker.com/r/diginc/pi-hole/) +- [Splunk: Pi-hole Visualizser](https://splunkbase.splunk.com/app/3023/) +- [Pi-hole Chrome extension](https://chrome.google.com/webstore/detail/pi-hole-list-editor/hlnoeoejkllgkjbnnnhfolapllcnaglh) ([open source](https://github.com/packtloss/pihole-extension)) +- [Go Bananas for CHiP-hole ad blocking](https://www.hackster.io/jacobsalmela/chip-hole-network-wide-ad-blocker-98e037) +- [Sky-Hole](http://dlaa.me/blog/post/skyhole) +- [Pi-hole in the Cloud!](http://blog.codybunch.com/2015/07/28/Pi-Hole-in-the-cloud/) +- [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/) +- [Minibian Pi-hole](http://munkjensen.net/wiki/index.php/See_my_Pi-Hole#Minibian_Pi-hole) ## Coverage -- [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) -- [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/) -- [The Defrag Show - MSDN/Channel 9](https://channel9.msdn.com/Shows/The-Defrag-Show/Defrag-Endoscope-USB-Camera-The-Final-HoloLens-Vote-Adblock-Pi-and-more?WT.mc_id=dlvr_twitter_ch9#time=20m39s) -- [MacObserver Podcast 585](http://www.macobserver.com/tmo/podcast/macgeekgab-585) -- [Medium: Block All Ads For $53](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d) -- [MakeUseOf: Adblock Everywhere, The Pi-hole Way](http://www.makeuseof.com/tag/adblock-everywhere-raspberry-pi-hole-way/) -- [Lifehacker: Turn Your Pi Into An Ad Blocker With A Single Command](http://lifehacker.com/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-co-1686093533)! -- [Pi-hole on TekThing](https://youtu.be/8Co59HU2gY0?t=2m) -- [Pi-hole on Security Now! Podcast](http://www.youtube.com/watch?v=p7-osq_y8i8&t=100m26s) -- [Foolish Tech Show](https://youtu.be/bYyena0I9yc?t=2m4s) -- [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/) -- [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) + +- [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) +- [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/) +- [The Defrag Show - MSDN/Channel 9](https://channel9.msdn.com/Shows/The-Defrag-Show/Defrag-Endoscope-USB-Camera-The-Final-HoloLens-Vote-Adblock-Pi-and-more?WT.mc_id=dlvr_twitter_ch9#time=20m39s) +- [MacObserver Podcast 585](http://www.macobserver.com/tmo/podcast/macgeekgab-585) +- [Medium: Block All Ads For $53](https://medium.com/@robleathern/block-ads-on-all-home-devices-for-53-18-a5f1ec139693#.gj1xpgr5d) +- [MakeUseOf: Adblock Everywhere, The Pi-hole Way](http://www.makeuseof.com/tag/adblock-everywhere-raspberry-pi-hole-way/) +- [Lifehacker: Turn Your Pi Into An Ad Blocker With A Single Command](http://lifehacker.com/turn-a-raspberry-pi-into-an-ad-blocker-with-a-single-co-1686093533)! +- [Pi-hole on TekThing](https://youtu.be/8Co59HU2gY0?t=2m) +- [Pi-hole on Security Now! Podcast](http://www.youtube.com/watch?v=p7-osq_y8i8&t=100m26s) +- [Foolish Tech Show](https://youtu.be/bYyena0I9yc?t=2m4s) +- [Pi-hole on Ubuntu](http://www.boyter.org/2015/12/pi-hole-ubuntu-14-04/) +- [Catchpoint: iOS 9 Ad Blocking](http://blog.catchpoint.com/2015/09/14/ad-blocking-apple/) ## 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. From 0749e4ed70c6f5c34d1e2df1b0ff67b95f8f9aba Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 27 Jul 2016 18:58:05 -0700 Subject: [PATCH 12/53] Move BountySource to top position --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7feabfaa..aae3693f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# Automated Install - [![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 + 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! From 20d8c9053b126476283632c3a1f951eb308d34c8 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 29 Jul 2016 13:05:15 -0700 Subject: [PATCH 13/53] Remove defunct Optimal link Optimal has discontinued it's app program. Removing dead link --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index aae3693f..acfce86c 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,6 @@ Send a one-time donation or sign up for Optimal.com's service using our link bel - ![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 commission) ## Get Help Or Connect With Us On The Web From e642b41b5b1870184ebaf951eb9959818475ebe9 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Fri, 29 Jul 2016 16:35:26 -0700 Subject: [PATCH 14/53] Add PullApprove configuration --- .pullapprove.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .pullapprove.yml diff --git a/.pullapprove.yml b/.pullapprove.yml new file mode 100644 index 00000000..ae786ecf --- /dev/null +++ b/.pullapprove.yml @@ -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 From a3b3a7a34dfbef0eb73c915829bca18aedfca700 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 1 Aug 2016 21:43:13 +0100 Subject: [PATCH 15/53] Add option for uploading debug log to termbin --- advanced/Scripts/piholeDebug.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 36ae15bc..ec08c984 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -337,17 +337,27 @@ function dumpPiHoleLog { # Anything to be done after capturing of pihole.log terminates function finalWork { - echo "::: Finshed debugging!" - TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) + 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) + ;; + *) + echo "::: Log will NOT be uploaded to Termbin." + ;; + esac - # Check if termbin.com is reachable. When it's not, point to local log instead - if [ -n "$TERMBIN" ] - then - echo "::: Debug log can be found at : $TERMBIN" - else - echo "::: Debug log can be found at : /var/log/pihole_debug.log" - fi + # Check if termbin.com is reachable. When it's not, point to local log instead + if [ -n "$TERMBIN" ] + then + echo "::: Debug log can be found at : $TERMBIN" + else + echo "::: Debug log can be found at : /var/log/pihole_debug.log" + fi } + trap finalWork EXIT ### Method calls for additional logging ### From 66ff9a24c6a2c37816702adc527aa802f9f90951 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Mon, 1 Aug 2016 21:54:42 +0100 Subject: [PATCH 16/53] Add piholeDebug to the chmod 755 command in install script. Not sure how that went missing... --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 29e3237f..afd5f351 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -547,7 +547,7 @@ installScripts() { $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/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh - $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall,setupLCD}.sh + $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeDebug,piholeLogFlush,updateDashboard,uninstall,setupLCD}.sh $SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole $SUDO chmod 755 /usr/local/bin/pihole $SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole From 6a17a3eeec3dfb5de0920e96ca8f419cb844389d Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 2 Aug 2016 19:44:11 +0100 Subject: [PATCH 17/53] Add command to pihole script --- pihole | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pihole b/pihole index bbcb82d0..73c7fa64 100755 --- a/pihole +++ b/pihole @@ -74,6 +74,10 @@ function uninstallFunc { exit 1 } +function versionFunc{ + $SUDO /opt/pihole/version.sh + exit 1 +} function helpFunc { echo "::: Control all PiHole specific functions!" echo ":::" @@ -90,6 +94,7 @@ function helpFunc { 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 "::: -h, help Show this help dialog" + echo "::: -v, version Show current versions" echo "::: uninstall Uninstall Pi-Hole from your system!" exit 1 } @@ -109,6 +114,7 @@ case "$1" in "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; +"-v" | "version" ) versionFunc;; "uninstall" ) uninstallFunc;; * ) helpFunc;; esac From e11ef5a7f01a50e6e1a7373345b907b9a3e6234f Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 2 Aug 2016 20:07:09 +0100 Subject: [PATCH 18/53] Add version display script. Also checks current version on web and reports version. --- advanced/Scripts/version.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 advanced/Scripts/version.sh diff --git a/advanced/Scripts/version.sh b/advanced/Scripts/version.sh new file mode 100644 index 00000000..e7e7c782 --- /dev/null +++ b/advanced/Scripts/version.sh @@ -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)" \ No newline at end of file From 57df56dc629e2b71c15fef812c96d52f19eee244 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 2 Aug 2016 20:08:21 +0100 Subject: [PATCH 19/53] Add version.sh to the install script --- automated install/basic-install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 29e3237f..d99433c2 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -547,7 +547,8 @@ installScripts() { $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/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 chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall,setupLCD, version}.sh $SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole $SUDO chmod 755 /usr/local/bin/pihole $SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole From 2bc364023afec556b9f04d7c7ad6673b0234b705 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Tue, 2 Aug 2016 20:14:36 +0100 Subject: [PATCH 20/53] Remove erroneous space in chmod command Fix spacing in help function --- automated install/basic-install.sh | 2 +- pihole | 89 +++++++++++++++--------------- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d99433c2..254d601f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -548,7 +548,7 @@ installScripts() { $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/version.sh /opt/pihole/version.sh - $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall,setupLCD, version}.sh + $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall,setupLCD,version}.sh $SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole $SUDO chmod 755 /usr/local/bin/pihole $SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole diff --git a/pihole b/pihole index 73c7fa64..64a36c59 100755 --- a/pihole +++ b/pihole @@ -12,13 +12,13 @@ # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then - #echo "::: You are root." + #echo "::: You are root." #else - #echo "::: Sudo will be used for this tool." + #echo "::: Sudo will be used for this tool." # Check if it is actually installed # If it isn't, exit because the pihole cannot be invoked without privileges. if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" + export SUDO="sudo" else echo "::: Please install sudo or run this as root." exit 1 @@ -26,81 +26,82 @@ if [[ ! $EUID -eq 0 ]];then fi function whitelistFunc { - shift - $SUDO /opt/pihole/whitelist.sh "$@" - exit 1 + shift + $SUDO /opt/pihole/whitelist.sh "$@" + exit 1 } function blacklistFunc { - shift - $SUDO /opt/pihole/blacklist.sh "$@" - exit 1 + shift + $SUDO /opt/pihole/blacklist.sh "$@" + exit 1 } function debugFunc { - $SUDO /opt/pihole/piholeDebug.sh - exit 1 + $SUDO /opt/pihole/piholeDebug.sh + exit 1 } function flushFunc { - $SUDO /opt/pihole/piholeLogFlush.sh - exit 1 + $SUDO /opt/pihole/piholeLogFlush.sh + exit 1 } function updateDashboardFunc { - $SUDO /opt/pihole/updateDashboard.sh - exit 1 + $SUDO /opt/pihole/updateDashboard.sh + exit 1 } function updateGravityFunc { - $SUDO /opt/pihole/gravity.sh - exit 1 + $SUDO /opt/pihole/gravity.sh + exit 1 } function setupLCDFunction { - $SUDO /opt/pihole/setupLCD.sh - exit 1 + $SUDO /opt/pihole/setupLCD.sh + exit 1 } function chronometerFunc { - shift - $SUDO /opt/pihole/chronometer.sh "$@" - exit 1 + shift + $SUDO /opt/pihole/chronometer.sh "$@" + exit 1 } function uninstallFunc { - $SUDO /opt/pihole/uninstall.sh - exit 1 + $SUDO /opt/pihole/uninstall.sh + exit 1 } -function versionFunc{ +function versionFunc { $SUDO /opt/pihole/version.sh exit 1 } + function helpFunc { - echo "::: Control all PiHole specific functions!" - echo ":::" - echo "::: Usage: pihole [options]" - echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" - echo ":::" - echo "::: Options:" - echo "::: -w, whitelist Whitelist domains" - echo "::: -b, blacklist Blacklist domains" - echo "::: -d, debug Start a debugging session if having trouble" - echo "::: -f, flush Flush the pihole.log file" - echo "::: -u, updateDashboard Update the web dashboard manually" - 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 "::: -c, chronometer Calculates stats and displays to an LCD" - echo "::: -h, help Show this help dialog" - echo "::: -v, version Show current versions" - echo "::: uninstall Uninstall Pi-Hole from your system!" - exit 1 + echo "::: Control all PiHole specific functions!" + echo ":::" + echo "::: Usage: pihole [options]" + echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" + echo ":::" + echo "::: Options:" + echo "::: -w, whitelist Whitelist domains" + echo "::: -b, blacklist Blacklist domains" + echo "::: -d, debug Start a debugging session if having trouble" + echo "::: -f, flush Flush the pihole.log file" + echo "::: -u, updateDashboard Update the web dashboard manually" + 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 "::: -c, chronometer Calculates stats and displays to an LCD" + echo "::: -h, help Show this help dialog" + echo "::: -v, version Show current versions" + echo "::: uninstall Uninstall Pi-Hole from your system :(!" + exit 1 } if [[ $# = 0 ]]; then - helpFunc + helpFunc fi # Handle redirecting to specific functions based on arguments From 95edb49bb824daa93fc37a57a014256844728d92 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Mon, 1 Aug 2016 21:43:13 +0100 Subject: [PATCH 21/53] Add option for uploading debug log to termbin --- advanced/Scripts/piholeDebug.sh | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 36ae15bc..ec08c984 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -337,17 +337,27 @@ function dumpPiHoleLog { # Anything to be done after capturing of pihole.log terminates function finalWork { - echo "::: Finshed debugging!" - TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) + 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) + ;; + *) + echo "::: Log will NOT be uploaded to Termbin." + ;; + esac - # Check if termbin.com is reachable. When it's not, point to local log instead - if [ -n "$TERMBIN" ] - then - echo "::: Debug log can be found at : $TERMBIN" - else - echo "::: Debug log can be found at : /var/log/pihole_debug.log" - fi + # Check if termbin.com is reachable. When it's not, point to local log instead + if [ -n "$TERMBIN" ] + then + echo "::: Debug log can be found at : $TERMBIN" + else + echo "::: Debug log can be found at : /var/log/pihole_debug.log" + fi } + trap finalWork EXIT ### Method calls for additional logging ### From a9a499939ec1ea8add866479b7d5676cd1e0a4f8 Mon Sep 17 00:00:00 2001 From: "Daniel (Fourdee)" Date: Fri, 12 Aug 2016 12:44:45 +0100 Subject: [PATCH 22/53] Fourdee - See notes: https://github.com/pi-hole/pi-hole/issues/602 + Improve available free disk space check. + Option to override if the free disk space check is not a valid integer. --- automated install/basic-install.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 254d601f..994ed94c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -155,20 +155,35 @@ In the next section, you can choose to use your current network settings (DHCP) verifyFreeDiskSpace() { + # 50MB is the minimum space needed (45MB install (includes web admin bootstrap/jquery libraries etc) + 5MB one day of logs.) - requiredFreeBytes=51200 + # - Fourdee: Local ensures the variable is only created, and accessible within this function/void. Generally considered a "good" coding practice for non-global variables. + local requiredFreeBytes=51200 + local existingFreeBytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') - existingFreeBytes=$(df -lk / 2>&1 | awk '{print $4}' | head -2 | tail -1) + # - Unknown free disk space , not a integer if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then - existingFreeBytes=$(df -lk /dev 2>&1 | awk '{print $4}' | head -2 | tail -1) - fi - if [[ $existingFreeBytes -lt $requiredFreeBytes ]]; 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 existingFreeBytes ($existingFreeBytes)" + echo "Unknown free space, user aborted, exiting..." + exit + + fi + + # - Insufficient free disk space + elif [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then + 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 echo "$existingFreeBytes is less than $requiredFreeBytes" echo "Insufficient free space, exiting..." exit 1 + fi + } From 037318e2ffdb5edbcd67ad0844a6053f84cdbcea Mon Sep 17 00:00:00 2001 From: "Daniel (Fourdee)" Date: Fri, 12 Aug 2016 13:20:30 +0100 Subject: [PATCH 23/53] Provide non-zero exit code, as per existing sourcecode. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 994ed94c..0ed95976 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -170,7 +170,7 @@ verifyFreeDiskSpace() { echo "non-integer value from existingFreeBytes ($existingFreeBytes)" echo "Unknown free space, user aborted, exiting..." - exit + exit 1 fi From 3ade7a8b0eccc7b63766c85d626777db5d0c5f26 Mon Sep 17 00:00:00 2001 From: Patrick Geneva Date: Fri, 5 Aug 2016 21:27:55 -0400 Subject: [PATCH 24/53] Added - Readme Windows Tray App --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index acfce86c..09de0d03 100644 --- a/README.md +++ b/README.md @@ -102,6 +102,7 @@ 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) - [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) +- [Windows Tray Stat Application](https://github.com/goldbattle/copernicus) ## Coverage From ae47be0ce92376c64f37deb9fd96217d3fe87782 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 17 Aug 2016 18:59:00 +0100 Subject: [PATCH 25/53] Add HelpFunc --- gravity.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gravity.sh b/gravity.sh index 6278d80a..b5b119f3 100755 --- a/gravity.sh +++ b/gravity.sh @@ -27,6 +27,18 @@ else 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 piholeIPv6file=/etc/pihole/.useIPv6 From f6ac0d73b4fd017096fda97d7cf3e991db1b6997 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 17 Aug 2016 19:08:55 +0100 Subject: [PATCH 26/53] Add force delete option --- gravity.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gravity.sh b/gravity.sh index b5b119f3..52d4ee5b 100755 --- a/gravity.sh +++ b/gravity.sh @@ -340,6 +340,23 @@ function gravity_reload() { echo " done!" } + +for var in "$@" +do + case "$var" in + "-f" | "--force" ) force=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 $force; 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_spinup From e4cc5b5b70f6cd578c2c662e17274937cd70fbcf Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 22:31:11 +0100 Subject: [PATCH 27/53] testing a new update method by detecting the existence of vars saved from install --- automated install/basic-install.sh | 587 +++++++++++++++-------------- 1 file changed, 296 insertions(+), 291 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0ed95976..3a413a51 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -19,6 +19,7 @@ ######## VARIABLES ######### + tmpLog=/tmp/pihole-install.log instalLogLoc=/etc/pihole/install.log @@ -27,6 +28,7 @@ webInterfaceDir="/var/www/html/admin" piholeGitUrl="https://github.com/pi-hole/pi-hole.git" piholeFilesDir="/etc/.pihole" +useUpdateVars=false # Find the rows and columns rows=$(tput lines) @@ -53,7 +55,7 @@ else fi fi -# Compatability +# Compatibility if [ -x "$(command -v rpm)" ];then # Fedora Family if [ -x "$(command -v dnf)" ];then @@ -104,8 +106,8 @@ spinner() while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do local temp=${spinstr#?} printf " [%c] " "$spinstr" - local spinstr=$temp${spinstr%"$temp"} - sleep $delay + local spinstr=${temp}${spinstr%"$temp"} + sleep ${delay} printf "\b\b\b\b\b\b" done printf " \b\b\b\b" @@ -119,38 +121,18 @@ findIPRoute() { 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() { # 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 - 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 - 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} } @@ -164,7 +146,7 @@ verifyFreeDiskSpace() { # - Unknown free disk space , not a integer if ! [[ "$existingFreeBytes" =~ ^([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 + 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 @@ -175,9 +157,9 @@ verifyFreeDiskSpace() { fi # - Insufficient free disk space - elif [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then + elif [[ ${existingFreeBytes} -lt ${requiredFreeBytes} ]]; then - 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 + 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} echo "$existingFreeBytes is less than $requiredFreeBytes" echo "Insufficient free space, exiting..." exit 1 @@ -190,13 +172,13 @@ verifyFreeDiskSpace() { chooseInterface() { # Turn the available interfaces into an array so it can be used with a whiptail dialog interfacesArray=() - firstloop=1 + firstLoop=1 while read -r line do mode="OFF" - if [[ $firstloop -eq 1 ]]; then - firstloop=0 + if [[ ${firstLoop} -eq 1 ]]; then + firstLoop=0 mode="ON" fi interfacesArray+=("$line" "available" "$mode") @@ -204,14 +186,15 @@ chooseInterface() { # Find out how many interfaces are available to choose from 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) if [[ $? = 0 ]]; then - for desiredInterface in $chooseInterfaceOptions + for desiredInterface in ${chooseInterfaceOptions} do - piholeInterface=$desiredInterface + piholeInterface=${desiredInterface} echo "::: Using interface: $piholeInterface" echo "${piholeInterface}" > /tmp/piholeINT + echo "piholeInterface=${piholeInterface}" > /etc/pihole/setupVars.conf done else echo "::: Cancel selected, exiting...." @@ -229,38 +212,40 @@ cleanupIPv6() { use4andor6() { # 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 IPv6 "Block ads over IPv6" off) choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) if [[ $? = 0 ]];then - for choice in $choices + for choice in ${choices} do - case $choice in + case ${choice} in IPv4 ) useIPv4=true;; IPv6 ) useIPv6=true;; esac done - if [ $useIPv4 ] && [ ! $useIPv6 ]; then + if [ ${useIPv4} ] && [ ! ${useIPv6} ]; then getStaticIPv4Settings setStaticIPv4 + ${SUDO} echo "IPv4addr=${IPv4addr}" > /etc/pihole/setupVars.conf echo "::: Using IPv4 on $IPv4addr" echo "::: IPv6 will NOT be used." fi - if [ ! $useIPv4 ] && [ $useIPv6 ]; then + if [ ! ${useIPv4} ] && [ ${useIPv6} ]; then useIPv6dialog echo "::: IPv4 will NOT be used." echo "::: Using IPv6 on $piholeIPv6" fi - if [ $useIPv4 ] && [ $useIPv6 ]; then + if [ ${useIPv4} ] && [ ${useIPv6} ]; then getStaticIPv4Settings setStaticIPv4 + ${SUDO} echo "IPv4addr=${IPv4addr}" > /etc/pihole/setupVars.conf useIPv6dialog echo "::: Using IPv4 on $IPv4addr" echo "::: Using IPv6 on $piholeIPv6" fi - if [ ! $useIPv4 ] && [ ! $useIPv6 ]; then + if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then echo "::: Cannot continue, neither IPv4 or IPv6 selected" echo "::: Exiting" exit 1 @@ -275,45 +260,46 @@ use4andor6() { useIPv6dialog() { # 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) }') - whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." $r $c + ${SUDO} echo "piholeIPv6=${piholeIPv6}" > /etc/pihole/setupVars.conf + 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() { # 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? 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. 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. -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 - $SUDO echo "${IPv4addr%/*}" > /etc/pihole/piholeIP + ${SUDO} echo "${IPv4addr%/*}" > /etc/pihole/piholeIP # Nothing else to do since the variables are already set above else # 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 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 # 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 echo "::: Your static IPv4 address: $IPv4addr" # 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 echo "::: Your static IPv4 gateway: $IPv4gw" # 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? 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 # 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 "$piholeInterface" > /tmp/piholeINT + ${SUDO} echo "${IPv4addr%/*}" > /etc/pihole/piholeIP + ${SUDO} echo "$piholeInterface" > /tmp/piholeINT # After that's done, the loop ends and we move on ipSettingsCorrect=True else @@ -342,7 +328,7 @@ setDHCPCD() { echo "## interface $piholeInterface static ip_address=$IPv4addr 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() { @@ -352,33 +338,33 @@ setStaticIPv4() { echo "::: Static IP already configured" else setDHCPCD - $SUDO ip addr replace dev "$piholeInterface" "$IPv4addr" + ${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr" echo ":::" echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." echo ":::" fi - elif [[ -f /etc/sysconfig/network-scripts/ifcfg-$piholeInterface ]];then + elif [[ -f /etc/sysconfig/network-scripts/ifcfg-${piholeInterface} ]];then # Fedora Family - IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-$piholeInterface - if grep -q "$IPv4addr" $IFCFG_FILE; then + IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${piholeInterface} + if grep -q "$IPv4addr" ${IFCFG_FILE}; then echo "::: Static IP already configured" else - IPADDR=$(echo $IPv4addr | cut -f1 -d/) - CIDR=$(echo $IPv4addr | cut -f2 -d/) + IPADDR=$(echo ${IPv4addr} | cut -f1 -d/) + CIDR=$(echo ${IPv4addr} | cut -f2 -d/) # 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: - $SUDO echo "# Configured via Pi-Hole installer" > $IFCFG_FILE - $SUDO echo "DEVICE=$piholeInterface" >> $IFCFG_FILE - $SUDO echo "BOOTPROTO=none" >> $IFCFG_FILE - $SUDO echo "ONBOOT=yes" >> $IFCFG_FILE - $SUDO echo "IPADDR=$IPADDR" >> $IFCFG_FILE - $SUDO echo "PREFIX=$CIDR" >> $IFCFG_FILE - $SUDO echo "USERCTL=no" >> $IFCFG_FILE - $SUDO ip addr replace dev "$piholeInterface" "$IPv4addr" + ${SUDO} echo "# Configured via Pi-Hole installer" > ${IFCFG_FILE} + ${SUDO} echo "DEVICE=$piholeInterface" >> ${IFCFG_FILE} + ${SUDO} echo "BOOTPROTO=none" >> ${IFCFG_FILE} + ${SUDO} echo "ONBOOT=yes" >> ${IFCFG_FILE} + ${SUDO} echo "IPADDR=$IPADDR" >> ${IFCFG_FILE} + ${SUDO} echo "PREFIX=$CIDR" >> ${IFCFG_FILE} + ${SUDO} echo "USERCTL=no" >> ${IFCFG_FILE} + ${SUDO} ip addr replace dev "$piholeInterface" "$IPv4addr" if [ -x "$(command -v nmcli)" ];then # 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 echo ":::" echo "::: Setting IP to $IPv4addr. You may need to restart after the install is complete." @@ -396,20 +382,20 @@ function valid_ip() local ip=$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 IFS='.' - ip=($ip) - IFS=$OIFS + ip=(${ip}) + IFS=${OIFS} [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] stat=$? fi - return $stat + return ${stat} } 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 OpenDNS "" off Level3 "" off @@ -418,85 +404,88 @@ setDNS(){ Custom "" off) DNSchoices=$("${DNSChoseCmd[@]}" "${DNSChooseOptions[@]}" 2>&1 >/dev/tty) if [[ $? = 0 ]];then - case $DNSchoices in - Google) - echo "::: Using Google DNS servers." - piholeDNS1="8.8.8.8" - piholeDNS2="8.8.4.4" - ;; - OpenDNS) - echo "::: Using OpenDNS servers." - piholeDNS1="208.67.222.222" - piholeDNS2="208.67.220.220" - ;; - Level3) - echo "::: Using Level3 servers." - piholeDNS1="4.2.2.1" - piholeDNS2="4.2.2.2" - ;; - Norton) - echo "::: Using Norton ConnectSafe servers." - piholeDNS1="199.85.126.10" - piholeDNS2="199.85.127.10" - ;; - Comodo) - echo "::: Using Comodo Secure servers." - piholeDNS1="8.26.56.26" - piholeDNS2="8.20.247.20" - ;; - Custom) - until [[ $DNSSettingsCorrect = True ]] - do - strInvalid="Invalid" - if [ ! $piholeDNS1 ]; then - if [ ! $piholeDNS2 ]; then - prePopulate="" - else - prePopulate=", $piholeDNS2" - fi - elif [ $piholeDNS1 ] && [ ! $piholeDNS2 ]; then - prePopulate="$piholeDNS1" - elif [ $piholeDNS1 ] && [ $piholeDNS2 ]; then - prePopulate="$piholeDNS1, $piholeDNS2" - 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) - if [[ $? = 0 ]];then - piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') - piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') - if ! valid_ip "$piholeDNS1" || [ ! "$piholeDNS1" ]; then - piholeDNS1=$strInvalid - fi - if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then - piholeDNS2=$strInvalid - fi - else - echo "::: Cancel selected, exiting...." - exit 1 - fi - 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 - if [[ $piholeDNS1 == "$strInvalid" ]]; then - piholeDNS1="" - fi - if [[ $piholeDNS2 == "$strInvalid" ]]; then - piholeDNS2="" - fi - DNSSettingsCorrect=False - 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 - DNSSettingsCorrect=True - else - # If the settings are wrong, the loop continues - DNSSettingsCorrect=False - fi - fi - done - ;; - esac + case ${DNSchoices} in + Google) + echo "::: Using Google DNS servers." + piholeDNS1="8.8.8.8" + piholeDNS2="8.8.4.4" + ;; + OpenDNS) + echo "::: Using OpenDNS servers." + piholeDNS1="208.67.222.222" + piholeDNS2="208.67.220.220" + ;; + Level3) + echo "::: Using Level3 servers." + piholeDNS1="4.2.2.1" + piholeDNS2="4.2.2.2" + ;; + Norton) + echo "::: Using Norton ConnectSafe servers." + piholeDNS1="199.85.126.10" + piholeDNS2="199.85.127.10" + ;; + Comodo) + echo "::: Using Comodo Secure servers." + piholeDNS1="8.26.56.26" + piholeDNS2="8.20.247.20" + ;; + Custom) + until [[ ${DNSSettingsCorrect} = True ]] + do + strInvalid="Invalid" + if [ ! ${piholeDNS1} ]; then + if [ ! ${piholeDNS2} ]; then + prePopulate="" + else + prePopulate=", $piholeDNS2" + fi + elif [ ${piholeDNS1} ] && [ ! ${piholeDNS2} ]; then + prePopulate="$piholeDNS1" + elif [ ${piholeDNS1} ] && [ ${piholeDNS2} ]; then + prePopulate="$piholeDNS1, $piholeDNS2" + 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) + if [[ $? = 0 ]];then + piholeDNS1=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$1}') + piholeDNS2=$(echo "$piholeDNS" | sed 's/[, \t]\+/,/g' | awk -F, '{print$2}') + if ! valid_ip "$piholeDNS1" || [ ! "$piholeDNS1" ]; then + piholeDNS1=${strInvalid} + fi + if ! valid_ip "$piholeDNS2" && [ "$piholeDNS2" ]; then + piholeDNS2=${strInvalid} + fi + else + echo "::: Cancel selected, exiting...." + exit 1 + fi + 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} + if [[ ${piholeDNS1} == "$strInvalid" ]]; then + piholeDNS1="" + fi + if [[ ${piholeDNS2} == "$strInvalid" ]]; then + piholeDNS2="" + fi + DNSSettingsCorrect=False + 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 + DNSSettingsCorrect=True + else + # If the settings are wrong, the loop continues + DNSSettingsCorrect=False + fi + fi + done + ;; + esac else echo "::: Cancel selected. Exiting..." exit 1 fi + + ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> /etc/pihole/setupVars/conf + ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> /etc/pihole/setupVars/conf } versionCheckDNSmasq(){ @@ -508,106 +497,106 @@ versionCheckDNSmasq(){ newFileToInstall="/etc/.pihole/advanced/01-pihole.conf" newFileFinalLocation="/etc/dnsmasq.d/01-pihole.conf" - if [ -f $dnsFile1 ]; then + if [ -f ${dnsFile1} ]; then 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 -n "::: Backing up dnsmasq.conf to dnsmasq.conf.orig..." - $SUDO mv -f $dnsFile1 $dnsFile2 + ${SUDO} mv -f ${dnsFile1} ${dnsFile2} echo " done." echo -n "::: Restoring default dnsmasq.conf..." - $SUDO cp $defaultFile $dnsFile1 + ${SUDO} cp ${defaultFile} ${dnsFile1} echo " done." else echo " it is not a pi-hole file, leaving alone!" fi else echo -n "::: No dnsmasq.conf found.. restoring default dnsmasq.conf..." - $SUDO cp $defaultFile $dnsFile1 + ${SUDO} cp ${defaultFile} ${dnsFile1} echo " done." fi echo -n "::: Copying 01-pihole.conf to /etc/dnsmasq.d/01-pihole.conf..." - $SUDO cp $newFileToInstall $newFileFinalLocation + ${SUDO} cp ${newFileToInstall} ${newFileFinalLocation} echo " done." - $SUDO sed -i "s/@INT@/$piholeInterface/" $newFileFinalLocation + ${SUDO} sed -i "s/@INT@/$piholeInterface/" ${newFileFinalLocation} if [[ "$piholeDNS1" != "" ]]; then - $SUDO sed -i "s/@DNS1@/$piholeDNS1/" $newFileFinalLocation + ${SUDO} sed -i "s/@DNS1@/$piholeDNS1/" ${newFileFinalLocation} else - $SUDO sed -i '/^server=@DNS1@/d' $newFileFinalLocation + ${SUDO} sed -i '/^server=@DNS1@/d' ${newFileFinalLocation} fi if [[ "$piholeDNS2" != "" ]]; then - $SUDO sed -i "s/@DNS2@/$piholeDNS2/" $newFileFinalLocation + ${SUDO} sed -i "s/@DNS2@/$piholeDNS2/" ${newFileFinalLocation} else - $SUDO sed -i '/^server=@DNS2@/d' $newFileFinalLocation + ${SUDO} sed -i '/^server=@DNS2@/d' ${newFileFinalLocation} 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() { # Install the scripts from /etc/.pihole to their various locations - $SUDO echo ":::" - $SUDO echo -n "::: Installing scripts to /opt/pihole..." + ${SUDO} echo ":::" + ${SUDO} echo -n "::: Installing scripts to /opt/pihole..." if [ ! -d /opt/pihole ]; then - $SUDO mkdir /opt/pihole - $SUDO chown "$USER":root /opt/pihole - $SUDO chmod u+srwx /opt/pihole + ${SUDO} mkdir /opt/pihole + ${SUDO} chown "$USER":root /opt/pihole + ${SUDO} chmod u+srwx /opt/pihole fi - $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/whitelist.sh /opt/pihole/whitelist.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/piholeLogFlush.sh /opt/pihole/piholeLogFlush.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/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh - $SUDO cp /etc/.pihole/advanced/Scripts/version.sh /opt/pihole/version.sh - $SUDO chmod 755 /opt/pihole/{gravity,chronometer,whitelist,blacklist,piholeLogFlush,updateDashboard,uninstall,setupLCD,version}.sh - $SUDO cp /etc/.pihole/pihole /usr/local/bin/pihole - $SUDO chmod 755 /usr/local/bin/pihole - $SUDO cp /etc/.pihole/advanced/bash-completion/pihole /etc/bash_completion.d/pihole + ${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/whitelist.sh /opt/pihole/whitelist.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/piholeLogFlush.sh /opt/pihole/piholeLogFlush.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/advanced/Scripts/setupLCD.sh /opt/pihole/setupLCD.sh + ${SUDO} cp /etc/.pihole/advanced/Scripts/version.sh /opt/pihole/version.sh + ${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} cp /etc/.pihole/pihole /usr/local/bin/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 #Tidy up /usr/local/bin directory if installing over previous install. oldFiles=( gravity chronometer whitelist blacklist piholeLogFlush updateDashboard uninstall setupLCD piholeDebug) for i in "${oldFiles[@]}"; do if [ -f "/usr/local/bin/$i.sh" ]; then - $SUDO rm /usr/local/bin/"$i".sh + ${SUDO} rm /usr/local/bin/"$i".sh fi done - $SUDO echo " done." + ${SUDO} echo " done." } installConfigs() { # Install the configs from /etc/.pihole to their various locations - $SUDO echo ":::" - $SUDO echo "::: Installing configs..." + ${SUDO} echo ":::" + ${SUDO} echo "::: Installing configs..." versionCheckDNSmasq if [ ! -d "/etc/lighttpd" ]; then - $SUDO mkdir /etc/lighttpd - $SUDO chown "$USER":root /etc/lighttpd - $SUDO mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig + ${SUDO} mkdir /etc/lighttpd + ${SUDO} chown "$USER":root /etc/lighttpd + ${SUDO} mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig fi - $SUDO cp /etc/.pihole/advanced/$LIGHTTPD_CFG /etc/lighttpd/lighttpd.conf - $SUDO mkdir -p /var/run/lighttpd - $SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/run/lighttpd - $SUDO mkdir -p /var/cache/lighttpd/compress - $SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/cache/lighttpd/compress + ${SUDO} cp /etc/.pihole/advanced/${LIGHTTPD_CFG} /etc/lighttpd/lighttpd.conf + ${SUDO} mkdir -p /var/run/lighttpd + ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/run/lighttpd + ${SUDO} mkdir -p /var/cache/lighttpd/compress + ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/cache/lighttpd/compress } stopServices() { # Stop dnsmasq and lighttpd - $SUDO echo ":::" - $SUDO echo -n "::: Stopping services..." + ${SUDO} echo ":::" + ${SUDO} echo -n "::: Stopping services..." #$SUDO service dnsmasq stop & spinner $! || true if [ -x "$(command -v systemctl)" ]; then - $SUDO systemctl stop lighttpd & spinner $! || true + ${SUDO} systemctl stop lighttpd & spinner $! || true else - $SUDO service lighttpd stop & spinner $! || true + ${SUDO} service lighttpd stop & spinner $! || true fi - $SUDO echo " done." + ${SUDO} echo " done." } installerDependencies() { @@ -617,7 +606,7 @@ installerDependencies() { # 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 # 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") today=$(date "+%b %e") @@ -625,15 +614,15 @@ installerDependencies() { #update package lists echo ":::" 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!" fi echo ":::" echo -n "::: Checking $PKG_MANAGER for upgraded packages...." - updatesToInstall=$(eval "$SUDO $PKG_COUNT") + updatesToInstall=$(eval "${SUDO} ${PKG_COUNT}") echo " done!" echo ":::" - if [[ $updatesToInstall -eq "0" ]]; then + if [[ ${updatesToInstall} -eq "0" ]]; then echo "::: Your pi is up to date! Continuing with pi-hole installation..." else echo "::: There are $updatesToInstall updates availible for your pi!" @@ -644,10 +633,10 @@ installerDependencies() { echo "::: Checking installer dependencies..." for i in "${INSTALLER_DEPS[@]}"; do echo -n "::: Checking for $i..." - package_check $i > /dev/null + package_check ${i} > /dev/null if ! [ $? -eq 0 ]; then echo -n " Not found! Installing...." - $SUDO $PKG_INSTALL "$i" > /dev/null 2>&1 + ${SUDO} ${PKG_INSTALL} "$i" > /dev/null 2>&1 echo " done!" else echo " already installed!" @@ -661,10 +650,10 @@ checkForDependencies() { for i in "${PIHOLE_DEPS[@]}"; do echo -n "::: Checking for $i..." - package_check $i > /dev/null + package_check ${i} > /dev/null if ! [ $? -eq 0 ]; then echo -n " Not found! Installing...." - $SUDO $PKG_INSTALL "$i" > /dev/null & spinner $! + ${SUDO} ${PKG_INSTALL} "$i" > /dev/null & spinner $! echo " done!" else echo " already installed!" @@ -676,18 +665,18 @@ getGitFiles() { # Setup git repos for base files and web admin echo ":::" echo "::: Checking for existing base files..." - if is_repo $piholeFilesDir; then - make_repo $piholeFilesDir $piholeGitUrl + if is_repo ${piholeFilesDir}; then + make_repo ${piholeFilesDir} ${piholeGitUrl} else - update_repo $piholeFilesDir + update_repo ${piholeFilesDir} fi echo ":::" echo "::: Checking for existing web interface..." - if is_repo $webInterfaceDir; then - make_repo $webInterfaceDir $webInterfaceGitUrl + if is_repo ${webInterfaceDir}; then + make_repo ${webInterfaceDir} ${webInterfaceGitUrl} else - update_repo $webInterfaceDir + update_repo ${webInterfaceDir} fi } @@ -705,8 +694,8 @@ is_repo() { make_repo() { # Remove the non-repod interface and clone the interface echo -n "::: Cloning $2 into $1..." - $SUDO rm -rf "$1" - $SUDO git clone -q "$2" "$1" > /dev/null & spinner $! + ${SUDO} rm -rf "$1" + ${SUDO} git clone -q "$2" "$1" > /dev/null & spinner $! echo " done!" } @@ -714,7 +703,7 @@ update_repo() { # Pull the latest commits echo -n "::: Updating repo in $1..." cd "$1" || exit - $SUDO git pull -q > /dev/null & spinner $! + ${SUDO} git pull -q > /dev/null & spinner $! echo " done!" } @@ -722,59 +711,59 @@ update_repo() { CreateLogFile() { # Create logfiles if necessary 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 - $SUDO touch /var/log/pihole.log - $SUDO chmod 644 /var/log/pihole.log - $SUDO chown dnsmasq:root /var/log/pihole.log - $SUDO echo " done!" + ${SUDO} touch /var/log/pihole.log + ${SUDO} chmod 644 /var/log/pihole.log + ${SUDO} chown dnsmasq:root /var/log/pihole.log + ${SUDO} echo " done!" else - $SUDO echo " already exists!" + ${SUDO} echo " already exists!" fi } installPiholeWeb() { # Install the web interface - $SUDO echo ":::" - $SUDO echo -n "::: Installing pihole custom index page..." + ${SUDO} echo ":::" + ${SUDO} echo -n "::: Installing pihole custom index page..." if [ -d "/var/www/html/pihole" ]; then - $SUDO echo " Existing page detected, not overwriting" + ${SUDO} echo " Existing page detected, not overwriting" else - $SUDO mkdir /var/www/html/pihole + ${SUDO} mkdir /var/www/html/pihole 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 printf "\n:::\tNo default index.lighttpd.html file found... not backing up" fi - $SUDO cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. - $SUDO echo " done!" + ${SUDO} cp /etc/.pihole/advanced/index.* /var/www/html/pihole/. + ${SUDO} echo " done!" fi # Install Sudoer file echo -n "::: Installing sudoer file..." - $SUDO mkdir -p /etc/sudoers.d/ - $SUDO cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole - $SUDO chmod 0440 /etc/sudoers.d/pihole + ${SUDO} mkdir -p /etc/sudoers.d/ + ${SUDO} cp /etc/.pihole/advanced/pihole.sudo /etc/sudoers.d/pihole + ${SUDO} chmod 0440 /etc/sudoers.d/pihole echo " done!" } installCron() { # Install the cron job - $SUDO echo ":::" - $SUDO echo -n "::: Installing latest Cron script..." - $SUDO cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole - $SUDO echo " done!" + ${SUDO} echo ":::" + ${SUDO} echo -n "::: Installing latest Cron script..." + ${SUDO} cp /etc/.pihole/advanced/pihole.cron /etc/cron.d/pihole + ${SUDO} echo " done!" } runGravity() { # Rub gravity.sh to build blacklists - $SUDO echo ":::" - $SUDO echo "::: Preparing to run gravity.sh to refresh hosts..." + ${SUDO} echo ":::" + ${SUDO} echo "::: Preparing to run gravity.sh to refresh hosts..." if ls /etc/pihole/list* 1> /dev/null 2>&1; then echo "::: Cleaning up previous install (preserving whitelist/blacklist)" - $SUDO rm /etc/pihole/list.* + ${SUDO} rm /etc/pihole/list.* fi echo "::: Running gravity.sh" - $SUDO /opt/pihole/gravity.sh + ${SUDO} /opt/pihole/gravity.sh } setUser(){ @@ -784,28 +773,28 @@ setUser(){ echo "::: User 'pihole' already exists" else echo "::: User 'pihole' doesn't exist. Creating..." - $SUDO useradd -r -s /usr/sbin/nologin pihole + ${SUDO} useradd -r -s /usr/sbin/nologin pihole fi } configureFirewall() { # Allow HTTP and DNS traffic if [ -x "$(command -v firewall-cmd)" ]; then - $SUDO firewall-cmd --state > /dev/null + ${SUDO} firewall-cmd --state > /dev/null if [[ $? -eq 0 ]]; then - $SUDO echo "::: Configuring firewalld for httpd and dnsmasq.." - $SUDO firewall-cmd --permanent --add-port=80/tcp - $SUDO firewall-cmd --permanent --add-port=53/tcp - $SUDO firewall-cmd --permanent --add-port=53/udp - $SUDO firewall-cmd --reload + ${SUDO} echo "::: Configuring firewalld for httpd and dnsmasq.." + ${SUDO} firewall-cmd --permanent --add-port=80/tcp + ${SUDO} firewall-cmd --permanent --add-port=53/tcp + ${SUDO} firewall-cmd --permanent --add-port=53/udp + ${SUDO} firewall-cmd --reload fi elif [ -x "$(command -v iptables)" ]; then - $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 53 -j ACCEPT - $SUDO iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT + ${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 53 -j ACCEPT + ${SUDO} iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT else - $SUDO echo "::: No firewall detected.. skipping firewall configuration." + ${SUDO} echo "::: No firewall detected.. skipping firewall configuration." fi } @@ -814,15 +803,15 @@ installPihole() { checkForDependencies # done stopServices setUser - $SUDO mkdir -p /etc/pihole/ + ${SUDO} mkdir -p /etc/pihole/ if [ ! -d "/var/www/html" ]; then - $SUDO mkdir -p /var/www/html + ${SUDO} mkdir -p /var/www/html fi - $SUDO chown $LIGHTTPD_USER:$LIGHTTPD_GROUP /var/www/html - $SUDO chmod 775 /var/www/html - $SUDO usermod -a -G $LIGHTTPD_GROUP pihole + ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html + ${SUDO} chmod 775 /var/www/html + ${SUDO} usermod -a -G ${LIGHTTPD_GROUP} pihole 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 printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" fi @@ -830,6 +819,7 @@ installPihole() { getGitFiles installScripts installConfigs + installConfigs CreateLogFile configureSelinux installPiholeWeb @@ -845,22 +835,22 @@ configureSelinux() { package_check "selinux-policy-devel" > /dev/null if ! [ $? -eq 0 ]; then 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!" else echo " already installed!" fi 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 echo -n "Success\n" fi printf ":::\tCompiling Pi-Hole SELinux policy..\n" - $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 -i /etc/pihole/pihole.pp - $SUDO rm -f /etc/pihole/pihole.mod - $SUDO semodule -l | grep pihole > /dev/null + ${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 -i /etc/pihole/pihole.pp + ${SUDO} rm -f /etc/pihole/pihole.mod + ${SUDO} semodule -l | grep pihole > /dev/null if [ $? -eq 0 ]; then printf "::: Successfully installed Pi-Hole SELinux policy\n" else @@ -879,51 +869,66 @@ IPv6: $piholeIPv6 If you set a new IP address, you should restart the Pi. 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(){ + + if (whiptail --title "Existing Install detected" --yesno "We have detected you are installing over the top of an existing install.\n\n\nWould you like update?" --defaultyes ${r} ${c}); then + echo "::: Updating existing install selected" + useUpdateVars = true + fi + } ######## SCRIPT ############ -# Start the installer -$SUDO mkdir -p /etc/pihole/ +if [[ -f /etc/pihole/setupVars.conf ]];then + . /etc/pihole/setupVars.conf + updateDialogs +fi +# Start the installer # Install packages used by this installation script installerDependencies -welcomeDialogs +if [[ ${useUpdateVars} == false ]]; then + ${SUDO} echo "" > /etc/pihole/setupVars.conf + ${SUDO} mkdir -p /etc/pihole/ + welcomeDialogs + # Verify there is enough disk space for the install + verifyFreeDiskSpace + # Find IP used to route to outside world + findIPRoute + # Find interfaces and let the user choose one + chooseInterface + # Let the user decide if they want to block ads over IPv4 and/or IPv6 + use4andor6 + # Decide what upstream DNS Servers to use + setDNS + # Install and log everything to a file + installPihole | tee ${tmpLog} +else + echo "Hi!" +fi -# Verify there is enough disk space for the install -verifyFreeDiskSpace -# Just back up the original Pi-hole right away since it won't take long and it gets it out of the way -backupLegacyPihole -# Find IP used to route to outside world -findIPRoute -# Find interfaces and let the user choose one -chooseInterface -# Let the user decide if they want to block ads over IPv4 and/or IPv6 -use4andor6 -# Decide what upstream DNS Servers to use -setDNS - -# Install and log everything to a file -installPihole | tee $tmpLog # Move the log file into /etc/pihole for storage -$SUDO mv $tmpLog $instalLogLoc +${SUDO} mv ${tmpLog} ${instalLogLoc} displayFinalMessage echo -n "::: Restarting services..." # Start services if [ -x "$(command -v systemctl)" ]; then - $SUDO systemctl enable dnsmasq - $SUDO systemctl restart dnsmasq - $SUDO systemctl enable lighttpd - $SUDO systemctl start lighttpd + ${SUDO} systemctl enable dnsmasq + ${SUDO} systemctl restart dnsmasq + ${SUDO} systemctl enable lighttpd + ${SUDO} systemctl start lighttpd else - $SUDO service dnsmasq restart - $SUDO service lighttpd start + ${SUDO} service dnsmasq restart + ${SUDO} service lighttpd start fi echo " done." From 9fb549293acd6f4af34d0425702de80898cb1050 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 22:34:50 +0100 Subject: [PATCH 28/53] APPEND --- automated install/basic-install.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3a413a51..2ebc6784 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -194,7 +194,7 @@ chooseInterface() { piholeInterface=${desiredInterface} echo "::: Using interface: $piholeInterface" echo "${piholeInterface}" > /tmp/piholeINT - echo "piholeInterface=${piholeInterface}" > /etc/pihole/setupVars.conf + echo "piholeInterface=${piholeInterface}" >> /etc/pihole/setupVars.conf done else echo "::: Cancel selected, exiting...." @@ -228,7 +228,7 @@ use4andor6() { if [ ${useIPv4} ] && [ ! ${useIPv6} ]; then getStaticIPv4Settings setStaticIPv4 - ${SUDO} echo "IPv4addr=${IPv4addr}" > /etc/pihole/setupVars.conf + ${SUDO} echo "IPv4addr=${IPv4addr}" >> /etc/pihole/setupVars.conf echo "::: Using IPv4 on $IPv4addr" echo "::: IPv6 will NOT be used." fi @@ -240,7 +240,7 @@ use4andor6() { if [ ${useIPv4} ] && [ ${useIPv6} ]; then getStaticIPv4Settings setStaticIPv4 - ${SUDO} echo "IPv4addr=${IPv4addr}" > /etc/pihole/setupVars.conf + ${SUDO} echo "IPv4addr=${IPv4addr}" >> /etc/pihole/setupVars.conf useIPv6dialog echo "::: Using IPv4 on $IPv4addr" echo "::: Using IPv6 on $piholeIPv6" @@ -260,7 +260,7 @@ use4andor6() { useIPv6dialog() { # 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) }') - ${SUDO} echo "piholeIPv6=${piholeIPv6}" > /etc/pihole/setupVars.conf + ${SUDO} echo "piholeIPv6=${piholeIPv6}" >> /etc/pihole/setupVars.conf whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." ${r} ${c} ${SUDO} touch /etc/pihole/.useIPv6 From 8fc83655ab534d6d5fef53bc3c30cf5641df1b18 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 22:38:16 +0100 Subject: [PATCH 29/53] correct filename spelling mistake --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 2ebc6784..a4a12c4a 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -484,8 +484,8 @@ setDNS(){ exit 1 fi - ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> /etc/pihole/setupVars/conf - ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> /etc/pihole/setupVars/conf + ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> /etc/pihole/setupVars.conf + ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> /etc/pihole/setupVars.conf } versionCheckDNSmasq(){ From cc157def632101913ab360a66ecee9384389df48 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 22:40:27 +0100 Subject: [PATCH 30/53] remove --defaultyes from update whiptail --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index a4a12c4a..e8ae5a76 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -874,7 +874,7 @@ View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" $ updateDialogs(){ - if (whiptail --title "Existing Install detected" --yesno "We have detected you are installing over the top of an existing install.\n\n\nWould you like update?" --defaultyes ${r} ${c}); then + if (whiptail --title "Existing Install detected" --yesno "We have detected you are installing over the top of an existing install.\n\n\nWould you like update?" ${r} ${c}); then echo "::: Updating existing install selected" useUpdateVars = true fi From f54828352d3441f80355a1a1110001195d52450a Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 22:42:04 +0100 Subject: [PATCH 31/53] remove spaces from update bool set --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index e8ae5a76..f9341206 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -876,7 +876,7 @@ updateDialogs(){ if (whiptail --title "Existing Install detected" --yesno "We have detected you are installing over the top of an existing install.\n\n\nWould you like update?" ${r} ${c}); then echo "::: Updating existing install selected" - useUpdateVars = true + useUpdateVars=true fi } From fdb104348c5e12ee3dd8773575ad0a0589e8025e Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 22:45:24 +0100 Subject: [PATCH 32/53] Add updatePihole method --- automated install/basic-install.sh | 51 +++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f9341206..f1568983 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -828,6 +828,52 @@ installPihole() { configureFirewall } +installPihole() { + # Install base files and web interface + checkForDependencies # done + stopServices + setUser + ${SUDO} mkdir -p /etc/pihole/ + if [ ! -d "/var/www/html" ]; then + ${SUDO} mkdir -p /var/www/html + fi + ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html + ${SUDO} chmod 775 /var/www/html + ${SUDO} usermod -a -G ${LIGHTTPD_GROUP} pihole + if [ -x "$(command -v lighty-enable-mod)" ]; then + ${SUDO} lighty-enable-mod fastcgi fastcgi-php > /dev/null + else + printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" + fi + + getGitFiles + installScripts + installConfigs + installConfigs + CreateLogFile + configureSelinux + installPiholeWeb + installCron + runGravity + configureFirewall +} + +updatePihole() { + # Install base files and web interface + checkForDependencies # done + stopServices + getGitFiles + installScripts + installConfigs + installConfigs + CreateLogFile + configureSelinux + installPiholeWeb + installCron + runGravity + configureFirewall +} + configureSelinux() { if [ -x "$(command -v getenforce)" ]; then printf "\n::: SELinux Detected\n" @@ -908,12 +954,9 @@ if [[ ${useUpdateVars} == false ]]; then # Install and log everything to a file installPihole | tee ${tmpLog} else - echo "Hi!" + updatePihole | tee ${tmpLog} fi - - - # Move the log file into /etc/pihole for storage ${SUDO} mv ${tmpLog} ${instalLogLoc} From 201304e6786a97e636b349ef6c0d68e091b82771 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 22:51:09 +0100 Subject: [PATCH 33/53] fix variables in gravity to stop it using -f wether it's set or not --- gravity.sh | 102 ++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/gravity.sh b/gravity.sh index 52d4ee5b..baf50a29 100755 --- a/gravity.sh +++ b/gravity.sh @@ -47,9 +47,9 @@ adListDefault=/etc/pihole/adlists.default whitelistScript=/opt/pihole/whitelist.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 - piholeIP=$(cat $piholeIPfile) + piholeIP=$(cat ${piholeIPfile}) #rm $piholeIPfile else # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script @@ -58,7 +58,7 @@ else piholeIP=${piholeIPCIDR%/*} 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 piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi @@ -66,22 +66,22 @@ fi # Variables for various stages of downloading and formatting the list ## Nate 3/26/2016 - Commented unused variables basename=pihole -piholeDir=/etc/$basename -adList=$piholeDir/gravity.list +piholeDir=/etc/${basename} +adList=${piholeDir}/gravity.list #blacklist=$piholeDir/blacklist.txt #whitelist=$piholeDir/whitelist.txt #latentWhitelist=$piholeDir/latentWhitelist.txt justDomainsExtension=domains -matterandlight=$basename.0.matterandlight.txt -supernova=$basename.1.supernova.txt -eventHorizon=$basename.2.eventHorizon.txt -accretionDisc=$basename.3.accretionDisc.txt +matterandlight=${basename}.0.matterandlight.txt +supernova=${basename}.1.supernova.txt +eventHorizon=${basename}.2.eventHorizon.txt +accretionDisc=${basename}.3.accretionDisc.txt #eyeOfTheNeedle=$basename.4.wormhole.txt # 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..." - . $piholeDir/pihole.conf + . ${piholeDir}/pihole.conf fi ########################### @@ -90,18 +90,18 @@ function gravity_collapse() { echo "::: Neutrino emissions detected..." echo ":::" #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 echo -n "::: Custom adList file detected. Reading..." sources=() while read -r line; do #Do not read commented out or blank lines - if [[ $line = \#* ]] || [[ ! $line ]]; then + if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then echo "" > /dev/null else - sources+=($line) + sources+=(${line}) fi - done < $adListFile + done < ${adListFile} echo " done!" else #no custom file found, use defaults! @@ -109,27 +109,27 @@ function gravity_collapse() { sources=() while read -r line; do #Do not read commented out or blank lines - if [[ $line = \#* ]] || [[ ! $line ]]; then + if [[ ${line} = \#* ]] || [[ ! ${line} ]]; then echo "" > /dev/null else - sources+=($line) + sources+=(${line}) fi - done < $adListDefault + done < ${adListDefault} echo " done!" fi # 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 # Will update later, needed for existing installs, new installs should # create this directory as non-root - $SUDO chmod 777 $piholeDir + ${SUDO} chmod 777 ${piholeDir} echo ":::" echo "::: Existing pihole directory found" else echo "::: Creating pihole directory..." - mkdir $piholeDir - $SUDO chmod 777 $piholeDir + mkdir ${piholeDir} + ${SUDO} chmod 777 ${piholeDir} fi } @@ -158,13 +158,13 @@ function gravity_transport() { # tmp file, so we don't have to store the (long!) lists in RAM patternBuffer=$(mktemp) heisenbergCompensator="" - if [[ -r $saveLocation ]]; then + if [[ -r ${saveLocation} ]]; then # if domain has been saved, add file for date check to only download newer heisenbergCompensator="-z $saveLocation" fi # Silently curl url - curl -s -L $cmd_ext $heisenbergCompensator -A "$agent" $url > $patternBuffer + curl -s -L ${cmd_ext} ${heisenbergCompensator} -A "$agent" ${url} > ${patternBuffer} # Check for list updates gravity_patternCheck "$patternBuffer" # Cleanup @@ -182,8 +182,8 @@ function gravity_spinup() { domain=$(echo "$url" | cut -d'/' -f3) # Save the file as list.#.domain - saveLocation=$piholeDir/list.$i.$domain.$justDomainsExtension - activeDomains[$i]=$saveLocation + saveLocation=${piholeDir}/list.${i}.${domain}.${justDomainsExtension} + activeDomains[$i]=${saveLocation} agent="Mozilla/10.0" @@ -213,10 +213,10 @@ function gravity_Schwarzchild() { echo "::: " # Find all active domains and compile them into one file and remove CRs echo -n "::: Aggregating list of domains..." - truncate -s 0 $piholeDir/$matterandlight + truncate -s 0 ${piholeDir}/${matterandlight} for i in "${activeDomains[@]}" do - cat "$i" | tr -d '\r' >> $piholeDir/$matterandlight + cat "$i" | tr -d '\r' >> ${piholeDir}/${matterandlight} done echo " done!" } @@ -224,7 +224,7 @@ function gravity_Schwarzchild() { function gravity_Blacklist(){ # Append blacklist entries if they exist 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") plural=; [[ "$numBlacklisted" != "1" ]] && plural=s @@ -241,12 +241,12 @@ function gravity_Whitelist() { for url in "${sources[@]}" do tmp=$(echo "$url" | awk -F '/' '{print $3}') - urls=("${urls[@]}" $tmp) + urls=("${urls[@]}" ${tmp}) done echo " done!" 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") plural=; [[ "$numWhitelisted" != "1" ]] && plural=s echo " $numWhitelisted domain${plural} whitelisted!" @@ -255,9 +255,9 @@ function gravity_Whitelist() { function gravity_unique() { # Sort and remove duplicates echo -n "::: Removing duplicate domains...." - sort -u $piholeDir/$supernova > $piholeDir/$eventHorizon + sort -u ${piholeDir}/${supernova} > ${piholeDir}/${eventHorizon} echo " done!" - numberOf=$(wc -l < $piholeDir/$eventHorizon) + numberOf=$(wc -l < ${piholeDir}/${eventHorizon}) echo "::: $numberOf unique domains trapped in the event horizon." } @@ -266,25 +266,25 @@ function gravity_hostFormat() { echo "::: Formatting domains into a HOSTS file..." hostname=$( $piholeDir/$accretionDisc - cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $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} else # 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) - echo -e "$piholeIP $hostname\n$piholeIP pi.hole" > $piholeDir/$accretionDisc - cat $piholeDir/$eventHorizon | awk -v ipv4addr="$piholeIP" '{sub(/\r$/,""); print ipv4addr" "$0}' >> $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} fi # 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 function gravity_blackbody() { # Loop through list files - for file in $piholeDir/*.$justDomainsExtension + for file in ${piholeDir}/*.${justDomainsExtension} do # If list is in active array then leave it (noop) else rm the list if [[ " ${activeDomains[@]} " =~ ${file} ]]; then @@ -301,10 +301,10 @@ function gravity_advanced() { # 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 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!" - numberOf=$(wc -l < $piholeDir/$supernova) + numberOf=$(wc -l < ${piholeDir}/${supernova}) echo "::: $numberOf domains being pulled in by gravity..." gravity_unique @@ -314,7 +314,7 @@ function gravity_reload() { #Clear no longer needed files... echo ":::" echo -n "::: Cleaning up un-needed files..." - $SUDO rm $piholeDir/pihole.*.txt + ${SUDO} rm ${piholeDir}/pihole.*.txt echo " done!" # Reload hosts file @@ -325,17 +325,17 @@ function gravity_reload() { #First escape forward slashes in the path: adList=${adList//\//\\\/} #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) - 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 - $SUDO killall -s HUP dnsmasq + ${SUDO} killall -s HUP dnsmasq else # service not running, start it up - $SUDO service dnsmasq start + ${SUDO} service dnsmasq start fi echo " done!" } @@ -351,13 +351,13 @@ done #Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list -if $force; then +if [[ ${force} ]]; then echo -n "::: Deleting exising list cache..." - $SUDO rm /etc/pihole/list.* + ${SUDO} rm /etc/pihole/list.* echo " done!" fi -$SUDO cp /etc/.pihole/adlists.default /etc/pihole/adlists.default +${SUDO} cp /etc/.pihole/adlists.default /etc/pihole/adlists.default gravity_collapse gravity_spinup gravity_Schwarzchild From 475d016029fc021948111f6432668be9668d3bb3 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 22:52:55 +0100 Subject: [PATCH 34/53] hmmm --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index baf50a29..9f11ee42 100755 --- a/gravity.sh +++ b/gravity.sh @@ -351,7 +351,7 @@ done #Overwrite adlists.default from /etc/.pihole in case any changes have been made. Changes should be saved in /etc/adlists.list -if [[ ${force} ]]; then +if [[ ${force} == true ]]; then echo -n "::: Deleting exising list cache..." ${SUDO} rm /etc/pihole/list.* echo " done!" From 6796b8bdadba99ae6e8d103bb36707d9cab2c210 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 23:06:56 +0100 Subject: [PATCH 35/53] pass argument from pihole command to gravity for -f check --- gravity.sh | 4 ++-- pihole | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index 9f11ee42..0b1622e0 100755 --- a/gravity.sh +++ b/gravity.sh @@ -344,14 +344,14 @@ function gravity_reload() { for var in "$@" do case "$var" in - "-f" | "--force" ) force=true;; + "-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 [[ ${force} == true ]]; then +if [[ ${forceGrav} == true ]]; then echo -n "::: Deleting exising list cache..." ${SUDO} rm /etc/pihole/list.* echo " done!" diff --git a/pihole b/pihole index 64a36c59..428bc6a2 100755 --- a/pihole +++ b/pihole @@ -53,7 +53,7 @@ function updateDashboardFunc { } function updateGravityFunc { - $SUDO /opt/pihole/gravity.sh + $SUDO /opt/pihole/gravity.sh "$@" exit 1 } From c0430a2248de0cd6459af152f2d57b12cf41440c Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 23:10:56 +0100 Subject: [PATCH 36/53] It wouldn't be me if there weren't loads of commits for simple mistakes. --- pihole | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pihole b/pihole index 428bc6a2..3403effa 100755 --- a/pihole +++ b/pihole @@ -27,55 +27,55 @@ fi function whitelistFunc { shift - $SUDO /opt/pihole/whitelist.sh "$@" + ${SUDO} /opt/pihole/whitelist.sh "$@" exit 1 } function blacklistFunc { shift - $SUDO /opt/pihole/blacklist.sh "$@" + ${SUDO} /opt/pihole/blacklist.sh "$@" exit 1 } function debugFunc { - $SUDO /opt/pihole/piholeDebug.sh + ${SUDO} /opt/pihole/piholeDebug.sh exit 1 } function flushFunc { - $SUDO /opt/pihole/piholeLogFlush.sh + ${SUDO} /opt/pihole/piholeLogFlush.sh exit 1 } function updateDashboardFunc { - $SUDO /opt/pihole/updateDashboard.sh + ${SUDO} /opt/pihole/updateDashboard.sh exit 1 } function updateGravityFunc { - $SUDO /opt/pihole/gravity.sh "$@" + ${SUDO} /opt/pihole/gravity.sh "$@" exit 1 } function setupLCDFunction { - $SUDO /opt/pihole/setupLCD.sh + ${SUDO} /opt/pihole/setupLCD.sh exit 1 } function chronometerFunc { shift - $SUDO /opt/pihole/chronometer.sh "$@" + ${SUDO} /opt/pihole/chronometer.sh "$@" exit 1 } function uninstallFunc { - $SUDO /opt/pihole/uninstall.sh + ${SUDO} /opt/pihole/uninstall.sh exit 1 } function versionFunc { - $SUDO /opt/pihole/version.sh + ${SUDO} /opt/pihole/version.sh exit 1 } @@ -111,7 +111,7 @@ case "$1" in "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; "-u" | "updateDashboard" ) updateDashboardFunc;; -"-g" | "updateGravity" ) updateGravityFunc;; +"-g" | "updateGravity" ) updateGravityFunc "$@";; "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; From 7eb43a0b47d3d61b7fa386ce66a6fe5467643b6b Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 19 Aug 2016 23:21:07 +0100 Subject: [PATCH 37/53] Expand update dialog text --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f1568983..9bba93c0 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -920,7 +920,7 @@ View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" $ updateDialogs(){ - if (whiptail --title "Existing Install detected" --yesno "We have detected you are installing over the top of an existing install.\n\n\nWould you like update?" ${r} ${c}); then + if (whiptail --title "Existing Install detected" --yesno "We have detected you are installing over the top of an existing install.\n\nIf you would like to update, select yes.\n\n If you would like to run the complete setup again, select no." ${r} ${c}); then echo "::: Updating existing install selected" useUpdateVars=true fi From 01211364986a842ace33bab93607eb4455476af8 Mon Sep 17 00:00:00 2001 From: Victor Marquez Date: Fri, 19 Aug 2016 20:45:17 -0400 Subject: [PATCH 38/53] Added window.close() to index.html Adding window.close() will automatically close any pop-ups that might get loaded with a blocked ad. --- advanced/index.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/advanced/index.html b/advanced/index.html index 6bfc7988..3a4abe1f 100644 --- a/advanced/index.html +++ b/advanced/index.html @@ -1,4 +1,7 @@ + + + - \ No newline at end of file + From b3e7619048fb8e88b90b79c2056e361f1c2e5387 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 21 Aug 2016 02:12:02 +0100 Subject: [PATCH 39/53] curly brackets all the variables! --- advanced/Scripts/blacklist.sh | 68 ++++----- advanced/Scripts/chronometer.sh | 6 +- advanced/Scripts/piholeDebug.sh | 228 ++++++++++++++-------------- advanced/Scripts/setupLCD.sh | 30 ++-- advanced/Scripts/updateDashboard.sh | 2 +- advanced/Scripts/whitelist.sh | 80 +++++----- automated install/uninstall.sh | 60 ++++---- 7 files changed, 237 insertions(+), 237 deletions(-) diff --git a/advanced/Scripts/blacklist.sh b/advanced/Scripts/blacklist.sh index d83ca867..a289a9a5 100755 --- a/advanced/Scripts/blacklist.sh +++ b/advanced/Scripts/blacklist.sh @@ -47,9 +47,9 @@ fi #globals basename=pihole -piholeDir=/etc/$basename -adList=$piholeDir/gravity.list -blacklist=$piholeDir/blacklist.txt +piholeDir=/etc/${basename} +adList=${piholeDir}/gravity.list +blacklist=${piholeDir}/blacklist.txt reload=true addmode=true force=false @@ -61,9 +61,9 @@ domToRemoveList=() piholeIPfile=/etc/pihole/piholeIP 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 - piholeIP=$(cat $piholeIPfile) + piholeIP=$(cat ${piholeIPfile}) #rm $piholeIPfile else # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script @@ -75,13 +75,13 @@ fi modifyHost=false # 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..." - . $piholeDir/pihole.conf + . ${piholeDir}/pihole.conf 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 piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi @@ -92,14 +92,14 @@ function HandleOther(){ if [ -z "$validDomain" ]; then echo "::: $1 is not a valid argument or domain name" else - domList=("${domList[@]}" $validDomain) + domList=("${domList[@]}" ${validDomain}) fi } function PopBlacklistFile(){ #check blacklist file exists, and if not, create it - if [[ ! -f $blacklist ]];then - touch $blacklist + if [[ ! -f ${blacklist} ]];then + touch ${blacklist} fi for dom in "${domList[@]}"; do if "$addmode"; then @@ -113,17 +113,17 @@ function PopBlacklistFile(){ function AddDomain(){ #| sed 's/\./\\./g' bool=false - grep -Ex -q "$1" $blacklist || bool=true - if $bool; then + grep -Ex -q "$1" ${blacklist} || bool=true + if ${bool}; then #domain not found in the blacklist file, add it! - if $verbose; then + if ${verbose}; then echo -n "::: Adding $1 to blacklist file..." fi - echo "$1" >> $blacklist + echo "$1" >> ${blacklist} modifyHost=true echo " done!" else - if $verbose; then + if ${verbose}; then echo "::: $1 already exists in $blacklist! No need to add" fi fi @@ -132,15 +132,15 @@ function AddDomain(){ function RemoveDomain(){ bool=false - grep -Ex -q "$1" $blacklist || bool=true - if $bool; then + grep -Ex -q "$1" ${blacklist} || bool=true + if ${bool}; then #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" fi else #Domain is in the blacklist file, add to a temporary array - if $verbose; then + if ${verbose}; then echo "::: Un-blacklisting $dom..." fi domToRemoveList=("${domToRemoveList[@]}" $1) @@ -149,17 +149,17 @@ function RemoveDomain(){ } function ModifyHostFile(){ - if $addmode; then + if ${addmode}; then #add domains to the hosts file - if [[ -r $blacklist ]];then - numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) + if [[ -r ${blacklist} ]];then + numberOf=$(cat ${blacklist} | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s echo ":::" echo -n "::: Modifying HOSTS file to blacklist $numberOf domain${plural}..." - if [[ -n $piholeIPv6 ]];then - cat $blacklist | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> $adList + if [[ -n ${piholeIPv6} ]];then + cat ${blacklist} | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} 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 else @@ -169,10 +169,10 @@ function ModifyHostFile(){ #we need to remove the domains from the blacklist file and the host file echo "::: $dom" 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 -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!" done fi @@ -185,12 +185,12 @@ function Reload() { dnsmasqPid=$(pidof dnsmasq) - if [[ $dnsmasqPid ]]; then + if [[ ${dnsmasqPid} ]]; then # service already running - reload config - $SUDO killall -s HUP dnsmasq + ${SUDO} killall -s HUP dnsmasq else # service not running, start it up - $SUDO service dnsmasq start + ${SUDO} service dnsmasq start fi echo " done!" } @@ -223,15 +223,15 @@ done PopBlacklistFile -if $modifyHost || $force; then +if ${modifyHost} || ${force}; then ModifyHostFile else - if $verbose; then + if ${verbose}; then echo "::: No changes need to be made" fi exit 1 fi -if $reload; then +if ${reload}; then Reload fi diff --git a/advanced/Scripts/chronometer.sh b/advanced/Scripts/chronometer.sh index 806093e1..eae7cf1c 100755 --- a/advanced/Scripts/chronometer.sh +++ b/advanced/Scripts/chronometer.sh @@ -21,7 +21,7 @@ function CalcBlockedDomains(){ CheckIPv6 if [ -e "$gravity" ]; then #Are we IPV6 or IPV4? - if [[ -n $piholeIPv6 ]];then + if [[ -n ${piholeIPv6} ]];then #We are IPV6 blockedDomainsTotal=$(wc -l /etc/pihole/gravity.list | awk '{print $1/2}') else @@ -43,7 +43,7 @@ function CalcQueriesToday(){ function CalcblockedToday(){ 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 blockedToday="Err." fi @@ -63,7 +63,7 @@ function CalcPercentBlockedToday(){ function CheckIPv6(){ 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 piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index ec08c984..e2e59244 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -43,75 +43,75 @@ fi # Ensure the file exists, create if not, clear if exists. if [ ! -f "$DEBUG_LOG" ]; then - $SUDO touch $DEBUG_LOG - $SUDO chmod 644 $DEBUG_LOG - $SUDO chown "$USER":root $DEBUG_LOG + ${SUDO} touch ${DEBUG_LOG} + ${SUDO} chmod 644 ${DEBUG_LOG} + ${SUDO} chown "$USER":root ${DEBUG_LOG} else - truncate -s 0 $DEBUG_LOG + truncate -s 0 ${DEBUG_LOG} fi ### Private functions exist here ### function versionCheck { - echo "#######################################" >> $DEBUG_LOG - echo "########## Versions Section ###########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "########## Versions Section ###########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} 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) - echo "WebUI Version: $TMP" >> $DEBUG_LOG - echo >> $DEBUG_LOG + echo "WebUI Version: $TMP" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } function distroCheck { - echo "#######################################" >> $DEBUG_LOG - echo "######## Distribution Section #########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "######## Distribution Section #########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} TMP=$(cat /etc/*release || echo "Failed to find release") - echo "Distribution Version: $TMP" >> $DEBUG_LOG + echo "Distribution Version: $TMP" >> ${DEBUG_LOG} } function compareWhitelist { if [ ! -f "$WHITELISTMATCHES" ]; then - $SUDO touch $WHITELISTMATCHES - $SUDO chmod 644 $WHITELISTMATCHES - $SUDO chown "$USER":root $WHITELISTMATCHES + ${SUDO} touch ${WHITELISTMATCHES} + ${SUDO} chmod 644 ${WHITELISTMATCHES} + ${SUDO} chown "$USER":root ${WHITELISTMATCHES} else - truncate -s 0 $WHITELISTMATCHES + truncate -s 0 ${WHITELISTMATCHES} fi - echo "#######################################" >> $DEBUG_LOG - echo "######## Whitelist Comparison #########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "######## Whitelist Comparison #########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} while read -r line; do TMP=$(grep -w ".* $line$" "$GRAVITYFILE") if [ ! -z "$TMP" ]; then - echo "$TMP" >> $DEBUG_LOG - echo "$TMP" >> $WHITELISTMATCHES + echo "$TMP" >> ${DEBUG_LOG} + echo "$TMP" >> ${WHITELISTMATCHES} fi done < "$WHITELISTFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} } function compareBlacklist { - echo "#######################################" >> $DEBUG_LOG - echo "######## Blacklist Comparison #########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "######## Blacklist Comparison #########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} while read -r line; do if [ ! -z "$line" ]; then - grep -w ".* $line$" "$GRAVITYFILE" >> $DEBUG_LOG + grep -w ".* $line$" "$GRAVITYFILE" >> ${DEBUG_LOG} fi done < "$BLACKLISTFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} } function testNslookup { TESTURL="doubleclick.com" - echo "#######################################" >> $DEBUG_LOG - echo "############ NSLookup Test ############" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "############ NSLookup Test ############" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} # Find a blocked url that has not been whitelisted. if [ -s "$WHITELISTMATCHES" ]; then while read -r line; do @@ -128,77 +128,77 @@ function testNslookup { done < "$GRAVITYFILE" fi - echo "NSLOOKUP of $TESTURL from PiHole:" >> $DEBUG_LOG - nslookup "$TESTURL" >> $DEBUG_LOG - echo >> $DEBUG_LOG - echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> $DEBUG_LOG - nslookup "$TESTURL" 8.8.8.8 >> $DEBUG_LOG - echo >> $DEBUG_LOG + echo "NSLOOKUP of $TESTURL from PiHole:" >> ${DEBUG_LOG} + nslookup "$TESTURL" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} + echo "NSLOOKUP of $TESTURL from 8.8.8.8:" >> ${DEBUG_LOG} + nslookup "$TESTURL" 8.8.8.8 >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} } function checkProcesses { - echo "#######################################" >> $DEBUG_LOG - echo "########### Processes Check ###########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "########### Processes Check ###########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} echo ":::" echo "::: Logging status of lighttpd and dnsmasq..." PROCESSES=( lighttpd dnsmasq ) for i in "${PROCESSES[@]}" do - echo "" >> $DEBUG_LOG + echo "" >> ${DEBUG_LOG} echo -n "$i" >> "$DEBUG_LOG" - echo " processes status:" >> $DEBUG_LOG - $SUDO systemctl -l status "$i" >> "$DEBUG_LOG" + echo " processes status:" >> ${DEBUG_LOG} + ${SUDO} systemctl -l status "$i" >> "$DEBUG_LOG" done } function debugLighttpd { echo "::: Writing lighttpd to debug log..." - echo "#######################################" >> $DEBUG_LOG - echo "############ lighttpd.conf ############" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "############ lighttpd.conf ############" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} if [ -e "$LIGHTTPDFILE" ] then while read -r line; do if [ ! -z "$line" ]; then [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + echo "$line" >> ${DEBUG_LOG} fi done < "$LIGHTTPDFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} else - echo "No lighttpd.conf file found!" >> $DEBUG_LOG + echo "No lighttpd.conf file found!" >> ${DEBUG_LOG} printf ":::\tNo lighttpd.conf file found\n" fi if [ -e "$LIGHTTPDERRFILE" ] then - echo "#######################################" >> $DEBUG_LOG - echo "######### lighttpd error.log ##########" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG - cat "$LIGHTTPDERRFILE" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "######### lighttpd error.log ##########" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} + cat "$LIGHTTPDERRFILE" >> ${DEBUG_LOG} 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" fi - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} } ### END FUNCTIONS ### ### Check Pi internet connections ### # 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 "IP Addresses of this Pi:" >> $DEBUG_LOG -echo "$IPADDR" >> $DEBUG_LOG -echo >> $DEBUG_LOG +echo "IP Addresses of this Pi:" >> ${DEBUG_LOG} +echo "$IPADDR" >> ${DEBUG_LOG} +echo >> ${DEBUG_LOG} # 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) -echo "Gateway check:" >> $DEBUG_LOG -echo "$GATEWAY_CHECK" >> $DEBUG_LOG -echo >> $DEBUG_LOG +echo "Gateway check:" >> ${DEBUG_LOG} +echo "$GATEWAY_CHECK" >> ${DEBUG_LOG} +echo >> ${DEBUG_LOG} versionCheck distroCheck @@ -209,109 +209,109 @@ checkProcesses debugLighttpd echo "::: Writing dnsmasq.conf to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############### Dnsmasq ###############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############### Dnsmasq ###############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$DNSMASQFILE" ] then #cat $DNSMASQFILE >> $DEBUG_LOG while read -r line; do if [ ! -z "$line" ]; then [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + echo "$line" >> ${DEBUG_LOG} fi done < "$DNSMASQFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} else - echo "No dnsmasq.conf file found!" >> $DEBUG_LOG + echo "No dnsmasq.conf file found!" >> ${DEBUG_LOG} printf ":::\tNo dnsmasq.conf file found!\n" fi echo "::: Writing 01-pihole.conf to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "########### 01-pihole.conf ############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "########### 01-pihole.conf ############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$PIHOLECONFFILE" ] then while read -r line; do if [ ! -z "$line" ]; then [[ "$line" =~ ^#.*$ ]] && continue - echo "$line" >> $DEBUG_LOG + echo "$line" >> ${DEBUG_LOG} fi done < "$PIHOLECONFFILE" - echo >> $DEBUG_LOG + echo >> ${DEBUG_LOG} 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" fi echo "::: Writing size of gravity.list to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############ gravity.list #############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############ gravity.list #############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$GRAVITYFILE" ] then - wc -l "$GRAVITYFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + wc -l "$GRAVITYFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No gravity.list file found!" >> $DEBUG_LOG + echo "No gravity.list file found!" >> ${DEBUG_LOG} printf ":::\tNo gravity.list file found\n" fi # Write the hostname output to compare against entries in /etc/hosts, which is logged next -echo "Hostname of this pihole is: " >> $DEBUG_LOG -hostname >> $DEBUG_LOG +echo "Hostname of this pihole is: " >> ${DEBUG_LOG} +hostname >> ${DEBUG_LOG} echo "::: Writing hosts file to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "################ Hosts ################" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "################ Hosts ################" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$HOSTSFILE" ] then - cat "$HOSTSFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + cat "$HOSTSFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No hosts file found!" >> $DEBUG_LOG + echo "No hosts file found!" >> ${DEBUG_LOG} printf ":::\tNo hosts file found!\n" fi ### PiHole application specific logging ### echo "::: Writing whitelist to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############## Whitelist ##############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############## Whitelist ##############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$WHITELISTFILE" ] then - cat "$WHITELISTFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + cat "$WHITELISTFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No whitelist.txt file found!" >> $DEBUG_LOG + echo "No whitelist.txt file found!" >> ${DEBUG_LOG} printf ":::\tNo whitelist.txt file found!\n" fi echo "::: Writing blacklist to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############## Blacklist ##############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############## Blacklist ##############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$BLACKLISTFILE" ] then - cat "$BLACKLISTFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + cat "$BLACKLISTFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} else - echo "No blacklist.txt file found!" >> $DEBUG_LOG + echo "No blacklist.txt file found!" >> ${DEBUG_LOG} printf ":::\tNo blacklist.txt file found!\n" fi echo "::: Writing adlists.list to debug log..." -echo "#######################################" >> $DEBUG_LOG -echo "############ adlists.list #############" >> $DEBUG_LOG -echo "#######################################" >> $DEBUG_LOG +echo "#######################################" >> ${DEBUG_LOG} +echo "############ adlists.list #############" >> ${DEBUG_LOG} +echo "#######################################" >> ${DEBUG_LOG} if [ -e "$ADLISTSFILE" ] then - cat "$ADLISTSFILE" >> $DEBUG_LOG - echo >> $DEBUG_LOG + cat "$ADLISTSFILE" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} 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" fi @@ -320,17 +320,17 @@ fi function dumpPiHoleLog { 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 "#######################################" >> $DEBUG_LOG - echo "############# pihole.log ##############" >> $DEBUG_LOG - echo "#######################################" >> $DEBUG_LOG + echo "#######################################" >> ${DEBUG_LOG} + echo "############# pihole.log ##############" >> ${DEBUG_LOG} + echo "#######################################" >> ${DEBUG_LOG} if [ -e "$PIHOLELOG" ] then while true; do - tail -f "$PIHOLELOG" >> $DEBUG_LOG - echo >> $DEBUG_LOG + tail -f "$PIHOLELOG" >> ${DEBUG_LOG} + echo >> ${DEBUG_LOG} done else - echo "No pihole.log file found!" >> $DEBUG_LOG + echo "No pihole.log file found!" >> ${DEBUG_LOG} printf ":::\tNo pihole.log file found!\n" fi } @@ -340,7 +340,7 @@ function finalWork { 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 + case ${response} in [yY][eE][sS]|[yY]) TERMBIN=$(cat /var/log/pihole_debug.log | nc termbin.com 9999) ;; diff --git a/advanced/Scripts/setupLCD.sh b/advanced/Scripts/setupLCD.sh index 03be4e0a..c77f1f4a 100755 --- a/advanced/Scripts/setupLCD.sh +++ b/advanced/Scripts/setupLCD.sh @@ -44,12 +44,12 @@ getInitSys() { # https://github.com/adafruit/Adafruit-PiTFT-Helper/blob/master/adafruit-pitft-helper#L274-L285 autoLoginPiToConsole() { if [ -e /etc/init.d/lightdm ]; then - if [ $SYSTEMD -eq 1 ]; then - $SUDO systemctl set-default multi-user.target - $SUDO ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service + if [ ${SYSTEMD} -eq 1 ]; then + ${SUDO} systemctl set-default multi-user.target + ${SUDO} ln -fs /etc/systemd/system/autologin@.service /etc/systemd/system/getty.target.wants/getty@tty1.service else - $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} 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/" fi fi } @@ -66,23 +66,23 @@ echo /usr/local/bin/chronometer.sh >> /home/pi/.bashrc # Set up the LCD screen based on Adafruits instuctions: # 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 -$SUDO apt-get -y install raspberrypi-bootloader -$SUDO apt-get -y install adafruit-pitft-helper -$SUDO adafruit-pitft-helper -t 28r +curl -SLs https://apt.adafruit.com/add-pin | ${SUDO} bash +${SUDO} apt-get -y install raspberrypi-bootloader +${SUDO} apt-get -y install adafruit-pitft-helper +${SUDO} adafruit-pitft-helper -t 28r # 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 curl -o /boot/cmdline.txt https://raw.githubusercontent.com/pi-hole/pi-hole/master/advanced/cmdline.txt +${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 # Back up the original file and download the new one -$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} 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 # 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: # http://unix.stackexchange.com/questions/170063/start-a-process-on-a-different-tty diff --git a/advanced/Scripts/updateDashboard.sh b/advanced/Scripts/updateDashboard.sh index 6955683d..991089c2 100755 --- a/advanced/Scripts/updateDashboard.sh +++ b/advanced/Scripts/updateDashboard.sh @@ -55,7 +55,7 @@ is_repo() { # replaces it with the current master branch from github make_repo() { # 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" } diff --git a/advanced/Scripts/whitelist.sh b/advanced/Scripts/whitelist.sh index 5195aa83..75d62173 100755 --- a/advanced/Scripts/whitelist.sh +++ b/advanced/Scripts/whitelist.sh @@ -47,9 +47,9 @@ fi #globals basename=pihole -piholeDir=/etc/$basename -adList=$piholeDir/gravity.list -whitelist=$piholeDir/whitelist.txt +piholeDir=/etc/${basename} +adList=${piholeDir}/gravity.list +whitelist=${piholeDir}/whitelist.txt reload=true addmode=true force=false @@ -61,9 +61,9 @@ domToRemoveList=() piholeIPfile=/etc/pihole/piholeIP 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 - piholeIP=$(cat $piholeIPfile) + piholeIP=$(cat ${piholeIPfile}) #rm $piholeIPfile else # Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script @@ -75,12 +75,12 @@ fi modifyHost=false # 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..." - . $piholeDir/pihole.conf + . ${piholeDir}/pihole.conf 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 piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " " '{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }') fi @@ -91,18 +91,18 @@ function HandleOther(){ if [ -z "$validDomain" ]; then echo "::: $1 is not a valid argument or domain name" else - domList=("${domList[@]}" $validDomain) + domList=("${domList[@]}" ${validDomain}) fi } function PopWhitelistFile(){ #check whitelist file exists, and if not, create it - if [[ ! -f $whitelist ]];then - touch $whitelist + if [[ ! -f ${whitelist} ]];then + touch ${whitelist} fi for dom in "${domList[@]}" do - if $addmode; then + if ${addmode}; then AddDomain "$dom" else RemoveDomain "$dom" @@ -114,19 +114,19 @@ function AddDomain(){ #| sed 's/\./\\./g' bool=false - grep -Ex -q "$1" $whitelist || bool=true - if $bool; then + grep -Ex -q "$1" ${whitelist} || bool=true + if ${bool}; then #domain not found in the whitelist file, add it! - if $verbose; then + if ${verbose}; then echo -n "::: Adding $1 to $whitelist..." fi - echo "$1" >> $whitelist + echo "$1" >> ${whitelist} modifyHost=true - if $verbose; then + if ${verbose}; then echo " done!" fi else - if $verbose; then + if ${verbose}; then echo "::: $1 already exists in $whitelist, no need to add!" fi fi @@ -135,10 +135,10 @@ function AddDomain(){ function RemoveDomain(){ bool=false - grep -Ex -q "$1" $whitelist || bool=true - if $bool; then + grep -Ex -q "$1" ${whitelist} || bool=true + if ${bool}; then #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" fi else @@ -152,21 +152,21 @@ function RemoveDomain(){ } function ModifyHostFile(){ - if $addmode; then + if ${addmode}; then #remove domains in from hosts file - if [[ -r $whitelist ]];then + if [[ -r ${whitelist} ]];then # Remove whitelist entries - numberOf=$(cat $whitelist | sed '/^\s*$/d' | wc -l) + numberOf=$(cat ${whitelist} | sed '/^\s*$/d' | wc -l) plural=; [[ "$numberOf" != "1" ]] && plural=s echo ":::" 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 "$piholeIPv6 $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 echo "l" >> /etc/pihole/whitelist.tmp - grep -F -x -v -f $piholeDir/whitelist.tmp $adList > $piholeDir/gravity.tmp - rm $adList - mv $piholeDir/gravity.tmp $adList - rm $piholeDir/whitelist.tmp + grep -F -x -v -f ${piholeDir}/whitelist.tmp ${adList} > ${piholeDir}/gravity.tmp + rm ${adList} + mv ${piholeDir}/gravity.tmp ${adList} + rm ${piholeDir}/whitelist.tmp echo " done!" fi @@ -178,18 +178,18 @@ function ModifyHostFile(){ do if grep -q "$rdom" /etc/pihole/*.domains; then echo "::: AdLists contain $rdom, re-adding block" - if [[ -n $piholeIPv6 ]];then + 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 "$rdom" | awk -v ipv4addr="$piholeIP" -v ipv6addr="$piholeIPv6" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${adList} echo " done!" else 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!" fi fi 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!" done fi @@ -201,12 +201,12 @@ function Reload() { echo -n "::: Refresh lists in dnsmasq..." dnsmasqPid=$(pidof dnsmasq) - if [[ $dnsmasqPid ]]; then + if [[ ${dnsmasqPid} ]]; then # service already running - reload config - $SUDO killall -s HUP dnsmasq + ${SUDO} killall -s HUP dnsmasq else # service not running, start it up - $SUDO service dnsmasq start + ${SUDO} service dnsmasq start fi echo " done!" } @@ -239,16 +239,16 @@ done PopWhitelistFile -if $modifyHost || $force; then +if ${modifyHost} || ${force}; then ModifyHostFile else - if $verbose; then + if ${verbose}; then echo ":::" echo "::: No changes need to be made" fi exit 1 fi -if $reload; then +if ${reload}; then Reload fi diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 5730c531..01e76cad 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -39,7 +39,7 @@ if [ -x "$(command -v rpm)" ];then rpm -qa | grep ^$1- > /dev/null } package_cleanup() { - $SUDO $PKG_MANAGER -y autoremove + ${SUDO} ${PKG_MANAGER} -y autoremove } elif [ -x "$(command -v apt-get)" ];then # 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" } package_cleanup() { - $SUDO $PKG_MANAGER -y autoremove - $SUDO $PKG_MANAGER -y autoclean + ${SUDO} ${PKG_MANAGER} -y autoremove + ${SUDO} ${PKG_MANAGER} -y autoclean } else echo "OS distribution not supported" @@ -66,8 +66,8 @@ spinner() while [ "$(ps a | awk '{print $1}' | grep "$pid")" ]; do local temp=${spinstr#?} printf " [%c] " "$spinstr" - local spinstr=$temp${spinstr%"$temp"} - sleep $delay + local spinstr=${temp}${spinstr%"$temp"} + sleep ${delay} printf "\b\b\b\b\b\b" done printf " \b\b\b\b" @@ -77,12 +77,12 @@ function removeAndPurge { # Purge dependencies echo ":::" for i in "${PIHOLE_DEPS[@]}"; do - package_check $i > /dev/null + package_check ${i} > /dev/null if [ $? -eq 0 ]; then while true; do read -rp "::: Do you wish to remove $i from your system? [y/n]: " yn - case $yn in - [Yy]* ) printf ":::\tRemoving %s..." "$i"; $SUDO $PKG_REMOVE "$i" &> /dev/null & spinner $!; printf "done!\n"; break;; + case ${yn} in + [Yy]* ) printf ":::\tRemoving %s..." "$i"; ${SUDO} ${PKG_REMOVE} "$i" &> /dev/null & spinner $!; printf "done!\n"; break;; [Nn]* ) printf ":::\tSkipping %s" "$i\n"; break;; * ) printf "::: You must answer yes or no!\n";; esac @@ -94,7 +94,7 @@ echo ":::" # Remove dependency 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 printf "::: Auto removing & cleaning remaining dependencies..." @@ -108,14 +108,14 @@ function removeNoPurge { echo ":::" # Only web directories/files that are created by pihole should be removed. echo "::: Removing the Pi-hole Web server files..." - $SUDO rm -rf /var/www/html/admin &> /dev/null - $SUDO rm -rf /var/www/html/pihole &> /dev/null - $SUDO rm /var/www/html/index.lighttpd.orig &> /dev/null + ${SUDO} rm -rf /var/www/html/admin &> /dev/null + ${SUDO} rm -rf /var/www/html/pihole &> /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 [ -d "/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 @@ -125,36 +125,36 @@ function removeNoPurge { # preserved. if [[ -f /etc/crontab.orig ]]; then echo "::: Initial Pi-hole cron detected. Restoring the default system cron..." - $SUDO mv /etc/crontab /etc/crontab.pihole - $SUDO mv /etc/crontab.orig /etc/crontab - $SUDO service cron restart + ${SUDO} mv /etc/crontab /etc/crontab.pihole + ${SUDO} mv /etc/crontab.orig /etc/crontab + ${SUDO} service cron restart fi # Attempt to preserve backwards compatibility with older versions if [[ -f /etc/cron.d/pihole ]];then echo "::: Removing cron.d/pihole..." - $SUDO rm /etc/cron.d/pihole &> /dev/null + ${SUDO} rm /etc/cron.d/pihole &> /dev/null fi echo "::: Removing config files and scripts..." - package_check $i > /dev/null + package_check ${i} > /dev/null if [ $? -eq 1 ]; then - $SUDO rm -rf /etc/lighttpd/ &> /dev/null + ${SUDO} rm -rf /etc/lighttpd/ &> /dev/null else 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 - $SUDO rm /etc/dnsmasq.d/adList.conf &> /dev/null - $SUDO rm /etc/dnsmasq.d/01-pihole.conf &> /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 /opt/pihole/ &> /dev/null - $SUDO rm /usr/local/bin/pihole &> /dev/null - $SUDO rm /etc/bash_completion.d/pihole &> /dev/null - $SUDO rm /etc/sudoers.d/pihole &> /dev/null + ${SUDO} rm /etc/dnsmasq.d/adList.conf &> /dev/null + ${SUDO} rm /etc/dnsmasq.d/01-pihole.conf &> /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 /opt/pihole/ &> /dev/null + ${SUDO} rm /usr/local/bin/pihole &> /dev/null + ${SUDO} rm /etc/bash_completion.d/pihole &> /dev/null + ${SUDO} rm /etc/sudoers.d/pihole &> /dev/null echo ":::" 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)" 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 - case $yn in + case ${yn} in [Yy]* ) removeAndPurge; break;; [Nn]* ) removeNoPurge; break;; From 2f2e746e560ac14da332ecc8c2edffa35384f8bd Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 21 Aug 2016 02:23:11 +0100 Subject: [PATCH 40/53] Add update function to pihole script --- pihole | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pihole b/pihole index 3403effa..0791a023 100755 --- a/pihole +++ b/pihole @@ -52,6 +52,14 @@ function updateDashboardFunc { exit 1 } +function updateMainFunc { + echo "::: Fetching latest changes from Github..." + cd /etc/.pihole + ${SUDO} git pull + ${SUDO} /etc/.pihole/automated install/basic-install.sh + exit 1 +} + function updateGravityFunc { ${SUDO} /opt/pihole/gravity.sh "$@" exit 1 @@ -91,6 +99,7 @@ function helpFunc { echo "::: -d, debug Start a debugging session if having trouble" echo "::: -f, flush Flush the pihole.log file" echo "::: -u, updateDashboard Update the web dashboard manually" + echo "::: -U, updateMain Update Pi-hole" 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 "::: -c, chronometer Calculates stats and displays to an LCD" @@ -111,6 +120,7 @@ case "$1" in "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; "-u" | "updateDashboard" ) updateDashboardFunc;; +"-U" | "updateMain" ) updateMainFunc;; "-g" | "updateGravity" ) updateGravityFunc "$@";; "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; From af666e22092d867e90039c991ea1eb140015ad0d Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 20 Aug 2016 18:37:35 -0700 Subject: [PATCH 41/53] Escape space in updateMainFunc Legacy space in path strikes again! --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index 0791a023..d06ac29c 100755 --- a/pihole +++ b/pihole @@ -56,7 +56,7 @@ function updateMainFunc { echo "::: Fetching latest changes from Github..." cd /etc/.pihole ${SUDO} git pull - ${SUDO} /etc/.pihole/automated install/basic-install.sh + ${SUDO} /etc/.pihole/automated\ install/basic-install.sh exit 1 } From eb42b894c418e3fa8360ef94827640cd740e726a Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 21 Aug 2016 17:57:11 +0100 Subject: [PATCH 42/53] Delete setupVars.conf if user cancels out of install process. --- automated install/basic-install.sh | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9bba93c0..bc8e2fc9 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -22,6 +22,7 @@ tmpLog=/tmp/pihole-install.log instalLogLoc=/etc/pihole/install.log +setupVars=/etc/pihole/setupVars.conf webInterfaceGitUrl="https://github.com/pi-hole/AdminLTE.git" webInterfaceDir="/var/www/html/admin" @@ -194,10 +195,11 @@ chooseInterface() { piholeInterface=${desiredInterface} echo "::: Using interface: $piholeInterface" echo "${piholeInterface}" > /tmp/piholeINT - echo "piholeInterface=${piholeInterface}" >> /etc/pihole/setupVars.conf + echo "piholeInterface=${piholeInterface}" >> ${setupVars} done else echo "::: Cancel selected, exiting...." + ${SUDO} rm ${setupVars} exit 1 fi @@ -228,7 +230,7 @@ use4andor6() { if [ ${useIPv4} ] && [ ! ${useIPv6} ]; then getStaticIPv4Settings setStaticIPv4 - ${SUDO} echo "IPv4addr=${IPv4addr}" >> /etc/pihole/setupVars.conf + ${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars} echo "::: Using IPv4 on $IPv4addr" echo "::: IPv6 will NOT be used." fi @@ -240,7 +242,7 @@ use4andor6() { if [ ${useIPv4} ] && [ ${useIPv6} ]; then getStaticIPv4Settings setStaticIPv4 - ${SUDO} echo "IPv4addr=${IPv4addr}" >> /etc/pihole/setupVars.conf + ${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars} useIPv6dialog echo "::: Using IPv4 on $IPv4addr" echo "::: Using IPv6 on $piholeIPv6" @@ -248,11 +250,13 @@ use4andor6() { if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then echo "::: Cannot continue, neither IPv4 or IPv6 selected" echo "::: Exiting" + ${SUDO} rm ${setupVars} exit 1 fi cleanupIPv6 else echo "::: Cancel selected. Exiting..." + ${SUDO} rm ${setupVars} exit 1 fi } @@ -260,7 +264,7 @@ use4andor6() { useIPv6dialog() { # 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) }') - ${SUDO} echo "piholeIPv6=${piholeIPv6}" >> /etc/pihole/setupVars.conf + ${SUDO} echo "piholeIPv6=${piholeIPv6}" >> ${setupVars} whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." ${r} ${c} ${SUDO} touch /etc/pihole/.useIPv6 @@ -310,12 +314,14 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Cancelling gateway settings window ipSettingsCorrect=False echo "::: Cancel selected. Exiting..." + ${SUDO} rm ${setupVars} exit 1 fi else # Cancelling IPv4 settings window ipSettingsCorrect=False echo "::: Cancel selected. Exiting..." + ${SUDO} rm ${setupVars} exit 1 fi done @@ -373,6 +379,7 @@ setStaticIPv4() { fi else echo "::: Warning: Unable to locate configuration file to set static IPv4 address!" + ${SUDO} rm ${setupVars} exit 1 fi } @@ -457,6 +464,7 @@ setDNS(){ fi else echo "::: Cancel selected, exiting...." + ${SUDO} rm ${setupVars} exit 1 fi if [[ ${piholeDNS1} == "$strInvalid" ]] || [[ ${piholeDNS2} == "$strInvalid" ]]; then @@ -481,11 +489,12 @@ setDNS(){ esac else echo "::: Cancel selected. Exiting..." + ${SUDO} rm ${setupVars} exit 1 fi - ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> /etc/pihole/setupVars.conf - ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> /etc/pihole/setupVars.conf + ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars} + ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars} } versionCheckDNSmasq(){ @@ -928,8 +937,8 @@ updateDialogs(){ } ######## SCRIPT ############ -if [[ -f /etc/pihole/setupVars.conf ]];then - . /etc/pihole/setupVars.conf +if [[ -f ${setupVars} ]];then + . ${setupVars} updateDialogs fi @@ -938,11 +947,11 @@ fi installerDependencies if [[ ${useUpdateVars} == false ]]; then - ${SUDO} echo "" > /etc/pihole/setupVars.conf - ${SUDO} mkdir -p /etc/pihole/ welcomeDialogs # Verify there is enough disk space for the install verifyFreeDiskSpace + ${SUDO} echo "" > ${setupVars} + ${SUDO} mkdir -p /etc/pihole/ # Find IP used to route to outside world findIPRoute # Find interfaces and let the user choose one From a57b097afc13ab9aed4e770fb936b0f161ea2e66 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Sun, 21 Aug 2016 18:00:41 +0100 Subject: [PATCH 43/53] Change echos at the end of install depending on install or update --- automated install/basic-install.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index bc8e2fc9..5dcfbd20 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -969,7 +969,9 @@ fi # Move the log file into /etc/pihole for storage ${SUDO} mv ${tmpLog} ${instalLogLoc} -displayFinalMessage +if [[ ${useUpdateVars} == false ]]; then + displayFinalMessage +fi echo -n "::: Restarting services..." # Start services @@ -986,11 +988,16 @@ fi echo " done." echo ":::" -echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" -echo "::: ${IPv4addr%/*}" -echo "::: $piholeIPv6" -echo ":::" -echo "::: If you set a new IP address, you should restart the Pi." +if [[ ${useUpdateVars} == false ]]; then + echo "::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:" + echo "::: ${IPv4addr%/*}" + echo "::: $piholeIPv6" + echo ":::" + echo "::: If you set a new IP address, you should restart the Pi." +else + echo "::: Update complete!" +fi + echo ":::" 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" From ed94f4b1df07ff564f12d43343b15a1e5eb643ac Mon Sep 17 00:00:00 2001 From: Promofaux Date: Mon, 22 Aug 2016 22:06:33 +0100 Subject: [PATCH 44/53] Create directory before trying to create a blank file in it.... --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 5dcfbd20..05170fdf 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -950,8 +950,8 @@ if [[ ${useUpdateVars} == false ]]; then welcomeDialogs # Verify there is enough disk space for the install verifyFreeDiskSpace - ${SUDO} echo "" > ${setupVars} ${SUDO} mkdir -p /etc/pihole/ + ${SUDO} echo "" > ${setupVars} # Find IP used to route to outside world findIPRoute # Find interfaces and let the user choose one From d217626318174f4651f6642eb224e4e5f595badb Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 24 Aug 2016 22:52:11 +0100 Subject: [PATCH 45/53] If an existing install is detected, offer the user a choice of Updating or Installing with a radio list whiptail. --- automated install/basic-install.sh | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 05170fdf..4e2df395 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -929,10 +929,26 @@ View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin" $ updateDialogs(){ - if (whiptail --title "Existing Install detected" --yesno "We have detected you are installing over the top of an existing install.\n\nIf you would like to update, select yes.\n\n If you would like to run the complete setup again, select no." ${r} ${c}); then - echo "::: Updating existing install selected" - useUpdateVars=true - fi + 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 } From 6c0a8a43377bc24994e50cc2c6c6b7c6956a088c Mon Sep 17 00:00:00 2001 From: "Daniel (Fourdee)" Date: Thu, 25 Aug 2016 12:11:54 +0100 Subject: [PATCH 46/53] Minor - Corrected var names Kilobyte values are used, not Bytes. --- automated install/basic-install.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0ed95976..415251e3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -158,27 +158,27 @@ verifyFreeDiskSpace() { # 50MB is the minimum space needed (45MB install (includes web admin bootstrap/jquery libraries etc) + 5MB one day of logs.) # - Fourdee: Local ensures the variable is only created, and accessible within this function/void. Generally considered a "good" coding practice for non-global variables. - local requiredFreeBytes=51200 - local existingFreeBytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') + local required_free_kilobytes=51200 + local existing_free_kilobytes=$(df -Pk | grep -m1 '\/$' | awk '{print $4}') # - Unknown free disk space , not a integer - if ! [[ "$existingFreeBytes" =~ ^([0-9])+$ ]]; then + 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 existingFreeBytes ($existingFreeBytes)" + echo "non-integer value from existing_free_kilobytes ($existing_free_kilobytes)" echo "Unknown free space, user aborted, exiting..." exit 1 fi # - Insufficient free disk space - elif [[ $existingFreeBytes -lt $requiredFreeBytes ]]; then + elif [[ $existing_free_kilobytes -lt $required_free_kilobytes ]]; then - 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 - 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 Bytes.\nYou only have $existing_free_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..." exit 1 From 49ded54306523b571b0c58bba9e968310f61f78f Mon Sep 17 00:00:00 2001 From: "Daniel (Fourdee)" Date: Thu, 25 Aug 2016 12:17:36 +0100 Subject: [PATCH 47/53] Minor - Update descriptions Apply to whiptail descriptions also. --- automated install/basic-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 415251e3..614ff291 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -177,7 +177,7 @@ verifyFreeDiskSpace() { # - Insufficient free disk space elif [[ $existing_free_kilobytes -lt $required_free_kilobytes ]]; then - 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 Bytes.\nYou only have $existing_free_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 + 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..." exit 1 From 29b548f07c94618ea683fbd533bf28d45df2b09a Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 26 Aug 2016 09:39:27 +0100 Subject: [PATCH 48/53] Add queryfunc --- pihole | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pihole b/pihole index 64a36c59..0b67d6c0 100755 --- a/pihole +++ b/pihole @@ -62,6 +62,11 @@ function setupLCDFunction { exit 1 } +function queryFunc { + for list in /etc/pihole/list.*;do echo $list;grep '$@' $list;done + exit 1 +} + function chronometerFunc { shift $SUDO /opt/pihole/chronometer.sh "$@" @@ -96,6 +101,7 @@ function helpFunc { echo "::: -c, chronometer Calculates stats and displays to an LCD" echo "::: -h, help Show this help dialog" 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 } @@ -116,6 +122,7 @@ case "$1" in "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; "-v" | "version" ) versionFunc;; +"-q" | "query" ) queryFunc;; "uninstall" ) uninstallFunc;; * ) helpFunc;; esac From 77135ca3c74a6aca0265b0696aadd73f01b051ad Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 26 Aug 2016 10:09:39 +0100 Subject: [PATCH 49/53] Actually pass through the argument to the function --- pihole | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pihole b/pihole index 0b67d6c0..7d0f4c18 100755 --- a/pihole +++ b/pihole @@ -63,7 +63,8 @@ function setupLCDFunction { } function queryFunc { - for list in /etc/pihole/list.*;do echo $list;grep '$@' $list;done + domain=$2 + for list in /etc/pihole/list.*;do echo $list;grep ${domain} $list;done exit 1 } @@ -122,7 +123,7 @@ case "$1" in "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; "-v" | "version" ) versionFunc;; -"-q" | "query" ) queryFunc;; +"-q" | "query" ) queryFunc "$@";; "uninstall" ) uninstallFunc;; * ) helpFunc;; esac From e4295f5d3c0777315a7c832f7a927a708f25f451 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 26 Aug 2016 22:45:38 +0100 Subject: [PATCH 50/53] Move exporting the setupConf files to a function to be run at the end of the script only. If script is cancelled, then they are not written. Simples. Also I'm surprised nobody noticed the duplicate installPihole() function :S --- automated install/basic-install.sh | 57 +++++++----------------------- 1 file changed, 13 insertions(+), 44 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4e2df395..756d1427 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -195,11 +195,9 @@ chooseInterface() { piholeInterface=${desiredInterface} echo "::: Using interface: $piholeInterface" echo "${piholeInterface}" > /tmp/piholeINT - echo "piholeInterface=${piholeInterface}" >> ${setupVars} done else echo "::: Cancel selected, exiting...." - ${SUDO} rm ${setupVars} exit 1 fi @@ -230,7 +228,6 @@ use4andor6() { if [ ${useIPv4} ] && [ ! ${useIPv6} ]; then getStaticIPv4Settings setStaticIPv4 - ${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars} echo "::: Using IPv4 on $IPv4addr" echo "::: IPv6 will NOT be used." fi @@ -242,7 +239,6 @@ use4andor6() { if [ ${useIPv4} ] && [ ${useIPv6} ]; then getStaticIPv4Settings setStaticIPv4 - ${SUDO} echo "IPv4addr=${IPv4addr}" >> ${setupVars} useIPv6dialog echo "::: Using IPv4 on $IPv4addr" echo "::: Using IPv6 on $piholeIPv6" @@ -250,13 +246,11 @@ use4andor6() { if [ ! ${useIPv4} ] && [ ! ${useIPv6} ]; then echo "::: Cannot continue, neither IPv4 or IPv6 selected" echo "::: Exiting" - ${SUDO} rm ${setupVars} exit 1 fi cleanupIPv6 else echo "::: Cancel selected. Exiting..." - ${SUDO} rm ${setupVars} exit 1 fi } @@ -264,7 +258,6 @@ use4andor6() { useIPv6dialog() { # 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) }') - ${SUDO} echo "piholeIPv6=${piholeIPv6}" >> ${setupVars} whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported" "$piholeIPv6 will be used to block ads." ${r} ${c} ${SUDO} touch /etc/pihole/.useIPv6 @@ -314,14 +307,12 @@ It is also possible to use a DHCP reservation, but if you are going to do that, # Cancelling gateway settings window ipSettingsCorrect=False echo "::: Cancel selected. Exiting..." - ${SUDO} rm ${setupVars} exit 1 fi else # Cancelling IPv4 settings window ipSettingsCorrect=False echo "::: Cancel selected. Exiting..." - ${SUDO} rm ${setupVars} exit 1 fi done @@ -379,7 +370,6 @@ setStaticIPv4() { fi else echo "::: Warning: Unable to locate configuration file to set static IPv4 address!" - ${SUDO} rm ${setupVars} exit 1 fi } @@ -464,7 +454,6 @@ setDNS(){ fi else echo "::: Cancel selected, exiting...." - ${SUDO} rm ${setupVars} exit 1 fi if [[ ${piholeDNS1} == "$strInvalid" ]] || [[ ${piholeDNS2} == "$strInvalid" ]]; then @@ -489,12 +478,8 @@ setDNS(){ esac else echo "::: Cancel selected. Exiting..." - ${SUDO} rm ${setupVars} exit 1 fi - - ${SUDO} echo "piholeDNS1=${piholeDNS1}" >> ${setupVars} - ${SUDO} echo "piholeDNS2=${piholeDNS2}" >> ${setupVars} } versionCheckDNSmasq(){ @@ -807,36 +792,19 @@ configureFirewall() { fi } -installPihole() { - # Install base files and web interface - checkForDependencies # done - stopServices - setUser - ${SUDO} mkdir -p /etc/pihole/ - if [ ! -d "/var/www/html" ]; then - ${SUDO} mkdir -p /var/www/html - fi - ${SUDO} chown ${LIGHTTPD_USER}:${LIGHTTPD_GROUP} /var/www/html - ${SUDO} chmod 775 /var/www/html - ${SUDO} usermod -a -G ${LIGHTTPD_GROUP} pihole - if [ -x "$(command -v lighty-enable-mod)" ]; then - ${SUDO} lighty-enable-mod fastcgi fastcgi-php > /dev/null - else - printf "\n:::\tWarning: 'lighty-enable-mod' utility not found. Please ensure fastcgi is enabled if you experience issues.\n" - fi - - getGitFiles - installScripts - installConfigs - installConfigs - CreateLogFile - configureSelinux - installPiholeWeb - installCron - runGravity - configureFirewall +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() { # Install base files and web interface checkForDependencies # done @@ -865,6 +833,7 @@ installPihole() { installCron runGravity configureFirewall + finalExports } updatePihole() { @@ -967,7 +936,7 @@ if [[ ${useUpdateVars} == false ]]; then # Verify there is enough disk space for the install verifyFreeDiskSpace ${SUDO} mkdir -p /etc/pihole/ - ${SUDO} echo "" > ${setupVars} + # Find IP used to route to outside world findIPRoute # Find interfaces and let the user choose one From 681144b2a31c4aac0e5cf2f6a3423018038bae74 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 26 Aug 2016 22:52:44 +0100 Subject: [PATCH 51/53] Change the switched for updateDashboard and updatePihole(was updateMain) --- pihole | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pihole b/pihole index d06ac29c..40581e9e 100755 --- a/pihole +++ b/pihole @@ -98,8 +98,8 @@ function helpFunc { echo "::: -b, blacklist Blacklist domains" echo "::: -d, debug Start a debugging session if having trouble" echo "::: -f, flush Flush the pihole.log file" - echo "::: -u, updateDashboard Update the web dashboard manually" - echo "::: -U, updateMain Update Pi-hole" + 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 "::: -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" @@ -119,8 +119,8 @@ case "$1" in "-b" | "blacklist" ) blacklistFunc "$@";; "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; -"-u" | "updateDashboard" ) updateDashboardFunc;; -"-U" | "updateMain" ) updateMainFunc;; +"-ud" | "updateDashboard" ) updateDashboardFunc;; +"-up" | "updatePihole" ) updateMainFunc;; "-g" | "updateGravity" ) updateGravityFunc "$@";; "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; From 344e63c2dc5d25cbebaf0618582134dc4ed28025 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 26 Aug 2016 23:06:35 +0100 Subject: [PATCH 52/53] Add undocumented argument to install script ("pihole") which allows the pihole command to run the update script without prompting the user. Useful for update automation --- automated install/basic-install.sh | 8 +- pihole | 132 +---------------------------- 2 files changed, 8 insertions(+), 132 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 756d1427..70036761 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -924,7 +924,13 @@ updateDialogs(){ ######## SCRIPT ############ if [[ -f ${setupVars} ]];then . ${setupVars} - updateDialogs + + if [ "$1" == "pihole" ]; then + useUpdateVars=true + else + updateDialogs + fi + fi # Start the installer diff --git a/pihole b/pihole index 40581e9e..c8ceb8ca 100755 --- a/pihole +++ b/pihole @@ -1,131 +1 @@ -#!/bin/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 -# Controller for all pihole scripts and functions. -# -# 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. - -# Must be root to use this tool -if [[ ! $EUID -eq 0 ]];then - #echo "::: You are root." -#else - #echo "::: Sudo will be used for this tool." - # Check if it is actually installed - # If it isn't, exit because the pihole cannot be invoked without privileges. - if [ -x "$(command -v sudo)" ];then - export SUDO="sudo" - else - echo "::: Please install sudo or run this as root." - exit 1 - fi -fi - -function whitelistFunc { - shift - ${SUDO} /opt/pihole/whitelist.sh "$@" - exit 1 -} - -function blacklistFunc { - shift - ${SUDO} /opt/pihole/blacklist.sh "$@" - exit 1 -} - -function debugFunc { - ${SUDO} /opt/pihole/piholeDebug.sh - exit 1 -} - -function flushFunc { - ${SUDO} /opt/pihole/piholeLogFlush.sh - exit 1 -} - -function updateDashboardFunc { - ${SUDO} /opt/pihole/updateDashboard.sh - exit 1 -} - -function updateMainFunc { - echo "::: Fetching latest changes from Github..." - cd /etc/.pihole - ${SUDO} git pull - ${SUDO} /etc/.pihole/automated\ install/basic-install.sh - exit 1 -} - -function updateGravityFunc { - ${SUDO} /opt/pihole/gravity.sh "$@" - exit 1 -} - -function setupLCDFunction { - ${SUDO} /opt/pihole/setupLCD.sh - exit 1 -} - -function chronometerFunc { - shift - ${SUDO} /opt/pihole/chronometer.sh "$@" - exit 1 -} - - -function uninstallFunc { - ${SUDO} /opt/pihole/uninstall.sh - exit 1 -} - -function versionFunc { - ${SUDO} /opt/pihole/version.sh - exit 1 -} - -function helpFunc { - echo "::: Control all PiHole specific functions!" - echo ":::" - echo "::: Usage: pihole [options]" - echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" - echo ":::" - echo "::: Options:" - echo "::: -w, whitelist Whitelist domains" - echo "::: -b, blacklist Blacklist domains" - echo "::: -d, debug Start a debugging session if having trouble" - echo "::: -f, flush Flush the pihole.log file" - 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 "::: -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 "::: -h, help Show this help dialog" - echo "::: -v, version Show current versions" - echo "::: uninstall Uninstall Pi-Hole from your system :(!" - exit 1 -} - -if [[ $# = 0 ]]; then - helpFunc -fi - -# Handle redirecting to specific functions based on arguments -case "$1" in -"-w" | "whitelist" ) whitelistFunc "$@";; -"-b" | "blacklist" ) blacklistFunc "$@";; -"-d" | "debug" ) debugFunc;; -"-f" | "flush" ) flushFunc;; -"-ud" | "updateDashboard" ) updateDashboardFunc;; -"-up" | "updatePihole" ) updateMainFunc;; -"-g" | "updateGravity" ) updateGravityFunc "$@";; -"-s" | "setupLCD" ) setupLCDFunction;; -"-c" | "chronometer" ) chronometerFunc "$@";; -"-h" | "help" ) helpFunc;; -"-v" | "version" ) versionFunc;; -"uninstall" ) uninstallFunc;; -* ) helpFunc;; -esac +#!/bin/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 # Controller for all pihole scripts and functions. # # 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. # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then #echo "::: You are root." #else #echo "::: Sudo will be used for this tool." # Check if it is actually installed # If it isn't, exit because the pihole cannot be invoked without privileges. if [ -x "$(command -v sudo)" ];then export SUDO="sudo" else echo "::: Please install sudo or run this as root." exit 1 fi fi function whitelistFunc { shift ${SUDO} /opt/pihole/whitelist.sh "$@" exit 1 } function blacklistFunc { shift ${SUDO} /opt/pihole/blacklist.sh "$@" exit 1 } function debugFunc { ${SUDO} /opt/pihole/piholeDebug.sh exit 1 } function flushFunc { ${SUDO} /opt/pihole/piholeLogFlush.sh exit 1 } function updateDashboardFunc { ${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 } function updateGravityFunc { ${SUDO} /opt/pihole/gravity.sh "$@" exit 1 } function setupLCDFunction { ${SUDO} /opt/pihole/setupLCD.sh exit 1 } function chronometerFunc { shift ${SUDO} /opt/pihole/chronometer.sh "$@" exit 1 } function uninstallFunc { ${SUDO} /opt/pihole/uninstall.sh exit 1 } function versionFunc { ${SUDO} /opt/pihole/version.sh exit 1 } function helpFunc { echo "::: Control all PiHole specific functions!" echo ":::" echo "::: Usage: pihole [options]" echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" echo ":::" echo "::: Options:" echo "::: -w, whitelist Whitelist domains" echo "::: -b, blacklist Blacklist domains" echo "::: -d, debug Start a debugging session if having trouble" echo "::: -f, flush Flush the pihole.log file" 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 "::: -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 "::: -h, help Show this help dialog" echo "::: -v, version Show current versions" echo "::: uninstall Uninstall Pi-Hole from your system :(!" exit 1 } if [[ $# = 0 ]]; then helpFunc fi # Handle redirecting to specific functions based on arguments case "$1" in "-w" | "whitelist" ) whitelistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";; "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; "-ud" | "updateDashboard" ) updateDashboardFunc;; "-up" | "updatePihole" ) updatePiholeFunc;; "-g" | "updateGravity" ) updateGravityFunc "$@";; "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; "-v" | "version" ) versionFunc;; "uninstall" ) uninstallFunc;; * ) helpFunc;; esac \ No newline at end of file From d938f7320786955f3498cf4db18d210c0f1e56c0 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Fri, 26 Aug 2016 23:10:22 +0100 Subject: [PATCH 53/53] Fix line endings --- pihole | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/pihole b/pihole index c8ceb8ca..3863db74 100755 --- a/pihole +++ b/pihole @@ -1 +1,131 @@ -#!/bin/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 # Controller for all pihole scripts and functions. # # 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. # Must be root to use this tool if [[ ! $EUID -eq 0 ]];then #echo "::: You are root." #else #echo "::: Sudo will be used for this tool." # Check if it is actually installed # If it isn't, exit because the pihole cannot be invoked without privileges. if [ -x "$(command -v sudo)" ];then export SUDO="sudo" else echo "::: Please install sudo or run this as root." exit 1 fi fi function whitelistFunc { shift ${SUDO} /opt/pihole/whitelist.sh "$@" exit 1 } function blacklistFunc { shift ${SUDO} /opt/pihole/blacklist.sh "$@" exit 1 } function debugFunc { ${SUDO} /opt/pihole/piholeDebug.sh exit 1 } function flushFunc { ${SUDO} /opt/pihole/piholeLogFlush.sh exit 1 } function updateDashboardFunc { ${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 } function updateGravityFunc { ${SUDO} /opt/pihole/gravity.sh "$@" exit 1 } function setupLCDFunction { ${SUDO} /opt/pihole/setupLCD.sh exit 1 } function chronometerFunc { shift ${SUDO} /opt/pihole/chronometer.sh "$@" exit 1 } function uninstallFunc { ${SUDO} /opt/pihole/uninstall.sh exit 1 } function versionFunc { ${SUDO} /opt/pihole/version.sh exit 1 } function helpFunc { echo "::: Control all PiHole specific functions!" echo ":::" echo "::: Usage: pihole [options]" echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" echo ":::" echo "::: Options:" echo "::: -w, whitelist Whitelist domains" echo "::: -b, blacklist Blacklist domains" echo "::: -d, debug Start a debugging session if having trouble" echo "::: -f, flush Flush the pihole.log file" 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 "::: -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 "::: -h, help Show this help dialog" echo "::: -v, version Show current versions" echo "::: uninstall Uninstall Pi-Hole from your system :(!" exit 1 } if [[ $# = 0 ]]; then helpFunc fi # Handle redirecting to specific functions based on arguments case "$1" in "-w" | "whitelist" ) whitelistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";; "-d" | "debug" ) debugFunc;; "-f" | "flush" ) flushFunc;; "-ud" | "updateDashboard" ) updateDashboardFunc;; "-up" | "updatePihole" ) updatePiholeFunc;; "-g" | "updateGravity" ) updateGravityFunc "$@";; "-s" | "setupLCD" ) setupLCDFunction;; "-c" | "chronometer" ) chronometerFunc "$@";; "-h" | "help" ) helpFunc;; "-v" | "version" ) versionFunc;; "uninstall" ) uninstallFunc;; * ) helpFunc;; esac \ No newline at end of file +#!/bin/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 +# Controller for all pihole scripts and functions. +# +# 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. + +# Must be root to use this tool +if [[ ! $EUID -eq 0 ]];then + #echo "::: You are root." +#else + #echo "::: Sudo will be used for this tool." + # Check if it is actually installed + # If it isn't, exit because the pihole cannot be invoked without privileges. + if [ -x "$(command -v sudo)" ];then + export SUDO="sudo" + else + echo "::: Please install sudo or run this as root." + exit 1 + fi +fi + +function whitelistFunc { + shift + ${SUDO} /opt/pihole/whitelist.sh "$@" + exit 1 +} + +function blacklistFunc { + shift + ${SUDO} /opt/pihole/blacklist.sh "$@" + exit 1 +} + +function debugFunc { + ${SUDO} /opt/pihole/piholeDebug.sh + exit 1 +} + +function flushFunc { + ${SUDO} /opt/pihole/piholeLogFlush.sh + exit 1 +} + +function updateDashboardFunc { + ${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 +} + +function updateGravityFunc { + ${SUDO} /opt/pihole/gravity.sh "$@" + exit 1 +} + +function setupLCDFunction { + ${SUDO} /opt/pihole/setupLCD.sh + exit 1 +} + +function chronometerFunc { + shift + ${SUDO} /opt/pihole/chronometer.sh "$@" + exit 1 +} + + +function uninstallFunc { + ${SUDO} /opt/pihole/uninstall.sh + exit 1 +} + +function versionFunc { + ${SUDO} /opt/pihole/version.sh + exit 1 +} + +function helpFunc { + echo "::: Control all PiHole specific functions!" + echo ":::" + echo "::: Usage: pihole [options]" + echo "::: Add -h after -w (whitelist), -b (blacklist), or -c (chronometer) for more information on usage" + echo ":::" + echo "::: Options:" + echo "::: -w, whitelist Whitelist domains" + echo "::: -b, blacklist Blacklist domains" + echo "::: -d, debug Start a debugging session if having trouble" + echo "::: -f, flush Flush the pihole.log file" + 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 "::: -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 "::: -h, help Show this help dialog" + echo "::: -v, version Show current versions" + echo "::: uninstall Uninstall Pi-Hole from your system :(!" + exit 1 +} + +if [[ $# = 0 ]]; then + helpFunc +fi + +# Handle redirecting to specific functions based on arguments +case "$1" in +"-w" | "whitelist" ) whitelistFunc "$@";; +"-b" | "blacklist" ) blacklistFunc "$@";; +"-d" | "debug" ) debugFunc;; +"-f" | "flush" ) flushFunc;; +"-ud" | "updateDashboard" ) updateDashboardFunc;; +"-up" | "updatePihole" ) updatePiholeFunc;; +"-g" | "updateGravity" ) updateGravityFunc "$@";; +"-s" | "setupLCD" ) setupLCDFunction;; +"-c" | "chronometer" ) chronometerFunc "$@";; +"-h" | "help" ) helpFunc;; +"-v" | "version" ) versionFunc;; +"uninstall" ) uninstallFunc;; +* ) helpFunc;; +esac