2019-07-16 06:13:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
genRandStr(){
|
|
|
|
cat /dev/urandom | tr -dc [:alnum:] | head -c $1
|
|
|
|
}
|
|
|
|
#Set some vars
|
2022-09-18 23:54:41 +00:00
|
|
|
_database_host_="${DATABASE_HOST:-uoj-db}"
|
|
|
|
_database_password_="${DATABASE_PASSWORD:-root}"
|
|
|
|
_judger_socket_port_="${JUDGER_SOCKET_PORT:-2333}"
|
|
|
|
_judger_socket_password_="${JUDGER_SOCKET_PASSWORD:-_judger_socket_password_}"
|
2022-09-20 07:00:09 +00:00
|
|
|
_salt0_="${SALT_0:-salt0}"
|
|
|
|
_salt1_="${SALT_1:-salt1}"
|
|
|
|
_salt2_="${SALT_2:-salt2}"
|
|
|
|
_salt3_="${SALT_3:-salt3}"
|
2022-09-20 05:50:29 +00:00
|
|
|
_uoj_protocol_="${UOJ_PROTOCOL:-http}"
|
2019-07-16 06:13:28 +00:00
|
|
|
|
|
|
|
getAptPackage(){
|
|
|
|
printf "\n\n==> Getting environment packages\n"
|
2022-03-17 08:19:43 +00:00
|
|
|
# Update apt sources and install
|
2019-07-16 06:13:28 +00:00
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
|
|
|
dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg)
|
2022-10-04 12:57:49 +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 1A10946ED858A0DF
|
|
|
|
echo "deb http://ppa.launchpad.net/ondrej/php/ubuntu jammy main" | tee /etc/apt/sources.list.d/ondrej-php.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C
|
|
|
|
apt-get update --allow-unauthenticated
|
|
|
|
apt-get install -y --allow-unauthenticated -o Dpkg::Options::="--force-overwrite" libv8 php7.4 php7.4-yaml php7.4-xml php7.4-dev php7.4-zip php7.4-mysql php7.4-mbstring php7.4-gd libseccomp-dev git vim ntp zip unzip curl wget libapache2-mod-xsendfile mysql-server php-pear cmake fp-compiler re2c libv8-7.5-dev libyaml-dev python2.7 python3.10 python3-requests openjdk-8-jdk openjdk-11-jdk openjdk-17-jdk
|
2022-03-16 09:00:39 +00:00
|
|
|
# Install PHP extensions
|
2022-10-05 01:36:56 +00:00
|
|
|
git clone https://github.com/phpv8/v8js.git --depth=1 -b 2.1.2 /tmp/pear/download/v8js-master && cd /tmp/pear/download/v8js-master
|
2022-03-17 08:19:43 +00:00
|
|
|
phpize && ./configure --with-php-config=/usr/bin/php-config --with-v8js=/opt/libv8-7.5 && make install && cd -
|
2019-07-16 06:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setLAMPConf(){
|
|
|
|
printf "\n\n==> Setting LAMP configs\n"
|
|
|
|
#Set Apache UOJ site conf
|
|
|
|
cat >/etc/apache2/sites-available/000-uoj.conf <<UOJEOF
|
|
|
|
<VirtualHost *:80>
|
|
|
|
#ServerName local_uoj.ac
|
|
|
|
ServerAdmin opensource@uoj.ac
|
|
|
|
DocumentRoot /var/www/uoj
|
|
|
|
|
|
|
|
SetEnvIf Request_URI "^/judge/.*$" judgelog
|
|
|
|
#LogLevel info ssl:warn
|
|
|
|
ErrorLog \${APACHE_LOG_DIR}/uoj_error.log
|
|
|
|
CustomLog \${APACHE_LOG_DIR}/uoj_judge.log common env=judgelog
|
|
|
|
CustomLog \${APACHE_LOG_DIR}/uoj_access.log combined env=!judgelog
|
|
|
|
|
|
|
|
XSendFile On
|
|
|
|
XSendFilePath /var/uoj_data
|
|
|
|
XSendFilePath /var/www/uoj/app/storage
|
|
|
|
XSendFilePath /opt/uoj/judger/uoj_judger/include
|
|
|
|
</VirtualHost>
|
|
|
|
UOJEOF
|
|
|
|
#Enable modules and make UOJ site conf enabled
|
|
|
|
a2ensite 000-uoj.conf && a2dissite 000-default.conf
|
|
|
|
a2enmod rewrite headers && sed -i -e '172s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
|
|
|
|
#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
|
2022-03-17 08:19:43 +00:00
|
|
|
sed -i -e '912a\extension=v8js.so\nextension=yaml.so' /etc/php/7.4/apache2/php.ini
|
2022-09-18 04:06:30 +00:00
|
|
|
sed -i 's|;sys_temp_dir = "/tmp"|sys_temp_dir = "/tmp"|g' /etc/php/7.4/apache2/php.ini
|
2019-07-16 06:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setWebConf(){
|
|
|
|
printf "\n\n==> Setting web files\n"
|
2022-03-16 09:00:39 +00:00
|
|
|
# Set webroot path
|
2019-07-16 06:13:28 +00:00
|
|
|
ln -sf /opt/uoj/web /var/www/uoj
|
|
|
|
chown -R www-data /var/www/uoj/app/storage
|
2022-03-16 09:00:39 +00:00
|
|
|
# Set web config file
|
2019-07-16 06:13:28 +00:00
|
|
|
php -a <<UOJEOF
|
|
|
|
\$config = include '/var/www/uoj/app/.default-config.php';
|
|
|
|
\$config['database']['host']='$_database_host_';
|
|
|
|
\$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
|
2022-03-16 09:00:39 +00:00
|
|
|
# Prepare local sandbox
|
2022-03-16 11:59:14 +00:00
|
|
|
cd /opt/uoj/judger/uoj_judger
|
2019-07-16 06:13:28 +00:00
|
|
|
cat >include/uoj_work_path.h <<UOJEOF
|
|
|
|
#define UOJ_WORK_PATH "/opt/uoj/judger/uoj_judger"
|
|
|
|
#define UOJ_JUDGER_BASESYSTEM_UBUNTU1804
|
|
|
|
#define UOJ_JUDGER_PYTHON3_VERSION "3.6"
|
|
|
|
#define UOJ_JUDGER_FPC_VERSION "3.0.4"
|
|
|
|
UOJEOF
|
2022-10-04 12:57:49 +00:00
|
|
|
make all -j$(($(nproc) + 1)) && cd /opt/uoj/web
|
2019-07-16 06:13:28 +00:00
|
|
|
}
|
|
|
|
|
2022-09-20 06:39:55 +00:00
|
|
|
dockerInitProgress() {
|
2019-07-16 06:13:28 +00:00
|
|
|
printf "\n\n==> Doing initial config and start service\n"
|
|
|
|
#Set uoj_data path
|
|
|
|
mkdir -p /var/uoj_data/upload
|
|
|
|
chown -R www-data:www-data /var/uoj_data
|
|
|
|
#Replace password placeholders
|
2022-09-18 23:54:41 +00:00
|
|
|
sed -i -e "s/salt0/$_salt0_/g" -e "s/salt1/$_salt1_/g" -e "s/salt2/$_salt2_/g" -e "s/salt3/$_salt3_/g" -e "s/_judger_socket_password_/$_judger_socket_password_/g" /var/www/uoj/app/.config.php
|
2022-09-20 07:08:57 +00:00
|
|
|
sed -i -e "s/'protocol' => 'http'/'protocol' => '$_uoj_protocol_'/g" /var/www/uoj/app/.config.php
|
2019-07-16 06:13:28 +00:00
|
|
|
#Start services
|
|
|
|
service ntp restart
|
|
|
|
service apache2 restart
|
2022-09-18 04:06:30 +00:00
|
|
|
mkdir -p /opt/uoj/web/app/storage/submission
|
|
|
|
mkdir -p /opt/uoj/web/app/storage/tmp
|
|
|
|
chmod -R 777 /opt/uoj/web/app/storage
|
2022-09-20 06:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initProgress(){
|
|
|
|
dockerInitProgress;
|
|
|
|
#Using cli upgrade to latest
|
|
|
|
php /var/www/uoj/app/cli.php upgrade:latest
|
|
|
|
touch /var/uoj_data/.UOJSetupDone
|
|
|
|
#Touch SetupDone flag file
|
2019-07-16 06:13:28 +00:00
|
|
|
printf "\n\n***Installation complete. Enjoy!***\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
prepProgress(){
|
2022-09-18 11:55:54 +00:00
|
|
|
setLAMPConf;setWebConf
|
2019-07-16 06:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -le 0 ]; then
|
|
|
|
echo 'Installing UOJ System web...'
|
2022-09-18 11:55:54 +00:00
|
|
|
getAptPackage;prepProgress;initProgress
|
2019-07-16 06:13:28 +00:00
|
|
|
fi
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
-p | --prep)
|
|
|
|
echo 'Preparing UOJ System web environment...'
|
|
|
|
prepProgress
|
|
|
|
;;
|
|
|
|
-i | --init)
|
|
|
|
echo 'Initing UOJ System web...'
|
|
|
|
initProgress
|
|
|
|
;;
|
2022-09-20 06:39:55 +00:00
|
|
|
-d | --docker-init)
|
|
|
|
echo 'Initing UOJ System web for docker...'
|
|
|
|
dockerInitProgress
|
2022-09-20 06:43:40 +00:00
|
|
|
;;
|
2019-07-16 06:13:28 +00:00
|
|
|
-? | --*)
|
|
|
|
echo "Illegal option $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift $(( $#>0?1:0 ))
|
|
|
|
done
|