whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer""This installer will transform your Raspberry Pi into a network-wide ad blocker!"$r$c
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer""This installer will transform your Raspberry Pi into a network-wide ad blocker!"${r}${c}
# Support for a part-time dev
whiptail --msgbox --backtitle "Plea" --title "Free and open source""The Pi-hole is free, but powered by your donations: http://pi-hole.net/donate"$r$c
whiptail --msgbox --backtitle "Plea" --title "Free and open source""The Pi-hole is free, but powered by your donations: http://pi-hole.net/donate"${r}${c}
# 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.
whiptail --msgbox --backtitle "Initiating network interface" --title "Static IP Needed""The Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them."$r$c
In the next section, you can choose to use your current network settings (DHCP) or to manually edit them."${r}${c}
}
@ -164,7 +146,7 @@ verifyFreeDiskSpace() {
# - Unknown free disk space , not a integer
if ! [["$existingFreeBytes"=~ ^([0-9])+$ ]];then
whiptail --title "Unknown free disk space" --yesno "We were unable to determine available free disk space on this system.\n\nYou may override this check and force the installation, however, it is not recommended.\n\nWould you like to continue with the installation?" --defaultno --backtitle "Pi-hole"$r$c
whiptail --title "Unknown free disk space" --yesno "We were unable to determine available free disk space on this system.\n\nYou may override this check and force the installation, however, it is not recommended.\n\nWould you like to continue with the installation?" --defaultno --backtitle "Pi-hole"${r}${c}
whiptail --msgbox --backtitle "Insufficient Disk Space" --title "Insufficient Disk Space""\nYour system appears to be low on disk space. pi-hole recomends a minimum of $requiredFreeBytes Bytes.\nYou only have $existingFreeBytes Free.\n\nIf this is a new install you may need to expand your disk.\n\nTry running:\n 'sudo raspi-config'\nChoose the 'expand file system option'\n\nAfter rebooting, run this installation again.\n\ncurl -L install.pi-hole.net | bash\n"$r$c
whiptail --msgbox --backtitle "Insufficient Disk Space" --title "Insufficient Disk Space""\nYour system appears to be low on disk space. pi-hole recomends a minimum of $requiredFreeBytes Bytes.\nYou only have $existingFreeBytes Free.\n\nIf this is a new install you may need to expand your disk.\n\nTry running:\n 'sudo raspi-config'\nChoose the 'expand file system option'\n\nAfter rebooting, run this installation again.\n\ncurl -L install.pi-hole.net | bash\n"${r}${c}
echo"$existingFreeBytes is less than $requiredFreeBytes"
echo"Insufficient free space, exiting..."
exit1
@ -190,13 +172,13 @@ verifyFreeDiskSpace() {
chooseInterface(){
# Turn the available interfaces into an array so it can be used with a whiptail dialog
interfacesArray=()
firstloop=1
firstLoop=1
whileread -r line
do
mode="OFF"
if[[$firstloop -eq 1]];then
firstloop=0
if[[${firstLoop} -eq 1]];then
firstLoop=0
mode="ON"
fi
interfacesArray+=("$line""available""$mode")
@ -204,14 +186,15 @@ chooseInterface() {
# Find out how many interfaces are available to choose from
whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported""$piholeIPv6 will be used to block ads."${r}${c}
$SUDO touch /etc/pihole/.useIPv6
${SUDO} touch /etc/pihole/.useIPv6
}
getStaticIPv4Settings(){
# Ask if the user wants 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
Gateway: $IPv4gw"$r$c) then
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
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}
#piholeIP is saved to a permanent file so gravity.sh can use it when updating
# Give the user a chance to review their settings before moving on
if(whiptail --backtitle "Calibrating network interface" --title "Static IP Address" --yesno "Are these settings correct?
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
# Saving it to a temporary file us to retrieve it later when we run the gravity.sh script. piholeIP is saved to a permanent file so gravity.sh can use it when updating
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'"$r$c"$prePopulate" 3>&1 1>&2 2>&3)
if[[$?=0]];then
piholeDNS1=$(echo"$piholeDNS"| sed 's/[, \t]\+/,/g'| awk -F, '{print$1}')
piholeDNS2=$(echo"$piholeDNS"| sed 's/[, \t]\+/,/g'| awk -F, '{print$2}')
if ! valid_ip "$piholeDNS1"||[ ! "$piholeDNS1"];then
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP""One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2"$r$c
if[[$piholeDNS1=="$strInvalid"]];then
piholeDNS1=""
fi
if[[$piholeDNS2=="$strInvalid"]];then
piholeDNS2=""
fi
DNSSettingsCorrect=False
else
if(whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2"$r $c)then
DNSSettingsCorrect=True
else
# If the settings are wrong, the loop continues
DNSSettingsCorrect=False
fi
fi
done
;;
esac
case${DNSchoices} in
Google)
echo"::: Using Google DNS servers."
piholeDNS1="8.8.8.8"
piholeDNS2="8.8.4.4"
;;
OpenDNS)
echo"::: Using OpenDNS servers."
piholeDNS1="208.67.222.222"
piholeDNS2="208.67.220.220"
;;
Level3)
echo"::: Using Level3 servers."
piholeDNS1="4.2.2.1"
piholeDNS2="4.2.2.2"
;;
Norton)
echo"::: Using Norton ConnectSafe servers."
piholeDNS1="199.85.126.10"
piholeDNS2="199.85.127.10"
;;
Comodo)
echo"::: Using Comodo Secure servers."
piholeDNS1="8.26.56.26"
piholeDNS2="8.20.247.20"
;;
Custom)
until[[${DNSSettingsCorrect}= True ]]
do
strInvalid="Invalid"
if[ ! ${piholeDNS1}];then
if[ ! ${piholeDNS2}];then
prePopulate=""
else
prePopulate=", $piholeDNS2"
fi
elif[${piholeDNS1}]&&[ ! ${piholeDNS2}];then
prePopulate="$piholeDNS1"
elif[${piholeDNS1}]&&[${piholeDNS2}];then
prePopulate="$piholeDNS1, $piholeDNS2"
fi
piholeDNS=$(whiptail --backtitle "Specify Upstream DNS Provider(s)" --inputbox "Enter your desired upstream DNS provider(s), seperated by a comma.\n\nFor example '8.8.8.8, 8.8.4.4'"${r}${c}"$prePopulate" 3>&1 1>&2 2>&3)
if[[$?=0]];then
piholeDNS1=$(echo"$piholeDNS"| sed 's/[, \t]\+/,/g'| awk -F, '{print$1}')
piholeDNS2=$(echo"$piholeDNS"| sed 's/[, \t]\+/,/g'| awk -F, '{print$2}')
if ! valid_ip "$piholeDNS1"||[ ! "$piholeDNS1"];then
whiptail --msgbox --backtitle "Invalid IP" --title "Invalid IP""One or both entered IP addresses were invalid. Please try again.\n\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2"${r}${c}
if[[${piholeDNS1}=="$strInvalid"]];then
piholeDNS1=""
fi
if[[${piholeDNS2}=="$strInvalid"]];then
piholeDNS2=""
fi
DNSSettingsCorrect=False
else
if(whiptail --backtitle "Specify Upstream DNS Provider(s)" --title "Upstream DNS Provider(s)" --yesno "Are these settings correct?\n DNS Server 1: $piholeDNS1\n DNS Server 2: $piholeDNS2"${r}${c});then
If you set a new IP address, you should restart the Pi.
The install log is in /etc/pihole.
View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin"$r$c
View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin"${r}${c}
}
updateDialogs(){
if(whiptail --title "Existing Install detected" --yesno "We have detected you are installing over the top of an existing install.\n\n\nWould you like update?" --defaultyes ${r}${c});then
echo"::: Updating existing install selected"
useUpdateVars= true
fi
}
######## SCRIPT ############
# Start the installer
$SUDO mkdir -p /etc/pihole/
if[[ -f /etc/pihole/setupVars.conf ]];then
. /etc/pihole/setupVars.conf
updateDialogs
fi
# Start the installer
# Install packages used by this installation script
installerDependencies
welcomeDialogs
# Verify there is enough disk space for the install
verifyFreeDiskSpace
if[[${useUpdateVars}==false]];then
${SUDO}echo"" > /etc/pihole/setupVars.conf
${SUDO} mkdir -p /etc/pihole/
welcomeDialogs
# Verify there is enough disk space for the install
verifyFreeDiskSpace
# Find IP used to route to outside world
findIPRoute
# 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 what upstream DNS Servers to use
setDNS
# Install and log everything to a file
installPihole | tee ${tmpLog}
else
echo"Hi!"
fi
# 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 IP used to route to outside world
findIPRoute
# Find interfaces and let the user choose one
chooseInterface
# Let the user decide if they want to block ads over IPv4 and/or IPv6