Update install.func

This commit is contained in:
CanbiZ 2025-04-07 10:38:33 +02:00
parent 8d65df0e2e
commit 5d64161e57

View File

@ -282,23 +282,24 @@ get_gh_release() {
local header=()
local attempt=0
local max_attempts=3
local api_response tag http_code
local tag
local tmpfile http_code
echo "🔍 Checking latest release for: $repo"
[[ -n "${GITHUB_TOKEN:-}" ]] && header=(-H "Authorization: token $GITHUB_TOKEN")
tmpfile=$(mktemp)
until [[ $attempt -ge $max_attempts ]]; do
((attempt++)) || true
$STD msg_info "[$attempt/$max_attempts] Fetching GitHub release for $repo...\n"
# Hole HTTP-Status explizit
api_response=$(curl -fsSL -w "%{http_code}" -o /tmp/gh_resp.json "${header[@]}" "$api_url")
http_code="${api_response:(-3)}"
http_code=$(curl -sSL -w "%{http_code}" -o "$tmpfile" "${header[@]}" "$api_url")
if [[ "$http_code" == "404" ]]; then
rm -f "$tmpfile"
msg_error "Repository $repo has no Release candidate (404)"
return 1
exit 1
fi
if [[ "$http_code" != "200" ]]; then
@ -307,19 +308,19 @@ get_gh_release() {
continue
fi
api_response=$(</tmp/gh_resp.json)
if echo "$api_response" | grep -q "API rate limit exceeded"; then
if grep -q "API rate limit exceeded" "$tmpfile"; then
rm -f "$tmpfile"
msg_error "GitHub API rate limit exceeded."
return 1
exit 1
fi
if echo "$api_response" | jq -e '.message == "Not Found"' &>/dev/null; then
if jq -e '.message == "Not Found"' "$tmpfile" &>/dev/null; then
rm -f "$tmpfile"
msg_error "Repository not found: $repo"
return 1
exit 1
fi
tag=$(echo "$api_response" | jq -r '.tag_name // .name // empty')
tag=$(jq -r '.tag_name // .name // empty' "$tmpfile")
[[ "$tag" =~ ^v[0-9] ]] && tag="${tag:1}"
if [[ -z "$tag" ]]; then
@ -328,10 +329,13 @@ get_gh_release() {
continue
fi
rm -f "$tmpfile"
$STD msg_ok "Found release: $tag for $repo"
echo "$tag"
return 0
done
rm -f "$tmpfile"
msg_error "Failed to fetch release for $repo after $max_attempts attempts."
exit 1
}