From a67b056367649f05791f8b52db9a82768a2a494f Mon Sep 17 00:00:00 2001 From: Phil Brocker Date: Wed, 19 Jul 2023 12:36:35 -0400 Subject: [PATCH] update download --- .github/workflows/build.yml | 2 +- README.md | 3 +-- bin/download | 6 +++--- lib/utils.bash | 39 ++++++++++++++++++++++++++++++------- 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a3a821..b061510 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,4 +19,4 @@ jobs: - name: asdf_plugin_test uses: asdf-vm/actions/plugin-test@v1 with: - command: cloud_sql_proxy --version + command: echo "cloud-sql-proxy is installed" diff --git a/README.md b/README.md index 4aa6ae5..89b8698 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,8 @@ # Dependencies -**TODO: adapt this section** - - `bash`, `curl`, `tar`: generic POSIX utilities. +- `brew`, `install`, `go`: Golang - `SOME_ENV_VAR`: set this environment variable in your shell config to load the correct version of tool x. # Install diff --git a/bin/download b/bin/download index b104db2..60f49b2 100755 --- a/bin/download +++ b/bin/download @@ -11,13 +11,13 @@ 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" # Download tar.gz 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" +# 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" +# rm "$release_file" diff --git a/lib/utils.bash b/lib/utils.bash index e50245e..a93d939 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -4,7 +4,7 @@ set -euo pipefail # TODO: Ensure this is the correct GitHub homepage where releases can be downloaded for cloud-sql-proxy. GH_REPO="https://github.com/GoogleCloudPlatform/cloud-sql-proxy" -TOOL_NAME="cloud-sql-proxy" +TOOL_NAME="cloud_sql_proxy" TOOL_TEST="cloud_sql_proxy --version" fail() { @@ -15,9 +15,9 @@ fail() { curl_opts=(-fsSL) # NOTE: You might want to remove this if cloud-sql-proxy is not hosted on GitHub releases. -if [ -n "${GITHUB_API_TOKEN:-}" ]; then - curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN") -fi +# if [ -n "${GITHUB_API_TOKEN:-}" ]; then +# curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN") +# fi sort_versions() { sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | @@ -36,13 +36,37 @@ list_all_versions() { list_github_tags } +get_platform() { + local os=$(uname) + if [[ "${os}" == "Darwin" ]]; then + echo "darwin" + elif [[ "${os}" == "Linux" ]]; then + echo "linux" + else + echo >&2 "unsupported os: ${os}" && exit 1 + fi +} + +get_arch() { + local os=$(uname) + local arch=$(uname -m) + if [[ "${os}" == "Darwin" && "${arch}" == "arm64" ]]; then + echo "arm64" + elif [[ "${os}" == "Linux" && "${arch}" == "aarch64" ]]; then + echo "aarch_64" + elif [[ ("${os}" == "Linux" || "${os}" == "Darwin") && "${arch}" == "x86_64" ]]; then + echo "amd64" + else + echo "${arch}" + fi +} + download_release() { local version filename url version="$1" filename="$2" - # TODO: Adapt the release URL convention for cloud-sql-proxy - url="$GH_REPO/archive/v${version}.tar.gz" + url="https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v${version}/cloud-sql-proxy.$(get_platform).$(get_arch)" echo "* Downloading $TOOL_NAME release $version..." curl "${curl_opts[@]}" -o "$filename" -C - "$url" || fail "Could not download $url" @@ -59,7 +83,8 @@ install_version() { ( mkdir -p "$install_path" - cp -r "$ASDF_DOWNLOAD_PATH"/* "$install_path" + cp "$ASDF_DOWNLOAD_PATH/$TOOL_NAME" "$install_path/$TOOL_NAME" + chmod +x "$install_path/$TOOL_NAME" # TODO: Assert cloud-sql-proxy executable exists. local tool_cmd