From 7a82d1ff17af9d17139bd0714746303a75f07514 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 3 Dec 2015 09:26:43 -0800 Subject: [PATCH 01/15] Breakout basic-install.sh into functions --- automated install/basic-install.sh | 82 ++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 28 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3c6d14fd..f59214b3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -182,45 +182,71 @@ static domain_name_servers=$IPv4gw" | sudo tee -a $dhcpcdFile >/dev/null sudo ip addr replace dev $piholeInterface $IPv4addr } -installPihole() -{ +installScripts(){ +sudo curl -o /usr/local/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh +sudo curl -o /usr/local/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh +sudo curl -o /usr/local/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh +sudo curl -o /usr/local/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh +sudo chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,piholeLogFlush}.sh +} + +installConfigs(){ +sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig +sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig +sudo curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf +sudo curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf +} + +stopServices(){ +sudo service dnsmasq stop || true +sudo service lighttpd stop || true +} + +installDependencies(){ sudo apt-get update sudo apt-get -y upgrade sudo apt-get -y install dnsutils bc toilet sudo apt-get -y install dnsmasq sudo apt-get -y install lighttpd php5-common php5-cgi php5 -sudo mkdir /var/www/html -sudo chown www-data:www-data /var/www/html -sudo chmod 775 /var/www/html -sudo usermod -a -G www-data pi -sudo service dnsmasq stop -sudo service lighttpd stop -sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig -sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig -sudo mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig -sudo mv /etc/crontab /etc/crontab.orig -sudo curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf -sudo curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf -sudo mv /etc/crontab /etc/crontab.orig -sudo curl -o /etc/crontab https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron -sudo lighty-enable-mod fastcgi fastcgi-php -sudo mkdir /var/www/html/pihole -sudo curl -o /var/www/html/pihole/index.html https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html +} + +installWebAdmin(){ sudo wget https://github.com/jacobsalmela/AdminLTE/archive/master.zip -O /var/www/master.zip -sudo unzip -o /var/www/master.zip -d /var/www/html/ +sudo unzip -oq /var/www/master.zip -d /var/www/html/ sudo mv /var/www/html/AdminLTE-master /var/www/html/admin sudo rm /var/www/master.zip 2>/dev/null +} + +installPiholeWeb(){ +sudo mkdir /var/www/html/pihole +sudo mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig +sudo curl -o /var/www/html/pihole/index.html https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html +} + +installCron(){ +sudo mv /etc/crontab /etc/crontab.orig +sudo curl -o /etc/crontab https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron +} + +installPiLog(){ sudo touch /var/log/pihole.log sudo chmod 644 /var/log/pihole.log sudo chown dnsmasq:root /var/log/pihole.log -sudo curl -o /usr/local/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh -sudo curl -o /usr/local/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh -sudo curl -o /usr/local/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh -sudo curl -o /usr/local/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh -sudo chmod 755 /usr/local/bin/gravity.sh -sudo chmod 755 /usr/local/bin/chronometer.sh -sudo chmod 755 /usr/local/bin/whitelist.sh -sudo chmod 755 /usr/local/bin/piholeLogFlush.sh +} +installPihole() +{ +installDependencies +stopServices +sudo chown www-data:www-data /var/www/html +sudo chmod 775 /var/www/html +sudo usermod -a -G www-data pi +sudo lighty-enable-mod fastcgi fastcgi-php +installScripts +installConfigs +installWebAdmin +installPiholeWeb +installCron +installPiLog sudo /usr/local/bin/gravity.sh } From 3651ee5480a434435d8800d98b759353709c1a08 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 3 Dec 2015 09:56:27 -0800 Subject: [PATCH 02/15] Bugfix for hardcoded dnsmasq.conf interface Add target to dnsmasq.conf for sed Replace dnsmasq.conf target with selected interface --- advanced/dnsmasq.conf | 2 +- automated install/basic-install.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/advanced/dnsmasq.conf b/advanced/dnsmasq.conf index 30d72381..c4269165 100644 --- a/advanced/dnsmasq.conf +++ b/advanced/dnsmasq.conf @@ -26,7 +26,7 @@ server=8.8.4.4 # If you want dnsmasq to listen for DHCP and DNS requests only on # specified interfaces (and the loopback) give the name of the # interface (eg eth0) here. -interface=eth0 +interface=@INT@ # Or which to listen on by address (remember to include 127.0.0.1 if # you use this.) listen-address=127.0.0.1 diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index f59214b3..04f1b39c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -82,6 +82,7 @@ for desiredInterface in $chooseInterfaceOptions do piholeInterface=$desiredInterface echo "Using interface: $piholeInterface" + echo ${piholeInterface} > /tmp/piholeINT done } @@ -195,6 +196,7 @@ sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig sudo curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf sudo curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf +sudo sed -i "s/@INT@/$piholeInterface/" /etc/dnsmasq.conf } stopServices(){ From 861673594d91e1710b2492b9dedd64b89d5ae969 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 3 Dec 2015 13:17:27 -0800 Subject: [PATCH 03/15] Point to wiki Point users to the Wiki Customization entry instead of the PR --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 258168c2..4021b766 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,11 @@ The [Web interface](https://github.com/jacobsalmela/AdminLTE#pi-hole-admin-dashb If you want to use your own variables for the gravity script (i.e. storing the files in a different location) and don't want to have to change them every time there is an update to the script, create a file called `/etc/pihole/pihole.conf`. In it, you should add your own variables in a similar fashion as shown below: ``` -origin=/var/run/pihole +piholeDir=/var/run/pihole adList=/etc/dnsmasq.d/adList ``` -See [this PR](https://github.com/jacobsalmela/pi-hole/pull/20) for more details. +See the [Wiki](https://github.com/jacobsalmela/pi-hole/wiki/Customization) entry for more details. ### How It Works A technical and detailed description can be found [here](http://jacobsalmela.com/block-millions-ads-network-wide-with-a-raspberry-pi-hole-2-0)! From b9a5ca60b2f63a3ea27ea77a1ef9edb164d158e0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 3 Dec 2015 20:34:45 -0800 Subject: [PATCH 04/15] Oneline ip link call, tighten awk call --- 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 f59214b3..55292ade 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -34,7 +34,7 @@ IPv4gw=$(echo $IPv4info | awk '{print $3}') #IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1) #IPv6linkLocal=$(ip addr show | awk '/inet/ && /scope\ link/ && /fe80/ {print $2}' | cut -d'/' -f1) -availableInterfaces=$(ip link show | awk -F' ' '/[0-9]: [a-z]/ {print $2}' | grep -v "lo" | cut -d':' -f1) +availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1) dhcpcdFile=/etc/dhcpcd.conf ####### FUCNTIONS ########## From 0c3409a028920f059fc783217a8d1408646a471a Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Fri, 4 Dec 2015 21:41:37 -0600 Subject: [PATCH 05/15] fixes #111 Also clears out some errors users don't need to see --- gravity.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gravity.sh b/gravity.sh index 7d9440a3..170774c6 100755 --- a/gravity.sh +++ b/gravity.sh @@ -14,7 +14,7 @@ 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 IPv4dev=$(ip route get 8.8.8.8 | awk '{print $5}') piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}') - piholeIP=${piholeIPCIDR%/*} + piholeIP=${piholeIPCIDR%/*} fi # Ad-list sources--one per line in single quotes @@ -89,7 +89,7 @@ function gravity_transport() { url=$1 cmd_ext=$2 agent=$3 - + # tmp file, so we don't have to store the (long!) lists in RAM patternBuffer=$(mktemp) heisenbergCompensator="" @@ -140,7 +140,7 @@ function gravity_spinup() { # Default is a simple request *) cmd_ext="" esac - gravity_transport $url $cmd_ext $agent + gravity_transport $url $cmd_ext $agent done } @@ -151,14 +151,14 @@ function gravity_Schwarzchild() { echo "** Aggregating list of domains..." truncate -s 0 $piholeDir/$matter for i in "${activeDomains[@]}" - do + do cat $i |tr -d '\r' >> $piholeDir/$matter done } # Pulsar - White/blacklist application function gravity_pulsar() { - + # Append blacklist entries if they exist if [[ -r $blacklist ]];then numberOf=$(cat $blacklist | sed '/^\s*$/d' | wc -l) @@ -178,11 +178,11 @@ function gravity_pulsar() { # regexp so it can be parsed out with grep -x awk -F '[# \t]' 'NF>0&&$1!="" {print "^"$1"$"}' $whitelist | sed 's/\./\\./g' > $latentWhitelist else - rm $latentWhitelist + rm $latentWhitelist >/dev/null fi # Prevent our sources from being pulled into the hole - plural=; [[ "${#sources[@]}" != "1" ]] && plural=s + plural=; [[ "${#sources[@]}" != "1" ]] && plural=s echo "** Whitelisting ${#sources[@]} ad list source${plural}..." for url in ${sources[@]} do @@ -210,7 +210,7 @@ function gravity_hostFormat() { # blackbody - remove any remnant files from script processes function gravity_blackbody() { - # Loop through list files + # Loop through list files for file in $piholeDir/*.$justDomainsExtension do # If list is in active array then leave it (noop) else rm the list @@ -234,14 +234,14 @@ function gravity_advanced() { echo "** $numberOf domains being pulled in by gravity..." gravity_unique - - sudo kill -HUP $(pidof dnsmasq) + + sudo kill -s -HUP $(pidof dnsmasq) } gravity_collapse gravity_spinup gravity_Schwarzchild gravity_pulsar -gravity_hostFormat gravity_advanced +gravity_hostFormat gravity_blackbody From 49a40115c8fd5692b43bce68e9e818dcb0c0d157 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Sat, 5 Dec 2015 14:04:37 -0600 Subject: [PATCH 06/15] fixes #105 --- advanced/dnsmasq.conf | 4 ++-- automated install/basic-install.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/advanced/dnsmasq.conf b/advanced/dnsmasq.conf index 30d72381..8fe5bb27 100644 --- a/advanced/dnsmasq.conf +++ b/advanced/dnsmasq.conf @@ -18,7 +18,7 @@ bogus-priv # uncomment this. no-resolv -# Add other name servers here, with domain specs if they are for +# Add other name servers here, with domain specs if they are for # non-public domains. server=8.8.8.8 server=8.8.4.4 @@ -26,7 +26,7 @@ server=8.8.4.4 # If you want dnsmasq to listen for DHCP and DNS requests only on # specified interfaces (and the loopback) give the name of the # interface (eg eth0) here. -interface=eth0 +interface=@INT@ # Or which to listen on by address (remember to include 127.0.0.1 if # you use this.) listen-address=127.0.0.1 diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3c6d14fd..d2a67a10 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -92,7 +92,6 @@ cmd=(whiptail --separate-output --checklist "Select Protocols" $r $c 2) options=(IPv4 "Block ads over IPv4" on IPv6 "Block ads over IPv4" off) choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) -clear for choice in $choices do case $choice in @@ -179,6 +178,7 @@ echo "interface $piholeInterface static ip_address=$IPv4addr static routers=$IPv4gw static domain_name_servers=$IPv4gw" | sudo tee -a $dhcpcdFile >/dev/null +echo "Setting IP to $IPv4addr. You may need to restart after the install is complete." sudo ip addr replace dev $piholeInterface $IPv4addr } @@ -200,6 +200,7 @@ sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig sudo mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig sudo mv /etc/crontab /etc/crontab.orig sudo curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf +sudo sed -i "s/@INT@/$piholeInterface/" /etc/dnsmasq.conf sudo curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf sudo mv /etc/crontab /etc/crontab.orig sudo curl -o /etc/crontab https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron From f453d407a9f03d6eb601e12936a55e11c76ffe89 Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Sat, 5 Dec 2015 14:14:34 -0600 Subject: [PATCH 07/15] log-async For better performance. I have been using it for a few weeks with no adverse effects. --- advanced/dnsmasq.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/dnsmasq.conf b/advanced/dnsmasq.conf index 8fe5bb27..25f52a57 100644 --- a/advanced/dnsmasq.conf +++ b/advanced/dnsmasq.conf @@ -45,3 +45,6 @@ log-facility=/var/log/pihole.log # server for potentially stale date, you can set a time-to-live (in # seconds) here. local-ttl=300 + +# This allows it to continue functioning without being blocked by syslog, and allows syslog to use dnsmasq for DNS queries without risking deadlock +log-async From 2b5030e629cca370ee16d0bbc12c7e27c475f8af Mon Sep 17 00:00:00 2001 From: Jacob Salmela Date: Sat, 5 Dec 2015 23:23:44 -0600 Subject: [PATCH 08/15] Link to explainer video Also clarifies that the automated install is for Raspbian installs only. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4021b766..6e6f6a8f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# Automated Install +# Automated Install +#### Designed For Raspberry Pi B, B+, 2, +##### and Zero (with an Ethernet adapter) 1. Install Raspbian 2. Run the command below @@ -11,12 +13,10 @@ Once installed, **configure any device to use the Raspberry Pi as its DNS server [![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif "AdminLTE Presentation")](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=3J2L3Z4DHW9UY "Donate") -# Raspberry Pi Ad Blocker -**A black hole for ads, hence Pi-hole** +# How Does It Work? +**Watch the 60-second video below to get a quick overview** -![Pi-hole](http://i.imgur.com/wd5ltCU.png) - -The Pi-hole is a DNS/Web server that will **block ads for any device on your network**. +[![Pi-hole exlplained](http://i.imgur.com/wd5ltCU.png)](https://vimeo.com/135965232) ## Coverage From d8034f41560e644772634df3f0e289b85c88033e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 5 Dec 2015 22:17:28 -0800 Subject: [PATCH 09/15] Get last IP listed for interface --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 170774c6..043b3139 100755 --- a/gravity.sh +++ b/gravity.sh @@ -13,7 +13,7 @@ if [[ -f $piholeIPfile ]];then 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 IPv4dev=$(ip route get 8.8.8.8 | awk '{print $5}') - piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}') + piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}') | sed -n '$p' piholeIP=${piholeIPCIDR%/*} fi From d0685935822efd01200bd9e39be76e3586f0703a Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 6 Dec 2015 00:30:16 -0800 Subject: [PATCH 10/15] Get last IP for selected interface --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 043b3139..2598baa9 100755 --- a/gravity.sh +++ b/gravity.sh @@ -13,7 +13,7 @@ if [[ -f $piholeIPfile ]];then 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 IPv4dev=$(ip route get 8.8.8.8 | awk '{print $5}') - piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}') | sed -n '$p' + piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}') | awk 'END {print}') piholeIP=${piholeIPCIDR%/*} fi From 7cf5320f50364107c4c7122f526f964fb513bbdc Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 6 Dec 2015 02:40:30 -0800 Subject: [PATCH 11/15] Only write to dhcpcd.conf if address isn't set --- automated install/basic-install.sh | 105 +++++++++++++++++++---------- 1 file changed, 70 insertions(+), 35 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 3c6d14fd..8ea854fc 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -34,7 +34,7 @@ IPv4gw=$(echo $IPv4info | awk '{print $3}') #IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1) #IPv6linkLocal=$(ip addr show | awk '/inet/ && /scope\ link/ && /fe80/ {print $2}' | cut -d'/' -f1) -availableInterfaces=$(ip link show | awk -F' ' '/[0-9]: [a-z]/ {print $2}' | grep -v "lo" | cut -d':' -f1) +availableInterfaces=$(ip -o link | awk '{print $2}' | grep -v "lo" | cut -d':' -f1) dhcpcdFile=/etc/dhcpcd.conf ####### FUCNTIONS ########## @@ -82,6 +82,7 @@ for desiredInterface in $chooseInterfaceOptions do piholeInterface=$desiredInterface echo "Using interface: $piholeInterface" + echo ${piholeInterface} > /tmp/piholeINT done } @@ -92,7 +93,6 @@ cmd=(whiptail --separate-output --checklist "Select Protocols" $r $c 2) options=(IPv4 "Block ads over IPv4" on IPv6 "Block ads over IPv4" off) choices=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty) -clear for choice in $choices do case $choice in @@ -171,56 +171,91 @@ done fi } - -setStaticIPv4() -{ -# Append these lines to /etc/dhcpcd.conf to enable a static IP +setDHCPCD(){ +# Append these lines to dhcpcd.conf to enable a static IP echo "interface $piholeInterface static ip_address=$IPv4addr static routers=$IPv4gw static domain_name_servers=$IPv4gw" | sudo tee -a $dhcpcdFile >/dev/null -sudo ip addr replace dev $piholeInterface $IPv4addr } -installPihole() -{ +setStaticIPv4(){ +if grep -q $IPv4addr $dhcpcdFile; then + # address already set, noop + : +else + setDHCPCD + sudo ip addr replace dev $piholeInterface $IPv4addr + echo "Setting IP to $IPv4addr. You may need to restart after the install is complete." +fi +} + +installScripts(){ +sudo curl -o /usr/local/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh +sudo curl -o /usr/local/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh +sudo curl -o /usr/local/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh +sudo curl -o /usr/local/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh +sudo chmod 755 /usr/local/bin/{gravity,chronometer,whitelist,piholeLogFlush}.sh +} + +installConfigs(){ +sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig +sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig +sudo curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf +sudo curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf +sudo sed -i "s/@INT@/$piholeInterface/" /etc/dnsmasq.conf +} + +stopServices(){ +sudo service dnsmasq stop || true +sudo service lighttpd stop || true +} + +installDependencies(){ sudo apt-get update sudo apt-get -y upgrade sudo apt-get -y install dnsutils bc toilet sudo apt-get -y install dnsmasq sudo apt-get -y install lighttpd php5-common php5-cgi php5 -sudo mkdir /var/www/html -sudo chown www-data:www-data /var/www/html -sudo chmod 775 /var/www/html -sudo usermod -a -G www-data pi -sudo service dnsmasq stop -sudo service lighttpd stop -sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig -sudo mv /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.orig -sudo mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig -sudo mv /etc/crontab /etc/crontab.orig -sudo curl -o /etc/dnsmasq.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/dnsmasq.conf -sudo curl -o /etc/lighttpd/lighttpd.conf https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/lighttpd.conf -sudo mv /etc/crontab /etc/crontab.orig -sudo curl -o /etc/crontab https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron -sudo lighty-enable-mod fastcgi fastcgi-php -sudo mkdir /var/www/html/pihole -sudo curl -o /var/www/html/pihole/index.html https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html +} + +installWebAdmin(){ sudo wget https://github.com/jacobsalmela/AdminLTE/archive/master.zip -O /var/www/master.zip -sudo unzip -o /var/www/master.zip -d /var/www/html/ +sudo unzip -oq /var/www/master.zip -d /var/www/html/ sudo mv /var/www/html/AdminLTE-master /var/www/html/admin sudo rm /var/www/master.zip 2>/dev/null +} + +installPiholeWeb(){ +sudo mkdir /var/www/html/pihole +sudo mv /var/www/html/index.lighttpd.html /var/www/html/index.lighttpd.orig +sudo curl -o /var/www/html/pihole/index.html https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/index.html +} + +installCron(){ +sudo mv /etc/crontab /etc/crontab.orig +sudo curl -o /etc/crontab https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron +} + +installPiLog(){ sudo touch /var/log/pihole.log sudo chmod 644 /var/log/pihole.log sudo chown dnsmasq:root /var/log/pihole.log -sudo curl -o /usr/local/bin/gravity.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/gravity.sh -sudo curl -o /usr/local/bin/chronometer.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/chronometer.sh -sudo curl -o /usr/local/bin/whitelist.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/whitelist.sh -sudo curl -o /usr/local/bin/piholeLogFlush.sh https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/Scripts/piholeLogFlush.sh -sudo chmod 755 /usr/local/bin/gravity.sh -sudo chmod 755 /usr/local/bin/chronometer.sh -sudo chmod 755 /usr/local/bin/whitelist.sh -sudo chmod 755 /usr/local/bin/piholeLogFlush.sh +} +installPihole() +{ +installDependencies +stopServices +sudo chown www-data:www-data /var/www/html +sudo chmod 775 /var/www/html +sudo usermod -a -G www-data pi +sudo lighty-enable-mod fastcgi fastcgi-php +installScripts +installConfigs +installWebAdmin +installPiholeWeb +installCron +installPiLog sudo /usr/local/bin/gravity.sh } From b391afef49a589d5d1aa9a5a3e33add78f3a3372 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 6 Dec 2015 04:45:04 -0800 Subject: [PATCH 12/15] Interface pull for multiple platforms --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 2598baa9..e097f702 100755 --- a/gravity.sh +++ b/gravity.sh @@ -12,7 +12,7 @@ if [[ -f $piholeIPfile ]];then 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 - IPv4dev=$(ip route get 8.8.8.8 | awk '{print $5}') + IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}') | awk 'END {print}') piholeIP=${piholeIPCIDR%/*} fi From a230df00320fb3a257cb41fcbbf829d8b4bec4d1 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 6 Dec 2015 05:33:22 -0800 Subject: [PATCH 13/15] Fix errant ) --- gravity.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index e097f702..66df1e3e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -13,7 +13,7 @@ if [[ -f $piholeIPfile ]];then 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 IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') - piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}') | awk 'END {print}') + piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') piholeIP=${piholeIPCIDR%/*} fi From d2b260fc1e04c243b9edaa0ad4920ad3e25df893 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 6 Dec 2015 10:29:59 -0800 Subject: [PATCH 14/15] Log file is automatically generated by dnsmasq, no need to create. --- automated install/basic-install.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8ea854fc..59baecf7 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -237,11 +237,6 @@ sudo mv /etc/crontab /etc/crontab.orig sudo curl -o /etc/crontab https://raw.githubusercontent.com/jacobsalmela/pi-hole/master/advanced/pihole.cron } -installPiLog(){ -sudo touch /var/log/pihole.log -sudo chmod 644 /var/log/pihole.log -sudo chown dnsmasq:root /var/log/pihole.log -} installPihole() { installDependencies @@ -255,7 +250,6 @@ installConfigs installWebAdmin installPiholeWeb installCron -installPiLog sudo /usr/local/bin/gravity.sh } From 412a190b429a8c545729a9fc5edae21cbd6ce88b Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 6 Dec 2015 11:05:09 -0800 Subject: [PATCH 15/15] Basic-install.sh should only show one ip address in whiptail screen. --- automated install/basic-install.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 8ea854fc..8d3e2358 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -25,10 +25,9 @@ r=$(( rows / 2 )) c=$(( columns / 2 )) # Find IP used to route to outside world -IPv4info=$(ip route get 8.8.8.8) -IPv4dev=$(echo $IPv4info| awk '{print $5}') -IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}') -IPv4gw=$(echo $IPv4info | awk '{print $3}') +IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}') +IPv4addr=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}') +IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}') # IPv6 support to be added later #IPv6eui64=$(ip addr show | awk '/scope\ global/ && /ff:fe/ {print $2}' | cut -d'/' -f1)