Skip to content

Commit ca3e7ea

Browse files
committed
fix(apt): auto-recover from interrupted dpkg operations
When a previous installation is interrupted (e.g., by script error or user cancellation), dpkg can be left in an inconsistent state requiring 'dpkg --configure -a' to fix. This change: - Adds dpkg --configure -a check to ensure_apt_working() - Adds dpkg --configure -a to retry logic in install_packages_with_retry() - Adds dpkg --configure -a to retry logic in upgrade_packages_with_retry() Fixes: Omada Controller update failing after interrupted installation Reported-in: #9663
1 parent 6368e07 commit ca3e7ea

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

misc/tools.func

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ install_packages_with_retry() {
192192
if [[ $retry -le $max_retries ]]; then
193193
msg_warn "Package installation failed, retrying ($retry/$max_retries)..."
194194
sleep 2
195+
# Fix any interrupted dpkg operations before retry
196+
$STD dpkg --configure -a 2>/dev/null || true
195197
$STD apt update 2>/dev/null || true
196198
fi
197199
done
@@ -217,6 +219,8 @@ upgrade_packages_with_retry() {
217219
if [[ $retry -le $max_retries ]]; then
218220
msg_warn "Package upgrade failed, retrying ($retry/$max_retries)..."
219221
sleep 2
222+
# Fix any interrupted dpkg operations before retry
223+
$STD dpkg --configure -a 2>/dev/null || true
220224
$STD apt update 2>/dev/null || true
221225
fi
222226
done
@@ -1182,6 +1186,12 @@ cleanup_orphaned_sources() {
11821186
# This should be called at the start of any setup function
11831187
# ------------------------------------------------------------------------------
11841188
ensure_apt_working() {
1189+
# Fix interrupted dpkg operations first
1190+
# This can happen if a previous installation was interrupted (e.g., by script error)
1191+
if [[ -f /var/lib/dpkg/lock-frontend ]] || dpkg --audit 2>&1 | grep -q "interrupted"; then
1192+
$STD dpkg --configure -a 2>/dev/null || true
1193+
fi
1194+
11851195
# Clean up orphaned sources first
11861196
cleanup_orphaned_sources
11871197

0 commit comments

Comments
 (0)