From db89fa9881f0a2047311e6e058c1e8d32904dfbd Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 14 Dec 2016 19:26:55 +0000 Subject: [PATCH 1/6] initial support for additional hosts file --- gravity.sh | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/gravity.sh b/gravity.sh index 0184f193..1c1c397f 100755 --- a/gravity.sh +++ b/gravity.sh @@ -45,11 +45,13 @@ fi #Remove the /* from the end of the IPv4addr. IPV4_ADDRESS=${IPV4_ADDRESS%/*} +IPV6_ADDRESS=${IPV6_ADDRESS} # Variables for various stages of downloading and formatting the list basename=pihole piholeDir=/etc/${basename} adList=${piholeDir}/gravity.list +localList=${piholeDir}/local.list justDomainsExtension=domains matterAndLight=${basename}.0.matterandlight.txt supernova=${basename}.1.supernova.txt @@ -241,26 +243,37 @@ gravity_unique() { gravity_hostFormat() { # Format domain list as "192.168.x.x domain.com" echo -n "::: Formatting domains into a HOSTS file..." - # Check vars from setupVars.conf to see if we're using IPv4, IPv6, Or both. - if [[ -n "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then + rm ${localList} + if [[ -f /etc/hostname ]]; then + hostname=$(> ${piholeDir}/${accretionDisc} + echo -e "${IPV4_ADDRESS} ${hostname}\n${IPV6_ADDRESS} ${hostname}\n${IPV4_ADDRESS} pi.hole\n${IPV6_ADDRESS} pi.hole" > ${localList} + # Both IPv4 and IPv6 + cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPV4_ADDRESS" -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} - elif [[ -n "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then + elif [[ -n "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then - # Only IPv4 - cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPV4_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} + echo -e "${IPV4_ADDRESS} ${hostname}\n${IPV4_ADDRESS} pi.hole" > ${localList} + # Only IPv4 + cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPV4_ADDRESS" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc} - elif [[ -z "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then + elif [[ -z "${IPV4_ADDRESS}" && -n "${IPV6_ADDRESS}" ]];then - # Only IPv6 - cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} + echo -e "${IPV6_ADDRESS} ${hostname}\n${IPV6_ADDRESS} pi.hole" > ${localList} + # Only IPv6 + cat ${piholeDir}/${eventHorizon} | awk -v ipv6addr="$IPV6_ADDRESS" '{sub(/\r$/,""); print ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc} - elif [[ -z "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then - echo "::: No IP Values found! Please run 'pihole -r' and choose reconfigure to restore values" - exit 1 - fi + elif [[ -z "${IPV4_ADDRESS}" && -z "${IPV6_ADDRESS}" ]];then + echo "::: No IP Values found! Please run 'pihole -r' and choose reconfigure to restore values" + exit 1 + fi # Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it cp ${piholeDir}/${accretionDisc} ${adList} From 684ac98c8ed6c365ec94f0a0894b0a1ef58e3602 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 14 Dec 2016 19:28:01 +0000 Subject: [PATCH 2/6] Remove hostname and pi.hole entries, move to /etc/pihole/local.list --- advanced/01-pihole.conf | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/advanced/01-pihole.conf b/advanced/01-pihole.conf index f4707ef4..0ddf1caa 100644 --- a/advanced/01-pihole.conf +++ b/advanced/01-pihole.conf @@ -20,13 +20,8 @@ # OR IN /etc/dnsmasq.conf # ############################################################################### -address=/pi.hole/@IPv4@ -address=/pi.hole/@IPv6@ - -address=/@HOSTNAME@/@IPv4@ -address=/@HOSTNAME@/@IPv6@ - addn-hosts=/etc/pihole/gravity.list +addn-hosts=/etc/pihole/local.list domain-needed From c10ec5548f0ce1c45052e80235e825120b9dde40 Mon Sep 17 00:00:00 2001 From: Promofaux Date: Wed, 14 Dec 2016 19:29:44 +0000 Subject: [PATCH 3/6] remove code that replaces tokens in 01-pihole.conf --- automated install/basic-install.sh | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index afa44701..9464d03b 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -612,36 +612,6 @@ version_check_dnsmasq() { sed -i '/^server=@DNS2@/d' ${dnsmasq_pihole_01_location} fi - #sed -i "s/@HOSTNAME@/$hostname/" ${dnsmasq_pihole_01_location} - - if [[ -f /etc/hostname ]]; then - hostname=$( Date: Wed, 14 Dec 2016 19:31:57 +0000 Subject: [PATCH 4/6] check for list before removing it --- gravity.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gravity.sh b/gravity.sh index 1c1c397f..9ddd7beb 100755 --- a/gravity.sh +++ b/gravity.sh @@ -243,7 +243,11 @@ gravity_unique() { gravity_hostFormat() { # Format domain list as "192.168.x.x domain.com" echo -n "::: Formatting domains into a HOSTS file..." - rm ${localList} + + if [[ -f ${localList} ]]; then + rm ${localList} + fi + if [[ -f /etc/hostname ]]; then hostname=$( Date: Wed, 14 Dec 2016 19:33:15 +0000 Subject: [PATCH 5/6] no need to remove list, because of echo > --- gravity.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gravity.sh b/gravity.sh index 9ddd7beb..58d0eef9 100755 --- a/gravity.sh +++ b/gravity.sh @@ -244,10 +244,6 @@ gravity_hostFormat() { # Format domain list as "192.168.x.x domain.com" echo -n "::: Formatting domains into a HOSTS file..." - if [[ -f ${localList} ]]; then - rm ${localList} - fi - if [[ -f /etc/hostname ]]; then hostname=$( Date: Wed, 14 Dec 2016 19:42:20 +0000 Subject: [PATCH 6/6] specifically comment out gravity.list addn-host --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index 6d5f8c9d..5509df47 100755 --- a/pihole +++ b/pihole @@ -135,7 +135,7 @@ restartDNS() { piholeEnable() { if [[ "${1}" == "0" ]] ; then #Disable Pihole - sed -i 's/^addn-hosts/#addn-hosts/' /etc/dnsmasq.d/01-pihole.conf + sed -i 's/^addn-hosts=\/etc\/pihole\/gravity.list/#addn-hosts=\/etc\/pihole\/gravity.list/' /etc/dnsmasq.d/01-pihole.conf echo "::: Blocking has been disabled!" if [[ $# > 1 ]] ; then if [[ ${2} == *"s"* ]] ; then