2017-11-25 04:00:00 +00:00
|
|
|
#!/bin/bash
|
|
|
|
genRandStr(){
|
2018-04-15 07:06:43 +00:00
|
|
|
cat /dev/urandom | tr -dc [:alnum:] | head -c $1
|
2017-11-25 04:00:00 +00:00
|
|
|
}
|
|
|
|
#Set some vars
|
|
|
|
_database_password_=root
|
|
|
|
_judger_socket_port_=2333
|
2018-04-15 02:58:57 +00:00
|
|
|
_judger_socket_password_=$(genRandStr 32)
|
2017-11-25 04:00:00 +00:00
|
|
|
_main_judger_password_=$(genRandStr 32)
|
|
|
|
|
|
|
|
getAptPackage(){
|
2018-12-15 11:55:03 +00:00
|
|
|
printf "\n\n==> Getting environment packages\n"
|
2018-04-15 07:06:43 +00:00
|
|
|
#Set MySQL root password
|
2018-12-15 11:55:03 +00:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
(echo "mysql-server mysql-server/root_password password $_database_password_";echo "mysql-server mysql-server/root_password_again password $_database_password_") | debconf-set-selections
|
2018-04-15 07:06:43 +00:00
|
|
|
#Update apt sources and install
|
2018-12-25 15:58:33 +00:00
|
|
|
dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg)
|
2019-07-08 04:56:08 +00:00
|
|
|
echo "deb http://ppa.launchpad.net/stesie/libv8/ubuntu bionic main" | tee /etc/apt/sources.list.d/stesie-libv8.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D858A0DF
|
2019-07-15 08:32:05 +00:00
|
|
|
apt-get update && apt-get install -y vim ntp zip unzip curl wget apache2 libapache2-mod-xsendfile libapache2-mod-php php php-dev php-pear php-zip php-mysql php-mbstring mysql-server cmake fp-compiler re2c libv8-7.5-dev libyaml-dev python python3 python3-requests openjdk-8-jdk openjdk-11-jdk
|
2018-04-15 07:06:43 +00:00
|
|
|
#Install PHP extensions
|
2020-05-01 15:40:11 +00:00
|
|
|
yes | pecl install yaml
|
|
|
|
git clone https://github.com/phpv8/v8js.git --depth=1 /tmp/pear/download/v8js-master && cd /tmp/pear/download/v8js-master
|
|
|
|
phpize && ./configure --with-php-config=/usr/bin/php-config --with-v8js=/opt/libv8-7.5 && make install && cd -
|
2017-11-25 04:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setLAMPConf(){
|
2018-12-15 11:55:03 +00:00
|
|
|
printf "\n\n==> Setting LAMP configs\n"
|
2018-04-15 07:06:43 +00:00
|
|
|
#Set Apache UOJ site conf
|
|
|
|
cat >/etc/apache2/sites-available/000-uoj.conf <<UOJEOF
|
2017-11-25 04:00:00 +00:00
|
|
|
<VirtualHost *:80>
|
2018-04-15 07:06:43 +00:00
|
|
|
#ServerName local_uoj.ac
|
|
|
|
ServerAdmin opensource@uoj.ac
|
|
|
|
DocumentRoot /var/www/uoj
|
2017-11-25 04:00:00 +00:00
|
|
|
|
2019-07-08 05:20:30 +00:00
|
|
|
SetEnvIf Request_URI "^/judge/.*$" judgelog
|
2018-04-15 07:06:43 +00:00
|
|
|
#LogLevel info ssl:warn
|
|
|
|
ErrorLog \${APACHE_LOG_DIR}/uoj_error.log
|
2019-07-08 05:20:30 +00:00
|
|
|
CustomLog \${APACHE_LOG_DIR}/uoj_judge.log common env=judgelog
|
|
|
|
CustomLog \${APACHE_LOG_DIR}/uoj_access.log combined env=!judgelog
|
2017-11-25 04:00:00 +00:00
|
|
|
|
2018-04-15 07:06:43 +00:00
|
|
|
XSendFile On
|
|
|
|
XSendFilePath /var/uoj_data
|
|
|
|
XSendFilePath /var/www/uoj/app/storage
|
2019-07-16 02:43:02 +00:00
|
|
|
XSendFilePath /opt/uoj/judger/uoj_judger/include
|
2017-11-25 04:00:00 +00:00
|
|
|
</VirtualHost>
|
|
|
|
UOJEOF
|
2018-04-15 07:06:43 +00:00
|
|
|
#Enable modules and make UOJ site conf enabled
|
|
|
|
a2ensite 000-uoj.conf && a2dissite 000-default.conf
|
2018-09-20 14:05:15 +00:00
|
|
|
a2enmod rewrite headers && sed -i -e '172s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
|
2018-04-15 07:06:43 +00:00
|
|
|
#Create UOJ session save dir and make PHP extensions available
|
|
|
|
mkdir --mode=733 /var/lib/php/uoj_sessions && chmod +t /var/lib/php/uoj_sessions
|
2020-05-01 15:40:11 +00:00
|
|
|
sed -i -e '912a\extension=v8js.so\nextension=yaml.so' /etc/php/7.4/apache2/php.ini
|
2018-04-15 07:06:43 +00:00
|
|
|
#Set MySQL user directory and connection config
|
|
|
|
usermod -d /var/lib/mysql/ mysql
|
|
|
|
cat >/etc/mysql/mysql.conf.d/uoj_mysqld.cnf <<UOJEOF
|
|
|
|
[mysqld]
|
2019-03-09 04:50:07 +00:00
|
|
|
default-time-zone='+8:00'
|
2019-07-10 04:14:45 +00:00
|
|
|
character-set-server=utf8mb4
|
|
|
|
collation-server=utf8mb4_unicode_ci
|
|
|
|
init_connect='SET NAMES utf8mb4'
|
|
|
|
init_connect='SET collation_connection = utf8mb4_unicode_ci'
|
2018-04-15 07:06:43 +00:00
|
|
|
skip-character-set-client-handshake
|
2020-05-01 15:40:11 +00:00
|
|
|
sql-mode=ONLY_FULL_GROUP_BY,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
|
2018-04-15 07:06:43 +00:00
|
|
|
UOJEOF
|
2017-11-25 04:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setWebConf(){
|
2018-12-15 11:55:03 +00:00
|
|
|
printf "\n\n==> Setting web files\n"
|
2018-04-15 07:06:43 +00:00
|
|
|
#Set webroot path
|
2019-07-16 02:43:02 +00:00
|
|
|
ln -sf /opt/uoj/web /var/www/uoj
|
2018-12-15 11:55:03 +00:00
|
|
|
chown -R www-data /var/www/uoj/app/storage
|
2018-04-15 07:06:43 +00:00
|
|
|
#Set web config file
|
|
|
|
php -a <<UOJEOF
|
2017-11-25 04:00:00 +00:00
|
|
|
\$config = include '/var/www/uoj/app/.default-config.php';
|
|
|
|
\$config['database']['password']='$_database_password_';
|
|
|
|
\$config['judger']['socket']['port']='$_judger_socket_port_';
|
|
|
|
file_put_contents('/var/www/uoj/app/.config.php', "<?php\nreturn ".str_replace('\'_httpHost_\'','UOJContext::httpHost()',var_export(\$config, true)).";\n");
|
|
|
|
UOJEOF
|
2018-04-15 07:06:43 +00:00
|
|
|
#Import MySQL database
|
2018-09-20 14:05:15 +00:00
|
|
|
service mysql restart
|
2019-07-16 06:13:28 +00:00
|
|
|
mysql -u root --password=$_database_password_ <../db/app_uoj233.sql
|
2020-05-01 15:40:11 +00:00
|
|
|
echo "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$_database_password_';" | mysql -u root --password=$_database_password_
|
2017-11-25 04:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setJudgeConf(){
|
2019-07-15 08:32:05 +00:00
|
|
|
printf "\n\n==> Setting judger files\n"
|
|
|
|
#Add local_main_judger user
|
|
|
|
useradd -m local_main_judger && usermod -a -G www-data local_main_judger
|
2018-04-15 07:06:43 +00:00
|
|
|
#Set uoj_data path
|
2019-07-16 06:13:28 +00:00
|
|
|
mkdir -p /var/uoj_data/upload
|
|
|
|
chown -R www-data:www-data /var/uoj_data
|
2019-07-15 08:32:05 +00:00
|
|
|
#Compile uoj_judger and set runtime
|
2019-07-16 06:13:28 +00:00
|
|
|
chown -R local_main_judger:local_main_judger /opt/uoj/judger
|
2018-04-15 07:06:43 +00:00
|
|
|
su local_main_judger <<EOD
|
2019-07-16 02:43:02 +00:00
|
|
|
ln -s /var/uoj_data /opt/uoj/judger/uoj_judger/data
|
|
|
|
cd /opt/uoj/judger && chmod +x judge_client
|
2018-09-21 16:42:01 +00:00
|
|
|
cat >uoj_judger/include/uoj_work_path.h <<UOJEOF
|
2019-07-16 02:43:02 +00:00
|
|
|
#define UOJ_WORK_PATH "/opt/uoj/judger/uoj_judger"
|
2018-09-21 16:42:01 +00:00
|
|
|
#define UOJ_JUDGER_BASESYSTEM_UBUNTU1804
|
2020-05-01 15:40:11 +00:00
|
|
|
#define UOJ_JUDGER_PYTHON3_VERSION "3.8"
|
2018-09-21 16:42:01 +00:00
|
|
|
#define UOJ_JUDGER_FPC_VERSION "3.0.4"
|
|
|
|
UOJEOF
|
2019-07-15 08:32:05 +00:00
|
|
|
cd uoj_judger && make -j$(($(nproc) + 1))
|
2017-11-25 04:00:00 +00:00
|
|
|
EOD
|
2018-04-15 07:06:43 +00:00
|
|
|
#Set judge_client config file
|
2019-07-15 08:32:05 +00:00
|
|
|
cat >../../judger/.conf.json <<UOJEOF
|
2017-11-25 04:00:00 +00:00
|
|
|
{
|
2018-04-15 07:06:43 +00:00
|
|
|
"uoj_protocol": "http",
|
|
|
|
"uoj_host": "127.0.0.1",
|
|
|
|
"judger_name": "main_judger",
|
2018-12-25 15:58:33 +00:00
|
|
|
"judger_password": "_main_judger_password_",
|
2018-04-15 07:06:43 +00:00
|
|
|
"socket_port": $_judger_socket_port_,
|
2019-06-14 15:30:02 +00:00
|
|
|
"socket_password": "_judger_socket_password_"
|
2017-11-25 04:00:00 +00:00
|
|
|
}
|
|
|
|
UOJEOF
|
2019-07-15 08:32:05 +00:00
|
|
|
chmod 600 ../../judger/.conf.json && chown local_main_judger ../../judger/.conf.json
|
2017-11-25 04:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-25 15:58:33 +00:00
|
|
|
initProgress(){
|
|
|
|
printf "\n\n==> Doing initial config and start service\n"
|
|
|
|
#Replace password placeholders
|
2019-07-16 02:43:02 +00:00
|
|
|
sed -i -e "s/_main_judger_password_/$_main_judger_password_/g" -e "s/_judger_socket_password_/$_judger_socket_password_/g" /opt/uoj/judger/.conf.json
|
2018-12-25 15:58:33 +00:00
|
|
|
sed -i -e "s/salt0/$(genRandStr 32)/g" -e "s/salt1/$(genRandStr 16)/g" -e "s/salt2/$(genRandStr 16)/g" -e "s/salt3/$(genRandStr 16)/g" -e "s/_judger_socket_password_/$_judger_socket_password_/g" /var/www/uoj/app/.config.php
|
|
|
|
#Import judge_client to MySQL database
|
|
|
|
service mysql start
|
|
|
|
echo "insert into judger_info (judger_name, password) values (\"main_judger\", \"$_main_judger_password_\")" | mysql app_uoj233 -u root --password=$_database_password_
|
2018-04-15 07:06:43 +00:00
|
|
|
#Using cli upgrade to latest
|
|
|
|
php /var/www/uoj/app/cli.php upgrade:latest
|
|
|
|
#Start services
|
|
|
|
service ntp restart
|
|
|
|
service mysql restart
|
|
|
|
service apache2 restart
|
2019-07-16 02:43:02 +00:00
|
|
|
su local_main_judger -c '/opt/uoj/judger/judge_client start'
|
2018-12-25 15:58:33 +00:00
|
|
|
#Touch SetupDone flag file
|
2019-07-15 08:32:05 +00:00
|
|
|
touch /var/uoj_data/.UOJSetupDone
|
2018-12-15 11:55:03 +00:00
|
|
|
printf "\n\n***Installation complete. Enjoy!***\n"
|
2017-11-25 04:00:00 +00:00
|
|
|
}
|
|
|
|
|
2018-12-25 15:58:33 +00:00
|
|
|
prepProgress(){
|
2019-07-15 08:32:05 +00:00
|
|
|
getAptPackage;setLAMPConf;setWebConf;setJudgeConf
|
2018-12-25 15:58:33 +00:00
|
|
|
}
|
|
|
|
|
2019-07-16 06:13:28 +00:00
|
|
|
if [ $# -le 0 ]; then
|
2018-04-15 07:06:43 +00:00
|
|
|
echo 'Installing UOJ System bundle...'
|
2018-12-25 15:58:33 +00:00
|
|
|
prepProgress;initProgress
|
2017-11-25 04:00:00 +00:00
|
|
|
fi
|
2018-04-15 07:06:43 +00:00
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
2018-12-25 15:58:33 +00:00
|
|
|
-p | --prep)
|
|
|
|
echo 'Preparing UOJ System bundle environment...'
|
|
|
|
prepProgress
|
2018-04-15 07:06:43 +00:00
|
|
|
;;
|
2018-12-25 15:58:33 +00:00
|
|
|
-i | --init)
|
|
|
|
echo 'Initing UOJ System bundle...'
|
|
|
|
initProgress
|
2018-04-15 07:06:43 +00:00
|
|
|
;;
|
2018-12-15 11:55:03 +00:00
|
|
|
-? | --*)
|
2018-04-15 07:06:43 +00:00
|
|
|
echo "Illegal option $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift $(( $#>0?1:0 ))
|
|
|
|
done
|