From 3140f5441934cd74ef100a967e5aaef2e5641b9d Mon Sep 17 00:00:00 2001 From: Smittix Date: Mon, 16 Mar 2026 21:34:42 +0000 Subject: [PATCH] Add apt lock wait to prevent setup.sh hanging on fresh Ubuntu VMs On first boot, unattended-upgrades or apt-daily often holds the dpkg lock, causing silent hangs with no user feedback. Added wait_for_apt_lock() that polls for up to 120s with status messages, called before apt-get update and inside apt_try_install_any. Co-Authored-By: Claude Opus 4.6 --- setup.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/setup.sh b/setup.sh index 090c54e..72c8121 100755 --- a/setup.sh +++ b/setup.sh @@ -605,7 +605,25 @@ apt_install() { fi } +wait_for_apt_lock() { + local max_wait=120 + local waited=0 + while fuser /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock /var/cache/apt/archives/lock >/dev/null 2>&1; do + if [[ $waited -eq 0 ]]; then + info "Waiting for apt lock (another package manager is running)..." + fi + sleep 5 + waited=$((waited + 5)) + if [[ $waited -ge $max_wait ]]; then + warn "apt lock held for over ${max_wait}s. Continuing anyway (may fail)." + return 1 + fi + done + return 0 +} + apt_try_install_any() { + wait_for_apt_lock local p for p in "$@"; do if $SUDO apt-get install -y --no-install-recommends "$p" >/dev/null 2>&1; then @@ -1722,6 +1740,7 @@ install_profiles() { export NEEDRESTART_MODE=a fi + wait_for_apt_lock info "Updating APT package lists..." if ! $SUDO apt-get update -y >/dev/null 2>&1; then warn "apt-get update reported errors. Continuing anyway."