dua 설치 스크립트 최신 릴리스 태그 필터링 오류 수정

This commit is contained in:
mcchae committed 2026-10-31 04:28:07 +09:00
1 parent 8f2177b3b5
commit 5a67e7bbcf
4 files changed
+351 -194

No files matched your search

+98 -98
View File
@@ -18,6 +18,7 @@ set -euo pipefail
# ────────────────────────────────────────────
REPO="Byron/dua-cli"
API_URL="https://api.github.com/repos/${REPO}/releases"
FALLBACK_TAG="v2.46.0"
INSTALL_DIR="${HOME}/.local/bin"
# ────────────────────────────────────────────
@@ -71,22 +72,28 @@ for cmd in curl; do
done
# Fallback: use python3 if jq is not available
# Note: Byron/dua-cli publishes library tags like 'dua-core-v5.0.1' without binary assets.
# Filter only CLI releases whose tag starts with 'v' and contain downloadable assets.
if command -v jq &>/dev/null; then
_json_latest_tag() {
jq -r '[.[] | select(.prerelease==false)] | .[0].tag_name'
jq -r '[.[] | select(.prerelease==false and (.tag_name | startswith("v")) 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'):
print(r['tag_name'])
tag = r.get('tag_name', '')
if not r.get('prerelease') and tag.startswith('v') and r.get('assets'):
print(tag)
break
"
}
else
_json_latest_tag() {
grep -oE '"tag_name":[[:space:]]*"v[0-9]+\.[0-9]+\.[0-9]+"' | head -1 | sed -E 's/.*"v/v/; s/"$//'
}
fi
# ────────────────────────────────────────────
@@ -95,14 +102,79 @@ fi
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=""
releases="$(curl -fsSL -H "User-Agent: install-dua-sh" "${API_URL}" 2>/dev/null)" || true
local tag=""
if [[ -n "$releases" ]]; then
tag="$(echo "$releases" | _json_latest_tag 2>/dev/null || true)"
fi
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"
}
# ────────────────────────────────────────────
# Install binary from GitHub releases
# ────────────────────────────────────────────
install_from_github() {
local target=""
case "$OS" in
Darwin)
case "$ARCH" in
x86_64 | amd64) target="x86_64-apple-darwin" ;;
aarch64 | arm64) target="aarch64-apple-darwin" ;;
*) error "Unsupported macOS architecture: $ARCH" ;;
esac
;;
Linux)
case "$ARCH" in
x86_64 | amd64) target="x86_64-unknown-linux-musl" ;;
aarch64 | arm64) target="aarch64-unknown-linux-musl" ;;
armv7l | armhf) target="arm-unknown-linux-gnueabihf" ;;
riscv64) target="riscv64gc-unknown-linux-gnu" ;;
*) error "Unsupported Linux architecture: $ARCH" ;;
esac
;;
esac
local tag
tag="$(echo "$releases" | _json_latest_tag)"
tag="$(get_latest_tag)"
local filename="dua-${tag}-${target}.tar.gz"
local download_url="https://github.com/${REPO}/releases/download/${tag}/${filename}"
[[ -z "$tag" || "$tag" == "null" ]] && error "Could not find latest release tag."
echo "$tag"
info "Downloading: $download_url"
TMPDIR="$(mktemp -d)"
trap '[[ -d "${TMPDIR:-}" ]] && rm -rf "$TMPDIR"' EXIT
curl -fsSL --progress-bar -o "${TMPDIR}/${filename}" "$download_url" ||
error "Download failed: $download_url"
info "Extracting..."
tar -xzf "${TMPDIR}/${filename}" -C "$TMPDIR"
# Find the dua binary
local dua_bin
dua_bin="$(find "$TMPDIR" -maxdepth 3 -type f -name "dua" | head -1)"
[[ -z "$dua_bin" ]] && error "Cannot find 'dua' binary in the archive."
mkdir -p "$INSTALL_DIR"
cp "$dua_bin" "${INSTALL_DIR}/dua"
chmod +x "${INSTALL_DIR}/dua"
export PATH="${INSTALL_DIR}:${PATH}"
success "dua ${tag} installed to ${INSTALL_DIR}/dua"
# PATH instructions
if ! grep -qs "${INSTALL_DIR}" "${HOME}/.bashrc" "${HOME}/.zshrc" 2>/dev/null; then
if [[ ":$PATH:" != *":${INSTALL_DIR}:"* ]]; then
warn "'${INSTALL_DIR}' is not in your PATH."
fi
info "Ensure '${INSTALL_DIR}' is in your PATH (e.g. ~/.bashrc or ~/.zshrc):"
info " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
}
# ────────────────────────────────────────────
@@ -112,96 +184,24 @@ info "Installing dua (Disk Usage Analyzer)..."
if command -v dua &>/dev/null; then
CURRENT_VER="$(dua --version 2>/dev/null || echo 'unknown')"
info "dua is already installed ($CURRENT_VER). Skipping installation."
else
case "$OS" in
Darwin)
ensure_brew
brew install dua-cli
success "dua installed via Homebrew"
;;
Linux)
# Try package managers first
DUA_INSTALLED=false
if command -v apt-get &>/dev/null; then
info "Trying apt-get..."
sudo apt-get update -y 2>/dev/null || true
if sudo apt-get install -y dua-cli 2>/dev/null; then
DUA_INSTALLED=true
success "dua installed via apt-get"
fi
fi
if [ "$DUA_INSTALLED" = "false" ] && command -v dnf &>/dev/null; then
info "Trying dnf..."
if sudo dnf install -y dua-cli 2>/dev/null; then
DUA_INSTALLED=true
success "dua installed via dnf"
fi
fi
if [ "$DUA_INSTALLED" = "false" ] && command -v pacman &>/dev/null; then
info "Trying pacman..."
if sudo pacman -S --noconfirm dua-cli 2>/dev/null; then
DUA_INSTALLED=true
success "dua installed via pacman"
fi
fi
if [ "$DUA_INSTALLED" = "false" ] && command -v zypper &>/dev/null; then
info "Trying zypper..."
if sudo zypper -n install dua-cli 2>/dev/null; then
DUA_INSTALLED=true
success "dua installed via zypper"
fi
fi
# Fallback: download binary from GitHub releases
if [ "$DUA_INSTALLED" = "false" ]; then
info "No package manager had dua-cli. Downloading from GitHub releases..."
# Determine target
case "$ARCH" in
x86_64 | amd64) TARGET="x86_64-unknown-linux-musl" ;;
aarch64 | arm64) TARGET="aarch64-unknown-linux-musl" ;;
*) error "Unsupported Linux architecture: $ARCH" ;;
esac
TAG="$(get_latest_tag)"
FILENAME="dua-${TAG}-${TARGET}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${TAG}/${FILENAME}"
info "Downloading: $DOWNLOAD_URL"
TMPDIR="$(mktemp -d)"
trap '[[ -d "${TMPDIR:-}" ]] && rm -rf "$TMPDIR"' EXIT
curl -fsSL --progress-bar -o "${TMPDIR}/${FILENAME}" "$DOWNLOAD_URL" ||
error "Download failed: $DOWNLOAD_URL"
info "Extracting..."
tar -xzf "${TMPDIR}/${FILENAME}" -C "$TMPDIR"
# Find the dua binary
DUA_BIN="$(find "$TMPDIR" -maxdepth 3 -type f -name "dua" | head -1)"
[[ -z "$DUA_BIN" ]] && error "Cannot find 'dua' binary in the archive."
mkdir -p "$INSTALL_DIR"
cp "$DUA_BIN" "${INSTALL_DIR}/dua"
chmod +x "${INSTALL_DIR}/dua"
success "dua installed to ${INSTALL_DIR}/dua"
# PATH instructions
if ! echo ":${PATH}:" | grep -q ":${INSTALL_DIR}:"; then
warn "'${INSTALL_DIR}' is not in your PATH."
warn "Add this line to your ~/.bashrc or ~/.zshrc:"
warn " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
fi
;;
esac
info "dua is already installed ($CURRENT_VER). Updating/checking latest version..."
fi
case "$OS" in
Darwin)
if command -v brew &>/dev/null && brew install dua-cli 2>/dev/null; then
success "dua installed via Homebrew"
else
info "Installing dua from GitHub releases..."
install_from_github
fi
;;
Linux)
info "Installing dua from GitHub releases..."
install_from_github
;;
esac
# Verify dua is available
if command -v dua &>/dev/null; then
success "dua is available: $(command -v dua)"