Skip to content

Commit

Permalink
feat(plugin): add installer flow
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoHsu committed May 25, 2021
1 parent 052c1e7 commit 5fad106
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
13 changes: 5 additions & 8 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ 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"
# proper extension and adapt extracting strategy.
release_file="$ASDF_DOWNLOAD_PATH/$TOOL_NAME"

# Download tar.gz file to the download directory
# Download 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"
# Change permission to run binary file
chmod +x "$release_file"
18 changes: 11 additions & 7 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

# TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for devspace.
# this is the correct GitHub homepage where releases can be downloaded for devspace.
GH_REPO="https://github.com/loft-sh/devspace"
TOOL_NAME="devspace"
TOOL_TEST="devspace --version"
Expand Down Expand Up @@ -31,7 +31,6 @@ list_github_tags() {
}

list_all_versions() {
# TODO: Adapt this. By default we simply list the tag names from GitHub releases.
# Change this function if devspace has other means of determining installable versions.
list_github_tags
}
Expand Down Expand Up @@ -70,9 +69,14 @@ download_release() {
local version filename url
version="$1"
filename="$2"
platform=$(get_platform)
arch=$(get_arch)

# TODO: Adapt the release URL convention for devspace
url="$GH_REPO/archive/v${version}.tar.gz"
# release URL convention for devspace
url="$GH_REPO/releases/download/v${version}/devspace-${platform}-${arch}"
if [ arch == "windows" ]; then
url="${url}.exe"
fi

echo "* Downloading $TOOL_NAME release $version..."
curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url"
Expand All @@ -88,10 +92,10 @@ install_version() {
fi

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

# TODO: Asert devspace executable exists.
# devspace 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 Down

0 comments on commit 5fad106

Please sign in to comment.