#!/bin/bash # Mirror an Ollama model into a portable tarball you can upload to S3 # (or any HTTPS host) and re-fetch via init-models.sh's s3_pull. # # Run on any machine that already has the model pulled locally — the # script reads ~/.ollama/models/, parses the manifest to find the # referenced blobs, and tars them together. # # Usage: ./mirror-ollama-model.sh # Example: ./mirror-ollama-model.sh huihui_ai/qwen3.5-abliterated:9b qwen3.5-abliterated-9b.tgz # # Upload the tarball to S3, then add to init-models.sh: # s3_pull "huihui_ai/qwen3.5-abliterated:9b" "qwen3.5-abliterated-9b.tgz" # and set S3_OLLAMA_BASE in .env to your bucket's HTTPS base URL. set -euo pipefail MODEL="${1:?Usage: $0 }" OUT="${2:?Usage: $0 }" OLLAMA_HOME="${OLLAMA_HOME:-$HOME/.ollama}" MODELS="$OLLAMA_HOME/models" if ! ollama list | awk 'NR>1 {print $1}' | grep -qx "$MODEL"; then echo "Model $MODEL not found locally; pulling first..." ollama pull "$MODEL" fi # huihui_ai/qwen3.5-abliterated:9b → manifests/registry.ollama.ai/huihui_ai/qwen3.5-abliterated/9b ns_and_name="${MODEL%:*}" tag="${MODEL##*:}" manifest_rel="manifests/registry.ollama.ai/$ns_and_name/$tag" manifest_abs="$MODELS/$manifest_rel" if [ ! -f "$manifest_abs" ]; then echo "ERROR: manifest not found at $manifest_abs" >&2 exit 1 fi # Pull every sha256:* digest out of the manifest JSON. Each maps to # blobs/sha256-. blob_files="" for digest in $(grep -oE 'sha256:[a-f0-9]+' "$manifest_abs" | sort -u); do blob_rel="blobs/${digest/:/-}" if [ ! -f "$MODELS/$blob_rel" ]; then echo "WARNING: missing blob $blob_rel — skipping" >&2 continue fi blob_files="$blob_files $blob_rel" done count=$(echo "$blob_files" | wc -w | tr -d ' ') echo "Archiving manifest + $count blob(s)..." tar -czf "$OUT" -C "$MODELS" "$manifest_rel" $blob_files size=$(du -h "$OUT" | cut -f1) echo "Done: $OUT ($size)" echo echo "Next:" echo " 1. Upload to your bucket, e.g." echo " aws s3 cp $OUT s3://YOUR-BUCKET/ollama-models/ --acl public-read" echo " (or whatever exposes it over HTTPS)" echo " 2. Set S3_OLLAMA_BASE in .env to the bucket's HTTPS base, e.g." echo " S3_OLLAMA_BASE=https://YOUR-BUCKET.s3.amazonaws.com/ollama-models" echo " 3. Add to init-models.sh:" echo " s3_pull \"$MODEL\" \"$(basename "$OUT")\""