Last active
February 28, 2023 15:11
-
-
Save piyoki/895b88b553c4e3369305aa0a4b0efc47 to your computer and use it in GitHub Desktop.
k0s-bootstrap.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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