From 7ffea8a28a6c4af820889849ed5139c4e993a566 Mon Sep 17 00:00:00 2001 From: Dennis Ploeger Date: Fri, 29 Dec 2023 08:40:54 +0100 Subject: [PATCH] feat: Support for k9s closes #96 --- assets/feature-installer-utils.sh | 18 ++++++++++++++++++ feature/k9s/feature.yaml | 5 +++++ feature/k9s/goss/.env | 1 + feature/k9s/goss/goss.yaml | 6 ++++++ feature/k9s/install.sh | 20 ++++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 feature/k9s/feature.yaml create mode 100644 feature/k9s/goss/.env create mode 100644 feature/k9s/goss/goss.yaml create mode 100644 feature/k9s/install.sh diff --git a/assets/feature-installer-utils.sh b/assets/feature-installer-utils.sh index 4fa4368..5eb02f6 100644 --- a/assets/feature-installer-utils.sh +++ b/assets/feature-installer-utils.sh @@ -60,3 +60,21 @@ function checkAndCleanVersion { echo "${VERSION}" fi } + +# Usage: downloadFromGithub USER REPO VERSION PACKAGE_PREFIX PACKAGE_SUFFIX TARGET +# Downloads a release package from github using the common architecture names +# The package will be downloaded from github.com/USER/REPO/releases/VERSION/download/PACKAGE to the given TARGET file +# where PACKAGE consists of PACKAGE_PREFIXARCHITECTURE.PACKAGE_SUFFIX. +# Example: PACKAGE_PREFIX=krew_linux_, PACKAGE_SUFFIX=tar.gz on an arm architecture will download krew_linux_arm64.tar.gz +function downloadFromGithub { + USER=$1 + REPO=$2 + VERSION=$3 + PACKAGE_PREFIX=$4 + PACKAGE_SUFFIX=$5 + TARGET=$6 + + ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/\(arm\)\(64\)\?.*/\1\2/' -e 's/aarch64$/arm64/')" + PACKAGE="${PACKAGE_PREFIX}${ARCH}.${PACKAGE_SUFFIX}" + execHandle "Downloading ${USER}/${REPO}@${VERSION}" curl -f -s -L "https://github.com/${USER}/${REPO}/releases/${VERSION}/download/${PACKAGE}" --output "${TARGET}" +} \ No newline at end of file diff --git a/feature/k9s/feature.yaml b/feature/k9s/feature.yaml new file mode 100644 index 0000000..d1a73b9 --- /dev/null +++ b/feature/k9s/feature.yaml @@ -0,0 +1,5 @@ +icon: "🐾" +title: "k9s" +description: "Installs [k9s](https://k9scli.io/)" +configuration: + - "Environment K9S_VERSION (optional): Valid k9s version to install (defaults to latest)" diff --git a/feature/k9s/goss/.env b/feature/k9s/goss/.env new file mode 100644 index 0000000..e7e4106 --- /dev/null +++ b/feature/k9s/goss/.env @@ -0,0 +1 @@ +DEBUG_k9s=yes \ No newline at end of file diff --git a/feature/k9s/goss/goss.yaml b/feature/k9s/goss/goss.yaml new file mode 100644 index 0000000..b247081 --- /dev/null +++ b/feature/k9s/goss/goss.yaml @@ -0,0 +1,6 @@ +command: + k9s: + exec: "/home/cloudcontrol/bin/k9s version" + exit-status: 0 + stdout: + - "Version:" diff --git a/feature/k9s/install.sh b/feature/k9s/install.sh new file mode 100644 index 0000000..d46cf18 --- /dev/null +++ b/feature/k9s/install.sh @@ -0,0 +1,20 @@ +. /feature-installer-utils.sh + +if [ -n "${K9S_VERSION}" ] +then + K9S_VERSION=$(checkAndCleanVersion "${K9S_VERSION}") +else + K9S_VERSION="latest" +fi + +TEMPDIR=$(mktemp -d) +cd "${TEMPDIR}" || exit + +downloadFromGithub derailed k9s "${K9S_VERSION}" k9s_Linux_ tar.gz k9s.tar.gz + +execHandle "Unpacking k9s" tar xzf k9s.tar.gz +execHandle "Installing k9s" mv k9s /home/cloudcontrol/bin +execHandle "Making k9s executable" chmod +x /home/cloudcontrol/bin/k9s + +cd - &>/dev/null || exit +rm -rf "${TEMPDIR}" \ No newline at end of file