Skip to content

Commit

Permalink
feat(installer): add kubergrunt installer
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoHsu committed Jun 17, 2021
1 parent 1a86594 commit 0e7464b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
13 changes: 3 additions & 10 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@

set -euo pipefail

# shellcheck source=../lib/utils.bash
# shellcheck source=lib/utils.bash
source "$(dirname "$0")/../lib/utils.bash"

mkdir -p "$ASDF_DOWNLOAD_PATH"

# TODO: Adapt this to proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME-$ASDF_INSTALL_VERSION.tar.gz"
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME"

# Download tar.gz file to the download directory
# Download binary file to the download directory
download_release "$ASDF_INSTALL_VERSION" "$release_file"

# Extract contents of tar.gz file into the download directory
tar -xzf "$release_file" -C "$ASDF_DOWNLOAD_PATH" --strip-components=1 || fail "Could not extract $release_file"

# Remove the tar.gz file since we don't need to keep it
rm "$release_file"
2 changes: 1 addition & 1 deletion bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/utils.bash
# shellcheck source=lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

install_version "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
2 changes: 1 addition & 1 deletion bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -euo pipefail
current_script_path=${BASH_SOURCE[0]}
plugin_dir=$(dirname "$(dirname "$current_script_path")")

# shellcheck source=../lib/utils.bash
# shellcheck source=lib/utils.bash
source "${plugin_dir}/lib/utils.bash"

list_all_versions | sort_versions | xargs echo
53 changes: 44 additions & 9 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for kubergrunt.
GH_REPO="https://github.com/gruntwork-io/kubergrunt"
TOOL_NAME="kubergrunt"
TOOL_TEST="kubergrunt --version"
Expand Down Expand Up @@ -31,21 +30,27 @@ list_github_tags() {
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if kubergrunt has other means of determining installable versions.
list_github_tags
}

download_release() {
platform=$(get_platform)
arch=$(get_arch)
ext=""

case $platform in
windows) ext=".exe" ;;
esac

local version filename url
version="$1"
filename="$2"

# TODO: Adapt the release URL convention for kubergrunt
url="$GH_REPO/archive/v${version}.tar.gz"
filename="$2$ext"
url="$GH_REPO/releases/download/v${version}/${TOOL_NAME}_${platform}_${arch}${ext}"

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
chmod +x "$filename"
}

install_version() {
Expand All @@ -58,10 +63,9 @@ install_version() {
fi

(
mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path"
mkdir -p "$install_path/bin"
cp -R "$ASDF_DOWNLOAD_PATH/." "$install_path/bin"

# TODO: Asert kubergrunt executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"
test -x "$install_path/bin/$tool_cmd" || fail "Expected $install_path/bin/$tool_cmd to be executable."
Expand All @@ -72,3 +76,34 @@ install_version() {
fail "An error ocurred while installing $TOOL_NAME $version."
)
}

get_arch() {
local arch=""

case "$(uname -m)" in
x86_64 | amd64) arch="amd64" ;;
i686 | i386) arch="386" ;;
armv6l | armv7l) arch="arm" ;;
aarch64 | arm64) arch="arm64" ;;
*)
fail "Arch '$(uname -m)' not supported!"
;;
esac

echo -n $arch
}

get_platform() {
local platform=""

case "$(uname | tr '[:upper:]' '[:lower:]')" in
darwin) platform="darwin" ;;
linux) platform="linux" ;;
windows) platform="windows" ;;
*)
fail "Platform '$(uname -m)' not supported!"
;;
esac

echo -n $platform
}

0 comments on commit 0e7464b

Please sign in to comment.