-
Notifications
You must be signed in to change notification settings - Fork 2
/
prestart.sh
executable file
·92 lines (83 loc) · 2.73 KB
/
prestart.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
echo "Running preload.sh"
# Function to check if Ollama is installed and if llava:v1.6 & mxbai-embed-large are installed
function check_ollama_installed {
if command -v ollama &> /dev/null
then
echo "Ollama is already installed"
if ollama list | grep -q "llava:v1.6" && ollama list | grep -q "mxbai-embed-large"
then
echo "All required models are already installed"
return 0
else
echo "One or more required models are not installed"
return 1
fi
else
echo "Ollama is not installed"
return 2
fi
}
# Function to install Ollama on Linux
function install_ollama_linux {
sudo curl -L https://ollama.com/download/ollama-linux-amd64 -o /usr/bin/ollama
sudo chmod +x /usr/bin/ollama
}
# Function to install Ollama on macOS
function install_ollama_macos {
sudo curl -L https://ollama.com/download/ollama-darwin-amd64 -o /usr/local/bin/ollama
sudo chmod +x /usr/local/bin/ollama
}
# Function to add Ollama as a startup service on Linux
function setup_service_linux {
sudo useradd -r -s /bin/false -m -d /usr/share/ollama ollama
echo "[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
[Install]
WantedBy=default.target" | sudo tee /etc/systemd/system/ollama.service
sudo systemctl daemon-reload
sudo systemctl enable ollama
}
# Function to add Ollama as a startup service on macOS
function setup_service_macos {
sudo defaults write /Library/LaunchDaemons/com.ollama.ollama.plist Label -string "com.ollama.ollama"
sudo defaults write /Library/LaunchDaemons/com.ollama.ollama.plist ProgramArguments -array "/usr/local/bin/ollama" "serve"
sudo defaults write /Library/LaunchDaemons/com.ollama.ollama.plist RunAtLoad -bool true
sudo chown root:wheel /Library/LaunchDaemons/com.ollama.ollama.plist
}
# Detect the operating system and install Ollama if necessary
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
check_ollama_installed
status=$?
if [ $status -eq 2 ]; then
install_ollama_linux
setup_service_linux
sudo systemctl start ollama
fi
if [ $status -ne 0 ]; then
ollama pull llava:v1.6
ollama pull mxbai-embed-large
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
check_ollama_installed
status=$?
if [ $status -eq 2 ]; then
install_ollama_macos
setup_service_macos
sudo launchctl load /Library/LaunchDaemons/com.ollama.ollama.plist
fi
if [ $status -ne 0 ]; then
ollama pull llava:v1.6
ollama pull mxbai-embed-large
fi
else
echo "Unsupported OS. Please install Ollama manually."
exit 1
fi