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>
96 lines
3.5 KiB
Python
96 lines
3.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Force-fix neko-3 Tampermonkey: deploy script, repair profile, restart."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
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"
|
|
|
|
LOCAL = ROOT / "backend/neko/browser-launch.sh"
|
|
LOCAL.write_bytes(LOCAL.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n"))
|
|
|
|
|
|
def main() -> None:
|
|
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()
|
|
sftp.put(str(LOCAL), "/opt/douyinWEB/backend/neko/browser-launch.sh")
|
|
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
|
|
echo "=== host script check ==="
|
|
grep -n "Managed Extension Settings" /opt/douyinWEB/backend/neko/browser-launch.sh || true
|
|
echo "=== container mount check ==="
|
|
docker exec douyinweb-neko-3 grep -n "Managed Extension Settings" /etc/neko/browser-launch.sh || true
|
|
|
|
name=douyinweb-neko-3
|
|
docker exec "$name" supervisorctl stop google-chrome
|
|
|
|
docker exec "$name" sh -c '
|
|
ext=dhdgffkkebhmkfjojejmpbldmpobfkfo
|
|
for base in /home/neko/.config/google-chrome/Default /home/neko/.config/chromium/Default; do
|
|
[ -d "$base" ] || continue
|
|
rm -f "$base/Local Extension Settings/$ext/LOCK" 2>/dev/null || true
|
|
rm -f "$base/Managed Extension Settings/$ext/LOCK" 2>/dev/null || true
|
|
chown -R neko:neko "$base/Local Extension Settings" "$base/Managed Extension Settings" 2>/dev/null || true
|
|
chmod -R u+rwX "$base/Local Extension Settings" "$base/Managed Extension Settings" 2>/dev/null || true
|
|
echo "fixed_perms $base"
|
|
done
|
|
'
|
|
|
|
docker exec "$name" supervisorctl start google-chrome
|
|
sleep 12
|
|
|
|
docker exec "$name" python3 - <<'PY'
|
|
import json
|
|
import urllib.request
|
|
|
|
junk = ("tampermonkey.net/changelog", "tampermonkey.net/installed")
|
|
with urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=8) as resp:
|
|
tabs = json.loads(resp.read().decode())
|
|
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:
|
|
urllib.request.urlopen(f"http://127.0.0.1:9222/json/close/{tid}", timeout=3)
|
|
closed += 1
|
|
print("closed_junk", closed)
|
|
|
|
# try open TM dashboard
|
|
body = json.dumps({"url": "chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/dashboard.html"}).encode()
|
|
req = urllib.request.Request("http://127.0.0.1:9222/json/new", data=body, headers={"Content-Type": "application/json"})
|
|
try:
|
|
with urllib.request.urlopen(req, timeout=5) as resp:
|
|
tab = json.loads(resp.read().decode())
|
|
print("tm_dashboard", (tab.get("url") or "")[:120])
|
|
except Exception as exc:
|
|
print("tm_dashboard_fail", exc)
|
|
PY
|
|
|
|
docker exec "$name" sh -c 'grep -R -a "YouTube Studio Auto Dismiss" "/home/neko/.config/google-chrome/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo" 2>/dev/null | wc -c'
|
|
docker exec "$name" grep -n "rm -rf.*Managed Extension Settings" /etc/neko/browser-launch.sh && echo BAD_STILL_PRESENT || echo OK_NO_RM_MANAGED
|
|
"""
|
|
_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("ERR", err[:2000])
|
|
client.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|