-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
307 lines (276 loc) · 9 KB
/
install.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#!/bin/bash
# Global variable to identify if running in a Jupyter environment
IS_JUPYTER=false
if [ -d "/kaggle/working/Ollama-Colab-Integration-Kaggle/" ]; then
IS_JUPYTER=true
fi
# Function to check if a command exists in executable paths
is_command_installed() {
command -v "$1" >/dev/null 2>&1
}
# Function to check if a specific version of Python is installed
is_python_installed() {
if is_command_installed python3; then
local python_version=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
if [[ "$python_version" < "3.10" ]]; then
echo "Python 3.10 or later is required. Installed version is $python_version."
return 1
fi
echo "Python 3.10 or later is already installed."
return 0
else
echo "Python 3.10 is not installed."
return 1
fi
}
# Function to check if Docker is installed
is_docker_installed() {
is_command_installed docker
}
# Function to install Docker based on OS
install_docker() {
if is_docker_installed; then
echo "Docker is already installed."
return 0
fi
local os=$(detect_os)
case "$os" in
debian)
sudo apt-get update && sudo apt-get install -y docker.io
;;
redhat)
sudo yum update && sudo yum install -y docker
;;
arch)
sudo pacman -Syu && sudo pacman -S docker
;;
macos)
brew install docker
;;
*)
echo "Unsupported OS for Docker installation."
return 1
;;
esac
echo "Docker installed successfully."
return 0
}
# Function to configure Docker
configure_docker() {
local os=$(detect_os)
if [ "$os" != "macos" ] && [ "$os" != "jupyter" ]; then
sudo groupadd docker 2>/dev/null || true
sudo usermod -aG docker $USER
sudo systemctl start docker
sudo systemctl enable docker
echo "Docker configured successfully."
else
echo "Docker configuration not required for macOS or Jupyter environments."
fi
return 0
}
# Function to install essential packages
install_packages() {
local packages=("gcc" "make" "aria2" "git" "pciutils" )
local install_needed=false
for package in "${packages[@]}"; do
if ! is_command_installed "$package"; then
install_needed=true
break
fi
done
if [ "$install_needed" = false ]; then
echo "All essential packages are already installed."
return 0
fi
local os=$(detect_os)
case "$os" in
debian)
sudo apt-get update && sudo apt-get install -y "${packages[@]}"
;;
redhat)
sudo yum update && sudo yum install -y "${packages[@]}"
;;
arch)
sudo pacman -Syu && sudo pacman -S --noconfirm "${packages[@]}"
;;
macos)
brew install "${packages[@]}"
;;
*)
echo "Unsupported OS for package installation."
return 1
;;
esac
echo "Packages installed successfully."
return 0
}
# Function to change ownership and permissions of all files and directories
change_file_ownership() {
# Check if running in Jupyter environment
if $IS_JUPYTER; then
echo "In Jupyter environment, skipping chown commands."
return 0
fi
local script_dir="/kaggle/working/Ollama-Colab-Integration-Kaggle"
echo "Changing ownership of all files and directories in $script_dir for Linux environment..."
# Change ownership to the current user for all files and directories
find "$script_dir" -exec chown $USER {} \;
# Change file permissions to read, write, and execute for the owner
find "$script_dir" -type f -exec chmod u+rwx {} \;
find "$script_dir" -type d -exec chmod u+rwx {} \;
echo "Ownership and permissions changed successfully."
}
# Function to determine the operating system
detect_os() {
if is_jupyter; then
echo "jupyter"
return 0
fi
local os_name=$(uname -s)
case "$os_name" in
Darwin)
echo "macos"
;;
Linux)
if grep -qi ubuntu /etc/os-release; then
echo "debian"
elif grep -qi centos /etc/os-release; then
echo "redhat"
elif grep -qi arch /etc/os-release; then
echo "arch"
else
echo "Unsupported Linux OS."
return 1
fi
;;
*)
echo "Unsupported OS."
return 1
;;
esac
return 0
}
# Function to clone the llama.cpp repository
clone_repository() {
if $IS_JUPYTER; then
mkdir -p /kaggle/working/Ollama-Colab-Integration-Kaggle
if git clone https://github.com/Fatin-Ishraq/Ollama-Colab-Integration-Kaggle.git /kaggle/working/Ollama-Colab-Integration-Kaggle/llama.cpp; then
echo "Repository cloned successfully into Jupyter environment."
else
echo "Failed to clone repository into Jupyter environment."
return 1
fi
elif git clone https://github.com/Fatin-Ishraq/Ollama-Colab-Integration-Kaggle.git; then
echo "Repository cloned successfully."
else
echo "Failed to clone repository."
return 1
fi
return 0
}
# Function to install Python requirements
install_python_requirements() {
local required_packages=("streamlit" "requests" "flask" "flask-cloudflared" "httpx" "litellm" "huggingface_hub" "asyncio" "Pyyaml" "httpx" "APScheduler" "cryptography" "pycloudflared" "numpy==1.24.4" "sentencepiece==0.1.98" "transformers>=4.34.0" "gguf>=0.1.0" "protobuf>=4.21.0" "torch==2.1.1" "transformers==4.35.2")
for package in "${required_packages[@]}"; do
if pip install "$package"; then
echo "$package installed successfully."
else
echo "Failed to install $package."
return 1
fi
done
echo "All required Python packages installed successfully."
return 0
}
# Function to build llama.cpp
build_llama_cpp() {
if $IS_JUPYTER; then
# Jupyter Notebook specific build steps
if [ -d "/kaggle/working/Ollama-Colab-Integration-Kaggle/llama.cpp" ]; then
if make -C /kaggle/working/Ollama-Colab-Integration-Kaggle/llama.cpp; then
echo "llama.cpp built successfully in Jupyter Notebook environment."
else
echo "Failed to build llama.cpp in Jupyter Notebook environment."
return 1
fi
else
echo "/kaggle/working/Ollama-Colab-Integration-Kaggle/llama.cpp directory not found."
return 1
fi
else
# Existing logic for other environments
if [ -d "llama.cpp" ]; then
cd llama.cpp || return 1
if make; then
echo "llama.cpp built successfully using make."
else
echo "Failed to build llama.cpp using make."
return 1
fi
cd - || return 1
else
echo "llama.cpp directory not found."
return 1
fi
fi
return 0
}
# Function to install Ollama
install_ollama() {
if $IS_JUPYTER; then
mkdir -p /kaggle/working/Ollama-Colab-Integration-Kaggle
curl https://ollama.ai/install.sh > /kaggle/working/Ollama-Colab-Integration-Kaggle/ollama_install.sh
chmod +x /kaggle/working/Ollama-Colab-Integration-Kaggle/ollama_install.sh
/kaggle/working/Ollama-Colab-Integration-Kaggle/ollama_install.sh
echo "Ollama installed in Jupyter environment."
else
read -p "Do you want to install Ollama on this host? (y/n) " answer
case $answer in
[Yy]* )
curl https://ollama.ai/install.sh | sh
echo "Ollama installed on this host."
;;
* )
echo "Ollama installation skipped."
;;
esac
fi
}
# Function to run the key_generation script
run_key_generation() {
local script_dir="/kaggle/working/Ollama-Colab-Integration-Kaggle"
pushd "$script_dir" > /dev/null || return 1
if python3 "./key_generation.py"; then
echo "Key generation script executed successfully."
else
echo "Key generation script execution failed."
popd > /dev/null || return 1
return 1
fi
popd > /dev/null || return 1
return 0
}
# Main function
main() {
local os=$(detect_os)
if [ "$os" = "Unsupported OS." ]; then
echo "Exiting due to unsupported OS."
exit 1
fi
if ! is_python_installed; then
echo "Python 3.10 or later is required but not installed. Exiting."
exit 1
fi
install_docker "$os" && configure_docker "$os"
install_packages "$os"
clone_repository
build_llama_cpp
install_python_requirements
change_file_ownership
install_ollama
run_key_generation
echo "Installation complete."
}
# Run main function
main