mirror of
https://github.com/smittix/intercept.git
synced 2026-07-08 01:28:13 -07:00
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 <noreply@anthropic.com>
This commit is contained in:
@@ -605,7 +605,25 @@ apt_install() {
|
|||||||
fi
|
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() {
|
apt_try_install_any() {
|
||||||
|
wait_for_apt_lock
|
||||||
local p
|
local p
|
||||||
for p in "$@"; do
|
for p in "$@"; do
|
||||||
if $SUDO apt-get install -y --no-install-recommends "$p" >/dev/null 2>&1; then
|
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
|
export NEEDRESTART_MODE=a
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
wait_for_apt_lock
|
||||||
info "Updating APT package lists..."
|
info "Updating APT package lists..."
|
||||||
if ! $SUDO apt-get update -y >/dev/null 2>&1; then
|
if ! $SUDO apt-get update -y >/dev/null 2>&1; then
|
||||||
warn "apt-get update reported errors. Continuing anyway."
|
warn "apt-get update reported errors. Continuing anyway."
|
||||||
|
|||||||
Reference in New Issue
Block a user