전체 설치 스크립트 GitHub 릴리스 에셋 검증 및 폴백 다운로드 방어 로직 적용
This commit is contained in:
1 parent
5a67e7bbcf
commit
b41d2f68f3
21 files changed
+541
-190
No files matched your search
+33
-15
@@ -18,6 +18,7 @@ set -euo pipefail
|
||||
# ────────────────────────────────────────────
|
||||
REPO="ClementTsang/bottom"
|
||||
API_URL="https://api.github.com/repos/${REPO}/releases"
|
||||
FALLBACK_TAG="0.12.3"
|
||||
INSTALL_DIR="${HOME}/.local/bin"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
@@ -35,23 +36,26 @@ for cmd in curl uname; do
|
||||
command -v "$cmd" &>/dev/null || error "'$cmd' 명령어가 필요합니다."
|
||||
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_nightly_tag() {
|
||||
jq -r '[.[] | select(.prerelease==true and (.tag_name | startswith("nightly-")))] | .[0].tag_name'
|
||||
jq -r '[.[] | select((.assets | length) > 0 and ((.prerelease==true and (.tag_name | startswith("nightly-"))) or .prerelease==false))] | .[0].tag_name'
|
||||
}
|
||||
else
|
||||
command -v python3 &>/dev/null || error "'jq' or 'python3' is required."
|
||||
elif command -v python3 &>/dev/null; then
|
||||
_json_nightly_tag() {
|
||||
python3 -c "
|
||||
import sys, json
|
||||
data = json.load(sys.stdin)
|
||||
for r in data:
|
||||
if r.get('prerelease') and r.get('tag_name','').startswith('nightly-'):
|
||||
if r.get('assets') and ((r.get('prerelease') and r.get('tag_name','').startswith('nightly-')) or not r.get('prerelease')):
|
||||
print(r['tag_name'])
|
||||
break
|
||||
"
|
||||
}
|
||||
else
|
||||
_json_nightly_tag() {
|
||||
grep -oE '"tag_name":[[:space:]]*"[^"]+"' | head -1 | sed -E 's/.*"([^"]+)"$/\1/'
|
||||
}
|
||||
fi
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
@@ -131,15 +135,19 @@ detect_platform() {
|
||||
# Get latest Nightly release tag
|
||||
# ────────────────────────────────────────────
|
||||
get_latest_nightly_tag() {
|
||||
info "Fetching latest Nightly release from GitHub API..."
|
||||
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-bottom-sh" --connect-timeout 10 "${API_URL}" 2>/dev/null)" || true
|
||||
|
||||
local tag
|
||||
tag="$(echo "$releases" | _json_nightly_tag)"
|
||||
if [[ -n "$releases" ]]; then
|
||||
tag="$(echo "$releases" | _json_nightly_tag 2>/dev/null || true)"
|
||||
fi
|
||||
|
||||
[[ -z "$tag" || "$tag" == "null" ]] && error "Could not find Nightly release tag."
|
||||
if [[ -z "$tag" || "$tag" == "null" ]]; then
|
||||
warn "Could not fetch release tag from GitHub API. Using fallback tag: ${FALLBACK_TAG}"
|
||||
tag="${FALLBACK_TAG}"
|
||||
fi
|
||||
echo "$tag"
|
||||
}
|
||||
|
||||
@@ -161,6 +169,7 @@ download_and_install() {
|
||||
local url="$1"
|
||||
local ext="$2" # tar.gz | zip
|
||||
local is_windows="${3:-false}"
|
||||
local fallback_url="${4:-}"
|
||||
|
||||
local tmpdir
|
||||
tmpdir="$(mktemp -d)"
|
||||
@@ -170,8 +179,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
|
||||
|
||||
info "Extracting..."
|
||||
case "$ext" in
|
||||
@@ -239,10 +255,12 @@ main() {
|
||||
[[ "$triple" == *"windows"* ]] && is_windows="true"
|
||||
|
||||
tag="$(get_latest_nightly_tag)"
|
||||
info "Latest Nightly tag: $tag"
|
||||
info "Release tag: $tag"
|
||||
|
||||
url="$(build_download_url "$tag" "$triple" "$ext")"
|
||||
download_and_install "$url" "$ext" "$is_windows"
|
||||
local fallback_url
|
||||
fallback_url="$(build_download_url "$FALLBACK_TAG" "$triple" "$ext")"
|
||||
download_and_install "$url" "$ext" "$is_windows" "$fallback_url"
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in new issue
Block a user