mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 00:21:04 +00:00
feat: Improve install script with error handling and robustness
- Add error checking for failed downloads/API requests using set -e - Use proper GitHub API parsing instead of fragile sed extraction - Better architecture/OS detection and mapping - Add user feedback messages and progress reporting - Ensure target directory creation before installation - Verify successful extraction before installation This enhances reliability, handles edge cases better, and improves the user experience during installation/updates.
This commit is contained in:
parent
bedde4a037
commit
313fbef49e
1 changed files with 39 additions and 15 deletions
|
|
@ -1,24 +1,48 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# allow specifying different destination directory
|
set -e # Exit on any error
|
||||||
|
|
||||||
|
# Allow custom installation directory
|
||||||
DIR="${DIR:-"$HOME/.local/bin"}"
|
DIR="${DIR:-"$HOME/.local/bin"}"
|
||||||
|
|
||||||
# map different architecture variations to the available binaries
|
# Map architecture to GitHub's binary naming convention
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
case $ARCH in
|
case "$ARCH" in
|
||||||
i386|i686) ARCH=x86 ;;
|
i386|i686) ARCH="x86" ;;
|
||||||
armv6*) ARCH=armv6 ;;
|
armv6*) ARCH="armv6" ;;
|
||||||
armv7*) ARCH=armv7 ;;
|
armv7*) ARCH="armv7" ;;
|
||||||
aarch64*) ARCH=arm64 ;;
|
aarch64*) ARCH="arm64" ;;
|
||||||
|
x86_64) ARCH="x86_64" ;; # Explicitly handle common 64-bit
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# prepare the download URL
|
OS=$(uname -s | tr '[:upper:]' '[:lower:]') # Ensure lowercase (e.g., "darwin")
|
||||||
GITHUB_LATEST_VERSION=$(curl -L -s -H 'Accept: application/json' https://github.com/jesseduffield/lazydocker/releases/latest | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
|
|
||||||
GITHUB_FILE="lazydocker_${GITHUB_LATEST_VERSION//v/}_$(uname -s)_${ARCH}.tar.gz"
|
# Fetch latest version using GitHub API
|
||||||
|
GITHUB_LATEST_VERSION=$(curl -sfL https://api.github.com/repos/jesseduffield/lazydocker/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')
|
||||||
|
if [ -z "$GITHUB_LATEST_VERSION" ]; then
|
||||||
|
echo "Failed to fetch latest version."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build URL and download
|
||||||
|
GITHUB_FILE="lazydocker_${GITHUB_LATEST_VERSION//v/}_${OS}_${ARCH}.tar.gz"
|
||||||
GITHUB_URL="https://github.com/jesseduffield/lazydocker/releases/download/${GITHUB_LATEST_VERSION}/${GITHUB_FILE}"
|
GITHUB_URL="https://github.com/jesseduffield/lazydocker/releases/download/${GITHUB_LATEST_VERSION}/${GITHUB_FILE}"
|
||||||
|
|
||||||
# install/update the local binary
|
echo "Downloading lazydocker $GITHUB_LATEST_VERSION for ${OS}_${ARCH}..."
|
||||||
curl -L -o lazydocker.tar.gz $GITHUB_URL
|
if ! curl -sfL -o lazydocker.tar.gz "$GITHUB_URL"; then
|
||||||
tar xzvf lazydocker.tar.gz lazydocker
|
echo "Download failed. Check your OS/architecture or network connection."
|
||||||
install -Dm 755 lazydocker -t "$DIR"
|
exit 1
|
||||||
rm lazydocker lazydocker.tar.gz
|
fi
|
||||||
|
|
||||||
|
# Extract and install
|
||||||
|
tar -xzf lazydocker.tar.gz lazydocker
|
||||||
|
if [ ! -f "lazydocker" ]; then
|
||||||
|
echo "Extraction failed. Corrupted download?"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$DIR" # Ensure directory exists
|
||||||
|
install -v -m 755 lazydocker -t "$DIR"
|
||||||
|
rm -f lazydocker lazydocker.tar.gz
|
||||||
|
|
||||||
|
echo "Installed lazydocker to $DIR"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue