-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathollama_control_forbash.sh
132 lines (128 loc) · 4.22 KB
/
ollama_control_forbash.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
125
126
127
128
129
130
131
132
#!/bin/bash
# Ollama control for bash
# by superjulien
# > https://github.com/Superjulien
# > https://framagit.org/Superjulien
# V0.3
logo() {
echo ""
echo "##################"
echo "# Ollama Control #"
echo "# for bash #"
echo "# v0.03 #"
echo "##################"
echo ""
}
while true; do
clear
logo
echo "Choose an option:"
echo ""
echo "1: Start ollama server"
echo "2: Update and install ollama"
echo "3: List installed models"
echo "4: Stop ollama"
echo "5: Launch ollama"
echo "6: Check the status of ollama"
echo "7: Quit"
echo ""
if [ ! -z "$result" ]; then
echo -e "$result"
result=""
fi
read -p "> " choice
case $choice in
1)
if sudo systemctl is-active --quiet ollama; then
result="[!] Error: ollama is already active."
else
result="[#] Starting ollama..."
sudo systemctl start ollama
fi
;;
2)
if sudo systemctl is-active --quiet ollama; then
result="[!] Error: ollama is active."
else
result="[#] Updating and installing ollama..."
sudo curl https://ollama.ai/install.sh | sh
fi
;;
3)
if sudo systemctl is-active --quiet ollama; then
result="[#] List of installed models:"
result+="\n"
result+="$(sudo ollama list)"
else
result="[!] Error: ollama is stopped."
fi
;;
4)
if sudo systemctl is-active --quiet ollama; then
result="[#] Stopping ollama..."
sudo systemctl stop ollama
else
result="[!] Error: ollama is already stopped."
fi
;;
5)
while true; do
if sudo systemctl is-active --quiet ollama; then
clear
logo
echo "[#>] List of installed models:"
models=($(ollama list | awk 'NR > 1 {split($1, arr, ":"); print arr[1]}'))
if [ ${#models[@]} -eq 0 ]; then
echo ""
echo "[!] No models installed."
sleep 2
break
else
for ((i=0; i<${#models[@]}; i++)); do
echo "$((i+1)): ${models[i]}"
done
echo ""
echo "Select a model (0 to quit):"
echo ""
read -p "> " model_choice
if [[ "$model_choice" =~ ^[0-9]+$ && "$model_choice" -ge 0 && "$model_choice" -le ${#models[@]} ]]; then
if [ "$model_choice" -eq 0 ]; then
echo ""
echo "[#] Return to main menu."
sleep 1
break
else
selected_model=${models[model_choice-1]}
clear
echo "[#] Launching ollama run with model $selected_model..."
sudo ollama run "$selected_model"
break
fi
else
echo ""
echo "[!] Invalid option. Please select a valid number."
sleep 1
fi
fi
else
result="[!] Error: ollama is stopped."
break
fi
done
;;
6)
if sudo systemctl is-active --quiet ollama; then
result="[#] Ollama is active."
else
result="[#] Ollama is stopped."
fi
;;
7)
result="[#] Exiting the script."
exit 0
;;
*)
result="[!] Invalid option. Please select a valid number."
;;
esac
done