11package provisionersdk
22
3- import "fmt"
3+ import (
4+ "fmt"
5+ "strings"
6+ )
47
58var (
6- // A mapping of operating-system ($GOOS) to architecture ($GOARCH)
7- // to agent install and run script. ${DOWNLOAD_URL} is replaced
8- // with strings.ReplaceAll() when being consumed.
9- agentScripts = map [string ]map [string ]string {
10- // On Windows, VS Code Remote requires a parent process of the
11- // executing shell to be named "sshd", otherwise it fails. See:
12- // https://github.com/microsoft/vscode-remote-release/issues/5699
13- "windows" : {
14- "amd64" : `$ProgressPreference = "SilentlyContinue"
15- Invoke-WebRequest -Uri ${ACCESS_URL}bin/coder-windows-amd64.exe -OutFile $env:TEMP\sshd.exe
9+ // On Windows, VS Code Remote requires a parent process of the
10+ // executing shell to be named "sshd", otherwise it fails. See:
11+ // https://github.com/microsoft/vscode-remote-release/issues/5699
12+ windowsScript = `$ProgressPreference = "SilentlyContinue"
13+ Invoke-WebRequest -Uri ${ACCESS_URL}bin/coder-windows-${ARCH}.exe -OutFile $env:TEMP\sshd.exe
1614Set-MpPreference -DisableRealtimeMonitoring $true -ExclusionPath $env:TEMP\sshd.exe
1715$env:CODER_AGENT_AUTH = "${AUTH_TYPE}"
1816$env:CODER_AGENT_URL = "${ACCESS_URL}"
19- Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru` ,
20- },
21- "linux" : {
22- "amd64" : `#!/usr/bin/env sh
17+ Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru`
18+
19+ linuxScript = `#!/usr/bin/env sh
2320set -eu pipefail
2421export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
25- curl -fsSL ${ACCESS_URL}bin/coder-linux-amd64 -o $BINARY_LOCATION
22+ curl -fsSL ${ACCESS_URL}bin/coder-linux-${ARCH} -o $BINARY_LOCATION
2623chmod +x $BINARY_LOCATION
2724export CODER_AGENT_AUTH="${AUTH_TYPE}"
2825export CODER_AGENT_URL="${ACCESS_URL}"
29- exec $BINARY_LOCATION agent` ,
30- },
31- "darwin" : {
32- "amd64" : `#!/usr/bin/env sh
26+ exec $BINARY_LOCATION agent`
27+
28+ darwinScript = `#!/usr/bin/env sh
3329set -eu pipefail
3430export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
35- curl -fsSL ${ACCESS_URL}bin/coder-darwin-amd64 -o $BINARY_LOCATION
31+ curl -fsSL ${ACCESS_URL}bin/coder-darwin-${ARCH} -o $BINARY_LOCATION
3632chmod +x $BINARY_LOCATION
3733export CODER_AGENT_AUTH="${AUTH_TYPE}"
3834export CODER_AGENT_URL="${ACCESS_URL}"
39- exec $BINARY_LOCATION agent` ,
35+ exec $BINARY_LOCATION agent`
36+
37+ // A mapping of operating-system ($GOOS) to architecture ($GOARCH)
38+ // to agent install and run script. ${DOWNLOAD_URL} is replaced
39+ // with strings.ReplaceAll() when being consumed. ${ARCH} is replaced
40+ // with the architecture when being provided.
41+ agentScripts = map [string ]map [string ]string {
42+ "windows" : {
43+ "amd64" : windowsScript ,
44+ "arm64" : windowsScript ,
45+ },
46+ "linux" : {
47+ "amd64" : linuxScript ,
48+ "arm64" : linuxScript ,
49+ "armv7" : linuxScript ,
50+ },
51+ "darwin" : {
52+ "amd64" : darwinScript ,
53+ "arm64" : darwinScript ,
4054 },
4155 }
4256)
@@ -48,6 +62,7 @@ func AgentScriptEnv() map[string]string {
4862 env := map [string ]string {}
4963 for operatingSystem , scripts := range agentScripts {
5064 for architecture , script := range scripts {
65+ script := strings .ReplaceAll (script , "${ARCH}" , architecture )
5166 env [fmt .Sprintf ("CODER_AGENT_SCRIPT_%s_%s" , operatingSystem , architecture )] = script
5267 }
5368 }
0 commit comments