From b3cbf91a19e9b4fd2637491c391a7622a3492631 Mon Sep 17 00:00:00 2001 From: Reza <108628946+r3xcr4py@users.noreply.github.com> Date: Mon, 20 Feb 2023 06:35:26 +0330 Subject: [PATCH] Check GitHub API status code (#271) Co-authored-by: IceCodeNew <32576256+IceCodeNew@users.noreply.github.com> --- install-release.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/install-release.sh b/install-release.sh index 0313525..2164215 100644 --- a/install-release.sh +++ b/install-release.sh @@ -243,11 +243,17 @@ get_version() { fi # Get V2Ray release version number TMP_FILE="$(mktemp)" - if ! curl -x "${PROXY}" -sS -H "Accept: application/vnd.github.v3+json" -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then + if ! curl -x "${PROXY}" -sS -i -H "Accept: application/vnd.github.v3+json" -o "$TMP_FILE" 'https://api.github.com/repos/v2fly/v2ray-core/releases/latest'; then "rm" "$TMP_FILE" echo 'error: Failed to get release list, please check your network.' exit 1 fi + HTTP_STATUS_CODE=$(awk 'NR==1 {print $2}' "$TMP_FILE") + if [[ $HTTP_STATUS_CODE -lt 200 ]] || [[ $HTTP_STATUS_CODE -gt 299 ]]; then + "rm" "$TMP_FILE" + echo "error: Failed to get release list, GitHub API response code: $HTTP_STATUS_CODE" + exit 1 + fi RELEASE_LATEST="$(sed 'y/,/\n/' "$TMP_FILE" | grep 'tag_name' | awk -F '"' '{print $4}')" "rm" "$TMP_FILE" RELEASE_VERSION="v${RELEASE_LATEST#v}"