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)}')
IPv4addr=$(ip -o -f inet addr show dev $IPv4dev| awk '{print $4}'| awk 'END {print}')
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}')
IPv4gw=$(ip route get 8.8.8.8 | awk '{print $3}')
@ -59,33 +63,32 @@ else
fi
fi
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
upgrade=true
else
else
upgrade=false
upgrade=false
fi
fi
####### FUNCTIONS ##########
####### FUNCTIONS ##########
###All credit for the below function goes to http://fitnr.com/showing-a-bash-spinner.html
###All credit for the below function goes to http://fitnr.com/showing-a-bash-spinner.html
spinner(){
spinner(){
localpid=$1
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"
}
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
if[[ -f /etc/dnsmasq.d/adList.conf ]];then
echo"Original Pi-hole detected. Initiating sub space transport"
echo"Original Pi-hole detected. Initiating sub space transport"
$SUDO mkdir -p /etc/pihole/original/
$SUDO mkdir -p /etc/pihole/original/
@ -100,7 +103,7 @@ backupLegacyPihole(){
fi
fi
}
}
welcomeDialogs(){
welcomeDialogs(){
# Display the welcome dialog
# 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
whiptail --msgbox --backtitle "Welcome" --title "Pi-hole automated installer""This installer will transform your Raspberry Pi into a network-wide ad blocker!"$r$c
@ -112,8 +115,8 @@ welcomeDialogs(){
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
}
}
chooseInterface(){
chooseInterface(){
# Turn the available interfaces into an array so it can be used with a whiptail dialog
# Turn the available interfaces into an array so it can be used with a whiptail dialog
piholeIPv6=$(ip -6 route get 2001:4860:4860::8888 | awk -F " "'{ for(i=1;i<=NF;i++) if ($i == "src") print $(i+1) }')
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
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
$SUDO touch /etc/pihole/.useIPv6
}
}
getStaticIPv4Settings(){
getStaticIPv4Settings(){
# Ask if the user wants to use DHCP settings as their static IP
# 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?
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: $IPv4addr
@ -241,22 +245,25 @@ getStaticIPv4Settings(){
fi
fi
}
}
setDHCPCD(){
setDHCPCD(){
#Append these lines to dhcpcd.conf to enable a static IP
#Append these lines to dhcpcd.conf to enable a static IP
echo"interface $piholeInterface
echo"interface $piholeInterface
static ip_address=$IPv4addr
static ip_address=$IPv4addr
static routers=$IPv4gw
static routers=$IPv4gw
static domain_name_servers=$IPv4gw" | $SUDO tee -a $dhcpcdFile >/dev/null
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
if grep -q $IPv4addr$dhcpcdFile;then
# address already set, noop
# address already set, noop
:
:
else
else
setDHCPCD
setDHCPCD
$SUDO ip addr replace dev $piholeInterface$IPv4addr
$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
fi
}
}
@ -305,7 +312,8 @@ versionCheckDNSmasq(){
$SUDO sed -i "s/@DNS2@/$piholeDNS2/" /etc/dnsmasq.d/01-pihole.conf
$SUDO sed -i "s/@DNS2@/$piholeDNS2/" /etc/dnsmasq.d/01-pihole.conf
}
}
installScripts(){
installScripts(){
# Install the scripts from /etc/.pihole to their various locations