#!/usr/bin/env bash # scripts/pull-models.sh — Pull all Ollama models from the manifest # # Usage: # bash scripts/pull-models.sh # pull all models # bash scripts/pull-models.sh nomic-embed-text # pull specific model set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_DIR="$(cd "${SCRIPT_DIR}/../.." && pwd)" source "${REPO_DIR}/scripts/common.sh" MANIFEST="${SCRIPT_DIR}/../ollama-models.txt" if ! command_exists ollama; then die "Ollama not found. Run: bash homeai-llm/setup.sh first." fi if ! curl -sf http://localhost:11434 -o /dev/null; then die "Ollama is not running. Start it first." fi # If a specific model is given as arg, just pull that if [[ $# -gt 0 ]]; then for model in "$@"; do log_info "Pulling $model..." ollama pull "$model" log_success "Pulled $model" done exit 0 fi # Pull all models from manifest log_section "Pulling Ollama models" total=0; pulled=0; skipped=0; failed=0 while IFS= read -r line || [[ -n "$line" ]]; do # Skip comments and blank lines [[ "$line" =~ ^[[:space:]]*# ]] && continue [[ -z "${line// }" ]] && continue model="${line%% *}" # strip any trailing comment total=$((total + 1)) # Check if model is already present if ollama list 2>/dev/null | grep -q "^${model%%:*}"; then tag="${model##*:}" model_name="${model%%:*}" if [[ "$tag" != "$model_name" ]]; then # Has explicit tag — check exact match if ollama list 2>/dev/null | grep -q "^${model_name}.*${tag}"; then log_info "Already present: $model — skipping" skipped=$((skipped + 1)) continue fi else log_info "Already present: $model — skipping" skipped=$((skipped + 1)) continue fi fi log_step "Pulling $model..." if ollama pull "$model"; then log_success "Pulled $model" pulled=$((pulled + 1)) else log_error "Failed to pull $model" failed=$((failed + 1)) fi done < "$MANIFEST" echo "" log_info "Pull complete: ${pulled} pulled, ${skipped} already present, ${failed} failed (of ${total} total)" if [[ $failed -gt 0 ]]; then log_warn "Some models failed to pull. Check your internet connection and retry." exit 1 fi echo "" log_info "Installed models:" ollama list