bootstrap: auto-remove interfering .pths proactively when auto-fix chosen; fallback installer for non-exec files

This commit is contained in:
nose
2025-12-24 02:58:58 -08:00
parent 983cb193cd
commit a2ba2ced08

View File

@@ -308,6 +308,7 @@ if [[ "$NOINSTALL" != "true" ]]; then
fi fi
read -p "Attempt automatic fix now? (y/N) " REPLY read -p "Attempt automatic fix now? (y/N) " REPLY
if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then if [[ "$REPLY" == "y" || "$REPLY" == "Y" ]]; then
AUTOFIX_INTERACTIVE=1
if attempt_fix_urllib3 "$VENV_PY"; then if attempt_fix_urllib3 "$VENV_PY"; then
echo "Success: urllib3 issues resolved; continuing..." >&2 echo "Success: urllib3 issues resolved; continuing..." >&2
else 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)" echo "Backing up existing $USER_BIN/mm to $USER_BIN/mm.bak.$(date +%s)"
mv "$USER_BIN/mm" "$USER_BIN/mm.bak.$(date +%s)" mv "$USER_BIN/mm" "$USER_BIN/mm.bak.$(date +%s)"
fi fi
cat > "$USER_BIN/mm" <<EOF cat > "$USER_BIN/mm" <<'EOF'
#!/usr/bin/env bash #!/usr/bin/env bash
REPO="$REPO" REPO="$REPO"
VENV="$REPO/.venv" VENV="$REPO/.venv"
@@ -429,7 +430,27 @@ chmod +x "$USER_BIN/mm"
if "$USER_BIN/mm" --help >/dev/null 2>&1; then if "$USER_BIN/mm" --help >/dev/null 2>&1; then
echo "Global 'mm' launcher verified: $USER_BIN/mm runs correctly." echo "Global 'mm' launcher verified: $USER_BIN/mm runs correctly."
else 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 fi
# Ensure the user's bin is on PATH for future sessions by adding to ~/.profile if needed # Ensure the user's bin is on PATH for future sessions by adding to ~/.profile if needed