douyinWEB/scripts/_deploy_neko_ui_simplify.py
2026-09-13 22:10:49 -05:00

59 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy simplified Neko button row (FE only)."""
from __future__ import annotations
import sys
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB")
FILES = ["frontend/src/components/YtRelayProStatusPanel.tsx"]
REMOTE = r'''#!/bin/bash
set -euo pipefail
ROOT=/opt/douyinWEB
i=0
while [ -f "/tmp/_dy_neko_ui_${i}.path" ]; do
rel=$(cat "/tmp/_dy_neko_ui_${i}.path")
dst="$ROOT/$rel"
mkdir -p "$(dirname "$dst")"
python3 -c "from pathlib import Path; p=Path('/tmp/_dy_neko_ui_${i}.bin'); d=Path('$dst'); d.write_bytes(p.read_bytes().replace(b'\r\n',b'\n').replace(b'\r',b'\n')); print('ok', d)"
i=$((i+1))
done
cd "$ROOT/frontend"
npm run build >/tmp/dy_neko_ui_fe.log 2>&1 && echo FE_OK || { echo FE_FAIL; tail -40 /tmp/dy_neko_ui_fe.log; exit 1; }
systemctl restart douyinweb-web.service
sleep 2
systemctl is-active douyinweb-web.service
grep -nE '另开本机|启动本机 Neko|去配对远程|打开工作室' "$ROOT/frontend/src/components/YtRelayProStatusPanel.tsx" | head -20
'''
def deploy(label, host, port, user, pw, *, sudo):
print(f"\n===== {label} =====")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(host, port, user, pw, timeout=45, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for i, rel in enumerate(FILES):
data = (ROOT / rel).read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
with sftp.file(f"/tmp/_dy_neko_ui_{i}.bin", "wb") as f:
f.write(data)
with sftp.file(f"/tmp/_dy_neko_ui_{i}.path", "w") as f:
f.write(rel.replace("\\", "/"))
with sftp.file("/tmp/_dy_neko_ui_remote.sh", "w") as f:
f.write(REMOTE.replace("\r\n", "\n"))
sftp.close()
cmd = f"echo '{pw}' | sudo -S -p '' bash /tmp/_dy_neko_ui_remote.sh" if sudo else "bash /tmp/_dy_neko_ui_remote.sh"
_, o, e = c.exec_command(cmd, timeout=600)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
deploy("VPS dylive", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False)
deploy("phys dy", "107.173.30.245", 4014, "eric", "4669805", sudo=True)
print("done")