diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index b8068b9..514328a 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -22,4 +22,4 @@ jobs: steps: - uses: asdf-vm/actions/plugin-test@v2 with: - command: crictl --version \ No newline at end of file + command: crictl --version diff --git a/README.md b/README.md index 637ece9..deec9c3 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,62 @@ -# asdf-crictl +
-crictl plugin for [asdf](https://github.com/asdf-vm/asdf) version manager +# asdf-crictl [![CI](https://github.com/FairwindsOps/asdf-crictl/actions/workflows/workflow.yml/badge.svg?branch=main)](https://github.com/FairwindsOps/asdf-crictl/actions/workflows/workflow.yml) -## Install +[crictl](https://github.com/kubernetes-sigs/cri-tools) plugin for the [asdf version manager](https://asdf-vm.com). -``` -asdf plugin-add crictl https://github.com/FairwindsOps/asdf-crictl.git -``` +
-## Use +# Contents -Check out the [asdf documentation](https://asdf-vm.com/#/core-manage-versions?id=install-version) for instructions on how to install and manage versions of crictl. +- [Dependencies](#dependencies) +- [Install](#install) +- [Contributing](#contributing) +- [License](#license) -## Architecture Override -The `ASDF_crictl_OVERWRITE_ARCH` variable can be used to override the architecture that is used for determining which `crictl` build to download. The primary use case is when attempting to install an older version of `crictl` for use on an Apple M1 computer as `crictl` was not built for ARM at the time. +# Dependencies -### Without `ASDF_crictl_OVERWRITE_ARCH`: +- `bash`, `curl`, `gzip`, `cut`: generic POSIX utilities. -``` -% asdf install crictl 6.0.0 -Downloading crictl from https://github.com/FairwindsOps/crictl/releases/download/v6.0.0/crictl_6.0.0_darwin_amd64.tar.gz -% asdf global crictl 6.0.0 -``` +# Install -### With `ASDF_crictl_OVERWRITE_ARCH`: +Plugin: +```shell +asdf plugin add crictl +# or +asdf plugin add crictl https://github.com/FairwindsOps/asdf-crictl.git ``` -% ASDF_crictl_OVERWRITE_ARCH=amd64 asdf install crictl 6.0.0-rc.5 -Downloading crictl from https://github.com/FairwindsOps/crictl/releases/download/v6.0.0-rc.5/crictl_6.0.0-rc.5_darwin_amd64.tar.gz -% asdf global crictl 6.0.0-rc.5 + +crictl: + +```shell +# Show all installable versions +asdf list-all crictl + +# Install specific version +asdf install crictl latest + +# Set a version globally (on your ~/.tool-versions file) +asdf global crictl latest + +# Now crictl commands are available +crictl --help ``` +Check [asdf](https://github.com/asdf-vm/asdf) readme for more instructions on how to +install & manage versions. + +# Contributing + +Contributions of any kind welcome! See the [contributing guide](contributing.md). + +[Thanks goes to these contributors](https://github.com/FairwindsOps/asdf-crictl/graphs/contributors)! + +# License + +See [LICENSE](LICENSE) © [Ivan Valdes](https://github.com/FairwindsOps/) + + ## Join the Fairwinds Open Source Community diff --git a/bin/check b/bin/check index 2201d1b..c00114b 100755 --- a/bin/check +++ b/bin/check @@ -5,17 +5,23 @@ local_version="$1" os_name="$(uname -s)" case "${os_name}" in - Linux*) os=linux;; - Darwin*) os=darwin;; - CYGWIN*) os=windows;; - MINGW*) os=windows;; - *) echo "unknown OS"; exit 1;; +Linux*) os=linux ;; +Darwin*) os=darwin ;; +CYGWIN*) os=windows ;; +MINGW*) os=windows ;; +*) + echo "unknown OS" + exit 1 + ;; esac case "$(uname -m)" in - x86_64*) arch=amd64;; - arm64*) arch=arm64;; - *) echo "unknown architecture"; exit 1;; +x86_64*) arch=amd64 ;; +arm64*) arch=arm64 ;; +*) + echo "unknown architecture" + exit 1 + ;; esac curl --silent --fail "https://github.com/kubernetes-sigs/cri-tools/releases/download/v${local_version}/crictl-v${local_version}-${os}-${arch}.tar.gz" >/dev/null diff --git a/bin/install b/bin/install index c73d616..0751afc 100755 --- a/bin/install +++ b/bin/install @@ -4,46 +4,46 @@ set -e set -o pipefail install_crictl() { - local install_type=$1 - local version=$2 - local install_path=$3 - local platform="$(uname | tr '[:upper:]' '[:lower:]')-amd64" - local bin_install_path="$install_path/bin" - local binary_path="$bin_install_path/crictl" - local download_url=$(get_download_url $version $platform) - - if [ "$TMPDIR" = "" ]; then - local tmp_download_dir=$(mktemp -d -t crictl_XXXXXX) - else - local tmp_download_dir=$TMPDIR - fi - - local download_path="$tmp_download_dir/$(get_filename $version $platform)" - - echo "Downloading crictl from ${download_url} to ${download_path}" - curl -Lo $download_path $download_url - - echo "Creating bin directory" - mkdir -p "${bin_install_path}" - - echo "Cleaning previous binaries" - rm -f $binary_path 2>/dev/null || true - - echo "Copying binary" - tar -zxf ${download_path} --directory $tmp_download_dir - cp ${tmp_download_dir}/crictl ${bin_install_path} - chmod +x ${binary_path} + local install_type=$1 + local version=$2 + local install_path=$3 + local platform="$(uname | tr '[:upper:]' '[:lower:]')-amd64" + local bin_install_path="$install_path/bin" + local binary_path="$bin_install_path/crictl" + local download_url=$(get_download_url $version $platform) + + if [ "$TMPDIR" = "" ]; then + local tmp_download_dir=$(mktemp -d -t crictl_XXXXXX) + else + local tmp_download_dir=$TMPDIR + fi + + local download_path="$tmp_download_dir/$(get_filename $version $platform)" + + echo "Downloading crictl from ${download_url} to ${download_path}" + curl -Lo $download_path $download_url + + echo "Creating bin directory" + mkdir -p "${bin_install_path}" + + echo "Cleaning previous binaries" + rm -f $binary_path 2>/dev/null || true + + echo "Copying binary" + tar -zxf ${download_path} --directory $tmp_download_dir + cp ${tmp_download_dir}/crictl ${bin_install_path} + chmod +x ${binary_path} } get_filename() { - echo "crictl-v${1}-${2}.tar.gz" + echo "crictl-v${1}-${2}.tar.gz" } get_download_url() { - local version="$1" - local platform="$2" - local filename="$(get_filename $version $platform)" - echo "https://github.com/kubernetes-sigs/cri-tools/releases/download/v${version}/${filename}" + local version="$1" + local platform="$2" + local filename="$(get_filename $version $platform)" + echo "https://github.com/kubernetes-sigs/cri-tools/releases/download/v${version}/${filename}" } install_crictl $ASDF_INSTALL_TYPE $ASDF_INSTALL_VERSION $ASDF_INSTALL_PATH diff --git a/bin/list-all b/bin/list-all index 2ff5f01..3504ec9 100755 --- a/bin/list-all +++ b/bin/list-all @@ -3,13 +3,13 @@ release_path=https://api.github.com/repos/kubernetes-sigs/cri-tools/releases cmd="curl -s" if [ -n "$GITHUB_API_TOKEN" ]; then - cmd="$cmd -H 'Authorization: token $GITHUB_API_TOKEN'" + cmd="$cmd -H 'Authorization: token $GITHUB_API_TOKEN'" fi cmd="$cmd $release_path" function sort_versions() { - sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \ - LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' + sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | + LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' } versions=$(eval $cmd | grep -oE "tag_name\": *\"v.*.{1,15}\"," | sed 's/tag_name\": *\"v//;s/\",//' | sort_versions) diff --git a/lib/commands.bash b/lib/commands.bash index 37386e1..a3e2c1c 100644 --- a/lib/commands.bash +++ b/lib/commands.bash @@ -1,29 +1,29 @@ list_all_versions() { - local release_url="https://github.com/kubernetes-sigs/cri-tools/releases" - curl -Ls $release_url | grep -oE 'href="/kubernetes-sigs/cri-tools/releases/tag/v[0-9]+\.[0-9]+\.[0-9]+"' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -rV + local release_url="https://github.com/kubernetes-sigs/cri-tools/releases" + curl -Ls $release_url | grep -oE 'href="/kubernetes-sigs/cri-tools/releases/tag/v[0-9]+\.[0-9]+\.[0-9]+"' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -rV } list_installed_versions() { - ls -1 ~/.asdf/installs/crictl + ls -1 ~/.asdf/installs/crictl } install_version() { - local version=$1 - asdf plugin-add crictl https://github.com/kubernetes-sigs/cri-tools.git - asdf install crictl $version + local version=$1 + asdf plugin-add crictl https://github.com/kubernetes-sigs/cri-tools.git + asdf install crictl $version } uninstall_version() { - local version=$1 - asdf uninstall crictl $version + local version=$1 + asdf uninstall crictl $version } set_global_version() { - local version=$1 - asdf global crictl $version + local version=$1 + asdf global crictl $version } set_local_version() { - local version=$1 - asdf local crictl $version + local version=$1 + asdf local crictl $version } diff --git a/scripts/format.bash b/scripts/format.bash new file mode 100755 index 0000000..1a216ea --- /dev/null +++ b/scripts/format.bash @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +shfmt --language-dialect bash --write \ + ./**/* diff --git a/scripts/lint.bash b/scripts/lint.bash new file mode 100755 index 0000000..3451a05 --- /dev/null +++ b/scripts/lint.bash @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +shellcheck --shell=bash --external-sources \ + bin/* --source-path=template/lib/ \ + lib/* \ + scripts/* + +shfmt --language-dialect bash --diff \ + ./**/*