From: Nico Kerschbaumer Date: Sun, 10 Jan 2021 00:06:13 +0000 (+0100) Subject: added kubens installer X-Git-Url: https://git.josue.xyz/?p=webi-installers%2F.git;a=commitdiff_plain;h=9250bd7453b85e94143d103ab5ce7fa3a59b9513 added kubens installer --- diff --git a/kubens/README.md b/kubens/README.md new file mode 100644 index 0000000..84d576e --- /dev/null +++ b/kubens/README.md @@ -0,0 +1,22 @@ +--- +title: kubens +homepage: https://github.com/ahmetb/kubectx +tagline: | + kubens: kubens is a utility to easily switch between Kubernetes namespaces. +--- + +### Updating `kubens` + +`webi kubens@stable` + +Use the `@beta` tag for pre-releases. + +## Cheat Sheet + +> `kubens` kubens helps you switch between Kubernetes namespaces + +To run kubens: + +```bash +kubens +``` diff --git a/kubens/install.ps1 b/kubens/install.ps1 new file mode 100644 index 0000000..41a1a82 --- /dev/null +++ b/kubens/install.ps1 @@ -0,0 +1,58 @@ +#!/usr/bin/env pwsh + +################### +# Install kubens # +################### + +# Every package should define these variables +$pkg_cmd_name = "kubens" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\kubens.exe" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\kubens-v$Env:WEBI_VERSION\bin\kubens.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\kubens-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\kubens-v$Env:WEBI_VERSION" +$pkg_src = "$pkg_src_cmd" + +$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE" + +# Fetch archive +IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE")) +{ + # TODO: arch detection + echo "Downloading kubens from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A -L "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part" + & move "$pkg_download.part" "$pkg_download" +} + +IF (!(Test-Path -Path "$pkg_src_cmd")) +{ + echo "Installing kubens" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\kubens-v*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\kubens.exe" -Recurse -ErrorAction Ignore + + # Unpack archive file into this temporary directory + # Windows BSD-tar handles zip. Imagine that. + echo "Unpacking $pkg_download" + & tar xf "$pkg_download" + + # Settle unpacked archive into place + echo "Install Location: $pkg_src_cmd" + New-Item "$pkg_src_bin" -ItemType Directory -Force + Move-Item -Path "kubens.exe" -Destination "$pkg_src_bin" + + # Exit tmp + popd +} + +echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'" +Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse +Remove-Item -Path "$pkg_src" -Recurse -ErrorAction Ignore diff --git a/kubens/install.sh b/kubens/install.sh new file mode 100644 index 0000000..21b4ffe --- /dev/null +++ b/kubens/install.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +{ + set -e + set -u + + ################### + # Install kubens # + ################### + + # Every package should define these 6 variables + pkg_cmd_name="kubens" + + pkg_dst_cmd="$HOME/.local/bin/kubens" + pkg_dst="$pkg_dst_cmd" + + pkg_src_cmd="$HOME/.local/opt/kubens-v$WEBI_VERSION/bin/kubens" + pkg_src_dir="$HOME/.local/opt/kubens-v$WEBI_VERSION" + pkg_src="$pkg_src_cmd" + + # pkg_install must be defined by every package + pkg_install() { + # e.g. ~/.local/opt/kubens-v0.99.9/bin + mkdir -p "$(dirname $pkg_src_cmd)" + + # mv ./kubens-*/kubens ~/.local/opt/kubens-v0.99.9/bin/kubens + mv kubens "$pkg_src_cmd" + } + + # pkg_get_current_version is recommended, but (soon) not required + pkg_get_current_version() { + # 'kubens' has no version parameter + echo + } + +} diff --git a/kubens/releases.js b/kubens/releases.js new file mode 100644 index 0000000..009b8b2 --- /dev/null +++ b/kubens/releases.js @@ -0,0 +1,24 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'ahmetb'; +var repo = 'kubectx'; + +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + // remove kubectx, etc. from kubens list + all.releases = all.releases.filter(function (rel) { + return !/(\.txt)|(kubectx)|(kubectx_)$/i.test(rel.name); + }); + return all; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + all = require('../_webi/normalize.js')(all); + // just select the first 5 for demonstration + all.releases = all.releases.slice(0, 5); + console.info(JSON.stringify(all, null, 2)); + }); +}