From 885069d4406d53fcecee2b74e81808d4f4137752 Mon Sep 17 00:00:00 2001 From: Jofre Palau Date: Fri, 18 Sep 2015 23:06:29 +0200 Subject: [PATCH 1/2] Allow external IP as an input script parameter: ./gravity.sh 123.123.123.123 --- gravity.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/gravity.sh b/gravity.sh index 2bef29b7..c90501f0 100755 --- a/gravity.sh +++ b/gravity.sh @@ -3,7 +3,12 @@ # Compiles a list of ad-serving domains by downloading them from multiple sources # This script should only be run after you have a static IP address set on the Pi -piholeIP=$(hostname -I) +piholeIP="$1" + +if [[ "$piholeIP" == "" ]]; then + piholeIP=$(hostname -I) +fi + # Ad-list sources--one per line in single quotes sources=('https://adaway.org/hosts.txt' @@ -128,7 +133,7 @@ function gravity_advanced() echo "** $numberOf unique domains trapped in the event horizon." # Format domain list as "192.168.x.x domain.com" echo "** Formatting domains into a HOSTS file..." - cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP"'" $0}' > $origin/$accretionDisc + cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP "'" $0}' > $origin/$accretionDisc # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it sudo cp $origin/$accretionDisc $adList kill -HUP $(pidof dnsmasq) From 4ea397bc717b110c3e8c37889c27a7bf5fd6ee02 Mon Sep 17 00:00:00 2001 From: Jofre Palau Date: Mon, 28 Sep 2015 17:40:13 +0200 Subject: [PATCH 2/2] Removed extra blank space if no IP added --- gravity.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gravity.sh b/gravity.sh index c90501f0..30e8413e 100755 --- a/gravity.sh +++ b/gravity.sh @@ -5,8 +5,8 @@ # This script should only be run after you have a static IP address set on the Pi piholeIP="$1" -if [[ "$piholeIP" == "" ]]; then - piholeIP=$(hostname -I) +if [ -n "$piholeIP"]; then + piholeIP=$(hostname -I|xargs) fi @@ -133,7 +133,7 @@ function gravity_advanced() echo "** $numberOf unique domains trapped in the event horizon." # Format domain list as "192.168.x.x domain.com" echo "** Formatting domains into a HOSTS file..." - cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP "'" $0}' > $origin/$accretionDisc + cat $origin/$eventHorizon | awk '{sub(/\r$/,""); print "'"$piholeIP "'" $0}' > $origin/$accretionDisc # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it sudo cp $origin/$accretionDisc $adList kill -HUP $(pidof dnsmasq)