#!/bin/bash set -e # UI Constants matching the CLI theme RESET="\033[0m" BOLD="\033[1m" DIM="\033[2m" CYAN="\033[36m" GREEN="\033[32m" RED="\033[31m" YELLOW="\033[33m" GREY="\033[37m" print_banner() { echo "" echo -e "${GREY} ██████╗ █████╗ ██████╗██╗ ██╗ █████╗ ██████╗ ███████╗${RESET}" echo -e "${GREY} ██╔══██╗██╔══██╗██╔════╝██║ ██╔╝██╔══██╗██╔════╝ ██╔════╝${RESET}" echo -e "${GREY} ██████╔╝███████║██║ █████╔╝ ███████║██║ ███╗█████╗ ${RESET}" echo -e "${GREY} ██╔═══╝ ██╔══██║██║ ██╔═██╗ ██╔══██║██║ ██║██╔══╝ ${RESET}" echo -e "${GREY} ██║ ██║ ██║╚██████╗██║ ██╗██║ ██║╚██████╔╝███████╗${RESET}" echo -e "${GREY} ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝${RESET}" echo "" echo -e "${GREY} ███╗ ███╗ █████╗ ████████╗███████╗${RESET}" echo -e "${GREY} ████╗ ████║██╔══██╗╚══██╔══╝██╔════╝${RESET}" echo -e "${GREY} ██╔████╔██║███████║ ██║ █████╗ ${RESET}" echo -e "${GREY} ██║╚██╔╝██║██╔══██║ ██║ ██╔══╝ ${RESET}" echo -e "${GREY} ██║ ╚═╝ ██║██║ ██║ ██║ ███████╗${RESET}" echo -e "${GREY} ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚══════╝${RESET}" echo "" } print_banner VERSION="v1.0.0" OS="$(uname -s)" ARCH="$(uname -m)" # 1. Detect macOS if [ "$OS" != "Darwin" ]; then echo -e " ${RED}Error:${RESET}" echo "" echo -e " Package Mate Is Not Available on ${OS}" echo -e " Only pristine macOS environments are currently supported." echo "" exit 1 fi # 2. Detect Apple Silicon (M-Series) if [ "$ARCH" != "arm64" ] && [ "$ARCH" != "aarch64" ]; then echo -e " ${RED}Error:${RESET}" echo "" echo -e " Package Mate is exclusively optimized for Apple Silicon (M-Series)." echo -e " Intel-based Macs are not supported natively." echo "" exit 1 fi # 3. Check if Already Installed if [ -f "/usr/local/bin/mate" ]; then echo -e " ${YELLOW}Notice:${RESET}" echo "" echo -e " ❯ Package Mate is already securely installed on your system." echo "" echo -e " ❯ Run ${CYAN}mate${RESET} via the CLI to start managing your environment." echo "" exit 0 fi # 4. Install Manager Engine (Homebrew) if missing if ! command -v brew >/dev/null 2>&1; then echo -e " ${DIM}Installing the Manager Engine (Homebrew)...${RESET}" echo "" # NONINTERACTIVE ensures it doesn't prompt for ENTER to continue installing NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" >/dev/null # Adding brew to path for future commands in this session if [ -d "/opt/homebrew/bin" ]; then export PATH="/opt/homebrew/bin:$PATH" fi fi # 5. Download and Extract the Binary echo -e " ${DIM}Fetching Package Mate ${VERSION}...${RESET}" echo "" TARBALL_URL="https://github.com/yousefbustamiii/package-mate/releases/download/${VERSION}/mate-${VERSION}-darwin-arm64.tar.gz" # Try to download the release binary HTTP_CODE=$(curl -w "%{http_code}" -fsSL -o /tmp/mate.tar.gz "$TARBALL_URL" 2>/dev/null || echo "000") if [ "$HTTP_CODE" = "000" ] || [ "$HTTP_CODE" = "404" ]; then echo "" echo -e " ${RED}Error:${RESET}" echo "" echo -e " Failed to download the release archive (HTTP ${HTTP_CODE})." echo -e " The ${VERSION} release may not be available yet." echo "" echo -e " ${YELLOW}Alternative:${RESET} Install from source instead:" echo "" echo -e " ${DIM}git clone https://github.com/yousefbustamiii/package-mate.git${RESET}" echo -e " ${DIM}cd package-mate${RESET}" echo -e " ${DIM}go build -o mate .${RESET}" echo -e " ${DIM}sudo mv mate /usr/local/bin/${RESET}" echo "" exit 1 fi # Verify what we actually downloaded FILE_TYPE=$(file -b /tmp/mate.tar.gz 2>/dev/null || echo "unknown") # Case 1: It's actually a gzip archive - extract it if [[ "$FILE_TYPE" =~ [Gg]zip ]]; then tar -xzf /tmp/mate.tar.gz -C /tmp/ || { echo -e " ${RED}Error:${RESET}" echo "" echo -e " Failed to extract the archive." echo -e " The release archive may be corrupted." echo "" exit 1 } # Case 2: It's already the binary (GitHub sometimes serves raw binaries with .tar.gz extension) elif [[ "$FILE_TYPE" =~ "Mach-O" ]]; then mv /tmp/mate.tar.gz /tmp/mate else echo "" echo -e " ${RED}Error:${RESET}" echo "" echo -e " Downloaded file is not a valid archive or binary." echo -e " Detected format: ${FILE_TYPE}" echo -e " The release URL may be incorrect or the file is corrupted." echo "" exit 1 fi # Find the mate binary (could be directly in /tmp or in a subdirectory) if [ -f /tmp/mate ]; then MATE_BINARY="/tmp/mate" elif [ -f "/tmp/mate-${VERSION}-darwin-arm64/mate" ]; then MATE_BINARY="/tmp/mate-${VERSION}-darwin-arm64/mate" else # Try to find any 'mate' binary in the extracted contents MATE_BINARY=$(find /tmp -name "mate" -type f -perm /111 2>/dev/null | head -1) fi if [ -z "$MATE_BINARY" ] || [ ! -f "$MATE_BINARY" ]; then echo "" echo -e " ${RED}Error:${RESET}" echo "" echo -e " Could not locate the mate binary in the archive." echo -e " The release structure may have changed." echo "" exit 1 fi # Ensure the binary is executable chmod +x "$MATE_BINARY" # Cleanup the tarball and extracted directory rm -f /tmp/mate.tar.gz rm -rf "/tmp/mate-${VERSION}-darwin-arm64" rm -rf /tmp/mate-* # 6. Request sudo with standard elegant macOS style echo -e " ${GREEN}Download and extraction successful.${RESET}\n" echo -e " To finalize the installation, we need to move the binary to /usr/local/bin." echo -e " Please secure this action by verifying your identity." echo "" echo "" # The native macOS terminal will automatically attach the key icon to the password prompt sudo -p " Password: " mv "$MATE_BINARY" /usr/local/bin/mate echo "" echo -e " ${GREEN}Installation Complete.${RESET}" echo -e " Run ${CYAN}mate${RESET} to launch your developer experience." echo ""