Skip to content

Commit

Permalink
feat: working mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
jthegedus committed Mar 3, 2020
1 parent 188f027 commit dbf95e0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
- name: Shellcheck
run: shellcheck bin/*
run: shellcheck -x bin/* -P lib/
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

# asdf-gcloud ![Build](https://github.com/jthegedus/asdf-gcloud/workflows/Build/badge.svg) ![Lint](https://github.com/jthegedus/asdf-gcloud/workflows/Lint/badge.svg)

GCloud CLI plugin for [asdf](https://asdf-vm.com) version manager.
<a href="https://cloud.google.com/sdk/gcloud/reference" target="_blank" rel="noopener noreferrer">
<img src="images/logo_lockup_cloud_rgb.png" height="42" align="middle" />
</a>

[GCloud CLI](https://cloud.google.com/sdk/gcloud/reference) plugin for [asdf version manager](https://asdf-vm.com).

</div>

Expand Down Expand Up @@ -48,7 +52,7 @@ asdf global gcloud 282.0.0

# Contributing

Contributions of any kind welcome! See the [contributing guide](contributing.md).
Contributions of any kind welcome! See the [contributing guide](contributing.md) for a list of items to tackle.

[Thanks goes to these contributors](https://github.com/jthegedus/asdf-gcloud/graphs/contributors)!

Expand Down
52 changes: 13 additions & 39 deletions bin/install
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
#!/usr/bin/env bash

set -euo pipefail
os_support_error="🚨 Script only supports macOS and Ubuntu"

get_os_name() {
local os_name
case $(uname -s) in
Linux*)
os_name="linux"
;;
Darwin*)
os_name="darwin"
;;
*)
printf "%s\\n" "${os_support_error}"
exit 1
;;
esac
echo "${os_name}"
}

get_os_architecture() {
local arch
if [[ $(getconf LONG_BIT) == "64" ]]; then
arch="x86_64"
else
arch="x86"
fi
echo "${arch}"
}
# shellcheck source=../lib/utils.bash
source "$(dirname "$0")/../lib/utils.bash"

install_gcloud() {
local asdf_install_type="$1"
Expand All @@ -52,25 +27,24 @@ install_gcloud() {
gcs_object="google-cloud-sdk-${asdf_install_version}-${os_name}-${os_architecture}.tar.gz"

printf "⏬ downloading... %s\\n" "${gcs_object}"
if [[ -e "${gcs_object}" ]]; then
tmp_download_dir="$(mktemp -d -t 'asdf_gcloud_XXXXXX')"
trap 'rm -rf "${tmp_download_dir}"' EXIT
if [[ -e "${tmp_download_dir}/${gcs_object}" ]]; then
printf "✅ using cached download!\\n"
else
curl -X GET \
-o "./${gcs_object}" \
-o "${tmp_download_dir}/${gcs_object}" \
"https://storage.googleapis.com/storage/v1/b/${gcs_bucket_name}/o/${gcs_object}?alt=media"
printf "download successful!\\n"
printf "downloaded!\\n"
fi
# extract to asdf plugin location for the version
printf "📦 extracting...\\n"
tar -C "${asdf_install_path}" -zxf "${gcs_object}"
printf "✅ extract successful!\\n"
# install and add to PATH
tar -zxf "${tmp_download_dir}/${gcs_object}" -C "${asdf_install_path}" --strip-components=1
printf "✅ extracted!\\n"
printf "🚧 installing...\\n"
printf " ⚠️ ensure CLOUDSDK_PYTHON is set in you shell profile\\n"
echo "$PATH"
"${asdf_install_path}/google-cloud-sdk/install.sh" --usage-reporting=false --path-update=false --quiet
printf "✅ install successful!\\n"
# TODO: instruct on setup of shell completions
printf " ⚠️ CLOUDSDK_PYTHON must be set in you shell profile\\n"
"${asdf_install_path}/install.sh" --usage-reporting=false --path-update=false --quiet
printf "✅ gcloud %s installed!\\n" "${asdf_install_version}"
# TODO: instruct on setup of shell completions. This should be some form of ".asdf/installs/gcloud/$version/completions
}

# shellcheck disable=SC2153
Expand Down
Binary file added images/logo_lockup_cloud_rgb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions lib/utils.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -euo pipefail

os_support_error="🚨 Script only supports macOS and Ubuntu"

get_os_name() {
local os_name
case $(uname -s) in
Linux*)
os_name="linux"
;;
Darwin*)
os_name="darwin"
;;
*)
printf "%s\\n" "${os_support_error}"
exit 1
;;
esac
echo "${os_name}"
}

get_os_architecture() {
local arch
if [[ $(getconf LONG_BIT) == "64" ]]; then
arch="x86_64"
else
arch="x86"
fi
echo "${arch}"
}

0 comments on commit dbf95e0

Please sign in to comment.