# -*- coding: utf-8 -*- r'''把设备上改好的 watchdog.sh 同步回仓库,重新打服务端 zip 并上传。 为什么要同步回来: watchdog 的「建齐过就立刻重启」逻辑是在设备上直接改的, 本地仓库还是旧版。不同步回来,打出来的 zip 就是旧的, 用户装到新设备上就没有这个改进。 ''' from __future__ import annotations import subprocess 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 WD_LOCAL = ROOT / "relay" / "watchdog.sh" def main() -> int: # ---- 1. 从设备拉回 watchdog ---- print(" 1. 从设备拉回 watchdog.sh") _c, out, _e = run("cat /root/lanremote-relay/watchdog.sh", timeout=120) if not out or "MIN_RESTART_GAP" not in out: print(" [失败] 拉不到") return 1 old = WD_LOCAL.read_text(encoding="utf-8") if WD_LOCAL.is_file() else "" WD_LOCAL.write_text(out, encoding="utf-8", newline="\n") print(" %d 行 -> relay/watchdog.sh(原来 %d 行)" % (out.count("\n"), old.count("\n"))) # 关键内容自检 for token in ("GRACE", "BUILT", "built=", "立即重启"): print(" %s %s" % ("有" if token in out else "**缺**", token)) # ---- 2. 重新打服务端 zip ---- print() print(" 2. 重打服务端 zip") r = subprocess.run([sys.executable, "_build/package_remote.py"], cwd=str(ROOT), capture_output=True, text=True, encoding="utf-8", errors="replace") for line in (r.stdout or "").strip().splitlines()[-8:]: print(" " + line) # ---- 3. 重新上传 ---- print() print(" 3. 重新上传服务端 zip") src = ROOT / "dist" / "ykxmz-server-1.8.0.zip" if not src.is_file(): print(" [失败] 没打出 zip") return 1 upload(str(src), "/root/lanremote-relay/downloads/ykxmz-server-1.8.0.zip", 0o644) print(" ✓ ykxmz-server-1.8.0.zip %.2f MB" % (src.stat().st_size / 1024 / 1024)) # ---- 4. 确认 ---- print() print(" 4. 服务端 zip 内容自检") import zipfile with zipfile.ZipFile(src) as archive: names = archive.namelist() wd = None for name in names: if name.endswith("watchdog.sh"): wd = archive.read(name).decode("utf-8") break print(" 条目 %d 个" % len(names)) if wd: for token in ("GRACE=150", "BUILT", "built="): print(" %s %s" % ("有" if token in wd else "**缺**", token)) print() print(" 5. 设备上下载目录") _c, out, _e = run("ls -la /root/lanremote-relay/downloads/", timeout=60) for line in (out or "").strip().splitlines(): print(" " + line) return 0 if __name__ == "__main__": sys.exit(main())