-
Notifications
You must be signed in to change notification settings - Fork 4
/
syncmodels
executable file
·31 lines (23 loc) · 1.01 KB
/
syncmodels
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# syncs models from ollama to somewhere else
#
# Base directories
base_dir=~/.ollama/models
manifest_dir=$base_dir/manifests/registry.ollama.ai
blob_dir=$base_dir/blobs
publicmodels_dir=~/publicmodels/mattw/lmstudio
# Remove all existing symbolic links from publicmodels directory
find "$publicmodels_dir" -type l -exec rm {} +
# Create publicmodels directory if it doesn't exist
mkdir -p "$publicmodels_dir"
# Use find to get all files under the 'model' directories
find "$manifest_dir" -mindepth 3 -maxdepth 3 -type f | while IFS= read -r file; do
user=$(basename "$(dirname "$(dirname "$file")")" | sed 's/^registry\.ollama\.ai/ollama/')
model=$(basename "$(dirname "$file")")
tag=$(basename "$file")
digest=$(jq -r '.layers[] | select(.mediaType == "application/vnd.ollama.image.model") | .digest' "$file")
# Create symbolic link
ln -s "$blob_dir/$digest" "$publicmodels_dir/$user-$model-$tag.bin"
# Print the user, model, and tag
echo "$user - $model:$tag"
done