전체 설치 스크립트 GitHub 릴리스 에셋 검증 및 폴백 다운로드 방어 로직 적용
This commit is contained in:
1 parent
5a67e7bbcf
commit
b41d2f68f3
21 files changed
+541
-190
No files matched your search
+31
-13
@@ -16,6 +16,7 @@ set -euo pipefail
|
||||
# ────────────────────────────────────────────
|
||||
REPO="bcicen/ctop"
|
||||
API_URL="https://api.github.com/repos/${REPO}/releases"
|
||||
FALLBACK_TAG="v0.7.7"
|
||||
INSTALL_DIR="${HOME}/.local/bin"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
@@ -33,23 +34,26 @@ for cmd in curl uname; do
|
||||
command -v "$cmd" &>/dev/null || error "'$cmd' command is required."
|
||||
done
|
||||
|
||||
# Fallback: use python3 if jq is not available
|
||||
# Fallback: use python3 or grep if jq is not available
|
||||
if command -v jq &>/dev/null; then
|
||||
_json_latest_tag() {
|
||||
jq -r '[.[] | select(.prerelease==false)] | .[0].tag_name'
|
||||
jq -r '[.[] | select(.prerelease==false and ((.assets | length) > 0))] | .[0].tag_name'
|
||||
}
|
||||
else
|
||||
command -v python3 &>/dev/null || error "'jq' or 'python3' is required."
|
||||
elif command -v python3 &>/dev/null; then
|
||||
_json_latest_tag() {
|
||||
python3 -c "
|
||||
import sys, json
|
||||
data = json.load(sys.stdin)
|
||||
for r in data:
|
||||
if not r.get('prerelease'):
|
||||
if not r.get('prerelease') and r.get('assets'):
|
||||
print(r['tag_name'])
|
||||
break
|
||||
"
|
||||
}
|
||||
else
|
||||
_json_latest_tag() {
|
||||
grep -oE '"tag_name":[[:space:]]*"[^"]+"' | head -1 | sed -E 's/.*"([^"]+)"$/\1/'
|
||||
}
|
||||
fi
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
@@ -118,13 +122,17 @@ detect_platform() {
|
||||
get_latest_tag() {
|
||||
info "Fetching latest release from GitHub API..."
|
||||
|
||||
local releases
|
||||
releases="$(curl -fsSL "${API_URL}")" || error "Failed to call GitHub API."
|
||||
local releases="" tag=""
|
||||
releases="$(curl -fsSL -H "User-Agent: install-ctop-sh" --connect-timeout 10 "${API_URL}" 2>/dev/null)" || true
|
||||
|
||||
local tag
|
||||
tag="$(echo "$releases" | _json_latest_tag)"
|
||||
if [[ -n "$releases" ]]; then
|
||||
tag="$(echo "$releases" | _json_latest_tag 2>/dev/null || true)"
|
||||
fi
|
||||
|
||||
[[ -z "$tag" || "$tag" == "null" ]] && error "Could not find latest release tag."
|
||||
if [[ -z "$tag" || "$tag" == "null" ]]; then
|
||||
warn "Could not fetch latest release tag from GitHub API. Using fallback tag: ${FALLBACK_TAG}"
|
||||
tag="${FALLBACK_TAG}"
|
||||
fi
|
||||
echo "$tag"
|
||||
}
|
||||
|
||||
@@ -146,6 +154,7 @@ build_download_url() {
|
||||
# ────────────────────────────────────────────
|
||||
download_and_install() {
|
||||
local url="$1"
|
||||
local fallback_url="${2:-}"
|
||||
|
||||
local tmpdir
|
||||
tmpdir="$(mktemp -d)"
|
||||
@@ -155,8 +164,15 @@ download_and_install() {
|
||||
filename="${url##*/}"
|
||||
|
||||
info "Downloading: $url"
|
||||
curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$url" \
|
||||
|| error "Download failed: $url"
|
||||
if ! curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$url"; then
|
||||
if [[ -n "$fallback_url" && "$fallback_url" != "$url" ]]; then
|
||||
warn "Primary download failed. Retrying with fallback URL: $fallback_url"
|
||||
curl -fsSL --progress-bar -o "${tmpdir}/${filename}" "$fallback_url" \
|
||||
|| error "Download failed: $fallback_url"
|
||||
else
|
||||
error "Download failed: $url"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ctop provides raw binaries (not archives), so skip extraction
|
||||
local bin_src="${tmpdir}/${filename}"
|
||||
@@ -194,7 +210,9 @@ main() {
|
||||
info "Latest release: $tag"
|
||||
|
||||
url="$(build_download_url "$tag" "$platform")"
|
||||
download_and_install "$url"
|
||||
local fallback_url
|
||||
fallback_url="$(build_download_url "$FALLBACK_TAG" "$platform")"
|
||||
download_and_install "$url" "$fallback_url"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in new issue
Block a user