From fd5ed124f1cf98ea1504f54263a5700ed3d78ed9 Mon Sep 17 00:00:00 2001 From: Ryan Burnette Date: Sun, 14 Mar 2021 16:01:31 -0400 Subject: [PATCH] add awless installer --- awless/README.md | 14 ++++++++++++ awless/install.ps1 | 57 ++++++++++++++++++++++++++++++++++++++++++++++ awless/install.sh | 42 ++++++++++++++++++++++++++++++++++ awless/releases.js | 22 ++++++++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 awless/README.md create mode 100644 awless/install.ps1 create mode 100644 awless/install.sh create mode 100644 awless/releases.js diff --git a/awless/README.md b/awless/README.md new file mode 100644 index 0000000..856a874 --- /dev/null +++ b/awless/README.md @@ -0,0 +1,14 @@ +--- +title: awless +homepage: https://github.com/wallix/awless +tagline: | + awless is a powerful, innovative and small surface command line interface (CLI) to manage Amazon Web Services. +--- + +## Updating awless + +```bash +webi awless +``` + +## Cheat Sheet diff --git a/awless/install.ps1 b/awless/install.ps1 new file mode 100644 index 0000000..13ac3db --- /dev/null +++ b/awless/install.ps1 @@ -0,0 +1,57 @@ +#!/usr/bin/env pwsh + +################# +# Install awless # +################# + +# Every package should define these variables +$pkg_cmd_name = "awless" + +$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\awless.exe" +$pkg_dst_bin = "$Env:USERPROFILE\.local\bin" +$pkg_dst = "$pkg_dst_cmd" + +$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\awless-v$Env:WEBI_VERSION\bin\awless.exe" +$pkg_src_bin = "$Env:USERPROFILE\.local\opt\awless-v$Env:WEBI_VERSION\bin" +$pkg_src_dir = "$Env:USERPROFILE\.local\opt\awless-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 awless from $Env:WEBI_PKG_URL to $pkg_download" + & curl.exe -A "$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 awless" + + # TODO: create package-specific temp directory + # Enter tmp + pushd .local\tmp + + # Remove any leftover tmp cruft + Remove-Item -Path ".\awless-v*" -Recurse -ErrorAction Ignore + Remove-Item -Path ".\awless.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 ".\awless.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 +New-Item "$pkg_dst_bin" -ItemType Directory -Force +Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse diff --git a/awless/install.sh b/awless/install.sh new file mode 100644 index 0000000..080859d --- /dev/null +++ b/awless/install.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# "This is too simple" you say! "Where is the magic!?" you ask. +# There is no magic! +# The custom functions for awless are here. +# The generic functions - version checks, download, extract, etc - are here: +# - https://github.com/webinstall/packages/branches/master/_webi/template.sh + +set -e +set -u + +pkg_cmd_name="awless" + +# IMPORTANT: this let's other functions know to expect this to be a single file +WEBI_SINGLE=true + +pkg_get_current_version() { + # 'awless version' has output in this format: + # v2.1.0 h1:pQSaIJGFluFvu8KDGDODV8u4/QRED/OPyIR+MWYYse8= + # This trims it down to just the version number: + # 2.1.0 + echo "$(awless version 2>/dev/null | head -n 1 | cut -d' ' -f1 | sed 's:^v::')" +} + +pkg_install() { + # $HOME/.local/opt/awless-v2.1.0/bin + mkdir -p "$pkg_src_bin" + + # mv ./awless* "$HOME/.local/opt/awless-v2.1.0/bin/awless" + mv ./"$pkg_cmd_name"* "$pkg_src_cmd" + + # chmod a+x "$HOME/.local/opt/awless-v2.1.0/bin/awless" + chmod a+x "$pkg_src_cmd" +} + +pkg_link() { + # rm -f "$HOME/.local/bin/awless" + rm -f "$pkg_dst_cmd" + + # ln -s "$HOME/.local/opt/awless-v2.1.0/bin/awless" "$HOME/.local/bin/awless" + ln -s "$pkg_src_cmd" "$pkg_dst_cmd" +} diff --git a/awless/releases.js b/awless/releases.js new file mode 100644 index 0000000..281dfbf --- /dev/null +++ b/awless/releases.js @@ -0,0 +1,22 @@ +'use strict'; + +var github = require('../_common/github.js'); +var owner = 'wallix'; +var repo = 'awless'; + +module.exports = function (request) { + return github(request, owner, repo).then(function (all) { + // remove checksums and .deb + all.releases = all.releases.filter(function (rel) { + return !/(\.txt)|(\.deb)$/i.test(rel.name); + }); + return all; + }); +}; + +if (module === require.main) { + module.exports(require('@root/request')).then(function (all) { + all = require('../_webi/normalize.js')(all); + console.info(JSON.stringify(all)); + }); +} -- 2.25.1