diff --git a/README.md b/README.md index 6a03aa8..e501b57 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,15 @@ For automated setup, run the provided script: ./setup.sh ``` -The script automates most steps and pauses for manual configuration when needed (Docker settings, web interface setup, etc.). For detailed manual instructions, continue reading below. +The script automates most steps and pauses for manual configuration when needed (Docker settings, web interface setup, etc.). + +**After installation**, verify everything is working: + +```bash +./check-status.sh +``` + +For detailed manual instructions, continue reading below. --- diff --git a/check-status.sh b/check-status.sh new file mode 100755 index 0000000..2963a48 --- /dev/null +++ b/check-status.sh @@ -0,0 +1,265 @@ +#!/bin/bash + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Status indicators +PASS="${GREEN}✓${NC}" +FAIL="${RED}✗${NC}" +WARN="${YELLOW}⚠${NC}" +INFO="${BLUE}ℹ${NC}" + +print_header() { + echo -e "\n${BLUE}═══════════════════════════════════════════════════${NC}" + echo -e "${BLUE}$1${NC}" + echo -e "${BLUE}═══════════════════════════════════════════════════${NC}\n" +} + +print_section() { + echo -e "\n${BLUE}▶ $1${NC}" +} + +check_command() { + if command -v $1 &> /dev/null; then + echo -e "$PASS $2 installed" + return 0 + else + echo -e "$FAIL $2 not found" + return 1 + fi +} + +check_service() { + if $1 &> /dev/null; then + echo -e "$PASS $2" + return 0 + else + echo -e "$FAIL $2" + return 1 + fi +} + +# Main status check +print_header "RIoT AI System Status Check" + +OVERALL_STATUS=0 + +# ============================================================================= +# System Information +# ============================================================================= +print_section "System Information" + +echo -e "$INFO macOS Version: $(sw_vers -productVersion)" +echo -e "$INFO Hostname: $(hostname)" + +# Check available disk space +AVAILABLE_GB=$(df -g / | awk 'NR==2 {print $4}') +if [ "$AVAILABLE_GB" -lt 20 ]; then + echo -e "$WARN Available disk space: ${AVAILABLE_GB}GB (recommended: 20GB+)" + OVERALL_STATUS=1 +else + echo -e "$PASS Available disk space: ${AVAILABLE_GB}GB" +fi + +# Check total memory +TOTAL_MEM_GB=$(sysctl -n hw.memsize | awk '{print int($1/1024/1024/1024)}') +if [ "$TOTAL_MEM_GB" -lt 16 ]; then + echo -e "$WARN Total memory: ${TOTAL_MEM_GB}GB (recommended: 16GB+)" +else + echo -e "$PASS Total memory: ${TOTAL_MEM_GB}GB" +fi + +# ============================================================================= +# Core Components +# ============================================================================= +print_section "Core Components" + +# Homebrew +if check_command brew "Homebrew"; then + echo -e " ${INFO} Version: $(brew --version | head -n1)" +else + OVERALL_STATUS=1 +fi + +# Ollama +if check_command ollama "Ollama"; then + echo -e " ${INFO} Version: $(ollama --version 2>&1 | head -n1)" +else + OVERALL_STATUS=1 +fi + +# Docker Desktop +if [ -d "/Applications/Docker.app" ]; then + echo -e "$PASS Docker Desktop installed" +else + echo -e "$FAIL Docker Desktop not found" + OVERALL_STATUS=1 +fi + +# ============================================================================= +# Docker Service +# ============================================================================= +print_section "Docker Service" + +if check_service "docker info" "Docker daemon running"; then + # Get Docker resource settings + DOCKER_CPUS=$(docker info 2>/dev/null | grep "CPUs:" | awk '{print $2}') + DOCKER_MEM=$(docker info 2>/dev/null | grep "Total Memory:" | awk '{print $3$4}') + + echo -e " ${INFO} CPUs allocated: ${DOCKER_CPUS}" + echo -e " ${INFO} Memory allocated: ${DOCKER_MEM}" + + # Check running containers + CONTAINER_COUNT=$(docker ps -q | wc -l | tr -d ' ') + echo -e " ${INFO} Running containers: ${CONTAINER_COUNT}" +else + echo -e "$WARN Docker is not running. Start Docker Desktop to continue." + OVERALL_STATUS=1 +fi + +# ============================================================================= +# Ollama Service +# ============================================================================= +print_section "Ollama Service" + +if pgrep -x "ollama" > /dev/null; then + echo -e "$PASS Ollama service running" + + # Check available models + if command -v ollama &> /dev/null; then + echo -e "\n Available models:" + MODELS=$(ollama list 2>/dev/null) + if [ -n "$MODELS" ]; then + echo "$MODELS" | tail -n +2 | while read line; do + MODEL_NAME=$(echo "$line" | awk '{print $1}') + if [[ $MODEL_NAME == riot* ]]; then + echo -e " $PASS $line" + else + echo -e " $INFO $line" + fi + done + else + echo -e " $WARN No models found" + OVERALL_STATUS=1 + fi + fi +else + echo -e "$WARN Ollama service not running" + echo -e " ${INFO} Start with: ollama serve" + OVERALL_STATUS=1 +fi + +# ============================================================================= +# Onyx Installation +# ============================================================================= +print_section "Onyx" + +if [ -d ~/onyx_data ]; then + echo -e "$PASS Onyx data directory exists" + + # Check if Onyx containers are running + if command -v docker &> /dev/null && docker info &> /dev/null; then + cd ~/onyx_data 2>/dev/null + if [ -f "docker-compose.yaml" ] || [ -f "docker-compose.yml" ]; then + echo -e "$PASS Docker Compose file found" + + # Check running Onyx containers + ONYX_CONTAINERS=$(docker ps --filter "name=onyx" -q | wc -l | tr -d ' ') + if [ "$ONYX_CONTAINERS" -gt 0 ]; then + echo -e "$PASS Onyx containers running: ${ONYX_CONTAINERS}" + docker ps --filter "name=onyx" --format " $INFO {{.Names}} ({{.Status}})" + else + echo -e "$WARN No Onyx containers running" + echo -e " ${INFO} Start with: cd ~/onyx_data && docker compose up -d" + OVERALL_STATUS=1 + fi + fi + cd - > /dev/null 2>&1 + fi +else + echo -e "$FAIL Onyx data directory not found" + echo -e " ${INFO} Run ./setup.sh to install" + OVERALL_STATUS=1 +fi + +# ============================================================================= +# Web Interface +# ============================================================================= +print_section "Web Interface" + +# Check if port 3000 is in use +if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null 2>&1; then + echo -e "$PASS Port 3000 is active" + + # Try to connect to the web interface + if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200\|301\|302"; then + echo -e "$PASS Web interface responding" + echo -e "\n ${INFO} Access at: ${GREEN}http://localhost:3000${NC}" + + # Get local IP for network access + LOCAL_IP=$(ipconfig getifaddr en0 2>/dev/null || ipconfig getifaddr en1 2>/dev/null) + if [ -n "$LOCAL_IP" ]; then + echo -e " ${INFO} Network access: ${GREEN}http://${LOCAL_IP}:3000${NC}" + fi + else + echo -e "$WARN Port 3000 is active but interface not responding" + OVERALL_STATUS=1 + fi +else + echo -e "$FAIL Port 3000 not in use" + echo -e " ${INFO} Onyx containers may not be running" + OVERALL_STATUS=1 +fi + +# ============================================================================= +# Repository Status +# ============================================================================= +print_section "Repository" + +if [ -d ~/riotsecure ]; then + echo -e "$PASS Repository exists at ~/riotsecure" + + cd ~/riotsecure 2>/dev/null + if [ -d .git ]; then + CURRENT_BRANCH=$(git branch --show-current 2>/dev/null) + echo -e " ${INFO} Current branch: ${CURRENT_BRANCH}" + + # Check for updates + git fetch --quiet 2>/dev/null + LOCAL=$(git rev-parse @ 2>/dev/null) + REMOTE=$(git rev-parse @{u} 2>/dev/null) + + if [ "$LOCAL" != "$REMOTE" ]; then + echo -e " $WARN Updates available (run: git pull)" + else + echo -e " $PASS Repository up to date" + fi + fi + cd - > /dev/null 2>&1 +else + echo -e "$FAIL Repository not found at ~/riotsecure" + OVERALL_STATUS=1 +fi + +# ============================================================================= +# Summary +# ============================================================================= +print_header "Summary" + +if [ $OVERALL_STATUS -eq 0 ]; then + echo -e "${GREEN}✓ All systems operational${NC}\n" + exit 0 +else + echo -e "${YELLOW}⚠ Some issues detected - review output above${NC}\n" + echo "Common fixes:" + echo " • Docker not running → Open Docker Desktop" + echo " • Ollama not running → Run: ollama serve" + echo " • Onyx not running → cd ~/onyx_data && docker compose up -d" + echo " • Low disk space → Free up disk space" + echo "" + exit 1 +fi diff --git a/setup.sh b/setup.sh index 1a539de..460780a 100755 --- a/setup.sh +++ b/setup.sh @@ -40,15 +40,109 @@ check_mac() { fi } +preflight_checks() { + print_step "Pre-flight System Checks" + + local PREFLIGHT_FAILED=0 + + # Check macOS version + MACOS_VERSION=$(sw_vers -productVersion) + MACOS_MAJOR=$(echo $MACOS_VERSION | cut -d. -f1) + echo -e "macOS Version: ${BLUE}$MACOS_VERSION${NC}" + + if [ "$MACOS_MAJOR" -lt 12 ]; then + print_error "macOS 12 (Monterey) or later recommended. You have: $MACOS_VERSION" + PREFLIGHT_FAILED=1 + else + print_success "macOS version compatible" + fi + + # Check available disk space + AVAILABLE_GB=$(df -g / | awk 'NR==2 {print $4}') + echo -e "Available disk space: ${BLUE}${AVAILABLE_GB}GB${NC}" + + if [ "$AVAILABLE_GB" -lt 30 ]; then + print_error "Insufficient disk space. Required: 30GB+, Available: ${AVAILABLE_GB}GB" + echo " Docker images, Ollama models, and Onyx require significant storage" + PREFLIGHT_FAILED=1 + elif [ "$AVAILABLE_GB" -lt 50 ]; then + print_warning "Low disk space. Recommended: 50GB+, Available: ${AVAILABLE_GB}GB" + echo " Installation will proceed but may fail if space runs out" + else + print_success "Sufficient disk space available" + fi + + # Check total memory + TOTAL_MEM_GB=$(sysctl -n hw.memsize | awk '{print int($1/1024/1024/1024)}') + echo -e "Total system memory: ${BLUE}${TOTAL_MEM_GB}GB${NC}" + + if [ "$TOTAL_MEM_GB" -lt 16 ]; then + print_warning "Low memory. Recommended: 16GB+, Available: ${TOTAL_MEM_GB}GB" + echo " Docker will be configured with 20GB limit (may need adjustment)" + else + print_success "Sufficient memory available" + fi + + # Check internet connectivity + if ping -c 1 -W 2 8.8.8.8 &> /dev/null; then + print_success "Internet connectivity verified" + else + print_error "No internet connection detected" + echo " Internet required to download Homebrew, Docker, Ollama, etc." + PREFLIGHT_FAILED=1 + fi + + # Check if Docker is already running (might conflict) + if pgrep -x "Docker" > /dev/null 2>&1; then + print_warning "Docker Desktop is already running" + echo " This is fine if it's already installed, otherwise it may cause conflicts" + fi + + # Check if port 3000 is already in use + if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null 2>&1; then + print_warning "Port 3000 is already in use" + echo " Onyx web interface requires port 3000 to be available" + echo " You may need to stop the conflicting service" + fi + + # Estimate installation time + echo "" + echo -e "${YELLOW}⏱ Estimated installation time: 20-40 minutes${NC}" + echo " (depends on internet speed and system performance)" + echo "" + + # Show what will be installed + echo "The following will be installed/configured:" + echo " • Homebrew (package manager)" + echo " • Ollama (AI model runtime)" + echo " • Docker Desktop (containerization)" + echo " • Onyx (web interface)" + echo " • RIoT AI models (several GB download)" + echo "" + + if [ $PREFLIGHT_FAILED -eq 1 ]; then + print_error "Pre-flight checks failed. Please resolve the issues above." + echo "" + echo "Continue anyway? (not recommended) [y/N]" + read -r response + if [[ ! "$response" =~ ^[Yy]$ ]]; then + print_error "Setup aborted by user" + exit 1 + fi + else + print_success "Pre-flight checks passed" + fi + + echo "" + echo "Press ENTER to begin installation..." + read +} + # Check if running on macOS check_mac -print_step "RIoT AI Setup Script - Mac Mini Configuration" -echo "This script will guide you through setting up the RIoT AI system." -echo "Some steps require manual interaction and will pause for your input." -echo "" -echo "Press ENTER to begin..." -read +# Run pre-flight checks +preflight_checks # ============================================================================= # STEP 1: Homebrew