#!/usr/bin/env python3 import paramiko import sys from pathlib import Path sys.stdout.reconfigure(encoding="utf-8", errors="replace") LOCAL = Path(__file__).resolve().parents[1] FILES = [ "frontend/src/components/YtAssignPanel.tsx", "frontend/src/components/YtRelayOpsHero.tsx", ] def put(c, root, sudo=None): sftp = c.open_sftp() for rel in FILES: tmp = f"/tmp/_dd_{Path(rel).name}" with sftp.file(tmp, "wb") as f: f.write((LOCAL / rel).read_bytes()) dst = f"{root}/{rel}" cmd = ( f"echo '{sudo}' | sudo -S -p '' bash -lc \"install -m 644 {tmp} {dst}; sed -i 's/\\r$//' {dst}\"" if sudo else f"install -m 644 {tmp} {dst}; sed -i 's/\\r$//' {dst}" ) c.exec_command(cmd, timeout=30)[1].read() print("ok", rel, flush=True) sftp.close() def build(c, sudo=None): inner = ( "cd /opt/douyinWEB/frontend && npm run build >/tmp/fe_dd.log 2>&1 && echo FE_OK || (tail -15 /tmp/fe_dd.log; echo FE_FAIL); " "systemctl restart douyinweb-web; systemctl is-active douyinweb-web" ) cmd = f"echo '{sudo}' | sudo -S -p '' bash -lc '{inner}'" if sudo else inner _i, o, e = c.exec_command(cmd, timeout=600) print((o.read() + e.read()).decode("utf-8", "replace"), flush=True) p = paramiko.SSHClient(); p.set_missing_host_key_policy(paramiko.AutoAddPolicy()) p.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False) print("PHYS", flush=True); put(p, "/opt/douyinWEB", "4669805"); build(p, "4669805"); p.close() v = paramiko.SSHClient(); v.set_missing_host_key_policy(paramiko.AutoAddPolicy()) v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False) print("VPS", flush=True); put(v, "/opt/douyinWEB"); build(v); v.close() print("DONE", flush=True)