From 7a82d1ff17af9d17139bd0714746303a75f07514 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 3 Dec 2015 09:26:43 -0800 Subject: [PATCH 1/3] 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 3c6d14f..f59214b 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 2/3] 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 30d7238..c426916 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 f59214b..04f1b39 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 b9a5ca60b2f63a3ea27ea77a1ef9edb164d158e0 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Thu, 3 Dec 2015 20:34:45 -0800 Subject: [PATCH 3/3] 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 f59214b..55292ad 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 ##########