| 1 | #!/usr/bin/env python3 |
| 2 | import json |
| 3 | from pathlib import Path |
| 4 | import subprocess |
| 5 | import sys |
| 6 | |
| 7 | |
| 8 | data = json.load(sys.stdin) |
| 9 | vm = Path(data["hostRoot"]) / "vm" |
| 10 | source = Path(__file__).parent |
| 11 | options = ["-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")] |
| 14 | for 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) |
| 21 | subprocess.run(["ssh", "-p", "18892", *options, "ocadmin@127.0.0.1", "sudo bash -se"], check=True, input=""" |
| 22 | set -e |
| 23 | install -m 755 /tmp/openclaw-install /usr/local/sbin/openclaw-install |
| 24 | install /tmp/openclaw-install.service /etc/systemd/system/openclaw-install.service |
| 25 | install /tmp/resolv.conf /opt/openclaw/resolv.conf |
| 26 | install /tmp/Dockerfile.guest /opt/openclaw/Dockerfile |
| 27 | install -o 1000 -g 1000 -m 600 /tmp/openclaw.json /opt/openclaw/state/openclaw.json |
| 28 | install /tmp/openclaw.service /etc/systemd/system/openclaw.service |
| 29 | systemctl daemon-reload |
| 30 | systemctl enable openclaw-install |
| 31 | systemctl restart openclaw-install |
| 32 | rm /tmp/openclaw.json /tmp/Dockerfile.guest /tmp/openclaw.service /tmp/openclaw-install /tmp/openclaw-install.service /tmp/resolv.conf |
| 33 | """, text=True) |