전체 설치 스크립트 GitHub 릴리스 에셋 검증 및 폴백 다운로드 방어 로직 적용

This commit is contained in:
mcchae committed 2026-10-31 04:54:34 +09:00
1 parent 5a67e7bbcf
commit b41d2f68f3
21 files changed
+541 -190

No files matched your search

+31 -13
View File
@@ -16,6 +16,7 @@ set -euo pipefail
# ────────────────────────────────────────────
REPO="jesseduffield/lazydocker"
API_URL="https://api.github.com/repos/${REPO}/releases"
FALLBACK_TAG="v0.25.2"
INSTALL_DIR="${HOME}/.local/bin"
# ────────────────────────────────────────────
@@ -55,23 +56,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
# ────────────────────────────────────────────
@@ -124,13 +128,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-lazydocker-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"
}
@@ -153,6 +161,7 @@ build_download_url() {
download_and_install() {
local url="$1"
local ext="$2"
local fallback_url="${3:-}"
local tmpdir
tmpdir="$(mktemp -d)"
@@ -162,8 +171,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
@@ -248,7 +264,9 @@ main() {
info "Latest release: $tag"
url="$(build_download_url "$tag" "$platform" "$ext")"
download_and_install "$url" "$ext"
local fallback_url
fallback_url="$(build_download_url "$FALLBACK_TAG" "$platform" "$ext")"
download_and_install "$url" "$ext" "$fallback_url"
fi
fi