#!/usr/bin/env python3 """Deploy neko hardening scripts to 10.88.0.8 and smoke-check reconfigure.""" from __future__ import annotations import sys import time from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") HOST, USER, PASS = "10.88.0.8", "eric", "4669805" REMOTE_BASE = "/opt/live/d2ypp" ROOT = Path(__file__).resolve().parent.parent FILES = [ "src/neko_webrtc_ports.py", "tools/render_neko_compose.py", "scripts/linux/service_ctl.sh", "scripts/linux/lib/common.sh", "scripts/linux/neko_ip_watch.sh", "config/system-stack.env.example", "live-platform/config/defaults/services/neko.json", "tests/test_neko_webrtc_ports.py", ] def run(c: paramiko.SSHClient, cmd: str, timeout: int = 120) -> str: _, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True) return (o.read() + e.read()).decode("utf-8", "replace") def sudo(c: paramiko.SSHClient, cmd: str, timeout: int = 300) -> str: return run(c, f"echo {PASS!r} | sudo -S -p '' bash -lc {cmd!r}", timeout=timeout) def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, username=USER, password=PASS, timeout=20) sftp = c.open_sftp() stamp = int(time.time()) for rel in FILES: local = ROOT / rel if not local.exists(): print("MISSING", rel) continue remote_tmp = f"/tmp/{Path(rel).name}.{stamp}" sftp.put(str(local), remote_tmp) remote = f"{REMOTE_BASE}/{rel}" sudo(c, f"mkdir -p $(dirname {remote}) && cp {remote_tmp} {remote} && chmod +x {remote} || chmod 644 {remote}") # Ensure LF on shell/python text after Windows SFTP sudo(c, f"sed -i 's/\\r$//' {remote}") print("uploaded", rel) sftp.close() print("=== unit smoke on host ===") print( run( c, f"cd {REMOTE_BASE} && NEKO_SKIP_UDP_PORT_PROBE=1 python3 -m unittest tests.test_neko_webrtc_ports -v 2>&1 | tail -30", timeout=60, ) ) print("=== neko reconfigure (uses autofix) ===") # Don't force recreate if already healthy — just re-render and verify status. # Use reconfigure only if we want to apply script path; containers already good. out = sudo( c, f"bash {REMOTE_BASE}/scripts/linux/service_ctl.sh neko status | head -20; " f"python3 {REMOTE_BASE}/tools/render_neko_compose.py --count 2 " f"--output {REMOTE_BASE}/services/neko/docker-compose.generated.yml " f"--stack-env {REMOTE_BASE}/config/system-stack.env 2>&1 | tail -20; " f"grep -E 'NEKO_WEBRTC_UDP_RANGE_1=|NEKO_WEBRTC_EPR_1=' {REMOTE_BASE}/config/system-stack.env; " f"grep -E '52000-|52101-' {REMOTE_BASE}/services/neko/docker-compose.generated.yml | head -10", timeout=120, ) print(out[:5000]) print("=== health ===") print( run( c, "docker ps --format 'table {{.Names}}\t{{.Status}}' | grep neko; " "printf '9200='; curl -sS -m 5 -o /dev/null -w '%{http_code}' http://127.0.0.1:9200/; echo; " "printf '9201='; curl -sS -m 5 -o /dev/null -w '%{http_code}' http://127.0.0.1:9201/; echo", ) ) c.close() return 0 if __name__ == "__main__": raise SystemExit(main())