forked from CodeGraphContext/CodeGraphContext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_macos.py
More file actions
95 lines (79 loc) · 3.66 KB
/
setup_macos.py
File metadata and controls
95 lines (79 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# src/codegraphcontext/cli/setup_macos.py
import platform
import time
from pathlib import Path
def _has_brew(run_comman
8B72
d, console) -> bool:
return run_command(["which", "brew"], console, check=False) is not None
def _brew_install_neo4j(run_command, console) -> str:
if run_command(["brew", "install", "neo4j@5"], console, check=False):
return "neo4j@5"
if run_command(["brew", "install", "neo4j"], console, check=False):
return "neo4j"
return ""
def _brew_start(service: str, run_command, console) -> bool:
return run_command(["brew", "services", "start", service], console, check=False) is not None
def _set_initial_password(new_pw: str, run_command, console) -> bool:
cmd = [
"cypher-shell",
"-u", "neo4j",
"-p", "neo4j",
f"ALTER CURRENT USER SET PASSWORD FROM 'neo4j' TO '{new_pw}'",
]
return run_command(cmd, console, check=False) is not None
def setup_macos_binary(console, prompt, run_command, _generate_mcp_json):
"""Automates Neo4j install & config on macOS via Homebrew."""
os_name = platform.system()
console.print(f"Detected Operating System: [bold yellow]{os_name}[/bold yellow]")
if os_name != "Darwin":
console.print("[yellow]This installer is for macOS only.[/yellow]")
return
console.print("[bold]Starting automated Neo4j installation for macOS.[/bold]")
if not prompt([{
"type": "confirm",
"message": "Proceed with Homebrew-based install of Neo4j?",
"name": "proceed",
"default": True
}]).get("proceed"):
return
console.print("\n[bold]Step: Checking for Homebrew...[/bold]")
if not _has_brew(run_command, console):
console.print(
"[bold red]Homebrew not found.[/bold red] "
"Install from [bold blue]https://brew.sh[/bold blue] and re-run this setup."
)
return
console.print("\n[bold]Step: Installing Neo4j via Homebrew...[/bold]")
service = _brew_install_neo4j(run_command, console)
if not service:
console.print("[bold red]Failed to install Neo4j via Homebrew.[/bold red]")
return
console.print(f"\n[bold]Step: Starting Neo4j service ({service})...[/bold]")
if not _brew_start(service, run_command, console):
console.print("[bold red]Failed to start Neo4j with brew services.[/bold red]")
return
while True:
answers = prompt([
{"type": "password", "message": "Enter a new password for Neo4j:", "name": "pw"},
{"type": "password", "message": "Confirm the new password:", "name": "pw2"},
]) or {}
if not answers:
return
pw, pw2 = answers.get("pw"), answers.get("pw2")
if pw and pw == pw2:
new_password = pw
break
console.print("[red]Passwords do not match or are empty. Please try again.[/red]")
console.print("\n[yellow]Waiting 10 seconds for Neo4j to finish starting...[/yellow]")
time.sleep(10)
console.print("\n[bold]Step: Setting initial password with cypher-shell...[/bold]")
if not _set_initial_password(new_password, run_command, console):
console.print(
"[bold red]Failed to set the initial password.[/bold red]\n"
"Try manually:\n"
" cypher-shell -u neo4j -p neo4j \"ALTER CURRENT USER SET PASSWORD FROM 'neo4j' TO '<your_pw>'\""
)
return
creds = {"uri": "neo4j://localhost:7687", "username": "neo4j", "password": new_password}
_generate_mcp_json(creds)
env_path = Path.home() / ".codegraphcontext" / ".env"
console.print(f"\n[bold green]All done![/bold green] Neo4j running. Credentials saved to: [bold]{env_path}[/bold]")