-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·423 lines (367 loc) · 13.4 KB
/
setup.sh
File metadata and controls
executable file
·423 lines (367 loc) · 13.4 KB
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#!/bin/bash
# ICPC AutoAnalyst Setup Script
# This script sets up the complete ICPC AutoAnalyst environment
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Logging functions
log_info() {
echo -e "${BLUE}[INFO]${NC} $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if running as root
check_root() {
if [[ $EUID -eq 0 ]]; then
log_error "This script should not be run as root for security reasons"
log_info "Please run as a regular user with sudo privileges"
exit 1
fi
}
# Detect operating system
detect_os() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v apt-get &> /dev/null; then
OS="ubuntu"
log_info "Detected Ubuntu/Debian system"
elif command -v yum &> /dev/null; then
OS="rhel"
log_info "Detected RHEL/CentOS system"
elif command -v pacman &> /dev/null; then
OS="arch"
log_info "Detected Arch Linux system"
else
log_error "Unsupported Linux distribution"
exit 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
log_info "Detected macOS system"
else
log_error "Unsupported operating system: $OSTYPE"
exit 1
fi
}
# Install dependencies based on OS
install_dependencies() {
log_info "Installing system dependencies..."
case $OS in
"ubuntu")
sudo apt-get update
sudo apt-get install -y \
apache2 \
php \
php-cli \
php-mysql \
php-yaml \
php-curl \
php-mbstring \
php-xml \
libapache2-mod-php \
mariadb-server \
mariadb-client \
python3 \
python3-pip \
python3-dev \
python3-mysqldb \
python3-yaml \
openjdk-21-jdk \
git \
curl \
wget \
unzip \
build-essential \
default-libmysqlclient-dev
;;
"macos")
if ! command -v brew &> /dev/null; then
log_error "Homebrew is required but not installed"
log_info "Please install Homebrew first: https://brew.sh/"
exit 1
fi
brew update
brew install \
httpd \
php \
mysql \
python3 \
openjdk@21 \
git \
curl \
wget \
unzip
# Install PHP extensions
brew install php-yaml || log_warning "php-yaml not available via brew"
# Install Python packages
pip3 install --user PyMySQL PyYAML
;;
"rhel")
sudo yum update -y
sudo yum install -y \
httpd \
php \
php-cli \
php-mysql \
php-curl \
php-mbstring \
php-xml \
mariadb-server \
mariadb \
python3 \
python3-pip \
python3-devel \
java-21-openjdk-devel \
git \
curl \
wget \
unzip \
gcc \
gcc-c++ \
make
;;
"arch")
sudo pacman -Syu --noconfirm
sudo pacman -S --noconfirm \
apache \
php \
php-apache \
mariadb \
python \
python-pip \
jdk21-openjdk \
git \
curl \
wget \
unzip \
base-devel
;;
esac
log_success "System dependencies installed"
}
# Configure Apache
configure_apache() {
log_info "Configuring Apache web server..."
case $OS in
"ubuntu")
# Enable required modules
sudo a2enmod rewrite proxy_http
# Create virtual host configuration
sudo tee /etc/apache2/sites-available/autoanalyst.conf > /dev/null <<EOF
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/html
ErrorLog \${APACHE_LOG_DIR}/error.log
CustomLog \${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/icat>
AllowOverride All
Require all granted
</Directory>
ProxyPassMatch ^/icat/api/(EventFeed|scoreboard|teams)$ http://localhost:8099/\$1
<Location "/icat/api/">
RewriteEngine On
RewriteRule icat/api/(CodeActivity|EditActivity|LastEditActivity|LastEditedNotSolvedProblem)$ /icat/api/\$1.php
</Location>
</VirtualHost>
EOF
# Enable the site
sudo a2ensite autoanalyst
sudo a2dissite 000-default || true
# Create symlink for web files
sudo rm -rf /var/www/html
sudo ln -sf "$(pwd)/www" /var/www/html
# Set permissions
sudo chown -R www-data:www-data "$(pwd)/www" || true
sudo find "$(pwd)/www" -type d -exec chmod 755 {} +
# Restart Apache
sudo systemctl restart apache2
sudo systemctl enable apache2
;;
"macos")
# macOS Apache configuration
APACHE_CONFIG="/usr/local/etc/httpd/httpd.conf"
# Basic Apache configuration for macOS
log_info "Please manually configure Apache on macOS"
log_info "Web files are in: $(pwd)/www"
;;
"rhel"|"arch")
# Similar configuration for RHEL/Arch
log_info "Please manually configure Apache for your distribution"
log_info "Web files are in: $(pwd)/www"
;;
esac
log_success "Apache configured"
}
# Configure MySQL/MariaDB
configure_database() {
log_info "Configuring MySQL/MariaDB database..."
case $OS in
"ubuntu")
# Start MySQL service
sudo systemctl start mysql
sudo systemctl enable mysql
# Secure installation (basic)
sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'autoanalyst';" || true
;;
"macos")
# Start MySQL service
brew services start mysql
;;
"rhel"|"arch")
# Start MariaDB service
sudo systemctl start mariadb
sudo systemctl enable mariadb
;;
esac
# Wait for MySQL to start
sleep 5
# Create database and user
mysql -u root -pautoanalyst -e "CREATE DATABASE IF NOT EXISTS icat;" 2>/dev/null || \
mysql -u root -e "CREATE DATABASE IF NOT EXISTS icat;" 2>/dev/null || \
sudo mysql -e "CREATE DATABASE IF NOT EXISTS icat;"
mysql -u root -pautoanalyst -e "CREATE USER IF NOT EXISTS 'autoanalyst'@'localhost' IDENTIFIED BY 'autoanalyst';" 2>/dev/null || \
mysql -u root -e "CREATE USER IF NOT EXISTS 'autoanalyst'@'localhost' IDENTIFIED BY 'autoanalyst';" 2>/dev/null || \
sudo mysql -e "CREATE USER IF NOT EXISTS 'autoanalyst'@'localhost' IDENTIFIED BY 'autoanalyst';"
mysql -u root -pautoanalyst -e "GRANT ALL PRIVILEGES ON icat.* TO 'autoanalyst'@'localhost';" 2>/dev/null || \
mysql -u root -e "GRANT ALL PRIVILEGES ON icat.* TO 'autoanalyst'@'localhost';" 2>/dev/null || \
sudo mysql -e "GRANT ALL PRIVILEGES ON icat.* TO 'autoanalyst'@'localhost';"
mysql -u root -pautoanalyst -e "FLUSH PRIVILEGES;" 2>/dev/null || \
mysql -u root -e "FLUSH PRIVILEGES;" 2>/dev/null || \
sudo mysql -e "FLUSH PRIVILEGES;"
# Initialize database schema if available
if [[ -f "create_icat_instance.sql" ]]; then
log_info "Initializing database schema..."
mysql -u autoanalyst -pautoanalyst icat < create_icat_instance.sql 2>/dev/null || \
log_warning "Could not initialize database schema automatically"
fi
log_success "Database configured"
}
# Create configuration file
create_config() {
log_info "Creating configuration file..."
if [[ ! -f "config.yaml" ]]; then
if [[ -f "config.yaml.template" ]]; then
cp config.yaml.template config.yaml
# Update configuration with default values
sed -i.bak 's/THISISNOTAPASSWORD/autoanalyst/g' config.yaml
sed -i.bak 's/localhost/localhost/g' config.yaml
rm config.yaml.bak 2>/dev/null || true
log_success "Configuration file created from template"
else
log_error "config.yaml.template not found"
exit 1
fi
else
log_info "Configuration file already exists"
fi
}
# Build Katalyzer
build_katalyzer() {
log_info "Building Katalyzer application..."
if [[ -d "katalyze" ]]; then
cd katalyze
./gradlew install
cd - > /dev/null
log_success "Katalyzer build completed"
else
log_warning "Katalyze directory not found, skipping build"
fi
}
# Set up directory structure
setup_directories() {
log_info "Setting up directory structure..."
# Create necessary directories
mkdir -p backup
mkdir -p githomes
mkdir -p logs
# Set permissions
sudo chmod 755 backup githomes logs
dir="$(pwd)"
while [ "$dir" != "/" ]; do
sudo chmod a+x "$dir"
dir="$(dirname "$dir")"
done
log_success "Directory structure created"
}
# Install Python dependencies
install_python_deps() {
log_info "Installing Python dependencies..."
# Install required Python packages
pip3 install --user PyMySQL PyYAML 2>/dev/null || \
python3 -m pip install --user PyMySQL PyYAML 2>/dev/null || \
log_warning "Could not install Python dependencies"
log_success "Python dependencies installed"
}
# Display final information
show_completion_info() {
echo
log_success "ICPC AutoAnalyst setup completed!"
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " 🎉 Setup Complete!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo
echo "📁 Project directory: $(pwd)"
echo "🌐 Web interface: http://localhost/icat/"
echo "🔧 Katalyzer API: http://localhost:8099/ (when running)"
echo "🗄️ Database: icat (user: autoanalyst, password: autoanalyst)"
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " 📋 Next Steps:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo
echo "1. 🚀 Start Katalyzer:"
echo " cd katalyze && java -jar build/libs/katalyze-1.0-SNAPSHOT.jar"
echo
echo "2. 🔧 Run Python code analyzer:"
echo " cd code_analyzer && python3 analyzer.py"
echo
echo "3. ⚙️ Edit configuration:"
echo " vim config.yaml"
echo
echo "4. 🌐 Access web interface:"
echo " Open http://localhost/icat/ in your browser"
echo
echo "5. 🗄️ Access database:"
echo " mysql -u autoanalyst -pautoanalyst icat"
echo
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " 🔍 Troubleshooting:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo
echo "• Check Apache status: sudo systemctl status apache2"
echo "• Check MySQL status: sudo systemctl status mysql"
echo "• View Apache logs: sudo tail -f /var/log/apache2/error.log"
echo "• Test database: mysql -u autoanalyst -pautoanalyst -e 'SHOW DATABASES;'"
echo
echo "🎯 The system is ready for testing ICPC contest analysis!"
echo
}
# Main execution
main() {
echo "🚀 ICPC AutoAnalyst Setup Script"
echo "=================================="
echo
check_root
detect_os
install_dependencies
create_config
setup_directories
configure_apache
configure_database
install_python_deps
build_katalyzer
show_completion_info
}
# Run main function
main "$@"