Files
dotfiles/scripts/ollama_detect_and_link.sh
2026-02-23 19:53:49 -06:00

54 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
echo "🔍 Detecting Ollama model directories and linking into OLLAMA_MODELS"
# Load env if available
if [ -f "$HOME/.bashrc" ]; then
set +u
# shellcheck disable=SC1091
source "$HOME/.bashrc" || true
set -u
fi
OLLAMA_MODELS="${OLLAMA_MODELS:-$HOME/models/ollama}"
mkdir -p "$OLLAMA_MODELS"
candidates=(
"$HOME/.ollama/models"
"$HOME/.local/share/ollama/models"
"/var/lib/ollama/models"
"/usr/local/var/ollama/models"
"$HOME/.ollama"
)
linked=0
for cand in "${candidates[@]}"; do
if [ -d "$cand" ]; then
# skip empty directories
if [ -z "$(ls -A "$cand" 2>/dev/null)" ]; then
echo " Found $cand but it's empty — skipping"
continue
fi
name=$(basename "$cand")
dest="$OLLAMA_MODELS/$name"
if [ -e "$dest" ]; then
echo " Destination exists: $dest — skipping"
continue
fi
ln -sfn "$cand" "$dest"
echo "✅ Linked $cand$dest"
linked=$((linked+1))
fi
done
if [ $linked -eq 0 ]; then
echo "⚠️ No existing Ollama model directories detected in common locations."
echo "You can place models in: $OLLAMA_MODELS or run: pull_ollama_model <model-ref> (see scripts/ollama_tmux.sh)"
else
echo "🎉 Completed linking ($linked). Verify with: ls -la $OLLAMA_MODELS"
fi
echo "Done."