diff --git a/provisionersdk/agent.go b/provisionersdk/agent.go index 00f6861ef9136..59d06556e8799 100644 --- a/provisionersdk/agent.go +++ b/provisionersdk/agent.go @@ -17,18 +17,28 @@ $env:CODER_AGENT_URL = "${ACCESS_URL}" Start-Process -FilePath $env:TEMP\sshd.exe -ArgumentList "agent" -PassThru` linuxScript = `#!/usr/bin/env sh -set -eu pipefail -export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder -curl -fsSL ${ACCESS_URL}bin/coder-linux-${ARCH} -o $BINARY_LOCATION +set -eux pipefail +BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXXX)/coder +BINARY_URL=${ACCESS_URL}bin/coder-linux-${ARCH} +if which curl >/dev/null 2>&1; then + curl -fsSL "${BINARY_URL}" -o "${BINARY_LOCATION}" +elif which wget >/dev/null 2>&1; then + wget -q "${BINARY_URL}" -O "${BINARY_LOCATION}" +elif which busybox >/dev/null 2>&1; then + busybox wget -q "${BINARY_URL}" -O "${BINARY_LOCATION}" +else + echo "error: no download tool found, please install curl, wget or busybox wget" + exit 1 +fi chmod +x $BINARY_LOCATION export CODER_AGENT_AUTH="${AUTH_TYPE}" export CODER_AGENT_URL="${ACCESS_URL}" exec $BINARY_LOCATION agent` darwinScript = `#!/usr/bin/env sh -set -eu pipefail -export BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXX)/coder -curl -fsSL ${ACCESS_URL}bin/coder-darwin-${ARCH} -o $BINARY_LOCATION +set -eux pipefail +BINARY_LOCATION=$(mktemp -d -t tmp.coderXXXXXX)/coder +curl -fsSL "${ACCESS_URL}bin/coder-darwin-${ARCH}" -o "${BINARY_LOCATION}" chmod +x $BINARY_LOCATION export CODER_AGENT_AUTH="${AUTH_TYPE}" export CODER_AGENT_URL="${ACCESS_URL}" diff --git a/provisionersdk/agent_test.go b/provisionersdk/agent_test.go index d9ebbb8d8936a..255d713c7c8a2 100644 --- a/provisionersdk/agent_test.go +++ b/provisionersdk/agent_test.go @@ -49,8 +49,11 @@ func TestAgentScript(t *testing.T) { output, err := exec.Command("sh", "-c", script).CombinedOutput() t.Log(string(output)) require.NoError(t, err) + // Ignore debug output from `set -x`, we're only interested in the last line. + lines := strings.Split(strings.TrimSpace(string(output)), "\n") + lastLine := lines[len(lines)-1] // Because we use the "echo" binary, we should expect the arguments provided // as the response to executing our script. - require.Equal(t, "agent", strings.TrimSpace(string(output))) + require.Equal(t, "agent", lastLine) }) }