-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstaller.py
More file actions
384 lines (301 loc) · 13.2 KB
/
installer.py
File metadata and controls
384 lines (301 loc) · 13.2 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#!/usr/bin/env python3
"""ECHO interactive installer. Run via: curl -fsSL .../install.sh | bash"""
# /// script
# requires-python = ">=3.11"
# dependencies = ["httpx"]
# ///
from __future__ import annotations
import json
import os
import subprocess
import sys
from pathlib import Path
# ── Colors ──────────────────────────────────────────────────
GREEN = "\033[0;32m"
YELLOW = "\033[1;33m"
RED = "\033[0;31m"
BOLD = "\033[1m"
DIM = "\033[2m"
NC = "\033[0m"
def info(msg: str) -> None:
print(f" {msg}")
def ok(msg: str) -> None:
print(f" {GREEN}✓{NC} {msg}")
def warn(msg: str) -> None:
print(f" {YELLOW}⚠{NC} {msg}")
def die(msg: str) -> None:
print(f" {RED}Error: {msg}{NC}", file=sys.stderr)
sys.exit(1)
def ask(prompt: str, default: str = "") -> str:
display = f" [{default}]" if default else ""
try:
value = input(f" {prompt}{display}: ").strip()
return value if value else default
except (EOFError, KeyboardInterrupt):
print()
return default
def ask_yn(prompt: str, default: bool = True) -> bool:
hint = "Y/n" if default else "y/N"
try:
value = input(f" {prompt} ({hint}): ").strip().lower()
if not value:
return default
return value in ("y", "yes")
except (EOFError, KeyboardInterrupt):
print()
return default
def run(cmd: list[str], **kwargs) -> subprocess.CompletedProcess:
return subprocess.run(cmd, **kwargs)
def banner() -> None:
print()
print(f" {BOLD}ECHO{NC} - Explore Calls, Hearings & Observations")
print(f" {DIM}Search your Zoom meeting transcripts from any MCP-compatible AI tool.{NC}")
print()
# ── Step 1: Install location ────────────────────────────────
def step_install(home: Path) -> Path:
print(f"{BOLD}Step 1: Install location{NC}")
default = str(home / "echo-mcp")
install_dir = Path(ask("Install directory", default))
if (install_dir / ".git").exists():
info(f"{YELLOW}Existing installation found. Updating...{NC}")
run(["git", "-C", str(install_dir), "pull", "--ff-only"], capture_output=True)
else:
info("Cloning ECHO...")
run(["git", "clone", "--quiet", "https://github.com/Percona-Lab/ECHO.git", str(install_dir)])
ok(f"Installed at {install_dir}")
return install_dir
# ── Step 2: Dependencies ────────────────────────────────────
def step_deps(install_dir: Path) -> None:
print()
print(f"{BOLD}Step 2: Dependencies{NC}")
info("Installing Python dependencies...")
run(["uv", "sync", "--quiet"], cwd=install_dir)
ok("Dependencies installed")
# ── Step 3: Zoom OAuth ──────────────────────────────────────
def _resolve_registry(org_slug: str) -> dict | None:
"""Look up an org in the registry and return {client_id, bff_url} or None."""
try:
import httpx
resp = httpx.get(
"https://raw.githubusercontent.com/Percona-Lab/ECHO/main/client_registry.json",
timeout=5,
)
if resp.status_code != 200:
return None
entry = resp.json().get("orgs", {}).get(org_slug)
if entry is None:
return None
if isinstance(entry, str):
return {"client_id": entry, "bff_url": None}
return {
"client_id": entry.get("client_id", ""),
"bff_url": entry.get("bff_url"),
}
except Exception:
return None
def _write_env(env_file: Path, settings: dict) -> None:
"""Write key=value lines to .env, preserving order."""
env_file.write_text(
"".join(f"{k}={v}\n" for k, v in settings.items() if v is not None)
)
def step_zoom_oauth(install_dir: Path) -> str | None:
print()
print(f"{BOLD}Step 3: Zoom OAuth Setup{NC}")
env_file = install_dir / ".env"
# Check for existing config
if env_file.exists():
existing = {}
for line in env_file.read_text().splitlines():
if "=" in line:
k, v = line.split("=", 1)
existing[k.strip()] = v.strip()
if existing.get("ZOOM_SUBDOMAIN") or (
existing.get("ZOOM_CLIENT_ID")
and not existing["ZOOM_CLIENT_ID"].startswith("your_")
):
summary = existing.get("ZOOM_SUBDOMAIN") or (existing.get("ZOOM_CLIENT_ID", "")[:8] + "...")
ok(f"ECHO already configured for: {DIM}{summary}{NC}")
if ask_yn("Keep existing config?"):
return existing.get("ZOOM_CLIENT_ID") or existing.get("ZOOM_SUBDOMAIN")
# Ask for Zoom subdomain and look up in registry
org_slug = ask("Your Zoom subdomain (the prefix before .zoom.us, e.g. acme)", "")
settings: dict[str, str] = {}
if org_slug:
# Clean up in case they entered the full domain
org_slug = org_slug.replace("https://", "").replace(".zoom.us", "").strip().lower()
entry = _resolve_registry(org_slug)
if entry and entry["client_id"]:
ok(f"Found registered config for {BOLD}{org_slug}{NC}")
# Store the subdomain; the server resolves client_id + bff_url
# from the registry at runtime (so future registry updates flow
# through without reinstall).
settings["ZOOM_SUBDOMAIN"] = org_slug
_write_env(env_file, settings)
ok("Config saved to .env")
return org_slug
warn(f"No registered config found for {BOLD}{org_slug}{NC}")
# Registry miss — ask if they have a Client ID
print()
if ask_yn("Do you have a Zoom OAuth Client ID?", default=False):
client_id = ask("Zoom OAuth Client ID", "")
if client_id:
settings["ZOOM_CLIENT_ID"] = client_id
# Without a registered BFF, the client will try to contact Zoom
# directly which requires ZOOM_CLIENT_SECRET too.
client_secret = ask(
"Zoom OAuth Client Secret (required without a registered BFF)",
"",
)
if client_secret:
settings["ZOOM_CLIENT_SECRET"] = client_secret
_write_env(env_file, settings)
ok("Config saved to .env")
return client_id
print()
info("You need a Client ID from a Zoom OAuth app before ECHO can work.")
info("If you have Zoom admin access, create one yourself. Otherwise ask your Zoom admin.")
print()
info(f"{BOLD}How to create the Zoom OAuth app:{NC}")
info(f" 1. Go to https://marketplace.zoom.us > Develop > Build App")
info(f" 2. Select General App, set redirect URL: http://localhost:8090/callback")
info(f" 3. Under Scopes, choose User-managed and add:")
info(f" cloud_recording:read:content")
info(f" cloud_recording:read:list_user_recordings")
info(f" user:read:user")
info(f" 4. Activate the app and copy the Client ID")
print()
info(f"Full instructions: https://github.com/Percona-Lab/ECHO#prerequisites")
print()
info("To register your org so others can skip this step,")
info("submit a PR adding your Client ID to client_registry.json.")
return None
# ── Step 4: Authenticate ────────────────────────────────────
def step_auth(install_dir: Path, client_id: str | None) -> None:
print()
print(f"{BOLD}Step 4: Zoom Authentication{NC}")
token_file = Path.home() / ".echo" / "tokens.json"
if token_file.exists():
ok("Already authenticated (tokens found at ~/.echo/tokens.json)")
elif client_id:
if ask_yn("Log in to Zoom now?"):
run(["uv", "run", "echo-login"], cwd=install_dir)
else:
info(f"{DIM}Run 'uv run echo-login' later to authenticate.{NC}")
else:
info(f"{DIM}Skipped (no Client ID configured yet).{NC}")
info(f"{DIM}After adding your Client ID to .env, run: uv run echo-login{NC}")
# ── Step 5: Configure AI client ─────────────────────────────
def step_configure_client(install_dir: Path) -> None:
print()
print(f"{BOLD}Step 5: Configure AI Client{NC}")
mcp_entry = {
"type": "stdio",
"command": "uv",
"args": ["run", "--directory", str(install_dir), "echo-mcp"],
}
# Claude Code
claude_settings = Path.home() / ".claude" / "settings.json"
has_claude_code = claude_settings.exists() or _command_exists("claude")
if has_claude_code:
if ask_yn("Configure Claude Code?"):
_merge_mcp_config(claude_settings, "echo", mcp_entry)
_install_claude_code_commands(install_dir)
ok("Claude Code configured")
# Claude Desktop
claude_desktop = _find_claude_desktop_config()
if claude_desktop and claude_desktop.exists():
if ask_yn("Configure Claude Desktop?"):
_merge_mcp_config(claude_desktop, "echo", mcp_entry)
ok("Claude Desktop configured (restart to apply)")
if not has_claude_code and not (claude_desktop and claude_desktop.exists()):
info("No AI clients detected. Add ECHO to your MCP client config manually:")
info(f'{DIM} "echo": {json.dumps(mcp_entry)}{NC}')
def _install_claude_code_commands(install_dir: Path) -> None:
"""Copy ECHO's slash-command wrappers into ~/.claude/commands/.
MCP prompts don't surface as slash commands in Claude Code, so we
install thin Markdown command wrappers that invoke the MCP tools.
"""
src = install_dir / "commands"
if not src.exists():
return
dst = Path.home() / ".claude" / "commands"
dst.mkdir(parents=True, exist_ok=True)
import shutil
count = 0
for cmd in src.glob("echo-*.md"):
shutil.copy2(cmd, dst / cmd.name)
count += 1
if count:
info(f"Installed {count} slash commands to {dst}")
def _merge_mcp_config(path: Path, name: str, entry: dict) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
try:
cfg = json.loads(path.read_text())
except (FileNotFoundError, json.JSONDecodeError):
cfg = {}
cfg.setdefault("mcpServers", {})[name] = entry
path.write_text(json.dumps(cfg, indent=2) + "\n")
info(f"Updated {path}")
def _find_claude_desktop_config() -> Path | None:
import platform
if platform.system() == "Darwin":
p = Path.home() / "Library" / "Application Support" / "Claude" / "claude_desktop_config.json"
else:
p = Path.home() / ".config" / "Claude" / "claude_desktop_config.json"
return p if p.exists() else None
def _command_exists(cmd: str) -> bool:
try:
run(["which", cmd], capture_output=True)
return True
except Exception:
return False
# ── Done (no Client ID) ─────────────────────────────────────
def step_done_no_client(install_dir: Path) -> None:
print()
print(f" {YELLOW}{BOLD}ECHO partially installed.{NC}")
print()
info("ECHO needs a Zoom OAuth Client ID to work.")
info("Once you have one, re-run the installer:")
print()
info(f" {BOLD}curl -fsSL https://raw.githubusercontent.com/Percona-Lab/ECHO/main/install.sh | bash{NC}")
print()
info(f"{DIM}How to create a Zoom OAuth app: https://github.com/Percona-Lab/ECHO#prerequisites{NC}")
print()
# ── Done ────────────────────────────────────────────────────
def step_done(install_dir: Path) -> None:
token_file = Path.home() / ".echo" / "tokens.json"
print()
print(f" {GREEN}{BOLD}ECHO installed!{NC}")
print()
info(f"{DIM}Location:{NC} {install_dir}")
if token_file.exists():
info(f"{DIM}Auth:{NC} Authenticated")
else:
info(f"{DIM}Auth:{NC} Run 'uv run echo-login' to connect your Zoom account")
print()
info(f'{DIM}Usage:{NC} Ask your AI assistant about your Zoom meetings.')
info(f'{DIM}Example:{NC} "Search my Zoom calls for quarterly roadmap"')
print()
# ── Main ────────────────────────────────────────────────────
def main() -> None:
# Always reopen stdin from /dev/tty. When run via `curl | bash`,
# stdin may be the pipe or an intermediary that doesn't block on input.
# Opening /dev/tty directly guarantees we read from the real terminal.
try:
sys.stdin = open("/dev/tty")
except OSError:
pass # Windows or no tty available, fall through to defaults
banner()
home = Path.home()
install_dir = step_install(home)
step_deps(install_dir)
client_id = step_zoom_oauth(install_dir)
if not client_id:
# Can't continue without a Client ID. Tell them how to resume.
step_done_no_client(install_dir)
return
step_auth(install_dir, client_id)
step_configure_client(install_dir)
step_done(install_dir)
if __name__ == "__main__":
main()