From 3d567c74988215e3eb741a9968c95b067de2bc4a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= <raphael.beamonte@gmail.com>
Date: Tue, 12 Nov 2024 09:49:59 -0500
Subject: [PATCH 1/7] Update install script to support architectures better

---
 bin/install | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/bin/install b/bin/install
index 284e314..ffb8ec6 100755
--- a/bin/install
+++ b/bin/install
@@ -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"
+  if [[ "${arch}" == "x86-64" ]] || [[ "${arch}" == "x64" ]] || [[ "${arch}" == "amd64" ]]; then
+    echo "x86_64"
   else
     echo "${arch}"
   fi

From ed2a3c4485287be2fc133fb1e04f3149336ff8ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= <raphael.beamonte@gmail.com>
Date: Tue, 12 Nov 2024 09:56:19 -0500
Subject: [PATCH 2/7] Update install

---
 bin/install | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bin/install b/bin/install
index ffb8ec6..e77b622 100755
--- a/bin/install
+++ b/bin/install
@@ -26,7 +26,7 @@ get_arch() {
   # protoc releases use "aarch_64" for arm64
   if [[ "${arch}" == "arm64" ]] || [[ "${arch}" == "aarch64" ]]; then
     echo "aarch_64"
-  if [[ "${arch}" == "x86-64" ]] || [[ "${arch}" == "x64" ]] || [[ "${arch}" == "amd64" ]]; then
+  elif [[ "${arch}" == "x86-64" ]] || [[ "${arch}" == "x64" ]] || [[ "${arch}" == "amd64" ]]; then
     echo "x86_64"
   else
     echo "${arch}"

From 1aa263dca6b1e7bdb35197052b8a4f857959c3cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= <raphael.beamonte@gmail.com>
Date: Tue, 12 Nov 2024 10:02:56 -0500
Subject: [PATCH 3/7] Update list-all

---
 bin/list-all | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bin/list-all b/bin/list-all
index 87b403f..07d6f43 100755
--- a/bin/list-all
+++ b/bin/list-all
@@ -2,8 +2,8 @@
 
 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'"
+if [ -n "$GITHUB_TOKEN" ]; then
+  cmd="$cmd -H 'Authorization: token $GITHUB_TOKEN'"
 fi
 cmd="$cmd $releases_path"
 

From 6140ac03d279863e535993044601718b7aa7b34b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= <raphael.beamonte@gmail.com>
Date: Tue, 12 Nov 2024 10:04:23 -0500
Subject: [PATCH 4/7] Update install

---
 bin/install | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bin/install b/bin/install
index e77b622..25f8e8a 100755
--- a/bin/install
+++ b/bin/install
@@ -45,8 +45,12 @@ 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"
+  if [ -n "$GITHUB_TOKEN" ]; then
+    cmd="$cmd -H 'Authorization: token $GITHUB_TOKEN'"
+  fi
   echo "Downloading ${url}"
-  curl -fsSL "${url}" -o "${download_path}"
+  $cmd "${url}" -o "${download_path}"
 
   unzip -qq "${download_path}" -d "${install_path}"
 }

From 1e9002d82bc0c6e2b70a30242888a3d7138ef677 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= <raphael.beamonte@gmail.com>
Date: Tue, 12 Nov 2024 10:12:06 -0500
Subject: [PATCH 5/7] Update install

---
 bin/install | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/bin/install b/bin/install
index 25f8e8a..08a56ad 100755
--- a/bin/install
+++ b/bin/install
@@ -45,12 +45,13 @@ 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"
+  cmd=("curl" "-fsSL")
   if [ -n "$GITHUB_TOKEN" ]; then
-    cmd="$cmd -H 'Authorization: token $GITHUB_TOKEN'"
+    cmd+=("-H" "Authorization: token $GITHUB_TOKEN")
   fi
+  cmd+=("${url}" "-o" "${download_path}")
   echo "Downloading ${url}"
-  $cmd "${url}" -o "${download_path}"
+  "${cmd[@]}"
 
   unzip -qq "${download_path}" -d "${install_path}"
 }

From d56cf015613c470c3a67bfe7ad4ef213539842ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= <raphael.beamonte@gmail.com>
Date: Tue, 12 Nov 2024 10:19:02 -0500
Subject: [PATCH 6/7] Update list-all

---
 bin/list-all | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/bin/list-all b/bin/list-all
index 07d6f43..94aa402 100755
--- a/bin/list-all
+++ b/bin/list-all
@@ -1,11 +1,12 @@
 #!/usr/bin/env bash
 
 releases_path=https://api.github.com/repos/protocolbuffers/protobuf/releases
-cmd="curl -fSs"
-if [ -n "$GITHUB_TOKEN" ]; then
-  cmd="$cmd -H 'Authorization: token $GITHUB_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() {
@@ -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

From bb032241ff8c4c134abcebb1f063ea9d0e72cb9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Beamonte?= <raphael.beamonte@gmail.com>
Date: Tue, 12 Nov 2024 10:19:21 -0500
Subject: [PATCH 7/7] Update install

---
 bin/install | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/bin/install b/bin/install
index 08a56ad..fa9145b 100755
--- a/bin/install
+++ b/bin/install
@@ -46,8 +46,9 @@ install_protoc() {
   local download_path="${TMP_DIR}/protoc.zip"
 
   cmd=("curl" "-fsSL")
-  if [ -n "$GITHUB_TOKEN" ]; then
-    cmd+=("-H" "Authorization: token $GITHUB_TOKEN")
+  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}"