-
Notifications
You must be signed in to change notification settings - Fork 1
/
Install.bash
executable file
·396 lines (386 loc) · 19.6 KB
/
Install.bash
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
#!/bin/bash
TerminalWidth=$(tput cols)
PasswordSalt1=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
PasswordSalt2=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
function BeginSection() {
echo -e "╭$(printf '─%.0s' $(seq 1 $((TerminalWidth - 2))))╮\033[3G $1 "
}
function EndSection() {
echo -e "╰$(printf '─%.0s' $(seq 1 $((TerminalWidth - 2))))╯"
echo ""
}
function Output() {
echo -e "│$(printf ' %.0s' $(seq 1 $((TerminalWidth - 2))))│\033[3G$1"
echo -e "╰$(printf '─%.0s' $(seq 1 $((TerminalWidth - 2))))╯"
echo -n -e "\033[1A"
if [ "$2" == "-n" ]; then
echo -n -e "\033[1A\033[$((${#1} - 13))C"
fi
}
function Error() {
Output "\033[31m✗ $1\033[0m"
}
function Success() {
Output "\033[32m✓ $1\033[0m"
}
function Warning() {
Output "\033[33m⚠ $1\033[0m"
}
function Wait() {
Output "\033[34m○ $1\033[0m"
echo -e "\033[2A"
}
function Confirm() {
Output "\033[35m? $1 (Y/n) \033[0m" -n
read -n 1 -p "" ConfirmData
echo -e "\033[?25l"
if [ "$ConfirmData" == "Y" ] || [ "$ConfirmData" == "y" ]; then
return 1
elif [ "$ConfirmData" == "" ]; then
echo -n -e "\033[1A"
return 1
elif [ "$ConfirmData" == "N" ] || [ "$ConfirmData" == "n" ]; then
return 0
else
Confirm "$1"
return $?
fi
}
function Input() {
Output "\033[36m? $1 \033[0m" -n
if [ "$2" == "-p" ]; then
read -s -p "" InputData
else
read -p "" InputData
fi
echo -e "\033[?25l"
if [ "$2" != "-p" ]; then
echo -n -e "\033[1A"
fi
export InputResult=$InputData
}
function BasicChecks() {
BeginSection "Basic checks"
if [ ! -f /etc/os-release ] || [ $(cat /etc/os-release | grep -c "Ubuntu") -eq 0 ]; then
Error "This script only supports Ubuntu."
EndSection
exit
elif [ $(id -u) -ne 0 ]; then
Error "Please run with root privilege."
EndSection
exit
else
Success "All checks passed."
fi
EndSection
}
function InstallPackages() {
BeginSection "Install packages"
Wait "Updating package list..."
apt-get update >/dev/null 2>&1
if [ $? -ne 0 ]; then
Error "Failed to update package list."
EndSection
exit
else
Success "Package list updated."
fi
Wait "Upgrading packages..."
apt-get upgrade -y >/dev/null 2>&1
if [ $? -ne 0 ]; then
Error "Failed to upgrade packages."
EndSection
exit
else
Success "Packages upgraded."
fi
Wait "Installing packages..."
apt-get install g++ make cmake git libcurl4-gnutls-dev mysql-client mysql-server libmysqlcppconn-dev mount libssl-dev libminizip-dev -y >/dev/null 2>&1
if [ $? -ne 0 ]; then
Error "Failed to install packages."
EndSection
exit
else
Success "Packages installed."
fi
EndSection
}
function CloneRepo() {
BeginSection "Clone repo"
if [ -d ./OJ ]; then
git config --global safe.directory '*' >/dev/null 2>&1
if [ $(git -C ./OJ remote -v | grep -c "CYEZOI/OJ.git") -gt 0 ]; then
Wait "Updating repo..."
git -C ./OJ pull --depth 1 >/dev/null 2>&1
if [ $? -ne 0 ]; then
Error "Failed to update repo."
EndSection
exit
else
Success "Repo updated."
fi
EndSection
return
else
Error "Folder \"OJ\" already exists and is not a git repo or the url is incorrect."
EndSection
exit
fi
fi
Wait "Cloning repo..."
git clone https://github.com/CYEZOI/OJ.git --depth 1 >/dev/null 2>&1
if [ $? -ne 0 ]; then
Error "Failed to clone repo."
EndSection
exit
else
Success "Repo cloned."
fi
EndSection
}
function CreateJudgeUser() {
BeginSection "Create judge user"
if [ $(cat /etc/passwd | grep -c "Judger") -ne 0 ]; then
Warning "Judge user already exists."
EndSection
return
fi
Wait "Creating judge user..."
groupadd judge
useradd Judger -g judge
passwd Judger -d >/dev/null 2>&1
mkdir /home/Judger
chown -R Judger /home/Judger
chgrp -R judge /home/Judger
echo -e "Judger\tALL=(ALL:ALL) ALL" | tee -a /etc/sudoers >/dev/null 2>&1
chmod a+s /bin/chgrp
chmod a+s /bin/chown
mkdir /home/Judger/Run
chown -R Judger /home/Judger/Run
chgrp -R judge /home/Judger/Run
mkdir /home/Judger/IOData
chown -R Judger /home/Judger/IOData
chgrp -R judge /home/Judger/IOData
if [ $? -ne 0 ]; then
Error "Failed to create judge user."
EndSection
exit
else
Success "Judge user created."
fi
EndSection
}
function ConfigDatabase() {
BeginSection "Config database"
usermod -d /var/lib/mysql/ mysql >/dev/null 2>&1
service mysql start >/dev/null 2>&1
if [ $? -ne 0 ]; then
Error "Failed to start mysql service."
EndSection
exit
else
Success "Mysql service started."
fi
if [ -d /etc/OJ ]; then
if [ -f /etc/OJ/DatabaseHost ] && [ -f /etc/OJ/DatabasePort ] && [ -f /etc/OJ/DatabaseUsername ] && [ -f /etc/OJ/DatabasePassword ] && [ -f /etc/OJ/DatabaseName ]; then
echo "[client]" > /etc/OJ/DatabaseConfig.cnf
echo "user = \"$(cat /etc/OJ/DatabaseUsername)\"" >> /etc/OJ/DatabaseConfig.cnf
echo "password = \"$(cat /etc/OJ/DatabasePassword)\"" >> /etc/OJ/DatabaseConfig.cnf
echo "host = \"$(cat /etc/OJ/DatabaseHost)\"" >> /etc/OJ/DatabaseConfig.cnf
echo "port = \"$(cat /etc/OJ/DatabasePort)\"" >> /etc/OJ/DatabaseConfig.cnf
echo "database = \"$(cat /etc/OJ/DatabaseName)\"" >> /etc/OJ/DatabaseConfig.cnf
mysql --defaults-extra-file=/etc/OJ/DatabaseConfig.cnf -e "SELECT 1;" >/dev/null 2>&1
if [ $? -ne 0 ]; then
Error "Failed to login to database with the config files in \"/etc/OJ\"."
Confirm "Do you want to reconfigure the database?"
if [ $? -eq 1 ]; then
rm -rf /etc/OJ >/dev/null 2>&1
else
EndSection
exit
fi
else
Warning "Database already configured."
EndSection
return
fi
else
Error "Folder \"/etc/OJ\" already exists and is not a valid database config folder."
Confirm "Do you want to remove the folder \"/etc/OJ\" and reconfigure the database?"
if [ $? -eq 1 ]; then
rm -rf /etc/OJ >/dev/null 2>&1
else
EndSection
exit
fi
fi
fi
DatabaseUsername="OJUser"
DatabasePassword=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
MYSQL_PWD=$DatabasePassword
mkdir /etc/OJ
echo "localhost" >/etc/OJ/DatabaseHost
echo "3306" >/etc/OJ/DatabasePort
echo "$DatabaseUsername" >/etc/OJ/DatabaseUsername
echo "$DatabasePassword" >/etc/OJ/DatabasePassword
echo "OJ" >/etc/OJ/DatabaseName
Success "Database configure files created."
echo "CREATE DATABASE OJ;" >./ConfigDatabase.sql
echo "CREATE USER $DatabaseUsername IDENTIFIED BY \"$DatabasePassword\";" >>./ConfigDatabase.sql
echo "GRANT ALL ON OJ.* TO $DatabaseUsername;" >>./ConfigDatabase.sql
echo "FLUSH PRIVILEGES;" >>./ConfigDatabase.sql
mysql <./ConfigDatabase.sql
if [ $? -ne 0 ]; then
Error "Failed to create database \"OJ\" and user \"$DatabaseUsername\" using file \"./ConfigDatabase.sql\"."
Warning "Maybe either the database or the user already exists."
Confirm "Do you want to remove the database and user (MAY CAUSE DATA LOSS)?"
if [ $? -eq 1 ]; then
echo "DROP DATABASE OJ IF EXISTS;" >./RemoveDatabase.sql
echo "DROP USER $DatabaseUsername IF EXISTS;" >>./RemoveDatabase.sql
mysql <./RemoveDatabase.sql
if [ $? -ne 0 ]; then
Error "Failed to remove database \"OJ\" or user \"$DatabaseUsername\"."
else
Success "Database removed, please rerun this script."
fi
fi
EndSection
exit
else
Success "Database created."
fi
echo "[client]" > /etc/OJ/DatabaseConfig.cnf
echo "user = \"$DatabaseUsername\"" >> /etc/OJ/DatabaseConfig.cnf
echo "password = \"$DatabasePassword\"" >> /etc/OJ/DatabaseConfig.cnf
echo "host = \"localhost\"" >> /etc/OJ/DatabaseConfig.cnf
echo "port = \"3306\"" >> /etc/OJ/DatabaseConfig.cnf
echo "database = \"OJ\"" >> /etc/OJ/DatabaseConfig.cnf
EndSection
}
function CreateTables() {
BeginSection "Create tables"
Wait "Creating tables..."
mysql $(cat /etc/OJ/DatabaseName) <./OJ/Database.sql
if [ $? -ne 0 ]; then
Error "Failed to import database using file \"./OJ/Database.sql\"."
EndSection
exit
else
Success "Database imported."
fi
EndSection
}
function CreateAdminAccount() {
BeginSection "Create admin account"
if [ $(mysql -e "SELECT COUNT(*) FROM Users WHERE Role = 0;" $(cat /etc/OJ/DatabaseName) | grep -c "0") -eq 1 ]; then
Input "Please enter the username of the admin account."
AdminUsername=$InputResult
while [ 1 ]; do
Input "Please enter the password of the admin account." -p
AdminPassword=$InputResult
Input "Please enter the password of the admin account again." -p
AdminPasswordAgain=$InputResult
if [ "$AdminPassword" != "$AdminPasswordAgain" ]; then
Warning "The passwords you entered are not the same. Please try again."
else
break
fi
done
Input "Please enter the nickname of the admin account."
AdminNickname=$InputResult
Input "Please enter the email of the admin account."
AdminEmail=$InputResult
HashedPassword=$(echo -n "$PasswordSalt1$AdminPassword$PasswordSalt2" | sha256sum | awk '{print $1}')
echo "INSERT INTO Users (\`Username\`, \`Password\`, \`Nickname\`, \`EmailAddress\`, \`Role\`) VALUES ('$AdminUsername', '$HashedPassword', '$AdminNickname', '$AdminEmail', 0);" >./CreateAdminAccount.sql
mysql $(cat /etc/OJ/DatabaseName) <./CreateAdminAccount.sql
if [ $? -ne 0 ]; then
Error "Failed to create admin account."
EndSection
exit
else
Success "Admin account created."
fi
else
Warning "Admin account already exists."
fi
EndSection
}
function CreateDefaultProblem() {
BeginSection "Create default problem"
if [ $(mysql -e "SELECT COUNT(*) FROM Problems;" $(cat /etc/OJ/DatabaseName) | grep -c "0") -eq 1 ]; then
echo "INSERT INTO \`Problems\` (\`PID\`, \`Title\`, \`IOFilename\`, \`Description\`, \`Input\`, \`Output\`, \`Range\`, \`Hint\`, \`Samples\`, \`TestGroups\`) VALUES (1000, 'Add', 'Add', '***Add*** two numbers \$a\$ and \$b\$', 'two numbers in _one line_', 'one number', '\$\$-2^{32} < a,b < 2^{32}\$\$', '', '[{\"Description\":\"\",\"Input\":\"1 2\",\"Output\":\"3\"}]', '[{\"TGID\":0,\"TestCases\":[{\"Answer\":\"3\",\"Input\":\"1 2\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":0,\"TimeLimit\":1000},{\"Answer\":\"5\",\"Input\":\"2 3\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":1,\"TimeLimit\":1000},{\"Answer\":\"50\",\"Input\":\"23 27\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":2,\"TimeLimit\":1000},{\"Answer\":\"29\",\"Input\":\"20 09\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":3,\"TimeLimit\":1000},{\"Answer\":\"18\",\"Input\":\"01 17\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":4,\"TimeLimit\":1000},{\"Answer\":\"67\",\"Input\":\"45 22\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":5,\"TimeLimit\":1000},{\"Answer\":\"198\",\"Input\":\"99 99\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":6,\"TimeLimit\":1000},{\"Answer\":\"1011\",\"Input\":\"465 546\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":7,\"TimeLimit\":1000},{\"Answer\":\"579\",\"Input\":\"123 456\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":8,\"TimeLimit\":1000},{\"Answer\":\"1356\",\"Input\":\"877 479\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":9,\"TimeLimit\":1000}]},{\"TGID\":1,\"TestCases\":[{\"Answer\":\"4294967296\",\"Input\":\"2147483648 2147483648\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":0,\"TimeLimit\":1000},{\"Answer\":\"12185866737\",\"Input\":\"6567867981 5617998756\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":1,\"TimeLimit\":1000},{\"Answer\":\"11111111100\",\"Input\":\"1234567890 9876543210\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":2,\"TimeLimit\":1000},{\"Answer\":\"3825938259\",\"Input\":\"1357924680 2468013579\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":3,\"TimeLimit\":1000},{\"Answer\":\"7800224355\",\"Input\":\"1122334455 6677889900\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":4,\"TimeLimit\":1000}]},{\"TGID\":2,\"TestCases\":[{\"Answer\":\"0\",\"Input\":\"1 -1\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":0,\"TimeLimit\":1000},{\"Answer\":\"-1\",\"Input\":\"2 -3\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":1,\"TimeLimit\":1000},{\"Answer\":\"-4\",\"Input\":\"23 -27\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":2,\"TimeLimit\":1000},{\"Answer\":\"11\",\"Input\":\"20 -09\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":3,\"TimeLimit\":1000},{\"Answer\":\"-16\",\"Input\":\"01 -17\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":4,\"TimeLimit\":1000},{\"Answer\":\"23\",\"Input\":\"45 -22\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":5,\"TimeLimit\":1000},{\"Answer\":\"0\",\"Input\":\"99 -99\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":6,\"TimeLimit\":1000},{\"Answer\":\"-81\",\"Input\":\"465 -546\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":7,\"TimeLimit\":1000},{\"Answer\":\"-333\",\"Input\":\"123 -456\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":8,\"TimeLimit\":1000},{\"Answer\":\"398\",\"Input\":\"877 -479\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":9,\"TimeLimit\":1000}]},{\"TGID\":3,\"TestCases\":[{\"Answer\":\"0\",\"Input\":\"2147483647 -2147483647\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":0,\"TimeLimit\":1000},{\"Answer\":\"949869225\",\"Input\":\"6567867981 -5617998756\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":1,\"TimeLimit\":1000},{\"Answer\":\"-8641975320\",\"Input\":\"1234567890 -9876543210\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":2,\"TimeLimit\":1000},{\"Answer\":\"-1110088899\",\"Input\":\"1357924680 -2468013579\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":3,\"TimeLimit\":1000},{\"Answer\":\"-5555555445\",\"Input\":\"1122334455 -6677889900\",\"MemoryLimit\":1073741824,\"Score\":100,\"TCID\":4,\"TimeLimit\":1000}]}]');" >./CreateDefaultProblem.sql
mysql $(cat /etc/OJ/DatabaseName) <./CreateDefaultProblem.sql
if [ $? -ne 0 ]; then
Error "Failed to create default problem."
EndSection
exit
else
Success "Default problem created."
fi
else
Warning "Problems already exist, skipping."
fi
EndSection
}
function ConfigureSettings() {
BeginSection "Configure settings"
if [ $(mysql -e "SELECT COUNT(*) FROM Settings;" $(cat /etc/OJ/DatabaseName) | grep -c "0") -eq 1 ]; then
Warning "As the server use the email to send verification code when registering or resetting password, you need to set the email server."
Warning "You can use the email server provided by Microsoft, Google, or other email service providers."
Input "Please enter the smtp server. (eg. smtp-mail.outlook.com)"
EmailServer=$InputResult
Input "Please enter the port of the email server. (Most of the time it is 587)"
EmailPort=$InputResult
Input "Please enter the email address you want to use."
EmailAddress=$InputResult
Input "Please enter password or authentication code of the email address you want to use." -p
EmailPassword=$InputResult
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('EmailServer', 'smtp://$EmailServer:$EmailPort');" >./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('EmailUsername', '$EmailAddress');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('EmailPassword', '$EmailPassword');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('PasswordSalt1', '$PasswordSalt1');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('PasswordSalt2', '$PasswordSalt2');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('Compiler', '/bin/g++');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('CompileOutputLimit', '134217728');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('CompileTimeLimit', '10000');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('JudgeUserGroupID', '1001');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('JudgeUserID', '1001');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('JudgeUsername', 'Judger');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('SocketPort', '80');" >>./ConfigureSettings.sql
echo "INSERT INTO \`Settings\` (\`Key\`, \`Value\`) VALUES ('SystemCallList', '-1,-1,0,-1,-1,-1,0,0,-1,-1,-1,-1,-1,-1,-1,0,0,-1,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,1,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,-1,0,0,0,-1,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0');" >>./ConfigureSettings.sql
mysql $(cat /etc/OJ/DatabaseName) <./ConfigureSettings.sql
if [ $? -ne 0 ]; then
Error "Failed to configure settings."
EndSection
exit
else
Success "Settings configured."
fi
else
Warning "Settings already exist, skipping."
fi
EndSection
}
echo -e "\033[?25l"
echo -e "\033[33m"
echo "OJ Copyright (C) 2024 langningchen"
echo "This program comes with ABSOLUTELY NO WARRANTY."
echo "This is free software, and you are welcome to redistribute it under certain conditions."
echo -e "\033[0m"
BasicChecks
InstallPackages
CloneRepo
CreateJudgeUser
ConfigDatabase
CreateTables
CreateAdminAccount
CreateDefaultProblem
ConfigureSettings
echo -e "\033[4;5;32mInstallation complete\033[0m"
echo -e "\033[33mThe server is installed in the folder \"./OJ\". You can start the server by running \"./OJ/Run.bash\".\033[0m"
echo -e "Please go to \"https://github.com/CYEZOI/OJ\" for more information or to report bugs."
echo "We strongly recommend you to install the dbeaver database management tool at \"https://dbeaver.io/\"."
echo ""
echo "Thank you for installing this OJ."
echo "Have a nice day!"
echo -e "\033[?25h"