#!/usr/bin/env bash # BrokeCrew Installer # Usage: curl -fsSL https://raw.githubusercontent.com/oiupoyt/brokecrew/main/install.sh | bash set -euo pipefail REPO="oiupoyt/brokecrew" BINARY_NAME="brokecrew" # ANSI Color codes BOLD="\033[1m" GREEN="\033[0;32m" CYAN="\033[0;36m" YELLOW="\033[0;33m" RED="\033[0;31m" RESET="\033[0m" log_info() { printf "${CYAN}==>${RESET} ${BOLD}%b${RESET}\n" "$1" } log_success() { printf "${GREEN}✔${RESET} ${BOLD}%b${RESET}\n" "$1" } log_warn() { printf "${YELLOW}⚠ %b${RESET}\n" "$1" } log_error() { printf "${RED}✖ Error: %b${RESET}\n" "$1" >&2 } # 1. Detect Operating System OS="$(uname -s | tr '[:upper:]' '[:lower:]')" case "$OS" in linux) TARGET_OS="unknown-linux-gnu" ;; darwin) TARGET_OS="apple-darwin" ;; *) log_error "Unsupported operating system: $OS. BrokeCrew supports Linux and macOS via this script." exit 1 ;; esac # 2. Detect CPU Architecture ARCH="$(uname -m)" case "$ARCH" in x86_64|amd64) TARGET_ARCH="x86_64" ;; aarch64|arm64) TARGET_ARCH="aarch64" ;; *) log_error "Unsupported CPU architecture: $ARCH. BrokeCrew prebuilts support x86_64 and aarch64." exit 1 ;; esac TARGET="${TARGET_ARCH}-${TARGET_OS}" log_info "Detected platform: ${BOLD}${TARGET}${RESET}" # 3. Determine Installation Directory if [ -n "${INSTALL_DIR:-}" ]; then DEST_DIR="$INSTALL_DIR" elif [ -d "$HOME/.cargo/bin" ] && [[ ":$PATH:" == *":$HOME/.cargo/bin:"* ]]; then DEST_DIR="$HOME/.cargo/bin" elif [ -d "$HOME/.local/bin" ]; then DEST_DIR="$HOME/.local/bin" else DEST_DIR="$HOME/.local/bin" fi mkdir -p "$DEST_DIR" # 4. Resolve Latest Version from GitHub log_info "Resolving latest release for ${REPO}..." LATEST_TAG=$(curl -sSL "https://api.github.com/repos/${REPO}/releases/latest" 2>/dev/null | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' || true) if [ -z "$LATEST_TAG" ]; then LATEST_TAG="v0.1.0" log_warn "Could not resolve latest tag from GitHub API, defaulting to ${LATEST_TAG}" fi ARCHIVE_NAME="brokecrew-${LATEST_TAG}-${TARGET}.tar.gz" DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${LATEST_TAG}/${ARCHIVE_NAME}" TMP_DIR=$(mktemp -d -t brokecrew-install-XXXXXX) cleanup() { rm -rf "$TMP_DIR" } trap cleanup EXIT # 5. Download & Extract log_info "Downloading BrokeCrew (${LATEST_TAG}) for ${TARGET}..." DOWNLOAD_SUCCESS=false if curl -sSL -f -o "${TMP_DIR}/${ARCHIVE_NAME}" "$DOWNLOAD_URL"; then DOWNLOAD_SUCCESS=true tar -xzf "${TMP_DIR}/${ARCHIVE_NAME}" -C "$TMP_DIR" INSTALL_SRC="${TMP_DIR}/${BINARY_NAME}" fi # Fallback to cargo install if release asset not yet published if [ "$DOWNLOAD_SUCCESS" = false ]; then log_warn "Precompiled release asset not found at ${DOWNLOAD_URL}." if command -v cargo >/dev/null 2>&1; then log_info "Building from source via cargo..." cargo install --git "https://github.com/${REPO}.git" --root "${TMP_DIR}/cargo-install" INSTALL_SRC="${TMP_DIR}/cargo-install/bin/${BINARY_NAME}" else log_error "No prebuilt binary available and cargo is not installed." log_info "Please install Rust (https://rustup.rs) or download a binary manually from https://github.com/${REPO}/releases" exit 1 fi fi # 6. Install Executable chmod +x "$INSTALL_SRC" cp -f "$INSTALL_SRC" "${DEST_DIR}/${BINARY_NAME}" log_success "Installed '${BINARY_NAME}' into ${DEST_DIR}/${BINARY_NAME}" # 7. PATH Verification if [[ ":$PATH:" != *":$DEST_DIR:"* ]]; then log_warn "${DEST_DIR} is not in your system PATH." printf "Add the following line to your ~/.bashrc or ~/.zshrc:\n" printf " export PATH=\"%s:\$PATH\"\n\n" "$DEST_DIR" fi # 8. Success Banner printf "\n" printf "${GREEN}${BOLD}BrokeCrew successfully installed!${RESET}\n\n" printf "Run the command:\n" printf " ${CYAN}${BOLD}brokecrew --help${RESET}\n\n" printf "To set up your OpenRouter API key:\n" printf " ${CYAN}${BOLD}brokecrew config set-key${RESET}\n\n" printf "To start chatting with your AI personas:\n" printf " ${CYAN}${BOLD}brokecrew chat \"build me a proxy checker site\"${RESET}\n\n"