Skip to content

Instantly share code, notes, and snippets.

@piyoki
Last active February 28, 2023 15:11
Show Gist options
  • Save piyoki/895b88b553c4e3369305aa0a4b0efc47 to your computer and use it in GitHub Desktop.
Save piyoki/895b88b553c4e3369305aa0a4b0efc47 to your computer and use it in GitHub Desktop.
k0s-bootstrap.sh
#!/bin/sh
set -e
if [ -n "${DEBUG}" ]; then
set -x
fi
_k0s_latest() {
curl -sSLf "https://docs.k0sproject.io/stable.txt"
}
_detect_binary() {
os="$(uname)"
case "$os" in
Linux) echo "k0s" ;;
*) echo "Unsupported operating system: $os" 1>&2; return 1 ;;
esac
unset os
}
_detect_arch() {
arch="$(uname -m)"
case "$arch" in
amd64|x86_64) echo "amd64" ;;
arm64|aarch64) echo "arm64" ;;
armv7l|armv8l|arm) echo "arm" ;;
*) echo "Unsupported processor architecture: $arch" 1>&2; return 1 ;;
esac
unset arch
}
_download_url() {
echo "https://ghproxy.com/github.com/k0sproject/k0s/releases/download/$K0S_VERSION/$k0sBinary-$K0S_VERSION-$k0sArch"
}
main() {
if [ -z "${K0S_VERSION}" ]; then
K0S_VERSION=$(_k0s_latest)
fi
k0sInstallPath=/usr/local/bin
k0sBinary="$(_detect_binary)"
k0sArch="$(_detect_arch)"
k0sDownloadUrl="$(_download_url)"
mkdir -p -- "$k0sInstallPath"
echo "Downloading k0s from URL: $k0sDownloadUrl"
curl -sSLf "$k0sDownloadUrl" >"$k0sInstallPath/$k0sBinary"
chmod 755 -- "$k0sInstallPath/$k0sBinary"
echo "k0s is now executable in $k0sInstallPath"
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment