Skip to content

Commit

Permalink
fix: convert indent to tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
jthegedus committed Jun 3, 2020
1 parent 81122e2 commit 811b4d4
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 135 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# asdf-gcloud ![Build](https://github.com/jthegedus/asdf-gcloud/workflows/Build/badge.svg) ![Lint](https://github.com/jthegedus/asdf-gcloud/workflows/Lint/badge.svg)

<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" />
<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) allowing you to pin `gcloud` versions for each GCP project.
Expand Down
28 changes: 14 additions & 14 deletions bin/download
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ source "$(dirname "$0")/../lib/helpers.bash"
source "$(dirname "$0")/../lib/utils.bash"

download() {
local gcs_bucket_name="cloud-sdk-release"
local gcs_object
local status_code
gcs_object="$(construct_gcs_object "${ASDF_INSTALL_VERSION}" "$(get_os_name)" "$(get_os_architecture)")"
local gcs_bucket_name="cloud-sdk-release"
local gcs_object
local status_code
gcs_object="$(construct_gcs_object "${ASDF_INSTALL_VERSION}" "$(get_os_name)" "$(get_os_architecture)")"

log_info "⏬ downloading ${gcs_object}"
status_code=$(curl -X GET \
--write-out "%{http_code}" \
--progress-bar \
-Lo "${ASDF_DOWNLOAD_PATH}/${gcs_object}" \
"https://storage.googleapis.com/storage/v1/b/${gcs_bucket_name}/o/${gcs_object}?alt=media")
log_info "⏬ downloading ${gcs_object}"
status_code=$(curl -X GET \
--write-out "%{http_code}" \
--progress-bar \
-Lo "${ASDF_DOWNLOAD_PATH}/${gcs_object}" \
"https://storage.googleapis.com/storage/v1/b/${gcs_bucket_name}/o/${gcs_object}?alt=media")

if [[ ${status_code} -eq 404 ]]; then
log_failure_and_exit "gcloud not found for version ${ASDF_INSTALL_VERSION}. Full version required, not just major version numbers."
fi
log_success "downloaded!"
if [[ ${status_code} -eq 404 ]]; then
log_failure_and_exit "gcloud not found for version ${ASDF_INSTALL_VERSION}. Full version required, not just major version numbers."
fi
log_success "downloaded!"
}

download
8 changes: 4 additions & 4 deletions bin/exec-env
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ set -euo pipefail
source "$(dirname "$0")/../lib/utils.bash"

if [[ ! -x "$(command -v python)" ]]; then
log_failure_and_exit "Python not found and is required for gcloud. Might I suggest https://github.com/danhper/asdf-python"
log_failure_and_exit "Python not found and is required for gcloud. Might I suggest https://github.com/danhper/asdf-python"
fi

# credit: https://unix.stackexchange.com/a/56846/397902
if [ -z "${CLOUDSDK_PYTHON:+1}" ]; then
# undefined or defined and empty
python_sdk="$(command -v python)"
export CLOUDSDK_PYTHON=${python_sdk}
# undefined or defined and empty
python_sdk="$(command -v python)"
export CLOUDSDK_PYTHON=${python_sdk}
fi
44 changes: 22 additions & 22 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@ source "$(dirname "$0")/../lib/helpers.bash"
source "$(dirname "$0")/../lib/utils.bash"

install_gcloud() {
tmp_download_dir=$(mktemp -d -t 'asdf_gcloud_XXXXXX')
trap 'rm -rf "${tmp_download_dir}"' EXIT
tmp_download_dir=$(mktemp -d -t 'asdf_gcloud_XXXXXX')
trap 'rm -rf "${tmp_download_dir}"' EXIT

gcs_object="$(construct_gcs_object "${ASDF_INSTALL_VERSION}" "$(get_os_name)" "$(get_os_architecture)")"
gcs_object="$(construct_gcs_object "${ASDF_INSTALL_VERSION}" "$(get_os_name)" "$(get_os_architecture)")"

# if not asdf version with asdf_download_path then call download script here
if [ -z "${ASDF_DOWNLOAD_PATH:-}" ]; then
tmp_download_dir=$(mktemp -d -t 'asdf_gcloud_XXXXXX')
trap 'rm -rf "${tmp_download_dir}"' EXIT
log_info "ℹ️ run download script for older version of asdf"
export ASDF_DOWNLOAD_PATH="${tmp_download_dir}"
# if not asdf version with asdf_download_path then call download script here
if [ -z "${ASDF_DOWNLOAD_PATH:-}" ]; then
tmp_download_dir=$(mktemp -d -t 'asdf_gcloud_XXXXXX')
trap 'rm -rf "${tmp_download_dir}"' EXIT
log_info "ℹ️ run download script for older version of asdf"
export ASDF_DOWNLOAD_PATH="${tmp_download_dir}"

# download
bash "$(dirname "$0")/download"
fi
# download
bash "$(dirname "$0")/download"
fi

log_info "📦 extracting..."
tar -zxf "${ASDF_DOWNLOAD_PATH}/${gcs_object}" -C "${ASDF_INSTALL_PATH}" --strip-components=1
log_success "extracted!"
log_info "📦 extracting..."
tar -zxf "${ASDF_DOWNLOAD_PATH}/${gcs_object}" -C "${ASDF_INSTALL_PATH}" --strip-components=1
log_success "extracted!"

log_info "🚧 installing..."
"${ASDF_INSTALL_PATH}/install.sh" --usage-reporting=false --path-update=false --quiet
# test executable
test -x "${ASDF_INSTALL_PATH}/bin/gcloud" || log_failure_and_exit "Expected ${ASDF_INSTALL_PATH}/bin/gcloud to be executable."
log_success "gcloud ${ASDF_INSTALL_VERSION} installed!"
log_info "🚧 installing..."
"${ASDF_INSTALL_PATH}/install.sh" --usage-reporting=false --path-update=false --quiet
# test executable
test -x "${ASDF_INSTALL_PATH}/bin/gcloud" || log_failure_and_exit "Expected ${ASDF_INSTALL_PATH}/bin/gcloud to be executable."
log_success "gcloud ${ASDF_INSTALL_VERSION} installed!"

# TODO: instruct on setup of shell completions. This should be some form of ".asdf/installs/gcloud/$version/completions
# TODO: instruct on setup of shell completions. This should be some form of ".asdf/installs/gcloud/$version/completions
}

