#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Deploy Neko enable-switch sync + toggle UX (no global busy freeze).""" 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 = "Xiao4669805" HOSTS = [("dy", "108.174.50.68"), ("dylive", "107.173.30.245")] FILES = [ "frontend/src/components/EnableSwitch.tsx", "frontend/src/components/YtRelayProStatusPanel.tsx", "frontend/src/components/YtAssignPanel.tsx", "frontend/src/app/shorts/page.tsx", "frontend/src/app/yt-long/page.tsx", ] REMOTE = r'''#!/bin/bash set -euo pipefail python3 - <<'PY' from pathlib import Path pairs=[ ('/tmp/_es.tsx','/opt/douyinWEB/frontend/src/components/EnableSwitch.tsx'), ('/tmp/_yrpsp.tsx','/opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx'), ('/tmp/_yap.tsx','/opt/douyinWEB/frontend/src/components/YtAssignPanel.tsx'), ('/tmp/_shorts.tsx','/opt/douyinWEB/frontend/src/app/shorts/page.tsx'), ('/tmp/_ytlong.tsx','/opt/douyinWEB/frontend/src/app/yt-long/page.tsx'), ] for s,d in pairs: data=Path(s).read_bytes().replace(b'\r\n',b'\n').replace(b'\r',b'\n') Path(d).write_bytes(data) print('ok', d, len(data)) text=Path('/opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx').read_text(encoding='utf-8') assert 'nekoPowerOn' in text assert 'Optimistic' in text or 'optimistic' in text.lower() or 'Optimistic' in text print('assert_ok') PY cd /opt/douyinWEB/frontend npm run build 2>&1 | tail -40 systemctl restart douyinweb-web.service sleep 2 systemctl is-active douyinweb-web.service ''' def connect(host: str): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(8): try: c.connect(host, 22, "root", PASS, timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=90) return c except Exception as e: print(f"ssh_retry {host} {i}: {e}", flush=True) time.sleep(2 + i) raise SystemExit(f"ssh_fail {host}") def deploy(label: str, host: str): print(f"\n===== {label} {host} =====", flush=True) c = connect(host) sftp = c.open_sftp() mapping = [ (FILES[0], "/tmp/_es.tsx"), (FILES[1], "/tmp/_yrpsp.tsx"), (FILES[2], "/tmp/_yap.tsx"), (FILES[3], "/tmp/_shorts.tsx"), (FILES[4], "/tmp/_ytlong.tsx"), ] for rel, remote in mapping: data = (ROOT / rel).read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n") with sftp.file(remote, "wb") as f: f.write(data) with sftp.file("/tmp/_deploy_neko_switch_ux.sh", "w") as f: f.write(REMOTE.replace("\r\n", "\n")) sftp.close() _, o, e = c.exec_command("bash /tmp/_deploy_neko_switch_ux.sh", timeout=700) print((o.read() + e.read()).decode("utf-8", "replace")[-5000:], flush=True) c.close() def main(): for label, host in HOSTS: deploy(label, host) if __name__ == "__main__": main()