forked from patterniha/MITM-DomainFronting
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.py
More file actions
64 lines (53 loc) · 2.36 KB
/
Copy pathbootstrap.py
File metadata and controls
64 lines (53 loc) · 2.36 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
#!/usr/bin/env python3
"""Beginner-friendly local workspace bootstrapper."""
from __future__ import annotations
import argparse
import os
import subprocess
import sys
import venv
from pathlib import Path
ROOT = Path(__file__).resolve().parent
def run(cmd: list[str], label: str, required: bool = True) -> bool:
print(f"[...] {label}")
proc = subprocess.run(cmd, cwd=str(ROOT), check=False)
if proc.returncode == 0:
print(f"[OK ] {label}")
return True
print(f"[WARN] {label} failed with exit code {proc.returncode}")
if required:
raise SystemExit(proc.returncode)
return False
def venv_python(venv_dir: Path) -> Path:
return venv_dir / ("Scripts" if os.name == "nt" else "bin") / ("python.exe" if os.name == "nt" else "python")
def main() -> int:
parser = argparse.ArgumentParser(description="Set up Xray-Cooperative-Overlay local tooling")
parser.add_argument("--skip-browser-tools", action="store_true", help="do not install browser diagnostic dependencies")
parser.add_argument("--skip-xray", action="store_true", help="do not download local Xray runtime")
args = parser.parse_args()
print("=" * 72)
print(" Xray-Cooperative-Overlay Bootstrap")
print("=" * 72)
for rel in ("Xray-config", "providers", ".local-state", "browser-profiles"):
(ROOT / rel).mkdir(exist_ok=True)
venv_dir = ROOT / ".venv"
if not venv_dir.exists():
print("[...] Creating .venv")
venv.create(venv_dir, with_pip=True)
print("[OK ] Created .venv")
py = venv_python(venv_dir)
run([str(py), "-m", "pip", "install", "--upgrade", "pip"], "Upgrade pip", required=False)
req = ROOT / "requirements-browser-diagnostics.txt"
if req.exists() and not args.skip_browser_tools:
run([str(py), "-m", "pip", "install", "-r", str(req)], "Install browser diagnostics requirements", required=False)
xray_name = "xray.exe" if os.name == "nt" else "xray"
if not args.skip_xray and not (ROOT / "xray" / xray_name).exists():
run([str(py), str(ROOT / "scripts" / "install_xray.py"), "--out-dir", str(ROOT / "xray")], "Install local Xray runtime", required=False)
print("=" * 72)
print("Bootstrap complete")
print(f"Run GUI: {py} scripts/gui.py")
print(f"Run audit: {py} main.py audit")
print("=" * 72)
return 0
if __name__ == "__main__":
raise SystemExit(main())