Skip to content

Commit

Permalink
Update download script to latest version
Browse files Browse the repository at this point in the history
Use the same download script version as `dyff`.
  • Loading branch information
HeavyWombat committed Aug 2, 2024
1 parent 6bc0ce9 commit 448ab0e
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions scripts/download-latest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright © 2021 The Homeport Team
# Copyright © 2024 The Homeport Team
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -37,29 +37,31 @@ fi

if [[ $# -eq 0 ]]; then
# Find the latest version using the GitHub API
SELECTED_TAG="$(curl --silent --location https://api.github.com/repos/${ORG}/${REPO}/releases | jq --raw-output '.[0].tag_name')"
SELECTED_TAG="$(curl --silent --location "https://api.github.com/repos/${ORG}/${REPO}/releases" | jq --raw-output 'map(select((.assets | length) > 0)) | .[0].tag_name')"
else
# Use provided argument as tag to download
SELECTED_TAG="$1"
fi

# Find a suitable install location
if [[ -w /usr/local/bin ]]; then
TARGET_DIR=/usr/local/bin
for CANDIDATE in "$HOME/bin" "/usr/local/bin" "/usr/bin"; do
if [[ -w $CANDIDATE ]] && grep -q "$CANDIDATE" <<<"$PATH"; then
TARGET_DIR="$CANDIDATE"
break
fi
done

elif [[ -w "${HOME}/bin" ]] && grep -q -e "${HOME}/bin" -e '\~/bin' <<<"$PATH"; then
TARGET_DIR=${HOME}/bin

else
# Bail out in case no suitable location could be found
if [[ -z ${TARGET_DIR:-} ]]; then
echo -e "Unable to determine a writable install location. Make sure that you have write access to either \\033[1m/usr/local/bin\\033[0m or \\033[1m${HOME}/bin\\033[0m and that is in your PATH."
exit 1
fi

SYSTEM_UNAME="$(uname | tr '[:upper:]' '[:lower:]')"
SYSTEM_ARCH="$(uname -m | sed 's/x86_64/amd64/')"
SYSTEM_ARCH="$(uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')"

# Download and install
DOWNLOAD_URI="$(curl --silent --location "https://api.github.com/repos/${ORG}/${REPO}/releases/tags/${SELECTED_TAG}" | jq --raw-output ".assets[] | select( (.name | contains(\"${SYSTEM_UNAME}\")) and (.name | contains(\"${SYSTEM_ARCH}\")) ) | .browser_download_url")"
DOWNLOAD_URI="$(curl --silent --location "https://api.github.com/repos/${ORG}/${REPO}/releases/tags/${SELECTED_TAG}" | jq --raw-output "first(.assets[] | select( (.name | contains(\"${SYSTEM_UNAME}\")) and (.name | contains(\"${SYSTEM_ARCH}\")) ) | .browser_download_url)")"
if [[ -z ${DOWNLOAD_URI} ]]; then
echo -e "Unsupported operating system \\033[1m${SYSTEM_UNAME}\\033[0m or machine type \\033[1m${SYSTEM_ARCH}\\033[0m: Please check \\033[4;94mhttps://github.com/${ORG}/${REPO}/releases\\033[0m manually."
exit 1
Expand Down

0 comments on commit 448ab0e

Please sign in to comment.