From d2ff1bd342b14a64434f4c9732f951cf40556a91 Mon Sep 17 00:00:00 2001 From: tramondi Date: Mon, 16 Sep 2024 17:37:56 +0700 Subject: [PATCH] fix: non-success http codes handling --- website/public/install.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/website/public/install.sh b/website/public/install.sh index e2b423e..5c328c3 100755 --- a/website/public/install.sh +++ b/website/public/install.sh @@ -6,10 +6,12 @@ # Define current arch ARCH=$(uname -m) OSTYPE=$(uname -s) -RELEASE=${1:-"latest"} +RELEASE_VERSION=${1:-"latest"} -if [ "$RELEASE" != "latest" ]; then - RELEASE="tag/v$RELEASE" +RELEASE_PATH="releases/latest" + +if [ "$RELEASE_VERSION" != "latest" ]; then + RELEASE_PATH="releases/tags/$RELEASE_VERSION" fi case "$ARCH" in @@ -41,11 +43,16 @@ esac BIN_FOLDER_NAME=bins-$GREP_ARCH_PATTERN-$GREP_OS_PATTERN GREP_PATTERN="$BIN_FOLDER_NAME.tar.gz" +RELEASE_ENDPOINT="https://api.github.com/repos/roamiiing/dploy/${RELEASE_PATH}" + +CURL_RESPONSE_CODE=$(curl -o /dev/null -s -w "%{http_code}" $RELEASE_ENDPOINT) + +if [ "$CURL_RESPONSE_CODE" != "200" ]; then + echo "Failed to fetch release, status code: $CURL_RESPONSE_CODE" + exit 1 +fi -DOWNLOAD_URL=$( - curl -s "https://api.github.com/repos/roamiiing/dploy/releases/${RELEASE}" \ - | grep -o "https.*$GREP_PATTERN" \ -) +DOWNLOAD_URL=$(curl -s $RELEASE_ENDPOINT | grep -o "https.*$GREP_PATTERN") echo "Downloading binary from $DOWNLOAD_URL"