-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_requirements.sh
312 lines (288 loc) · 10.2 KB
/
install_requirements.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
308
309
310
311
312
#!/bin/bash
# This script installs required dependencies for the project.
# How to run this script:
## chmod +x install_requirements.sh
## ./install_requirements.sh
echo "Welcome to the installation script for the project."
echo "This script will install the required dependencies for the project, including Python, Pip, Git, Make, and Maven."
echo "Please ensure you have the necessary permissions to install software on your system."
# Ensure the Project is up-to-date
echo "Pulling the latest changes from the repository..."
git pull
echo "The project is up-to-date."
# Ensure Git submodules are initialized and updated
echo "Initializing and updating Git submodules..."
git submodule init
git submodule update
echo "Git submodules are up-to-date."
# Detect OS
OS=""
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="Linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="MacOS"
elif [[ "$OSTYPE" == "msys"* ]] || [[ "$OSTYPE" == "cygwin"* ]] || [[ "$OSTYPE" == "win32" ]]; then
OS="Windows"
else
echo "Unsupported OS."
exit 1
fi
echo "Detected OS: $OS"
# Function to check if a command exists
command_exists() {
command -v "$1" &> /dev/null
}
# Install Python and Pip
install_python_pip() {
if command_exists python3 && command_exists pip3; then
echo "Python and Pip are already installed."
else
echo "Installing Python and Pip..."
case "$OS" in
Linux)
sudo apt update
sudo apt install python3 python3-pip python3-venv -y
;;
MacOS)
# Install Python 3 using Homebrew
brew install python
# Ensure pip and venv are also installed with Python
python3 -m ensurepip --upgrade
python3 -m pip install --upgrade pip
python3 -m pip install virtualenv
;;
Windows)
# Check if Python is installed using Chocolatey
if ! command_exists python; then
echo "Installing Python using Chocolatey..."
echo "This requires Chocolatey to be installed."
choco install python --params "/InstallDir:C:\Python39" -y
fi
# Ensure pip is installed
if ! command_exists pip; then
echo "Installing pip..."
curl -sS https://bootstrap.pypa.io/get-pip.py | python
fi
# Install virtualenv
pip install --user virtualenv
;;
esac
echo "Python and Pip installation complete."
fi
}
# Install C/C++ Compiler
install_c_cpp_compiler() {
if command_exists gcc && command_exists g++; then
echo "C/C++ are already installed."
else
echo "Installing C/C++ Compiler..."
case "$OS" in
Linux)
sudo apt install build-essential -y
;;
MacOS)
echo "Build tools are included with Xcode Command Line Tools. Installing..."
xcode-select --install
;;
Windows)
echo "Please install build tools manually using MinGW from https://sourceforge.net/projects/mingw/."
;;
esac
echo "C/C++ Compiler installation complete."
fi
}
# Function to check if Java is installed and install it if not
install_java() {
if ! command -v java &> /dev/null; then
echo "Java is not installed. Installing Java..."
case "$OS" in
Linux)
sudo apt install -y default-jdk
;;
MacOS)
brew install openjdk
;;
Windows)
echo "Please install Java manually on Windows from https://www.java.com/"
exit 1
;;
esac
echo "Java installation complete."
else
echo "Java is already installed."
fi
}
# Function to set JAVA_HOME if not already set
setup_java_home() {
if [[ -z "$JAVA_HOME" ]]; then
echo "JAVA_HOME is not set. Attempting to configure it automatically..."
JAVA_VERSION=$(java -version 2>&1 | awk -F[\"._] '/version/ {print $2}')
case "$OS" in
Linux)
JAVA_HOME_CANDIDATE=$(ls /usr/lib/jvm | grep -E "java-?$JAVA_VERSION-openjdk-" | head -n 1)
if [[ -n "$JAVA_HOME_CANDIDATE" ]]; then
JAVA_HOME="/usr/lib/jvm/$JAVA_HOME_CANDIDATE"
# Check if JAVA_HOME_CANDIDATE is a directory
if [[ -d "$JAVA_HOME" ]]; then
echo "export JAVA_HOME=$JAVA_HOME" >> ~/.bashrc
export JAVA_HOME="$JAVA_HOME" # Export for current session
# Capture the output of echoing JAVA_HOME
CURRENT_JAVA_HOME=$(echo "$JAVA_HOME")
echo "JAVA_HOME set to $CURRENT_JAVA_HOME"
# Verify if JAVA_HOME is set correctly after export
if [[ -z "$CURRENT_JAVA_HOME" ]]; then
echo "WARNING: JAVA_HOME is not set correctly. Please run the following command to set it manually:"
echo "export JAVA_HOME=$JAVA_HOME"
else
echo "JAVA_HOME is set correctly with the command 'export JAVA_HOME=$JAVA_HOME'."
fi
echo "Note: To make this change permanent, please run 'source ~/.bashrc' or restart your terminal."
else
echo "WARNING: JAVA_HOME_CANDIDATE ($JAVA_HOME) is not a directory. Please set JAVA_HOME manually."
fi
else
echo "No matching Java installation found in /usr/lib/jvm for Java version $JAVA_VERSION."
echo "Please set JAVA_HOME manually."
fi
;;
MacOS)
JAVA_HOME=$(/usr/libexec/java_home -v "$JAVA_VERSION" 2>/dev/null)
if [[ -n "$JAVA_HOME" ]]; then
export JAVA_HOME
echo "JAVA_HOME set to $JAVA_HOME"
# Add JAVA_HOME to .bashrc or .zshrc
SHELL_CONFIG="$HOME/.bashrc"
if [[ $SHELL == *"zsh"* ]]; then
SHELL_CONFIG="$HOME/.zshrc"
fi
# Check if JAVA_HOME is already in the config file
if ! grep -q "export JAVA_HOME=" "$SHELL_CONFIG"; then
echo "export JAVA_HOME=\"$JAVA_HOME\"" >> "$SHELL_CONFIG"
echo "Added JAVA_HOME to $SHELL_CONFIG."
else
echo "JAVA_HOME is already set in $SHELL_CONFIG."
fi
# Source the config file
source "$SHELL_CONFIG"
echo "Sourced $SHELL_CONFIG to apply changes."
else
echo "No matching Java installation found. Please set JAVA_HOME manually."
fi
;;
Windows)
JAVA_PATHS=("C:\\Program Files\\Java" "C:\\Program Files (x86)\\Java")
for path in "${JAVA_PATHS[@]}"; do
JAVA_HOME_CANDIDATE=$(ls "$path" | grep -E "jdk-$JAVA_VERSION" | head -n 1)
if [[ -n "$JAVA_HOME_CANDIDATE" ]]; then
export JAVA_HOME="$path\\$JAVA_HOME_CANDIDATE"
echo "JAVA_HOME set to $JAVA_HOME"
echo "To make this change permanent, add the following line to your environment variables:"
echo "JAVA_HOME=$JAVA_HOME"
break
fi
done
if [[ -z "$JAVA_HOME" ]]; then
echo "No matching Java installation found in standard paths on Windows."
echo "Please set JAVA_HOME manually."
fi
;;
esac
else
echo "JAVA_HOME is already set to $JAVA_HOME."
fi
}
# Install Git
install_git() {
if command_exists git; then
echo "Git is already installed."
else
echo "Installing Git..."
case "$OS" in
Linux)
sudo apt update
sudo apt install git -y
;;
MacOS)
brew install git
;;
Windows)
echo "Please install Git manually from https://git-scm.com/downloads."
;;
esac
echo "Git installation complete."
fi
}
# Install Make
install_make() {
if command_exists make; then
echo "Make is already installed."
else
echo "Installing Make..."
case "$OS" in
Linux)
sudo apt update
sudo apt install make -y
;;
MacOS)
brew install make
;;
Windows)
echo "Please install Make as part of a Unix-like environment (e.g., Cygwin or WSL) or download from https://www.gnu.org/software/make/#download."
;;
esac
echo "Make installation complete."
fi
}
# Install Maven
install_maven() {
if command_exists mvn; then
echo "Maven is already installed."
else
echo "Installing Apache Maven..."
case "$OS" in
Linux)
sudo apt update
sudo apt install maven -y
;;
MacOS)
brew install maven
;;
Windows)
echo "Please install Maven manually from https://maven.apache.org/download.cgi or use Chocolatey:"
echo "choco install maven"
;;
esac
echo "Maven installation complete."
fi
}
# Set up .env file
setup_env_file() {
if [[ -f ".env" ]]; then
echo ".env file already exists. Please edit it to fill in your API keys and tokens."
else
if [[ -f ".env-example" ]]; then
echo "Copying .env-example to .env..."
cp .env-example .env
echo ".env file created. Please fill in your API keys and tokens."
else
echo ".env-example file not found. Creating .env file manually..."
touch .env-example
echo "GEMINI_API_KEY=" > .env-example
echo 'GITHUB_TOKEN=""' >> .env-example
cp .env-example .env
fi
echo ".env file setup complete."
fi
echo "Read the .env file section in the README.md for more information on how to fill in the required API keys and Tokens."
}
# Run installation functions
install_python_pip
install_c_cpp_compiler
install_java
setup_java_home
install_git
install_make
install_maven
setup_env_file
echo "Please, check for any errors in the installation process in the log messages above."
echo "All required dependencies should now be installed."