# -*- coding: utf-8 -*- """Deploy exact sh2 Neko stack; remove baked dismiss; wait for TM jsonImport.""" from __future__ import annotations import sys import tarfile import tempfile from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB") # normalize LF on shell launch = ROOT / "backend/neko/browser-launch.sh" launch.write_bytes(launch.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")) INCLUDE = [ "backend/neko/browser-launch.sh", "backend/neko/google-chrome.conf", "backend/neko/chromium.conf", "backend/neko/policies", "backend/neko/provisioning", "backend/neko/live-ops-extension", "backend/neko/tampermonkey-seed", "backend/neko/no-managed-policies", "backend/neko/render_tampermonkey_provisioning.py", "backend/app/youtube_neko.py", "backend/app/config.py", ] fd, tmp = tempfile.mkstemp(suffix=".tgz") import os os.close(fd) tgz = Path(tmp) with tarfile.open(tgz, "w:gz") as tar: for rel in INCLUDE: tar.add(ROOT / rel, arcname=rel) print("pack", rel) REMOTE = r"""#!/bin/bash set -e cd /opt/douyinWEB tar xzf /tmp/neko-sh2-exact.tgz # remove invented file if any rm -f /opt/douyinWEB/backend/neko/live-ops-extension/auto-dismiss.js chmod +x /opt/douyinWEB/backend/neko/browser-launch.sh sed -i 's/\r$//' /opt/douyinWEB/backend/neko/browser-launch.sh # keep sh2 default managed policies=1 mkdir -p /etc/systemd/system/douyinweb-api.service.d cat >/etc/systemd/system/douyinweb-api.service.d/neko-sh2.conf </dev/null | head -1; then echo FOUND_SCRIPT fi done done # no auto-dismiss in load-extension for f in /proc/[0-9]*/cmdline; do tr "\0" " " < "$f"; echo; done 2>/dev/null | grep load-extension | head -2 test ! -f /etc/neko/live-ops-extension/auto-dismiss.js && echo no_baked_dismiss_ok ' || true done if docker exec douyinweb-neko-2 sh -c 'grep -R -a -l "YouTube Studio Auto Dismiss" /home/neko/.config/google-chrome/Default/Local\ Extension\ Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo /home/neko/.config/google-chrome/Default/Managed\ Extension\ Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo 2>/dev/null | head -1' | grep -q .; then echo 'SCRIPT_IMPORTED_OK' break fi done # final state cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY' from app import youtube_neko, yt_assign_db print(youtube_neko.sync_for_groups(yt_assign_db.list_groups(False))) for i in youtube_neko.list_instances(2): print(i.get('id'), i.get('status'), i.get('running'), i.get('studio_url')) PY """ c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("108.174.50.68", 22, "root", "Xiao4669805", timeout=60, allow_agent=False, look_for_keys=False) s = c.open_sftp() s.put(str(tgz), "/tmp/neko-sh2-exact.tgz") print("uploaded", tgz.stat().st_size) with s.file("/tmp/neko_sh2_exact.sh", "w") as f: f.write(REMOTE) s.close() _i, o, e = c.exec_command("bash /tmp/neko_sh2_exact.sh", timeout=600) o.channel.settimeout(600) print(o.read().decode("utf-8", "replace")) err = e.read().decode("utf-8", "replace") if err.strip(): print("STDERR", err[:2500]) c.close() tgz.unlink(missing_ok=True)