add test
This commit is contained in:
parent
28591895f0
commit
8a9b8eaff5
@ -15,6 +15,7 @@ variables() {
|
||||
}
|
||||
|
||||
source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/api.func)
|
||||
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/github.func)
|
||||
|
||||
# This function sets various color variables using ANSI escape codes for formatting text in the terminal.
|
||||
color() {
|
||||
|
82
misc/github.func
Normal file
82
misc/github.func
Normal file
@ -0,0 +1,82 @@
|
||||
source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVED/main/misc/build.func)
|
||||
get_gh_release() {
|
||||
set -Eeuo pipefail
|
||||
trap 'echo -e "\n❌ [get_gh_release] Error on line $LINENO: $BASH_COMMAND"' ERR
|
||||
|
||||
local repo="$1"
|
||||
local app="${repo##*/}"
|
||||
local api_url="https://api.github.com/repos/$repo/releases/latest"
|
||||
local header=()
|
||||
local attempt=0
|
||||
local max_attempts=3
|
||||
local api_response tag
|
||||
|
||||
[[ -n "${GITHUB_TOKEN:-}" ]] && header=(-H "Authorization: token $GITHUB_TOKEN")
|
||||
|
||||
until [[ $attempt -ge $max_attempts ]]; do
|
||||
((attempt++))
|
||||
msg_info "[$attempt/$max_attempts] Fetching GitHub release for $repo"
|
||||
|
||||
if ! api_response=$(curl -fsSL "${header[@]}" "$api_url"); then
|
||||
msg_warn "Request failed for $repo, retrying..."
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
|
||||
if echo "$api_response" | grep -q "API rate limit exceeded"; then
|
||||
msg_error "GitHub API rate limit exceeded."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if echo "$api_response" | jq -e '.message == "Not Found"' &>/dev/null; then
|
||||
msg_error "Repository not found: $repo"
|
||||
return 1
|
||||
fi
|
||||
|
||||
tag=$(echo "$api_response" | jq -r '.tag_name // .name // empty')
|
||||
[[ "$tag" =~ ^v[0-9] ]] && tag="${tag:1}"
|
||||
|
||||
if [[ -z "$tag" ]]; then
|
||||
msg_error "Empty tag received, retrying..."
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
|
||||
msg_ok "Found release: $tag for $repo"
|
||||
|
||||
local version_file="/opt/${app}_version.txt"
|
||||
[[ ! -f "$version_file" ]] && echo "$tag" >"$version_file"
|
||||
|
||||
echo "$tag"
|
||||
return 0
|
||||
done
|
||||
|
||||
msg_error "Failed to fetch release for $repo after $max_attempts attempts."
|
||||
return 1
|
||||
}
|
||||
|
||||
fetch_and_extract_gh_release() {
|
||||
set -Eeuo pipefail
|
||||
trap 'echo -e "\n❌ [fetch_and_extract_gh_release] Error on line $LINENO: $BASH_COMMAND"' ERR
|
||||
|
||||
local repo="$1"
|
||||
local tag="$2"
|
||||
local app="${repo##*/}"
|
||||
|
||||
local temp_file
|
||||
temp_file=$(mktemp)
|
||||
local tarball_url="https://github.com/$repo/archive/refs/tags/v$tag.tar.gz"
|
||||
|
||||
msg_info "Downloading tarball for $app..."
|
||||
if ! curl -fsSL "$tarball_url" -o "$temp_file"; then
|
||||
msg_error "Failed to download tarball: $tarball_url"
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "/opt/$app"
|
||||
tar -xzf "$temp_file" -C /opt
|
||||
mv "/opt/${app}-${tag}"/* "/opt/$app/" 2>/dev/null || msg_warn "Could not move extracted files."
|
||||
rm -rf "/opt/${app}-${tag}"
|
||||
|
||||
msg_ok "Extracted $app to /opt/$app"
|
||||
}
|
@ -220,88 +220,6 @@ EOF
|
||||
msg_ok "Core dependencies installed"
|
||||
}
|
||||
|
||||
get_gh_release() {
|
||||
set -Eeuo pipefail
|
||||
trap 'echo -e "\n❌ [get_gh_release] Error on line $LINENO: $BASH_COMMAND"' ERR
|
||||
|
||||
local repo="$1"
|
||||
local app="${repo##*/}"
|
||||
local api_url="https://api.github.com/repos/$repo/releases/latest"
|
||||
local header=()
|
||||
local attempt=0
|
||||
local max_attempts=3
|
||||
local api_response tag
|
||||
|
||||
[[ -n "${GITHUB_TOKEN:-}" ]] && header=(-H "Authorization: token $GITHUB_TOKEN")
|
||||
|
||||
until [[ $attempt -ge $max_attempts ]]; do
|
||||
((attempt++))
|
||||
msg_info "[$attempt/$max_attempts] Fetching GitHub release for $repo"
|
||||
|
||||
if ! api_response=$(curl -fsSL "${header[@]}" "$api_url"); then
|
||||
msg_warn "Request failed for $repo, retrying..."
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
|
||||
if echo "$api_response" | grep -q "API rate limit exceeded"; then
|
||||
msg_error "GitHub API rate limit exceeded."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if echo "$api_response" | jq -e '.message == "Not Found"' &>/dev/null; then
|
||||
msg_error "Repository not found: $repo"
|
||||
return 1
|
||||
fi
|
||||
|
||||
tag=$(echo "$api_response" | jq -r '.tag_name // .name // empty')
|
||||
[[ "$tag" =~ ^v[0-9] ]] && tag="${tag:1}"
|
||||
|
||||
if [[ -z "$tag" ]]; then
|
||||
msg_warn "Empty tag received, retrying..."
|
||||
sleep 2
|
||||
continue
|
||||
fi
|
||||
|
||||
msg_ok "Found release: $tag for $repo"
|
||||
|
||||
local version_file="/opt/${app}_version.txt"
|
||||
[[ ! -f "$version_file" ]] && echo "$tag" >"$version_file"
|
||||
|
||||
echo "$tag"
|
||||
return 0
|
||||
done
|
||||
|
||||
msg_error "Failed to fetch release for $repo after $max_attempts attempts."
|
||||
return 1
|
||||
}
|
||||
|
||||
fetch_and_extract_gh_release() {
|
||||
set -Eeuo pipefail
|
||||
trap 'echo -e "\n❌ [fetch_and_extract_gh_release] Error on line $LINENO: $BASH_COMMAND"' ERR
|
||||
|
||||
local repo="$1"
|
||||
local tag="$2"
|
||||
local app="${repo##*/}"
|
||||
|
||||
local temp_file
|
||||
temp_file=$(mktemp)
|
||||
local tarball_url="https://github.com/$repo/archive/refs/tags/v$tag.tar.gz"
|
||||
|
||||
msg_info "Downloading tarball for $app..."
|
||||
if ! curl -fsSL "$tarball_url" -o "$temp_file"; then
|
||||
msg_error "Failed to download tarball: $tarball_url"
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "/opt/$app"
|
||||
tar -xzf "$temp_file" -C /opt
|
||||
mv "/opt/${app}-${tag}"/* "/opt/$app/" 2>/dev/null || msg_warn "Could not move extracted files."
|
||||
rm -rf "/opt/${app}-${tag}"
|
||||
|
||||
msg_ok "Extracted $app to /opt/$app"
|
||||
}
|
||||
|
||||
# This function modifies the message of the day (motd) and SSH settings
|
||||
motd_ssh() {
|
||||
grep -qxF "export TERM='xterm-256color'" /root/.bashrc || echo "export TERM='xterm-256color'" >>/root/.bashrc
|
||||
|
Loading…
x
Reference in New Issue
Block a user