50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Sync browser-launch.sh to physical host (bind-mounted into assign Nekos)."""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
LOCAL = ROOT / "backend/neko/browser-launch.sh"
|
|
REMOTE = "/opt/douyinWEB/backend/neko/browser-launch.sh"
|
|
|
|
|
|
def main() -> None:
|
|
data = LOCAL.read_bytes()
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
"4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/browser-launch.sh.stoptrap", "w") as f:
|
|
f.write(data)
|
|
sftp.close()
|
|
_i, o, e = c.exec_command(
|
|
"echo '4669805' | sudo -S -p '' bash -lc "
|
|
f"'cp -a {REMOTE} {REMOTE}.bak.stoptrap_20260905 && "
|
|
f"install -m 755 /tmp/browser-launch.sh.stoptrap {REMOTE} && "
|
|
f"sha256sum {REMOTE} && grep -n on_supervisor_stop {REMOTE} | head'",
|
|
timeout=30,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
print("local_sha", hashlib.sha256(data).hexdigest()[:12])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|