Skip to content

Instantly share code, notes, and snippets.

@t18n
Created June 17, 2024 10:23
Show Gist options
  • Save t18n/96a8c345ee72d76ec5873de5ee58394f to your computer and use it in GitHub Desktop.
Save t18n/96a8c345ee72d76ec5873de5ee58394f to your computer and use it in GitHub Desktop.
A script that allow to sync ollama models between computers. Useful for dotfiles backups
#!/bin/bash
# Create a list of existing Ollama models
existingModels=$(ollama list | awk '{if(NR>1) print $1}')
# Create a list of Ollama models to pull
models=(
llama3:8b
phi3:mini
phi3:medium
phi3:medium-128k
aya:8b
gemma:7b
)
contains_element() {
local element
for element in "${@:2}"; do
if [[ "$element" == "$1" ]]; then
return 0
fi
done
return 1
}
for model in "${existingModels[@]}"; do
if ! contains_element "$model" "${models[@]}"; then
echo "Purging $model"
ollama rm $model
fi
done
# Install all new models
for model in ${models[@]}; do
echo "Pulling model $model"
ollama pull $model
done
@t18n
Copy link
Author

t18n commented Jun 17, 2024

Edit your models list, run chmod +x ./sync-models.sh and ./sync-models.sh to run the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment