#!/usr/bin/env bash # ============================================================================== # SFI Coding Agent — Universal Installer for Linux & macOS # Product: SFI Agent by Shah Fahad Inc. # URL: https://agent.shahfahadinc.com # ============================================================================== set -euo pipefail # ANSI Colors BOLD="\033[1m" GREEN="\033[0;32m" CYAN="\033[0;36m" YELLOW="\033[0;33m" RED="\033[0;31m" GRAY="\033[0;90m" RESET="\033[0m" INSTALL_DIR="${HOME}/.sfi-agent" BIN_DIR="${HOME}/.local/bin" REPO_URL="https://github.com/ShahFahadIncCode/sfi-coding-agent.git" echo -e "\n${BOLD}${CYAN}=====================================================================${RESET}" echo -e "${BOLD}${GREEN} 🚀 SFI Agent — Universal Workstation Installer${RESET}" echo -e "${GRAY} Connecting ChatGPT, Claude Desktop, and Gemini to your Workstation${RESET}" echo -e "${BOLD}${CYAN}=====================================================================${RESET}\n" # 1. Detect OS & Architecture OS="$(uname -s)" ARCH="$(uname -m)" echo -e " ${BOLD}● System Detection:${RESET} ${OS} (${ARCH})" # 2. Check Git if ! command -v git >/dev/null 2>&1; then echo -e " ${RED}✖ Git is required but not installed.${RESET}" echo -e " Please install git first:" if [[ "${OS}" == "Darwin" ]]; then echo -e " Run: ${CYAN}xcode-select --install${RESET} or ${CYAN}brew install git${RESET}" elif command -v apt-get >/dev/null 2>&1; then echo -e " Run: ${CYAN}sudo apt update && sudo apt install -y git${RESET}" elif command -v dnf >/dev/null 2>&1; then echo -e " Run: ${CYAN}sudo dnf install -y git${RESET}" elif command -v pacman >/dev/null 2>&1; then echo -e " Run: ${CYAN}sudo pacman -S git${RESET}" fi exit 1 fi echo -e " ${GREEN}✔ Git detected:${RESET} $(git --version)" # 3. Check / Install Node.js (>= 18) NODE_OK=0 if command -v node >/dev/null 2>&1; then NODE_VER=$(node -v | sed 's/v//' | cut -d'.' -f1) if [ "$NODE_VER" -ge 18 ]; then NODE_OK=1 echo -e " ${GREEN}✔ Node.js detected:${RESET} $(node -v)" fi fi if [ $NODE_OK -eq 0 ]; then echo -e " ${YELLOW}⚠ Node.js (>= 18) not found. Installing via nvm...${RESET}" export NVM_DIR="${HOME}/.nvm" if [ ! -d "$NVM_DIR" ]; then curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash fi [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" nvm install 22 nvm use 22 echo -e " ${GREEN}✔ Node.js installed:${RESET} $(node -v)" fi # 4. Check / Install pnpm if ! command -v pnpm >/dev/null 2>&1; then echo -e " ${CYAN}● Installing pnpm package manager...${RESET}" if command -v npm >/dev/null 2>&1; then npm install -g pnpm else curl -fsSL https://get.pnpm.io/install.sh | sh - fi fi echo -e " ${GREEN}✔ pnpm detected:${RESET} $(pnpm --version)" # 5. Clone or Update SFI Agent Repository mkdir -p "${INSTALL_DIR}" if [ -d "${INSTALL_DIR}/.git" ]; then echo -e "\n ${CYAN}● Updating existing SFI Agent installation in ${INSTALL_DIR}...${RESET}" cd "${INSTALL_DIR}" git fetch origin main git reset --hard origin/main else echo -e "\n ${CYAN}● Downloading SFI Agent repository to ${INSTALL_DIR}...${RESET}" git clone "${REPO_URL}" "${INSTALL_DIR}" cd "${INSTALL_DIR}" fi # 6. Install Dependencies & Build Packages echo -e "\n ${CYAN}● Installing workspace dependencies...${RESET}" pnpm install --frozen-lockfile=false echo -e "\n ${CYAN}● Compiling SFI MCP Gateway & Desktop Host...${RESET}" pnpm --filter @sfi/mcp build pnpm --filter @sfi/desktop build # 7. Create Global Executable Symlink mkdir -p "${BIN_DIR}" chmod +x "${INSTALL_DIR}/bin/sfi-host" ln -sf "${INSTALL_DIR}/bin/sfi-host" "${BIN_DIR}/sfi-host" # Also try /usr/local/bin if writable if [ -w "/usr/local/bin" ]; then ln -sf "${INSTALL_DIR}/bin/sfi-host" "/usr/local/bin/sfi-host" fi # 8. Ensure ~/.local/bin is in PATH SHELL_RC="" if [ -n "${ZSH_VERSION:-}" ] || [ -f "${HOME}/.zshrc" ]; then SHELL_RC="${HOME}/.zshrc" elif [ -f "${HOME}/.bashrc" ]; then SHELL_RC="${HOME}/.bashrc" fi if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then if [ -n "$SHELL_RC" ]; then if ! grep -q 'export PATH="$HOME/.local/bin:$PATH"' "$SHELL_RC" 2>/dev/null; then echo -e '\nexport PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_RC" fi fi export PATH="${BIN_DIR}:${PATH}" fi # 9. Download cloudflared (for 1-click Quick Tunnels) if missing if ! command -v cloudflared >/dev/null 2>&1 && [ ! -f "${BIN_DIR}/cloudflared" ]; then echo -e " ${CYAN}● Installing Cloudflare Tunnel binary for 1-click remote tunnels...${RESET}" CF_URL="" if [[ "${OS}" == "Linux" ]]; then if [[ "${ARCH}" == "x86_64" ]]; then CF_URL="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64" elif [[ "${ARCH}" == "aarch64" || "${ARCH}" == "arm64" ]]; then CF_URL="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64" fi elif [[ "${OS}" == "Darwin" ]]; then if [[ "${ARCH}" == "arm64" ]]; then CF_URL="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-arm64.tgz" else CF_URL="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-amd64.tgz" fi fi if [ -n "$CF_URL" ]; then if [[ "$CF_URL" == *.tgz ]]; then curl -fsSL "$CF_URL" | tar -xz -C "${BIN_DIR}" else curl -fsSL -o "${BIN_DIR}/cloudflared" "$CF_URL" fi chmod +x "${BIN_DIR}/cloudflared" 2>/dev/null || true echo -e " ${GREEN}✔ cloudflared installed successfully!${RESET}" fi fi # 10. Verify Installation echo -e "\n${BOLD}${GREEN}=====================================================================${RESET}" echo -e "${BOLD}${GREEN} ✔ SFI AGENT SUCCESSFULLY INSTALLED ON YOUR SYSTEM!${RESET}" echo -e "${BOLD}${GREEN}=====================================================================${RESET}" echo -e "\n ${BOLD}Available Commands:${RESET}" echo -e " ${CYAN}sfi-host --web${RESET} Start the Web Host Control Center (http://localhost:5180)" echo -e " ${CYAN}sfi-host --sse${RESET} Start the MCP SSE Gateway on port 3333" echo -e " ${CYAN}sfi-host --tunnel${RESET} Start 1-click Cloudflare Quick Tunnel" echo -e " ${CYAN}sfi-host${RESET} Launch the native Desktop Electron GUI" echo -e " ${CYAN}sfi-host --help${RESET} View all command options" echo -e "\n ${BOLD}Quick Start:${RESET}" echo -e " Run: ${BOLD}${CYAN}sfi-host --web${RESET} to open your control center in your browser.\n"