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""\n\nThis installer will transform your device 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""\n\nThe 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 "Initiating 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""\n\nThe 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}
}
@ -184,8 +188,15 @@ verifyFreeDiskSpace() {
chooseInterface(){
# Turn the available interfaces into an array so it can be used with a whiptail dialog
interfacesArray=()
firstLoop=1
localinterfacesArray=()
# Number of available interfaces
local interfaceCount
# Whiptail variable storage
local chooseInterfaceCmd
# Temporary Whiptail options storage
local chooseInterfaceOptions
# Loop sentinel variable
localfirstLoop=1
whileread -r line
do
@ -211,10 +222,18 @@ chooseInterface() {
echo"::: Cancel selected, exiting...."
exit1
fi
}
useIPv6dialog(){
# Show the IPv6 address used for blocking
IPv6_address=$(ip -6 route get 2001:4860:4860::8888 | awk -F " "'{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported""$IPv6_address will be used to block ads."${r}${c}
}
use4andor6(){
local useIPv4
local useIPv6
# Let use select IPv4 and/or IPv6
cmd=(whiptail --separate-output --checklist "Select Protocols (press space to select)"${r}${c} 2)
options=(IPv4 "Block ads over IPv4" on
@ -228,47 +247,31 @@ use4andor6() {
IPv6 )useIPv6=true;;
esac
done
if[${useIPv4}]&&[ ! ${useIPv6}];then
if[[${useIPv4}]];then
find_IPv4_information
getStaticIPv4Settings
setStaticIPv4
echo"::: Using IPv4 on $IPv4addr"
echo"::: IPv6 will NOT be used."
fi
if[ ! ${useIPv4}]&&[${useIPv6}];then
if[[${useIPv6}]];then
useIPv6dialog
echo"::: IPv4 will NOT be used."
echo"::: Using IPv6 on $piholeIPv6"
fi
if[${useIPv4}]&&[${useIPv6}];then
getStaticIPv4Settings
setStaticIPv4
useIPv6dialog
echo"::: Using IPv4 on $IPv4addr"
echo"::: Using IPv6 on $piholeIPv6"
fi
echo"::: IPv4 address: ${IPv4_address}"
echo"::: IPv6 address: ${IPv6_address}"
if[ ! ${useIPv4}]&&[ ! ${useIPv6}];then
echo"::: Cannot continue, neither IPv4 or IPv6 selected"
echo"::: Exiting"
exit1
fi
else
echo"::: Cancel selected. Exiting..."
exit1
fi
}
useIPv6dialog(){
# Show the IPv6 address used for blocking
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " "'{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
whiptail --msgbox --backtitle "IPv6..." --title "IPv6 Supported""$piholeIPv6 will be used to block ads."${r}${c}
}
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
IP address: $IPv4_address
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.
@ -282,16 +285,16 @@ It is also possible to use a DHCP reservation, but if you are going to do that,
printf"::: Warning: Pi-Hole SELinux policy did not install correctly!\n"
fi
semodule -l | grep pihole &> /dev/null &&echo"::: Installed Pi-Hole SELinux policy"||echo"::: Warning: Pi-Hole SELinux policy did not install."
fi
}
@ -850,18 +849,18 @@ displayFinalMessage() {
# Final completion message to user
whiptail --msgbox --backtitle "Make it so." --title "Installation Complete!""Configure your devices to use the Pi-hole as their DNS server using:
IPv4: ${IPv4addr%/*}
IPv6: $piholeIPv6
IPv4: ${IPv4_address%/*}
IPv6: $IPv6_address
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://${IPv4_address%/*}/admin"${r}${c}
}
update_dialogs(){
UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "We have detected an existing install.\n\nPlease chose from the following options:" ${r}${c}2\
UpdateCmd=$(whiptail --title "Existing Install Detected!" --menu "\n\nWe have detected an existing install.\n\nPlease choose from the following options:" ${r}${c}2\
"Update""Update install will retain existing settings."\
"Install""Install will allow you to enter new settings." 3>&2 2>&1 1>&3)
@ -869,6 +868,7 @@ update_dialogs(){
case${UpdateCmd} in
Update)
echo"::: Updating existing install"
. ${setupVars}
useUpdateVars=true
;;
Install)
@ -885,14 +885,11 @@ update_dialogs(){
main(){
if[[ -f ${setupVars}]];then
. ${setupVars}
if["$1"=="pihole"];then
useUpdateVars=true
else
update_dialogs
fi
fi
# Start the installer
@ -904,8 +901,17 @@ else
verifyFreeDiskSpace
fi
# Update package cache
update_pacakge_cache
# Notify user of package availability
notify_package_updates_available
# Install packages used by this installation script
installerDependencies
install_dependent_packages INSTALLER_DEPS[@]
# Install packages used by the Pi-hole
install_dependent_packages PIHOLE_DEPS[@]
if[[${useUpdateVars}==false]];then
# Display welcome dialogs
@ -920,8 +926,8 @@ if [[ ${useUpdateVars} == false ]]; then
# Stop resolver and webserver while installing proceses
stop_service dnsmasq
stop_service lighttpd
# Find IP used to route to outside world
findIPRoute
# Determine available interfaces
get_available_interfaces
# Find interfaces and let the user choose one
chooseInterface
# Let the user decide if they want to block ads over IPv4 and/or IPv6
@ -943,23 +949,17 @@ fi
echo -n "::: Restarting services..."
# Start services
if[ -x "$(command -v systemctl)"];then
systemctl enable dnsmasq
systemctl restart dnsmasq
systemctl enable lighttpd
systemctl start lighttpd
else
service dnsmasq restart
service lighttpd start
fi
start_service dnsmasq
enable_service dnsmasq
start_service lighttpd
enable_service lighttpd
echo" done."
echo":::"
if[[${useUpdateVars}==false]];then
echo"::: Installation Complete! Configure your devices to use the Pi-hole as their DNS server using:"
echo"::: ${IPv4addr%/*}"
echo"::: $piholeIPv6"
echo"::: ${IPv4_address%/*}"
echo"::: $IPv6_address"
echo":::"
echo"::: If you set a new IP address, you should restart the Pi."
else
@ -968,7 +968,7 @@ fi
echo":::"
echo"::: The install log is located at: /etc/pihole/install.log"
echo"::: View the web interface at http://pi.hole/admin or http://${IPv4addr%/*}/admin"
echo"::: View the web interface at http://pi.hole/admin or http://${IPv4_address%/*}/admin"
#Source the setupVars from install script for the IP
. /etc/pihole/setupVars.conf
#Remove the /* from the end of the IPv4addr.
IPv4addr=${IPv4addr%/*}
IPv4addr=${IPv4_address%/*}
# Variables for various stages of downloading and formatting the list
basename=pihole
@ -254,10 +254,10 @@ function gravity_hostFormat() {
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
if[[ -n "${IPv6_address}"]];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)
# Otherwise, just create gravity.list as normal using IPv4
# 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)