전체 설치 스크립트 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

+29 -12
View File
@@ -17,6 +17,7 @@ set -euo pipefail
# ────────────────────────────────────────────
REPO="tsl0922/ttyd"
API_URL="https://api.github.com/repos/${REPO}/releases/latest"
FALLBACK_TAG="1.7.7"
INSTALL_DIR="${HOME}/.local/bin"
# ────────────────────────────────────────────
@@ -53,20 +54,24 @@ for cmd in curl uname; do
command -v "$cmd" &>/dev/null || error "'$cmd' 명령어가 필요합니다."
done
# Fallback: jq가 없을 경우 python3를 사용해 JSON 정보 분석
# Fallback: jq가 없을 경우 python3 또는 grep을 사용해 JSON 정보 분석
if command -v jq &>/dev/null; then
_json_latest_tag() {
jq -r '.tag_name'
jq -r 'select((.assets | length) > 0) | .tag_name'
}
else
command -v python3 &>/dev/null || error "'jq' 또는 'python3' 명령어가 설치되어 있어야 합니다."
elif command -v python3 &>/dev/null; then
_json_latest_tag() {
python3 -c "
import sys, json
data = json.load(sys.stdin)
print(data.get('tag_name', ''))
if data.get('assets'):
print(data.get('tag_name', ''))
"
}
else
_json_latest_tag() {
grep -oE '"tag_name":[[:space:]]*"[^"]+"' | head -1 | sed -E 's/.*"([^"]+)"$/\1/'
}
fi
# ────────────────────────────────────────────
@@ -121,12 +126,15 @@ detect_platform() {
get_latest_release_tag() {
info "GitHub API를 통해 ttyd 최신 릴리스 버전을 가져오는 중..."
local release_json tag
release_json="$(curl -fsSL "${API_URL}")" || error "GitHub API 호출에 실패했습니다."
local release_json="" tag=""
release_json="$(curl -fsSL -H "User-Agent: install-ttyd-sh" --connect-timeout 10 "${API_URL}" 2>/dev/null)" || true
tag="$(echo "$release_json" | _json_latest_tag)"
if [[ -n "$release_json" ]]; then
tag="$(echo "$release_json" | _json_latest_tag 2>/dev/null || true)"
fi
if [[ -z "$tag" || "$tag" == "null" ]]; then
error "최신 릴리스 태그를 확인하는 데 실패했습니다."
warn "최신 릴리스 태그 조회 실패. 검증된 폴백 버전(${FALLBACK_TAG})을 사용합니다."
tag="${FALLBACK_TAG}"
fi
echo "$tag"
}
@@ -156,11 +164,12 @@ main() {
fi
# 2) Linux / Windows Bash (바이너리 직접 설치 방식)
local tag download_url
local tag download_url fallback_url
tag="$(get_latest_release_tag)"
info "최신 버전 감지: $tag"
download_url="https://github.com/tsl0922/ttyd/releases/download/${tag}/${asset_name}"
fallback_url="https://github.com/tsl0922/ttyd/releases/download/${FALLBACK_TAG}/${asset_name}"
# 설치 디렉토리 생성
mkdir -p "$INSTALL_DIR"
@@ -176,8 +185,16 @@ main() {
info "바이너리 다운로드 중: $download_url"
if ! curl -fsSL "$download_url" -o "$tmp_file"; then
rm -rf "$tmp_dir"
error "바이너리 다운로드에 실패했습니다. URL: $download_url"
if [[ "$tag" != "$FALLBACK_TAG" ]]; then
warn "다운로드 실패. 폴백 버전(${FALLBACK_TAG})으로 재시도합니다: $fallback_url"
if ! curl -fsSL "$fallback_url" -o "$tmp_file"; then
rm -rf "$tmp_dir"
error "바이너리 다운로드에 실패했습니다. URL: $fallback_url"
fi
else
rm -rf "$tmp_dir"
error "바이너리 다운로드에 실패했습니다. URL: $download_url"
fi
fi
info "설치 경로로 복사 중: $dest_file"