Skip to content

Commit

Permalink
feat: initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
pdemagny committed Jan 23, 2023
1 parent d0f5258 commit 0446ed1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

# Dependencies

**TODO: adapt this section**

- `bash`, `curl`, `tar`: generic POSIX utilities.
- `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x.
- `bash`, `curl`: generic POSIX utilities.

# Install

Expand Down
12 changes: 4 additions & 8 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ source "${plugin_dir}/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-$ASDF_INSTALL_VERSION"

# 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"
# Make sure the executable bit is set on the tool binary
chmod +x "$release_file"
24 changes: 16 additions & 8 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 serverless.
GH_REPO="https://github.com/serverless/serverless"
TOOL_NAME="serverless"
TOOL_TEST="serverless --version"
Expand All @@ -12,6 +11,16 @@ fail() {
exit 1
}

get_os() {
os=$(uname -s)
case $os in
Darwin) os="darwin" ;;
Linux) os="linux" ;;
*) fail "The os (${os}) is not supported by this installation script." ;;
esac
echo "$os"
}

curl_opts=(-fsSL)

# NOTE: You might want to remove this if serverless is not hosted on GitHub releases.
Expand All @@ -31,7 +40,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 serverless has other means of determining installable versions.
list_github_tags
}
Expand All @@ -41,8 +49,8 @@ download_release() {
version="$1"
filename="$2"

# TODO: Adapt the release URL convention for serverless
url="$GH_REPO/archive/v${version}.tar.gz"
os=$(get_os)
url="$GH_REPO/releases/download/v${version}/serverless-${os}-x64"

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

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

# TODO: Assert serverless executable exists.
local tool_cmd
tool_cmd="$(echo "$TOOL_TEST" | cut -d' ' -f1)"

mkdir -p "$install_path"
cp -r "$ASDF_DOWNLOAD_PATH/${tool_cmd}-${version}" "$install_path/$tool_cmd"

test -x "$install_path/$tool_cmd" || fail "Expected $install_path/$tool_cmd to be executable."

echo "$TOOL_NAME $version installation was successful!"
Expand Down

0 comments on commit 0446ed1

Please sign in to comment.