@ -36,58 +50,246 @@ if [[ -f /etc/dnsmasq.d/adList.conf ]];then
else
:
fi
}
echo"Updating the Pi..."
sudo apt-get update
sudo apt-get -y upgrade
welcomeDialogs()
{
# Display the welcome dialog
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer""This installer will transform your Raspberry Pi into a network-wide ad blocker!"$r$c
echo"Installing tools..."
sudo apt-get -y install dnsutils
sudo apt-get -y install bc
sudo apt-get -y install toilet
# Explain the need for a static address
whiptail --msgbox --backtitle "Initating network interface" --title "Static IP Needed""The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.
echo"Installing DNS..."
sudo apt-get -y install dnsmasq
sudo update-rc.d dnsmasq enable
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them."$r$c
}
chooseInterface()
{
# Turn the available interfaces into an array so it can be used with a whiptail dialog
interfacesArray=()
whileread -r line
do
interfacesArray+=("$line""available""ON")
done<<<"$availableInterfaces"
# Find out how many interfaces are available to choose from
whiptail --msgbox --backtitle "Coming soon..." --title "IPv6 not yet supported""I need your help for IPv6. Consider donating at: http://pi-hole.net/donate"$r$c
}
getStaticIPv4Settings()
{
# Ask if the user wannts to use DHCP settings as their static IP
if(whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Do you want to use your current network settings as a static address?
IP address: $IPv4addr
Subnet mask: $IPv4mask
Gateway: $IPv4gw"$r$c) then
# If they choose yes, let the user know that the IP address will not be available via DHCP and may cause a conflict.
whiptail --msgbox --backtitle "IP information" --title "FYI: IP Conflict""It is possible your router could still try to assign this IP to a device, which would cause a conflict. But in most cases the router is smart enough to not do that.
If you are worried, either manually set the address, or modify the DHCP reservation pool so it does not include the IP you want.
It is also possible to use a DHCP reservation, but if you are going to do that, you might as well set a static address."$r$c
# Nothing else to do since the variables are already set above
else
# Since a custom address will be used, restart at the end of the script to apply the new changes
rebootNeeded=true
# Otherwise, we need to ask the user to input their desired settings.
# Start by getting the IPv4 address (pre-filling it with info gathered from DHCP)
# Start a loop to let the user enter their information with the chance to go back and edit it if necessary
# Just back up the original Pi-hole right away since it won't take long and it gets it out of the way
backupLegacyPihole
# Find interfaces and let the user choose one
chooseInterface
# Let the user decide if they want to block ads over IPv4 and/or IPv6
use4andor6
# Decide is IPv4 will be used
if[["$useIPv4"=true]];then
echo"Using IPv4"
getStaticIPv4Settings
setStaticIPv4
else
useIPv4=false
echo"IPv4 will NOT be used."
fi
# Decide is IPv6 will be used
if[["$useIPv6"=true]];then
# If only IPv6 is selected, exit because it is not supported yet
if[["$useIPv6"=true]]&&[["$useIPv4"=false]];then
useIPv6dialog
exit
else
useIPv6dialog
fi
else
useIPv6=false
echo"IPv6 will NOT be used. Consider a donation at pi-hole.net/donate"
fi
# Install and log everything to a file
installPihole | tee $tmpLog
echo"Restarting..."
sudo reboot
# Move the log file into /etc/pihole for storage
sudo mv $tmpLog$instalLogLoc
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!""Configure your devices to use the Pi-hole as their DNS server using this IP: $IPv4addr.
If you didn't use DHCP settings as your new static address, the Pi will restart after this dialog. If you are using SSH, you may need to reconnect using the IP address above.
The install log is in /etc/pihole."$r$c
# If a custom address was set, restart
if[["$rebootNeeded"=true]];then
# Restart to apply the new static IP address
sudo reboot
else
# If not, just start the services since the address will stay the same