# -*- coding: utf-8 -*-
r'''给管理页补 favicon(第二版 —— 这次锚点找对了)。
管理页的 HTML 不在 _admin_page 开头,而是在它内部,
标题那行是
ykxmz 中转服务器,
所以插在它的 viewport 那行之后。
(上一版脚本的文档字符串里写了一个三引号,把自己的 docstring 提前闭合了,
这里改用单引号三连,避免同样的问题。)
'''
from __future__ import annotations
import ast
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
RELAY = ROOT / "relay" / "relay.py"
ANCHOR = '\nykxmz 中转服务器'
NEW = ('\n'
'\n'
'ykxmz 中转服务器')
def main() -> int:
text = RELAY.read_text(encoding="utf-8")
if '\nykxmz 中转服务器' in text:
print(" 管理页已经有 favicon")
elif ANCHOR in text:
text = text.replace(ANCHOR, NEW, 1)
RELAY.write_text(text, encoding="utf-8", newline="\n")
print(" 管理页补上 favicon link")
ast.parse(text)
print(" 语法 OK")
else:
print(" [失败] 锚点还是没找到,实际内容:")
idx = text.find("ykxmz 中转服务器")
if idx > 0:
print(text[max(0, idx - 200):idx + 40])
return 1
print()
print(" 部署…")
upload(str(RELAY), "/root/lanremote-relay/relay.py", 0o755)
upload(str(ROOT / "relay" / "favicon.ico"),
"/root/lanremote-relay/favicon.ico", 0o644)
run("systemctl restart lanremote-relay", timeout=90)
print(" 已重启")
print()
_c, out, _e = run("bash /root/check_web.sh 2>&1", timeout=180)
print(out)
return 0
if __name__ == "__main__":
sys.exit(main())