From a2ba2ced08cd76b8de9420ebca2f976616cb947a Mon Sep 17 00:00:00 2001 From: nose Date: Wed, 24 Dec 2025 02:58:58 -0800 Subject: [PATCH] bootstrap: auto-remove interfering .pths proactively when auto-fix chosen; fallback installer for non-exec files --- scripts/bootstrap.sh | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index db6d14e..56eeeb7 100644 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -308,6 +308,7 @@ if [[ "$NOINSTALL" != "true" ]]; then fi read -p "Attempt automatic fix now? (y/N) " REPLY if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then + AUTOFIX_INTERACTIVE=1 if attempt_fix_urllib3 "$VENV_PY"; then echo "Success: urllib3 issues resolved; continuing..." >&2 else @@ -411,7 +412,7 @@ if [[ -f "$USER_BIN/mm" ]]; then echo "Backing up existing $USER_BIN/mm to $USER_BIN/mm.bak.$(date +%s)" mv "$USER_BIN/mm" "$USER_BIN/mm.bak.$(date +%s)" fi -cat > "$USER_BIN/mm" < "$USER_BIN/mm" <<'EOF' #!/usr/bin/env bash REPO="$REPO" VENV="$REPO/.venv" @@ -429,7 +430,27 @@ chmod +x "$USER_BIN/mm" if "$USER_BIN/mm" --help >/dev/null 2>&1; then echo "Global 'mm' launcher verified: $USER_BIN/mm runs correctly." else - echo "Warning: Global 'mm' launcher failed to run in this shell. Ensure $USER_BIN is on your PATH and the venv is installed; try: $VENV_PY -m medeia_macina.cli_entry --help" >&2 + # Capture error output to detect permission issues + err=$( { "$USER_BIN/mm" --help >/dev/null 2>&1 || true; } 2>&1 || true ) + echo "Warning: Global 'mm' launcher failed to run in this shell. Error: ${err:-unknown}" >&2 + + # If we detected a permission denied (e.g., filesystem mounted noexec), fall back to user-local bin + if echo "${err}" | grep -qi "Permission denied" || [[ ${err:-} == *"Permission denied"* ]]; then + FALLBACK_BIN="$HOME/.local/bin" + mkdir -p "$FALLBACK_BIN" + # Backup the problematic file and copy to fallback (use a single timestamp variable) + backup="$USER_BIN/mm.broken.$(date +%s)" + if mv "$USER_BIN/mm" "$backup" 2>/dev/null; then + echo "Moved non-executable launcher to backup: $backup" >&2 + cp "$backup" "$FALLBACK_BIN/mm" 2>/dev/null || true + chmod +x "$FALLBACK_BIN/mm" 2>/dev/null || true + USER_BIN="$FALLBACK_BIN" + echo "Installed launcher to fallback location: $USER_BIN/mm" >&2 + echo "Ensure '$USER_BIN' is on your PATH (e.g. add 'export PATH=\"$USER_BIN:\$PATH\"' to your shell rc)." >&2 + else + echo "Failed to move the launcher for fallback installation; manual inspection recommended: $USER_BIN/mm" >&2 + fi + fi fi # Ensure the user's bin is on PATH for future sessions by adding to ~/.profile if needed