Update install.func
This commit is contained in:
parent
0670484b70
commit
c39afae957
@ -222,7 +222,7 @@ EOF
|
|||||||
|
|
||||||
get_gh_release() {
|
get_gh_release() {
|
||||||
local repo="$1"
|
local repo="$1"
|
||||||
local app="$2"
|
local app="${repo##*/}" # extract the app name from the repo URL
|
||||||
local api_url="https://api.github.com/repos/$repo/releases/latest"
|
local api_url="https://api.github.com/repos/$repo/releases/latest"
|
||||||
local header=()
|
local header=()
|
||||||
local attempt=0
|
local attempt=0
|
||||||
@ -231,7 +231,6 @@ get_gh_release() {
|
|||||||
|
|
||||||
[[ -n "$GITHUB_TOKEN" ]] && header=(-H "Authorization: token $GITHUB_TOKEN")
|
[[ -n "$GITHUB_TOKEN" ]] && header=(-H "Authorization: token $GITHUB_TOKEN")
|
||||||
|
|
||||||
# Retry loop
|
|
||||||
until [[ $attempt -ge $max_attempts ]]; do
|
until [[ $attempt -ge $max_attempts ]]; do
|
||||||
((attempt++))
|
((attempt++))
|
||||||
msg_info "[$attempt/$max_attempts] Fetching GitHub release for $repo"
|
msg_info "[$attempt/$max_attempts] Fetching GitHub release for $repo"
|
||||||
@ -241,13 +240,11 @@ get_gh_release() {
|
|||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for rate limit
|
|
||||||
if echo "$api_response" | grep -q "API rate limit exceeded"; then
|
if echo "$api_response" | grep -q "API rate limit exceeded"; then
|
||||||
msg_error "GitHub API rate limit exceeded. Set GITHUB_TOKEN to increase limit."
|
msg_error "GitHub API rate limit exceeded. Set GITHUB_TOKEN to increase limit."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if repo not found
|
|
||||||
if echo "$api_response" | jq -e '.message == "Not Found"' &>/dev/null; then
|
if echo "$api_response" | jq -e '.message == "Not Found"' &>/dev/null; then
|
||||||
msg_error "Repository not found: $repo"
|
msg_error "Repository not found: $repo"
|
||||||
return 1
|
return 1
|
||||||
@ -264,11 +261,11 @@ get_gh_release() {
|
|||||||
|
|
||||||
msg_ok "Found release: $tag for $repo"
|
msg_ok "Found release: $tag for $repo"
|
||||||
|
|
||||||
# Save version file if not exists
|
# save version to file
|
||||||
local version_file="/opt/${app}_version.txt"
|
local version_file="/opt/${app}_version.txt"
|
||||||
[[ ! -f "$version_file" ]] && echo "$tag" >"$version_file"
|
[[ ! -f "$version_file" ]] && echo "$tag" >"$version_file"
|
||||||
|
|
||||||
# Download tarball
|
# Download and extract
|
||||||
local temp_file
|
local temp_file
|
||||||
temp_file=$(mktemp)
|
temp_file=$(mktemp)
|
||||||
local tarball_url="https://github.com/$repo/archive/refs/tags/v$tag.tar.gz"
|
local tarball_url="https://github.com/$repo/archive/refs/tags/v$tag.tar.gz"
|
||||||
@ -280,8 +277,8 @@ get_gh_release() {
|
|||||||
|
|
||||||
mkdir -p "/opt/$app"
|
mkdir -p "/opt/$app"
|
||||||
tar -xzf "$temp_file" -C /opt
|
tar -xzf "$temp_file" -C /opt
|
||||||
mv /opt/"$(basename "$repo")-$tag"/* "/opt/$app/" 2>/dev/null
|
mv "/opt/${app}-${tag}"/* "/opt/$app/" 2>/dev/null || msg_warn "Could not move extracted files."
|
||||||
rm -rf "/opt/$(basename "$repo")-$tag"
|
rm -rf "/opt/${app}-${tag}"
|
||||||
|
|
||||||
echo "$tag"
|
echo "$tag"
|
||||||
return 0
|
return 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user