#!/usr/bin/env python3 # -*- coding: utf-8 -*- r'''把本地 relay 代码同步到设备并重启,然后验证。 为什么单独一个脚本: 之前用内联 python -c 配 PowerShell 的 @"..."@, 里面只要出现 $(...) / 反斜杠 / 嵌套引号就会被 PowerShell 吃掉 (这个坑今天踩了不下 10 次)。写成文件最稳。 ''' from __future__ import annotations import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") sys.path.insert(0, str(ROOT / "_build")) from devssh import run, upload # noqa: E402 FILES = [ ("relay/relay.py", "/root/lanremote-relay/relay.py", 0o755), ("relay/admin.py", "/root/lanremote-relay/admin.py", 0o644), ("relay/landing.py", "/root/lanremote-relay/landing.py", 0o644), ("relay/showcase.py", "/root/lanremote-relay/showcase.py", 0o644), ("relay/watchdog.sh", "/root/lanremote-relay/watchdog.sh", 0o755), ("relay/net-tune.sh", "/root/lanremote-relay/net-tune.sh", 0o755), ("relay/speed-up-boot.sh", "/root/lanremote-relay/speed-up-boot.sh", 0o755), ("relay/tunnel-run.sh", "/root/lanremote-relay/tunnel-run.sh", 0o755), ] def main() -> int: print(" 同步代码:") for local, remote, mode in FILES: src = ROOT / local if not src.is_file(): print(" [跳过] %s 不存在" % local) continue upload(str(src), remote, mode) print(" ✓ %-26s %d 字节" % (src.name, src.stat().st_size)) print() print(" 重启中转:") _c, out, _e = run("systemctl restart lanremote-relay; sleep 6; " "systemctl is-active lanremote-relay", timeout=120) print(" " + (out or "").strip().splitlines()[-1]) print() print(" 验证:") checks = [ ("中转版本", "curl -s --max-time 8 http://127.0.0.1:8080/v1/health " "| head -c 200"), ("管理页响应头", "curl -sI --max-time 10 " "http://127.0.0.1:8080/zhongzhuanzhan " "| grep -i '^content-type'"), ("官网响应头", "curl -sI --max-time 10 http://127.0.0.1:8080/ " "| grep -i '^content-type'"), ("官网大小", "curl -s --max-time 10 http://127.0.0.1:8080/ | wc -c"), ("下载接口", "curl -s --max-time 10 " "http://127.0.0.1:8080/v1/downloads"), ] for label, cmd in checks: _c, out, _e = run(cmd, timeout=60) text = (out or "").strip() if len(text) > 220: text = text[:220] + "…" print(" %-14s %s" % (label, text)) print() print(" 下载链接实测(走公网):") links = [ "/download/ykxmz-setup-1.8.0.exe", "/download/ykxmz-server-1.8.0.zip", "/download/ykxmz-watch-1.8.0.apk", ] for link in links: _c, out, _e = run( "curl -s -o /dev/null -w '%%{http_code} %%{size_download}' " "--max-time 60 -r 0-1023 https://relay.xxmxxs.top" + link, timeout=120) print(" %-34s %s" % (link, (out or "").strip())) print() print(" 公网首页 / 管理页:") for path, label in (("/", "官网"), ("/zhongzhuanzhan", "管理页")): _c, out, _e = run( "curl -s -o /dev/null -w '%%{http_code}' --max-time 20 " "-H 'User-Agent: LanRemote/1.8.0' https://relay.xxmxxs.top" + path, timeout=120) print(" %-8s HTTP %s" % (label, (out or "").strip())) print() print(" 中转日志最后几行:") _c, out, _e = run("tail -6 /root/lanremote-relay/relay.log", timeout=60) for line in (out or "").strip().splitlines(): print(" " + line) return 0 if __name__ == "__main__": sys.exit(main())