178 lines
5.7 KiB
Python
178 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Sync TM script seed dylive→local→dy; verify running nekos."""
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import sys
|
|
import tarfile
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PASS = "Xiao4669805"
|
|
TM = "dhdgffkkebhmkfjojejmpbldmpobfkfo"
|
|
SEED_REL = f"backend/neko/tampermonkey-seed/Default/Local Extension Settings/{TM}"
|
|
|
|
|
|
def connect(host: str):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(10):
|
|
try:
|
|
c.connect(
|
|
host,
|
|
22,
|
|
"root",
|
|
PASS,
|
|
timeout=50,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=180,
|
|
)
|
|
return c
|
|
except Exception as e:
|
|
print("retry", host, i, e, flush=True)
|
|
time.sleep(2)
|
|
raise SystemExit(f"ssh fail {host}")
|
|
|
|
|
|
def run(c, cmd: str, t: int = 300) -> str:
|
|
_i, o, e = c.exec_command(cmd, timeout=t)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-12000:] if len(out) > 12000 else out, flush=True)
|
|
return out
|
|
|
|
|
|
# 1) pull seed tarball from dylive
|
|
print("=== pull seed from dylive ===", flush=True)
|
|
dl = connect("107.173.30.245")
|
|
run(
|
|
dl,
|
|
r"""
|
|
set -e
|
|
SEED='/opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo'
|
|
test -d "$SEED"
|
|
grep -a -R -q 'YouTube Studio Auto Dismiss' "$SEED"
|
|
tar -C '/opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Local Extension Settings' \
|
|
-czf /tmp/tm_script_seed.tgz dhdgffkkebhmkfjojejmpbldmpobfkfo
|
|
ls -lh /tmp/tm_script_seed.tgz
|
|
# verify running
|
|
for name in douyinweb-neko-2 douyinweb-neko-19; do
|
|
docker exec "$name" sh -c 'python3 -c "
|
|
import os,re
|
|
p=\"/home/neko/.config/google-chrome/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo\"
|
|
b=b\"\"
|
|
for r,_,fs in os.walk(p):
|
|
for f in fs:
|
|
try: b+=open(os.path.join(r,f),\"rb\").read()
|
|
except: pass
|
|
print(\"'"$name"'\", \"markers\", len(re.findall(\"YouTube Studio Auto Dismiss\", b.decode(\"latin1\",\"ignore\"))), \"blob\", len(b))
|
|
"'
|
|
docker exec "$name" supervisorctl status google-chrome | head -1
|
|
done
|
|
""",
|
|
)
|
|
sftp = dl.open_sftp()
|
|
buf = io.BytesIO()
|
|
sftp.getfo("/tmp/tm_script_seed.tgz", buf)
|
|
sftp.close()
|
|
dl.close()
|
|
print(f"downloaded {buf.tell()} bytes", flush=True)
|
|
|
|
# 2) extract into local repo
|
|
local_dir = ROOT / "backend/neko/tampermonkey-seed/Default/Local Extension Settings"
|
|
local_dir.mkdir(parents=True, exist_ok=True)
|
|
buf.seek(0)
|
|
with tarfile.open(fileobj=buf, mode="r:gz") as tf:
|
|
tf.extractall(local_dir)
|
|
local_tm = local_dir / TM
|
|
assert local_tm.is_dir()
|
|
# quick marker check
|
|
blob = b""
|
|
for p in local_tm.rglob("*"):
|
|
if p.is_file():
|
|
blob += p.read_bytes()
|
|
assert b"YouTube Studio Auto Dismiss" in blob, "local seed missing script"
|
|
print(f"local seed ok markers bytes={len(blob)}", flush=True)
|
|
|
|
# 3) push to dy + repair empty profiles
|
|
print("=== sync to dy + repair profiles ===", flush=True)
|
|
dy = connect("108.174.50.68")
|
|
sftp = dy.open_sftp()
|
|
buf.seek(0)
|
|
with sftp.file("/tmp/tm_script_seed.tgz", "wb") as f:
|
|
f.write(buf.getvalue())
|
|
sftp.close()
|
|
run(
|
|
dy,
|
|
r"""
|
|
set -euo pipefail
|
|
TM=dhdgffkkebhmkfjojejmpbldmpobfkfo
|
|
SEED="/opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Local Extension Settings/$TM"
|
|
BASE=/opt/douyinWEB/backend/data/neko/profiles
|
|
mkdir -p "$(dirname "$SEED")"
|
|
ts=$(date +%s)
|
|
if [ -d "$SEED" ]; then mv "$SEED" "$SEED.bak-$ts"; fi
|
|
tar -C "/opt/douyinWEB/backend/neko/tampermonkey-seed/Default/Local Extension Settings" -xzf /tmp/tm_script_seed.tgz
|
|
grep -a -R -q 'YouTube Studio Auto Dismiss' "$SEED"
|
|
echo seed_ok
|
|
|
|
# pick GOOD = seed
|
|
GOOD="$SEED"
|
|
for d in "$BASE"/*; do
|
|
[ -d "$d" ] || continue
|
|
id=$(basename "$d")
|
|
p="$d/Default/Local Extension Settings/$TM"
|
|
markers=$(grep -a -R -c 'YouTube Studio Auto Dismiss' "$p" 2>/dev/null | awk -F: '{s+=$2} END{print s+0}')
|
|
bytes=$(du -sb "$p" 2>/dev/null | awk '{print $1}')
|
|
need=0
|
|
[ ! -d "$p" ] && need=1
|
|
[ "${markers:-0}" -lt 1 ] && need=1
|
|
[ "${bytes:-0}" -lt 8000 ] && need=1
|
|
if [ "$need" != 1 ]; then
|
|
echo OK id=$id markers=$markers
|
|
continue
|
|
fi
|
|
echo REPAIR id=$id
|
|
name=douyinweb-neko-$id
|
|
running=0
|
|
if docker inspect -f '{{.State.Running}}' "$name" 2>/dev/null | grep -q true; then
|
|
running=1
|
|
docker exec "$name" supervisorctl stop google-chrome 2>/dev/null || true
|
|
sleep 1
|
|
fi
|
|
mkdir -p "$(dirname "$p")"
|
|
if [ -d "$p" ]; then mv "$p" "$p.bak-empty-$ts"; fi
|
|
cp -a "$GOOD" "$p"
|
|
rm -f "$p/LOCK"
|
|
chown -R 1000:1000 "$p" 2>/dev/null || true
|
|
if [ "$running" = 1 ]; then
|
|
docker exec "$name" sh -c "rm -f /home/neko/.config/google-chrome/Singleton*; chown -R neko:neko '/home/neko/.config/google-chrome/Default/Local Extension Settings/$TM'; rm -f '/home/neko/.config/google-chrome/Default/Local Extension Settings/$TM/LOCK'; supervisorctl start google-chrome"
|
|
sleep 5
|
|
docker exec "$name" supervisorctl status google-chrome | head -1
|
|
fi
|
|
done
|
|
|
|
echo '=== dy running ==='
|
|
docker ps --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort -V
|
|
for name in $(docker ps --format '{{.Names}}' | grep '^douyinweb-neko-' | sort -V); do
|
|
docker exec "$name" python3 -c "
|
|
import os,re
|
|
p='/home/neko/.config/google-chrome/Default/Local Extension Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo'
|
|
b=b''
|
|
for r,_,fs in os.walk(p):
|
|
for f in fs:
|
|
try: b+=open(os.path.join(r,f),'rb').read()
|
|
except: pass
|
|
print('$name', 'markers', len(re.findall('YouTube Studio Auto Dismiss', b.decode('latin1','ignore'))), 'blob', len(b))
|
|
" 2>/dev/null || echo "$name check_fail"
|
|
done
|
|
echo DY_DONE
|
|
""",
|
|
)
|
|
dy.close()
|
|
print("ALL_DONE")
|