sh2/d2ypp2/tools/fix_host04_caddy.py
2026-06-14 10:41:48 -05:00

47 lines
1.6 KiB
Python

#!/usr/bin/env python3
from __future__ import annotations
import time
import paramiko
HOST, USER, PASS = "10.88.0.4", "eric", "4669805"
BASE = "/home/eric/d2ypp2-src"
def run(cmd: str, timeout: int = 180, sudo: bool = False) -> str:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(HOST, username=USER, password=PASS, timeout=20)
_, stdout, stderr = client.exec_command(f"export LC_ALL=C.UTF-8; {cmd}", timeout=timeout, get_pty=bool(sudo))
if sudo:
stdout.channel.send(f"{PASS}\n")
out = (stdout.read() + stderr.read()).decode("utf-8", "replace")
client.close()
return out.strip()
def main() -> int:
print("=== disk index bundle ===")
print(run(f"grep -o 'page-[a-z0-9]*\\.js' {BASE}/web-console/out/index.html | head -1"))
print("\n=== served bundle before edge reinstall ===")
print(run("curl -sS -m 8 http://127.0.0.1/ | grep -o 'page-[a-z0-9]*\\.js' | head -1"))
print("\n=== caddy root hints ===")
print(run(f"grep -R 'web-console/out' {BASE}/live-platform /etc/caddy 2>/dev/null | head -15"))
print("\n=== reinstall live edge ===")
print(run(f"sudo -S -p '' bash {BASE}/scripts/linux/reinstall_live_edge.sh", sudo=True))
time.sleep(8)
print("\n=== served bundle after edge reinstall ===")
print(run("curl -sS -m 8 http://127.0.0.1/ | grep -o 'page-[a-z0-9]*\\.js' | head -1"))
print(run("curl -sS -m 8 -o /dev/null -w 'http_code=%{http_code}' http://127.0.0.1/; echo"))
return 0
if __name__ == "__main__":
raise SystemExit(main())