oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3import (
4 "fmt"
5 "os/exec"
6 "path/filepath"
7 "sort"
8 "strconv"
9 "strings"
10
11 "amadan.net/oficina/equipo/internal/runner"
12 runnersetup "amadan.net/oficina/equipo/internal/runner/setup"
13)
14
15func installConfig(root, origin, instance, version string, getenv func(string) string) (runner.Config, error) {
16 values := map[string]string{"EQUIPO_TOOL_PROXY_PATH": filepath.Join(root, "releases", version, "equipo-tool-proxy"), "EQUIPO_ORIGIN": origin, "EQUIPO_INSTANCE_ID": instance, "EQUIPO_RUNNER_STATE_DIR": filepath.Join(root, "state"), "EQUIPO_ACCOUNT_BINDINGS_PATH": filepath.Join(root, "accounts.json"), "EQUIPO_AMADAN_CREDENTIAL_PATH": filepath.Join(root, "amadan.json"), "EQUIPO_WORKSPACE_ROOT": filepath.Join(root, "work"), "EQUIPO_SCRATCH_ROOT": filepath.Join(root, "scratch")}
17 for variable, binary := range map[string]string{"EQUIPO_BWRAP_PATH": "bwrap", "EQUIPO_CLAUDE_PATH": "claude", "EQUIPO_CODEX_PATH": "codex", "EQUIPO_CODEX_CODE_MODE_HOST_PATH": "codex-code-mode-host", "EQUIPO_GO_BINARY": "go", "EQUIPO_GIT_PATH": "git", "EQUIPO_AMADAN_PATH": "amadan"} {
18 path := getenv(variable)
19 if path == "" {
20 var e error
21 path, e = exec.LookPath(binary)
22 if e != nil {
23 return runner.Config{}, e
24 }
25 }
26 values[variable] = path
27 }
28 values["EQUIPO_GO_ROOT"] = getenv("EQUIPO_GO_ROOT")
29 if values["EQUIPO_GO_ROOT"] == "" {
30 cmd := exec.Command(values["EQUIPO_GO_BINARY"], "env", "GOROOT")
31 // Its own working directory: go reads the one it is started in.
32 cmd.Dir = root
33 b, e := cmd.Output()
34 if e != nil {
35 return runner.Config{}, e
36 }
37 values["EQUIPO_GO_ROOT"] = strings.TrimSpace(string(b))
38 }
39 values["EQUIPO_GO_MODULE_CACHE"] = getenv("EQUIPO_GO_MODULE_CACHE")
40 // The pinned Pi (equipo-runner install-pi), if this runner has one.
41 if root := getenv("EQUIPO_PI_ROOT"); root != "" {
42 values["EQUIPO_PI_ROOT"] = root
43 }
44 // The pinned OpenCode (equipo-runner install-opencode), if it has one.
45 if root := getenv("EQUIPO_OPENCODE_ROOT"); root != "" {
46 values["EQUIPO_OPENCODE_ROOT"] = root
47 }
48 cfg, e := runner.LoadConfig(func(k string) string { return values[k] })
49 if e != nil {
50 return cfg, e
51 }
52 keys := make([]string, 0, len(values))
53 for k := range values {
54 keys = append(keys, k)
55 }
56 sort.Strings(keys)
57 var content strings.Builder
58 for _, k := range keys {
59 fmt.Fprintf(&content, "%s=%s\n", k, strconv.Quote(values[k]))
60 }
61 return cfg, runnersetup.SaveServiceEnvironment(root, []byte(content.String()))
62}
63