install: preserve extracted dir when config wizard can't start

scripts/install.sh cleanup trap previously removed $INSTALL_DIR on
any non-zero exit if .env wasn't written yet. That made sense for
half-extracted state, but also bit us when config.sh failed at
/dev/tty (the common "curl | ssh bash" non-interactive case) — the
15MB tarball had already extracted cleanly and the user was forced
to re-download to retry on a console.

New EXTRACT_COMPLETE state flag:
  - Set to true after the tar xzf step verifies docker-compose.yml.
  - cleanup() distinguishes "extract OK, config wizard didn't run"
    from "extraction never completed":
      * First case: preserve the dir, print a resumption hint
        (cd $INSTALL_DIR && bash config.sh on an interactive console).
      * Second case: unchanged behaviour — remove the partial dir.

Typical SSH-without-tty recovery path now costs zero re-download.

Bunker Admin
This commit is contained in:
bunker-admin 2026-04-16 14:25:53 -06:00
parent 450b5ad4ba
commit 824f3cce99

View File

@ -27,6 +27,7 @@ HEALTH_INTERVAL=5
# --- State flags for cleanup ---
TARBALL_PATH=""
EXTRACT_COMPLETE=false
CONFIG_COMPLETE=false
# --- Colors ---
@ -50,7 +51,26 @@ cleanup() {
if [[ -z "$LOCAL_TARBALL" ]] && [[ -n "$TARBALL_PATH" ]] && [[ -f "$TARBALL_PATH" ]]; then
rm -f "$TARBALL_PATH"
fi
# Remove install dir only if config wizard never ran (no user data to lose)
# Post-extract state: tarball unpacked OK but config wizard didn't complete
# (common case: /dev/tty unavailable over non-interactive SSH). The expensive
# step succeeded, so preserve the dir and tell the user how to resume instead
# of forcing a full re-download.
if [[ "$EXTRACT_COMPLETE" == "true" ]] \
&& [[ "$CONFIG_COMPLETE" == "false" ]] \
&& [[ -d "$INSTALL_DIR" ]] \
&& [[ ! -f "$INSTALL_DIR/.env" ]]; then
echo ""
echo -e "${YELLOW}[INFO]${NC} Tarball extracted to $INSTALL_DIR — preserving."
echo -e "${YELLOW}[INFO]${NC} To finish setup on an interactive console:"
echo -e " ${BOLD}cd $INSTALL_DIR && bash config.sh${NC}"
echo ""
error "Configuration wizard could not run (likely no TTY available)."
return 0
fi
# Extraction failed or never happened — discard the partial dir so the next
# run-through starts from a clean slate.
if [[ "$CONFIG_COMPLETE" == "false" ]] && [[ -d "$INSTALL_DIR" ]] && [[ ! -f "$INSTALL_DIR/.env" ]]; then
rm -rf "$INSTALL_DIR"
fi
@ -244,6 +264,7 @@ if [[ ! -f "$INSTALL_DIR/docker-compose.yml" ]]; then
error "Tarball extraction failed — docker-compose.yml not found"
exit 1
fi
EXTRACT_COMPLETE=true
# Clean up downloaded tarball
if [[ -z "$LOCAL_TARBALL" ]] && [[ -f "$TARBALL_PATH" ]]; then