var. core fixes (bash to sh in fix_gpu_gids ...) (#9666)

* Switch container exec from bash to sh in fix_gpu_gids

Replaces bash with sh for container execution in fix_gpu_gids and updates device matching logic to use a POSIX-compliant case statement. This improves compatibility with containers that may not have bash installed.

* 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
This commit is contained in:
CanbiZ 2025-12-05 09:17:19 +01:00 committed by GitHub
parent eb53af44c9
commit e73f35e2c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 6 deletions

View File

@ -2954,15 +2954,14 @@ fix_gpu_gids() {
# For privileged containers: also fix permissions inside container # For privileged containers: also fix permissions inside container
if [[ "$CT_TYPE" == "0" ]]; then if [[ "$CT_TYPE" == "0" ]]; then
pct exec "$CTID" -- bash -c " pct exec "$CTID" -- sh -c "
if [ -d /dev/dri ]; then if [ -d /dev/dri ]; then
for dev in /dev/dri/*; do for dev in /dev/dri/*; do
if [ -e \"\$dev\" ]; then if [ -e \"\$dev\" ]; then
if [[ \"\$dev\" =~ renderD ]]; then case \"\$dev\" in
chgrp ${render_gid} \"\$dev\" 2>/dev/null || true *renderD*) chgrp ${render_gid} \"\$dev\" 2>/dev/null || true ;;
else *) chgrp ${video_gid} \"\$dev\" 2>/dev/null || true ;;
chgrp ${video_gid} \"\$dev\" 2>/dev/null || true esac
fi
chmod 660 \"\$dev\" 2>/dev/null || true chmod 660 \"\$dev\" 2>/dev/null || true
fi fi
done done

View File

@ -192,6 +192,8 @@ install_packages_with_retry() {
if [[ $retry -le $max_retries ]]; then if [[ $retry -le $max_retries ]]; then
msg_warn "Package installation failed, retrying ($retry/$max_retries)..." msg_warn "Package installation failed, retrying ($retry/$max_retries)..."
sleep 2 sleep 2
# Fix any interrupted dpkg operations before retry
$STD dpkg --configure -a 2>/dev/null || true
$STD apt update 2>/dev/null || true $STD apt update 2>/dev/null || true
fi fi
done done
@ -217,6 +219,8 @@ upgrade_packages_with_retry() {
if [[ $retry -le $max_retries ]]; then if [[ $retry -le $max_retries ]]; then
msg_warn "Package upgrade failed, retrying ($retry/$max_retries)..." msg_warn "Package upgrade failed, retrying ($retry/$max_retries)..."
sleep 2 sleep 2
# Fix any interrupted dpkg operations before retry
$STD dpkg --configure -a 2>/dev/null || true
$STD apt update 2>/dev/null || true $STD apt update 2>/dev/null || true
fi fi
done done
@ -1182,6 +1186,12 @@ cleanup_orphaned_sources() {
# This should be called at the start of any setup function # This should be called at the start of any setup function
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
ensure_apt_working() { ensure_apt_working() {
# Fix interrupted dpkg operations first
# This can happen if a previous installation was interrupted (e.g., by script error)
if [[ -f /var/lib/dpkg/lock-frontend ]] || dpkg --audit 2>&1 | grep -q "interrupted"; then
$STD dpkg --configure -a 2>/dev/null || true
fi
# Clean up orphaned sources first # Clean up orphaned sources first
cleanup_orphaned_sources cleanup_orphaned_sources