package main import ( "fmt" "os/exec" "path/filepath" "sort" "strconv" "strings" "amadan.net/oficina/equipo/internal/runner" runnersetup "amadan.net/oficina/equipo/internal/runner/setup" ) func installConfig(root, origin, instance, version string, getenv func(string) string) (runner.Config, error) { 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")} 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"} { path := getenv(variable) if path == "" { var e error path, e = exec.LookPath(binary) if e != nil { return runner.Config{}, e } } values[variable] = path } values["EQUIPO_GO_ROOT"] = getenv("EQUIPO_GO_ROOT") if values["EQUIPO_GO_ROOT"] == "" { cmd := exec.Command(values["EQUIPO_GO_BINARY"], "env", "GOROOT") // Its own working directory: go reads the one it is started in. cmd.Dir = root b, e := cmd.Output() if e != nil { return runner.Config{}, e } values["EQUIPO_GO_ROOT"] = strings.TrimSpace(string(b)) } values["EQUIPO_GO_MODULE_CACHE"] = getenv("EQUIPO_GO_MODULE_CACHE") // The pinned Pi (equipo-runner install-pi), if this runner has one. if root := getenv("EQUIPO_PI_ROOT"); root != "" { values["EQUIPO_PI_ROOT"] = root } // The pinned OpenCode (equipo-runner install-opencode), if it has one. if root := getenv("EQUIPO_OPENCODE_ROOT"); root != "" { values["EQUIPO_OPENCODE_ROOT"] = root } cfg, e := runner.LoadConfig(func(k string) string { return values[k] }) if e != nil { return cfg, e } keys := make([]string, 0, len(values)) for k := range values { keys = append(keys, k) } sort.Strings(keys) var content strings.Builder for _, k := range keys { fmt.Fprintf(&content, "%s=%s\n", k, strconv.Quote(values[k])) } return cfg, runnersetup.SaveServiceEnvironment(root, []byte(content.String())) }