From 1358209a9ae75eb09fefdd9d5032c914c7f9a4d3 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 3 Aug 2021 21:48:26 +0100 Subject: [PATCH 1/7] rename distro_check to package_manager_detect, as it is more in keeping with what the function actually does Signed-off-by: Adam Warner --- automated install/basic-install.sh | 6 ++--- automated install/uninstall.sh | 6 ++--- test/test_automated_install.py | 24 +++++++++---------- test/test_centos_7_support.py | 22 ++++++++--------- test/test_centos_8_support.py | 22 ++++++++--------- test/test_centos_common_support.py | 38 +++++++++++++++--------------- test/test_fedora_support.py | 6 ++--- 7 files changed, 62 insertions(+), 62 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 96d0b693..0d674b2f 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -276,7 +276,7 @@ os_check() { } # Compatibility -distro_check() { +package_manager_detect() { # If apt-get is installed, then we know it's part of the Debian family if is_command apt-get ; then # Set some global variables here @@ -1950,7 +1950,7 @@ installLogrotate() { if [[ -f ${target} ]]; then 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. + # the function did not complete. return 2 fi # Copy the file over from the local repo @@ -2643,7 +2643,7 @@ main() { fi # Check for supported distribution - distro_check + package_manager_detect # If the setup variable file exists, if [[ -f "${setupVars}" ]]; then diff --git a/automated install/uninstall.sh b/automated install/uninstall.sh index 543ca07a..0f4c4ca6 100755 --- a/automated install/uninstall.sh +++ b/automated install/uninstall.sh @@ -42,8 +42,8 @@ source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" # setupVars set in basic-install.sh source "${setupVars}" -# distro_check() sourced from basic-install.sh -distro_check +# package_manager_detect() sourced from basic-install.sh +package_manager_detect # Install packages used by the Pi-hole DEPS=("${INSTALLER_DEPS[@]}" "${PIHOLE_DEPS[@]}") @@ -113,7 +113,7 @@ removeNoPurge() { fi fi echo -e "${OVER} ${TICK} Removed Web Interface" - + # Attempt to preserve backwards compatibility with older versions # to guarantee no additional changes were made to /etc/crontab after # the installation of pihole, /etc/crontab.pihole should be permanently diff --git a/test/test_automated_install.py b/test/test_automated_install.py index b3078f5a..21468cd7 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -18,13 +18,13 @@ def test_supported_operating_system(Pihole): # break supported package managers to emulate an unsupported distribution Pihole.run('rm -rf /usr/bin/apt-get') Pihole.run('rm -rf /usr/bin/rpm') - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') expected_stdout = cross_box + ' OS distribution not supported' - assert expected_stdout in distro_check.stdout - # assert distro_check.rc == 1 + assert expected_stdout in package_manager_detect.stdout + # assert package_manager_detect.rc == 1 def test_setupVars_are_sourced_to_global_scope(Pihole): @@ -135,7 +135,7 @@ def test_update_package_cache_success_no_errors(Pihole): ''' updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect update_package_cache ''') expected_stdout = tick_box + ' Update local cache of available packages' @@ -150,7 +150,7 @@ def test_update_package_cache_failure_no_errors(Pihole): mock_command('apt-get', {'update': ('', '1')}, Pihole) updateCache = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect update_package_cache ''') expected_stdout = cross_box + ' Update local cache of available packages' @@ -357,7 +357,7 @@ def test_FTL_download_aarch64_no_errors(Pihole): mock_command('whiptail', {'*': ('', '0')}, Pihole) Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect install_dependent_packages ${INSTALLER_DEPS[@]} ''') download_binary = Pihole.run(''' @@ -567,7 +567,7 @@ def test_os_check_fails(Pihole): ''' Confirms install fails on unsupported OS ''' Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect install_dependent_packages ${INSTALLER_DEPS[@]} cat < /etc/os-release ID=UnsupportedOS @@ -586,7 +586,7 @@ def test_os_check_passes(Pihole): ''' Confirms OS meets the requirements ''' Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect install_dependent_packages ${INSTALLER_DEPS[@]} ''') detectOS = Pihole.run(''' @@ -602,7 +602,7 @@ def test_package_manager_has_installer_deps(Pihole): mock_command('whiptail', {'*': ('', '0')}, Pihole) output = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect install_dependent_packages ${INSTALLER_DEPS[@]} ''') @@ -615,7 +615,7 @@ def test_package_manager_has_pihole_deps(Pihole): mock_command('whiptail', {'*': ('', '0')}, Pihole) output = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect install_dependent_packages ${PIHOLE_DEPS[@]} ''') @@ -628,7 +628,7 @@ def test_package_manager_has_web_deps(Pihole): mock_command('whiptail', {'*': ('', '0')}, Pihole) output = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect install_dependent_packages ${PIHOLE_WEB_DEPS[@]} ''') diff --git a/test/test_centos_7_support.py b/test/test_centos_7_support.py index 2f744ab4..ed99231a 100644 --- a/test/test_centos_7_support.py +++ b/test/test_centos_7_support.py @@ -9,13 +9,13 @@ def test_php_upgrade_default_optout_centos_eq_7(Pihole): ''' confirms the default behavior to opt-out of installing PHP7 from REMI ''' - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' 'Deprecated PHP may be in use.') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout remi_package = Pihole.package('remi-release') assert not remi_package.is_installed @@ -27,13 +27,13 @@ def test_php_upgrade_user_optout_centos_eq_7(Pihole): ''' # Whiptail dialog returns Cancel for user prompt mock_command('whiptail', {'*': ('', '1')}, Pihole) - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' 'Deprecated PHP may be in use.') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout remi_package = Pihole.package('remi-release') assert not remi_package.is_installed @@ -45,16 +45,16 @@ def test_php_upgrade_user_optin_centos_eq_7(Pihole): ''' # Whiptail dialog returns Continue for user prompt mock_command('whiptail', {'*': ('', '0')}, Pihole) - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') - assert 'opt-out' not in distro_check.stdout + assert 'opt-out' not in package_manager_detect.stdout expected_stdout = info_box + (' Enabling Remi\'s RPM repository ' '(https://rpms.remirepo.net)') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout expected_stdout = tick_box + (' Remi\'s RPM repository has ' 'been enabled for PHP7') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout remi_package = Pihole.package('remi-release') assert remi_package.is_installed diff --git a/test/test_centos_8_support.py b/test/test_centos_8_support.py index d3e83658..b8ad9607 100644 --- a/test/test_centos_8_support.py +++ b/test/test_centos_8_support.py @@ -10,13 +10,13 @@ def test_php_upgrade_default_continue_centos_gte_8(Pihole): confirms the latest version of CentOS continues / does not optout (should trigger on CentOS7 only) ''' - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' ' Deprecated PHP may be in use.') - assert unexpected_stdout not in distro_check.stdout + assert unexpected_stdout not in package_manager_detect.stdout # ensure remi was not installed on latest CentOS remi_package = Pihole.package('remi-release') assert not remi_package.is_installed @@ -30,13 +30,13 @@ def test_php_upgrade_user_optout_skipped_centos_gte_8(Pihole): ''' # Whiptail dialog returns Cancel for user prompt mock_command('whiptail', {'*': ('', '1')}, Pihole) - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') unexpected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS.' ' Deprecated PHP may be in use.') - assert unexpected_stdout not in distro_check.stdout + assert unexpected_stdout not in package_manager_detect.stdout # ensure remi was not installed on latest CentOS remi_package = Pihole.package('remi-release') assert not remi_package.is_installed @@ -50,16 +50,16 @@ def test_php_upgrade_user_optin_skipped_centos_gte_8(Pihole): ''' # Whiptail dialog returns Continue for user prompt mock_command('whiptail', {'*': ('', '0')}, Pihole) - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') - assert 'opt-out' not in distro_check.stdout + assert 'opt-out' not in package_manager_detect.stdout unexpected_stdout = info_box + (' Enabling Remi\'s RPM repository ' '(https://rpms.remirepo.net)') - assert unexpected_stdout not in distro_check.stdout + assert unexpected_stdout not in package_manager_detect.stdout unexpected_stdout = tick_box + (' Remi\'s RPM repository has ' 'been enabled for PHP7') - assert unexpected_stdout not in distro_check.stdout + assert unexpected_stdout not in package_manager_detect.stdout remi_package = Pihole.package('remi-release') assert not remi_package.is_installed diff --git a/test/test_centos_common_support.py b/test/test_centos_common_support.py index fdf43cba..8412173d 100644 --- a/test/test_centos_common_support.py +++ b/test/test_centos_common_support.py @@ -13,29 +13,29 @@ def test_release_supported_version_check_centos(Pihole): ''' # modify /etc/redhat-release to mock an unsupported CentOS release Pihole.run('echo "CentOS Linux release 6.9" > /etc/redhat-release') - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') expected_stdout = cross_box + (' CentOS 6 is not supported.') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout expected_stdout = 'Please update to CentOS release 7 or later' - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout def test_enable_epel_repository_centos(Pihole): ''' confirms the EPEL package repository is enabled when installed on CentOS ''' - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') expected_stdout = info_box + (' Enabling EPEL package repository ' '(https://fedoraproject.org/wiki/EPEL)') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout expected_stdout = tick_box + ' Installed epel-release' - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout epel_package = Pihole.package('epel-release') assert epel_package.is_installed @@ -51,13 +51,13 @@ def test_php_version_lt_7_detected_upgrade_default_optout_centos(Pihole): default_centos_php_version = php_package.version.split('.')[0] if int(default_centos_php_version) >= 7: # PHP7 is supported/recommended pytest.skip("Test deprecated . Detected default PHP version >= 7") - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' 'Deprecated PHP may be in use.') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout remi_package = Pihole.package('remi-release') assert not remi_package.is_installed @@ -75,13 +75,13 @@ def test_php_version_lt_7_detected_upgrade_user_optout_centos(Pihole): pytest.skip("Test deprecated . Detected default PHP version >= 7") # Whiptail dialog returns Cancel for user prompt mock_command('whiptail', {'*': ('', '1')}, Pihole) - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' 'Deprecated PHP may be in use.') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout remi_package = Pihole.package('remi-release') assert not remi_package.is_installed @@ -99,20 +99,20 @@ def test_php_version_lt_7_detected_upgrade_user_optin_centos(Pihole): pytest.skip("Test deprecated . Detected default PHP version >= 7") # Whiptail dialog returns Continue for user prompt mock_command('whiptail', {'*': ('', '0')}, Pihole) - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect install_dependent_packages PIHOLE_WEB_DEPS[@] ''') expected_stdout = info_box + (' User opt-out of PHP 7 upgrade on CentOS. ' 'Deprecated PHP may be in use.') - assert expected_stdout not in distro_check.stdout + assert expected_stdout not in package_manager_detect.stdout expected_stdout = info_box + (' Enabling Remi\'s RPM repository ' '(https://rpms.remirepo.net)') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout expected_stdout = tick_box + (' Remi\'s RPM repository has ' 'been enabled for PHP7') - assert expected_stdout in distro_check.stdout + assert expected_stdout in package_manager_detect.stdout remi_package = Pihole.package('remi-release') assert remi_package.is_installed updated_php_package = Pihole.package('php') diff --git a/test/test_fedora_support.py b/test/test_fedora_support.py index 473b2e96..a2ac4c71 100644 --- a/test/test_fedora_support.py +++ b/test/test_fedora_support.py @@ -3,11 +3,11 @@ def test_epel_and_remi_not_installed_fedora(Pihole): confirms installer does not attempt to install EPEL/REMI repositories on Fedora ''' - distro_check = Pihole.run(''' + package_manager_detect = Pihole.run(''' source /opt/pihole/basic-install.sh - distro_check + package_manager_detect ''') - assert distro_check.stdout == '' + assert package_manager_detect.stdout == '' epel_package = Pihole.package('epel-release') assert not epel_package.is_installed From 913dcead7f2c154e63fa1a607c394a1d4e6ef93c Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 3 Aug 2021 22:39:33 +0100 Subject: [PATCH 2/7] move chmod/chown of macvendor.db to pihole-FTL.service Signed-off-by: Adam Warner --- advanced/Templates/pihole-FTL.service | 3 ++- automated install/basic-install.sh | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index f0743b49..88f50539 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -37,8 +37,9 @@ start() { chown pihole:pihole /etc/pihole /etc/pihole/dhcp.leases 2> /dev/null chown pihole:pihole /var/log/pihole-FTL.log /var/log/pihole.log chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port /var/log/pihole.log + chmod 0644 /etc/pihole/macvendor.db # Chown database files to the user FTL runs as. We ignore errors as the files may not (yet) exist - chown pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db 2> /dev/null + chown pihole:pihole /etc/pihole/pihole-FTL.db /etc/pihole/gravity.db /etc/pihole/macvendor.db 2> /dev/null if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN,CAP_SYS_NICE+eip "$(which pihole-FTL)"; then su -s /bin/sh -c "/usr/bin/pihole-FTL" "$FTLUSER" else diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 0d674b2f..71aa8b49 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2336,8 +2336,6 @@ FTLinstall() { # Before stopping FTL, we download the macvendor database curl -sSL "https://ftl.pi-hole.net/macvendor.db" -o "${PI_HOLE_CONFIG_DIR}/macvendor.db" || true - chmod 644 "${PI_HOLE_CONFIG_DIR}/macvendor.db" - chown pihole:pihole "${PI_HOLE_CONFIG_DIR}/macvendor.db" # Stop pihole-FTL service if available stop_service pihole-FTL &> /dev/null From d68a2ffaf312071c2d849689dab178c548b73628 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 3 Aug 2021 22:48:03 +0100 Subject: [PATCH 3/7] Install only minimal requiered package before performing os_check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christian König Signed-off-by: Adam Warner --- automated install/basic-install.sh | 16 +++++++++++----- test/test_automated_install.py | 2 ++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 71aa8b49..9cad94b3 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -354,10 +354,12 @@ if is_command apt-get ; then printf " %b Aborting installation: No SQLite PHP module was found in APT repository.\\n" "${CROSS}" exit 1 fi + # Packages required to perfom the os_check (stored as an array) + OS_CHECK_DEPS=(grep dnsutils) # Packages required to run this install script (stored as an array) - INSTALLER_DEPS=(dhcpcd5 git "${iproute_pkg}" whiptail dnsutils) + INSTALLER_DEPS=(git "${iproute_pkg}" whiptail) # Packages required to run Pi-hole (stored as an array) - PIHOLE_DEPS=(cron curl iputils-ping lsof netcat psmisc sudo unzip idn2 sqlite3 libcap2-bin dns-root-data libcap2) + PIHOLE_DEPS=(dhcpcd5 cron curl iputils-ping lsof netcat psmisc sudo unzip idn2 sqlite3 libcap2-bin dns-root-data libcap2) # Packages required for the Web admin interface (stored as an array) # It's useful to separate this from Pi-hole, since the two repos are also setup separately PIHOLE_WEB_DEPS=(lighttpd "${phpVer}-common" "${phpVer}-cgi" "${phpVer}-${phpSqlite}" "${phpVer}-xml" "${phpVer}-intl") @@ -400,7 +402,8 @@ elif is_command rpm ; then # These variable names match the ones in the Debian family. See above for an explanation of what they are for. PKG_INSTALL=("${PKG_MANAGER}" install -y) PKG_COUNT="${PKG_MANAGER} check-update | egrep '(.i686|.x86|.noarch|.arm|.src)' | wc -l" - INSTALLER_DEPS=(git iproute newt procps-ng which chkconfig bind-utils) + OS_CHECK_DEPS=(grep bind-utils) + INSTALLER_DEPS=(git iproute newt procps-ng which chkconfig) PIHOLE_DEPS=(cronie curl findutils nmap-ncat sudo unzip libidn2 psmisc sqlite libcap lsof) PIHOLE_WEB_DEPS=(lighttpd lighttpd-fastcgi php-common php-cli php-pdo php-xml php-json php-intl) LIGHTTPD_USER="lighttpd" @@ -2662,12 +2665,15 @@ main() { # Notify user of package availability notify_package_updates_available - # Install packages used by this installation script - install_dependent_packages "${INSTALLER_DEPS[@]}" + # Install packages necessary to perform os_check + install_dependent_packages "${OS_CHECK_DEPS[@]}" # Check that the installed OS is officially supported - display warning if not os_check + # Install packages used by this installation script + install_dependent_packages "${INSTALLER_DEPS[@]}" + # Check if SELinux is Enforcing checkSelinux diff --git a/test/test_automated_install.py b/test/test_automated_install.py index 21468cd7..593c19d2 100644 --- a/test/test_automated_install.py +++ b/test/test_automated_install.py @@ -568,6 +568,7 @@ def test_os_check_fails(Pihole): Pihole.run(''' source /opt/pihole/basic-install.sh package_manager_detect + install_dependent_packages ${OS_CHECK_DEPS[@]} install_dependent_packages ${INSTALLER_DEPS[@]} cat < /etc/os-release ID=UnsupportedOS @@ -587,6 +588,7 @@ def test_os_check_passes(Pihole): Pihole.run(''' source /opt/pihole/basic-install.sh package_manager_detect + install_dependent_packages ${OS_CHECK_DEPS[@]} install_dependent_packages ${INSTALLER_DEPS[@]} ''') detectOS = Pihole.run(''' From 3ad5097b12ae1ee26967a0ac757c04078aee2218 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 3 Aug 2021 22:53:29 +0100 Subject: [PATCH 4/7] Change initial install script order: 1. Ensure we have a compatible package manager 2. Install required packages for os_check to run (we need dnsutils and grep for this 3. Try to install FTL 4. FTL installed? Install installer dependencies and continue as normal - no other dependencies are installed until user has gone through all whiptails Signed-off-by: Adam Warner --- automated install/basic-install.sh | 57 +++++++++++++++--------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 9cad94b3..563b6bee 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2643,25 +2643,9 @@ main() { fi fi - # Check for supported distribution + # Check for supported package managers so that we may install dependencies package_manager_detect - # If the setup variable file exists, - if [[ -f "${setupVars}" ]]; then - # if it's running unattended, - if [[ "${runUnattended}" == true ]]; then - printf " %b Performing unattended setup, no whiptail 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 - fi - fi - - # Start the installer # Notify user of package availability notify_package_updates_available @@ -2671,12 +2655,39 @@ main() { # Check that the installed OS is officially supported - display warning if not os_check + # Check if FTL is installed - 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 + 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 + # Install packages used by this installation script install_dependent_packages "${INSTALLER_DEPS[@]}" # Check if SELinux is Enforcing checkSelinux + # If the setup variable file exists, + if [[ -f "${setupVars}" ]]; then + # if it's running unattended, + if [[ "${runUnattended}" == true ]]; then + printf " %b Performing unattended setup, no whiptail 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 + fi + fi + if [[ "${useUpdateVars}" == false ]]; then # Display welcome dialogs welcomeDialogs @@ -2740,18 +2751,6 @@ main() { # Create the pihole user create_pihole_user - # Check if FTL is installed - 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 - 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 - # Install and log everything to a file installPihole | tee -a /proc/$$/fd/3 From 2ff3b951170eb8ba00d5b328f853efbe3f7c6df4 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 3 Aug 2021 23:11:22 +0100 Subject: [PATCH 5/7] put FTL Install back to where it was Signed-off-by: Adam Warner --- automated install/basic-install.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 563b6bee..d38e94e1 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2655,18 +2655,6 @@ main() { # Check that the installed OS is officially supported - display warning if not os_check - # Check if FTL is installed - 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 - 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 - # Install packages used by this installation script install_dependent_packages "${INSTALLER_DEPS[@]}" @@ -2751,6 +2739,18 @@ main() { # Create the pihole user create_pihole_user + # Check if FTL is installed - 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 + 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 + # Install and log everything to a file installPihole | tee -a /proc/$$/fd/3 From 1ecb9165ee38e54149cc0cc1081577089dd6a7bc Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 3 Aug 2021 23:26:59 +0100 Subject: [PATCH 6/7] Remove weird global counter Signed-off-by: Adam Warner --- automated install/basic-install.sh | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index d38e94e1..01090285 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -1696,20 +1696,7 @@ notify_package_updates_available() { fi } -# This counter is outside of install_dependent_packages so that it can count the number of times the function is called. -counter=0 - install_dependent_packages() { - # Local, named variables should be used here, especially for an iterator - # Add one to the counter - counter=$((counter+1)) - if [[ "${counter}" == 1 ]]; then - # On the first loop, print a special message - printf " %b Installer Dependency checks...\\n" "${INFO}" - else - # On all subsequent loops, print a generic message. - printf " %b Main Dependency checks...\\n" "${INFO}" - fi # Install packages passed in via argument array # No spinner - conflicts with set -e @@ -2650,12 +2637,14 @@ main() { notify_package_updates_available # Install packages necessary to perform os_check + printf " %b Checking for / installing Required dependencies for OS Check...\\n" "${INFO}" install_dependent_packages "${OS_CHECK_DEPS[@]}" # Check that the installed OS is officially supported - display warning if not os_check # Install packages used by this installation script + printf " %b Checking for / installing Required dependencies for this install script...\\n" "${INFO}" install_dependent_packages "${INSTALLER_DEPS[@]}" # Check if SELinux is Enforcing @@ -2722,6 +2711,8 @@ main() { dep_install_list+=("${PIHOLE_WEB_DEPS[@]}") fi + # Install packages used by the actual software + printf " %b Checking for / installing Required dependencies for Pi-hole software...\\n" "${INFO}" install_dependent_packages "${dep_install_list[@]}" unset dep_install_list From bdab7014702aaa207cddad7b9a2b9728585adc20 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 3 Aug 2021 23:43:48 +0100 Subject: [PATCH 7/7] Remove dhcpcd5 dependency, however still help the user set the static IP if dhcpd5 is already installed (i.e on raspbian) Signed-off-by: Adam Warner --- automated install/basic-install.sh | 127 ++++------------------------- 1 file changed, 18 insertions(+), 109 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 01090285..5eda20ea 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -288,21 +288,6 @@ if is_command apt-get ; then 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" - # Some distros vary slightly so these fixes for dependencies may apply - # on Ubuntu 18.04.1 LTS we need to add the universe repository to gain access to dhcpcd5 - APT_SOURCES="/etc/apt/sources.list" - if awk 'BEGIN{a=1;b=0}/bionic main/{a=0}/bionic.*universe/{b=1}END{exit a + b}' ${APT_SOURCES}; then - if ! whiptail --defaultno --title "Dependencies Require Update to Allowed Repositories" --yesno "Would you like to enable 'universe' repository?\\n\\nThis repository is required by the following packages:\\n\\n- dhcpcd5" "${r}" "${c}"; then - printf " %b Aborting installation: Dependencies could not be installed.\\n" "${CROSS}" - exit 1 - else - printf " %b Enabling universe package repository for Ubuntu Bionic\\n" "${INFO}" - cp -p ${APT_SOURCES} ${APT_SOURCES}.backup # Backup current repo list - printf " %b Backed up current configuration to %s\\n" "${TICK}" "${APT_SOURCES}.backup" - add-apt-repository universe - printf " %b Enabled %s\\n" "${TICK}" "'universe' repository" - fi - fi # Update package cache. This is required already here to assure apt-cache calls have package lists available. update_package_cache || exit 1 # Debian 7 doesn't have iproute2 so check if it's available first @@ -359,7 +344,7 @@ if is_command apt-get ; then # Packages required to run this install script (stored as an array) INSTALLER_DEPS=(git "${iproute_pkg}" whiptail) # Packages required to run Pi-hole (stored as an array) - PIHOLE_DEPS=(dhcpcd5 cron curl iputils-ping lsof netcat psmisc sudo unzip idn2 sqlite3 libcap2-bin dns-root-data libcap2) + PIHOLE_DEPS=(cron curl iputils-ping lsof netcat psmisc sudo unzip idn2 sqlite3 libcap2-bin dns-root-data libcap2) # Packages required for the Web admin interface (stored as an array) # It's useful to separate this from Pi-hole, since the two repos are also setup separately PIHOLE_WEB_DEPS=(lighttpd "${phpVer}-common" "${phpVer}-cgi" "${phpVer}-${phpSqlite}" "${phpVer}-xml" "${phpVer}-intl") @@ -695,9 +680,17 @@ welcomeDialogs() { whiptail --msgbox --backtitle "Plea" --title "Free and open source" "\\n\\nThe Pi-hole is free, but powered by your donations: https://pi-hole.net/donate/" "${r}" "${c}" # Explain the need for a static address - whiptail --msgbox --backtitle "Initiating network interface" --title "Static IP Needed" "\\n\\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly. + if whiptail --defaultno --backtitle "Initiating network interface" --title "Static IP Needed" --yesno "\\n\\nThe Pi-hole is a SERVER so it needs a STATIC IP ADDRESS to function properly. -In the next section, you can choose to use your current network settings (DHCP) or to manually edit them." "${r}" "${c}" +IMPORTANT: If you have not already done so, you must ensure that this device has a static IP. Either through DHCP reservation, or by manually assigning one. Depending on your operating system, there are many ways to achieve this. + +Choose yes to indicate that you have understood this message, and wish to continue" "${r}" "${c}"; then +#Nothing to do, continue + echo +else + printf " %b Installer exited at static IP message.\\n" "${INFO}" + exit 1 +fi } # A function that lets the user pick an interface to use with Pi-hole @@ -850,8 +843,11 @@ use4andor6() { if [[ "${useIPv4}" ]]; then # Run our function to get the information we need find_IPv4_information - getStaticIPv4Settings - setStaticIPv4 + if [[ -f "/etc/dhcpcd.conf" ]]; then + # configure networking via dhcpcd + getStaticIPv4Settings + setDHCPCD + fi fi # If IPv6 is to be used, if [[ "${useIPv6}" ]]; then @@ -936,93 +932,6 @@ setDHCPCD() { fi } -# Configure networking ifcfg-xxxx file found at /etc/sysconfig/network-scripts/ -# This function requires the full path of an ifcfg file passed as an argument -setIFCFG() { - # Local, named variables - local IFCFG_FILE - local IPADDR - local CIDR - IFCFG_FILE=$1 - printf -v IPADDR "%s" "${IPV4_ADDRESS%%/*}" - # Check if the desired IP is already set - if grep -Eq "${IPADDR}(\\b|\\/)" "${IFCFG_FILE}"; then - printf " %b Static IP already configured\\n" "${INFO}" - else - # Otherwise, put the IP in variables without the CIDR notation - printf -v CIDR "%s" "${IPV4_ADDRESS##*/}" - # Backup existing interface configuration: - cp -p "${IFCFG_FILE}" "${IFCFG_FILE}".pihole.orig - # Build Interface configuration file using the GLOBAL variables we have - { - echo "# Configured via Pi-hole installer" - echo "DEVICE=$PIHOLE_INTERFACE" - echo "BOOTPROTO=none" - echo "ONBOOT=yes" - echo "IPADDR=$IPADDR" - echo "PREFIX=$CIDR" - echo "GATEWAY=$IPv4gw" - echo "DNS1=$PIHOLE_DNS_1" - echo "DNS2=$PIHOLE_DNS_2" - echo "USERCTL=no" - }> "${IFCFG_FILE}" - chmod 644 "${IFCFG_FILE}" - chown root:root "${IFCFG_FILE}" - # Use ip to immediately set the new address - ip addr replace dev "${PIHOLE_INTERFACE}" "${IPV4_ADDRESS}" - # If NetworkMangler command line interface exists and ready to mangle, - if is_command nmcli && nmcli general status &> /dev/null; then - # Tell NetworkManagler to read our new sysconfig file - nmcli con load "${IFCFG_FILE}" > /dev/null - fi - # Show a warning that the user may need to restart - printf " %b Set IP address to %s\\n You may need to restart after the install is complete\\n" "${TICK}" "${IPV4_ADDRESS%%/*}" - fi -} - -setStaticIPv4() { - # Local, named variables - local IFCFG_FILE - local CONNECTION_NAME - - # If a static interface is already configured, we are done. - if [[ -r "/etc/sysconfig/network/ifcfg-${PIHOLE_INTERFACE}" ]]; then - if grep -q '^BOOTPROTO=.static.' "/etc/sysconfig/network/ifcfg-${PIHOLE_INTERFACE}"; then - return 0 - fi - fi - # For the Debian family, if dhcpcd.conf exists then we can just configure using DHCPD. - if [[ -f "/etc/dhcpcd.conf" ]]; then - setDHCPCD - return 0 - fi - # If a DHCPCD config file was not found, check for an ifcfg config file based on the interface name - if [[ -f "/etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE}" ]];then - # If it exists, then we can configure using IFCFG - IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${PIHOLE_INTERFACE} - setIFCFG "${IFCFG_FILE}" - return 0 - fi - # If an ifcfg config does not exists for the interface name, search for one based on the connection name via network manager - if is_command nmcli && nmcli general status &> /dev/null; then - CONNECTION_NAME=$(nmcli dev show "${PIHOLE_INTERFACE}" | grep 'GENERAL.CONNECTION' | cut -d: -f2 | sed 's/^System//' | xargs | tr ' ' '_') - IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-${CONNECTION_NAME} - if [[ -f "${IFCFG_FILE}" ]];then - # If it exists, - setIFCFG "${IFCFG_FILE}" - return 0 - else - printf " %b Warning: sysconfig network script not found. Creating ${IFCFG_FILE}\\n" "${INFO}" - touch "${IFCFG_FILE}" - setIFCFG "${IFCFG_FILE}" - return 0 - fi - fi - # If previous conditions failed, show an error and exit - printf " %b Warning: Unable to locate configuration file to set static IPv4 address\\n" "${INFO}" - exit 1 -} - # Check an IP address to see if it is a valid one valid_ip() { # Local, named variables @@ -2120,7 +2029,7 @@ Your Admin Webpage login password is ${pwstring}" IPv4: ${IPV4_ADDRESS%/*} IPv6: ${IPV6_ADDRESS:-"Not Configured"} -If you set a new IP address, you should restart the Pi. +If you have not done so already, the above IP should be set to static. The install log is in /etc/pihole. @@ -2817,7 +2726,7 @@ main() { 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}" - printf " %b If you set a new IP address, please restart the server running the Pi-hole\\n" "${INFO}" + printf " %b If you have not done so already, the above IP should be set to static.\\n" "${INFO}" INSTALL_TYPE="Installation" else INSTALL_TYPE="Update"