#!/bin/bash # Step: Install and start Ollama. Source common.sh before sourcing this file. # Launchd plist that starts Ollama on all interfaces at login. OLLAMA_PLIST="$HOME/Library/LaunchAgents/com.ollama.serve.plist" install_ollama() { print_step "Installing Ollama" if command -v ollama &> /dev/null; then print_success "Ollama is already installed" ollama --version else print_warning "Installing Ollama..." curl -fsSL https://ollama.com/install.sh | sh print_success "Ollama installed successfully" fi # Register Ollama as a launchd agent so it: # - starts automatically at login # - listens on all interfaces (0.0.0.0) so other devices can reach it print_warning "Configuring Ollama to listen on all network interfaces..." mkdir -p "$HOME/Library/LaunchAgents" cat > "$OLLAMA_PLIST" < Label com.ollama.serve ProgramArguments /usr/local/bin/ollama serve EnvironmentVariables OLLAMA_HOST 0.0.0.0:11434 RunAtLoad KeepAlive StandardOutPath /tmp/ollama.log StandardErrorPath /tmp/ollama.log EOF # Stop any existing instance first so the new config takes effect if pgrep -x "ollama" > /dev/null; then print_warning "Restarting Ollama with network binding..." launchctl unload "$OLLAMA_PLIST" 2>/dev/null || true pkill -x ollama 2>/dev/null || true sleep 1 fi launchctl load "$OLLAMA_PLIST" sleep 3 if pgrep -x "ollama" > /dev/null; then print_success "Ollama service started (listening on 0.0.0.0:11434)" else print_warning "Ollama service may not have started properly" echo " Check logs at: /tmp/ollama.log" fi }