Skip to content

Commit

Permalink
feat: use cookiecutter template
Browse files Browse the repository at this point in the history
  • Loading branch information
looztra committed Dec 23, 2020
1 parent 869e6e4 commit 1a5262f
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 70 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/aio.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: AllInOne

on:
push:
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
schedule:
- cron: 0 0 * * 5

jobs:
plugin_test:
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- name: asdf_plugin_test
uses: asdf-vm/actions/plugin-test@v1
with:
command: gitui --version

lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run the sh-checker
uses: luizm/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
#SHELLCHECK_OPTS: -e SC1004 # Optional: exclude some shellcheck warnings.
SHFMT_OPTS: -i 2 # Optional: pass arguments to shfmt.
with:
sh_checker_comment: true
29 changes: 0 additions & 29 deletions .github/workflows/workflow.yml

This file was deleted.

12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# asdf-gitui

[![GitHub Actions Status](https://github.com/looztra/asdf-gitui/workflows/Main%20workflow/badge.svg?branch=master)](https://github.com/looztra/asdf-gitui/actions)
![AllInOne](https://github.com/looztra/asdf-gitui/workflows/AllInOne/badge.svg)
[![GitHub license](https://img.shields.io/github/license/looztra/asdf-gitui?style=plastic)](https://github.com/looztra/asdf-gitui/blob/master/LICENSE)

[gitui](https://github.com/extrawurst/gitui) plugin for the [asdf](https://github.com/asdf-vm/asdf) version manager.
## Build History

[![Build history](https://buildstats.info/github/chart/looztra/asdf-gitui?branch=master)](https://github.com/looztra/asdf-gitui/actions)

## gitui

<https://github.com/extrawurst/gitui>

## Install

Expand All @@ -15,4 +21,6 @@ asdf plugin-add gitui https://github.com/looztra/asdf-gitui

Check out the [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install and manage versions of gitui.

## Source code

This source code has been generated with : `cookiecutter --overwrite-if-exists --directory plugins/gitui --no-input https://github.com/looztra/cookiecutter-asdf-plugin`
118 changes: 89 additions & 29 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,25 @@ set -o pipefail

# https://github.com/extrawurst/gitui/releases/download/v0.6.0/gitui-linux-musl.tar.gz
# https://github.com/extrawurst/gitui/releases/download/v0.6.0/gitui-mac.tar.gz
readonly github_coordinates=extrawurst/gitui
readonly toolname=gitui
readonly filename_template=__BINARY_NAME__-__PLATFORM__.tar.gz
readonly download_url_template=https://github.com/__GITHUB_COORDINATES__/releases/download/v__VERSION__/__FILENAME__
readonly binary_path_in_archive_template=__ARCHIVE_DIR__/__BINARY_NAME__

readonly NO_BINARY_ALTNAME=@@UNDEFINED@@
readonly g_github_coordinates=extrawurst/gitui
readonly g_binary_name=gitui
readonly g_binary_altname="$NO_BINARY_ALTNAME"
#
# __VERSION__/__VERSION_SHORT__/__BINARY_NAME__/__PLATFORM__
#
readonly g_filename_template=__BINARY_NAME__-__PLATFORM__.tar.gz
#
# __GITHUB_COORDINATES__/__VERSION__/__VERSION_SHORT__/__FILENAME__
#
readonly g_download_url_template=https://github.com/__GITHUB_COORDINATES__/releases/download/v__VERSION__/__FILENAME__
#
# __ARCHIVE_DIR__/__BINARY_NAME__/__VERSION__/__VERSION_SHORT__/__PLATFORM__
#
readonly g_binary_path_in_archive_template=__ARCHIVE_DIR__/__BINARY_NAME__
readonly g_downloaded_file_is_not_an_archive=false
readonly g_platform_pattern=custom # one of uname_c_x86_64|uname_l_dash_amd64|uname_l_underscore_amd64|custom

# Borrowed to someone, but I don't remember who it was, sorry :(
# Print message $2 with log-level $1 to STDERR, colorized if terminal
Expand All @@ -36,51 +50,84 @@ function log() {
}

install_tool() {
#local install_type=$1
local install_type=$1
local version=$2
local install_path=$3
local tmp_download_dir=$4
local binary_name=$5
local binary_alt_name=$6
local downloaded_file_is_not_an_archive=$7

local platform
local bin_install_path="$install_path/bin"
local binary_path="$bin_install_path/${binary_name}"
local full_path_to_binary="$bin_install_path/${binary_name}"
local full_path_to_alt_binary
if [[ -n "$binary_alt_name" || "$binary_alt_name" == "$NO_BINARY_ALTNAME" ]]; then
full_path_to_alt_binary="$bin_install_path/${binary_alt_name}"
fi
local download_url
local download_path
local download_target_file
local download_sub_path_dir

if [[ "$install_type" != "version" ]]; then
log ERROR "Install of type [$install_type] not supported"
fi

platform=$(get_platform)
download_url=$(get_download_url "$version" "$platform" "$binary_name")
download_path="$tmp_download_dir/"$(get_filename "$version" "$platform" "$binary_name")
download_sub_path_dir=$tmp_download_dir/sub
mkdir -p "$download_sub_path_dir"
download_target_file="$download_sub_path_dir/"$(get_filename "$version" "$platform" "$binary_name")

log INFO "Downloading [${binary_name}] from ${download_url} to ${download_path}"
curl -Lo "$download_path" "$download_url"
log INFO "Downloading [${binary_name}] from ${download_url} to ${download_target_file}"
curl --location --output "$download_target_file" "$download_url"

log INFO "Creating bin directory"
log INFO "Creating bin directory [${bin_install_path}]"
mkdir -p "${bin_install_path}"

log INFO "Cleaning previous binaries"
rm -f "$binary_path" 2>/dev/null || true

log INFO "Extracting archive"
tar xpf "$download_path" -C "$tmp_download_dir"
log INFO "Cleaning previous binaries if any"
rm -f "$full_path_to_binary" 2>/dev/null || true
if [[ -n "$binary_alt_name" ]]; then
rm -f "$full_path_to_alt_binary" 2>/dev/null || true
fi
if [[ "$downloaded_file_is_not_an_archive" != "true" ]]; then
log INFO "Extracting archive"
tar xpf "$download_target_file" -C "$tmp_download_dir"
else
log INFO "Preparing downloaded file"
cp "$download_target_file" "$tmp_download_dir"
fi
log INFO "Copying binaries"
cp "$(get_binary_path_in_archive "${tmp_download_dir}" "${binary_name}" "${version}" "${platform}")" "${full_path_to_binary}"
chmod +x "${full_path_to_binary}"
if [[ -n "$binary_alt_name" ]]; then
cp "${full_path_to_binary}" "${full_path_to_alt_binary}"
chmod +x "${full_path_to_alt_binary}"
fi
}

log INFO "Copying binary"
cp "$(get_binary_path_in_archive "${tmp_download_dir}" "${binary_name}" "${version}" "${platform}")" "${binary_path}"
chmod +x "${binary_path}"
get_version_short() {
local version=$1
echo "$version" | tr -d "v"
}

get_binary_path_in_archive() {
local archive_dir=$1
local binary_name=$2
local version=$3
local platform=$4
local version_short
version_short=$(get_version_short "$version")

echo $binary_path_in_archive_template |
sed "s|__ARCHIVE_DIR__|${archive_dir}|g;s|__BINARY_NAME__|${binary_name}|g;s|__VERSION__|${version}|g;s|__PLATFORM__|${platform}|g;"

echo $g_binary_path_in_archive_template |
sed "s|__ARCHIVE_DIR__|${archive_dir}|g;s|__BINARY_NAME__|${binary_name}|g;s|__VERSION__|${version}|g;s|__VERSION_SHORT__|${version_short}|g;s|__PLATFORM__|${platform}|g;"
}

get_platform() {
get_platform_${g_platform_pattern}
}

get_platform_custom() {
local operating_system
operating_system=$(uname | tr '[:upper:]' '[:lower:]')
if [[ "$operating_system" == "linux" ]]; then
Expand All @@ -90,32 +137,45 @@ get_platform() {
fi
}

get_platform_uname_c_x86_64() {
echo "$(uname)_x86_64"
}

get_platform_uname_l_dash_amd64() {
echo "$(uname | tr '[:upper:]' '[:lower:]')-amd64"
}

get_platform_uname_l_underscore_amd64() {
echo "$(uname | tr '[:upper:]' '[:lower:]')_amd64"
}

get_filename() {
local version="$1"
local platform="$2"
local binary_name="$3"
local version_short
version_short=$(echo "$version" | tr -d "v")
version_short=$(get_version_short "$version")
# log DEBUG "version=${version}, version_short=${version_short}, binary_name=${binary_name}, platform=${platform}"

echo "$filename_template" |
echo "$g_filename_template" |
sed "s/__VERSION__/${version}/g;s/__VERSION_SHORT__/${version_short}/g;s/__BINARY_NAME__/${binary_name}/g;s/__PLATFORM__/${platform}/g"
}

get_download_url() {
local version="$1"
local platform="$2"
local binary_name="$3"

local filename
filename="$(get_filename "$version" "$platform" "$binary_name")"
local version_short
version_short=$(get_version_short "$version")
# log DEBUG "version=${version}, binary_name=${binary_name}, platform=${platform}, filename=${filename}"

echo "$download_url_template" |
sed "s|__GITHUB_COORDINATES__|${github_coordinates}|g;s|__VERSION__|${version}|g;s|__FILENAME__|${filename}|g;"
echo "$g_download_url_template" |
sed "s|__GITHUB_COORDINATES__|${g_github_coordinates}|g;s|__VERSION__|${version}|g;s|__VERSION_SHORT__|${version_short}|g;s|__FILENAME__|${filename}|g;"

}

readonly _tmp_download_dir="$(mktemp -d -t 'asdf_XXXXXXXX')"
trap 'rm -rf "${_tmp_download_dir}"' EXIT
install_tool "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" "$_tmp_download_dir" "$toolname"
install_tool "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH" "$_tmp_download_dir" "$g_binary_name" "$g_binary_altname" "$g_downloaded_file_is_not_an_archive"
10 changes: 0 additions & 10 deletions shellcheck-on-linux-only.sh

This file was deleted.

0 comments on commit 1a5262f

Please sign in to comment.