Skip to content

Instantly share code, notes, and snippets.

@joscha
Last active January 4, 2024 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joscha/da683f7436d339ebb5df9f9d248c326d to your computer and use it in GitHub Desktop.
Save joscha/da683f7436d339ebb5df9f9d248c326d to your computer and use it in GitHub Desktop.
kurtosis online exec

kurtosis_exec.sh is a wrapper for fetching, temporarily storing and executing the kurtosis CLI which can be executed with a bash one liner.

It would live in a public location, somewhere like https://kurtosis.com/exec and then be invoked with a single command like:

bash <(curl -s https://kurtosis.com/exec)

where exec is a modified copy of kurtosis_exec.sh by CI to include correct SHASUMs and version numbers. The exec script itself would also need SHASUM files provided, so anyone running this on CI or as part of a deployment script anywhere can ensure that the installer itself has not been tampered with, either.

For the purpose of testing this functionality whilst the script is not hosted anywhere, yet, you can just:

bash <(curl -s file://`pwd`/kurtosis_exec.sh)

to fetch it locally and execute it.

#!/usr/bin/env bash
set -euo pipefail
# TODO: This will need to be generated for each release
KURTOSIS_CLI_VERSION="0.85.55"
KURTOSIS_CLI_SHA256="37bc2ffaddab49c72317dc44d21b4d6ad9a7c6caba946a05ac6a7ea7c9ae5f79"
debug() {
>&2 echo "$*"
}
error() {
debug "$@"
exit 1
}
print_platform() {
local OS
OS=$(uname -s)
local ARCH
ARCH=$(uname -m)
if [[ "${OS}" = "Linux" ]] ; then
echo "linux_${ARCH}"
return
elif [[ "${OS}" == "Darwin" ]]; then
echo "darwin_${ARCH}"
return
fi
error "Unsupported platform; OS: ${OS}, ARCH: ${ARCH}"
}
print_tmpdir() {
local t
for t in "${TMPDIR:-}" "${TMP:-}" /var/tmp /tmp
do
test -d "${t}" && break
done
echo "${t}"
}
PLATFORM=$(print_platform)
KURTOSIS_CLI_URL="https://github.com/kurtosis-tech/kurtosis-cli-release-artifacts/releases/download/${KURTOSIS_CLI_VERSION}/kurtosis-cli_${KURTOSIS_CLI_VERSION}_${PLATFORM}.tar.gz"
STABLE_TMP_DIR=$(print_tmpdir)
main() {
# TODO: We could have target_folder to be just /usr/local/bin or allow the user of the script to specify it and tell them how to amend their PATH
# for the purpose of this script we just use a stable temp dir, so we download once and keep the binary there, assuming the release version is stable
local target_folder
target_folder="${STABLE_TMP_DIR}kurtosis/${PLATFORM}/${KURTOSIS_CLI_VERSION}"
mkdir -p "$target_folder"
local cli_binary_name="kurtosis"
local target_cli
target_cli="${target_folder}/${cli_binary_name}"
if ! [[ -f "${target_cli}" ]]; then
pushd "${target_folder}" >/dev/null
debug "Downloading Kurtosis CLI from ${KURTOSIS_CLI_URL} to ${target_folder}"
# TODO: we only pull the kurtosis binary for now, but we may want shell completions as well
curl -s -L "$KURTOSIS_CLI_URL" | tar xz - -C "." "${cli_binary_name}"
echo "${KURTOSIS_CLI_SHA256} ${cli_binary_name}" | sha256sum --check --status
popd >/dev/null
fi
"${target_cli}" "$@"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment