1#!/usr/bin/env python3
2import json
3from pathlib import Path
4import subprocess
5import sys
6
7
8data = json.load(sys.stdin)
9vm = Path(data["hostRoot"]) / "vm"
10source = Path(__file__).parent
11options = ["-i", str(vm / "ssh_key"), "-o", "BatchMode=yes", "-o", "IdentitiesOnly=yes",
12 "-o", "ForwardAgent=no", "-o", "StrictHostKeyChecking=accept-new",
13 "-o", "UserKnownHostsFile=" + str(vm / "known_hosts")]
14for file, destination in [(vm / "openclaw.json", "/tmp/openclaw.json"),
15 (source / "Dockerfile.guest", "/tmp/Dockerfile.guest"),
16 (source / "openclaw.service", "/tmp/openclaw.service"),
17 (source / "install.sh", "/tmp/openclaw-install"),
18 (source / "openclaw-install.service", "/tmp/openclaw-install.service"),
19 (source / "resolv.conf", "/tmp/resolv.conf")]:
20 subprocess.run(["scp", "-P", "18892", *options, str(file), "ocadmin@127.0.0.1:" + destination], check=True)
21subprocess.run(["ssh", "-p", "18892", *options, "ocadmin@127.0.0.1", "sudo bash -se"], check=True, input="""
22set -e
23install -m 755 /tmp/openclaw-install /usr/local/sbin/openclaw-install
24install /tmp/openclaw-install.service /etc/systemd/system/openclaw-install.service
25install /tmp/resolv.conf /opt/openclaw/resolv.conf
26install /tmp/Dockerfile.guest /opt/openclaw/Dockerfile
27install -o 1000 -g 1000 -m 600 /tmp/openclaw.json /opt/openclaw/state/openclaw.json
28install /tmp/openclaw.service /etc/systemd/system/openclaw.service
29systemctl daemon-reload
30systemctl enable openclaw-install
31systemctl restart openclaw-install
32rm /tmp/openclaw.json /tmp/Dockerfile.guest /tmp/openclaw.service /tmp/openclaw-install /tmp/openclaw-install.service /tmp/resolv.conf
33""", text=True)