Skip to content

Commit 01cc475

Browse files
fix(opencode): fallback to sh for curl upgrade (anomalyco#30499)
Co-authored-by: Shoubhit Dash <[email protected]>
1 parent a444410 commit 01cc475

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎packages/opencode/src/installation/index.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,20 @@ export const layer: Layer.Layer<Service, never, HttpClient.HttpClient | AppProce
149149
return `Upgrade failed for ${method}.`
150150
}
151151

152+
const upgradeScriptShell = Effect.fnUntraced(function* () {
153+
const bashVersion = yield* text(["bash", "--version"])
154+
if (bashVersion) return "bash"
155+
return "sh"
156+
})
157+
152158
const upgradeCurl = Effect.fnUntraced(
153159
function* (target: string) {
154160
const response = yield* httpOk.execute(HttpClientRequest.get("https://opencode.ai/install"))
155161
const body = yield* response.text
156162
const bodyBytes = new TextEncoder().encode(body)
163+
const shell = yield* upgradeScriptShell()
157164
const result = yield* appProcess.run(
158-
ChildProcess.make("bash", [], {
165+
ChildProcess.make(shell, [], {
159166
stdin: Stream.make(bodyBytes),
160167
env: { VERSION: target },
161168
extendEnv: true,

‎packages/opencode/test/installation/installation.test.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ describe("installation", () => {
194194
testEffect(
195195
testLayer(
196196
() => new Response("install script with token=secret", { status: 200 }),
197-
(cmd) => {
198-
if (cmd === "bash") return { code: 1, stderr: "script output with token=secret" }
197+
(cmd, args) => {
198+
if (cmd === "bash" && args[0] === "--version") return "GNU bash"
199+
if (cmd === "bash" || cmd === "sh") return { code: 1, stderr: "script output with token=secret" }
199200
return ""
200201
},
201202
),
@@ -209,5 +210,21 @@ describe("installation", () => {
209210
expect(error.stderr).not.toContain("script output")
210211
}),
211212
)
213+
214+
testEffect(
215+
testLayer(
216+
() => new Response("install script", { status: 200 }),
217+
(cmd, args) => {
218+
if (cmd === "bash" && args[0] === "--version") return { code: 1, stderr: "missing" }
219+
if (cmd === "bash") return { code: 1, stderr: "should not execute installer with bash" }
220+
if (cmd === "sh") return "ok"
221+
return ""
222+
},
223+
),
224+
).effect("falls back to sh when bash is unavailable during curl upgrade", () =>
225+
Effect.gen(function* () {
226+
yield* Installation.use.upgrade("curl", "9.9.9")
227+
}),
228+
)
212229
})
213230
})

0 commit comments

Comments
 (0)