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

60 lines
2.0 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy remaining UI busy-unlock pages."""
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/app/yt-long/page.tsx", "/tmp/_dy_yt_long.tsx"),
("frontend/src/app/x/ClipsPanel.tsx", "/tmp/_dy_x_clips.tsx"),
("frontend/src/app/youtube/page.tsx", "/tmp/_dy_youtube_page.tsx"),
]
REMOTE = r'''#!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
pairs=[
('/tmp/_dy_yt_long.tsx','/opt/douyinWEB/frontend/src/app/yt-long/page.tsx'),
('/tmp/_dy_x_clips.tsx','/opt/douyinWEB/frontend/src/app/x/ClipsPanel.tsx'),
('/tmp/_dy_youtube_page.tsx','/opt/douyinWEB/frontend/src/app/youtube/page.tsx'),
]
for s,d in pairs:
Path(d).write_bytes(Path(s).read_bytes().replace(b'\r\n',b'\n').replace(b'\r',b'\n'))
print('ok', d)
PY
cd /opt/douyinWEB/frontend && npm run build 2>&1 | tail -22
systemctl restart douyinweb-web.service
sleep 3
systemctl is-active douyinweb-web.service
'''
def deploy(label, host, port, user, pw, sudo=False):
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 local, remote in FILES:
data = (ROOT / local).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/_dy_ui_busy2.sh", "w") as f:
f.write(REMOTE.replace("\r\n", "\n"))
sftp.close()
cmd = f"echo '{pw}' | sudo -S -p '' bash /tmp/_dy_ui_busy2.sh" if sudo else "bash /tmp/_dy_ui_busy2.sh"
_, o, e = c.exec_command(cmd, timeout=600)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
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")