File tree Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Expand file tree Collapse file tree 3 files changed +35
-4
lines changed Original file line number Diff line number Diff line change 4
4
# This is to allow folks to exec into a failed workspace and poke around to
5
5
# troubleshoot.
6
6
waitonexit () {
7
- echo " === Agent script exited with non-zero code. Sleeping 24h to preserve logs..."
7
+ echo " === Agent script exited with non-zero code ( $? ) . Sleeping 24h to preserve logs..."
8
8
sleep 86400
9
9
}
10
10
trap waitonexit EXIT
31
31
32
32
export CODER_AGENT_AUTH=" ${AUTH_TYPE} "
33
33
export CODER_AGENT_URL=" ${ACCESS_URL} "
34
- exec ./$BINARY_NAME agent
34
+
35
+ output=$( ./${BINARY_NAME} --version | head -n1)
36
+ echo " ${output} " | grep -q Coder
37
+ if [ $? -ne 0 ] ; then
38
+ echo >&2 " ERROR: Downloaded agent binary is invalid"
39
+ echo >&2 " Script output: '${output} '"
40
+ exit 2
41
+ fi
42
+
43
+ exec ./${BINARY_NAME} agent
Original file line number Diff line number Diff line change 4
4
# This is to allow folks to exec into a failed workspace and poke around to
5
5
# troubleshoot.
6
6
waitonexit () {
7
- echo " === Agent script exited with non-zero code. Sleeping 24h to preserve logs..."
7
+ echo " === Agent script exited with non-zero code ( $? ) . Sleeping 24h to preserve logs..."
8
8
sleep 86400
9
9
}
10
10
trap waitonexit EXIT
86
86
87
87
export CODER_AGENT_AUTH=" ${AUTH_TYPE} "
88
88
export CODER_AGENT_URL=" ${ACCESS_URL} "
89
- exec ./$BINARY_NAME agent
89
+
90
+ output=$( ./${BINARY_NAME} --version | head -n1)
91
+ echo " ${output} " | grep -q Coder
92
+ if [ $? -ne 0 ] ; then
93
+ echo >&2 " ERROR: Downloaded agent binary is invalid"
94
+ echo >&2 " Script output: '${output} '"
95
+ exit 2
96
+ fi
97
+
98
+ exec ./${BINARY_NAME} agent
Original file line number Diff line number Diff line change @@ -35,6 +35,19 @@ if (-not (Get-Command 'Set-MpPreference' -ErrorAction SilentlyContinue)) {
35
35
$env: CODER_AGENT_AUTH = " ${AUTH_TYPE} "
36
36
$env: CODER_AGENT_URL = " ${ACCESS_URL} "
37
37
38
+ $psi = [System.Diagnostics.ProcessStartInfo ]::new(" $env: TEMP \sshd.exe" , ' --version' )
39
+ $psi.UseShellExecute = $false
40
+ $psi.RedirectStandardOutput = $true
41
+ $p = [System.Diagnostics.Process ]::Start($psi )
42
+ $output = $p.StandardOutput.ReadToEnd ()
43
+ $p.WaitForExit ()
44
+
45
+ if ($output -notlike " *Coder*" ) {
46
+ Write-Error " ERROR: Downloaded agent binary is invalid"
47
+ Write-Error " Script output: '$output '"
48
+ Exit 2
49
+ }
50
+
38
51
# Check if we're running inside a Windows container!
39
52
$inContainer = $false
40
53
if ((Get-ItemProperty ' HKLM:\SYSTEM\CurrentControlSet\Control' - Name ' ContainerType' - ErrorAction SilentlyContinue) -ne $null ) {
You can’t perform that action at this time.
0 commit comments