2015-11-25 21:43:59 +00:00
#!/usr/bin/env bash
2017-07-26 17:00:08 +00:00
# shellcheck disable=SC1090
2015-10-28 22:29:34 +00:00
# Pi-hole: A black hole for Internet advertisements
2022-06-19 00:17:10 +00:00
# (c) Pi-hole (https://pi-hole.net)
2017-02-22 17:55:20 +00:00
# Network-wide ad blocking via your own hardware.
#
2017-07-26 17:00:08 +00:00
# Installs and Updates Pi-hole
2015-12-06 14:31:49 +00:00
#
2017-02-22 17:55:20 +00:00
# This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license.
2015-10-28 22:29:34 +00:00
# pi-hole.net/donate
2015-06-14 03:14:21 +00:00
#
2017-07-07 00:25:56 +00:00
# Install with this command (from your Linux machine):
2015-06-14 03:14:21 +00:00
#
2018-01-20 13:29:38 +00:00
# curl -sSL https://install.pi-hole.net | bash
2015-06-14 03:14:21 +00:00
2017-07-07 00:25:56 +00:00
# -e option instructs bash to immediately exit if any command [1] has a non-zero exit status
# We do not want users to end up with a partially working install, so we exit the script
# instead of continuing the installation with something broken
2016-10-10 09:24:03 +00:00
set -e
2017-07-07 00:25:56 +00:00
2021-03-18 01:35:27 +00:00
# Append common folders to the PATH to ensure that all basic commands are available.
# When using "su" an incomplete PATH could be passed: https://github.com/pi-hole/pi-hole/issues/3209
2020-07-02 21:19:30 +00:00
export PATH += ':/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
2015-10-28 22:29:34 +00:00
######## VARIABLES #########
2017-07-07 00:25:56 +00:00
# For better maintainability, we store as much information that can change in variables
2018-02-07 05:45:23 +00:00
# This allows us to make a change in one place that can propagate to all instances of the variable
2017-07-07 00:25:56 +00:00
# These variables should all be GLOBAL variables, written in CAPS
# Local variables will be in lowercase and will exist only within functions
# It's still a work in progress, so you may see some variance in this guideline until it is complete
2022-06-19 00:17:10 +00:00
# Dialog result codes
# dialog code values can be set by environment variables, we only override if
# the env var is not set or empty.
: " ${ DIALOG_OK : =0 } "
: " ${ DIALOG_CANCEL : =1 } "
: " ${ DIALOG_ESC : =255 } "
2019-01-13 14:51:30 +00:00
# List of supported DNS servers
DNS_SERVERS = $( cat << EOM
2021-10-04 03:16:19 +00:00
Google ( ECS, DNSSEC) ; 8.8.8.8; 8.8.4.4; 2001:4860:4860:0:0:0:0:8888; 2001:4860:4860:0:0:0:0:8844
2020-11-24 20:02:53 +00:00
OpenDNS ( ECS, DNSSEC) ; 208.67.222.222; 208.67.220.220; 2620:119:35::35; 2620:119:53::53
2019-01-13 14:51:30 +00:00
Level3; 4.2.2.1; 4.2.2.2; ;
Comodo; 8.26.56.26; 8.20.247.20; ;
2021-10-04 03:16:19 +00:00
DNS.WATCH ( DNSSEC) ; 84.200.69.80; 84.200.70.40; 2001:1608:10:25:0:0:1c04:b12f; 2001:1608:10:25:0:0:9249:d69b
2019-01-13 14:51:30 +00:00
Quad9 ( filtered, DNSSEC) ; 9.9.9.9; 149.112.112.112; 2620:fe::fe; 2620:fe::9
Quad9 ( unfiltered, no DNSSEC) ; 9.9.9.10; 149.112.112.10; 2620:fe::10; 2620:fe::fe:10
2021-10-04 03:16:19 +00:00
Quad9 ( filtered, ECS, DNSSEC) ; 9.9.9.11; 149.112.112.11; 2620:fe::11; 2620:fe::fe:11
Cloudflare ( DNSSEC) ; 1.1.1.1; 1.0.0.1; 2606:4700:4700::1111; 2606:4700:4700::1001
2019-01-13 14:51:30 +00:00
EOM
)
2018-01-20 13:55:48 +00:00
# Location for final installation log storage
2021-10-05 15:40:12 +00:00
installLogLoc = "/etc/pihole/install.log"
2017-07-07 00:25:56 +00:00
# This is a file used for the colorized output
2021-10-05 15:40:12 +00:00
coltable = "/opt/pihole/COL_TABLE"
2015-10-31 14:15:57 +00:00
2019-02-05 09:30:43 +00:00
# Root of the web server
webroot = "/var/www/html"
2021-03-18 01:35:27 +00:00
# We clone (or update) two git repositories during the install. This helps to make sure that we always have the latest versions of the relevant files.
2023-10-08 13:09:47 +00:00
# web is used to set up the Web admin interface.
2021-03-18 01:35:27 +00:00
# Pi-hole contains various setup scripts and files which are critical to the installation.
# Search for "PI_HOLE_LOCAL_REPO" in this file to see all such scripts.
# Two notable scripts are gravity.sh (used to generate the HOSTS file) and advanced/Scripts/webpage.sh (used to install the Web admin interface)
2023-10-08 13:09:47 +00:00
webInterfaceGitUrl = "https://github.com/pi-hole/web.git"
2019-02-05 09:30:43 +00:00
webInterfaceDir = " ${ webroot } /admin "
2016-01-24 03:31:12 +00:00
piholeGitUrl = "https://github.com/pi-hole/pi-hole.git"
2016-11-02 07:14:25 +00:00
PI_HOLE_LOCAL_REPO = "/etc/.pihole"
2021-03-18 01:35:27 +00:00
# List of pihole scripts, stored in an array
2023-10-12 11:44:51 +00:00
PI_HOLE_FILES = ( list piholeDebug piholeLogFlush setupLCD update version gravity uninstall webpage)
2018-07-27 16:35:39 +00:00
# This directory is where the Pi-hole scripts will be installed
2017-01-09 07:01:18 +00:00
PI_HOLE_INSTALL_DIR = "/opt/pihole"
2018-07-30 21:26:07 +00:00
PI_HOLE_CONFIG_DIR = "/etc/pihole"
2019-08-24 11:33:32 +00:00
PI_HOLE_BIN_DIR = "/usr/local/bin"
2020-11-16 22:15:02 +00:00
if [ -z " $useUpdateVars " ] ; then
2021-11-25 06:41:40 +00:00
useUpdateVars = false
2020-11-16 22:15:02 +00:00
fi
2016-01-23 00:13:16 +00:00
2018-04-17 08:50:25 +00:00
adlistFile = "/etc/pihole/adlists.list"
2021-03-18 01:35:27 +00:00
# Pi-hole needs an IP address; to begin, these variables are empty since we don't know what the IP is until this script can run
2020-07-15 22:38:08 +00:00
IPV4_ADDRESS = ${ IPV4_ADDRESS }
IPV6_ADDRESS = ${ IPV6_ADDRESS }
2021-03-18 01:35:27 +00:00
# Give settings their default values. These may be changed by prompts later in the script.
2016-11-01 16:46:54 +00:00
QUERY_LOGGING = true
2023-01-01 12:49:07 +00:00
WEBPORT = 8080
2018-08-20 23:04:58 +00:00
PRIVACY_LEVEL = 0
2017-01-28 14:38:54 +00:00
2018-06-01 08:20:40 +00:00
if [ -z " ${ USER } " ] ; then
2021-11-25 06:41:40 +00:00
USER = " $( id -un) "
2018-06-01 08:20:40 +00:00
fi
2017-01-28 14:38:54 +00:00
2022-07-02 19:36:16 +00:00
# dialog dimensions: Let dialog handle appropriate sizing.
Hardcode whiptail dimensions to 20 rows and 70 chars width
With the suggested way to call the installer via "curl -sSL https://install.pi-hole.net | bash", STDIN is no terminal, but overridden by the curl output, hence in most cases, the minimum dimensions were applied, even on larger screens. All whiptail calls are hence assured to work fine with those dimensions, aside of one case, making the calculations obsolete.
This commit hardcodes the whiptail dimensions to the prior minimum and removes the calculations. This also helps with testing, as it does not matter anymore how the script is called, and developers have a clearly defined space to make dialogs look nice, including line breaks, menu and list heights.
The only case which does not fit the 70 character width, the second menu entry of the "pihole -r" dialog, has been shortened accordingly. This was not an issue before, as "pihole -r" does not override the scripts STDIN and hence did allow larger dimensions based on the now removed calculations.
See the following discussions for reference:
- https://github.com/pi-hole/pi-hole/issues/3323
- https://github.com/pi-hole/pi-hole/pull/4197#issuecomment-876702380
Signed-off-by: MichaIng <micha@dietpi.com>
2021-07-16 17:58:49 +00:00
r = 20
c = 70
2015-10-28 22:29:34 +00:00
2016-10-15 19:52:20 +00:00
######## Undocumented Flags. Shhh ########
2017-07-07 00:25:56 +00:00
# These are undocumented flags; some of which we can use when repairing an installation
# The runUnattended flag is one example of this
2016-10-15 20:12:13 +00:00
reconfigure = false
2016-10-15 19:43:03 +00:00
runUnattended = false
2018-04-15 01:08:16 +00:00
# Check arguments for the undocumented flags
for var in " $@ " ; do
2018-07-06 04:48:36 +00:00
case " $var " in
2018-07-26 23:27:06 +00:00
"--reconfigure" ) reconfigure = true; ;
2018-07-06 04:48:36 +00:00
"--unattended" ) runUnattended = true; ;
esac
2018-04-15 01:08:16 +00:00
done
2016-10-15 19:43:03 +00:00
2017-07-07 00:25:56 +00:00
# If the color table file exists,
2017-07-26 17:00:08 +00:00
if [ [ -f " ${ coltable } " ] ] ; then
2018-07-06 04:48:36 +00:00
# source it
2019-05-10 14:13:23 +00:00
source " ${ coltable } "
2018-02-07 05:45:23 +00:00
# Otherwise,
2017-06-21 11:49:05 +00:00
else
2018-07-06 04:48:36 +00:00
# Set these values so the installer can still run in color
COL_NC = '\e[0m' # No Color
COL_LIGHT_GREEN = '\e[1;32m'
COL_LIGHT_RED = '\e[1;31m'
TICK = " [ ${ COL_LIGHT_GREEN } ✓ ${ COL_NC } ] "
CROSS = " [ ${ COL_LIGHT_RED } ✗ ${ COL_NC } ] "
INFO = "[i]"
# shellcheck disable=SC2034
DONE = " ${ COL_LIGHT_GREEN } done! ${ COL_NC } "
OVER = "\\r\\033[K"
2017-06-21 11:49:05 +00:00
fi
2017-07-07 00:25:56 +00:00
# A simple function that just echoes out our logo in ASCII format
# This lets users know that it is a Pi-hole, LLC product
2017-03-09 03:14:21 +00:00
show_ascii_berry( ) {
2021-11-25 06:41:40 +00:00
echo -e "
2017-06-21 11:49:05 +00:00
${ COL_LIGHT_GREEN } .; ; ,.
2017-03-09 03:14:21 +00:00
.ccccc:,.
:cccclll:. ..,,
:ccccclll. ; ooodc
' ccll:; ll .oooodc
.; cll.; ; looo:.
2017-06-21 11:49:05 +00:00
${ COL_LIGHT_RED } .. ',' .
2017-03-09 03:14:21 +00:00
.',,,,,,' .
.' ,,,,,,,,,,.
.' ,,,,,,,,,,,,....
....'' ',,,,,,,' .......
......... .... .........
.......... ..........
.......... ..........
......... .... .........
........,,,,,,,' ......
....' ,,,,,,,,,,,,.
.',,,,,,,,,' .
.',,,,,,' .
2017-06-21 11:49:05 +00:00
..'' ' .${ COL_NC }
2017-03-09 03:14:21 +00:00
"
}
2018-11-01 19:00:08 +00:00
is_command( ) {
2021-03-18 01:35:27 +00:00
# Checks to see if the given command (passed as a string argument) exists on the system.
# The function returns 0 (success) if the command exists, and 1 if it doesn't.
2018-11-01 19:00:08 +00:00
local check_command = " $1 "
command -v " ${ check_command } " >/dev/null 2>& 1
}
2020-05-25 16:40:20 +00:00
os_check( ) {
2020-07-21 17:47:13 +00:00
if [ " $PIHOLE_SKIP_OS_CHECK " != true ] ; then
# This function gets a list of supported OS versions from a TXT record at versions.pi-hole.net
# and determines whether or not the script is running on one of those systems
2020-08-23 09:48:15 +00:00
local remote_os_domain valid_os valid_version valid_response detected_os detected_version display_warning cmdResult digReturnCode response
2021-04-15 13:59:10 +00:00
remote_os_domain = ${ OS_CHECK_DOMAIN_NAME :- "versions.pi-hole.net" }
2020-07-21 17:47:13 +00:00
2021-12-02 13:44:50 +00:00
detected_os = $( grep '^ID=' /etc/os-release | cut -d '=' -f2 | tr -d '"' )
2020-08-14 18:42:54 +00:00
detected_version = $( grep VERSION_ID /etc/os-release | cut -d '=' -f2 | tr -d '"' )
2020-07-21 17:47:13 +00:00
2023-06-04 20:51:10 +00:00
# Test via IPv4
cmdResult = " $( dig -4 +short -t txt " ${ remote_os_domain } " @ns1.pi-hole.net 2>& 1; echo $? ) "
2021-03-18 01:35:27 +00:00
# Gets the return code of the previous command (last line)
2020-08-23 09:48:15 +00:00
digReturnCode = " ${ cmdResult ##* $'\n' } "
2020-07-21 17:47:13 +00:00
2020-08-23 09:48:15 +00:00
if [ ! " ${ digReturnCode } " = = "0" ] ; then
valid_response = false
2020-07-27 15:01:55 +00:00
else
2021-03-18 01:35:27 +00:00
# Dig returned 0 (success), so get the actual response, and loop through it to determine if the detected variables above are valid
2020-08-23 09:48:15 +00:00
response = " ${ cmdResult %% $'\n' * } "
2021-03-18 01:35:27 +00:00
# If the value of ${response} is a single 0, then this is the return code, not an actual response.
2020-08-23 09:48:15 +00:00
if [ " ${ response } " = = 0 ] ; then
valid_response = false
2023-06-04 20:51:10 +00:00
else
valid_response = true
2020-08-23 09:48:15 +00:00
fi
2023-06-04 20:51:10 +00:00
fi
# Try again via IPv6
if [ " $valid_response " = false ] ; then
unset valid_response
cmdResult = " $( dig -6 +short -t txt " ${ remote_os_domain } " @ns1.pi-hole.net 2>& 1; echo $? ) "
# Gets the return code of the previous command (last line)
digReturnCode = " ${ cmdResult ##* $'\n' } "
if [ ! " ${ digReturnCode } " = = "0" ] ; then
valid_response = false
else
# Dig returned 0 (success), so get the actual response, and loop through it to determine if the detected variables above are valid
response = " ${ cmdResult %% $'\n' * } "
# If the value of ${response} is a single 0, then this is the return code, not an actual response.
if [ " ${ response } " = = 0 ] ; then
valid_response = false
else
valid_response = true
fi
fi
fi
2020-08-23 09:48:15 +00:00
2023-06-04 20:51:10 +00:00
if [ " $valid_response " = true ] ; then
2020-08-23 09:48:15 +00:00
IFS = " " read -r -a supportedOS < <( echo " ${ response } " | tr -d '"' )
2020-08-14 21:37:58 +00:00
for distro_and_versions in " ${ supportedOS [@] } "
do
distro_part = " ${ distro_and_versions %%=* } "
versions_part = " ${ distro_and_versions ##*= } "
2022-07-02 13:00:17 +00:00
# If the distro part is a (case-insensitive) substring of the computer OS
2020-08-14 21:37:58 +00:00
if [ [ " ${ detected_os ^^ } " = ~ ${ distro_part ^^ } ] ] ; then
valid_os = true
IFS = "," read -r -a supportedVer <<< " ${ versions_part } "
for version in " ${ supportedVer [@] } "
do
if [ [ " ${ detected_version } " = ~ $version ] ] ; then
valid_version = true
break
fi
done
2020-07-27 15:01:55 +00:00
break
2020-08-14 21:37:58 +00:00
fi
2020-07-21 17:47:13 +00:00
done
2020-08-14 21:37:58 +00:00
fi
2020-05-25 16:40:20 +00:00
2023-06-04 20:51:10 +00:00
if [ " $valid_os " = true ] && [ " $valid_version " = true ] && [ " $valid_response " = true ] ; then
2020-07-21 17:47:13 +00:00
display_warning = false
fi
2020-05-25 16:40:20 +00:00
2020-08-14 18:42:54 +00:00
if [ " $display_warning " != false ] ; then
2020-08-23 09:48:15 +00:00
if [ " $valid_response " = false ] ; then
if [ " ${ digReturnCode } " -eq 0 ] ; then
2020-08-23 13:50:04 +00:00
errStr = "dig succeeded, but response was blank. Please contact support"
2020-08-23 09:48:15 +00:00
else
errStr = " dig failed with return code ${ digReturnCode } "
fi
printf " %b %bRetrieval of supported OS list failed. %s. %b\\n" " ${ CROSS } " " ${ COL_LIGHT_RED } " " ${ errStr } " " ${ COL_NC } "
printf " %bUnable to determine if the detected OS (%s %s) is supported%b\\n" " ${ COL_LIGHT_RED } " " ${ detected_os ^ } " " ${ detected_version } " " ${ COL_NC } "
2020-08-23 13:50:04 +00:00
printf " Possible causes for this include:\\n"
printf " - Firewall blocking certain DNS lookups from Pi-hole device\\n"
printf " - ns1.pi-hole.net being blocked (required to obtain TXT record from versions.pi-hole.net containing supported operating systems)\\n"
printf " - Other internet connectivity issues\\n"
2020-08-23 09:48:15 +00:00
else
printf " %b %bUnsupported OS detected: %s %s%b\\n" " ${ CROSS } " " ${ COL_LIGHT_RED } " " ${ detected_os ^ } " " ${ detected_version } " " ${ COL_NC } "
printf " If you are seeing this message and you do have a supported OS, please contact support.\\n"
fi
printf "\\n"
2022-07-02 13:00:17 +00:00
printf " %bhttps://docs.pi-hole.net/main/prerequisites/#supported-operating-systems%b\\n" " ${ COL_LIGHT_GREEN } " " ${ COL_NC } "
2020-08-23 09:48:15 +00:00
printf "\\n"
printf " If you wish to attempt to continue anyway, you can try one of the following commands to skip this check:\\n"
2020-07-21 17:47:13 +00:00
printf "\\n"
2020-07-22 21:30:51 +00:00
printf " e.g: If you are seeing this message on a fresh install, you can run:\\n"
2022-04-13 19:30:12 +00:00
printf " %bcurl -sSL https://install.pi-hole.net | sudo PIHOLE_SKIP_OS_CHECK=true bash%b\\n" " ${ COL_LIGHT_GREEN } " " ${ COL_NC } "
2020-07-22 21:29:38 +00:00
printf "\\n"
printf " If you are seeing this message after having run pihole -up:\\n"
2022-04-13 19:30:12 +00:00
printf " %bsudo PIHOLE_SKIP_OS_CHECK=true pihole -r%b\\n" " ${ COL_LIGHT_GREEN } " " ${ COL_NC } "
2020-07-22 21:29:38 +00:00
printf " (In this case, your previous run of pihole -up will have already updated the local repository)\\n"
printf "\\n"
2020-08-23 09:48:15 +00:00
printf " It is possible that the installation will still fail at this stage due to an unsupported configuration.\\n"
2020-07-21 17:47:13 +00:00
printf " If that is the case, you can feel free to ask the community on Discourse with the %bCommunity Help%b category:\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } "
2020-08-23 09:48:15 +00:00
printf " %bhttps://discourse.pi-hole.net/c/bugs-problems-issues/community-help/%b\\n" " ${ COL_LIGHT_GREEN } " " ${ COL_NC } "
printf "\\n"
2020-07-21 17:47:13 +00:00
exit 1
else
printf " %b %bSupported OS detected%b\\n" " ${ TICK } " " ${ COL_LIGHT_GREEN } " " ${ COL_NC } "
fi
2020-05-25 16:40:20 +00:00
else
2020-07-21 17:47:13 +00:00
printf " %b %bPIHOLE_SKIP_OS_CHECK env variable set to true - installer will continue%b\\n" " ${ INFO } " " ${ COL_LIGHT_GREEN } " " ${ COL_NC } "
2020-05-25 16:40:20 +00:00
fi
}
2022-04-04 14:38:30 +00:00
# This function waits for dpkg to unlock, which signals that the previous apt-get command has finished.
test_dpkg_lock( ) {
i = 0
2022-04-07 07:11:53 +00:00
printf " %b Waiting for package manager to finish (up to 30 seconds)\\n" " ${ INFO } "
2022-04-04 14:38:30 +00:00
# fuser is a program to show which processes use the named files, sockets, or filesystems
# So while the lock is held,
while fuser /var/lib/dpkg/lock >/dev/null 2>& 1
do
# we wait half a second,
sleep 0.5
# increase the iterator,
( ( i = i+1) )
# exit if waiting for more then 30 seconds
if [ [ $i -gt 60 ] ] ; then
2022-04-04 14:48:34 +00:00
printf " %b %bError: Could not verify package manager finished and released lock. %b\\n" " ${ CROSS } " " ${ COL_LIGHT_RED } " " ${ COL_NC } "
printf " Attempt to install packages manually and retry.\\n"
2022-04-04 14:38:30 +00:00
exit 1;
fi
done
# and then report success once dpkg is unlocked.
return 0
}
2016-08-19 21:31:11 +00:00
# Compatibility
2021-08-03 20:48:26 +00:00
package_manager_detect( ) {
2022-07-04 19:35:08 +00:00
# TODO - pull common packages for both distributions out into a common variable, then add
# the distro-specific ones below.
2021-11-25 06:41:40 +00:00
# First check to see if apt-get is installed.
if is_command apt-get ; then
# Set some global variables here
# We don't set them earlier since the installed package manager might be rpm, so these values would be different
PKG_MANAGER = "apt-get"
# A variable to store the command used to update the package cache
UPDATE_PKG_CACHE = " ${ PKG_MANAGER } update "
# The command we will use to actually install packages
PKG_INSTALL = ( " ${ PKG_MANAGER } " -qq --no-install-recommends install)
# grep -c will return 1 if there are no matches. This is an acceptable condition, so we OR TRUE to prevent set -e exiting the script.
PKG_COUNT = " ${ PKG_MANAGER } -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true "
# Update package cache
update_package_cache || exit 1
2023-10-22 06:32:52 +00:00
# Packages required to perform the os_check and FTL binary detection
2023-10-21 17:15:10 +00:00
OS_CHECK_DEPS = ( grep dnsutils binutils)
2023-10-22 06:32:52 +00:00
# Packages required to run this install script
2023-10-21 17:15:10 +00:00
INSTALLER_DEPS = ( git iproute2 dialog ca-certificates)
2023-10-22 06:32:52 +00:00
# Packages required to run Pi-hole
2023-10-31 20:02:26 +00:00
PIHOLE_DEPS = ( cron curl iputils-ping psmisc sudo unzip libcap2-bin dns-root-data libcap2 netcat-openbsd procps jq)
2021-11-25 06:41:40 +00:00
# If apt-get is not found, check for rpm.
elif is_command rpm ; then
# Then check if dnf or yum is the package manager
if is_command dnf ; then
PKG_MANAGER = "dnf"
else
PKG_MANAGER = "yum"
fi
2017-03-03 10:28:35 +00:00
2021-11-25 06:41:40 +00:00
# These variable names match the ones for apt-get. See above for an explanation of what they are for.
PKG_INSTALL = ( " ${ PKG_MANAGER } " install -y)
2022-07-04 21:00:16 +00:00
# CentOS package manager returns 100 when there are packages to update so we need to || true to prevent the script from exiting.
2023-03-05 18:02:09 +00:00
PKG_COUNT = " ${ PKG_MANAGER } check-update | grep -E '(.i686|.x86|.noarch|.arm|.src|.riscv64)' | wc -l || true "
2021-11-25 06:41:40 +00:00
OS_CHECK_DEPS = ( grep bind-utils)
2023-06-09 17:30:28 +00:00
INSTALLER_DEPS = ( git dialog iproute newt procps-ng chkconfig ca-certificates binutils)
2023-10-31 20:02:26 +00:00
PIHOLE_DEPS = ( cronie curl findutils sudo unzip psmisc libcap nmap-ncat jq)
2022-07-30 18:18:33 +00:00
2021-11-25 06:41:40 +00:00
# If neither apt-get or yum/dnf package managers were found
2018-05-01 06:28:55 +00:00
else
2021-11-25 06:41:40 +00:00
# we cannot install required packages
printf " %b No supported package manager found\\n" " ${ CROSS } "
# so exit the installer
exit
2018-07-06 04:48:36 +00:00
fi
2017-01-21 20:34:47 +00:00
}
2015-11-08 23:21:02 +00:00
2018-07-27 16:35:39 +00:00
# A function for checking if a directory is a git repository
2016-11-02 07:14:25 +00:00
is_repo( ) {
2018-07-06 04:48:36 +00:00
# Use a named, local variable instead of the vague $1, which is the first argument passed to this function
# These local variables should always be lowercase
local directory = " ${ 1 } "
# A variable to store the return code
local rc
# If the first argument passed to this function is a directory,
if [ [ -d " ${ directory } " ] ] ; then
# move into the directory
2019-11-08 19:11:55 +00:00
pushd " ${ directory } " & > /dev/null || return 1
2018-07-27 16:35:39 +00:00
# Use git to check if the directory is a repo
2018-07-06 04:48:36 +00:00
# git -C is not used here to support git versions older than 1.8.4
git status --short & > /dev/null || rc = $?
# If the command was not successful,
else
# Set a non-zero return code if directory does not exist
rc = 1
fi
# Move back into the directory the user started in
2019-11-08 19:11:55 +00:00
popd & > /dev/null || return 1
2018-07-06 04:48:36 +00:00
# Return the code; if one is not set, return 0
return " ${ rc :- 0 } "
2016-11-02 07:14:25 +00:00
}
2017-07-07 00:25:56 +00:00
# A function to clone a repo
2016-11-02 07:14:25 +00:00
make_repo( ) {
2018-07-06 04:48:36 +00:00
# Set named variables for better readability
local directory = " ${ 1 } "
local remoteRepo = " ${ 2 } "
2019-10-28 22:35:01 +00:00
2018-07-06 04:48:36 +00:00
# The message to display when this function is running
str = " Clone ${ remoteRepo } into ${ directory } "
# Display the message and use the color table to preface the message with an "info" indicator
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# If the directory exists,
if [ [ -d " ${ directory } " ] ] ; then
2020-12-02 20:19:59 +00:00
# Return with a 1 to exit the installer. We don't want to overwrite what could already be here in case it is not ours
2020-12-02 20:49:07 +00:00
str = " Unable to clone ${ remoteRepo } into ${ directory } : Directory already exists "
2020-12-02 20:35:40 +00:00
printf "%b %b%s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
2020-12-02 20:19:59 +00:00
return 1
2018-07-06 04:48:36 +00:00
fi
# Clone the repo and return the return code from this command
2019-05-07 17:42:11 +00:00
git clone -q --depth 20 " ${ remoteRepo } " " ${ directory } " & > /dev/null || return $?
2019-10-28 22:35:01 +00:00
# Move into the directory that was passed as an argument
2019-11-08 19:11:55 +00:00
pushd " ${ directory } " & > /dev/null || return 1
2020-03-08 23:53:14 +00:00
# Check current branch. If it is master, then reset to the latest available tag.
2020-05-11 21:03:33 +00:00
# In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks)
2019-11-08 19:18:35 +00:00
curBranch = $( git rev-parse --abbrev-ref HEAD)
2021-03-18 01:35:27 +00:00
if [ [ " ${ curBranch } " = = "master" ] ] ; then
# If we're calling make_repo() then it should always be master, we may not need to check.
git reset --hard " $( git describe --abbrev= 0 --tags) " || return $?
2019-10-28 22:35:01 +00:00
fi
2018-07-06 04:48:36 +00:00
# Show a colored message showing it's status
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2020-02-14 19:41:43 +00:00
# Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git)
chmod -R a+rX " ${ directory } "
2019-10-28 22:35:01 +00:00
# Move back into the original directory
2019-11-08 19:11:55 +00:00
popd & > /dev/null || return 1
2018-07-06 04:48:36 +00:00
return 0
2016-11-02 07:14:25 +00:00
}
2017-07-07 00:25:56 +00:00
# We need to make sure the repos are up-to-date so we can effectively install Clean out the directory if it exists for git to clone into
2016-11-02 07:14:25 +00:00
update_repo( ) {
2018-07-06 04:48:36 +00:00
# Use named, local variables
# As you can see, these are the same variable names used in the last function,
# but since they are local, their scope does not go beyond this function
# This helps prevent the wrong value from being assigned if you were to set the variable as a GLOBAL one
local directory = " ${ 1 } "
2019-10-28 22:35:01 +00:00
local curBranch
2018-07-06 04:48:36 +00:00
# A variable to store the message we want to display;
# Again, it's useful to store these in variables in case we need to reuse or change the message;
# we only need to make one change here
local str = " Update repo in ${ 1 } "
2020-02-16 11:47:42 +00:00
# Move into the directory that was passed as an argument
2019-11-08 19:11:55 +00:00
pushd " ${ directory } " & > /dev/null || return 1
2018-07-06 04:48:36 +00:00
# Let the user know what's happening
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Stash any local commits as they conflict with our working code
git stash --all --quiet & > /dev/null || true # Okay for stash failure
git clean --quiet --force -d || true # Okay for already clean directory
# Pull the latest commits
2021-10-06 00:19:28 +00:00
git pull --no-rebase --quiet & > /dev/null || return $?
2020-03-08 23:53:14 +00:00
# Check current branch. If it is master, then reset to the latest available tag.
2020-05-11 21:03:33 +00:00
# In case extra commits have been added after tagging/release (i.e in case of metadata updates/README.MD tweaks)
2019-11-08 19:18:35 +00:00
curBranch = $( git rev-parse --abbrev-ref HEAD)
2019-10-28 22:35:01 +00:00
if [ [ " ${ curBranch } " = = "master" ] ] ; then
2021-11-25 06:41:40 +00:00
git reset --hard " $( git describe --abbrev= 0 --tags) " || return $?
2019-10-28 22:35:01 +00:00
fi
2018-07-06 04:48:36 +00:00
# Show a completion message
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2019-05-03 10:27:56 +00:00
# Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git)
2019-05-07 08:46:16 +00:00
chmod -R a+rX " ${ directory } "
2018-07-06 04:48:36 +00:00
# Move back into the original directory
2019-11-08 19:11:55 +00:00
popd & > /dev/null || return 1
2018-07-06 04:48:36 +00:00
return 0
2016-11-02 07:14:25 +00:00
}
2021-03-18 01:35:27 +00:00
# A function that combines the previous git functions to update or clone a repo
2016-11-02 07:14:25 +00:00
getGitFiles( ) {
2018-07-06 04:48:36 +00:00
# Setup named variables for the git repos
# We need the directory
local directory = " ${ 1 } "
# as well as the repo URL
local remoteRepo = " ${ 2 } "
# A local variable containing the message to be displayed
local str = " Check for existing repository in ${ 1 } "
# Show the message
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Check if the directory is a repository
if is_repo " ${ directory } " ; then
# Show that we're checking it
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Update the repo, returning an error message on failure
2018-10-31 18:14:05 +00:00
update_repo " ${ directory } " || { printf "\\n %b: Could not update local repository. Contact support.%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } " ; exit 1; }
2018-07-06 04:48:36 +00:00
# If it's not a .git repo,
else
# Show an error
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Attempt to make the repository, showing an error on failure
2018-10-31 18:14:05 +00:00
make_repo " ${ directory } " " ${ remoteRepo } " || { printf "\\n %bError: Could not update local repository. Contact support.%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } " ; exit 1; }
2018-07-06 04:48:36 +00:00
fi
echo ""
2021-03-18 01:35:27 +00:00
# Success via one of the two branches, as the commands would exit if they failed.
2018-07-06 04:48:36 +00:00
return 0
2016-11-02 07:14:25 +00:00
}
2017-07-07 00:25:56 +00:00
# Reset a repo to get rid of any local changed
2017-05-22 21:43:52 +00:00
resetRepo( ) {
2018-07-06 04:48:36 +00:00
# Use named variables for arguments
local directory = " ${ 1 } "
# Move into the directory
2019-11-08 19:11:55 +00:00
pushd " ${ directory } " & > /dev/null || return 1
2018-07-06 04:48:36 +00:00
# Store the message in a variable
str = " Resetting repository within ${ 1 } ... "
# Show the message
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Use git to remove the local changes
git reset --hard & > /dev/null || return $?
2019-05-03 10:27:56 +00:00
# Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git)
2019-05-07 08:46:16 +00:00
chmod -R a+rX " ${ directory } "
2018-07-06 04:48:36 +00:00
# And show the status
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2019-11-08 19:11:55 +00:00
# Return to where we came from
popd & > /dev/null || return 1
2021-03-18 01:35:27 +00:00
# Function succeeded, as "git reset" would have triggered a return earlier if it failed
2018-07-06 04:48:36 +00:00
return 0
2016-11-02 07:14:25 +00:00
}
2016-10-10 12:45:37 +00:00
find_IPv4_information( ) {
2018-11-03 20:20:40 +00:00
# Detects IPv4 address used for communication to WAN addresses.
# Accepts no arguments, returns no values.
2018-07-06 04:48:36 +00:00
# Named, local variables
local route
2018-11-03 20:20:40 +00:00
local IPv4bare
2018-07-06 04:48:36 +00:00
# Find IP used to route to outside world by checking the the route to Google's public DNS server
route = $( ip route get 8.8.8.8)
2018-11-03 20:20:40 +00:00
# Get just the interface IPv4 address
2018-11-03 20:39:43 +00:00
# shellcheck disable=SC2059,SC2086
# disabled as we intentionally want to split on whitespace and have printf populate
# the variable with just the first field.
2018-11-03 20:20:40 +00:00
printf -v IPv4bare " $( printf ${ route #*src } ) "
if ! valid_ip " ${ IPv4bare } " ; then
IPv4bare = "127.0.0.1"
fi
# Append the CIDR notation to the IP address, if valid_ip fails this should return 127.0.0.1/8
2019-04-27 19:39:45 +00:00
IPV4_ADDRESS = $( ip -oneline -family inet address show | grep " ${ IPv4bare } / " | awk '{print $4}' | awk 'END {print}' )
2016-05-01 02:27:38 +00:00
}
2017-07-07 00:25:56 +00:00
# Get available interfaces that are UP
2016-10-10 10:16:22 +00:00
get_available_interfaces( ) {
2018-07-06 04:48:36 +00:00
# There may be more than one so it's all stored in a variable
availableInterfaces = $( ip --oneline link show up | grep -v "lo" | awk '{print $2}' | cut -d':' -f1 | cut -d'@' -f1)
2016-10-10 10:16:22 +00:00
}
2015-11-10 00:33:32 +00:00
2017-07-07 00:25:56 +00:00
# A function for displaying the dialogs the user sees when first running the installer
2016-01-27 06:11:38 +00:00
welcomeDialogs( ) {
2018-07-06 04:48:36 +00:00
# Display the welcome dialog using an appropriately sized window via the calculation conducted earlier in the script
2022-07-04 21:00:16 +00:00
dialog --no-shadow --clear --keep-tite \
2022-06-19 00:17:10 +00:00
--backtitle "Welcome" \
--title "Pi-hole Automated Installer" \
--msgbox "\\n\\nThis installer will transform your device into a network-wide ad blocker!" \
" ${ r } " " ${ c } " \
2022-07-04 21:00:16 +00:00
--and-widget --clear \
2022-06-19 00:17:10 +00:00
--backtitle "Support Pi-hole" \
--title "Open Source Software" \
--msgbox "\\n\\nThe Pi-hole is free, but powered by your donations: https://pi-hole.net/donate/" \
" ${ r } " " ${ c } " \
2022-07-04 21:00:16 +00:00
--and-widget --clear \
2022-06-19 00:17:10 +00:00
--colors \
--backtitle "Initiating network interface" \
--title "Static IP Needed" \
--no-button "Exit" --yes-button "Continue" \
--defaultno \
2022-07-02 19:36:16 +00:00
--yesno " \\n\\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly.\\n\\n\
\\ Zb\\ Z1IMPORTANT:\\ Zn If you have not already done so, you must ensure that this device has a static IP.\\ n\\ n\
Depending on your operating system, there are many ways to achieve this, through DHCP reservation, or by manually assigning one.\\ n\\ n\
Please continue when the static addressing has been configured." \
2022-07-04 21:00:16 +00:00
" ${ r } " " ${ c } " && result = 0 || result = " $? "
2022-06-19 00:17:10 +00:00
case " ${ result } " in
" ${ DIALOG_CANCEL } " | " ${ DIALOG_ESC } " )
printf " %b Installer exited at static IP message.\\n" " ${ INFO } "
exit 1
; ;
esac
2015-11-08 23:21:02 +00:00
}
2021-03-18 01:35:27 +00:00
# A function that lets the user pick an interface to use with Pi-hole
2016-01-27 06:11:38 +00:00
chooseInterface( ) {
2022-06-19 00:17:10 +00:00
# Turn the available interfaces into a string so it can be used with dialog
local interfacesList
2018-07-06 04:48:36 +00:00
# Number of available interfaces
local interfaceCount
2022-06-19 00:17:10 +00:00
# POSIX compliant way to get the number of elements in an array
interfaceCount = $( printf "%s\n" " ${ availableInterfaces } " | wc -l)
2018-07-06 04:48:36 +00:00
# If there is one interface,
if [ [ " ${ interfaceCount } " -eq 1 ] ] ; then
# Set it as the interface to use since there is no other option
PIHOLE_INTERFACE = " ${ availableInterfaces } "
# Otherwise,
else
2022-06-19 00:17:10 +00:00
# Set status for the first entry to be selected
status = "ON"
2018-07-06 04:48:36 +00:00
# While reading through the available interfaces
2022-06-19 00:17:10 +00:00
for interface in ${ availableInterfaces } ; do
# Put all these interfaces into a string
interfacesList = " ${ interfacesList } ${ interface } available ${ status } "
# All further interfaces are deselected
status = "OFF"
2018-07-06 04:48:36 +00:00
done
2022-06-19 00:17:10 +00:00
# shellcheck disable=SC2086
# Disable check for double quote here as we are passing a string with spaces
2022-07-04 21:00:16 +00:00
PIHOLE_INTERFACE = $( dialog --no-shadow --keep-tite --output-fd 1 \
2022-07-05 21:23:59 +00:00
--cancel-label "Exit" --ok-label "Select" \
2022-06-19 00:17:10 +00:00
--radiolist "Choose An Interface (press space to toggle selection)" \
${ r } ${ c } " ${ interfaceCount } " ${ interfacesList } )
result = $?
case ${ result } in
" ${ DIALOG_CANCEL } " | " ${ DIALOG_ESC } " )
# Show an error message and exit
printf " %b %s\\n" " ${ CROSS } " "No interface selected, exiting installer"
exit 1
; ;
esac
printf " %b Using interface: %s\\n" " ${ INFO } " " ${ PIHOLE_INTERFACE } "
2018-07-06 04:48:36 +00:00
fi
2016-10-10 12:45:37 +00:00
}
2016-03-06 05:16:23 +00:00
2017-07-07 00:25:56 +00:00
# This lets us prefer ULA addresses over GUA
# This caused problems for some users when their ISP changed their IPv6 addresses
2017-06-02 21:01:48 +00:00
# See https://github.com/pi-hole/pi-hole/issues/1473#issuecomment-301745953
testIPv6( ) {
2018-07-06 04:48:36 +00:00
# first will contain fda2 (ULA)
2018-11-08 19:10:09 +00:00
printf -v first "%s" " ${ 1 %% : * } "
2021-03-18 01:35:27 +00:00
# value1 will contain 253 which is the decimal value corresponding to 0xFD
2018-07-06 04:48:36 +00:00
value1 = $(( ( 0 x$first ) / 256 ))
2021-03-18 01:35:27 +00:00
# value2 will contain 162 which is the decimal value corresponding to 0xA2
2018-07-06 04:48:36 +00:00
value2 = $(( ( 0 x$first ) % 256 ))
# the ULA test is testing for fc00::/7 according to RFC 4193
if ( ( ( value1& 254) = = 252 ) ) ; then
2018-10-31 18:14:05 +00:00
# echoing result to calling function as return value
2018-07-06 04:48:36 +00:00
echo "ULA"
fi
# the GUA test is testing for 2000::/3 according to RFC 4291
if ( ( ( value1& 112) = = 32 ) ) ; then
2018-10-31 18:14:05 +00:00
# echoing result to calling function as return value
2018-07-06 04:48:36 +00:00
echo "GUA"
fi
# the LL test is testing for fe80::/10 according to RFC 4193
if ( ( ( value1) = = 254 ) ) && ( ( ( value2& 192) = = 128 ) ) ; then
2018-10-31 18:14:05 +00:00
# echoing result to calling function as return value
2018-07-06 04:48:36 +00:00
echo "Link-local"
fi
2017-06-02 21:01:48 +00:00
}
2021-10-02 21:29:23 +00:00
find_IPv6_information( ) {
# Detects IPv6 address used for communication to WAN addresses.
2022-07-15 18:40:11 +00:00
mapfile -t IPV6_ADDRESSES <<< " $( ip -6 address | grep 'scope global' | awk '{print $2}' ) "
2018-07-06 04:48:36 +00:00
# For each address in the array above, determine the type of IPv6 address it is
for i in " ${ IPV6_ADDRESSES [@] } " ; do
# Check if it's ULA, GUA, or LL by using the function created earlier
result = $( testIPv6 " $i " )
# If it's a ULA address, use it and store it as a global variable
[ [ " ${ result } " = = "ULA" ] ] && ULA_ADDRESS = " ${ i %/* } "
2021-03-18 01:35:27 +00:00
# If it's a GUA address, use it and store it as a global variable
2018-07-06 04:48:36 +00:00
[ [ " ${ result } " = = "GUA" ] ] && GUA_ADDRESS = " ${ i %/* } "
2021-03-18 01:35:27 +00:00
# Else if it's a Link-local address, we cannot use it, so just continue
2018-07-06 04:48:36 +00:00
done
# Determine which address to be used: Prefer ULA over GUA or don't use any if none found
# If the ULA_ADDRESS contains a value,
2022-07-15 18:40:11 +00:00
if [ [ -n " ${ ULA_ADDRESS } " ] ] ; then
2018-07-06 04:48:36 +00:00
# set the IPv6 address to the ULA address
IPV6_ADDRESS = " ${ ULA_ADDRESS } "
# Show this info to the user
2021-10-02 21:29:23 +00:00
printf " %b Found IPv6 ULA address\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
# Otherwise, if the GUA_ADDRESS has a value,
2022-07-15 18:40:11 +00:00
elif [ [ -n " ${ GUA_ADDRESS } " ] ] ; then
2018-07-06 04:48:36 +00:00
# Let the user know
2021-10-02 21:29:23 +00:00
printf " %b Found IPv6 GUA address\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
# And assign it to the global variable
IPV6_ADDRESS = " ${ GUA_ADDRESS } "
# If none of those work,
else
2021-10-02 21:29:23 +00:00
printf " %b Unable to find IPv6 ULA/GUA address\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
# So set the variable to be empty
IPV6_ADDRESS = ""
fi
2015-11-10 00:33:32 +00:00
}
2021-10-02 21:29:23 +00:00
# A function to collect IPv4 and IPv6 information of the device
collect_v4andv6_information( ) {
find_IPv4_information
printf " %b IPv4 address: %s\\n" " ${ INFO } " " ${ IPV4_ADDRESS } "
find_IPv6_information
2018-10-31 18:14:05 +00:00
printf " %b IPv6 address: %s\\n" " ${ INFO } " " ${ IPV6_ADDRESS } "
2015-11-10 00:33:32 +00:00
}
2015-11-08 23:21:02 +00:00
2017-07-07 00:25:56 +00:00
# Check an IP address to see if it is a valid one
2016-10-20 02:47:45 +00:00
valid_ip( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
local ip = ${ 1 }
local stat = 1
2021-03-18 01:35:27 +00:00
# Regex matching one IPv4 component, i.e. an integer from 0 to 255.
2021-03-18 01:09:03 +00:00
# See https://tools.ietf.org/html/rfc1340
2020-06-15 21:52:24 +00:00
local ipv4elem = "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)" ;
2021-04-14 20:50:04 +00:00
# Regex matching an optional port (starting with '#') range of 1-65536
local portelem = "(#(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}|0))?" ;
2021-03-18 01:35:27 +00:00
# Build a full IPv4 regex from the above subexpressions
2021-12-02 13:44:50 +00:00
local regex = " ^ ${ ipv4elem } \\. ${ ipv4elem } \\. ${ ipv4elem } \\. ${ ipv4elem } ${ portelem } $"
2020-06-13 19:30:03 +00:00
2021-03-18 01:35:27 +00:00
# Evaluate the regex, and return the result
2020-06-15 21:52:24 +00:00
[ [ $ip = ~ ${ regex } ] ]
stat = $?
2019-05-10 14:13:23 +00:00
return " ${ stat } "
2016-02-20 17:33:20 +00:00
}
2020-06-23 19:38:18 +00:00
valid_ip6( ) {
local ip = ${ 1 }
local stat = 1
2021-03-18 01:35:27 +00:00
# Regex matching one IPv6 element, i.e. a hex value from 0000 to FFFF
2020-06-23 19:38:18 +00:00
local ipv6elem = "[0-9a-fA-F]{1,4}"
2021-03-18 01:35:27 +00:00
# Regex matching an IPv6 CIDR, i.e. 1 to 128
2020-06-23 19:38:18 +00:00
local v6cidr = "(\\/([1-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8])){0,1}"
2021-04-14 20:50:04 +00:00
# Regex matching an optional port (starting with '#') range of 1-65536
local portelem = "(#(6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}|0))?" ;
2021-03-18 01:35:27 +00:00
# Build a full IPv6 regex from the above subexpressions
2020-08-04 20:11:32 +00:00
local regex = " ^((( ${ ipv6elem } ))*((: ${ ipv6elem } ))*::(( ${ ipv6elem } ))*((: ${ ipv6elem } ))*|(( ${ ipv6elem } ))((: ${ ipv6elem } )){7}) ${ v6cidr } ${ portelem } $"
2020-06-23 19:38:18 +00:00
2021-03-18 01:35:27 +00:00
# Evaluate the regex, and return the result
2020-06-23 19:38:18 +00:00
[ [ ${ ip } = ~ ${ regex } ] ]
stat = $?
return " ${ stat } "
}
2017-07-07 00:25:56 +00:00
# A function to choose the upstream DNS provider(s)
2016-10-20 02:47:45 +00:00
setDNS( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
local DNSSettingsCorrect
# In an array, list the available upstream providers
2019-01-13 14:51:30 +00:00
DNSChooseOptions = ( )
local DNSServerCount = 0
2021-03-18 01:35:27 +00:00
# Save the old Internal Field Separator in a variable,
2019-01-13 14:51:30 +00:00
OIFS = $IFS
# and set the new one to newline
IFS = $'\n'
# Put the DNS Servers into an array
for DNSServer in ${ DNS_SERVERS }
do
DNSName = " $( cut -d';' -f1 <<< " ${ DNSServer } " ) "
DNSChooseOptions[ DNSServerCount] = " ${ DNSName } "
( ( DNSServerCount = DNSServerCount+1 ) )
DNSChooseOptions[ DNSServerCount] = ""
( ( DNSServerCount = DNSServerCount+1 ) )
done
DNSChooseOptions[ DNSServerCount] = "Custom"
( ( DNSServerCount = DNSServerCount+1 ) )
DNSChooseOptions[ DNSServerCount] = ""
# Restore the IFS to what it was
IFS = ${ OIFS }
2022-06-19 00:17:10 +00:00
# In a dialog, show the options
2022-07-04 21:00:16 +00:00
DNSchoices = $( dialog --no-shadow --keep-tite --output-fd 1 \
2022-07-05 21:23:59 +00:00
--cancel-label "Exit" \
2022-06-19 00:17:10 +00:00
--menu "Select Upstream DNS Provider. To use your own, select Custom." " ${ r } " " ${ c } " 7 \
" ${ DNSChooseOptions [@] } " )
result = $?
case ${ result } in
" ${ DIALOG_CANCEL } " | " ${ DIALOG_ESC } " )
2022-07-06 10:29:03 +00:00
printf " %b Cancel was selected, exiting installer%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } "
2022-06-19 00:17:10 +00:00
exit 1
; ;
esac
2017-06-21 11:49:05 +00:00
2021-03-18 01:35:27 +00:00
# Depending on the user's choice, set the GLOBAL variables to the IP of the respective provider
2019-01-13 14:51:30 +00:00
if [ [ " ${ DNSchoices } " = = "Custom" ] ]
then
2021-03-18 01:35:27 +00:00
# Loop until we have a valid DNS setting
2019-01-13 14:51:30 +00:00
until [ [ " ${ DNSSettingsCorrect } " = True ] ] ; do
2021-03-18 01:35:27 +00:00
# Signal value, to be used if the user inputs an invalid IP address
2019-01-13 14:51:30 +00:00
strInvalid = "Invalid"
if [ [ ! " ${ PIHOLE_DNS_1 } " ] ] ; then
if [ [ ! " ${ PIHOLE_DNS_2 } " ] ] ; then
2021-03-18 01:35:27 +00:00
# If the first and second upstream servers do not exist, do not prepopulate an IP address
2019-01-13 14:51:30 +00:00
prePopulate = ""
else
2022-06-19 00:17:10 +00:00
# Otherwise, prepopulate the dialogue with the appropriate DNS value(s)
2019-01-13 14:51:30 +00:00
prePopulate = " , ${ PIHOLE_DNS_2 } "
2018-07-06 04:48:36 +00:00
fi
2019-01-13 14:51:30 +00:00
elif [ [ " ${ PIHOLE_DNS_1 } " ] ] && [ [ ! " ${ PIHOLE_DNS_2 } " ] ] ; then
prePopulate = " ${ PIHOLE_DNS_1 } "
elif [ [ " ${ PIHOLE_DNS_1 } " ] ] && [ [ " ${ PIHOLE_DNS_2 } " ] ] ; then
prePopulate = " ${ PIHOLE_DNS_1 } , ${ PIHOLE_DNS_2 } "
fi
2018-07-06 04:48:36 +00:00
2021-03-18 01:35:27 +00:00
# Prompt the user to enter custom upstream servers
2022-07-04 21:00:16 +00:00
piholeDNS = $( dialog --no-shadow --keep-tite --output-fd 1 \
2022-07-05 21:23:59 +00:00
--cancel-label "Exit" \
2022-06-19 00:17:10 +00:00
--backtitle "Specify Upstream DNS Provider(s)" \
2022-07-02 19:36:16 +00:00
--inputbox " Enter your desired upstream DNS provider(s), separated by a comma.\
If you want to specify a port other than 53, separate it with a hash.\
\\ n\\ nFor example '8.8.8.8, 8.8.4.4' or '127.0.0.1#5335' " \
2022-06-19 00:17:10 +00:00
" ${ r } " " ${ c } " " ${ prePopulate } " )
result = $?
case ${ result } in
" ${ DIALOG_CANCEL } " | " ${ DIALOG_ESC } " )
2022-07-06 10:29:03 +00:00
printf " %b Cancel was selected, exiting installer%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } "
2022-06-19 00:17:10 +00:00
exit 1
; ;
esac
2019-01-13 14:51:30 +00:00
# Clean user input and replace whitespace with comma.
piholeDNS = $( sed 's/[, \t]\+/,/g' <<< " ${ piholeDNS } " )
2018-10-31 18:14:05 +00:00
2021-03-18 01:35:27 +00:00
# Separate the user input into the two DNS values (separated by a comma)
2019-01-13 14:51:30 +00:00
printf -v PIHOLE_DNS_1 "%s" " ${ piholeDNS %%,* } "
printf -v PIHOLE_DNS_2 "%s" " ${ piholeDNS ##*, } "
2018-10-31 18:14:05 +00:00
2021-03-18 01:35:27 +00:00
# If the first DNS value is invalid or empty, this if statement will be true and we will set PIHOLE_DNS_1="Invalid"
2019-01-13 14:51:30 +00:00
if ! valid_ip " ${ PIHOLE_DNS_1 } " || [ [ ! " ${ PIHOLE_DNS_1 } " ] ] ; then
PIHOLE_DNS_1 = ${ strInvalid }
fi
2021-03-18 01:35:27 +00:00
# If the second DNS value is invalid or empty, this if statement will be true and we will set PIHOLE_DNS_2="Invalid"
2019-01-13 14:51:30 +00:00
if ! valid_ip " ${ PIHOLE_DNS_2 } " && [ [ " ${ PIHOLE_DNS_2 } " ] ] ; then
PIHOLE_DNS_2 = ${ strInvalid }
fi
# If either of the DNS servers are invalid,
if [ [ " ${ PIHOLE_DNS_1 } " = = " ${ strInvalid } " ] ] || [ [ " ${ PIHOLE_DNS_2 } " = = " ${ strInvalid } " ] ] ; then
2021-03-18 01:35:27 +00:00
# explain this to the user,
2022-07-04 21:00:16 +00:00
dialog --no-shadow --keep-tite \
2022-06-19 00:17:10 +00:00
--title "Invalid IP Address(es)" \
--backtitle "Invalid IP" \
2022-07-02 19:36:16 +00:00
--msgbox " \\nOne or both of the entered IP addresses were invalid. Please try again.\
\\ n\\ nInvalid IPs: ${ PIHOLE_DNS_1 } , ${ PIHOLE_DNS_2 } " \
2022-07-05 21:23:59 +00:00
" ${ r } " " ${ c } "
2022-06-19 00:17:10 +00:00
2021-03-18 01:35:27 +00:00
# set the variables back to nothing,
2019-01-13 14:51:30 +00:00
if [ [ " ${ PIHOLE_DNS_1 } " = = " ${ strInvalid } " ] ] ; then
PIHOLE_DNS_1 = ""
2018-07-06 04:48:36 +00:00
fi
2019-01-13 14:51:30 +00:00
if [ [ " ${ PIHOLE_DNS_2 } " = = " ${ strInvalid } " ] ] ; then
PIHOLE_DNS_2 = ""
2018-07-06 04:48:36 +00:00
fi
2021-03-18 01:35:27 +00:00
# and continue the loop.
2019-11-07 12:59:44 +00:00
DNSSettingsCorrect = False
2019-01-13 14:51:30 +00:00
else
2022-09-22 12:49:25 +00:00
dialog --no-shadow --no-collapse --keep-tite \
2022-06-19 00:17:10 +00:00
--backtitle "Specify Upstream DNS Provider(s)" \
--title "Upstream DNS Provider(s)" \
2022-09-22 12:49:25 +00:00
--yesno "Are these settings correct?\\n" $'\t' "DNS Server 1:" $'\t' " ${ PIHOLE_DNS_1 } \\n " $'\t' "DNS Server 2:" $'\t' " ${ PIHOLE_DNS_2 } " \
2022-07-04 21:00:16 +00:00
" ${ r } " " ${ c } " && result = 0 || result = $?
2022-06-19 00:17:10 +00:00
case ${ result } in
" ${ DIALOG_OK } " )
DNSSettingsCorrect = True
; ;
" ${ DIALOG_CANCEL } " )
DNSSettingsCorrect = False
; ;
" ${ DIALOG_ESC } " )
2022-07-06 03:25:27 +00:00
printf " %b Escape pressed, exiting installer at DNS Settings%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } "
2022-06-19 00:17:10 +00:00
exit 1
; ;
esac
2019-01-13 14:51:30 +00:00
fi
done
2019-11-07 12:59:44 +00:00
else
2021-03-18 01:35:27 +00:00
# Save the old Internal Field Separator in a variable,
2019-01-13 14:51:30 +00:00
OIFS = $IFS
# and set the new one to newline
IFS = $'\n'
for DNSServer in ${ DNS_SERVERS }
do
DNSName = " $( cut -d';' -f1 <<< " ${ DNSServer } " ) "
if [ [ " ${ DNSchoices } " = = " ${ DNSName } " ] ]
then
PIHOLE_DNS_1 = " $( cut -d';' -f2 <<< " ${ DNSServer } " ) "
PIHOLE_DNS_2 = " $( cut -d';' -f3 <<< " ${ DNSServer } " ) "
break
fi
done
# Restore the IFS to what it was
IFS = ${ OIFS }
fi
2019-11-07 12:59:44 +00:00
# Display final selection
2019-12-04 17:59:25 +00:00
local DNSIP = ${ PIHOLE_DNS_1 }
[ [ -z ${ PIHOLE_DNS_2 } ] ] || DNSIP += " , ${ PIHOLE_DNS_2 } "
printf " %b Using upstream DNS: %s (%s)\\n" " ${ INFO } " " ${ DNSchoices } " " ${ DNSIP } "
2016-01-25 05:11:00 +00:00
}
2017-07-07 00:25:56 +00:00
# Allow the user to enable/disable logging
2016-10-31 21:38:48 +00:00
setLogging( ) {
2022-06-19 00:17:10 +00:00
# Ask the user if they want to enable logging
2022-07-04 21:00:16 +00:00
dialog --no-shadow --keep-tite \
2022-06-19 00:17:10 +00:00
--backtitle "Pihole Installation" \
--title "Enable Logging" \
--yesno "\\n\\nWould you like to enable query logging?" \
2022-07-04 21:00:16 +00:00
" ${ r } " " ${ c } " && result = 0 || result = $?
2022-06-19 00:17:10 +00:00
case ${ result } in
" ${ DIALOG_OK } " )
# If they chose yes,
2022-07-06 03:11:00 +00:00
printf " %b Query Logging on.\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
QUERY_LOGGING = true
; ;
2022-06-19 00:17:10 +00:00
" ${ DIALOG_CANCEL } " )
# If they chose no,
2022-07-06 03:11:00 +00:00
printf " %b Query Logging off.\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
QUERY_LOGGING = false
; ;
2022-06-19 00:17:10 +00:00
" ${ DIALOG_ESC } " )
# User pressed <ESC>
2022-07-06 03:25:27 +00:00
printf " %b Escape pressed, exiting installer at Query Logging choice.%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } "
2022-06-19 00:17:10 +00:00
exit 1
; ;
2016-12-21 01:22:57 +00:00
esac
2016-10-31 21:38:48 +00:00
}
2018-08-20 23:04:58 +00:00
# Allow the user to set their FTL privacy level
setPrivacyLevel( ) {
# The default selection is level 0
2022-07-04 21:00:16 +00:00
PRIVACY_LEVEL = $( dialog --no-shadow --keep-tite --output-fd 1 \
2022-07-05 21:23:59 +00:00
--cancel-label "Exit" \
--ok-label "Continue" \
2022-06-19 00:17:10 +00:00
--radiolist "Select a privacy mode for FTL. https://docs.pi-hole.net/ftldns/privacylevels/" \
" ${ r } " " ${ c } " 6 \
"0" "Show everything" on \
"1" "Hide domains" off \
"2" "Hide domains and clients" off \
"3" "Anonymous mode" off)
result = $?
case ${ result } in
" ${ DIALOG_OK } " )
printf " %b Using privacy level: %s\\n" " ${ INFO } " " ${ PRIVACY_LEVEL } "
; ;
" ${ DIALOG_CANCEL } " | " ${ DIALOG_ESC } " )
printf " %b Cancelled privacy level selection.%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } "
exit 1
; ;
esac
2018-08-20 23:04:58 +00:00
}
2018-04-17 08:50:25 +00:00
# A function to display a list of example blocklists for users to select
2018-04-17 18:35:46 +00:00
chooseBlocklists( ) {
2018-07-06 04:48:36 +00:00
# Back up any existing adlist file, on the off chance that it exists. Useful in case of a reconfigure.
if [ [ -f " ${ adlistFile } " ] ] ; then
mv " ${ adlistFile } " " ${ adlistFile } .old "
fi
2022-06-19 00:17:10 +00:00
# Let user select (or not) blocklists
2022-07-04 21:00:16 +00:00
dialog --no-shadow --keep-tite \
2022-06-19 00:17:10 +00:00
--backtitle "Pi-hole Installation" \
--title "Blocklists" \
2022-07-02 19:36:16 +00:00
--yesno " \\nPi-hole relies on third party lists in order to block ads.\
\\ n\\ nYou can use the suggestion below, and/or add your own after installation.\
\\ n\\ nSelect 'Yes' to include:\
\\ n\\ nStevenBlack' s Unified Hosts List" \
2022-07-04 21:00:16 +00:00
" ${ r } " " ${ c } " && result = 0 || result = $?
2022-06-19 00:17:10 +00:00
case ${ result } in
" ${ DIALOG_OK } " )
# If they chose yes,
2022-07-06 03:11:00 +00:00
printf " %b Installing StevenBlack's Unified Hosts List\\n" " ${ INFO } "
2022-06-19 00:17:10 +00:00
echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >> " ${ adlistFile } "
; ;
" ${ DIALOG_CANCEL } " )
# If they chose no,
2022-07-06 03:11:00 +00:00
printf " %b Not installing StevenBlack's Unified Hosts List\\n" " ${ INFO } "
2022-06-19 00:17:10 +00:00
; ;
" ${ DIALOG_ESC } " )
# User pressed <ESC>
2022-07-06 03:25:27 +00:00
printf " %b Escape pressed, exiting installer at blocklist choice.%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } "
2022-06-19 00:17:10 +00:00
exit 1
; ;
esac
2021-03-18 01:35:27 +00:00
# Create an empty adList file with appropriate permissions.
2022-03-31 19:03:17 +00:00
if [ ! -f " ${ adlistFile } " ] ; then
2022-03-31 21:32:07 +00:00
install -m 644 /dev/null " ${ adlistFile } "
else
2022-03-31 19:03:17 +00:00
chmod 644 " ${ adlistFile } "
fi
2017-01-28 14:38:54 +00:00
}
2018-08-12 21:19:16 +00:00
# Used only in unattended setup
# If there is already the adListFile, we keep it, else we create it using all default lists
installDefaultBlocklists( ) {
2018-08-14 12:59:41 +00:00
# In unattended setup, could be useful to use userdefined blocklist.
# If this file exists, we avoid overriding it.
2018-08-12 21:19:16 +00:00
if [ [ -f " ${ adlistFile } " ] ] ; then
return ;
2018-08-20 20:52:22 +00:00
fi
2022-06-19 00:17:10 +00:00
echo "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" >> " ${ adlistFile } "
2018-08-12 21:19:16 +00:00
}
2023-01-13 21:23:50 +00:00
remove_old_dnsmasq_ftl_configs( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
local dnsmasq_conf = "/etc/dnsmasq.conf"
2023-01-13 21:23:50 +00:00
local pihole_01 = "/etc/dnsmasq.d/01-pihole.conf"
local rfc6761_06 = "/etc/dnsmasq.d/06-rfc6761.conf"
local pihole_dhcp_02 = "/etc/dnsmasq.d/02-pihole-dhcp.conf"
2018-07-06 04:48:36 +00:00
2023-01-13 21:23:50 +00:00
# pihole-FTL does some fancy stuff with config these days, and so we can remove some old config files
if [ [ -f " ${ pihole_01 } " ] ] ; then
rm " ${ pihole_01 } "
2018-07-06 04:48:36 +00:00
fi
2016-12-21 01:22:57 +00:00
2023-01-13 21:23:50 +00:00
if [ [ -f " ${ rfc6761_06 } " ] ] ; then
rm " ${ rfc6761_06 } "
2018-07-06 04:48:36 +00:00
fi
2020-09-28 04:15:46 +00:00
2023-01-13 21:23:50 +00:00
if [ [ -f " ${ pihole_dhcp_02 } " ] ] ; then
rm " ${ pihole_dhcp_02 } "
2016-10-31 21:38:48 +00:00
fi
2021-08-15 09:17:09 +00:00
2023-01-13 21:23:50 +00:00
# If the dnsmasq config file exists
if [ [ -f " ${ dnsmasq_conf } " ] ] ; then
2023-01-15 11:33:53 +00:00
# There should not be anything custom in here for Pi-hole users
# It is no longer needed, but we'll back it up instead of deleting it just in case
2023-01-13 21:23:50 +00:00
mv " ${ dnsmasq_conf } " " ${ dnsmasq_conf } .old "
fi
2023-01-13 21:30:01 +00:00
# Create /etc/dnsmasq.d if it doesn't exist
if [ [ ! -d "/etc/dnsmasq.d" ] ] ; then
mkdir "/etc/dnsmasq.d"
fi
2016-01-25 05:04:02 +00:00
}
2023-06-12 21:33:50 +00:00
remove_old_pihole_lighttpd_configs( ) {
local lighttpdConfig = "/etc/lighttpd/lighttpd.conf"
local condfd = "/etc/lighttpd/conf.d/pihole-admin.conf"
local confavailable = "/etc/lighttpd/conf-available/15-pihole-admin.conf"
local confenabled = "/etc/lighttpd/conf-enabled/15-pihole-admin.conf"
2023-06-18 11:38:02 +00:00
if [ [ -f " ${ lighttpdConfig } " ] ] ; then
2023-06-13 18:08:12 +00:00
sed -i '/include "\/etc\/lighttpd\/conf.d\/pihole-admin.conf"/d' " ${ lighttpdConfig } "
2023-06-18 11:38:02 +00:00
fi
2023-06-12 21:33:50 +00:00
2023-06-18 11:38:02 +00:00
if [ [ -f " ${ condfd } " ] ] ; then
rm " ${ condfd } "
fi
2023-06-12 21:33:50 +00:00
2023-06-18 11:38:02 +00:00
if is_command lighty-disable-mod ; then
lighty-disable-mod pihole-admin > /dev/null || true
fi
2023-06-12 21:33:50 +00:00
2023-06-18 11:38:02 +00:00
if [ [ -f " ${ confavailable } " ] ] ; then
rm " ${ confavailable } "
fi
2023-06-12 21:33:50 +00:00
2023-06-18 11:38:02 +00:00
if [ [ -f " ${ confenabled } " ] ] ; then
rm " ${ confenabled } "
fi
2023-06-12 21:33:50 +00:00
}
2017-07-10 19:12:30 +00:00
# Clean an existing installation to prepare for upgrade/reinstall
2016-11-02 07:14:25 +00:00
clean_existing( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
# ${1} Directory to clean
local clean_directory = " ${ 1 } "
2021-03-18 01:35:27 +00:00
# Pop the first argument, and shift all addresses down by one (i.e. ${2} becomes ${1})
2018-07-06 04:48:36 +00:00
shift
2021-03-18 01:35:27 +00:00
# Then, we can access all arguments ($@) without including the directory to clean
2018-07-06 04:48:36 +00:00
local old_files = ( " $@ " )
2021-03-18 01:35:27 +00:00
# Remove each script in the old_files array
2018-07-06 04:48:36 +00:00
for script in " ${ old_files [@] } " ; do
rm -f " ${ clean_directory } / ${ script } .sh "
done
2016-11-02 07:14:25 +00:00
}
2016-10-05 16:57:48 +00:00
2017-07-07 00:25:56 +00:00
# Install the scripts from repository to their various locations
2016-11-02 07:14:25 +00:00
installScripts( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
local str = " Installing scripts from ${ PI_HOLE_LOCAL_REPO } "
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Clear out script files from Pi-hole scripts directory.
clean_existing " ${ PI_HOLE_INSTALL_DIR } " " ${ PI_HOLE_FILES [@] } "
# Install files from local core repository
if is_repo " ${ PI_HOLE_LOCAL_REPO } " ; then
# move into the directory
cd " ${ PI_HOLE_LOCAL_REPO } "
# Install the scripts by:
# -o setting the owner to the user
# -Dm755 create all leading components of destination except the last, then copy the source to the destination and setting the permissions to 755
#
# This first one is the directory
install -o " ${ USER } " -Dm755 -d " ${ PI_HOLE_INSTALL_DIR } "
# The rest are the scripts Pi-hole needs
install -o " ${ USER } " -Dm755 -t " ${ PI_HOLE_INSTALL_DIR } " gravity.sh
install -o " ${ USER } " -Dm755 -t " ${ PI_HOLE_INSTALL_DIR } " ./advanced/Scripts/*.sh
install -o " ${ USER } " -Dm755 -t " ${ PI_HOLE_INSTALL_DIR } " ./automated\ install/uninstall.sh
install -o " ${ USER } " -Dm755 -t " ${ PI_HOLE_INSTALL_DIR } " ./advanced/Scripts/COL_TABLE
2019-08-24 11:33:32 +00:00
install -o " ${ USER } " -Dm755 -t " ${ PI_HOLE_BIN_DIR } " pihole
2018-07-06 04:48:36 +00:00
install -Dm644 ./advanced/bash-completion/pihole /etc/bash_completion.d/pihole
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2018-07-30 21:02:18 +00:00
2018-07-06 04:48:36 +00:00
else
2021-03-18 01:35:27 +00:00
# Otherwise, show an error and exit
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
2018-10-31 21:35:55 +00:00
printf "\\t\\t%bError: Local repo %s not found, exiting installer%b\\n" " ${ COL_LIGHT_RED } " " ${ PI_HOLE_LOCAL_REPO } " " ${ COL_NC } "
2018-07-29 16:06:51 +00:00
return 1
2018-07-06 04:48:36 +00:00
fi
2015-12-03 17:25:13 +00:00
}
2017-07-07 00:25:56 +00:00
# Install the configs from PI_HOLE_LOCAL_REPO to their various locations
2016-01-27 06:11:38 +00:00
installConfigs( ) {
2018-10-31 18:14:05 +00:00
printf "\\n %b Installing configs from %s...\\n" " ${ INFO } " " ${ PI_HOLE_LOCAL_REPO } "
2023-01-13 22:23:33 +00:00
2023-10-09 20:35:02 +00:00
# Ensure that permissions are correctly set
chown -R pihole:pihole /etc/pihole
2019-01-13 14:51:30 +00:00
# Install list of DNS servers
# Format: Name;Primary IPv4;Secondary IPv4;Primary IPv6;Secondary IPv6
# Some values may be empty (for example: DNS servers without IPv6 support)
echo " ${ DNS_SERVERS } " > " ${ PI_HOLE_CONFIG_DIR } /dns-servers.conf "
2019-05-04 22:32:10 +00:00
chmod 644 " ${ PI_HOLE_CONFIG_DIR } /dns-servers.conf "
2023-10-09 20:35:02 +00:00
chown pihole:pihole " ${ PI_HOLE_CONFIG_DIR } /dns-servers.conf "
2019-01-13 14:51:30 +00:00
2020-07-24 18:32:32 +00:00
# Install empty custom.list file if it does not exist
if [ [ ! -r " ${ PI_HOLE_CONFIG_DIR } /custom.list " ] ] ; then
2023-08-06 10:04:55 +00:00
if ! install -o pihole -g pihole -m 660 /dev/null " ${ PI_HOLE_CONFIG_DIR } /custom.list " & >/dev/null; then
2022-07-06 10:29:03 +00:00
printf " %b Error: Unable to initialize configuration file %s/custom.list\\n" " ${ COL_LIGHT_RED } " " ${ PI_HOLE_CONFIG_DIR } "
2020-07-24 18:32:32 +00:00
return 1
fi
fi
2020-07-26 10:27:55 +00:00
2022-09-18 19:44:06 +00:00
# Install pihole-FTL systemd or init.d service, based on whether systemd is the init system or not
# Follow debhelper logic, which checks for /run/systemd/system to derive whether systemd is the init system
if [ [ -d '/run/systemd/system' ] ] ; then
install -T -m 0644 " ${ PI_HOLE_LOCAL_REPO } /advanced/Templates/pihole-FTL.systemd " '/etc/systemd/system/pihole-FTL.service'
# Remove init.d service if present
if [ [ -e '/etc/init.d/pihole-FTL' ] ] ; then
rm '/etc/init.d/pihole-FTL'
update-rc.d pihole-FTL remove
fi
# Load final service
systemctl daemon-reload
else
install -T -m 0755 " ${ PI_HOLE_LOCAL_REPO } /advanced/Templates/pihole-FTL.service " '/etc/init.d/pihole-FTL'
fi
install -T -m 0755 " ${ PI_HOLE_LOCAL_REPO } /advanced/Templates/pihole-FTL-prestart.sh " " ${ PI_HOLE_INSTALL_DIR } /pihole-FTL-prestart.sh "
install -T -m 0755 " ${ PI_HOLE_LOCAL_REPO } /advanced/Templates/pihole-FTL-poststop.sh " " ${ PI_HOLE_INSTALL_DIR } /pihole-FTL-poststop.sh "
2015-12-03 17:25:13 +00:00
}
2018-06-01 23:45:04 +00:00
install_manpage( ) {
2018-07-06 04:48:36 +00:00
# Copy Pi-hole man pages and call mandb to update man page database
# Default location for man files for /usr/local/bin is /usr/local/share/man
# on lightweight systems may not be present, so check before copying.
2018-10-31 18:14:05 +00:00
printf " %b Testing man page installation" " ${ INFO } "
2018-11-01 19:00:08 +00:00
if ! is_command mandb ; then
2018-07-06 04:48:36 +00:00
# if mandb is not present, no manpage support
2018-10-31 18:14:05 +00:00
printf "%b %b man not installed\\n" " ${ OVER } " " ${ INFO } "
2018-07-06 04:48:36 +00:00
return
elif [ [ ! -d "/usr/local/share/man" ] ] ; then
# appropriate directory for Pi-hole's man page is not present
2018-10-31 18:14:05 +00:00
printf "%b %b man pages not installed\\n" " ${ OVER } " " ${ INFO } "
2018-07-06 04:48:36 +00:00
return
fi
if [ [ ! -d "/usr/local/share/man/man8" ] ] ; then
# if not present, create man8 directory
2019-05-03 10:27:56 +00:00
install -d -m 755 /usr/local/share/man/man8
2018-07-06 04:48:36 +00:00
fi
if [ [ ! -d "/usr/local/share/man/man5" ] ] ; then
2019-04-30 20:41:12 +00:00
# if not present, create man5 directory
2019-05-03 10:27:56 +00:00
install -d -m 755 /usr/local/share/man/man5
2018-07-06 04:48:36 +00:00
fi
# Testing complete, copy the files & update the man db
2019-05-03 10:27:56 +00:00
install -D -m 644 -T ${ PI_HOLE_LOCAL_REPO } /manpages/pihole.8 /usr/local/share/man/man8/pihole.8
2021-12-29 05:52:17 +00:00
2023-05-30 19:39:10 +00:00
# remove previously installed man pages
2021-12-29 05:52:17 +00:00
if [ [ -f "/usr/local/share/man/man5/pihole-FTL.conf.5" ] ] ; then
rm /usr/local/share/man/man5/pihole-FTL.conf.5
fi
2023-05-30 19:39:10 +00:00
if [ [ -f "/usr/local/share/man/man5/pihole-FTL.8" ] ] ; then
rm /usr/local/share/man/man5/pihole-FTL.8
fi
2021-12-29 05:52:17 +00:00
2018-07-06 04:48:36 +00:00
if mandb -q & >/dev/null; then
# Updated successfully
2018-10-31 18:14:05 +00:00
printf "%b %b man pages installed and database updated\\n" " ${ OVER } " " ${ TICK } "
2018-07-06 04:48:36 +00:00
return
else
# Something is wrong with the system's man installation, clean up
# our files, (leave everything how we found it).
2023-05-30 19:39:10 +00:00
rm /usr/local/share/man/man8/pihole.8
2018-10-31 18:14:05 +00:00
printf "%b %b man page db not updated, man pages not installed\\n" " ${ OVER } " " ${ CROSS } "
2018-07-06 04:48:36 +00:00
fi
2018-06-01 23:45:04 +00:00
}
2016-10-10 08:25:11 +00:00
stop_service( ) {
2018-07-06 04:48:36 +00:00
# Stop service passed in as argument.
# Can softfail, as process may not be installed when this is called
local str = " Stopping ${ 1 } service "
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-11-01 19:00:08 +00:00
if is_command systemctl ; then
2018-07-06 04:48:36 +00:00
systemctl stop " ${ 1 } " & > /dev/null || true
else
service " ${ 1 } " stop & > /dev/null || true
fi
2018-10-31 18:14:05 +00:00
printf "%b %b %s...\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2016-10-10 13:06:34 +00:00
}
2017-07-07 00:25:56 +00:00
# Start/Restart service passed in as argument
2019-01-24 08:37:03 +00:00
restart_service( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
2019-02-02 07:00:58 +00:00
local str = " Restarting ${ 1 } service "
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# If systemctl exists,
2018-11-01 19:00:08 +00:00
if is_command systemctl ; then
2018-07-06 04:48:36 +00:00
# use that to restart the service
systemctl restart " ${ 1 } " & > /dev/null
else
2021-03-18 01:35:27 +00:00
# Otherwise, fall back to the service command
2018-07-06 04:48:36 +00:00
service " ${ 1 } " restart & > /dev/null
fi
2018-10-31 18:14:05 +00:00
printf "%b %b %s...\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2016-10-10 13:06:34 +00:00
}
2017-07-07 00:25:56 +00:00
# Enable service so that it will start with next reboot
2016-10-10 13:06:34 +00:00
enable_service( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
local str = " Enabling ${ 1 } service to start on reboot "
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# If systemctl exists,
2018-11-01 19:00:08 +00:00
if is_command systemctl ; then
2018-07-06 04:48:36 +00:00
# use that to enable the service
systemctl enable " ${ 1 } " & > /dev/null
else
2021-03-18 01:35:27 +00:00
# Otherwise, use update-rc.d to accomplish this
2018-07-06 04:48:36 +00:00
update-rc.d " ${ 1 } " defaults & > /dev/null
fi
2018-10-31 18:14:05 +00:00
printf "%b %b %s...\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2015-12-03 17:25:13 +00:00
}
2016-10-10 05:05:06 +00:00
2018-03-06 18:44:57 +00:00
# Disable service so that it will not with next reboot
disable_service( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
local str = " Disabling ${ 1 } service "
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# If systemctl exists,
2018-11-01 19:00:08 +00:00
if is_command systemctl ; then
2018-07-06 04:48:36 +00:00
# use that to disable the service
systemctl disable " ${ 1 } " & > /dev/null
else
2021-03-18 01:35:27 +00:00
# Otherwise, use update-rc.d to accomplish this
2018-07-06 04:48:36 +00:00
update-rc.d " ${ 1 } " disable & > /dev/null
fi
2018-10-31 18:14:05 +00:00
printf "%b %b %s...\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2018-03-06 18:44:57 +00:00
}
2018-03-07 23:31:28 +00:00
check_service_active( ) {
# If systemctl exists,
2018-11-01 19:00:08 +00:00
if is_command systemctl ; then
2018-07-06 04:48:36 +00:00
# use that to check the status of the service
2018-07-29 00:50:04 +00:00
systemctl is-enabled " ${ 1 } " & > /dev/null
2018-07-06 04:48:36 +00:00
else
2021-03-18 01:35:27 +00:00
# Otherwise, fall back to service command
2018-07-29 00:50:04 +00:00
service " ${ 1 } " status & > /dev/null
2018-07-06 04:48:36 +00:00
fi
2018-03-07 23:31:28 +00:00
}
2023-01-13 21:30:01 +00:00
# Systemd-resolved's DNSStubListener and ftl can't share port 53.
2018-05-15 10:23:36 +00:00
disable_resolved_stublistener( ) {
2018-10-31 18:14:05 +00:00
printf " %b Testing if systemd-resolved is enabled\\n" " ${ INFO } "
2018-07-26 23:27:06 +00:00
# Check if Systemd-resolved's DNSStubListener is enabled and active on port 53
if check_service_active "systemd-resolved" ; then
2018-07-06 04:48:36 +00:00
# Check if DNSStubListener is enabled
2022-07-06 10:29:03 +00:00
printf " %b %b Testing if systemd-resolved DNSStub-Listener is active" " ${ OVER } " " ${ INFO } "
2018-07-06 04:48:36 +00:00
if ( grep -E '#?DNSStubListener=yes' /etc/systemd/resolved.conf & > /dev/null ) ; then
# Disable the DNSStubListener to unbind it from port 53
2023-01-13 21:30:01 +00:00
# Note that this breaks dns functionality on host until ftl are up and running
2018-10-31 18:14:05 +00:00
printf "%b %b Disabling systemd-resolved DNSStubListener" " ${ OVER } " " ${ TICK } "
2018-07-06 04:48:36 +00:00
# Make a backup of the original /etc/systemd/resolved.conf
# (This will need to be restored on uninstallation)
2018-07-26 23:27:06 +00:00
sed -r -i.orig 's/#?DNSStubListener=yes/DNSStubListener=no/g' /etc/systemd/resolved.conf
2018-10-31 18:14:05 +00:00
printf " and restarting systemd-resolved\\n"
2018-07-26 23:27:06 +00:00
systemctl reload-or-restart systemd-resolved
2018-07-06 04:48:36 +00:00
else
2018-10-31 18:14:05 +00:00
printf "%b %b Systemd-resolved does not need to be restarted\\n" " ${ OVER } " " ${ INFO } "
2018-07-06 04:48:36 +00:00
fi
2018-05-16 21:44:07 +00:00
else
2018-10-31 18:14:05 +00:00
printf "%b %b Systemd-resolved is not enabled\\n" " ${ OVER } " " ${ INFO } "
2018-05-15 10:23:36 +00:00
fi
}
2017-01-28 23:44:31 +00:00
update_package_cache( ) {
2018-07-06 04:48:36 +00:00
# Update package cache on apt based OSes. Do this every time since
# it's quick and packages can be updated at any time.
# Local, named variables
local str = "Update local cache of available packages"
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Create a command from the package cache variable
if eval " ${ UPDATE_PKG_CACHE } " & > /dev/null; then
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2018-07-06 04:48:36 +00:00
else
2021-03-18 01:35:27 +00:00
# Otherwise, show an error and exit
2021-11-04 22:55:16 +00:00
# In case we used apt-get and apt is also available, we use this as recommendation as we have seen it
# gives more user-friendly (interactive) advice
if [ [ ${ PKG_MANAGER } = = "apt-get" ] ] && is_command apt ; then
UPDATE_PKG_CACHE = "apt update"
fi
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
2022-07-06 10:29:03 +00:00
printf " %b Error: Unable to update package cache. Please try \"%s\"%b\\n" " ${ COL_LIGHT_RED } " " sudo ${ UPDATE_PKG_CACHE } " " ${ COL_NC } "
2018-07-06 04:48:36 +00:00
return 1
fi
2016-10-10 09:24:03 +00:00
}
2017-07-07 00:25:56 +00:00
# Let user know if they have outdated packages on their system and
# advise them to run a package update at soonest possible.
2016-10-20 02:47:45 +00:00
notify_package_updates_available( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
local str = " Checking ${ PKG_MANAGER } for upgraded packages "
2018-10-31 18:14:05 +00:00
printf "\\n %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Store the list of packages in a variable
updatesToInstall = $( eval " ${ PKG_COUNT } " )
2017-07-26 17:00:08 +00:00
2018-07-06 04:48:36 +00:00
if [ [ -d " /lib/modules/ $( uname -r) " ] ] ; then
if [ [ " ${ updatesToInstall } " -eq 0 ] ] ; then
2018-10-31 18:14:05 +00:00
printf "%b %b %s... up to date!\\n\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2018-07-06 04:48:36 +00:00
else
2018-10-31 18:14:05 +00:00
printf "%b %b %s... %s updates available\\n" " ${ OVER } " " ${ TICK } " " ${ str } " " ${ updatesToInstall } "
printf " %b %bIt is recommended to update your OS after installing the Pi-hole!%b\\n\\n" " ${ INFO } " " ${ COL_LIGHT_GREEN } " " ${ COL_NC } "
2018-07-06 04:48:36 +00:00
fi
2016-12-29 09:34:49 +00:00
else
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
printf " Kernel update detected. If the install fails, please reboot and try again\\n"
2018-07-06 04:48:36 +00:00
fi
2016-10-10 05:00:23 +00:00
}
2016-10-20 02:47:45 +00:00
install_dependent_packages( ) {
2018-07-06 04:48:36 +00:00
# Install packages passed in via argument array
# No spinner - conflicts with set -e
declare -a installArray
# Debian based package install - debconf will download the entire package list
# so we just create an array of packages not currently installed to cut down on the
# amount of download traffic.
# NOTE: We may be able to use this installArray in the future to create a list of package that were
# installed by us, and remove only the installed packages, and not the entire list.
2019-10-13 17:44:15 +00:00
if is_command apt-get ; then
2021-03-18 01:35:27 +00:00
# For each package, check if it's already installed (and if so, don't add it to the installArray)
2019-05-10 14:37:38 +00:00
for i in " $@ " ; do
2018-10-31 18:14:05 +00:00
printf " %b Checking for %s..." " ${ INFO } " " ${ i } "
2018-07-06 04:48:36 +00:00
if dpkg-query -W -f= '${Status}' " ${ i } " 2>/dev/null | grep "ok installed" & > /dev/null; then
2018-10-31 18:14:05 +00:00
printf "%b %b Checking for %s\\n" " ${ OVER } " " ${ TICK } " " ${ i } "
2018-07-06 04:48:36 +00:00
else
2019-10-15 02:16:40 +00:00
printf "%b %b Checking for %s (will be installed)\\n" " ${ OVER } " " ${ INFO } " " ${ i } "
2018-07-06 04:48:36 +00:00
installArray += ( " ${ i } " )
fi
done
2021-03-18 01:35:27 +00:00
# If there's anything to install, install everything in the list.
2018-07-06 04:48:36 +00:00
if [ [ " ${# installArray [@] } " -gt 0 ] ] ; then
test_dpkg_lock
2021-04-07 19:53:52 +00:00
# Running apt-get install with minimal output can cause some issues with
# requiring user input (e.g password for phpmyadmin see #218)
2020-01-01 18:41:33 +00:00
printf " %b Processing %s install(s) for: %s, please wait...\\n" " ${ INFO } " " ${ PKG_MANAGER } " " ${ installArray [*] } "
2022-07-15 18:40:11 +00:00
printf '%*s\n' " ${ c } " '' | tr " " -;
2019-10-13 17:44:15 +00:00
" ${ PKG_INSTALL [@] } " " ${ installArray [@] } "
2022-07-15 18:40:11 +00:00
printf '%*s\n' " ${ c } " '' | tr " " -;
2018-07-06 04:48:36 +00:00
return
fi
2018-10-31 18:14:05 +00:00
printf "\\n"
2018-07-06 04:48:36 +00:00
return 0
fi
# Install Fedora/CentOS packages
2019-05-10 14:37:38 +00:00
for i in " $@ " ; do
2021-11-25 06:41:40 +00:00
# For each package, check if it's already installed (and if so, don't add it to the installArray)
2018-10-31 18:14:05 +00:00
printf " %b Checking for %s..." " ${ INFO } " " ${ i } "
2019-05-10 14:13:23 +00:00
if " ${ PKG_MANAGER } " -q list installed " ${ i } " & > /dev/null; then
2019-10-13 20:35:38 +00:00
printf "%b %b Checking for %s\\n" " ${ OVER } " " ${ TICK } " " ${ i } "
2018-07-06 04:48:36 +00:00
else
2019-10-15 02:16:40 +00:00
printf "%b %b Checking for %s (will be installed)\\n" " ${ OVER } " " ${ INFO } " " ${ i } "
2018-07-06 04:48:36 +00:00
installArray += ( " ${ i } " )
fi
2016-12-21 00:47:43 +00:00
done
2021-03-18 01:35:27 +00:00
# If there's anything to install, install everything in the list.
2017-07-26 17:00:08 +00:00
if [ [ " ${# installArray [@] } " -gt 0 ] ] ; then
2020-01-01 18:41:33 +00:00
printf " %b Processing %s install(s) for: %s, please wait...\\n" " ${ INFO } " " ${ PKG_MANAGER } " " ${ installArray [*] } "
2022-07-15 18:40:11 +00:00
printf '%*s\n' " ${ c } " '' | tr " " -;
2020-01-01 18:41:33 +00:00
" ${ PKG_INSTALL [@] } " " ${ installArray [@] } "
2022-07-15 18:40:11 +00:00
printf '%*s\n' " ${ c } " '' | tr " " -;
2018-07-06 04:48:36 +00:00
return
2016-12-22 07:38:31 +00:00
fi
2018-10-31 18:14:05 +00:00
printf "\\n"
2018-07-06 04:48:36 +00:00
return 0
2015-12-03 17:25:13 +00:00
}
2017-07-07 00:25:56 +00:00
# Installs a cron file
2016-01-27 06:11:38 +00:00
installCron( ) {
2018-07-06 04:48:36 +00:00
# Install the cron job
local str = "Installing latest Cron script"
2018-10-31 18:14:05 +00:00
printf "\\n %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Copy the cron file over from the local repo
2019-04-30 20:41:12 +00:00
# File must not be world or group writeable and must be owned by root
2019-05-03 10:27:56 +00:00
install -D -m 644 -T -o root -g root ${ PI_HOLE_LOCAL_REPO } /advanced/Templates/pihole.cron /etc/cron.d/pihole
2018-07-06 04:48:36 +00:00
# Randomize gravity update time
sed -i " s/59 1 / $(( 1 + RANDOM % 58 )) $(( 3 + RANDOM % 2 )) / " /etc/cron.d/pihole
# Randomize update checker time
sed -i " s/59 17/ $(( 1 + RANDOM % 58 )) $(( 12 + RANDOM % 8 )) / " /etc/cron.d/pihole
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2015-12-03 17:25:13 +00:00
}
2017-07-07 00:25:56 +00:00
# Gravity is a very important script as it aggregates all of the domains into a single HOSTS formatted list,
# which is what Pi-hole needs to begin blocking ads
2016-01-27 06:11:38 +00:00
runGravity( ) {
2023-10-09 19:52:43 +00:00
# Run gravity in the current shell as user pihole
2023-10-09 20:35:02 +00:00
{ sudo -u pihole bash /opt/pihole/gravity.sh --force; }
2016-01-19 22:52:29 +00:00
}
2017-07-07 00:25:56 +00:00
# Check if the pihole user exists and create if it does not
2016-10-20 02:47:45 +00:00
create_pihole_user( ) {
2018-07-06 04:48:36 +00:00
local str = "Checking for user 'pihole'"
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2021-03-18 01:35:27 +00:00
# If the pihole user exists,
2018-07-06 04:48:36 +00:00
if id -u pihole & > /dev/null; then
2021-03-18 01:35:27 +00:00
# and if the pihole group exists,
2020-04-03 18:07:44 +00:00
if getent group pihole > /dev/null 2>& 1; then
2021-03-18 01:35:27 +00:00
# succeed
2020-04-03 10:06:59 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
else
local str = "Checking for group 'pihole'"
printf " %b %s..." " ${ INFO } " " ${ str } "
local str = "Creating group 'pihole'"
# if group can be created
if groupadd pihole; then
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
local str = "Adding user 'pihole' to group 'pihole'"
printf " %b %s..." " ${ INFO } " " ${ str } "
# if pihole user can be added to group pihole
if usermod -g pihole pihole; then
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
else
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
fi
else
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
fi
fi
2018-07-06 04:48:36 +00:00
else
2021-03-18 01:35:27 +00:00
# If the pihole user doesn't exist,
2018-10-31 18:14:05 +00:00
printf "%b %b %s" " ${ OVER } " " ${ CROSS } " " ${ str } "
2022-11-24 21:06:04 +00:00
local str = "Checking for group 'pihole'"
printf " %b %s..." " ${ INFO } " " ${ str } "
2020-04-03 18:07:44 +00:00
if getent group pihole > /dev/null 2>& 1; then
2022-11-24 21:06:04 +00:00
# group pihole exists
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
# then create and add her to the pihole group
local str = "Creating user 'pihole'"
printf "%b %b %s..." " ${ OVER } " " ${ INFO } " " ${ str } "
2020-04-03 10:06:59 +00:00
if useradd -r --no-user-group -g pihole -s /usr/sbin/nologin pihole; then
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
else
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
fi
2018-10-12 17:05:44 +00:00
else
2022-11-24 21:06:04 +00:00
# group pihole does not exist
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
local str = "Creating group 'pihole'"
# if group can be created
if groupadd pihole; then
2020-04-03 10:06:59 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2022-11-24 21:06:04 +00:00
# create and add pihole user to the pihole group
local str = "Creating user 'pihole'"
printf "%b %b %s..." " ${ OVER } " " ${ INFO } " " ${ str } "
if useradd -r --no-user-group -g pihole -s /usr/sbin/nologin pihole; then
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
else
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
fi
2020-04-03 10:06:59 +00:00
else
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
fi
2018-10-12 17:05:44 +00:00
fi
2018-07-06 04:48:36 +00:00
fi
2016-01-25 05:28:53 +00:00
}
2016-01-20 23:34:18 +00:00
2017-07-07 00:25:56 +00:00
# Install the logrotate script
2017-01-27 13:16:24 +00:00
installLogrotate( ) {
2018-07-06 04:48:36 +00:00
local str = "Installing latest logrotate script"
2021-06-20 18:18:33 +00:00
local target = /etc/pihole/logrotate
2018-10-31 21:35:55 +00:00
printf "\\n %b %s..." " ${ INFO } " " ${ str } "
2021-06-20 18:18:33 +00:00
if [ [ -f ${ target } ] ] ; then
2022-07-10 08:52:55 +00:00
2022-07-10 10:50:09 +00:00
# Account for changed logfile paths from /var/log -> /var/log/pihole/ made in core v5.11.
if grep -q "/var/log/pihole.log" ${ target } || grep -q "/var/log/pihole-FTL.log" ${ target } ; then
2022-07-10 08:52:55 +00:00
sed -i 's/\/var\/log\/pihole.log/\/var\/log\/pihole\/pihole.log/g' ${ target }
sed -i 's/\/var\/log\/pihole-FTL.log/\/var\/log\/pihole\/FTL.log/g' ${ target }
printf "\\n\\t%b Old log file paths updated in existing logrotate file. \\n" " ${ INFO } "
return 3
fi
2022-07-10 10:50:09 +00:00
printf "\\n\\t%b Existing logrotate file found. No changes made.\\n" " ${ INFO } "
# Return value isn't that important, using 2 to indicate that it's not a fatal error but
# the function did not complete.
return 2
2021-06-20 18:18:33 +00:00
fi
2018-07-06 04:48:36 +00:00
# Copy the file over from the local repo
2023-10-18 20:09:38 +00:00
# Logrotate config file must be owned by root and not writable by group or other
install -o root -g root -D -m 644 -T " ${ PI_HOLE_LOCAL_REPO } " /advanced/Templates/logrotate ${ target }
2018-07-06 04:48:36 +00:00
# Different operating systems have different user / group
# settings for logrotate that makes it impossible to create
# a static logrotate file that will work with e.g.
# Rasbian and Ubuntu at the same time. Hence, we have to
# customize the logrotate script here in order to reflect
# the local properties of the /var/log directory
logusergroup = " $( stat -c '%U %G' /var/log) "
2021-03-18 01:35:27 +00:00
# If there is a usergroup for log rotation,
2021-06-20 18:19:19 +00:00
if [ [ -n " ${ logusergroup } " ] ] ; then
2021-03-18 01:35:27 +00:00
# replace the line in the logrotate script with that usergroup.
2021-06-20 18:18:33 +00:00
sed -i " s/# su #/su ${ logusergroup } /g; " ${ target }
2018-07-06 04:48:36 +00:00
fi
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2017-01-27 13:16:24 +00:00
}
2017-07-07 00:25:56 +00:00
# Install base files and web interface
2016-08-19 21:45:24 +00:00
installPihole( ) {
2018-07-06 04:48:36 +00:00
# Install base files and web interface
2018-07-29 16:06:51 +00:00
if ! installScripts; then
2018-10-31 18:14:05 +00:00
printf " %b Failure in dependent script copy function.\\n" " ${ CROSS } "
2018-07-29 16:06:51 +00:00
exit 1
fi
2022-08-18 15:08:52 +00:00
# /opt/pihole/utils.sh should be installed by installScripts now, so we can use it
if [ -f " ${ PI_HOLE_INSTALL_DIR } /utils.sh " ] ; then
# shellcheck disable=SC1091
source " ${ PI_HOLE_INSTALL_DIR } /utils.sh "
else
printf " %b Failure: /opt/pihole/utils.sh does not exist .\\n" " ${ CROSS } "
exit 1
fi
2023-01-13 22:23:33 +00:00
remove_old_dnsmasq_ftl_configs
2023-06-12 21:33:50 +00:00
remove_old_pihole_lighttpd_configs
2023-01-13 22:23:33 +00:00
2018-07-06 04:48:36 +00:00
# Install config files
2018-07-30 21:02:18 +00:00
if ! installConfigs; then
2018-10-31 18:14:05 +00:00
printf " %b Failure in dependent config copy function.\\n" " ${ CROSS } "
2018-07-30 21:02:18 +00:00
exit 1
fi
2023-01-13 21:30:01 +00:00
2018-07-06 04:48:36 +00:00
# Install the cron file
installCron
2021-07-28 19:18:02 +00:00
2018-07-06 04:48:36 +00:00
# Install the logrotate file
2021-07-28 19:18:02 +00:00
installLogrotate || true
2018-07-06 04:48:36 +00:00
# install a man page entry for pihole
install_manpage
2016-08-19 21:45:24 +00:00
}
2016-12-23 16:53:42 +00:00
2017-07-07 00:25:56 +00:00
# SELinux
2016-12-23 16:27:52 +00:00
checkSelinux( ) {
2019-10-14 18:14:45 +00:00
local DEFAULT_SELINUX
local CURRENT_SELINUX
local SELINUX_ENFORCING = 0
2020-05-12 21:45:56 +00:00
# Check for SELinux configuration file and getenforce command
2021-12-02 13:44:50 +00:00
if [ [ -f /etc/selinux/config ] ] && is_command getenforce; then
2020-05-12 21:45:56 +00:00
# Check the default SELinux mode
2019-10-14 18:14:45 +00:00
DEFAULT_SELINUX = $( awk -F= '/^SELINUX=/ {print $2}' /etc/selinux/config)
case " ${ DEFAULT_SELINUX ,, } " in
enforcing)
2022-07-10 11:08:33 +00:00
printf " %b %bDefault SELinux: %s%b\\n" " ${ CROSS } " " ${ COL_RED } " " ${ DEFAULT_SELINUX ,, } " " ${ COL_NC } "
2019-10-14 18:14:45 +00:00
SELINUX_ENFORCING = 1
; ;
*) # 'permissive' and 'disabled'
2022-07-10 11:08:33 +00:00
printf " %b %bDefault SELinux: %s%b\\n" " ${ TICK } " " ${ COL_GREEN } " " ${ DEFAULT_SELINUX ,, } " " ${ COL_NC } "
2019-10-14 18:14:45 +00:00
; ;
esac
# Check the current state of SELinux
CURRENT_SELINUX = $( getenforce)
case " ${ CURRENT_SELINUX ,, } " in
enforcing)
2022-07-10 11:08:33 +00:00
printf " %b %bCurrent SELinux: %s%b\\n" " ${ CROSS } " " ${ COL_RED } " " ${ CURRENT_SELINUX ,, } " " ${ COL_NC } "
2019-10-14 18:14:45 +00:00
SELINUX_ENFORCING = 1
; ;
*) # 'permissive' and 'disabled'
2022-07-10 11:08:33 +00:00
printf " %b %bCurrent SELinux: %s%b\\n" " ${ TICK } " " ${ COL_GREEN } " " ${ CURRENT_SELINUX ,, } " " ${ COL_NC } "
2019-10-14 18:14:45 +00:00
; ;
esac
else
2019-11-14 19:06:23 +00:00
echo -e " ${ INFO } ${ COL_GREEN } SELinux not detected ${ COL_NC } " ;
2019-10-14 18:14:45 +00:00
fi
# Exit the installer if any SELinux checks toggled the flag
if [ [ " ${ SELINUX_ENFORCING } " -eq 1 ] ] && [ [ -z " ${ PIHOLE_SELINUX } " ] ] ; then
2019-11-14 19:06:23 +00:00
printf " Pi-hole does not provide an SELinux policy as the required changes modify the security of your system.\\n"
printf " Please refer to https://wiki.centos.org/HowTos/SELinux if SELinux is required for your deployment.\\n"
2020-07-23 14:19:56 +00:00
printf " This check can be skipped by setting the environment variable %bPIHOLE_SELINUX%b to %btrue%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } " " ${ COL_LIGHT_RED } " " ${ COL_NC } "
printf " e.g: export PIHOLE_SELINUX=true\\n"
printf " By setting this variable to true you acknowledge there may be issues with Pi-hole during or after the install\\n"
2019-11-14 19:06:23 +00:00
printf "\\n %bSELinux Enforcing detected, exiting installer%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } " ;
2019-10-14 18:14:45 +00:00
exit 1;
2020-07-23 14:19:56 +00:00
elif [ [ " ${ SELINUX_ENFORCING } " -eq 1 ] ] && [ [ -n " ${ PIHOLE_SELINUX } " ] ] ; then
printf " %b %bSELinux Enforcing detected%b. PIHOLE_SELINUX env variable set - installer will continue\\n" " ${ INFO } " " ${ COL_LIGHT_RED } " " ${ COL_NC } "
2018-07-06 04:48:36 +00:00
fi
2015-11-07 18:07:50 +00:00
}
2017-07-07 00:25:56 +00:00
# Installation complete message with instructions for the user
2016-01-27 06:11:38 +00:00
displayFinalMessage( ) {
2023-02-05 18:59:38 +00:00
# TODO: COME BACK TO THIS, WHAT IS GOING ON?
2021-03-18 01:35:27 +00:00
# If the number of arguments is > 0,
2018-07-06 04:48:36 +00:00
if [ [ " ${# 1 } " -gt 0 ] ] ; then
2021-03-18 01:35:27 +00:00
# set the password to the first argument.
2018-07-06 04:48:36 +00:00
pwstring = " $1 "
2023-02-05 18:59:38 +00:00
elif [ [ $( pihole-FTL --config webserver.api.pwhash) = = '""' ] ] ; then
2021-03-18 01:35:27 +00:00
# Else if the password exists from previous setup, we'll load it later
2018-07-06 04:48:36 +00:00
pwstring = "unchanged"
else
2021-03-18 01:35:27 +00:00
# Else, inform the user that there is no set password.
2018-07-06 04:48:36 +00:00
pwstring = "NOT SET"
fi
2023-02-05 18:39:48 +00:00
# Store a message in a variable and display it
additional = " View the web interface at http://pi.hole/admin: ${ WEBPORT } or http:// ${ IPV4_ADDRESS %/* } : ${ WEBPORT } /admin\\n\\nYour Admin Webpage login password is ${ pwstring } "
2017-01-28 15:43:33 +00:00
2018-07-06 04:48:36 +00:00
# Final completion message to user
2022-07-04 21:00:16 +00:00
dialog --no-shadow --keep-tite \
2022-06-19 00:17:10 +00:00
--title "Installation Complete!" \
2022-07-02 19:36:16 +00:00
--msgbox " Configure your devices to use the Pi-hole as their DNS server using:\
\\ n\\ nIPv4: ${ IPV4_ADDRESS %/* } \
\\ nIPv6: ${ IPV6_ADDRESS :- "Not Configured" } \
\\ nIf you have not done so already, the above IP should be set to static.\
2022-07-06 02:10:40 +00:00
\\ n${ additional } " " ${ r } " " ${ c } "
2016-08-19 21:31:11 +00:00
}
2016-10-20 02:47:45 +00:00
update_dialogs( ) {
2018-07-06 04:48:36 +00:00
# If pihole -r "reconfigure" option was selected,
if [ [ " ${ reconfigure } " = true ] ] ; then
# set some variables that will be used
opt1a = "Repair"
opt1b = "This will retain existing settings"
strAdd = "You will remain on the same version"
else
2021-03-18 01:35:27 +00:00
# Otherwise, set some variables with different values
2018-07-06 04:48:36 +00:00
opt1a = "Update"
opt1b = "This will retain existing settings."
strAdd = "You will be updated to the latest version."
fi
opt2a = "Reconfigure"
Hardcode whiptail dimensions to 20 rows and 70 chars width
With the suggested way to call the installer via "curl -sSL https://install.pi-hole.net | bash", STDIN is no terminal, but overridden by the curl output, hence in most cases, the minimum dimensions were applied, even on larger screens. All whiptail calls are hence assured to work fine with those dimensions, aside of one case, making the calculations obsolete.
This commit hardcodes the whiptail dimensions to the prior minimum and removes the calculations. This also helps with testing, as it does not matter anymore how the script is called, and developers have a clearly defined space to make dialogs look nice, including line breaks, menu and list heights.
The only case which does not fit the 70 character width, the second menu entry of the "pihole -r" dialog, has been shortened accordingly. This was not an issue before, as "pihole -r" does not override the scripts STDIN and hence did allow larger dimensions based on the now removed calculations.
See the following discussions for reference:
- https://github.com/pi-hole/pi-hole/issues/3323
- https://github.com/pi-hole/pi-hole/pull/4197#issuecomment-876702380
Signed-off-by: MichaIng <micha@dietpi.com>
2021-07-16 17:58:49 +00:00
opt2b = "Resets Pi-hole and allows re-selecting settings."
2018-07-06 04:48:36 +00:00
# Display the information to the user
2022-07-04 21:00:16 +00:00
UpdateCmd = $( dialog --no-shadow --keep-tite --output-fd 1 \
2022-07-05 21:23:59 +00:00
--cancel-label Exit \
2022-06-19 00:17:10 +00:00
--title "Existing Install Detected!" \
2022-07-02 19:36:16 +00:00
--menu " \\n\\nWe have detected an existing install.\
\\ n\\ nPlease choose from the following options:\
\\ n( $strAdd ) " \
2022-06-19 00:17:10 +00:00
" ${ r } " " ${ c } " 2 \
2018-07-06 04:48:36 +00:00
" ${ opt1a } " " ${ opt1b } " \
2022-10-08 19:29:10 +00:00
" ${ opt2a } " " ${ opt2b } " ) || result = $?
2022-06-19 00:17:10 +00:00
case ${ result } in
" ${ DIALOG_CANCEL } " | " ${ DIALOG_ESC } " )
2022-07-06 10:29:03 +00:00
printf " %b Cancel was selected, exiting installer%b\\n" " ${ COL_LIGHT_RED } " " ${ COL_NC } "
2022-06-19 00:17:10 +00:00
exit 1
; ;
esac
2018-07-06 04:48:36 +00:00
# Set the variable based on if the user chooses
case ${ UpdateCmd } in
# repair, or
2022-06-19 00:17:10 +00:00
" ${ opt1a } " )
2018-10-31 18:14:05 +00:00
printf " %b %s option selected\\n" " ${ INFO } " " ${ opt1a } "
2018-07-06 04:48:36 +00:00
useUpdateVars = true
; ;
# reconfigure,
2022-06-19 00:17:10 +00:00
" ${ opt2a } " )
2018-10-31 18:14:05 +00:00
printf " %b %s option selected\\n" " ${ INFO } " " ${ opt2a } "
2018-07-06 04:48:36 +00:00
useUpdateVars = false
; ;
2016-12-21 01:22:57 +00:00
esac
2016-01-01 02:26:05 +00:00
}
2018-05-01 20:59:12 +00:00
check_download_exists( ) {
2018-07-06 04:48:36 +00:00
status = $( curl --head --silent " https://ftl.pi-hole.net/ ${ 1 } " | head -n 1)
if grep -q "404" <<< " $status " ; then
return 1
else
return 0
fi
2018-05-01 20:59:12 +00:00
}
fully_fetch_repo( ) {
2018-07-06 04:48:36 +00:00
# Add upstream branches to shallow clone
local directory = " ${ 1 } "
2018-05-01 20:59:12 +00:00
2018-07-06 04:48:36 +00:00
cd " ${ directory } " || return 1
if is_repo " ${ directory } " ; then
git remote set-branches origin '*' || return 1
git fetch --quiet || return 1
else
return 1
fi
return 0
2018-05-01 20:59:12 +00:00
}
get_available_branches( ) {
2018-07-06 04:48:36 +00:00
# Return available branches
local directory
directory = " ${ 1 } "
local output
cd " ${ directory } " || return 1
# Get reachable remote branches, but store STDERR as STDOUT variable
2018-07-28 03:20:59 +00:00
output = $( { git ls-remote --heads --quiet | cut -d'/' -f3- -; } 2>& 1 )
2018-10-31 18:14:05 +00:00
# echo status for calling function to capture
2018-07-06 04:48:36 +00:00
echo " $output "
return
2018-05-01 20:59:12 +00:00
}
fetch_checkout_pull_branch( ) {
2018-07-06 04:48:36 +00:00
# Check out specified branch
local directory
directory = " ${ 1 } "
local branch
branch = " ${ 2 } "
# Set the reference for the requested branch, fetch, check it put and pull it
cd " ${ directory } " || return 1
git remote set-branches origin " ${ branch } " || return 1
git stash --all --quiet & > /dev/null || true
git clean --quiet --force -d || true
git fetch --quiet || return 1
checkout_pull_branch " ${ directory } " " ${ branch } " || return 1
2018-05-01 20:59:12 +00:00
}
checkout_pull_branch( ) {
2018-07-06 04:48:36 +00:00
# Check out specified branch
local directory
directory = " ${ 1 } "
local branch
branch = " ${ 2 } "
local oldbranch
2018-05-01 20:59:12 +00:00
2018-07-06 04:48:36 +00:00
cd " ${ directory } " || return 1
2018-05-01 20:59:12 +00:00
2018-07-06 04:48:36 +00:00
oldbranch = " $( git symbolic-ref HEAD) "
2018-05-01 20:59:12 +00:00
2018-07-06 04:48:36 +00:00
str = " Switching to branch: ' ${ branch } ' from ' ${ oldbranch } ' "
2018-10-31 18:14:05 +00:00
printf " %b %s" " ${ INFO } " " $str "
2018-07-06 04:48:36 +00:00
git checkout " ${ branch } " --quiet || return 1
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " $str "
2019-05-03 10:27:56 +00:00
# Data in the repositories is public anyway so we can make it readable by everyone (+r to keep executable permission if already set by git)
2019-05-07 08:46:16 +00:00
chmod -R a+rX " ${ directory } "
2018-05-01 20:59:12 +00:00
2021-10-06 00:19:28 +00:00
git_pull = $( git pull --no-rebase || return 1)
2018-05-01 20:59:12 +00:00
2022-08-07 13:50:05 +00:00
printf " %b %s\\n" " ${ INFO } " " ${ git_pull } "
2018-05-01 20:59:12 +00:00
2018-07-06 04:48:36 +00:00
return 0
2018-05-01 20:59:12 +00:00
}
2017-01-28 15:15:42 +00:00
clone_or_update_repos( ) {
2018-07-06 04:48:36 +00:00
# If the user wants to reconfigure,
if [ [ " ${ reconfigure } " = = true ] ] ; then
2018-10-31 18:14:05 +00:00
printf " %b Performing reconfiguration, skipping download of local repos\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
# Reset the Core repo
resetRepo ${ PI_HOLE_LOCAL_REPO } || \
2022-07-06 10:29:03 +00:00
{ printf " %b Unable to reset %s, exiting installer%b\\n" " ${ COL_LIGHT_RED } " " ${ PI_HOLE_LOCAL_REPO } " " ${ COL_NC } " ; \
2017-05-22 21:43:52 +00:00
exit 1; \
2017-01-28 15:15:42 +00:00
}
2023-02-05 18:39:48 +00:00
# Reset the Web repo
resetRepo ${ webInterfaceDir } || \
{ printf " %b Unable to reset %s, exiting installer%b\\n" " ${ COL_LIGHT_RED } " " ${ webInterfaceDir } " " ${ COL_NC } " ; \
exit 1; \
}
2018-07-06 04:48:36 +00:00
# Otherwise, a repair is happening
else
# so get git files for Core
getGitFiles ${ PI_HOLE_LOCAL_REPO } ${ piholeGitUrl } || \
2022-07-06 10:29:03 +00:00
{ printf " %b Unable to clone %s into %s, unable to continue%b\\n" " ${ COL_LIGHT_RED } " " ${ piholeGitUrl } " " ${ PI_HOLE_LOCAL_REPO } " " ${ COL_NC } " ; \
2017-05-21 20:47:26 +00:00
exit 1; \
2017-01-28 15:15:42 +00:00
}
2023-02-05 18:39:48 +00:00
# get the Web git files
getGitFiles ${ webInterfaceDir } ${ webInterfaceGitUrl } || \
{ printf " %b Unable to clone %s into ${ webInterfaceDir } , exiting installer%b\\n " " ${ COL_LIGHT_RED } " " ${ webInterfaceGitUrl } " " ${ COL_NC } " ; \
exit 1; \
}
2018-07-06 04:48:36 +00:00
fi
2017-01-28 15:15:42 +00:00
}
2018-02-23 04:13:38 +00:00
# Download FTL binary to random temp directory and install FTL binary
2019-11-14 18:52:07 +00:00
# Disable directive for SC2120 a value _can_ be passed to this function, but it is passed from an external script that sources this one
# shellcheck disable=SC2120
2017-02-20 16:24:19 +00:00
FTLinstall( ) {
2018-07-06 04:48:36 +00:00
# Local, named variables
local str = "Downloading and Installing FTL"
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Move into the temp ftl directory
2018-10-31 18:14:05 +00:00
pushd " $( mktemp -d) " > /dev/null || { printf "Unable to make temporary directory for FTL binary download\\n" ; return 1; }
2023-10-15 20:15:11 +00:00
local tempdir
tempdir = " $( pwd ) "
2018-07-06 04:48:36 +00:00
local ftlBranch
local url
if [ [ -f "/etc/pihole/ftlbranch" ] ] ; then
ftlBranch = $( </etc/pihole/ftlbranch)
else
ftlBranch = "master"
fi
2019-11-14 18:52:07 +00:00
local binary
binary = " ${ 1 } "
2018-07-06 04:48:36 +00:00
# Determine which version of FTL to download
if [ [ " ${ ftlBranch } " = = "master" ] ] ; then
2020-02-17 21:29:25 +00:00
url = "https://github.com/pi-hole/ftl/releases/latest/download"
2018-07-06 04:48:36 +00:00
else
url = " https://ftl.pi-hole.net/ ${ ftlBranch } "
fi
if curl -sSL --fail " ${ url } / ${ binary } " -o " ${ binary } " ; then
2021-03-18 01:35:27 +00:00
# If the download worked, get sha1 of the binary we just downloaded for verification.
2018-07-06 04:48:36 +00:00
curl -sSL --fail " ${ url } / ${ binary } .sha1 " -o " ${ binary } .sha1 "
# If we downloaded binary file (as opposed to text),
if sha1sum --status --quiet -c " ${ binary } " .sha1; then
2018-10-31 18:14:05 +00:00
printf "transferred... "
2019-01-09 18:26:19 +00:00
# Before stopping FTL, we download the macvendor database
2019-01-28 19:48:30 +00:00
curl -sSL "https://ftl.pi-hole.net/macvendor.db" -o " ${ PI_HOLE_CONFIG_DIR } /macvendor.db " || true
2019-01-09 18:26:19 +00:00
2019-02-01 16:39:12 +00:00
# Stop pihole-FTL service if available
2018-07-06 04:48:36 +00:00
stop_service pihole-FTL & > /dev/null
2019-02-01 16:39:12 +00:00
2018-07-06 04:48:36 +00:00
# Install the new version with the correct permissions
install -T -m 0755 " ${ binary } " /usr/bin/pihole-FTL
2019-02-01 16:39:12 +00:00
2018-07-06 04:48:36 +00:00
# Move back into the original directory the user was in
2018-10-31 18:14:05 +00:00
popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n" ; return 1; }
2018-07-06 04:48:36 +00:00
2019-02-01 16:39:12 +00:00
# Installed the FTL service
2018-10-31 18:14:05 +00:00
printf "%b %b %s\\n" " ${ OVER } " " ${ TICK } " " ${ str } "
2023-10-15 20:15:11 +00:00
# Remove temp dir
remove_dir " ${ tempdir } "
2018-07-06 04:48:36 +00:00
return 0
else
2021-03-18 01:35:27 +00:00
# Otherwise, the hash download failed, so print and exit.
2018-10-31 18:14:05 +00:00
popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n" ; return 1; }
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
2022-07-06 10:29:03 +00:00
printf " %b Error: Download of %s/%s failed (checksum error)%b\\n" " ${ COL_LIGHT_RED } " " ${ url } " " ${ binary } " " ${ COL_NC } "
2023-10-15 20:15:11 +00:00
# Remove temp dir
remove_dir " ${ tempdir } "
2018-07-06 04:48:36 +00:00
return 1
fi
2017-02-20 17:36:24 +00:00
else
2021-03-18 01:35:27 +00:00
# Otherwise, the download failed, so print and exit.
2018-10-31 18:14:05 +00:00
popd > /dev/null || { printf "Unable to return to original directory after FTL binary download.\\n" ; return 1; }
printf "%b %b %s\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
2018-07-06 04:48:36 +00:00
# The URL could not be found
2022-07-06 10:29:03 +00:00
printf " %b Error: URL %s/%s not found%b\\n" " ${ COL_LIGHT_RED } " " ${ url } " " ${ binary } " " ${ COL_NC } "
2023-10-15 20:15:11 +00:00
# Remove temp dir
remove_dir " ${ tempdir } "
2018-07-06 04:48:36 +00:00
return 1
fi
2017-02-20 16:24:19 +00:00
}
2023-10-15 20:15:11 +00:00
remove_dir( ) {
# Delete dir
rm -r " ${ 1 } " > /dev/null 2>& 1 || \
echo -e " ${ CROSS } Unable to remove ${ 1 } "
}
2018-04-02 20:53:32 +00:00
get_binary_name( ) {
2023-10-22 06:32:52 +00:00
local l_binary
2018-07-06 04:48:36 +00:00
local machine
machine = $( uname -m)
2020-10-13 13:18:14 +00:00
local str = "Detecting processor"
2018-10-31 18:14:05 +00:00
printf " %b %s..." " ${ INFO } " " ${ str } "
2023-10-22 06:32:52 +00:00
# If the machine is aarch64 (armv8)
if [ [ " ${ machine } " = = "aarch64" ] ] ; then
# If AArch64 is found (e.g., BCM2711 in Raspberry Pi 4)
printf "%b %b Detected AArch64 (64 Bit ARM) architecture\\n" " ${ OVER } " " ${ TICK } "
l_binary = "pihole-FTL-arm64"
elif [ [ " ${ machine } " = = "arm" * ] ] ; then
# ARM 32 bit
2023-06-08 12:10:04 +00:00
# Get supported processor from other binaries installed on the system
2023-10-22 06:32:52 +00:00
# We cannot really rely on the output of $(uname -m) above as this may
# return an incorrect architecture when buildx-compiling with QEMU
2023-06-08 12:10:04 +00:00
local cpu_arch
cpu_arch = $( readelf -A " $( command -v sh) " | grep Tag_CPU_arch | awk '{ print $2 }' )
# Get the revision from the CPU architecture
2018-07-06 04:48:36 +00:00
local rev
2023-06-08 12:10:04 +00:00
rev = $( echo " ${ cpu_arch } " | grep -o '[0-9]*' )
2023-10-22 06:32:52 +00:00
if [ [ " ${ rev } " -eq 6 ] ] ; then
2023-10-21 17:13:45 +00:00
# If ARMv6 is found (e.g., BCM2835 in Raspberry Pi 1 and Zero)
2023-10-19 20:04:11 +00:00
printf "%b %b Detected ARMv6 architecture\\n" " ${ OVER } " " ${ TICK } "
2023-10-21 17:13:45 +00:00
l_binary = "pihole-FTL-armv6"
2023-10-21 17:28:59 +00:00
elif [ [ " ${ rev } " -ge 7 ] ] ; then
2023-10-21 17:13:45 +00:00
# If ARMv7 or higher is found (e.g., BCM2836 in Raspberry PI 2 Mod. B)
# This path is also used for ARMv8 when the OS is in 32bit mode
# (e.g., BCM2837 in Raspberry Pi Model 3B, or BCM2711 in Raspberry Pi 4)
printf "%b %b Detected ARMv7 (or newer) architecture (%s)\\n" " ${ OVER } " " ${ TICK } " " ${ cpu_arch } "
l_binary = "pihole-FTL-armv7"
2023-06-08 12:10:04 +00:00
else
2023-10-21 17:13:45 +00:00
# Otherwise, Pi-hole does not support this architecture
printf "%b %b This processor architecture is not supported by Pi-hole (%s)\\n" " ${ OVER } " " ${ CROSS } " " ${ cpu_arch } "
l_binary = ""
2018-07-06 04:48:36 +00:00
fi
elif [ [ " ${ machine } " = = "x86_64" ] ] ; then
2020-10-13 13:18:14 +00:00
# This gives the processor of packages dpkg installs (for example, "i386")
2018-07-06 04:48:36 +00:00
local dpkgarch
2020-12-23 22:59:28 +00:00
dpkgarch = $( dpkg --print-processor 2> /dev/null || dpkg --print-architecture 2> /dev/null)
2018-07-06 04:48:36 +00:00
# Special case: This is a 32 bit OS, installed on a 64 bit machine
2020-10-13 13:18:14 +00:00
# -> change machine processor to download the 32 bit executable
2019-02-22 17:32:36 +00:00
# We only check this for Debian-based systems as this has been an issue
# in the past (see https://github.com/pi-hole/pi-hole/pull/2004)
2018-07-06 04:48:36 +00:00
if [ [ " ${ dpkgarch } " = = "i386" ] ] ; then
2023-06-08 12:10:04 +00:00
printf "%b %b Detected 32bit (i686) architecture\\n" " ${ OVER } " " ${ TICK } "
2023-05-31 00:22:53 +00:00
l_binary = "pihole-FTL-386"
2018-07-06 04:48:36 +00:00
else
2023-10-21 17:13:45 +00:00
# 64bit OS
2023-06-08 12:10:04 +00:00
printf "%b %b Detected x86_64 architecture\\n" " ${ OVER } " " ${ TICK } "
2023-05-31 00:22:53 +00:00
l_binary = "pihole-FTL-amd64"
2018-07-06 04:48:36 +00:00
fi
2023-03-05 18:02:09 +00:00
elif [ [ " ${ machine } " = = "riscv64" ] ] ; then
2023-06-08 12:10:04 +00:00
printf "%b %b Detected riscv64 architecture\\n" " ${ OVER } " " ${ TICK } "
2023-05-31 00:22:53 +00:00
l_binary = "pihole-FTL-riscv64"
2017-02-13 15:50:48 +00:00
else
2018-07-06 04:48:36 +00:00
# Something else - we try to use 32bit executable and warn the user
if [ [ ! " ${ machine } " = = "i686" ] ] ; then
2018-10-31 18:14:05 +00:00
printf "%b %b %s...\\n" " ${ OVER } " " ${ CROSS } " " ${ str } "
2023-06-08 12:10:04 +00:00
printf " %b %bNot able to detect architecture (unknown: %s), trying x86 (32bit) executable%b\\n" " ${ INFO } " " ${ COL_LIGHT_RED } " " ${ machine } " " ${ COL_NC } "
2018-10-31 18:14:05 +00:00
printf " %b Contact Pi-hole Support if you experience issues (e.g: FTL not running)\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
else
2023-06-08 12:10:04 +00:00
printf "%b %b Detected 32bit (i686) architecture\\n" " ${ OVER } " " ${ TICK } "
2018-07-06 04:48:36 +00:00
fi
2023-05-31 00:22:53 +00:00
l_binary = "pihole-FTL-linux-386"
2017-02-13 13:42:11 +00:00
fi
2019-11-14 18:52:07 +00:00
2021-03-18 01:35:27 +00:00
# Returning a string value via echo
2019-11-14 18:52:07 +00:00
echo ${ l_binary }
2018-04-02 20:53:32 +00:00
}
2017-02-13 09:29:27 +00:00
2018-07-06 04:48:36 +00:00
FTLcheckUpdate( ) {
#In the next section we check to see if FTL is already installed (in case of pihole -r).
#If the installed version matches the latest version, then check the installed sha1sum of the binary vs the remote sha1sum. If they do not match, then download
2018-10-31 18:14:05 +00:00
printf " %b Checking for existing FTL binary...\\n" " ${ INFO } "
2017-07-12 21:02:07 +00:00
2018-07-06 04:48:36 +00:00
local ftlLoc
2022-01-01 18:02:20 +00:00
ftlLoc = $( command -v pihole-FTL 2>/dev/null)
2018-03-18 00:38:34 +00:00
2018-07-06 04:48:36 +00:00
local ftlBranch
2018-03-18 00:38:34 +00:00
2018-07-06 04:48:36 +00:00
if [ [ -f "/etc/pihole/ftlbranch" ] ] ; then
ftlBranch = $( </etc/pihole/ftlbranch)
else
ftlBranch = "master"
2018-05-01 20:59:12 +00:00
fi
2019-11-14 18:52:07 +00:00
local binary
binary = " ${ 1 } "
2018-07-06 04:48:36 +00:00
local remoteSha1
local localSha1
2018-04-02 20:53:32 +00:00
2018-07-06 04:48:36 +00:00
if [ [ ! " ${ ftlBranch } " = = "master" ] ] ; then
#Check whether or not the binary for this FTL branch actually exists. If not, then there is no update!
local path
path = " ${ ftlBranch } / ${ binary } "
# shellcheck disable=SC1090
if ! check_download_exists " $path " ; then
2018-10-31 18:14:05 +00:00
printf " %b Branch \"%s\" is not available.\\n" " ${ INFO } " " ${ ftlBranch } "
printf " %b Use %bpihole checkout ftl [branchname]%b to switch to a valid branch.\\n" " ${ INFO } " " ${ COL_LIGHT_GREEN } " " ${ COL_NC } "
2018-07-06 04:48:36 +00:00
return 2
fi
2017-07-12 21:02:07 +00:00
2018-07-06 04:48:36 +00:00
if [ [ ${ ftlLoc } ] ] ; then
# We already have a pihole-FTL binary downloaded.
# Alt branches don't have a tagged version against them, so just confirm the checksum of the local vs remote to decide whether we download or not
remoteSha1 = $( curl -sSL --fail " https://ftl.pi-hole.net/ ${ ftlBranch } / ${ binary } .sha1 " | cut -d ' ' -f 1)
2022-01-01 18:02:20 +00:00
localSha1 = $( sha1sum " $( command -v pihole-FTL) " | cut -d ' ' -f 1)
2018-07-06 04:48:36 +00:00
if [ [ " ${ remoteSha1 } " != " ${ localSha1 } " ] ] ; then
2018-10-31 18:14:05 +00:00
printf " %b Checksums do not match, downloading from ftl.pi-hole.net.\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
return 0
else
2018-10-31 18:14:05 +00:00
printf " %b Checksum of installed binary matches remote. No need to download!\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
return 1
fi
2018-03-06 18:44:57 +00:00
else
2018-07-06 04:48:36 +00:00
return 0
2018-03-06 18:44:57 +00:00
fi
else
2018-07-06 04:48:36 +00:00
if [ [ ${ ftlLoc } ] ] ; then
local FTLversion
FTLversion = $( /usr/bin/pihole-FTL tag)
local FTLlatesttag
2021-01-12 21:42:51 +00:00
if ! FTLlatesttag = $( curl -sI https://github.com/pi-hole/FTL/releases/latest | grep --color= never -i Location: | awk -F / '{print $NF}' | tr -d '[:cntrl:]' ) ; then
2019-06-29 03:49:56 +00:00
# There was an issue while retrieving the latest version
2019-07-20 00:35:21 +00:00
printf " %b Failed to retrieve latest FTL release metadata" " ${ CROSS } "
2019-06-29 03:49:56 +00:00
return 3
fi
2018-07-06 04:48:36 +00:00
if [ [ " ${ FTLversion } " != " ${ FTLlatesttag } " ] ] ; then
return 0
else
2018-10-31 18:14:05 +00:00
printf " %b Latest FTL Binary already installed (%s). Confirming Checksum...\\n" " ${ INFO } " " ${ FTLlatesttag } "
2018-07-06 04:48:36 +00:00
remoteSha1 = $( curl -sSL --fail " https://github.com/pi-hole/FTL/releases/download/ ${ FTLversion % $'\r' } / ${ binary } .sha1 " | cut -d ' ' -f 1)
2022-01-01 18:02:20 +00:00
localSha1 = $( sha1sum " $( command -v pihole-FTL) " | cut -d ' ' -f 1)
2018-07-06 04:48:36 +00:00
if [ [ " ${ remoteSha1 } " != " ${ localSha1 } " ] ] ; then
2018-10-31 18:14:05 +00:00
printf " %b Corruption detected...\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
return 0
else
2018-10-31 18:14:05 +00:00
printf " %b Checksum correct. No need to download!\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
return 1
fi
fi
else
return 0
fi
2018-03-06 18:44:57 +00:00
fi
2018-04-02 20:53:32 +00:00
}
# Detect suitable FTL binary platform
FTLdetect( ) {
2018-10-31 18:14:05 +00:00
printf "\\n %b FTL Checks...\\n\\n" " ${ INFO } "
2018-04-02 20:53:32 +00:00
2019-11-14 18:52:07 +00:00
printf " %b" " ${ 2 } "
if FTLcheckUpdate " ${ 1 } " ; then
FTLinstall " ${ 1 } " || return 1
2018-07-06 04:48:36 +00:00
fi
2018-01-20 13:55:48 +00:00
}
2017-07-25 21:49:06 +00:00
2018-01-20 13:55:48 +00:00
make_temporary_log( ) {
2018-07-06 04:48:36 +00:00
# Create a random temporary file for the log
TEMPLOG = $( mktemp /tmp/pihole_temp.XXXXXX)
# Open handle 3 for templog
# https://stackoverflow.com/questions/18460186/writing-outputs-to-log-file-and-console
exec 3>" $TEMPLOG "
# Delete templog, but allow for addressing via file handle
# This lets us write to the log without having a temporary file on the drive, which
# is meant to be a security measure so there is not a lingering file on the drive during the install process
rm " $TEMPLOG "
2018-01-20 13:55:48 +00:00
}
2017-02-13 13:47:06 +00:00
2018-01-20 13:55:48 +00:00
copy_to_install_log( ) {
2018-07-06 04:48:36 +00:00
# Copy the contents of file descriptor 3 into the install log
# Since we use color codes such as '\e[1;33m', they should be removed
sed 's/ \[[0-9;]\{1,5\}m//g' < /proc/$$ /fd/3 > " ${ installLogLoc } "
2019-05-01 09:20:26 +00:00
chmod 644 " ${ installLogLoc } "
2023-10-09 20:35:02 +00:00
chown pihole:pihole " ${ installLogLoc } "
2017-02-13 10:07:29 +00:00
}
2017-02-13 09:29:27 +00:00
2016-10-08 19:17:04 +00:00
main( ) {
2018-07-06 04:48:36 +00:00
######## FIRST CHECK ########
# Must be root to install
local str = "Root user check"
2018-10-31 18:14:05 +00:00
printf "\\n"
2018-07-06 04:48:36 +00:00
# If the user's id is zero,
if [ [ " ${ EUID } " -eq 0 ] ] ; then
# they are root and all is good
2018-10-31 18:14:05 +00:00
printf " %b %s\\n" " ${ TICK } " " ${ str } "
2018-07-06 04:48:36 +00:00
# Show the Pi-hole logo so people know it's genuine since the logo and name are trademarked
show_ascii_berry
make_temporary_log
2017-01-01 14:45:03 +00:00
else
2021-03-18 01:35:27 +00:00
# Otherwise, they do not have enough privileges, so let the user know
2020-10-29 19:37:08 +00:00
printf " %b %s\\n" " ${ INFO } " " ${ str } "
2018-10-31 18:14:05 +00:00
printf " %b %bScript called with non-root privileges%b\\n" " ${ INFO } " " ${ COL_LIGHT_RED } " " ${ COL_NC } "
printf " The Pi-hole requires elevated privileges to install and run\\n"
printf " Please check the installer for any concerns regarding this requirement\\n"
printf " Make sure to download this script from a trusted source\\n\\n"
printf " %b Sudo utility check" " ${ INFO } "
2018-07-06 04:48:36 +00:00
2021-03-18 01:35:27 +00:00
# If the sudo command exists, try rerunning as admin
2018-11-01 19:00:08 +00:00
if is_command sudo ; then
2018-10-31 18:14:05 +00:00
printf "%b %b Sudo utility check\\n" " ${ OVER } " " ${ TICK } "
2020-10-30 15:53:20 +00:00
# when run via curl piping
if [ [ " $0 " = = "bash" ] ] ; then
# Download the install script and run it with admin rights
2023-02-05 18:39:48 +00:00
exec curl -sSL https://install.pi-hole.net | sudo bash " $@ "
2020-10-30 15:53:20 +00:00
else
# when run via calling local bash script
exec sudo bash " $0 " " $@ "
fi
2018-07-06 04:48:36 +00:00
exit $?
else
2021-03-18 01:35:27 +00:00
# Otherwise, tell the user they need to run the script as root, and bail
2018-10-31 18:14:05 +00:00
printf "%b %b Sudo utility check\\n" " ${ OVER } " " ${ CROSS } "
printf " %b Sudo is needed for the Web Interface to run pihole commands\\n\\n" " ${ INFO } "
printf " %b %bPlease re-run this installer as root ${ COL_NC } \\n " " ${ INFO } " " ${ COL_LIGHT_RED } "
2018-07-06 04:48:36 +00:00
exit 1
fi
fi
2022-07-04 21:00:16 +00:00
# Check if SELinux is Enforcing and exit before doing anything else
checkSelinux
2021-08-03 21:53:29 +00:00
# Check for supported package managers so that we may install dependencies
2021-08-03 20:48:26 +00:00
package_manager_detect
2018-07-06 04:48:36 +00:00
# Notify user of package availability
notify_package_updates_available
2021-08-03 21:48:03 +00:00
# Install packages necessary to perform os_check
2021-08-03 22:26:59 +00:00
printf " %b Checking for / installing Required dependencies for OS Check...\\n" " ${ INFO } "
2021-08-03 21:48:03 +00:00
install_dependent_packages " ${ OS_CHECK_DEPS [@] } "
2018-07-06 04:48:36 +00:00
2020-06-13 20:33:03 +00:00
# Check that the installed OS is officially supported - display warning if not
os_check
2023-10-21 19:40:21 +00:00
# Check if there is a usable FTL binary available on this architecture - do
# this early on as FTL is a hard dependency for Pi-hole
local funcOutput
funcOutput = $( get_binary_name) #Store output of get_binary_name here
# Abort early if this processor is not supported (get_binary_name returns empty string)
if [ [ " ${ funcOutput } " = = "" ] ] ; then
printf " %b Upgrade/install aborted\\n" " ${ CROSS } " " ${ DISTRO_NAME } "
exit 1
fi
2021-08-03 21:48:03 +00:00
# Install packages used by this installation script
2021-08-03 22:26:59 +00:00
printf " %b Checking for / installing Required dependencies for this install script...\\n" " ${ INFO } "
2021-08-03 21:48:03 +00:00
install_dependent_packages " ${ INSTALLER_DEPS [@] } "
2023-02-05 18:59:38 +00:00
# if it's running unattended,
if [ [ " ${ runUnattended } " = = true ] ] ; then
printf " %b Performing unattended setup, no dialogs will be displayed\\n" " ${ INFO } "
# Use the setup variables
useUpdateVars = true
# also disable debconf-apt-progress dialogs
export DEBIAN_FRONTEND = "noninteractive"
else
# If running attended, show the available options (repair/reconfigure)
update_dialogs
2021-08-03 21:53:29 +00:00
fi
2018-07-06 04:48:36 +00:00
if [ [ " ${ useUpdateVars } " = = false ] ] ; then
# Display welcome dialogs
welcomeDialogs
2023-10-09 20:05:01 +00:00
# Create directory for Pi-hole storage (/etc/pihole/)
2023-10-09 20:35:02 +00:00
install -d -m 755 " ${ PI_HOLE_CONFIG_DIR } "
2018-07-06 04:48:36 +00:00
# Determine available interfaces
get_available_interfaces
# Find interfaces and let the user choose one
chooseInterface
2021-11-06 20:32:03 +00:00
# find IPv4 and IPv6 information of the device
collect_v4andv6_information
2018-07-06 04:48:36 +00:00
# Decide what upstream DNS Servers to use
setDNS
# Give the user a choice of blocklists to include in their install. Or not.
chooseBlocklists
# Let the user decide if they want query logging enabled...
setLogging
2018-08-20 23:04:58 +00:00
# Let the user decide the FTL privacy level
setPrivacyLevel
2017-07-26 13:34:40 +00:00
else
2018-08-12 21:19:16 +00:00
# Setup adlist file if not exists
installDefaultBlocklists
2018-07-06 04:48:36 +00:00
fi
2021-03-18 01:35:27 +00:00
# Download or update the scripts by updating the appropriate git repos
2018-07-06 04:48:36 +00:00
clone_or_update_repos
# Install the Core dependencies
local dep_install_list = ( " ${ PIHOLE_DEPS [@] } " )
2021-08-03 22:26:59 +00:00
# Install packages used by the actual software
printf " %b Checking for / installing Required dependencies for Pi-hole software...\\n" " ${ INFO } "
2019-05-10 14:37:38 +00:00
install_dependent_packages " ${ dep_install_list [@] } "
2018-07-06 04:48:36 +00:00
unset dep_install_list
2019-05-12 09:27:25 +00:00
# Create the pihole user
create_pihole_user
2019-11-14 18:52:07 +00:00
2023-05-31 00:22:53 +00:00
# Download and install FTL
2021-08-03 22:11:22 +00:00
local binary
binary = " pihole-FTL ${ funcOutput ##*pihole-FTL } " #binary name will be the last line of the output of get_binary_name (it always begins with pihole-FTL)
local theRest
theRest = " ${ funcOutput %pihole-FTL* } " # Print the rest of get_binary_name's output to display (cut out from first instance of "pihole-FTL")
if ! FTLdetect " ${ binary } " " ${ theRest } " ; then
printf " %b FTL Engine not installed\\n" " ${ CROSS } "
exit 1
fi
2018-07-06 04:48:36 +00:00
# Install and log everything to a file
installPihole | tee -a /proc/$$ /fd/3
2018-05-14 09:38:12 +00:00
2018-07-06 04:48:36 +00:00
# Copy the temp log file into final log location for storage
copy_to_install_log
2017-02-21 10:18:47 +00:00
2023-02-05 18:39:48 +00:00
# Add password to web UI if there is none
pw = ""
# If no password is set,
2023-02-05 18:59:38 +00:00
if [ [ $( pihole-FTL --config webserver.api.pwhash) = = '""' ] ] ; then
2023-02-05 18:39:48 +00:00
# generate a random password
pw = $( tr -dc _A-Z-a-z-0-9 < /dev/urandom | head -c 8)
pihole -a -p " ${ pw } "
2018-07-06 04:48:36 +00:00
fi
2018-07-26 23:27:06 +00:00
# Check for and disable systemd-resolved-DNSStubListener before reloading resolved
2018-07-06 04:48:36 +00:00
# DNSStubListener needs to remain in place for installer to download needed files,
# so this change needs to be made after installation is complete,
2023-10-04 15:22:01 +00:00
# but before starting or restarting the ftl service
2018-07-26 23:27:06 +00:00
disable_resolved_stublistener
2018-07-06 04:48:36 +00:00
2018-10-31 18:14:05 +00:00
printf " %b Restarting services...\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
# Start services
2018-07-26 23:27:06 +00:00
2018-08-20 20:52:22 +00:00
# Enable FTL
2018-08-16 15:52:47 +00:00
# Ensure the service is enabled before trying to start it
# Fixes a problem reported on Ubuntu 18.04 where trying to start
# the service before enabling causes installer to exit
2018-07-06 04:48:36 +00:00
enable_service pihole-FTL
2022-05-18 19:11:38 +00:00
# If this is an update from a previous Pi-hole installation
# we need to move any existing `pihole*` logs from `/var/log` to `/var/log/pihole`
2022-07-03 16:54:13 +00:00
# if /var/log/pihole.log is not a symlink (set during FTL startup) move the files
2022-05-18 19:11:38 +00:00
# can be removed with Pi-hole v6.0
# To be sure FTL is not running when we move the files we explicitly stop it here
stop_service pihole-FTL & > /dev/null
2022-07-07 20:50:41 +00:00
if [ ! -d /var/log/pihole/ ] ; then
2022-07-08 21:20:30 +00:00
mkdir -m 0755 /var/log/pihole/
2022-07-07 20:23:13 +00:00
fi
2022-07-03 16:54:13 +00:00
# Special handling for pihole-FTL.log -> pihole/FTL.log
if [ -f /var/log/pihole-FTL.log ] && [ ! -L /var/log/pihole-FTL.log ] ; then
# /var/log/pihole-FTL.log -> /var/log/pihole/FTL.log
# /var/log/pihole-FTL.log.1 -> /var/log/pihole/FTL.log.1
# /var/log/pihole-FTL.log.2.gz -> /var/log/pihole/FTL.log.2.gz
# /var/log/pihole-FTL.log.3.gz -> /var/log/pihole/FTL.log.3.gz
# /var/log/pihole-FTL.log.4.gz -> /var/log/pihole/FTL.log.4.gz
# /var/log/pihole-FTL.log.5.gz -> /var/log/pihole/FTL.log.5.gz
for f in /var/log/pihole-FTL.log*; do mv " $f " " $( sed "s/pihole-/pihole\//" <<< " $f " ) " ; done
fi
# Remaining log files
2022-05-18 19:11:38 +00:00
if [ -f /var/log/pihole.log ] && [ ! -L /var/log/pihole.log ] ; then
mv /var/log/pihole*.* /var/log/pihole/ 2>/dev/null
fi
2019-01-24 08:37:03 +00:00
restart_service pihole-FTL
2017-09-20 07:29:11 +00:00
2022-12-29 20:59:23 +00:00
# Download and compile the aggregated block list
runGravity
2023-01-19 20:41:32 +00:00
# Update local and remote versions via updatechecker
/opt/pihole/updatecheck.sh
2018-07-06 04:48:36 +00:00
if [ [ " ${ useUpdateVars } " = = false ] ] ; then
displayFinalMessage " ${ pw } "
2017-06-21 11:49:05 +00:00
fi
2017-01-28 15:25:02 +00:00
2023-02-05 18:39:48 +00:00
# If there is a password
if ( ( ${# pw } > 0 ) ) ; then
# display the password
printf " %b Web Interface password: %b%s%b\\n" " ${ INFO } " " ${ COL_LIGHT_GREEN } " " ${ pw } " " ${ COL_NC } "
printf " %b This can be changed using 'pihole -a -p'\\n\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
fi
if [ [ " ${ useUpdateVars } " = = false ] ] ; then
# If the Web interface was installed,
2023-02-05 18:39:48 +00:00
printf " %b View the web interface at http://pi.hole: ${ WEBPORT } /admin or http://%s/admin\\n\\n " " ${ INFO } " " ${ IPV4_ADDRESS %/* } : ${ WEBPORT } "
2018-07-06 04:48:36 +00:00
# Explain to the user how to use Pi-hole as their DNS server
2018-10-31 18:14:05 +00:00
printf " %b You may now configure your devices to use the Pi-hole as their DNS server\\n" " ${ INFO } "
[ [ -n " ${ IPV4_ADDRESS %/* } " ] ] && printf " %b Pi-hole DNS (IPv4): %s\\n" " ${ INFO } " " ${ IPV4_ADDRESS %/* } "
[ [ -n " ${ IPV6_ADDRESS } " ] ] && printf " %b Pi-hole DNS (IPv6): %s\\n" " ${ INFO } " " ${ IPV6_ADDRESS } "
2021-08-03 22:43:48 +00:00
printf " %b If you have not done so already, the above IP should be set to static.\\n" " ${ INFO } "
2018-07-06 04:48:36 +00:00
INSTALL_TYPE = "Installation"
else
INSTALL_TYPE = "Update"
fi
2017-06-29 01:18:52 +00:00
2018-07-06 04:48:36 +00:00
# Display where the log file is
2018-10-31 18:14:05 +00:00
printf "\\n %b The install log is located at: %s\\n" " ${ INFO } " " ${ installLogLoc } "
2022-07-29 21:43:20 +00:00
printf " %b %b%s complete! %b\\n" " ${ TICK } " " ${ COL_LIGHT_GREEN } " " ${ INSTALL_TYPE } " " ${ COL_NC } "
2017-07-26 13:34:40 +00:00
2018-07-06 04:48:36 +00:00
if [ [ " ${ INSTALL_TYPE } " = = "Update" ] ] ; then
2018-10-31 18:14:05 +00:00
printf "\\n"
2019-08-24 11:57:23 +00:00
" ${ PI_HOLE_BIN_DIR } " /pihole version --current
2018-07-06 04:48:36 +00:00
fi
2016-10-08 19:17:04 +00:00
}
2022-07-06 20:51:39 +00:00
# allow to source this script without running it
if [ [ " ${ SKIP_INSTALL } " != true ] ] ; then
2018-07-06 04:48:36 +00:00
main " $@ "
2016-10-11 04:14:39 +00:00
fi