-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathollama.sh
executable file
·124 lines (103 loc) · 1.96 KB
/
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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
set -e
cat << "EOF"
_ _
| | |
___ | | | __ _ _ __ ___ __ _
/ _ \| | |/ _` | '_ ` _ \ / _` |
| (_) | | | (_| | | | | | | (_| |
\___/|_|_|\__,_|_| |_| |_|\__,_|
EOF
cat << EOF
Ollama Container Helper
v0.1 by Sébastien Dominguez
https://github.com/SebDominguez
===================================================
EOF
CYAN='\033[0;36m'
RED='\033[1;31m'
NC='\033[0m' # No Color
# Get the directory of the current script
DIR=$(dirname "$(readlink -f "$0")")
# Get the path of the docker-compose.yml file
COMPOSE_FILE=$DIR/docker-compose.yml
# Check if docker-compose exist. If it doesnt then we use docker compose instead
if command -v docker-compose &> /dev/null
then
dccmd='docker-compose'
else
dccmd='docker compose'
fi
function dockerComposeDown() {
if [ $($dccmd ps | wc -l) -gt 2 ]; then
$dccmd -f $COMPOSE_FILE down
fi
}
# Functions
function restart() {
dockerComposeDown
dockerComposeUp
}
function dockerComposeUp() {
$dccmd -f $COMPOSE_FILE up -d
}
function dockerPull() {
$dccmd pull
}
function update() {
dockerComposeDown
dockerPull
dockerComposeUp
}
function listModel(){
docker exec -it ollama ollama list
}
function pullModel(){
docker exec -it ollama ollama pull $1
}
function deleteModel(){
docker exec -it ollama ollama rm $1
}
function listCommands() {
cat << EOT
Available commands:
start
stop
update
pullmodel
listmodel
deletemodel
help
EOT
}
# Commands
case $1 in
"start")
dockerComposeUp
;;
"update")
update
;;
"restart")
restart
;;
"stop")
dockerComposeDown
;;
"listmodel")
listModel
;;
"pullmodel")
pullModel "$2"
;;
"deletemodel")
deleteModel "$2"
;;
"help")
listCommands
;;
*)
echo "No command found."
echo
listCommands
esac