From 83750c4958d2814e0b52eb9cec57a9b69267303e Mon Sep 17 00:00:00 2001 From: Marco Dinis Date: Fri, 7 Jun 2024 16:05:28 +0100 Subject: [PATCH] Use sh in oneoff script oneoff script intends to be as simple and compatible as possible. Using `sh` allows us to be even more compatible, not only with more specific systems but also allows it to be used by the teleport discovery script (which uses `/bin/sh &2 return 1 fi; - if [[ ${ARCH} == "armv7l" ]]; then echo "${teleportFlavor}-${teleportVersion}-linux-arm-bin.tar.gz" - elif [[ ${ARCH} == "aarch64" ]]; then echo "${teleportFlavor}-${teleportVersion}-linux-arm64-bin.tar.gz" - elif [[ ${ARCH} == "x86_64" ]]; then echo "${teleportFlavor}-${teleportVersion}-linux-amd64-bin.tar.gz" - elif [[ ${ARCH} == "i686" ]]; then echo "${teleportFlavor}-${teleportVersion}-linux-386-bin.tar.gz" + if [ ${ARCH} = "armv7l" ]; then echo "${teleportFlavor}-${teleportVersion}-linux-arm-bin.tar.gz" + elif [ ${ARCH} = "aarch64" ]; then echo "${teleportFlavor}-${teleportVersion}-linux-arm64-bin.tar.gz" + elif [ ${ARCH} = "x86_64" ]; then echo "${teleportFlavor}-${teleportVersion}-linux-amd64-bin.tar.gz" + elif [ ${ARCH} = "i686" ]; then echo "${teleportFlavor}-${teleportVersion}-linux-386-bin.tar.gz" else echo "Invalid Linux architecture ${ARCH}." >&2 return 1 fi; } -function main() { - pushd $tempDir > /dev/null +main() { + cd $tempDir tarballName=$(teleportTarballName) curl --show-error --fail --location --remote-name ${cdnBaseURL}/${tarballName} @@ -48,7 +48,7 @@ function main() { echo "> ./bin/teleport ${teleportArgs}" ./bin/teleport ${teleportArgs} && echo $successMessage - popd > /dev/null + cd - } main diff --git a/lib/web/scripts/oneoff/oneoff_test.go b/lib/web/scripts/oneoff/oneoff_test.go index 774a687ea11db..842ee193e9def 100644 --- a/lib/web/scripts/oneoff/oneoff_test.go +++ b/lib/web/scripts/oneoff/oneoff_test.go @@ -103,7 +103,7 @@ func TestOneOffScript(t *testing.T) { require.NoError(t, err) // execute script - out, err := exec.Command("bash", scriptLocation).CombinedOutput() + out, err := exec.Command("sh", scriptLocation).CombinedOutput() // validate require.NoError(t, err, string(out)) @@ -130,7 +130,7 @@ func TestOneOffScript(t *testing.T) { require.NoError(t, err) // execute script - out, err := exec.Command("bash", scriptLocation).CombinedOutput() + out, err := exec.Command("sh", scriptLocation).CombinedOutput() // validate require.Error(t, err, string(out)) @@ -150,7 +150,7 @@ func TestOneOffScript(t *testing.T) { require.NoError(t, err) // execute script - out, err := exec.Command("bash", scriptLocation).CombinedOutput() + out, err := exec.Command("sh", scriptLocation).CombinedOutput() // validate require.Error(t, err, string(out)) @@ -213,7 +213,7 @@ func TestOneOffScript(t *testing.T) { require.NoError(t, err) // execute script - out, err := exec.Command("bash", scriptLocation).CombinedOutput() + out, err := exec.Command("sh", scriptLocation).CombinedOutput() // validate require.NoError(t, err, string(out))