diff --git a/scripts/bootstrap.py b/scripts/bootstrap.py index 505295b..cf354b4 100644 --- a/scripts/bootstrap.py +++ b/scripts/bootstrap.py @@ -722,18 +722,36 @@ def main() -> int: print(f" ✗ Error testing 'mm': {e}") else: # POSIX (Linux/macOS) - user_bin = home / ".local" / "bin" - mm_sh = user_bin / "mm" + # Check likely installation locations + locations = [home / ".local" / "bin" / "mm", Path("/usr/local/bin/mm"), Path("/usr/bin/mm")] + found_shims = [p for p in locations if p.exists()] - print(f"Checking for shim file:") - print(f" mm: {'✓' if mm_sh.exists() else '✗'} ({mm_sh})") + print(f"Checking for shim files:") + for p in locations: + if p.exists(): + print(f" mm: ✓ ({p})") + else: + if args.debug: + print(f" mm: ✗ ({p})") + + if not found_shims: + print(f" mm: ✗ (No shim found in standard locations)") print() path = os.environ.get("PATH", "") - user_bin_str = str(user_bin) - in_path = user_bin_str in path + + # Find which 'mm' is actually being run + actual_mm = shutil.which("mm") print(f"Checking PATH environment variable:") - print(f" {user_bin_str} in current session PATH: {'✓' if in_path else '✗'}") + if actual_mm: + print(f" 'mm' resolved to: {actual_mm}") + # Check if it's in a directory on the PATH + if any(str(Path(actual_mm).parent) in p for p in path.split(os.pathsep)): + print(f" Command is accessible via current session PATH: ✓") + else: + print(f" Command is found but directory may not be in current PATH: ⚠️") + else: + print(f" 'mm' not found in current session PATH: ✗") print() # Test if mm command works @@ -1205,14 +1223,33 @@ if (Test-Path (Join-Path $repo 'CLI.py')) { else: # POSIX - user_bin = Path( - os.environ.get("XDG_BIN_HOME", - str(home / ".local/bin")) - ) + # If running as root (id 0), prefer /usr/bin or /usr/local/bin which are standard on PATH + if os.getuid() == 0: + user_bin = Path("/usr/local/bin") + if not os.access(user_bin, os.W_OK): + user_bin = Path("/usr/bin") + else: + user_bin = Path(os.environ.get("XDG_BIN_HOME", str(home / ".local/bin"))) + user_bin.mkdir(parents=True, exist_ok=True) mm_sh = user_bin / "mm" + # Search PATH/standard locations for existing 'mm' shims to avoid conflicts + common_paths = [user_bin, Path("/usr/local/bin"), Path("/usr/bin"), home / ".local" / "bin"] + for p_dir in common_paths: + p_mm = p_dir / "mm" + if p_mm.exists() and p_mm.resolve() != mm_sh.resolve(): + try: + # Only remove if it looks like one of our shims + content = p_mm.read_text(encoding="utf-8", errors="ignore") + if "Medeia" in content or "Medios" in content or "cli_entry" in content: + p_mm.unlink() + if not args.quiet: + print(f"Removed conflicting old shim: {p_mm}") + except Exception: + pass + # Remove old launcher to overwrite with new one if mm_sh.exists(): try: