mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-21 21:48:42 +00:00
chore(install/bundle): improve installation procedure
In the past, we make the bundle installation as two parts. Some of the steps such as compile judger is done at local. And, to make it work, the steps may in a wrong order. Now we make most of the steps working online automaticly, and if you start the container you don't need to wait for a long time to let it prepare. It will only reset passwords. There are also some works moved to another place in order to make the installation flow clearer and simpler. Using more threads to boost judge_client's make. Deleted some old things and doing something new. TODAY: **Merry Christmas!**
This commit is contained in:
parent
eff4c8ed9c
commit
46aa7b7005
@ -2,15 +2,15 @@ FROM ubuntu:18.04
|
||||
MAINTAINER MascoSkray <MascoSkray@gmail.com>
|
||||
|
||||
#Update apt and install git
|
||||
RUN apt-get update && apt-get install -y git gnupg
|
||||
RUN apt-get update && apt-get install -y git
|
||||
#Clone the latest UOJ Community verison to local
|
||||
RUN cd ~ && git clone https://github.com/UniversalOJ/UOJ-System.git --depth 1
|
||||
#Install environment and set startup script
|
||||
RUN cd ~/UOJ-System/install/bundle && sh install.sh -e && echo "\
|
||||
RUN cd ~/UOJ-System/install/bundle && sh install.sh -p && echo "\
|
||||
#!/bin/sh\n\
|
||||
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld\n\
|
||||
if [ ! -f \"/var/svn/.UOJSetupDone\" ]; then\n\
|
||||
cd ~/UOJ-System/install/bundle && sh install.sh -c\n\
|
||||
cd ~/UOJ-System/install/bundle && sh install.sh -i\n\
|
||||
fi\n\
|
||||
service ntp start\n\
|
||||
service mysql start\n\
|
||||
|
@ -16,6 +16,7 @@ getAptPackage(){
|
||||
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
|
||||
#Update apt sources and install
|
||||
dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg)
|
||||
echo "deb http://ppa.launchpad.net/pinepain/libv8/ubuntu artful main" | tee /etc/apt/sources.list.d/pinepain-libv8.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 60C60AA4
|
||||
apt-get update && apt-get install -y vim ntp zip unzip curl wget subversion 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-6.6-dev libyaml-dev python python3 python-requests
|
||||
#Install PHP extensions
|
||||
@ -30,14 +31,13 @@ getOracleJDK(){
|
||||
mkdir -p /etc/oracle/java/ && echo 'com.oracle.usagetracker.track.last.usage=false' >/etc/oracle/java/usagetracker.properties
|
||||
#Get newest jdk dist file
|
||||
JDK_MIRROR_LINK=https://build.funtoo.org/distfiles/oracle-java/
|
||||
#Deprecated #JDK_CNMIRROR_LINK=http://funtoo.neu.edu.cn/funtoo/distfiles/oracle-java/
|
||||
curl -s ${JDK_MIRROR_LINK} | grep -oP '>jdk-[7,8].*-linux-x64.tar' | sed -e 's/[\",>]//g' -e 's/-linux-x64.tar//g' >jdkdist.list
|
||||
wget ${JDK_MIRROR_LINK}$(sed -n '1p' jdkdist.list)-linux-x64.tar.gz && wget ${JDK_MIRROR_LINK}$(sed -n '$p' jdkdist.list)-linux-x64.tar.gz
|
||||
#Change jdk and other environment version to faq.php
|
||||
wget --progress=dot:giga ${JDK_MIRROR_LINK}$(sed -n '1p' jdkdist.list)-linux-x64.tar.gz ${JDK_MIRROR_LINK}$(sed -n '$p' jdkdist.list)-linux-x64.tar.gz
|
||||
#Change compiler version to faq.php
|
||||
sed -i -e 's/Ubuntu Linux 14.04 LTS x64/Ubuntu Linux 18.04 LTS x64/' \
|
||||
-e 's/g++ 4.8.4/g++ 7.3.0/' -e 's/gcc 4.8.4/gcc 7.3.0/' -e 's/fpc 2.6.2/fpc 3.0.4/' -e 's/Python 2.7和3.4/Python 2.7和3.6/' \
|
||||
-e "s/jdk-7u76/$(sed -n '1p' jdkdist.list)/g" -e "s/jdk-8u31/$(sed -n '$p' jdkdist.list)/g" ../../uoj/1/app/controllers/faq.php
|
||||
#Move jdk file to judge user root
|
||||
#Move jdk file to judger user root
|
||||
chown local_main_judger jdkdist.list jdk-*-linux-x64.tar.gz
|
||||
mv jdkdist.list jdk-*-linux-x64.tar.gz /home/local_main_judger/
|
||||
}
|
||||
@ -93,12 +93,12 @@ setSVNServe(){
|
||||
cat /var/svn/uoj/conf/svnserve.conf >/var/svn/judge_client/conf/svnserve.conf
|
||||
cat >/var/svn/uoj/conf/passwd <<UOJEOF
|
||||
[users]
|
||||
root = $_svn_certroot_password_
|
||||
root = _svn_certroot_password_
|
||||
UOJEOF
|
||||
#Set SVN hook scripts
|
||||
cat >/var/svn/uoj/hooks/post-commit <<UOJEOF
|
||||
#!/bin/sh
|
||||
cd /var/svn/uoj/cur/uoj && svn update --username root --password $_svn_certroot_password_
|
||||
cd /var/svn/uoj/cur/uoj && svn update --username root --password _svn_certroot_password_
|
||||
UOJEOF
|
||||
chmod +x /var/svn/uoj/hooks/post-commit
|
||||
cat >/var/svn/judge_client/hooks/post-commit <<UOJEOF
|
||||
@ -125,7 +125,7 @@ password-db = passwd
|
||||
EOD
|
||||
|
||||
svnusr="our-root"
|
||||
svnpwd="$_svn_ourroot_password_"
|
||||
svnpwd="_svn_ourroot_password_"
|
||||
|
||||
cat >\$path/conf/passwd <<EOD
|
||||
[users]
|
||||
@ -146,7 +146,7 @@ UOJEOF
|
||||
cat >/var/svn/problem/post-commit.sh <<UOJEOF
|
||||
#!/bin/sh
|
||||
svnusr="our-root"
|
||||
svnpwd="$_svn_ourroot_password_"
|
||||
svnpwd="_svn_ourroot_password_"
|
||||
cd /var/svn/problem/\$1/cur/\$1
|
||||
svn update --username \$svnusr --password \$svnpwd
|
||||
chown -R www-data /var/svn/problem/\$1
|
||||
@ -154,30 +154,26 @@ UOJEOF
|
||||
chmod +x /var/svn/problem/post-commit.sh
|
||||
#Precheckout to cur folder
|
||||
mkdir /var/svn/uoj/cur /var/svn/judge_client/cur
|
||||
svn co svn://127.0.0.1/uoj --username root --password $_svn_certroot_password_ /var/svn/uoj/cur/uoj
|
||||
svn co svn://127.0.0.1/judge_client --username root --password $_svn_certroot_password_ /var/svn/judge_client/cur/judge_client
|
||||
svn co svn://127.0.0.1/uoj --username root --password '_svn_certroot_password_' /var/svn/uoj/cur/uoj
|
||||
svn co svn://127.0.0.1/judge_client --username root --password '_svn_certroot_password_' /var/svn/judge_client/cur/judge_client
|
||||
chown -R local_main_judger /var/svn/judge_client/cur/judge_client
|
||||
}
|
||||
|
||||
setWebConf(){
|
||||
printf "\n\n==> Setting web files\n"
|
||||
#Commit web source file
|
||||
svn co svn://127.0.0.1/uoj --username root --password $_svn_certroot_password_
|
||||
mv ../../uoj/1 uoj/1 && cd uoj
|
||||
svn add 1 && svn ci -m "Installtion commit" --username root --password $_svn_certroot_password_
|
||||
cd .. && rm -r uoj /var/www/uoj
|
||||
svn co svn://127.0.0.1/uoj --username root --password '_svn_certroot_password_'
|
||||
cp -r ../../uoj/1 uoj/1 && cd uoj
|
||||
svn add 1 && svn ci -m "Installtion commit" --username root --password '_svn_certroot_password_'
|
||||
cd .. && rm -r uoj
|
||||
#Set webroot path
|
||||
ln -s /var/svn/uoj/cur/uoj/1 /var/www/uoj
|
||||
ln -sf /var/svn/uoj/cur/uoj/1 /var/www/uoj
|
||||
chown -R www-data /var/www/uoj/app/storage
|
||||
#Set web config file
|
||||
php -a <<UOJEOF
|
||||
\$config = include '/var/www/uoj/app/.default-config.php';
|
||||
\$config['database']['password']='$_database_password_';
|
||||
\$config['security']['user']['client_salt']='$(genRandStr 32)';
|
||||
\$config['security']['cookie']['checksum_salt']=['$(genRandStr 16)','$(genRandStr 16)','$(genRandStr 16)'];
|
||||
\$config['judger']['socket']['port']='$_judger_socket_port_';
|
||||
\$config['judger']['socket']['password']='$_judger_socket_password_';
|
||||
\$config['svn']['our-root']['password']='$_svn_ourroot_password_';
|
||||
file_put_contents('/var/www/uoj/app/.config.php', "<?php\nreturn ".str_replace('\'_httpHost_\'','UOJContext::httpHost()',var_export(\$config, true)).";\n");
|
||||
UOJEOF
|
||||
#Import MySQL database
|
||||
@ -188,16 +184,16 @@ UOJEOF
|
||||
setJudgeConf(){
|
||||
printf "\n\n==> Setting judge_client files\n"
|
||||
#Commit judge_client source file
|
||||
svn co svn://127.0.0.1/judge_client --username root --password $_svn_certroot_password_
|
||||
mv ../../judge_client/1 judge_client/1 && cd judge_client
|
||||
svn add 1 && svn ci -m "Installation commit" --username root --password $_svn_certroot_password_
|
||||
svn co svn://127.0.0.1/judge_client --username root --password '_svn_certroot_password_'
|
||||
cp -r ../../judge_client/1 judge_client/1 && cd judge_client
|
||||
svn add 1 && svn ci -m "Installation commit" --username root --password '_svn_certroot_password_'
|
||||
cd .. && rm -r judge_client
|
||||
#Set uoj_data path
|
||||
mkdir /var/uoj_data
|
||||
chown -R www-data /var/uoj_data && chgrp -R www-data /var/uoj_data
|
||||
#Compile judge_client and set runtime
|
||||
su local_main_judger <<EOD
|
||||
svn update /var/svn/judge_client/cur/judge_client --username root --password $_svn_certroot_password_
|
||||
svn update /var/svn/judge_client/cur/judge_client --username root --password '_svn_certroot_password_'
|
||||
ln -s /var/svn/judge_client/cur/judge_client/1 ~/judge_client
|
||||
ln -s /var/uoj_data ~/judge_client/uoj_judger/data
|
||||
cd ~/judge_client && chmod +x judge_client
|
||||
@ -207,7 +203,7 @@ cat >uoj_judger/include/uoj_work_path.h <<UOJEOF
|
||||
#define UOJ_JUDGER_PYTHON3_VERSION "3.6"
|
||||
#define UOJ_JUDGER_FPC_VERSION "3.0.4"
|
||||
UOJEOF
|
||||
make
|
||||
cd uoj_judger && make -j$(($(grep -c ^processor /proc/cpuinfo) + 1))
|
||||
mkdir ~/judge_client/uoj_judger/run/runtime && cd ~/judge_client/uoj_judger/run/runtime
|
||||
mv ~/jdkdist.list ~/jdk-*-linux-x64.tar.gz .
|
||||
tar -xzf jdk-7*-linux-x64.tar.gz && tar -xzf jdk-8*-linux-x64.tar.gz
|
||||
@ -219,21 +215,27 @@ EOD
|
||||
"uoj_protocol": "http",
|
||||
"uoj_host": "127.0.0.1",
|
||||
"judger_name": "main_judger",
|
||||
"judger_password": "$_main_judger_password_",
|
||||
"judger_password": "_main_judger_password_",
|
||||
"socket_port": $_judger_socket_port_,
|
||||
"socket_password": "$_judger_socket_password_",
|
||||
"socket_password": "_judger_socket_password_",
|
||||
"svn_username": "root",
|
||||
"svn_password": "$_svn_certroot_password_"
|
||||
"svn_password": "_svn_certroot_password_"
|
||||
}
|
||||
UOJEOF
|
||||
chmod 600 /home/local_main_judger/judge_client/.conf.json
|
||||
chown local_main_judger /home/local_main_judger/judge_client/.conf.json
|
||||
#Import judge_client to MySQL database
|
||||
echo "insert into judger_info (judger_name, password) values (\"main_judger\", \"$_main_judger_password_\")" | mysql app_uoj233 -u root --password=$_database_password_
|
||||
}
|
||||
|
||||
endUpProgress(){
|
||||
printf "\n\n==> Ending progress and start service\n"
|
||||
initProgress(){
|
||||
printf "\n\n==> Doing initial config and start service\n"
|
||||
#Replace password placeholders
|
||||
sed -i "s/_svn_ourroot_password_/$_svn_ourroot_password_/g" /var/svn/problem/new_problem.sh /var/svn/problem/post-commit.sh /var/www/uoj/app/.config.php
|
||||
sed -i "s/_svn_certroot_password_/$_svn_certroot_password_/g" /var/svn/uoj/conf/passwd /var/svn/uoj/hooks/post-commit /home/local_main_judger/judge_client/.conf.json
|
||||
sed -i -e "s/_main_judger_password_/$_main_judger_password_/g" -e "s/_judger_socket_password_/$_judger_socket_password_/g" /home/local_main_judger/judge_client/.conf.json
|
||||
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_
|
||||
#Using cli upgrade to latest
|
||||
php /var/www/uoj/app/cli.php upgrade:latest
|
||||
#Start services
|
||||
@ -241,35 +243,28 @@ endUpProgress(){
|
||||
service mysql restart
|
||||
service apache2 restart
|
||||
su local_main_judger -c '~/judge_client/judge_client start'
|
||||
#Set SetupDone flag file
|
||||
echo 'Congratulations!' > /var/svn/.UOJSetupDone
|
||||
#Touch SetupDone flag file
|
||||
touch /var/svn/.UOJSetupDone
|
||||
printf "\n\n***Installation complete. Enjoy!***\n"
|
||||
}
|
||||
|
||||
prepProgress(){
|
||||
getAptPackage;getOracleJDK;setLAMPConf;setSVNServe;setWebConf;setJudgeConf
|
||||
}
|
||||
|
||||
if [ $# -le 0 ] ;then
|
||||
echo 'Installing UOJ System bundle...'
|
||||
getAptPackage
|
||||
getOracleJDK
|
||||
setLAMPConf
|
||||
setSVNServe
|
||||
setWebConf
|
||||
setJudgeConf
|
||||
endUpProgress
|
||||
prepProgress;initProgress
|
||||
fi
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-e | --environment)
|
||||
echo 'Setting UOJ System bundle environment...'
|
||||
getAptPackage
|
||||
getOracleJDK
|
||||
setLAMPConf
|
||||
-p | --prep)
|
||||
echo 'Preparing UOJ System bundle environment...'
|
||||
prepProgress
|
||||
;;
|
||||
-c | --config)
|
||||
echo 'Configuring UOJ System bundle...'
|
||||
setSVNServe
|
||||
setWebConf
|
||||
setJudgeConf
|
||||
endUpProgress
|
||||
-i | --init)
|
||||
echo 'Initing UOJ System bundle...'
|
||||
initProgress
|
||||
;;
|
||||
-? | --*)
|
||||
echo "Illegal option $1"
|
||||
|
Loading…
Reference in New Issue
Block a user