Install script now saves interface and IPv4 address to files in /etc/pihole rather than /tmp.

gravity.sh, blacklist.sh, whitelist.sh read from these files first.  If they cannot find them then they warn the user and detect and use the most sensible interface / IPv4 address.
gravity.sh no longer deletes the IPv4 file.
This commit is contained in:
ryt51V 2016-02-29 21:57:44 +00:00
parent 40ac22a427
commit d823af896a
4 changed files with 71 additions and 21 deletions

View file

@ -34,13 +34,31 @@ domList=()
domToRemoveList=()
piholeIPfile=/tmp/piholeIP
piholeINTfile=/etc/pihole/piholeINT
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
# Know which interface we are using.
if [[ -f $piholeINTfile ]]; then
# This file should normally exist - it was saved as part of the install.
IPv4dev=$(cat $piholeINTfile)
else
# If it doesn't, we err on the side of working with the majority of setups and detect the most likely interface.
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
echo "::: Warning: ${piholeINTfile} is missing. Using interface ${IPv4dev}."
fi
# Know which IPv4 address we are using.
if [[ -f $piholeIPfile ]];then
# This file should normally exist - it was saved as part of the install.
piholeIP=$(cat $piholeIPfile)
else
# If it doesn't, we err on the side of working with the majority of setups and detect the most likely IPv4 address,
# which is the first one we find belonging to the given interface.
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | head -n 1)
piholeIP=${piholeIPCIDR%/*}
echo "::: Warning: ${piholeIPfile} is missing. Using IPv4 address ${piholeIP}."
fi
modifyHost=false

View file

@ -33,13 +33,31 @@ versbose=true
domList=()
domToRemoveList=()
piholeIPfile=/tmp/piholeIP
piholeINTfile=/etc/pihole/piholeINT
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
piholeIP=${piholeIPCIDR%/*}
# Know which interface we are using.
if [[ -f $piholeINTfile ]]; then
# This file should normally exist - it was saved as part of the install.
IPv4dev=$(cat $piholeINTfile)
else
# If it doesn't, we err on the side of working with the majority of setups and detect the most likely interface.
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
echo "::: Warning: ${piholeINTfile} is missing. Using interface ${IPv4dev}."
fi
# Know which IPv4 address we are using.
if [[ -f $piholeIPfile ]];then
# This file should normally exist - it was saved as part of the install.
piholeIP=$(cat $piholeIPfile)
else
# If it doesn't, we err on the side of working with the majority of setups and detect the most likely IPv4 address,
# which is the first one we find belonging to the given interface.
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | head -n 1)
piholeIP=${piholeIPCIDR%/*}
echo "::: Warning: ${piholeIPfile} is missing. Using IPv4 address ${piholeIP}."
fi
modifyHost=false

View file

@ -152,7 +152,6 @@ chooseInterface() {
do
piholeInterface=$desiredInterface
echo "::: Using interface: $piholeInterface"
echo ${piholeInterface} > /tmp/piholeINT
done
else
echo "::: Cancel selected, exiting...."
@ -219,6 +218,9 @@ use4andor6() {
Gateway: $IPv4gw" $r $c)
then
echo "::: Leaving IPv4 settings as is."
# Saving the IP and interface to a file for future use by other scripts (gravity.sh, whitelist.sh, etc.)
echo ${IPv4addr%/*} > /etc/pihole/piholeIP
echo $piholeInterface > /etc/pihole/piholeINT
else
getStaticIPv4Settings
setStaticIPv4
@ -284,9 +286,9 @@ getStaticIPv4Settings() {
IP address: $IPv4addr
Gateway: $IPv4gw" $r $c)then
# If the settings are correct, then we need to set the piholeIP
# Saving it to a temporary file us to retrieve it later when we run the gravity.sh script
echo ${IPv4addr%/*} > /tmp/piholeIP
echo $piholeInterface > /tmp/piholeINT
# Saving the IP and interface to a file for future use by other scripts (gravity.sh, whitelist.sh, etc.)
echo ${IPv4addr%/*} > /etc/pihole/piholeIP
echo $piholeInterface > /etc/pihole/piholeINT
# After that's done, the loop ends and we move on
ipSettingsCorrect=True
else

View file

@ -26,7 +26,8 @@ else
fi
fi
piholeIPfile=/tmp/piholeIP
piholeINTfile=/etc/pihole/piholeINT
piholeIPfile=/etc/pihole/piholeIP
piholeIPv6file=/etc/pihole/.useIPv6
adListFile=/etc/pihole/adlists.list
@ -34,15 +35,26 @@ adListDefault=/etc/pihole/adlists.default
whitelistScript=/usr/local/bin/whitelist.sh
blacklistScript=/usr/local/bin/blacklist.sh
if [[ -f $piholeIPfile ]];then
# If the file exists, it means it was exported from the installation script and we should use that value instead of detecting it in this script
piholeIP=$(cat $piholeIPfile)
rm $piholeIPfile
# Know which interface we are using.
if [[ -f $piholeINTfile ]]; then
# This file should normally exist - it was saved as part of the install.
IPv4dev=$(cat $piholeINTfile)
else
# Otherwise, the IP address can be taken directly from the machine, which will happen when the script is run by the user and not the installation script
# If it doesn't, we err on the side of working with the majority of setups and detect the most likely interface.
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
echo "::: Warning: ${piholeINTfile} is missing. Using interface ${IPv4dev}."
fi
# Know which IPv4 address we are using.
if [[ -f $piholeIPfile ]];then
# This file should normally exist - it was saved as part of the install.
piholeIP=$(cat $piholeIPfile)
else
# If it doesn't, we err on the side of working with the majority of setups and detect the most likely IPv4 address,
# which is the first one we find belonging to the given interface.
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | head -n 1)
piholeIP=${piholeIPCIDR%/*}
echo "::: Warning: ${piholeIPfile} is missing. Using IPv4 address ${piholeIP}."
fi
if [[ -f $piholeIPv6file ]];then