IPv4dev=$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++)if($i~/dev/)print $(i+1)}')
IPv4addr=$(ip -o -f inet addr show dev $IPv4dev| awk '{print $4}'| awk 'END {print}')
IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}')
@ -59,33 +63,32 @@ else
fi
fi
if[ -f "/etc/dnsmasq.d/01-pihole.conf"];then
#Likely an existing install
if[ -d "/etc/pihole"];then
# Likely an existing install
upgrade=true
else
upgrade=false
upgrade=false
fi
####### FUNCTIONS ##########
###All credit for the below function goes to http://fitnr.com/showing-a-bash-spinner.html
spinner(){
localpid=$1
spin='-\|/'
i=0
while$SUDOkill -0 $pid 2>/dev/null
do
i=$(((i+1)%4))
printf"\b${spin:$i:1}"
sleep .1
done
printf"\b"
}
spinner(){
localpid=$1
spin='-\|/'
i=0
while$SUDOkill -0 $pid 2>/dev/null
do
i=$(((i+1)%4))
printf"\b${spin:$i:1}"
sleep .1
done
printf"\b"
}
backupLegacyPihole(){
backupLegacyPihole(){
# This function detects and backups the pi-hole v1 files. It will not do anything to the current version files.
if[[ -f /etc/dnsmasq.d/adList.conf ]];then
echo"Original Pi-hole detected. Initiating sub space transport"
$SUDO mkdir -p /etc/pihole/original/
@ -100,23 +103,23 @@ backupLegacyPihole(){
fi
}
welcomeDialogs(){
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
# 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
# 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.
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
chooseInterface(){
# Turn the available interfaces into an array so it can be used with a whiptail dialog
interfacesArray=()
firstloop=1
whileread -r line
do
mode="OFF"
@ -126,12 +129,12 @@ chooseInterface(){
fi
interfacesArray+=("$line""available""$mode")
done<<<"$availableInterfaces"
# Find out how many interfaces are available to choose from
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
$SUDO mkdir -p /etc/pihole/
$SUDO touch /etc/pihole/.useIPv6
}
getStaticIPv4Settings(){
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
@ -241,22 +245,25 @@ getStaticIPv4Settings(){
fi
}
setDHCPCD(){
#Append these lines to dhcpcd.conf to enable a static IP
setDHCPCD(){
#Append these lines to dhcpcd.conf to enable a static IP
echo"interface $piholeInterface
static ip_address=$IPv4addr
static routers=$IPv4gw
static domain_name_servers=$IPv4gw" | $SUDO tee -a $dhcpcdFile >/dev/null
}
setStaticIPv4(){
setStaticIPv4(){
# Tries to set the IPv4 address
if grep -q $IPv4addr$dhcpcdFile;then
# address already set, noop
:
else
setDHCPCD
$SUDO ip addr replace dev $piholeInterface$IPv4addr
echo"Setting IP to $IPv4addr. You may need to restart after the install is complete."
echo":::"
echo"::: Setting IP to $IPv4addr. You may need to restart after the install is complete."
echo":::"
fi
}
@ -305,110 +312,123 @@ versionCheckDNSmasq(){
$SUDO sed -i "s/@DNS2@/$piholeDNS2/" /etc/dnsmasq.d/01-pihole.conf
}
installScripts(){
installScripts(){
# Install the scripts from /etc/.pihole to their various locations