From ea61755881b9c3b4c7776ab265079f3695c9cd69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 5 Jun 2025 12:50:10 +0200 Subject: [PATCH 1/4] Only update the package cache on fresh installations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/update.sh | 1 + automated install/basic-install.sh | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index 51c1b1a1..d9412f8a 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -114,6 +114,7 @@ main() { # Install packages used by this installation script (necessary if users have removed e.g. git from their systems) + check_fresh_install package_manager_detect build_dependency_package install_dependent_packages diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 279dc1d1..cbad9eac 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -231,6 +231,13 @@ is_command() { command -v "${check_command}" >/dev/null 2>&1 } +check_fresh_install() { + # in case of an update (can be a v5 -> v6 or v6 -> v6 update) or repair + if [[ -f "${PI_HOLE_V6_CONFIG}" ]] || [[ -f "/etc/pihole/setupVars.conf" ]]; then + fresh_install=false + fi +} + # Compatibility package_manager_detect() { @@ -247,8 +254,10 @@ package_manager_detect() { PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" # The command we will use to remove packages (used in the uninstaller) PKG_REMOVE="${PKG_MANAGER} -y remove --purge" - # Update package cache - update_package_cache || exit 1 + # Update package cache only on fresh installs + if [[ "${fresh_install}" == true ]]; then + update_package_cache || exit 1 + fi # If apt-get is not found, check for rpm. elif is_command rpm; then @@ -2193,6 +2202,9 @@ main() { # Check for availability of either the "service" or "systemctl" commands check_service_command + # Check if this is a fresh install or an update/repair + check_fresh_install + # Check for supported package managers so that we may install dependencies package_manager_detect @@ -2216,10 +2228,7 @@ main() { exit 1 fi - # in case of an update (can be a v5 -> v6 or v6 -> v6 update) or repair - if [[ -f "${PI_HOLE_V6_CONFIG}" ]] || [[ -f "/etc/pihole/setupVars.conf" ]]; then - # retain settings - fresh_install=false + if [[ "${fresh_install}" == false ]]; then # if it's running unattended, if [[ "${runUnattended}" == true ]]; then printf " %b Performing unattended setup, no dialogs will be displayed\\n" "${INFO}" From 93ecfb9504c7f353ebf8dd83b23a8c89c9bbdc4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 5 Jun 2025 13:09:03 +0200 Subject: [PATCH 2/4] We test a fresh installaton, so don't pretend this is not a fresh installation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- test/test_any_automated_install.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index 0fa0453a..eb1f72e4 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -89,10 +89,8 @@ def test_installPihole_fresh_install_readableFiles(host): export DEBIAN_FRONTEND=noninteractive umask 0027 runUnattended=true - fresh_install=false source /opt/pihole/basic-install.sh > /dev/null runUnattended=true - fresh_install=false main /opt/pihole/pihole-FTL-prestart.sh """ From 5777497f52c3c87da870e9282bf21e30ffcf5133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 8 Jun 2025 21:25:43 +0200 Subject: [PATCH 3/4] Separate package manager detection and cache update functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- advanced/Scripts/update.sh | 1 - automated install/basic-install.sh | 9 +++++---- test/test_any_automated_install.py | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/advanced/Scripts/update.sh b/advanced/Scripts/update.sh index d9412f8a..51c1b1a1 100755 --- a/advanced/Scripts/update.sh +++ b/advanced/Scripts/update.sh @@ -114,7 +114,6 @@ main() { # Install packages used by this installation script (necessary if users have removed e.g. git from their systems) - check_fresh_install package_manager_detect build_dependency_package install_dependent_packages diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index cbad9eac..99b11d5c 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -254,10 +254,6 @@ package_manager_detect() { PKG_COUNT="${PKG_MANAGER} -s -o Debug::NoLocking=true upgrade | grep -c ^Inst || true" # The command we will use to remove packages (used in the uninstaller) PKG_REMOVE="${PKG_MANAGER} -y remove --purge" - # Update package cache only on fresh installs - if [[ "${fresh_install}" == true ]]; then - update_package_cache || exit 1 - fi # If apt-get is not found, check for rpm. elif is_command rpm; then @@ -2208,6 +2204,11 @@ main() { # Check for supported package managers so that we may install dependencies package_manager_detect + # Update package cache only on fresh installs and apt based systems + if [[ "${fresh_install}" == true ]] && is_command apt-get; then + update_package_cache || exit 1 + fi + # Notify user of package availability notify_package_updates_available diff --git a/test/test_any_automated_install.py b/test/test_any_automated_install.py index eb1f72e4..cf4b454d 100644 --- a/test/test_any_automated_install.py +++ b/test/test_any_automated_install.py @@ -471,6 +471,7 @@ def test_package_manager_has_pihole_deps(host): """ source /opt/pihole/basic-install.sh package_manager_detect + update_package_cache build_dependency_package install_dependent_packages """ @@ -487,6 +488,7 @@ def test_meta_package_uninstall(host): """ source /opt/pihole/basic-install.sh package_manager_detect + update_package_cache build_dependency_package install_dependent_packages """ From 7a16024020d975b3e0490621e4cc6832b4151111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 8 Jun 2025 21:31:56 +0200 Subject: [PATCH 4/4] Run package update everytime before building the meta package when invoking from the install script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- automated install/basic-install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/automated install/basic-install.sh b/automated install/basic-install.sh index 99b11d5c..c18e6c0d 100755 --- a/automated install/basic-install.sh +++ b/automated install/basic-install.sh @@ -2204,8 +2204,8 @@ main() { # Check for supported package managers so that we may install dependencies package_manager_detect - # Update package cache only on fresh installs and apt based systems - if [[ "${fresh_install}" == true ]] && is_command apt-get; then + # Update package cache only on apt based systems + if is_command apt-get; then update_package_cache || exit 1 fi