Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy TM internal-error fix and repair running neko profiles."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
HOST = "108.174.50.68"
|
|
PASS = "Xiao4669805"
|
|
FILES = [
|
|
"backend/neko/browser-launch.sh",
|
|
"backend/neko/live-ops-extension/background.js",
|
|
"backend/neko/live-ops-extension/manifest.json",
|
|
]
|
|
|
|
|
|
def main() -> None:
|
|
launch = ROOT / FILES[0]
|
|
launch.write_bytes(launch.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n"))
|
|
|
|
client = paramiko.SSHClient()
|
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
client.connect(HOST, 22, "root", PASS, timeout=60, allow_agent=False, look_for_keys=False)
|
|
sftp = client.open_sftp()
|
|
for rel in FILES:
|
|
sftp.put(str(ROOT / rel), f"/opt/douyinWEB/{rel.replace(chr(92), '/')}")
|
|
print("uploaded", rel)
|
|
sftp.close()
|
|
|
|
cmd = r"""
|
|
set -e
|
|
chmod +x /opt/douyinWEB/backend/neko/browser-launch.sh
|
|
sed -i 's/\r$//' /opt/douyinWEB/backend/neko/browser-launch.sh
|
|
for id in 1 2 3 4 5; do
|
|
name=douyinweb-neko-$id
|
|
if docker ps --format '{{.Names}}' | grep -qx "$name"; then
|
|
echo "=== repair $name ==="
|
|
docker exec "$name" sh -c 'rm -f "/home/neko/.config/chromium/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo/LOCK" 2>/dev/null || true'
|
|
docker exec "$name" sh -c 'test -d "/home/neko/.config/chromium/Default/Managed Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo" && echo managed_ok || echo managed_missing'
|
|
docker exec "$name" supervisorctl restart google-chrome 2>/dev/null || docker exec "$name" supervisorctl restart chromium 2>/dev/null || true
|
|
sleep 8
|
|
docker exec "$name" python3 - <<'PY'
|
|
import json
|
|
import urllib.request
|
|
|
|
junk = ("tampermonkey.net/changelog", "tampermonkey.net/installed")
|
|
try:
|
|
with urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=3) as resp:
|
|
tabs = json.loads(resp.read().decode("utf-8", "replace"))
|
|
except Exception as exc:
|
|
print("cdp_skip", exc)
|
|
raise SystemExit(0)
|
|
closed = 0
|
|
for tab in tabs:
|
|
url = tab.get("url") or ""
|
|
if any(x in url for x in junk):
|
|
tid = tab.get("id")
|
|
if tid:
|
|
try:
|
|
urllib.request.urlopen(f"http://127.0.0.1:9222/json/close/{tid}", timeout=3)
|
|
closed += 1
|
|
except Exception:
|
|
pass
|
|
print("closed_junk_tabs", closed, "total_tabs", len(tabs))
|
|
PY
|
|
fi
|
|
done
|
|
"""
|
|
_i, o, e = client.exec_command(cmd, timeout=240)
|
|
print(o.read().decode("utf-8", "replace"))
|
|
err = e.read().decode("utf-8", "replace")
|
|
if err.strip():
|
|
print("STDERR", err[:2000])
|
|
client.close()
|
|
print("done")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|