전체 설치 스크립트 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 -18
View File
@@ -17,6 +17,7 @@ set -euo pipefail
# ────────────────────────────────────────────
REPO="jesseduffield/lazygit"
API_URL="https://api.github.com/repos/${REPO}/releases"
FALLBACK_TAG="v0.61.1"
INSTALL_DIR="${HOME}/.local/bin"
# ────────────────────────────────────────────
@@ -48,11 +49,6 @@ ensure_brew() {
command -v brew &>/dev/null || error "Homebrew installation failed. Install it manually: https://brew.sh/"
success "Homebrew installed"
}
error() {
echo "[ERROR] $*" >&2
exit 1
}
success() { echo "[OK] $*" >&2; }
# ────────────────────────────────────────────
# Check for git (required by lazygit)
@@ -105,23 +101,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
# ────────────────────────────────────────────
@@ -205,13 +204,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-lazygit-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"
}
@@ -234,6 +237,7 @@ download_and_install() {
local url="$1"
local ext="$2"
local is_windows="${3:-false}"
local fallback_url="${4:-}"
local tmpdir
tmpdir="$(mktemp -d)"
@@ -243,8 +247,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
@@ -313,7 +324,9 @@ main() {
info "Latest release: $tag"
url="$(build_download_url "$tag" "$platform" "$ext")"
download_and_install "$url" "$ext" "$is_windows"
local fallback_url
fallback_url="$(build_download_url "$FALLBACK_TAG" "$platform" "$ext")"
download_and_install "$url" "$ext" "$is_windows" "$fallback_url"
}
main "$@"