Skip to content

Commit

Permalink
Use sh in oneoff script (#42744)
Browse files Browse the repository at this point in the history
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 <my-script.sh`)
  • Loading branch information
marcoandredinis authored Jun 11, 2024
1 parent 496bb7c commit 14417af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
24 changes: 12 additions & 12 deletions lib/web/scripts/oneoff/oneoff.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -euo pipefail
#!/usr/bin/env sh
set -eu

cdnBaseURL='{{.CDNBaseURL}}'
teleportVersion='{{.TeleportVersion}}'
Expand All @@ -14,29 +14,29 @@ ARCH=$({{.BinUname}} -m)

teleportArgs='{{.TeleportArgs}}'

function teleportTarballName(){
if [[ ${OS} == "Darwin" ]]; then
teleportTarballName() {
if [ ${OS} = "Darwin" ]; then
echo ${teleportFlavor}-${teleportVersion}-darwin-universal-bin.tar.gz
return 0
fi;

if [[ ${OS} != "Linux" ]]; then
if [ ${OS} != "Linux" ]; then
echo "Only MacOS and Linux are supported." >&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}
Expand All @@ -48,7 +48,7 @@ function main() {
echo "> ./bin/teleport ${teleportArgs}"
./bin/teleport ${teleportArgs} && echo $successMessage

popd > /dev/null
cd -
}

main
8 changes: 4 additions & 4 deletions lib/web/scripts/oneoff/oneoff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 14417af

Please sign in to comment.