# -*- coding: utf-8 -*- from __future__ import annotations import sys import time from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = Path(__file__).resolve().parents[1] PASS = "4669805" SH = r"""#!/bin/bash set -euo pipefail install -m 644 /tmp/_ytnav_nav.ts /opt/douyinWEB/frontend/src/lib/youtubeLiveNav.ts install -m 644 /tmp/_ytnav_page.tsx /opt/douyinWEB/frontend/src/app/youtube/page.tsx systemctl stop douyinweb-web || true cd /opt/douyinWEB/frontend && npm run build systemctl start douyinweb-web sleep 2 systemctl is-active douyinweb-web grep -n 'never Shorts' /opt/douyinWEB/frontend/src/lib/youtubeLiveNav.ts | head -2 echo BUILD_OK """ def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(8): try: c.connect( "107.173.30.245", 4014, "eric", PASS, timeout=50, banner_timeout=100, allow_agent=False, look_for_keys=False, ) break except Exception as ex: print("ssh", i, type(ex).__name__, flush=True) time.sleep(2) else: raise SystemExit("ssh fail") sftp = c.open_sftp() with sftp.file("/tmp/_ytnav_nav.ts", "w") as f: f.write((ROOT / "frontend/src/lib/youtubeLiveNav.ts").read_text(encoding="utf-8")) with sftp.file("/tmp/_ytnav_page.tsx", "w") as f: f.write((ROOT / "frontend/src/app/youtube/page.tsx").read_text(encoding="utf-8")) with sftp.file("/tmp/_ytnav_deploy.sh", "w") as f: f.write(SH) sftp.close() _, o, e = c.exec_command(f"echo '{PASS}' | sudo -S -p '' bash /tmp/_ytnav_deploy.sh", timeout=700) out = (o.read() + e.read()).decode("utf-8", "replace") print(out[-10000:] if len(out) > 10000 else out, flush=True) c.close() return 0 if "BUILD_OK" in out else 1 if __name__ == "__main__": raise SystemExit(main())