sh2/d2ypp2/tools/apply_host04_like_05.py
2026-06-14 10:41:48 -05:00

59 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Upload and run remote_patch_host04.py on 10.88.0.4, restart shellcrash, verify."""
from __future__ import annotations
import json
from pathlib import Path
import paramiko
HOST, USER, PASS = "10.88.0.4", "eric", "4669805"
LOCAL = Path(__file__).resolve().parent / "remote_patch_host04.py"
REMOTE = "/tmp/remote_patch_host04.py"
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 120) -> str:
_, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
return (o.read() + e.read()).decode("utf-8", "replace")
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=20)
sftp = c.open_sftp()
sftp.put(str(LOCAL), REMOTE)
sftp.close()
print("=== apply patch ===")
print(run(c, f"python3 {REMOTE}"))
print("\n=== restart shellcrash ===")
print(run(c, f"echo '{PASS}' | sudo -S -p '' systemctl restart shellcrash && sleep 2 && systemctl is-active shellcrash"))
verify = (
"curl -sS -m 8 -x socks5://127.0.0.1:7890 https://www.gstatic.com/generate_204 "
"-w 'gstatic=%{http_code} t=%{time_total}\\n' -o /dev/null; "
"curl -sS -m 10 -x socks5://127.0.0.1:7890 https://a.rtmps.youtube.com/ "
"-w 'yt_rtmps_t=%{time_total}\\n' -o /dev/null 2>&1 | tail -1; "
"python3 -c \"import urllib.request,json;print(json.load(urllib.request.urlopen('http://127.0.0.1:9999/proxies',timeout=5))['proxies']['\\U0001f680 \\u8282\\u70b9\\u9009\\u62e9']['now'])\""
)
print("\n=== verify proxy ===")
print(run(c, verify))
print("\n=== config snapshot ===")
print(run(c, "grep -H 'video_mode\\|bitrate\\|fast_audio' /home/eric/d2ypp2-src/config/youtube.youtube2__*.ini | head -10"))
print(run(c, "cat /home/eric/d2ypp2-src/config/hardware.env"))
print(run(c, "grep SHELLCRASH /home/eric/d2ypp2-src/config/system-stack.env"))
print("\n=== active ffmpeg (restart lanes from UI if needed) ===")
print(run(c, "pgrep -af 'ffmpeg.*rtmps' || echo none"))
c.close()
return 0
if __name__ == "__main__":
raise SystemExit(main())