gzip 오류
This commit is contained in:
1 parent
9b34662c51
commit
8e5f8b549b
1 file changed
+103
-22
+103
-22
@@ -5,11 +5,11 @@
|
||||
#
|
||||
# Supported platforms:
|
||||
# macOS : Apple Silicon (arm64), Intel (x86_64) — via Homebrew
|
||||
# Linux : x86_64, aarch64 — via package manager or curl installer
|
||||
# Linux : x86_64, aarch64 — via package manager or direct download
|
||||
#
|
||||
# Prerequisites:
|
||||
# - macOS: Homebrew (brew) — auto-installed if missing
|
||||
# - Linux: curl — for curl-based installer
|
||||
# - Linux: curl — for direct download fallback
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
@@ -17,6 +17,8 @@ set -euo pipefail
|
||||
# Constants
|
||||
# ────────────────────────────────────────────
|
||||
REPO="Byron/dua-cli"
|
||||
API_URL="https://api.github.com/repos/${REPO}/releases"
|
||||
INSTALL_DIR="${HOME}/.local/bin"
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Utility functions (all stderr output)
|
||||
@@ -49,7 +51,7 @@ ensure_brew() {
|
||||
}
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Detect OS
|
||||
# Detect OS / Architecture
|
||||
# ────────────────────────────────────────────
|
||||
OS="$(uname -s)"
|
||||
ARCH="$(uname -m)"
|
||||
@@ -68,6 +70,41 @@ for cmd in curl; do
|
||||
command -v "$cmd" &>/dev/null || error "'$cmd' command is required."
|
||||
done
|
||||
|
||||
# Fallback: use python3 if jq is not available
|
||||
if command -v jq &>/dev/null; then
|
||||
_json_latest_tag() {
|
||||
jq -r '[.[] | select(.prerelease==false)] | .[0].tag_name'
|
||||
}
|
||||
else
|
||||
command -v python3 &>/dev/null || error "'jq' or 'python3' is required."
|
||||
_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'])
|
||||
break
|
||||
"
|
||||
}
|
||||
fi
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Get latest stable release tag
|
||||
# ────────────────────────────────────────────
|
||||
get_latest_tag() {
|
||||
info "Fetching latest release from GitHub API..."
|
||||
|
||||
local releases
|
||||
releases="$(curl -fsSL "${API_URL}")" || error "Failed to call GitHub API."
|
||||
|
||||
local tag
|
||||
tag="$(echo "$releases" | _json_latest_tag)"
|
||||
|
||||
[[ -z "$tag" || "$tag" == "null" ]] && error "Could not find latest release tag."
|
||||
echo "$tag"
|
||||
}
|
||||
|
||||
# ────────────────────────────────────────────
|
||||
# Step 1: Install dua
|
||||
# ────────────────────────────────────────────
|
||||
@@ -84,39 +121,83 @@ else
|
||||
success "dua installed via Homebrew"
|
||||
;;
|
||||
Linux)
|
||||
# Try package managers first, fall back to curl installer
|
||||
# Try package managers first
|
||||
DUA_INSTALLED=false
|
||||
|
||||
if command -v apt-get &>/dev/null; then
|
||||
# dua-cli is available in newer Ubuntu/Debian repos
|
||||
info "Installing via apt-get..."
|
||||
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"
|
||||
else
|
||||
info "dua-cli not in apt repos. Using curl installer..."
|
||||
curl -LSfs https://raw.githubusercontent.com/Byron/dua-cli/master/ci/install.sh |
|
||||
sh -s -- --git Byron/dua-cli --crate dua --target x86_64-unknown-linux-musl
|
||||
success "dua installed via curl installer"
|
||||
fi
|
||||
elif command -v dnf &>/dev/null; then
|
||||
sudo dnf install -y dua-cli
|
||||
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"
|
||||
elif command -v pacman &>/dev/null; then
|
||||
sudo pacman -S --noconfirm dua-cli
|
||||
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"
|
||||
elif command -v zypper &>/dev/null; then
|
||||
sudo zypper -n install dua-cli
|
||||
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"
|
||||
else
|
||||
info "No supported package manager found. Using curl installer..."
|
||||
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
|
||||
curl -LSfs https://raw.githubusercontent.com/Byron/dua-cli/master/ci/install.sh |
|
||||
sh -s -- --git Byron/dua-cli --crate dua --target "$TARGET"
|
||||
success "dua installed via curl installer"
|
||||
|
||||
TAG="$(get_latest_tag)"
|
||||
VERSION="${TAG#v}"
|
||||
FILENAME="dua-${VERSION}-${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
|
||||
|
||||
Reference in new issue
Block a user