1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-11-19 14:48:13 +00:00

additional hostname checks in gravity.sh

- Test if /etc/hostname exists before attempting to cat the file.
 - Add alternative hostname discovery via hostname command
 - Add an error message to stdout if unable to determine host fqdn
This commit is contained in:
bcambl 2016-09-07 20:38:44 -06:00
parent 6c0c6182e9
commit 640af300cb

View File

@ -264,7 +264,13 @@ function gravity_unique() {
function gravity_hostFormat() {
# Format domain list as "192.168.x.x domain.com"
echo "::: Formatting domains into a HOSTS file..."
hostname=$(</etc/hostname)
if [[ -f /etc/hostname ]]; then
hostname=$(</etc/hostname)
elif [ -x "$(command -v hostname)" ]; then
hostname=$(hostname -f)
else
echo "::: Error: Unable to determine fully qualified domain name of host"
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 ${piholeIPv6} ]];then
# 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)