This captures the current live stack updates across the API, Linux service scripts, tests, diagnostics, and exported console assets so the Ubuntu deployment can pull a consistent test3 build. Co-authored-by: Cursor <cursoragent@cursor.com>
91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Fix NEKO_WEBRTC_NAT1TO1 on 10.88.0.4 for WireGuard WebRTC access."""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
HOST, USER, PASS = "10.88.0.4", "eric", "4669805"
|
|
REMOTE_BASE = "/home/eric/d2ypp2-src"
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
FILES = [
|
|
"scripts/linux/service_ctl.sh",
|
|
"scripts/linux/lib/common.sh",
|
|
"scripts/linux/neko_ip_watch.sh",
|
|
]
|
|
|
|
|
|
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 300) -> 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
|
|
remote_tmp = f"/tmp/{Path(rel).name}.{stamp}"
|
|
sftp.put(str(local), remote_tmp)
|
|
sudo(c, f"cp {remote_tmp} {REMOTE_BASE}/{rel} && chmod +x {REMOTE_BASE}/{rel}")
|
|
print(f"uploaded {rel}")
|
|
sftp.close()
|
|
|
|
env_path = f"{REMOTE_BASE}/config/system-stack.env"
|
|
raw = run(c, f"cat {env_path}")
|
|
for key, val in [
|
|
("NEKO_WEBRTC_NAT1TO1", "10.88.0.4"),
|
|
("NEKO_WIREGUARD_HOST", "10.88.0.4"),
|
|
("NEKO_ACCESS_MODE", "remote"),
|
|
]:
|
|
if re.search(rf"^{re.escape(key)}=", raw, re.M):
|
|
raw = re.sub(rf"^{re.escape(key)}=.*$", f"{key}={val}", raw, count=1, flags=re.M)
|
|
else:
|
|
raw = raw.rstrip() + f"\n{key}={val}\n"
|
|
|
|
tmp_env = f"/tmp/system-stack.env.{stamp}"
|
|
sftp = c.open_sftp()
|
|
with sftp.file(tmp_env, "w") as fh:
|
|
fh.write(raw.replace("\r\n", "\n").replace("\r", "\n"))
|
|
sftp.close()
|
|
sudo(c, f"cp {tmp_env} {env_path}")
|
|
print("env:", run(c, f"grep -E 'NEKO_ACCESS_MODE|NEKO_WIREGUARD_HOST|NEKO_WEBRTC_NAT1TO1' {env_path}"))
|
|
|
|
print(
|
|
sudo(
|
|
c,
|
|
f"docker rm -f live-neko-1 live-neko-2 2>/dev/null || true; "
|
|
f"bash {REMOTE_BASE}/scripts/linux/service_ctl.sh neko start; "
|
|
f"bash {REMOTE_BASE}/scripts/linux/service_ctl.sh neko status | head -30",
|
|
timeout=600,
|
|
)
|
|
)
|
|
print(sudo(c, "systemctl restart live-neko-ip-watch.service"))
|
|
time.sleep(10)
|
|
print(run(c, "curl -sS -m 5 -o /dev/null -w 'local9200=%{http_code}\n' http://127.0.0.1:9200/"))
|
|
print(run(c, "curl -sS -m 5 -o /dev/null -w 'wg9200=%{http_code}\n' http://10.88.0.4:9200/"))
|
|
print(sudo(c, "docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' | grep neko || true"))
|
|
print(
|
|
sudo(
|
|
c,
|
|
"docker inspect live-neko-1 --format '{{range .Config.Env}}{{println .}}{{end}}' | grep NEKO_WEBRTC_NAT1TO1 || true",
|
|
)
|
|
)
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|