mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-15 02:42:58 +00:00
make IPv4/IPv6 checking more robust in gravity
This commit is contained in:
parent
16e4f79f09
commit
8cb72d87e4
1 changed files with 25 additions and 12 deletions
37
gravity.sh
37
gravity.sh
|
@ -42,7 +42,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Remove the /* from the end of the IPv4addr.
|
#Remove the /* from the end of the IPv4addr.
|
||||||
IPv4addr=${IPv4_address%/*}
|
IPv4_address=${IPv4_address%/*}
|
||||||
|
|
||||||
# Variables for various stages of downloading and formatting the list
|
# Variables for various stages of downloading and formatting the list
|
||||||
basename=pihole
|
basename=pihole
|
||||||
|
@ -246,17 +246,30 @@ gravity_hostFormat() {
|
||||||
else
|
else
|
||||||
echo "::: Error: Unable to determine fully qualified domain name of host"
|
echo "::: Error: Unable to determine fully qualified domain name of host"
|
||||||
fi
|
fi
|
||||||
# If there is a value in the $piholeIPv6, then IPv6 will be used, so the awk command modified to create a line for both protocols
|
|
||||||
if [[ -n "${IPv6_address}" ]];then
|
# Check vars from setupVars.conf to see if we're using IPv4, IPv6, Or both.
|
||||||
# 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)
|
if [[ -n "${IPv4_address}" && -n "${IPv6_address}" ]];then
|
||||||
echo -e "$IPv4addr $hostname\n$IPv6_address $hostname\n$IPv4addr pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc}
|
|
||||||
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
# Both IPv4 and IPv6
|
||||||
else
|
echo -e "$IPv4_address $hostname\n$IPv6_address $hostname\n$IPv4_address pi.hole\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc}
|
||||||
# Otherwise, just create gravity.list as normal using IPv4
|
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" -v ipv6addr="$IPv6_address" '{sub(/\r$/,""); print ipv4addr" "$0"\n"ipv6addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
||||||
# 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 "$IPv4addr $hostname\n$IPv4addr pi.hole" > ${piholeDir}/${accretionDisc}
|
elif [[ -n "${IPv4_address}" && -z "${IPv6_address}" ]];then
|
||||||
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4addr" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
|
||||||
fi
|
# Only IPv4
|
||||||
|
echo -e "$IPv4addr $hostname\n$IPv4addr pi.hole" > ${piholeDir}/${accretionDisc}
|
||||||
|
cat ${piholeDir}/${eventHorizon} | awk -v ipv4addr="$IPv4_address" '{sub(/\r$/,""); print ipv4addr" "$0}' >> ${piholeDir}/${accretionDisc}
|
||||||
|
|
||||||
|
elif [[ -z "${IPv4_address}" && -n "${IPv6_address}" ]];then
|
||||||
|
|
||||||
|
# Only IPv6
|
||||||
|
echo -e "$IPv6_address $hostname\n$IPv6_address pi.hole" > ${piholeDir}/${accretionDisc}
|
||||||
|
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
|
||||||
|
|
||||||
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
# Copy the file over as /etc/pihole/gravity.list so dnsmasq can use it
|
||||||
cp ${piholeDir}/${accretionDisc} ${adList}
|
cp ${piholeDir}/${accretionDisc} ${adList}
|
||||||
|
|
Loading…
Reference in a new issue