common.sh: fix Docker install failing silently in piped execution

Two bugs in require_docker:
1. apt post-install hooks (needrestart etc.) block on stdin which is
   at EOF when running via pipe; DEBIAN_FRONTEND=noninteractive skips them
2. bash's command hash table doesn't pick up a newly installed binary;
   hash -r flushes it so command -v docker finds /usr/bin/docker
Also moved usermod and success log after the binary check so [OK] only
prints when docker is actually reachable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LQJBvqzXeyuhhAcAA3Q5Wq
This commit is contained in:
Claude
2026-06-28 12:18:10 +00:00
parent bb107b424b
commit 64776731fb
+17 -8
View File
@@ -170,14 +170,16 @@ require_docker() {
return 0 return 0
fi fi
# Official Docker convenience script — installs Docker CE + Compose plugin # Official Docker convenience script — installs Docker CE + Compose plugin.
if curl -fsSL https://get.docker.com | sh; then # DEBIAN_FRONTEND suppresses interactive apt hooks (needrestart etc.) that
if [ -n "$ACTUAL_USER" ] && [ "$ACTUAL_USER" != "root" ]; then # would block waiting on the piped stdin and cause a silent install failure.
usermod -aG docker "$ACTUAL_USER" \ export DEBIAN_FRONTEND=noninteractive
&& log_info "Added $ACTUAL_USER to the docker group (re-login or run 'newgrp docker' to activate)" curl -fsSL https://get.docker.com | sh
fi local _rc=${PIPESTATUS[1]}
log_success "Docker installed ($(docker --version 2>/dev/null))" unset DEBIAN_FRONTEND
else hash -r 2>/dev/null || true # flush command hash so new binary is found
if [ "$_rc" -ne 0 ]; then
log_error "Docker installation failed. Try manually: curl -fsSL https://get.docker.com | sh" log_error "Docker installation failed. Try manually: curl -fsSL https://get.docker.com | sh"
return 1 return 1
fi fi
@@ -186,6 +188,13 @@ require_docker() {
log_error "Docker binary not found after install — something went wrong." log_error "Docker binary not found after install — something went wrong."
return 1 return 1
fi fi
if [ -n "$ACTUAL_USER" ] && [ "$ACTUAL_USER" != "root" ]; then
usermod -aG docker "$ACTUAL_USER" \
&& log_info "Added $ACTUAL_USER to the docker group (re-login or run 'newgrp docker' to activate)"
fi
log_success "Docker installed ($(docker --version 2>/dev/null))"
} }
# ── Command execution honoring dry-run ─────────────────────────────────────── # ── Command execution honoring dry-run ───────────────────────────────────────