From b1ea60484ef5156900aa274b889a2deef430b592 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Mon, 26 Jul 2021 13:22:26 -0700 Subject: [PATCH 01/18] Guard for logrotate func non-zero return Signed-off-by: Dan Schaper --- automated install/basic-install.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4212159e..4ce3003b 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2043,7 +2043,10 @@ installPihole() { # Install the cron file installCron # Install the logrotate file - installLogrotate + if ! installLogrotate; then + printf " %b Failure in logrotate installation function.\\n" "${CROSS}" + # This isn't fatal, no need to exit. + fi # Check if dnsmasq is present. If so, disable it and back up any possible # config file disable_dnsmasq From 0c125eba2cc3cd097f93965f9084c8bf88649a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Tue, 27 Jul 2021 22:04:30 +0200 Subject: [PATCH 02/18] Make output of SHM dir human readable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8ea640c2..4c75f246 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1109,7 +1109,7 @@ list_files_in_dir() { : elif [[ "${dir_to_parse}" == "${SHM_DIRECTORY}" ]]; then # SHM file - we do not want to see the content, but we want to see the files and their sizes - log_write "$(ls -ld "${dir_to_parse}"/"${each_file}")" + log_write "$(ls -lhd "${dir_to_parse}"/"${each_file}")" else # Then, parse the file's content into an array so each line can be analyzed if need be for i in "${!REQUIRED_FILES[@]}"; do From fbfec961d5e9a47ffd2100e2f9647eabd7784421 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 28 Jul 2021 21:16:19 +0200 Subject: [PATCH 03/18] Remove comparison of IP addresses with setupVars.conf Signed-off-by: DL6ER --- advanced/Scripts/piholeDebug.sh | 42 +-------------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index f0a22b6d..895747b1 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -605,38 +605,6 @@ parse_locale() { parse_file "${pihole_locale}" } -does_ip_match_setup_vars() { - # Check for IPv4 or 6 - local protocol="${1}" - # IP address to check for - local ip_address="${2}" - # See what IP is in the setupVars.conf file - local setup_vars_ip - setup_vars_ip=$(< ${PIHOLE_SETUP_VARS_FILE} grep IPV"${protocol}"_ADDRESS | cut -d '=' -f2) - # If it's an IPv6 address - if [[ "${protocol}" == "6" ]]; then - # Strip off the / (CIDR notation) - if [[ "${ip_address%/*}" == "${setup_vars_ip%/*}" ]]; then - # if it matches, show it in green - log_write " ${COL_GREEN}${ip_address%/*}${COL_NC} matches the IP found in ${PIHOLE_SETUP_VARS_FILE}" - else - # otherwise show it in red with an FAQ URL - log_write " ${COL_RED}${ip_address%/*}${COL_NC} does not match the IP found in ${PIHOLE_SETUP_VARS_FILE} (${FAQ_ULA})" - fi - - else - # if the protocol isn't 6, it's 4 so no need to strip the CIDR notation - # since it exists in the setupVars.conf that way - if [[ "${ip_address}" == "${setup_vars_ip}" ]]; then - # show in green if it matches - log_write " ${COL_GREEN}${ip_address}${COL_NC} matches the IP found in ${PIHOLE_SETUP_VARS_FILE}" - else - # otherwise show it in red - log_write " ${COL_RED}${ip_address}${COL_NC} does not match the IP found in ${PIHOLE_SETUP_VARS_FILE} (${FAQ_ULA})" - fi - fi -} - detect_ip_addresses() { # First argument should be a 4 or a 6 local protocol=${1} @@ -653,8 +621,7 @@ detect_ip_addresses() { log_write "${TICK} IPv${protocol} address(es) bound to the ${PIHOLE_INTERFACE} interface:" # Since there may be more than one IP address, store them in an array for i in "${!ip_addr_list[@]}"; do - # For each one in the list, print it out - does_ip_match_setup_vars "${protocol}" "${ip_addr_list[$i]}" + log_write " ${ip_addr_list[$i]}" done # Print a blank line just for formatting log_write "" @@ -663,13 +630,6 @@ detect_ip_addresses() { log_write "${CROSS} ${COL_RED}No IPv${protocol} address(es) found on the ${PIHOLE_INTERFACE}${COL_NC} interface.\\n" return 1 fi - # If the protocol is v6 - if [[ "${protocol}" == "6" ]]; then - # let the user know that as long as there is one green address, things should be ok - log_write " ^ Please note that you may have more than one IP address listed." - log_write " As long as one of them is green, and it matches what is in ${PIHOLE_SETUP_VARS_FILE}, there is no need for concern.\\n" - log_write " The link to the FAQ is for an issue that sometimes occurs when the IPv6 address changes, which is why we check for it.\\n" - fi } ping_ipv4_or_ipv6() { From d0eb0d50376358eed7d34579fcfa32a89fc0d1ec Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 28 Jul 2021 21:18:02 +0200 Subject: [PATCH 04/18] Remove extra failure display when installation of logrotate file is skipped because the file already exists Signed-off-by: DL6ER --- automated install/basic-install.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 4ce3003b..96d0b693 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2042,11 +2042,10 @@ installPihole() { fi # Install the cron file installCron + # Install the logrotate file - if ! installLogrotate; then - printf " %b Failure in logrotate installation function.\\n" "${CROSS}" - # This isn't fatal, no need to exit. - fi + installLogrotate || true + # Check if dnsmasq is present. If so, disable it and back up any possible # config file disable_dnsmasq From d02aa3ced18094e33705b7b3e0d748ec10548791 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 28 Jul 2021 21:38:36 +0200 Subject: [PATCH 05/18] Fix error on checking interfaces that are not dual-stack Signed-off-by: DL6ER --- advanced/Scripts/piholeDebug.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 4c75f246..837e1778 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -922,16 +922,20 @@ dig_at() { # s/\/.*$//g; # Removes CIDR and everything thereafter (e.g., scope properties) addresses="$(ip address show dev "${iface}" | sed "/${sed_selector} /!d;s/^.*${sed_selector} //g;s/\/.*$//g;")" - while IFS= read -r local_address ; do - # Check if Pi-hole can use itself to block a domain - if local_dig=$(dig +tries=1 +time=2 -"${protocol}" "${random_url}" @"${local_address}" +short "${record_type}"); then - # If it can, show success - log_write "${TICK} ${random_url} ${COL_GREEN}is ${local_dig}${COL_NC} on ${COL_CYAN}${iface}${COL_NC} (${COL_CYAN}${local_address}${COL_NC})" - else - # Otherwise, show a failure - log_write "${CROSS} ${COL_RED}Failed to resolve${COL_NC} ${random_url} on ${COL_RED}${iface}${COL_NC} (${COL_RED}${local_address}${COL_NC})" - fi - done <<< "${addresses}" + if [ -n "${addresses}" ]; then + while IFS= read -r local_address ; do + # Check if Pi-hole can use itself to block a domain + if local_dig=$(dig +tries=1 +time=2 -"${protocol}" "${random_url}" @"${local_address}" +short "${record_type}"); then + # If it can, show success + log_write "${TICK} ${random_url} ${COL_GREEN}is ${local_dig}${COL_NC} on ${COL_CYAN}${iface}${COL_NC} (${COL_CYAN}${local_address}${COL_NC})" + else + # Otherwise, show a failure + log_write "${CROSS} ${COL_RED}Failed to resolve${COL_NC} ${random_url} on ${COL_RED}${iface}${COL_NC} (${COL_RED}${local_address}${COL_NC})" + fi + done <<< "${addresses}" + else + log_write "${TICK} No IPv${protocol} address available on ${COL_CYAN}${iface}${COL_NC}" + fi done <<< "${interfaces}" # Finally, we need to make sure legitimate queries can out to the Internet using an external, public DNS server From d2c75a33d5c0fc4e75b466533a1e3f0a7c68498f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Wed, 4 Aug 2021 20:13:41 +0200 Subject: [PATCH 06/18] Increase width of ID column in adlist and domain table in debug script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 837e1778..e9b4be76 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -1258,11 +1258,11 @@ show_groups() { } show_adlists() { - show_db_entries "Adlists" "SELECT id,CASE enabled WHEN '0' THEN ' 0' WHEN '1' THEN ' 1' ELSE enabled END enabled,GROUP_CONCAT(adlist_by_group.group_id) group_ids,address,datetime(date_added,'unixepoch','localtime') date_added,datetime(date_modified,'unixepoch','localtime') date_modified,comment FROM adlist LEFT JOIN adlist_by_group ON adlist.id = adlist_by_group.adlist_id GROUP BY id;" "4 7 12 100 19 19 50" + show_db_entries "Adlists" "SELECT id,CASE enabled WHEN '0' THEN ' 0' WHEN '1' THEN ' 1' ELSE enabled END enabled,GROUP_CONCAT(adlist_by_group.group_id) group_ids,address,datetime(date_added,'unixepoch','localtime') date_added,datetime(date_modified,'unixepoch','localtime') date_modified,comment FROM adlist LEFT JOIN adlist_by_group ON adlist.id = adlist_by_group.adlist_id GROUP BY id;" "5 7 12 100 19 19 50" } show_domainlist() { - show_db_entries "Domainlist (0/1 = exact white-/blacklist, 2/3 = regex white-/blacklist)" "SELECT id,CASE type WHEN '0' THEN '0 ' WHEN '1' THEN ' 1 ' WHEN '2' THEN ' 2 ' WHEN '3' THEN ' 3' ELSE type END type,CASE enabled WHEN '0' THEN ' 0' WHEN '1' THEN ' 1' ELSE enabled END enabled,GROUP_CONCAT(domainlist_by_group.group_id) group_ids,domain,datetime(date_added,'unixepoch','localtime') date_added,datetime(date_modified,'unixepoch','localtime') date_modified,comment FROM domainlist LEFT JOIN domainlist_by_group ON domainlist.id = domainlist_by_group.domainlist_id GROUP BY id;" "4 4 7 12 100 19 19 50" + show_db_entries "Domainlist (0/1 = exact white-/blacklist, 2/3 = regex white-/blacklist)" "SELECT id,CASE type WHEN '0' THEN '0 ' WHEN '1' THEN ' 1 ' WHEN '2' THEN ' 2 ' WHEN '3' THEN ' 3' ELSE type END type,CASE enabled WHEN '0' THEN ' 0' WHEN '1' THEN ' 1' ELSE enabled END enabled,GROUP_CONCAT(domainlist_by_group.group_id) group_ids,domain,datetime(date_added,'unixepoch','localtime') date_added,datetime(date_modified,'unixepoch','localtime') date_modified,comment FROM domainlist LEFT JOIN domainlist_by_group ON domainlist.id = domainlist_by_group.domainlist_id GROUP BY id;" "5 4 7 12 100 19 19 50" } show_clients() { From 075b3f64682d9025370ae696d3ec4534d9ee07cd Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Wed, 4 Aug 2021 20:57:09 -0700 Subject: [PATCH 07/18] Remove ports, nc option and fix wording. Signed-off-by: Dan Schaper --- advanced/Scripts/piholeDebug.sh | 42 ++++++++++----------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 8ea640c2..55c5739e 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -56,11 +56,6 @@ FAQ_BAD_ADDRESS="${COL_CYAN}https://discourse.pi-hole.net/t/why-do-i-see-bad-add # Other URLs we may use FORUMS_URL="${COL_CYAN}https://discourse.pi-hole.net${COL_NC}" -TRICORDER_CONTEST="${COL_CYAN}https://pi-hole.net/2016/11/07/crack-our-medical-tricorder-win-a-raspberry-pi-3/${COL_NC}" - -# Port numbers used for uploading the debug log -TRICORDER_NC_PORT_NUMBER=9999 -TRICORDER_SSL_PORT_NUMBER=9998 # Directories required by Pi-hole # https://discourse.pi-hole.net/t/what-files-does-pi-hole-use/1684 @@ -1366,25 +1361,14 @@ analyze_pihole_log() { IFS="$OLD_IFS" } -tricorder_use_nc_or_curl() { - # Users can submit their debug logs using nc (unencrypted) or curl (encrypted) if available - # Check for curl first since encryption is a good thing - if command -v curl &> /dev/null; then - # If the command exists, - log_write " * Using ${COL_GREEN}curl${COL_NC} for transmission." - # transmit he log via TLS and store the token returned in a variable - tricorder_token=$(curl --silent --upload-file ${PIHOLE_DEBUG_LOG} https://tricorder.pi-hole.net:${TRICORDER_SSL_PORT_NUMBER}) - if [ -z "${tricorder_token}" ]; then - # curl failed, fallback to nc - log_write " * ${COL_GREEN}curl${COL_NC} failed, falling back to ${COL_YELLOW}netcat${COL_NC} for transmission." - tricorder_token=$(< ${PIHOLE_DEBUG_LOG} nc tricorder.pi-hole.net ${TRICORDER_NC_PORT_NUMBER}) - fi - # Otherwise, - else - # use net cat - log_write "${INFO} Using ${COL_YELLOW}netcat${COL_NC} for transmission." - # Save the token returned by our server in a variable - tricorder_token=$(< ${PIHOLE_DEBUG_LOG} nc tricorder.pi-hole.net ${TRICORDER_NC_PORT_NUMBER}) +curl_to_tricorder() { + # Users can submit their debug logs using curl (encrypted) + log_write " * Using ${COL_GREEN}curl${COL_NC} for transmission." + # transmit he log via TLS and store the token returned in a variable + tricorder_token=$(curl --silent --upload-file ${PIHOLE_DEBUG_LOG} https://tricorder.pi-hole.net) + if [ -z "${tricorder_token}" ]; then + # curl failed, fallback to nc + log_write " * ${COL_GREEN}curl${COL_NC} failed, contact Pi-hole support for assistance." fi } @@ -1403,14 +1387,13 @@ upload_to_tricorder() { # Provide information on what they should do with their token log_write " * The debug log can be uploaded to tricorder.pi-hole.net for sharing with developers only." - log_write " * For more information, see: ${TRICORDER_CONTEST}" - log_write " * If available, we'll use openssl to upload the log, otherwise it will fall back to netcat." + # If pihole -d is running automatically (usually through the dashboard) if [[ "${AUTOMATED}" ]]; then # let the user know log_write "${INFO} Debug script running in automated mode" # and then decide again which tool to use to submit it - tricorder_use_nc_or_curl + curl_to_tricorder # If we're not running in automated mode, else echo "" @@ -1419,7 +1402,7 @@ upload_to_tricorder() { read -r -p "[?] Would you like to upload the log? [y/N] " response case ${response} in # If they say yes, run our function for uploading the log - [yY][eE][sS]|[yY]) tricorder_use_nc_or_curl;; + [yY][eE][sS]|[yY]) curl_to_tricorder;; # If they choose no, just exit out of the script *) log_write " * Log will ${COL_GREEN}NOT${COL_NC} be uploaded to tricorder.\\n * A local copy of the debug log can be found at: ${COL_CYAN}${PIHOLE_DEBUG_LOG}${COL_NC}\\n";exit; esac @@ -1433,12 +1416,13 @@ upload_to_tricorder() { log_write "${COL_PURPLE}***********************************${COL_NC}" log_write "${COL_PURPLE}***********************************${COL_NC}" log_write "${TICK} Your debug token is: ${COL_GREEN}${tricorder_token}${COL_NC}" + log_write "${INFO}${COL_RED} Logs are deleted 48 hours after upload.${COL_NC}" log_write "${COL_PURPLE}***********************************${COL_NC}" log_write "${COL_PURPLE}***********************************${COL_NC}" log_write "" log_write " * Provide the token above to the Pi-hole team for assistance at" log_write " * ${FORUMS_URL}" - log_write " * Your log will self-destruct on our server after ${COL_RED}48 hours${COL_NC}." + # If no token was generated else # Show an error and some help instructions From 1358209a9ae75eb09fefdd9d5032c914c7f9a4d3 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Tue, 3 Aug 2021 21:48:26 +0100 Subject: [PATCH 08/18] 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 09/18] 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 10/18] 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 11/18] 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 12/18] 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 13/18] 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 14/18] 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" From ffe45e8b76b19ecc7db0b3f06d8c2027e20d1d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Fri, 6 Aug 2021 20:51:48 +0200 Subject: [PATCH 15/18] On enabling/disabeling only reload-lists instead of reload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- pihole | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pihole b/pihole index 470c9dc7..e8fa9317 100755 --- a/pihole +++ b/pihole @@ -242,7 +242,7 @@ Time: echo "BLOCKING_ENABLED=true" >> "${setupVars}" fi - restartDNS reload + restartDNS reload-lists echo -e "${OVER} ${TICK} ${str}" } From bb7c7cdf337ba0ddee21f83d99ae03c569b61bf5 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Sat, 7 Aug 2021 20:07:14 +0200 Subject: [PATCH 16/18] Add uptime to debug log (#4265) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add uptime to debug log Signed-off-by: Christian König * Address github comments Signed-off-by: Christian König --- advanced/Scripts/piholeDebug.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/advanced/Scripts/piholeDebug.sh b/advanced/Scripts/piholeDebug.sh index 0c4393cc..26ef61fa 100755 --- a/advanced/Scripts/piholeDebug.sh +++ b/advanced/Scripts/piholeDebug.sh @@ -230,6 +230,7 @@ copy_to_debug_log() { } initialize_debug() { + local system_uptime # Clear the screen so the debug log is readable clear show_disclaimer @@ -237,6 +238,10 @@ initialize_debug() { log_write "${COL_PURPLE}*** [ INITIALIZING ]${COL_NC}" # Timestamp the start of the log log_write "${INFO} $(date "+%Y-%m-%d:%H:%M:%S") debug log has been initialized." + # Uptime of the system + # credits to https://stackoverflow.com/questions/28353409/bash-format-uptime-to-show-days-hours-minutes + system_uptime=$(uptime | awk -F'( |,|:)+' '{if ($7=="min") m=$6; else {if ($7~/^day/){if ($9=="min") {d=$6;m=$8} else {d=$6;h=$8;m=$9}} else {h=$6;m=$7}}} {print d+0,"days,",h+0,"hours,",m+0,"minutes"}') + log_write "${INFO} System has been running for ${system_uptime}" } # This is a function for visually displaying the current test that is being run. From ee749f700fcaecb888093d6785f6140682b91f26 Mon Sep 17 00:00:00 2001 From: yubiuser Date: Sat, 7 Aug 2021 20:07:45 +0200 Subject: [PATCH 17/18] Add switching 'to...from' message to ftl checkout output (#4266) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add switching 'to...from' message to ftl checkout output Signed-off-by: Christian König * Add quotes Signed-off-by: Christian König --- advanced/Scripts/piholeCheckout.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced/Scripts/piholeCheckout.sh b/advanced/Scripts/piholeCheckout.sh index 1c1b16a4..4c0a4f40 100644 --- a/advanced/Scripts/piholeCheckout.sh +++ b/advanced/Scripts/piholeCheckout.sh @@ -166,12 +166,15 @@ checkout() { checkout_pull_branch "${webInterfaceDir}" "${2}" elif [[ "${1}" == "ftl" ]] ; then local path + local oldbranch path="${2}/${binary}" + oldbranch="$(pihole-FTL -b)" if check_download_exists "$path"; then echo " ${TICK} Branch ${2} exists" echo "${2}" > /etc/pihole/ftlbranch chmod 644 /etc/pihole/ftlbranch + echo -e " ${INFO} Switching to branch: \"${2}\" from \"${oldbranch}\"" FTLinstall "${binary}" restart_service pihole-FTL enable_service pihole-FTL From 676b7e60f3dd3e0eee661f4e2638bf387440e118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 12 Aug 2021 13:55:40 +0200 Subject: [PATCH 18/18] Fix Splashpage not appearing properly on non-root directories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/advanced/index.php b/advanced/index.php index a38cd365..d0c5fc5d 100644 --- a/advanced/index.php +++ b/advanced/index.php @@ -73,12 +73,12 @@ if ($serverName === "pi.hole" $viewPort ● $serverName - - + +
- Pi-hole logo + Pi-hole logo

Pi-hole: Your black hole for Internet advertisements

Did you mean to go to the admin panel?