mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-24 23:23:42 +00:00
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:
parent
40ac22a427
commit
d823af896a
4 changed files with 71 additions and 21 deletions
|
@ -34,13 +34,31 @@ domList=()
|
||||||
domToRemoveList=()
|
domToRemoveList=()
|
||||||
|
|
||||||
|
|
||||||
piholeIPfile=/tmp/piholeIP
|
piholeINTfile=/etc/pihole/piholeINT
|
||||||
|
piholeIPfile=/etc/pihole/piholeIP
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
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
|
# Know which interface we are using.
|
||||||
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
|
if [[ -f $piholeINTfile ]]; then
|
||||||
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
|
# This file should normally exist - it was saved as part of the install.
|
||||||
piholeIP=${piholeIPCIDR%/*}
|
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
|
modifyHost=false
|
||||||
|
|
||||||
|
|
|
@ -33,13 +33,31 @@ versbose=true
|
||||||
domList=()
|
domList=()
|
||||||
domToRemoveList=()
|
domToRemoveList=()
|
||||||
|
|
||||||
piholeIPfile=/tmp/piholeIP
|
piholeINTfile=/etc/pihole/piholeINT
|
||||||
|
piholeIPfile=/etc/pihole/piholeIP
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
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
|
# Know which interface we are using.
|
||||||
IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
|
if [[ -f $piholeINTfile ]]; then
|
||||||
piholeIPCIDR=$(ip -o -f inet addr show dev $IPv4dev | awk '{print $4}' | awk 'END {print}')
|
# This file should normally exist - it was saved as part of the install.
|
||||||
piholeIP=${piholeIPCIDR%/*}
|
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
|
modifyHost=false
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,6 @@ chooseInterface() {
|
||||||
do
|
do
|
||||||
piholeInterface=$desiredInterface
|
piholeInterface=$desiredInterface
|
||||||
echo "::: Using interface: $piholeInterface"
|
echo "::: Using interface: $piholeInterface"
|
||||||
echo ${piholeInterface} > /tmp/piholeINT
|
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "::: Cancel selected, exiting...."
|
echo "::: Cancel selected, exiting...."
|
||||||
|
@ -219,6 +218,9 @@ use4andor6() {
|
||||||
Gateway: $IPv4gw" $r $c)
|
Gateway: $IPv4gw" $r $c)
|
||||||
then
|
then
|
||||||
echo "::: Leaving IPv4 settings as is."
|
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
|
else
|
||||||
getStaticIPv4Settings
|
getStaticIPv4Settings
|
||||||
setStaticIPv4
|
setStaticIPv4
|
||||||
|
@ -284,9 +286,9 @@ getStaticIPv4Settings() {
|
||||||
IP address: $IPv4addr
|
IP address: $IPv4addr
|
||||||
Gateway: $IPv4gw" $r $c)then
|
Gateway: $IPv4gw" $r $c)then
|
||||||
# If the settings are correct, then we need to set the piholeIP
|
# 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
|
# Saving the IP and interface to a file for future use by other scripts (gravity.sh, whitelist.sh, etc.)
|
||||||
echo ${IPv4addr%/*} > /tmp/piholeIP
|
echo ${IPv4addr%/*} > /etc/pihole/piholeIP
|
||||||
echo $piholeInterface > /tmp/piholeINT
|
echo $piholeInterface > /etc/pihole/piholeINT
|
||||||
# After that's done, the loop ends and we move on
|
# After that's done, the loop ends and we move on
|
||||||
ipSettingsCorrect=True
|
ipSettingsCorrect=True
|
||||||
else
|
else
|
||||||
|
|
26
gravity.sh
26
gravity.sh
|
@ -26,7 +26,8 @@ else
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
piholeIPfile=/tmp/piholeIP
|
piholeINTfile=/etc/pihole/piholeINT
|
||||||
|
piholeIPfile=/etc/pihole/piholeIP
|
||||||
piholeIPv6file=/etc/pihole/.useIPv6
|
piholeIPv6file=/etc/pihole/.useIPv6
|
||||||
|
|
||||||
adListFile=/etc/pihole/adlists.list
|
adListFile=/etc/pihole/adlists.list
|
||||||
|
@ -34,15 +35,26 @@ adListDefault=/etc/pihole/adlists.default
|
||||||
whitelistScript=/usr/local/bin/whitelist.sh
|
whitelistScript=/usr/local/bin/whitelist.sh
|
||||||
blacklistScript=/usr/local/bin/blacklist.sh
|
blacklistScript=/usr/local/bin/blacklist.sh
|
||||||
|
|
||||||
if [[ -f $piholeIPfile ]];then
|
# Know which interface we are using.
|
||||||
# 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
|
if [[ -f $piholeINTfile ]]; then
|
||||||
piholeIP=$(cat $piholeIPfile)
|
# This file should normally exist - it was saved as part of the install.
|
||||||
rm $piholeIPfile
|
IPv4dev=$(cat $piholeINTfile)
|
||||||
else
|
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)}')
|
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%/*}
|
piholeIP=${piholeIPCIDR%/*}
|
||||||
|
echo "::: Warning: ${piholeIPfile} is missing. Using IPv4 address ${piholeIP}."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f $piholeIPv6file ]];then
|
if [[ -f $piholeIPv6file ]];then
|
||||||
|
|
Loading…
Reference in a new issue