#!/usr/bin/env python3 """Point host 10.88.0.3 Neko at the legacy profile directory and restart.""" import paramiko import sys HOST, PW = "10.88.0.3", "Xiao4669805" BASE = "/home/eric/d2ypp2-src" OLD = "/home/eric/live-d2ypp-neko-runtime/profiles/google-chrome-profile-v2" ENV_FILE = f"{BASE}/config/system-stack.env" def run(client: paramiko.SSHClient, cmd: str, timeout: int = 120) -> str: _, stdout, stderr = client.exec_command(cmd, timeout=timeout) out = (stdout.read() + stderr.read()).decode("utf-8", "replace") sys.stdout.buffer.write(out.encode("utf-8", "replace")) sys.stdout.buffer.write(b"\n") sys.stdout.flush() return out def sudo(client: paramiko.SSHClient, cmd: str, timeout: int = 120) -> str: return run(client, f"echo {PW!r} | sudo -S {cmd}", timeout=timeout) def main() -> None: client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(HOST, username="eric", password=PW, timeout=15) print("=== patch system-stack.env ===") sudo( client, f"sed -i 's|^NEKO_PROFILE_HOST_DIR=.*|NEKO_PROFILE_HOST_DIR={OLD}|' {ENV_FILE}", ) print(run(client, f"grep NEKO_PROFILE {ENV_FILE}")) print("=== restart neko ===") run( client, f"cd {BASE} && . scripts/linux/lib/common.sh && load_env && " "bash scripts/linux/service_ctl.sh neko restart 2>&1 | tail -25", timeout=180, ) print("=== verify ===") run( client, "docker inspect live-neko-1 live-neko-2 " "--format '{{.Name}} profile={{range .Mounts}}" "{{if eq .Destination \"/home/neko/.config/google-chrome\"}}{{.Source}}{{end}}" "{{end}}'", ) run( client, f"cd {BASE} && . scripts/linux/lib/common.sh && load_env && " "bash scripts/linux/service_ctl.sh neko status 2>&1 | head -6", ) client.close() if __name__ == "__main__": main()