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

fix: adjust downloads to align with new package names introduced #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
63 changes: 40 additions & 23 deletions lib/utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ fail() {

curl_opts=(-fsSL)

# starting with 1.47.0, the archive name OS name and architecture changes
ARCHIVE_CHANGE_VERSION="1.47.0"

# NOTE: You might want to remove this if glab is not hosted on GitHub releases.
if [ -n "${GITHUB_API_TOKEN:-}" ]; then
curl_opts=("${curl_opts[@]}" -H "Authorization: token $GITHUB_API_TOKEN")
Expand Down Expand Up @@ -58,8 +61,8 @@ download_release() {
local version filename url os arch cutoff_version compare_result
version="$1"
filename="$2"
os=$(get_os)
arch=$(get_arch)
os=$(get_os "$version")
arch=$(get_arch "$version")
cutoff_version="1.23.0"

# download from github if prior to version $cutoff_version
Expand Down Expand Up @@ -100,30 +103,44 @@ install_version() {
}

get_os() {
local version="$1"
local os=$(uname)

case $os in
Darwin)
echo macOS
;;
*)
echo $os
;;
esac
local compare_result

compare_versions "$version" "$ARCHIVE_CHANGE_VERSION" || compare_result=$?
if [ $compare_result -gt 1 ]; then
case $os in
Darwin) echo darwin ;;
Linux) echo linux ;;
Windows) echo windows ;;
*) echo $os ;;
esac
else
case $os in
Darwin) echo macOS ;;
*) echo $os ;;
esac
fi
}

get_arch() {
local version="$1"
local arch=$(uname -m)

case $arch in
*86)
echo i386
;;
aarch64)
echo arm64
;;
*)
echo $arch
;;
esac
local compare_result

compare_versions "$version" "$ARCHIVE_CHANGE_VERSION" || compare_result=$?
if [ $compare_result -gt 1 ]; then
case $arch in
*86) echo 386 ;;
aarch64) echo arm64 ;;
x86_64) echo amd64 ;;
*) echo $arch ;;
esac
else
case $arch in
*86) echo i386 ;;
aarch64) echo arm64 ;;
*) echo $arch ;;
esac
fi
}