# Some distros vary slightly so these fixes for dependencies may apply
# on Ubuntu 18.04.1 LTS we need to add the universe repository to gain access to dhcpcd5
APT_SOURCES="/etc/apt/sources.list"
if awk 'BEGIN{a=1;b=0}/bionic main/{a=0}/bionic.*universe/{b=1}END{exit a + b}'${APT_SOURCES};then
if ! whiptail --defaultno --title "Dependencies Require Update to Allowed Repositories" --yesno "Would you like to enable 'universe' repository?\\n\\nThis repository is required by the following packages:\\n\\n- dhcpcd5""${r}""${c}";then
printf" %b Aborting installation: Dependencies could not be installed.\\n""${CROSS}"
exit1
else
printf" %b Enabling universe package repository for Ubuntu Bionic\\n""${INFO}"
cp -p ${APT_SOURCES}${APT_SOURCES}.backup # Backup current repo list
printf" %b Backed up current configuration to %s\\n""${TICK}""${APT_SOURCES}.backup"
whiptail --msgbox --backtitle "Plea" --title "Free and open source""\\n\\nThe Pi-hole is free, but powered by your donations: https://pi-hole.net/donate/""${r}""${c}"
# Explain the need for a static address
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.
if whiptail --defaultno --backtitle "Initiating network interface" --title "Static IP Needed" --yesno"\\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}"
IMPORTANT: If you have not already done so, you must ensure that this device has a static IP. Either through DHCP reservation, or by manually assigning one. Depending on your operating system, there are many ways to achieve this.
Choose yes to indicate that you have understood this message, and wish to continue" "${r}" "${c}"; then
#Nothing to do, continue
echo
else
printf" %b Installer exited at static IP message.\\n""${INFO}"
exit1
fi
}
# A function that lets the user pick an interface to use with Pi-hole
@ -847,8 +843,11 @@ use4andor6() {
if[["${useIPv4}"]];then
# Run our function to get the information we need
find_IPv4_information
getStaticIPv4Settings
setStaticIPv4
if[[ -f "/etc/dhcpcd.conf"]];then
# configure networking via dhcpcd
getStaticIPv4Settings
setDHCPCD
fi
fi
# If IPv6 is to be used,
if[["${useIPv6}"]];then
@ -933,93 +932,6 @@ setDHCPCD() {
fi
}
# Configure networking ifcfg-xxxx file found at /etc/sysconfig/network-scripts/
# This function requires the full path of an ifcfg file passed as an argument
setIFCFG(){
# Local, named variables
local IFCFG_FILE
local IPADDR
local CIDR
IFCFG_FILE=$1
printf -v IPADDR "%s""${IPV4_ADDRESS%%/*}"
# Check if the desired IP is already set
if grep -Eq "${IPADDR}(\\b|\\/)""${IFCFG_FILE}";then
printf" %b Static IP already configured\\n""${INFO}"
else
# Otherwise, put the IP in variables without the CIDR notation
printf -v CIDR "%s""${IPV4_ADDRESS##*/}"
# Backup existing interface configuration:
cp -p "${IFCFG_FILE}""${IFCFG_FILE}".pihole.orig
# Build Interface configuration file using the GLOBAL variables we have
{
echo"# Configured via Pi-hole installer"
echo"DEVICE=$PIHOLE_INTERFACE"
echo"BOOTPROTO=none"
echo"ONBOOT=yes"
echo"IPADDR=$IPADDR"
echo"PREFIX=$CIDR"
echo"GATEWAY=$IPv4gw"
echo"DNS1=$PIHOLE_DNS_1"
echo"DNS2=$PIHOLE_DNS_2"
echo"USERCTL=no"
}> "${IFCFG_FILE}"
chmod 644"${IFCFG_FILE}"
chown root:root "${IFCFG_FILE}"
# Use ip to immediately set the new address
ip addr replace dev "${PIHOLE_INTERFACE}""${IPV4_ADDRESS}"
# If NetworkMangler command line interface exists and ready to mangle,
if is_command nmcli && nmcli general status &> /dev/null;then
# Tell NetworkManagler to read our new sysconfig file
nmcli con load "${IFCFG_FILE}" > /dev/null
fi
# Show a warning that the user may need to restart
printf" %b Set IP address to %s\\n You may need to restart after the install is complete\\n""${TICK}""${IPV4_ADDRESS%%/*}"
fi
}
setStaticIPv4(){
# Local, named variables
local IFCFG_FILE
local CONNECTION_NAME
# If a static interface is already configured, we are done.