1
1
package provisionersdk
2
2
3
- import "fmt"
3
+ import (
4
+ "fmt"
5
+ "strings"
6
+ )
4
7
5
8
var (
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
16
14
Set-MpPreference -DisableRealtimeMonitoring $true -ExclusionPath $env:TEMP\sshd.exe
17
15
$env:CODER_AGENT_AUTH = "${AUTH_TYPE}"
18
16
$env:CODER_AGENT_URL = "${ACCESS_URL}"
19
- Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru` ,
20
- "arm64" : `$ProgressPreference = "SilentlyContinue"
21
- Invoke-WebRequest -Uri ${ACCESS_URL}bin/coder-windows-arm64.exe -OutFile $env:TEMP\sshd.exe
22
- Set-MpPreference -DisableRealtimeMonitoring $true -ExclusionPath $env:TEMP\sshd.exe
23
- $env:CODER_AGENT_AUTH = "${AUTH_TYPE}"
24
- $env:CODER_AGENT_URL = "${ACCESS_URL}"
25
- Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru` ,
26
- },
27
- "linux" : {
28
- "amd64" : `#!/usr/bin/env sh
29
- set -eu pipefail
30
- export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
31
- curl -fsSL ${ACCESS_URL}bin/coder-linux-amd64 -o $BINARY_LOCATION
32
- chmod +x $BINARY_LOCATION
33
- export CODER_AGENT_AUTH="${AUTH_TYPE}"
34
- export CODER_AGENT_URL="${ACCESS_URL}"
35
- exec $BINARY_LOCATION agent` ,
36
- "arm64" : `#!/usr/bin/env sh
17
+ Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru`
18
+
19
+ linuxScript = `#!/usr/bin/env sh
37
20
set -eu pipefail
38
21
export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
39
- curl -fsSL ${ACCESS_URL}bin/coder-linux-arm64 -o $BINARY_LOCATION
22
+ curl -fsSL ${ACCESS_URL}bin/coder-linux-${ARCH} -o $BINARY_LOCATION
40
23
chmod +x $BINARY_LOCATION
41
24
export CODER_AGENT_AUTH="${AUTH_TYPE}"
42
25
export CODER_AGENT_URL="${ACCESS_URL}"
43
- exec $BINARY_LOCATION agent` ,
44
- "armv7" : `#!/usr/bin/env sh
26
+ exec $BINARY_LOCATION agent`
27
+
28
+ darwinScript = `#!/usr/bin/env sh
45
29
set -eu pipefail
46
30
export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
47
- curl -fsSL ${ACCESS_URL}bin/coder-linux-armv7 -o $BINARY_LOCATION
31
+ curl -fsSL ${ACCESS_URL}bin/coder-darwin-${ARCH} -o $BINARY_LOCATION
48
32
chmod +x $BINARY_LOCATION
49
33
export CODER_AGENT_AUTH="${AUTH_TYPE}"
50
34
export CODER_AGENT_URL="${ACCESS_URL}"
51
- 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 ,
52
50
},
53
51
"darwin" : {
54
- "amd64" : `#!/usr/bin/env sh
55
- set -eu pipefail
56
- export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
57
- curl -fsSL ${ACCESS_URL}bin/coder-darwin-amd64 -o $BINARY_LOCATION
58
- chmod +x $BINARY_LOCATION
59
- export CODER_AGENT_AUTH="${AUTH_TYPE}"
60
- export CODER_AGENT_URL="${ACCESS_URL}"
61
- exec $BINARY_LOCATION agent` ,
62
- "arm64" : `#!/usr/bin/env sh
63
- set -eu pipefail
64
- export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder
65
- curl -fsSL ${ACCESS_URL}bin/coder-darwin-arm64 -o $BINARY_LOCATION
66
- chmod +x $BINARY_LOCATION
67
- export CODER_AGENT_AUTH="${AUTH_TYPE}"
68
- export CODER_AGENT_URL="${ACCESS_URL}"
69
- exec $BINARY_LOCATION agent` ,
52
+ "amd64" : darwinScript ,
53
+ "arm64" : darwinScript ,
70
54
},
71
55
}
72
56
)
@@ -78,6 +62,7 @@ func AgentScriptEnv() map[string]string {
78
62
env := map [string ]string {}
79
63
for operatingSystem , scripts := range agentScripts {
80
64
for architecture , script := range scripts {
65
+ script := strings .ReplaceAll (script , "${ARCH}" , architecture )
81
66
env [fmt .Sprintf ("CODER_AGENT_SCRIPT_%s_%s" , operatingSystem , architecture )] = script
82
67
}
83
68
}
0 commit comments