-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate_ollama.sh
63 lines (51 loc) · 1.73 KB
/
migrate_ollama.sh
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
set -e
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check for required commands
for cmd in snap docker sudo; do
if ! command_exists "$cmd"; then
echo "Error: $cmd is required but not installed. Please install it and try again."
exit 1
fi
done
# Stop Ollama Snap service
echo "Stopping Ollama Snap service..."
sudo snap stop ollama
# Create Docker volume
echo "Creating Docker volume 'ollama'..."
docker volume create ollama
# Copy Snap data to Docker volume
echo "Copying Ollama data from Snap to Docker volume..."
sudo docker run --rm -v ollama:/data -v /var/snap/ollama/common:/backup alpine sh -c "cp -r /backup/* /data/"
# Run Ollama Docker container
echo "Starting Ollama Docker container..."
docker run -d --name ollama -v ollama:/root/.ollama -p 11434:11434 ollama/ollama
# Wait for container to start
echo "Waiting for Ollama container to start..."
sleep 5
# Verify Ollama is running
echo "Verifying Ollama installation..."
if docker exec -it ollama ollama list >/dev/null 2>&1; then
echo "Ollama is running successfully in Docker!"
else
echo "Error: Ollama doesn't seem to be running correctly in Docker."
exit 1
fi
# Add alias to shell configuration
echo "Adding 'ollama' alias to shell configuration..."
echo 'alias ollama="docker exec -it ollama ollama"' >> ~/.bashrc
echo "Alias added. Please run 'source ~/.bashrc' to apply changes."
# Prompt user to remove Snap installation
read -p "Do you want to remove the Ollama Snap installation? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Removing Ollama Snap installation..."
sudo snap remove ollama
else
echo "Keeping Ollama Snap installation."
fi
echo "Migration complete!"