Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update install script to support architectures better, and use GITHUB_TOKEN #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ get_platform() {
get_arch() {
local os=$(uname)
local arch=$(uname -m)
# On ARM Macs, uname -m returns "arm64", but in protoc releases this architecture is called "aarch_64"
if [[ "${os}" == "Darwin" && "${arch}" == "arm64" ]]; then
echo "aarch_64"
elif [[ "${os}" == "Linux" && "${arch}" == "aarch64" ]]; then
# protoc releases use "aarch_64" for arm64
if [[ "${arch}" == "arm64" ]] || [[ "${arch}" == "aarch64" ]]; then
echo "aarch_64"
elif [[ "${arch}" == "x86-64" ]] || [[ "${arch}" == "x64" ]] || [[ "${arch}" == "amd64" ]]; then
echo "x86_64"
else
echo "${arch}"
fi
Expand All @@ -45,8 +45,14 @@ install_protoc() {
local url="${base_url}/v${version}/protoc-${version}-$(get_platform)-$(get_arch).zip"
local download_path="${TMP_DIR}/protoc.zip"

cmd=("curl" "-fsSL")
github_token=${GITHUB_TOKEN:-${OAUTH_TOKEN}}
if [ -n "$github_token" ]; then
cmd+=("-H" "Authorization: token $github_token")
fi
cmd+=("${url}" "-o" "${download_path}")
echo "Downloading ${url}"
curl -fsSL "${url}" -o "${download_path}"
"${cmd[@]}"

unzip -qq "${download_path}" -d "${install_path}"
}
Expand Down
11 changes: 6 additions & 5 deletions bin/list-all
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env bash

releases_path=https://api.github.com/repos/protocolbuffers/protobuf/releases
cmd="curl -fSs"
if [ -n "$OAUTH_TOKEN" ]; then
cmd="$cmd -H 'Authorization: token $OAUTH_TOKEN'"
cmd=("curl" "-fSs")
github_token=${GITHUB_TOKEN:-${OAUTH_TOKEN}}
if [ -n "$github_token" ]; then
cmd+=("-H" "Authorization: token $github_token")
fi
cmd="$cmd $releases_path"
cmd+=("$releases_path")

# stolen from https://github.com/rbenv/ruby-build/pull/631/files#diff-fdcfb8a18714b33b07529b7d02b54f1dR942
function sort_versions() {
Expand All @@ -14,5 +15,5 @@ function sort_versions() {
}

# Fetch all tag names, and get only second column. Then remove all unnecesary characters.
versions=$(eval $cmd | grep -oE "tag_name\": *\".{1,15}\"," | sed 's/tag_name\": *\"v//;s/\",//' | sort_versions)
versions=$("${cmd[@]}" | grep -oE "tag_name\": *\".{1,15}\"," | sed 's/tag_name\": *\"v//;s/\",//' | sort_versions)
echo $versions