chore: improve just installation with binary fallback and better error handling

This commit is contained in:
Jose B
2025-12-04 13:39:33 -05:00
parent 066d457d41
commit 177d0d9f64

103
setup.sh
View File

@@ -170,28 +170,117 @@ check_dependencies() {
}
install_just() {
# Try package managers first
if [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew &> /dev/null; then
log_info "Installing just via Homebrew..."
brew install just
if brew install just; then
log_success "just installed"
return 0
else
log_error "Homebrew not found. Please install just manually: https://github.com/casey/just#installation"
exit 1
log_warning "Homebrew installation failed, trying binary download..."
fi
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v cargo &> /dev/null; then
log_info "Installing just via cargo..."
cargo install just
if cargo install just; then
log_success "just installed"
return 0
else
log_error "Cargo not found. Please install Rust or just manually: https://github.com/casey/just#installation"
log_warning "Cargo installation failed, trying binary download..."
fi
fi
fi
# Fall back to downloading pre-built binary
log_info "Downloading pre-built just binary..."
# Detect architecture
local arch=$(uname -m)
local os=$(uname -s | tr '[:upper:]' '[:lower:]')
# Map architecture names
case "$arch" in
x86_64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*)
log_error "Unsupported architecture: $arch"
log_info "Please install just manually: https://github.com/casey/just#installation"
exit 1
;;
esac
# Map OS names
case "$os" in
darwin) os="apple-darwin" ;;
linux) os="unknown-linux-musl" ;;
*)
log_error "Unsupported OS: $os"
log_info "Please install just manually: https://github.com/casey/just#installation"
exit 1
;;
esac
local binary_name="just-${arch}-${os}"
local download_url="https://github.com/casey/just/releases/latest/download/${binary_name}.tar.gz"
local install_dir="$HOME/.local/bin"
# Create install directory
mkdir -p "$install_dir"
# Download and extract
local tmp_dir=$(mktemp -d)
trap "rm -rf $tmp_dir" EXIT
log_info "Downloading from: $download_url"
if ! curl -fsSL "$download_url" -o "$tmp_dir/just.tar.gz"; then
log_error "Failed to download just binary"
log_info "Please install just manually: https://github.com/casey/just#installation"
exit 1
fi
else
log_error "Unsupported OS. Please install just manually: https://github.com/casey/just#installation"
log_info "Extracting to $install_dir..."
if ! tar -xzf "$tmp_dir/just.tar.gz" -C "$tmp_dir"; then
log_error "Failed to extract just binary"
exit 1
fi
# Install binary
if ! mv "$tmp_dir/just" "$install_dir/just"; then
log_error "Failed to install just to $install_dir"
exit 1
fi
chmod +x "$install_dir/just"
# Add to PATH if not already there
if [[ ":$PATH:" != *":$install_dir:"* ]]; then
log_info "Adding $install_dir to PATH..."
export PATH="$install_dir:$PATH"
# Add to shell profile
local shell_profile=""
if [ -n "$BASH_VERSION" ]; then
shell_profile="$HOME/.bashrc"
elif [ -n "$ZSH_VERSION" ]; then
shell_profile="$HOME/.zshrc"
fi
if [ -n "$shell_profile" ]; then
echo "export PATH=\"$install_dir:\$PATH\"" >> "$shell_profile"
log_info "Added to $shell_profile (restart shell or run: source $shell_profile)"
fi
fi
# Verify installation
if command -v just &> /dev/null; then
log_success "just installed successfully to $install_dir/just"
else
log_warning "just installed to $install_dir/just but not found in PATH"
log_info "You may need to restart your terminal or run:"
log_info " export PATH=\"$install_dir:\$PATH\""
fi
}
# ============================================================================