From 177d0d9f6456bf9f54b4d926e9f818068556292c Mon Sep 17 00:00:00 2001 From: Jose B Date: Thu, 4 Dec 2025 13:39:33 -0500 Subject: [PATCH] chore: improve just installation with binary fallback and better error handling --- setup.sh | 113 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 12 deletions(-) diff --git a/setup.sh b/setup.sh index 0b9e3cd..b156757 100755 --- a/setup.sh +++ b/setup.sh @@ -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 - log_success "just installed" - else - log_error "Homebrew not found. Please install just manually: https://github.com/casey/just#installation" - exit 1 + if brew install just; then + log_success "just installed" + return 0 + else + 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 - log_success "just installed" - else - log_error "Cargo not found. Please install Rust or just manually: https://github.com/casey/just#installation" - exit 1 + if cargo install just; then + log_success "just installed" + return 0 + else + log_warning "Cargo installation failed, trying binary download..." + fi fi - else - log_error "Unsupported OS. Please install just manually: https://github.com/casey/just#installation" + 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 + + 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 } # ============================================================================