if [ "${ASDF_INSTALL_TYPE}" != "version" ]; then
log_failure_and_exit "Please provide the gcloud version number you wish to install. See \`asdf list all gcloud\`"
log_failure_and_exit "Please provide the gcloud version number you wish to install. See \`asdf list all gcloud\`"
fi

check_dependencies "$(dirname "$0")/../lib/dependencies.txt" "failure"
Expand Down
30 changes: 15 additions & 15 deletions bin/list-all
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ gcs_object_prefix="google-cloud-sdk"
gcs_object_fields="kind,nextPageToken,items(name)"

function fetch() {
curl --silent GET "https://storage.googleapis.com/storage/v1/b/${gcs_bucket_name}/o?pageToken=${1}&prefix=${gcs_object_prefix}&fields=${gcs_object_fields}"
curl --silent GET "https://storage.googleapis.com/storage/v1/b/${gcs_bucket_name}/o?pageToken=${1}&prefix=${gcs_object_prefix}&fields=${gcs_object_fields}"
}

function list_all() {
local more=true
local nextPageToken=""
local list=""
while "${more}"; do
res=$(fetch "${nextPageToken}")
if [[ "${res}" =~ nextPageToken\"\:\ \"([a-zA-Z0-9]+)\" ]]; then
nextPageToken="${BASH_REMATCH[1]}"
else
more=false
fi
additions=$(echo "${res}" | grep -Eo "name.*google-cloud-sdk-[0-9]+\.[0-9]+\.[0-9]+-(linux)-x86_64" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
list="${list}${additions}"
done
echo "${list}"
local more=true
local nextPageToken=""
local list=""
while "${more}"; do
res=$(fetch "${nextPageToken}")
if [[ "${res}" =~ nextPageToken\"\:\ \"([a-zA-Z0-9]+)\" ]]; then
nextPageToken="${BASH_REMATCH[1]}"
else
more=false
fi
additions=$(echo "${res}" | grep -Eo "name.*google-cloud-sdk-[0-9]+\.[0-9]+\.[0-9]+-(linux)-x86_64" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")
list="${list}${additions}"
done
echo "${list}"
}

list_all | sort -V | tr '\n' ' '
54 changes: 27 additions & 27 deletions bin/post-install
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@ set -euo pipefail
source "$(dirname "$0")/../lib/utils.bash"

function default_cloud_sdk_components_config_path() {
local default_components_filename=".default-cloud-sdk-components"
local default_config_dir="$HOME/.config/gcloud"

local asdf_config_path="${ASDF_CONFIG_FILE:-"$HOME/.asdfrc"}"
local asdf_config_dir
asdf_config_dir=$(dirname "$asdf_config_path")

if [ -f "${default_config_dir}/${default_components_filename}" ]; then
echo "${default_config_dir}/${default_components_filename}"
elif [ -f "${asdf_config_dir}/${default_components_filename}" ]; then
echo "${asdf_config_dir}/${default_components_filename}"
else
echo "${HOME}/${default_components_filename}"
fi
local default_components_filename=".default-cloud-sdk-components"
local default_config_dir="$HOME/.config/gcloud"

local asdf_config_path="${ASDF_CONFIG_FILE:-"$HOME/.asdfrc"}"
local asdf_config_dir
asdf_config_dir=$(dirname "$asdf_config_path")

if [ -f "${default_config_dir}/${default_components_filename}" ]; then
echo "${default_config_dir}/${default_components_filename}"
elif [ -f "${asdf_config_dir}/${default_components_filename}" ]; then
echo "${asdf_config_dir}/${default_components_filename}"
else
echo "${HOME}/${default_components_filename}"
fi
}

function install_default_cloud_sdk_components() {
local default_cloud_sdk_components
default_cloud_sdk_components="$(default_cloud_sdk_components_config_path)"
local gcloud="${ASDF_INSTALL_PATH}/bin/gcloud"
declare -a component_list=()
local default_cloud_sdk_components
default_cloud_sdk_components="$(default_cloud_sdk_components_config_path)"
local gcloud="${ASDF_INSTALL_PATH}/bin/gcloud"
declare -a component_list=()

if [ ! -f "$default_cloud_sdk_components" ]; then
return
fi
if [ ! -f "$default_cloud_sdk_components" ]; then
return
fi

log_info "ℹ️ Installing SDK Components from ${default_cloud_sdk_components}"
log_info "ℹ️ Installing SDK Components from ${default_cloud_sdk_components}"

while IFS="" read -r p || [ -n "${p}" ]; do
component_list+=("${p}")
done <"${default_cloud_sdk_components}"
while IFS="" read -r p || [ -n "${p}" ]; do
component_list+=("${p}")
done <"${default_cloud_sdk_components}"

$gcloud --quiet components install "${component_list[@]}"
$gcloud --quiet components install "${component_list[@]}"

log_success "Cloud SDK Components installed"
log_success "Cloud SDK Components installed"
}

install_default_cloud_sdk_components
8 changes: 4 additions & 4 deletions lib/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
set -euo pipefail

function construct_gcs_object() {
local install_version="${1}"
local os_name="${2}"
local os_architecture="${3}"
local install_version="${1}"
local os_name="${2}"
local os_architecture="${3}"

echo "google-cloud-sdk-${install_version}-${os_name}-${os_architecture}.tar.gz"
echo "google-cloud-sdk-${install_version}-${os_name}-${os_architecture}.tar.gz"
}
96 changes: 48 additions & 48 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,79 @@ set -euo pipefail

# START Logging
function log_failure_and_exit() {
printf "🚨 %s\\n" "${@}"
exit 1
printf "🚨 %s\\n" "${@}"
exit 1
}

function log_failure() {
printf "🚨 %s\\n" "${@}"
printf "🚨 %s\\n" "${@}"
}

function log_info() {
printf "%s\\n" "${@}"
printf "%s\\n" "${@}"
}

function log_success() {
printf "✅ %s\\n" "${@}"
printf "✅ %s\\n" "${@}"
}

function log_warning() {
printf "⚠️ %s\\n" "${@}"
printf "⚠️ %s\\n" "${@}"
}
# END Logging

function check_dependencies() {
local dependencies_file="${1}"
local failure_type="${2}" # should be "warning" or "failure"
declare -a missing_dependencies=()
local dependencies_file="${1}"
local failure_type="${2}" # should be "warning" or "failure"
declare -a missing_dependencies=()

# loop over file of line separated list of dependencies required by this tool
while IFS="" read -r p || [ -n "${p}" ]; do
if [ ! "$(command -v "${p}")" ]; then
missing_dependencies+=("${p}")
fi
done <"${dependencies_file}"
# loop over file of line separated list of dependencies required by this tool
while IFS="" read -r p || [ -n "${p}" ]; do
if [ ! "$(command -v "${p}")" ]; then
missing_dependencies+=("${p}")
fi
done <"${dependencies_file}"

if [ "${#missing_dependencies[@]}" -ne 0 ]; then
if [ "${failure_type}" == "warning" ]; then
log_warning "Missing dependencies! These are hard requirements to install $(get_plugin_name)."
log_warning "${missing_dependencies[@]}"
log_info "You should install the listed dependencies before continuing."
else
log_failure "Missing dependencies! These are hard requirements to install $(get_plugin_name)."
log_failure_and_exit "${missing_dependencies[@]}"
fi
else
log_success "All dependencies found on system!"
fi
if [ "${#missing_dependencies[@]}" -ne 0 ]; then
if [ "${failure_type}" == "warning" ]; then
log_warning "Missing dependencies! These are hard requirements to install $(get_plugin_name)."
log_warning "${missing_dependencies[@]}"
log_info "You should install the listed dependencies before continuing."
else
log_failure "Missing dependencies! These are hard requirements to install $(get_plugin_name)."
log_failure_and_exit "${missing_dependencies[@]}"
fi
else
log_success "All dependencies found on system!"
fi
}

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

function get_os_name() {
local os_name
case $(uname -s) in
Linux*)
os_name="linux"
;;
Darwin*)
os_name="darwin"
;;
*)
log_failure_and_exit "Script only supports macOS and Ubuntu"
;;
esac
echo "${os_name}"
local os_name
case $(uname -s) in
Linux*)
os_name="linux"
;;
Darwin*)
os_name="darwin"
;;
*)
log_failure_and_exit "Script only supports macOS and Ubuntu"
;;
esac
echo "${os_name}"
}

get_plugin_name() {
basename "$(dirname "$(dirname "$0")")"
basename "$(dirname "$(dirname "$0")")"
}

0 comments on commit 811b4d4

Please sign in to comment.