2024-10-10

This commit is contained in:
2024-10-10 12:56:56 +08:00
commit 7b347c848a
2648 changed files with 643965 additions and 0 deletions

159
install/A+B.xml Executable file
View File

@@ -0,0 +1,159 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fps PUBLIC
"-//freeproblemset//An opensource XML standard for AlgorithmContest Problem Set//EN"
"http://hustoj.com/fps.current.dtd" >
<fps version="1.2" url="https://github.com/zhblue/freeproblemset/">
<generator name="HUSTOJ" url="https://github.com/zhblue/hustoj/"/>
<item>
<title><![CDATA[送分题-A+B Problem]]></title>
<time_limit unit="s"><![CDATA[1]]></time_limit>
<memory_limit unit="mb"><![CDATA[256]]></memory_limit>
<description><![CDATA[<p>Calculate a+b</p>]]></description>
<input><![CDATA[<p>Two integer a,b (0&lt;=a,b&lt;=10)</p>]]></input>
<output><![CDATA[<p>Output a+b</p>]]></output>
<sample_input><![CDATA[1 2]]></sample_input>
<sample_output><![CDATA[3]]></sample_output>
<test_input><![CDATA[500 17]]></test_input>
<test_output><![CDATA[517]]></test_output>
<test_input><![CDATA[2 3
]]></test_input>
<test_output><![CDATA[5
]]></test_output>
<hint><![CDATA[<p>Q: Where are the input and the output? A: Your program shall always <font color="#ff0000">read input from stdin (Standard Input) and write output to stdout (Standard Output)</font>. For example, you can use 'scanf' in C or 'cin' in C++ to read from stdin, and use 'printf' in C or 'cout' in C++ to write to stdout. You <font color="#ff0000">shall not output any extra data</font> to standard output other than that required by the problem, otherwise you will get a &quot;Wrong Answer&quot;. User programs are not allowed to open and read from/write to files. You will get a &quot;Runtime Error&quot; or a &quot;Wrong Answer&quot; if you try to do so. Here is a sample solution for problem 1000 using C++/G++:</p>
<pre>
#include &lt;iostream&gt;
using namespace std;
int main()
{
int a,b;
cin &gt;&gt; a &gt;&gt; b;
cout &lt;&lt; a+b &lt;&lt; endl;
return 0;
}</pre>
<p>It's important that the return type of main() must be int when you use G++/GCC,or you may get compile error. Here is a sample solution for problem 1000 using C/GCC:</p>
<pre>
#include &lt;stdio.h&gt;
int main()
{
int a,b;
scanf(&quot;%d %d&quot;,&amp;a, &amp;b);
printf(&quot;%d\n&quot;,a+b);
return 0;
}</pre>
<p>Here is a sample solution for problem 1000 using PASCAL:</p>
<pre>
program p1000(Input,Output);
var
a,b:Integer;
begin
Readln(a,b);
Writeln(a+b);
end.</pre>
<p>Here is a sample solution for problem 1000 using JAVA: Now java compiler is jdk 1.5, next is program for 1000</p>
<pre>
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String args[]) throws Exception
{
Scanner cin=new Scanner(System.in);
int a=cin.nextInt();
int b=cin.nextInt();
System.out.println(a+b);
}
}</pre>
<p>Old program for jdk 1.4</p>
<pre>
import java.io.*;
import java.util.*;
public class Main
{
public static void main (String args[]) throws Exception
{
BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
String line = stdin.readLine();
StringTokenizer st = new StringTokenizer(line);
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
System.out.println(a+b);
}
}</pre>]]></hint>
<source><![CDATA[系统原理熟悉OJ]]></source>
<solution language="C"><![CDATA[#include <stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
printf("%d\n",a+b);
}
return 0;
}]]></solution>
<solution language="C++"><![CDATA[#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int a,b;
while(cin >>a >>b)
{
cout <<a+b <<endl;
}
return 0;
}]]></solution>
<solution language="Pascal"><![CDATA[program abprob;
var
a,b:longint;
begin
readln(a,b);
writeln(a+b);
end.]]></solution>
<solution language="Java"><![CDATA[import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner cin = new Scanner(System.in);
int a,b;
while(cin.hasNextInt())
{
a = cin.nextInt();
b = cin.nextInt();
System.out.println(a+b);
}
}
}]]></solution>
<solution language="Bash"><![CDATA[read a b
let c=$a+$b
echo $c]]></solution>
<solution language="Python"><![CDATA[#!/usr/bin/python2
a=raw_input()
b=a.split(" ")
print eval(b[0]+"+"+b[1])
]]></solution>
<solution language="C#"><![CDATA[using System;
class Program {
public static void Main() {
string line;
string []p;
int a,b;
while((line=Console.ReadLine())!=null){
p=line.Split(' ');
a=int.Parse(p[0]);b=int.Parse(p[1]);
Console.WriteLine(a+b);
}
}
}]]></solution>
</item>
</fps>

72
install/Dockerfile Normal file
View File

@@ -0,0 +1,72 @@
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
#RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf
#RUN echo "100.100.2.148 mirrors.cloud.aliyuncs.com" >> /etc/hosts
RUN apt-get update && apt-get -y upgrade
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends libmariadb-dev
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends libmysqlclient-dev
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends libmysql++-dev
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends build-essential
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends flex
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends g++
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends python
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends python3
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends fp-compiler
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends mono-devel
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends busybox
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends dos2unix
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends openjdk-17-jdk
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends subversion
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends wget
RUN apt-get -y install sqlite3
RUN useradd -m -u 1536 judge
RUN cd /home/judge/ && \
wget dl.hustoj.com/hustoj.tar.gz && \
tar xzf hustoj.tar.gz
#Github update
#RUN svn up /home/judge/src
RUN cd /home/judge/src/core/ && bash make.sh
# for more compilers, VMs and runtimes , remove # and run "docker build -t hustoj ."
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends ruby
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends gobjc
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends clang
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends guile-3.0
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends lua5.3
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends nodejs
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends golang
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends sqlite3
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends gfortran
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends octave
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends gnucobol
#RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends r-base
# Scratch3 judge need these lines
#RUN wget -c http://dl.hustoj.com/scratch-run_0.1.5_linux_amd64.zip
#RUN apt-get install unzip
#RUN unzip scratch-run_0.1.5_linux_amd64.zip
#RUN mv scratch-run /usr/bin
#RUN chmod +x /usr/bin/scratch-run
#RUN apt-get update
# install debian package of similarity-tester
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends similarity-tester
RUN cp /usr/bin/sim_c++ /usr/bin/sim_cc
# make Chinese Character works in Docker
RUN apt-get install -y locales locales-all
RUN locale-gen zh_CN.UTF-8 && dpkg-reconfigure locales && /usr/sbin/update-locale LANG=zh_CN.UTF-8
ENV LANG zh_CN.UTF-8
ENV LANGUAGE zh_CN:zh
ENV LC_ALL zh_CN.UTF-8
# override endl not to flush the io buffer
RUN echo "#ifndef HUSTOJ">>`find /usr/include/c++/ -name iostream`
RUN echo "#define HUSTOJ">>`find /usr/include/c++/ -name iostream`
RUN echo "std::ostream& endl(std::ostream& s) {">>`find /usr/include/c++/ -name iostream`
RUN echo "s<<'\\\\n'; ">>`find /usr/include/c++/ -name iostream`
RUN echo "return s; ">>`find /usr/include/c++/ -name iostream`
RUN echo "}">>`find /usr/include/c++/ -name iostream`
RUN echo "#endif">>`find /usr/include/c++/ -name iostream`

13
install/README Executable file
View File

@@ -0,0 +1,13 @@
HUSTOJ安装说明
by zhblue(newsclan@gmail.com)
小白用户推荐ubuntu22.04
wget http://dl.hustoj.com/install.sh
sudo bash install.sh
服务器无法安装ubuntu可以用centos7 有的语言可能不支持可以用下面脚本快速安装OJ
wget http://dl.hustoj.com/install-centos7.sh
sudo bash install-centos7.sh

15
install/add_dns_to_docker.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
DNS=`cat /etc/resolv.conf |grep nameserver|awk '{print $2}' | tail -1 `
cd /etc/docker
if grep 'dns' daemon.json > /dev/null ; then
echo "has dns"
else
head -`wc -l daemon.json |awk '{print $1-1}'` daemon.json > new.json
echo ", \"dns\": [\"$DNS\", \"8.8.8.8\", \"114.114.114.114\"] " >> new.json
echo '}' >> new.json
mv daemon.json old.json
mv new.json daemon.json
fi

3
install/ans2out Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
cd $1
for i in *.ans;do mv $i `basename -s .ans $i`.out; done;

View File

@@ -0,0 +1,101 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
git clone https://gitee.com/zhblue/hustoj.git git
cp -a git/trunk src
for PKG in make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm nginx mysql-server php-mysql php-common php-gd php-zip fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml mariadb-server libmariadb-dev libmariadbclient-dev libmariadb-dev default-libmysqlclient-dev
do
apt-get install -y $PKG
done
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql < src/install/db.sql
echo "grant all privileges on jol.* to '$USER' identified by '$PASSWORD';\n flush privileges;\n"|mysql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "hustoj nginx config added!"
else
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.3/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.3/fpm/php.ini
fi
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php7.3-fpm restart
service php7.3-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable nginx
systemctl enable mysql
systemctl enable php7.3-fpm
systemctl enable judged
echo "Note: skip-networking is needed for Andorid based Linux Deploy to start mariadb "
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"

View File

@@ -0,0 +1,109 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
for PKG in make flex g++ clang libmariadb++-dev php-fpm nginx mariadb-server php-mysql php-common php-gd php-zip fp-compiler openjdk-8-jdk mono-devel php-mbstring php-xml
do
apt-get install -y $PKG
done
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql < src/install/db.sql
echo "grant all privileges on jol.* to '$USER' identified by '$PASSWORD';\n flush privileges;\n"|mysql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "hustoj nginx config added!"
else
sed -i "s#root /var/www/html;#root /home/judge/src/web;\n\n\tlocation /recent-contest.json {\n\t\tproxy_pass http://contests.acmicpc.info/contests.json;\n\t}#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
#sed -i "s:php7.0:php7.2:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.0/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.0/fpm/php.ini
fi
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf`
/etc/init.d/php7.0-fpm restart
service php7.0-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable nginx
systemctl enable mysql
systemctl enable php7.3-fpm
systemctl enable judged
cls
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"

View File

@@ -0,0 +1,57 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/
svn co https://github.com/zhblue/hustoj/trunk/trunk src
for PKG in make flex g++ clang libmysqlclient-dev libmysql++-dev php5-fpm php5-memcache memcached nginx mysql-server php5-mysql php5-gd fp-compiler openjdk-7-jdk
do
apt-get install -y $PKG
done
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
mkdir etc data log
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
cp src/install/nginx.default /etc/nginx/sites-available/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php5/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php5/fpm/php.ini
/etc/init.d/php5-fpm restart
service php5-fpm restart
cd src/core
bash ./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
/usr/bin/judged

View File

@@ -0,0 +1,64 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
for PKG in make flex g++ clang libmysqlclient-dev libmysql++-dev php7.0-fpm php7.0-memcache php-zip php-xml php-mbstring memcached nginx mysql-server php7.0-mysql php7.0-gd fp-compiler openjdk-7-jdk
do
apt-get install -y $PKG
done
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
mkdir etc data log
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
cp src/install/nginx.default /etc/nginx/sites-available/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php7.0/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php7.0/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf`
/etc/init.d/php7.0-fpm restart
service php7.0-fpm restart
cd src/core
bash ./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
/usr/bin/judged

View File

@@ -0,0 +1,85 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
if [ -z "$1" ]
then
echo "Using github latest..."
cd /home/judge/
svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
else
tar xzf $1
SRC=`find -name 'trunk'`
mv $SRC /home/judge/src
cd /home/judge/
fi
echo 'mysql-server-5.5 mysql-server/root_password password ""' | sudo debconf-set-selections
echo 'mysql-server-5.5 mysql-server/root_password_again password ""' | sudo debconf-set-selections
apt-get install -y make flex g++ clang libmysqlclient-dev libmysql++-dev php5-fpm php5-memcache memcached nginx mysql-server php5-mysql php5-gd fp-compiler openjdk-7-jdk
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
mkdir etc data log
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chown -R www-data src/web/
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
#sed -i "s#root /usr/share/nginx/html;#root /home/judge/src/web;\n\n\tlocation /recent-contest.json {\n\t\tproxy_pass http://contests.acmicpc.info/contests.json;\n\t}#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tfastcgi_split_path_info:\tfastcgi_split_path_info:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tfastcgi_pass unix:\tfastcgi_pass unix:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tfastcgi_index:\tfastcgi_index:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude fastcgi_params;:\tinclude fastcgi_params;\n\t}:g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php5/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php5/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php5 -name www.conf`
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php5 -name www.conf`
/etc/init.d/php5-fpm restart
service php5-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
/usr/bin/judged

View File

@@ -0,0 +1,90 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/
svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
echo 'mysql-server-5.5 mysql-server/root_password password ""' | sudo debconf-set-selections
echo 'mysql-server-5.5 mysql-server/root_password_again password ""' | sudo debconf-set-selections
apt-get install -y make flex g++ clang libmysqlclient-dev libmysql++-dev php5-fpm php5-memcache memcached nginx mysql-server php5-mysql php5-gd fp-compiler openjdk-7-jdk
apt-get -y install language-pack-zh-hans
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chown -R www-data src/web/
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
sed -i "s#root /usr/share/nginx/html;#root /home/judge/src/web;\n\n#g" /etc/nginx/sites-enabled/default
#sed -i "s#root /usr/share/nginx/html;#root /home/judge/src/web;\n\n\tlocation /recent-contest.json {\n\t\tproxy_pass http://contests.acmicpc.info/contests.json;\n\t}#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tfastcgi_split_path_info:\tfastcgi_split_path_info:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tfastcgi_pass unix:\tfastcgi_pass unix:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tfastcgi_index:\tfastcgi_index:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude fastcgi_params;:\tinclude fastcgi_params;\n\t}:g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php5/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php5/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php5 -name www.conf`
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php5 -name www.conf`
/etc/init.d/php5-fpm restart
service php5-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
/usr/bin/judged
systemctl enable hustoj
systemctl enable nginx
systemctl enable mysql
systemctl enable php7.3-fpm
systemctl enable judged
cls
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"

View File

@@ -0,0 +1,109 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
apt-get install -y make flex g++ libmysqlclient-dev libmysql++-dev php-fpm php-common php-xml-parser nginx mysql-server php-mysql php-gd php-zip fp-compiler openjdk-8-jdk mono-devel php-mbstring php-xml
apt-get install -y php-memcache memcached
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data src/web/
chown www-data src/web/upload data
if grep client_max_body_size /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
if [ -f "/run/php/php7.2-fpm.sock" ]; then
sed -i "s:php7.0:php7.2:g" /etc/nginx/sites-enabled/default
fi
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.0/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.0/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf`
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php7.2-fpm restart
service php7.2-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable hustoj
systemctl enable nginx
systemctl enable mysql
systemctl enable php7.2-fpm
systemctl enable judged
cls
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"

View File

@@ -0,0 +1,98 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
if [ -z "$1" ]
then
echo "Using github latest..."
cd /home/judge/
svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
else
tar xzf $1
SRC=`find -name 'trunk'`
mv $SRC /home/judge/src
cd /home/judge/
fi
apt-get install -y make flex g++ libmysqlclient-dev libmysql++-dev php-fpm php-common php-xml-parser nginx mysql-server php-mysql php-gd php-zip fp-compiler openjdk-8-jdk mono-devel php-mbstring php-xml
apt-get install -y php-memcache memcached
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data src/web/
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.0/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.0/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf`
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php7.0-fpm restart
service php7.0-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults

View File

@@ -0,0 +1,102 @@
#!/bin/bash
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
if [ -z "$1" ]
then
echo "Using github latest..."
cd /home/judge/
svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
else
tar xzf $1
SRC=`find -name 'trunk'`
mv $SRC /home/judge/src
cd /home/judge/
fi
apt-get install -y net-tools make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm nginx mysql-server php-mysql php-common php-gd php-zip fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data src/web/
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.0:php7.2:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.2/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.2/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf`
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php7.2-fpm restart
service php7.2-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
clear
echo "Visit http://127.0.0.1/"

View File

@@ -0,0 +1,112 @@
#!/bin/bash
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
apt-get update
apt-get install -y git
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
git clone https://gitee.com/zhblue/hustoj.git git
cp -a git/trunk src
for pkg in "net-tools make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm nginx mysql-server php-mysql php-common php-gd php-zip fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml"
do
while ! apt-get install -y $pkg
do
echo "Network fail, retry... you might want to change another apt source for install"
done
done
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data src/web/
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
echo "modify the default site"
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.0:php7.2:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.2/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.2/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf`
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php7.2-fpm restart
service php7.2-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable hustoj
systemctl enable nginx
systemctl enable mysql
systemctl enable php7.3-fpm
systemctl enable judged
cls
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"

View File

@@ -0,0 +1,123 @@
#!/bin/bash
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/ || exit
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
git clone https://gitee.com/zhblue/hustoj.git git
cp -a git/trunk src
for pkg in net-tools make flex g++ libmysqlclient-dev libmysql++-dev php-fpm nginx mysql-server php-mysql php-common php-gd php-zip fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml php-curl php-intl php-xmlrpc php-soap
do
while ! apt-get install -y "$pkg"
do
echo "Network fail, retry... you might want to change another apt source for install"
done
done
USER=$(grep user /etc/mysql/debian.cnf|head -1|awk '{print $3}')
PASSWORD=$(grep password /etc/mysql/debian.cnf|head -1|awk '{print $3}')
CPU=$(grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}')
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data src/web/
chown www-data:judge src/web/upload
chown www-data:judge data
chmod 711 -R data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u"$USER" -p"$PASSWORD" < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
echo "modify the default site"
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.0:php7.4:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.4/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.4/fpm/php.ini
WWW_CONF=$(find /etc/php -name www.conf)
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' "$WWW_CONF"
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' "$WWW_CONF"
COMPENSATION=$(grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}')
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
PHP_FPM=$(find /etc/init.d/ -name "php*-fpm")
$PHP_FPM restart
PHP_FPM=$(service --status-all|grep php|awk '{print $4}')
if [ "$PHP_FPM" != "" ]; then service "$PHP_FPM" restart ;else echo "NO PHP FPM";fi;
cd src/core || exit
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable hustoj
systemctl enable nginx
systemctl enable mysql
systemctl enable php7.4-fpm
#systemctl enable judged
mkdir /var/log/hustoj/
chown www-data -R /var/log/hustoj/
cls
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"

View File

@@ -0,0 +1,3 @@
#!/bin/bash
wget https://github.com/zhblue/vjudge/raw/master/install.sh
sudo bash install.sh

8
install/autocpu.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
cd /home/judge
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf

40
install/backup+.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/bash
if lsb_release -a|grep Ubuntu ; then
echo "This script is designed for CentOS"
echo "Ubuntu use restore.sh instead, please."
exit 1
fi
# current timestamp
cdate=`date '+%Y-%m-%d-%H-%M-%S'`
mkdir /home/judge/backup
mkdir /home/judge/backup/${cdate}
mkdir /home/judge/backup/${cdate}/etc
mkdir /home/judge/backup/${cdate}/src
# Get database password
OJ_USERNAME=`cat /home/judge/etc/judge.conf | grep OJ_USER_NAME`
OJ_PASSWORD=`cat /home/judge/etc/judge.conf | grep OJ_PASSWORD`
DB_USERNAME=`echo ${OJ_USERNAME:13}`
DB_PASSWORD=`echo ${OJ_PASSWORD:12}`
echo "dump mysql/mariadb database"
mysqldump -u${DB_USERNAME} -p${DB_PASSWORD} -B jol > /home/judge/backup/${cdate}/jol.sql
echo "backup data directory"
cp -r /home/judge/data /home/judge/backup/${cdate}/data
echo "backup config files"
cp /home/judge/etc/java0.policy /home/judge/backup/${cdate}/etc/java0.policy
cp /home/judge/etc/judge.conf /home/judge/backup/${cdate}/etc/judge.conf
echo "backup web files"
cp -r /home/judge/src/web /home/judge/backup/${cdate}/src/web
echo "Create backup archive"
tar -zcvf /home/judge/backup/${cdate}.tar.gz -C /home/judge/backup/${cdate} jol.sql data etc src
echo "clean backup temp files"
rm -rf /home/judge/backup/${cdate}

40
install/bak.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
DATE=`date +%Y%m%d`
OLD=`date -d"1 day ago" +"%Y%m%d"`
OLD3=`date -d"3 day ago" +"%Y%m%d"`
config="/home/judge/etc/judge.conf"
SERVER=`cat $config|grep 'OJ_HOST_NAME' |awk -F= '{print $2}'`
USER=`cat $config|grep 'OJ_USER_NAME' |awk -F= '{print $2}'`
PASSWORD=`cat $config|grep 'OJ_PASSWORD' |awk -F= '{print $2}'`
DATABASE=`cat $config|grep 'OJ_DB_NAME' |awk -F= '{print $2}'`
PORT=`cat $config|grep 'OJ_PORT_NUMBER' |awk -F= '{print $2}'`
echo "delete from source_code where solution_id in (select solution_id from solution where problem_id=0 and result>4);"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "delete from source_code_user where solution_id in (select solution_id from solution where problem_id=0 and result>4);"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "delete from runtimeinfo where solution_id in (select solution_id from solution where problem_id=0 and result>4);"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "delete from compileinfo where solution_id in (select solution_id from solution where problem_id=0 and result>4);"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "update solution set result=5 where result<4 and in_date<curdate()-interval 3 day ;"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "delete from solution where problem_id=0 and result>4 "|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
# cleanup trash from 6 month ago
echo "delete from loginlog where time<curdate()-interval 6 month;"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "delete from compileinfo where solution_id < (select solution_id from solution where result=11 and in_date< curdate()-interval 6 month order by solution_id desc limit 1);"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "delete from runtimeinfo where solution_id < (select solution_id from solution where result=11 and in_date< curdate()-interval 6 month order by solution_id desc limit 1);"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "repair table compileinfo,contest,contest_problem,loginlog,news,privilege,problem,solution,source_code,users,topic,reply,online,sim,mail;"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "optimize table compileinfo,contest,contest_problem,loginlog,news,privilege,problem,solution,source_code,users,topic,reply,online,sim,mail;"|mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE
echo "这里有警告是正常现象,请勿担心,下面的打包压缩耗时较长,请耐心等待备份结束,重新回到命令行提示符。"
echo "The warning here is normal, don't worry, the following packaging and compression takes a long time, please wait patiently for the backup to end and return to the command line prompt."
mkdir /var/backups
mysqldump -h $SERVER -P $PORT $DATABASE -u$USER -p$PASSWORD | bzip2 >/var/backups/db_${DATE}.sql.bz2
if tar cjf /var/backups/hustoj_${DATE}.tar.bz2 /home/judge/data /home/judge/src/web /home/judge/src/core /home/judge/etc /var/backups/db_${DATE}.sql.bz2; then
rm /var/backups/hustoj_${OLD3}.tar.bz2 2> /dev/null
rm /var/backups/db_${OLD}.sql.bz2 2> /dev/null
# 如果经常遇到磁盘空间不足,可以尝试启用下面的内容
# find /var/backups/ -maxdepth 2 -ctime 5 -name "*.bz2" -exec rm -f {} \;
fi
echo "备份完成请检查并用FileZilla通过sftp下载备份文件/var/backups/hustoj_${DATE}.tar.bz2"
echo "After the backup is complete, please check and download the backup file via sftp with FileZilla: /var/backups/hustoj_${DATE}.tar.bz2"

5
install/cleanproblem.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
cd /home/judge/src/install
rm -rf ../../data/*
echo "delete from problem ;" |./mysql.sh
echo "ALTER TABLE problem AUTO_INCREMENT = 1000 ;"|./mysql.sh

274
install/db.sql Normal file
View File

@@ -0,0 +1,274 @@
set names utf8mb4;
create database if not exists jol ;
use jol;
CREATE TABLE IF NOT EXISTS `compileinfo` (
`solution_id` int(11) NOT NULL DEFAULT 0,
`error` text,
PRIMARY KEY (`solution_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `contest` (
`contest_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`start_time` datetime DEFAULT NULL,
`end_time` datetime DEFAULT NULL,
`defunct` char(1) NOT NULL DEFAULT 'N',
`description` text,
`private` tinyint(4) NOT NULL DEFAULT '0',
`langmask` int NOT NULL DEFAULT '0' COMMENT 'bits for LANG to mask',
`password` CHAR( 16 ) NOT NULL DEFAULT '',
`user_id` varchar(48) NOT NULL DEFAULT 'admin',
PRIMARY KEY (`contest_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `contest_problem` (
`problem_id` int(11) NOT NULL DEFAULT '0',
`contest_id` int(11) DEFAULT NULL,
`title` char(200) NOT NULL DEFAULT '',
`num` int(11) NOT NULL DEFAULT '0',
`c_accepted` int(11) NOT NULL DEFAULT '0',
`c_submit` int(11) NOT NULL DEFAULT '0',
KEY `Index_contest_id` (`contest_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE `loginlog` (
`log_id` int NOT NULL AUTO_INCREMENT,
`user_id` varchar(48) NOT NULL DEFAULT '',
`password` varchar(40) DEFAULT NULL,
`ip` varchar(46) DEFAULT NULL,
`time` datetime DEFAULT NULL,
PRIMARY KEY (`log_id`),
KEY `user_log_index` (`user_id`,`time`),
KEY `user_time_index` (`user_id`,`time`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ;
CREATE TABLE IF NOT EXISTS `mail` (
`mail_id` int(11) NOT NULL AUTO_INCREMENT,
`to_user` varchar(48) NOT NULL DEFAULT '',
`from_user` varchar(48) NOT NULL DEFAULT '',
`title` varchar(200) NOT NULL DEFAULT '',
`content` text,
`new_mail` tinyint(1) NOT NULL DEFAULT '1',
`reply` tinyint(4) DEFAULT '0',
`in_date` datetime DEFAULT NULL,
`defunct` char(1) NOT NULL DEFAULT 'N',
PRIMARY KEY (`mail_id`),
KEY `uid` (`to_user`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `news` (
`news_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(48) NOT NULL DEFAULT '',
`title` varchar(200) NOT NULL DEFAULT '',
`content` mediumtext NOT NULL,
`time` datetime NOT NULL DEFAULT '2016-05-13 19:24:00',
`importance` tinyint(4) NOT NULL DEFAULT '0',
`menu` int(11) NOT NULL DEFAULT '0',
`defunct` char(1) NOT NULL DEFAULT 'N',
PRIMARY KEY (`news_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1004 DEFAULT CHARSET=utf8mb4;
INSERT INTO `news`(user_id,title,content,time,importance,menu,defunct) VALUES ('zhblue','HelloWorld!','\r\n 这是一个新安装的HUSTOJ系统有关它的使用和配置请看以下链接\r\n<br />\r\n\r\n <ul>\r\n <li>\r\n <a href=\"http://hustoj.com\" target=\"_blank\">hustoj.com</a>&nbsp;最新的常见问题\r\n </li>\r\n <li>\r\n <a href=\"https://gitee.com/zhblue/hustoj\" target=\"_blank\">gitee.com</a>&nbsp;国内的镜像站不定期同步github的源码\r\n </li>\r\n <li>\r\n <a href=\"http://github.com/zhblue/hustoj\" target=\"_blank\">github.com</a>&nbsp;国外的主站,最新源码在这里\r\n </li>\r\n <li>\r\n <a href=\"https://zhblue.github.io/hustoj/\" target=\"_blank\">https://zhblue.github.io/hustoj/</a>&nbsp;中文基础操作文档\r\n </li>\r\n <li>\r\n <a href=\"https://gitee.com/zhblue/hustoj/tree/master/wiki\" target=\"_blank\">wiki</a>&nbsp;英文高阶文档\r\n </li>\r\n </ul>\r\n<br />\r\n\r\n 如果需要题目,可以访问:\r\n<br />\r\n\r\n <ul>\r\n <li>\r\n <a href=\"http://tk.hustoj.com\" target=\"_blank\">tk.hustoj.com</a>&nbsp;注册即可下载免费专区的1000多道题目使用购物车可以批量下载下载到的xm<x>l文件可以直接导入系统。\r\n </li>\r\n <li>\r\n <a href=\"https://github.com/zhblue/freeproblemset/tree/master/fps-examples\" target=\"_blank\">FPS sample</a>&nbsp;FPS主站样例有部分题目可用。\r\n </li>\r\n <li>\r\n <a href=\"https://github.com/Azure99/EasyFPSViewer/releases\" target=\"_blank\">EasyFPSViewer</a>&nbsp;是一个Windows下的FPS/xm<x>l编辑查看工具&#44;可以查看、分割、提取xm<x>l中的题目。\r\n </li><li>\r\n<a href=\"http://royqh.net/redpandacpp/download/\" target=\"_blank\">小熊猫C++</a>&nbsp;是一个跨平台的IDE, 是DEV-C++的精神继承者。\r\n</li>\r\n </ul>\r\n<br />\r\n\r\n <br />\r\n<br />\r\n\r\n 当你已经熟练使用本系统,可以在后台公告列表编辑本页内容或者隐藏它。\r\n<br />','2009-06-13 18:00:00',0,0,'N');
INSERT INTO `news`(user_id,title,content,time,importance,menu,defunct) VALUES ('zhblue','题单模板','下面是一个题单模板注意其中plist=后面的题号需要自己整理。\r\n<div class=\"panel panel-success panel-heading panel-title \" onclick=\"$(\'#simple\').toggle()\" style=\"cursor:pointer\" >\r\n 初级操作\r\n</div>\r\n<div id=\"simple\" class=\"container\" style=\"display:none;\">\r\n [plist=1001,1002,1003,1004,1005,1006,1007,1008]1.高精度运算基础[/plist]\r\n[plist=1009,1010,1011,1012,1013]2.排序[/plist]\r\n[plist=1014,1015,1016,1017,1018,1019,1020,1021,1022,1023,1024]3.递推[/plist] \r\n[plist=1025,1026,1027,1028,1029,1030,1031,1032,1033,1034]4.递归[/plist]\r\n</div>\r\n<hr />\r\n<div class=\"panel panel-success panel-heading panel-title \" onclick=\"$(\'#middle\').toggle()\" style=\"cursor:pointer\" >\r\n 中级操作\r\n</div>\r\n<div id=\"middle\" class=\"container\" style=\"display:none;\">\r\n [plist=1035,1036,1037,1038,1039,1040]5.搜索[/plist]\r\n [plist=1032,1035,1041,1042,1043,1044]6.回溯[/plist]\r\n[plist=1045,1046,1047,1048,1049,1050]7.贪心[/plist] \r\n[plist=1054,1055,1056,1058,1059]8.分治[/plist]\r\n</div>\r\n<hr />\r\n<div class=\"panel panel-success panel-heading panel-title \" onclick=\"$(\'#dp\').toggle()\" style=\"cursor:pointer\" >\r\n 高级操作\r\n</div>\r\n<div id=\"dp\" class=\"container\" style=\"display:none;\">\r\n [plist=1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090]9.动态规划1[/plist]\r\n[plist=1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090]10.动态规划2[/plist]\r\n</div>\r\n ','2024-08-06 06:54:43',0,1,'N');
CREATE TABLE IF NOT EXISTS `privilege` (
`user_id` char(48) NOT NULL DEFAULT '',
`rightstr` char(30) NOT NULL DEFAULT '',
`valuestr` char(11) NOT NULL DEFAULT 'true',
`defunct` char(1) NOT NULL DEFAULT 'N',
KEY `user_id_index` (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `problem` (
`problem_id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(200) NOT NULL DEFAULT '',
`description` mediumtext,
`input` mediumtext,
`output` mediumtext,
`sample_input` text,
`sample_output` text,
`spj` char(1) NOT NULL DEFAULT '0',
`hint` mediumtext,
`source` varchar(100) DEFAULT NULL,
`in_date` datetime DEFAULT NULL,
`time_limit` DECIMAL(10,3) NOT NULL DEFAULT 0,
`memory_limit` int(11) NOT NULL DEFAULT 0,
`defunct` char(1) NOT NULL DEFAULT 'N',
`accepted` int(11) DEFAULT '0',
`submit` int(11) DEFAULT '0',
`solved` int(11) DEFAULT '0',
`remote_oj` varchar(16) DEFAULT NULL,
`remote_id` varchar(32) DEFAULT NULL,
PRIMARY KEY (`problem_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `reply` (
`rid` int(11) NOT NULL AUTO_INCREMENT,
`author_id` varchar(48) NOT NULL,
`time` datetime NOT NULL DEFAULT '2016-05-13 19:24:00',
`content` text NOT NULL,
`topic_id` int(11) NOT NULL,
`status` int(2) NOT NULL DEFAULT '0',
`ip` varchar(46) NOT NULL,
PRIMARY KEY (`rid`),
KEY `author_id` (`author_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `sim` (
`s_id` int(11) NOT NULL,
`sim_s_id` int(11) DEFAULT NULL,
`sim` int(11) DEFAULT NULL,
PRIMARY KEY (`s_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `solution` (
`solution_id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`problem_id` int(11) NOT NULL DEFAULT 0,
`user_id` char(48) NOT NULL,
`nick` char(20) NOT NULL DEFAULT '',
`time` int(11) NOT NULL DEFAULT 0,
`memory` int(11) NOT NULL DEFAULT 0,
`in_date` datetime NOT NULL DEFAULT '2016-05-13 19:24:00',
`result` smallint(6) NOT NULL DEFAULT '0',
`language` INT UNSIGNED NOT NULL DEFAULT '0',
`ip` char(46) NOT NULL,
`contest_id` int(11) DEFAULT 0,
`valid` tinyint(4) NOT NULL DEFAULT '1',
`num` tinyint(4) NOT NULL DEFAULT '-1',
`code_length` int(11) NOT NULL DEFAULT 0,
`judgetime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`pass_rate` DECIMAL(4,3) UNSIGNED NOT NULL DEFAULT 0,
`lint_error` int UNSIGNED NOT NULL DEFAULT 0,
`judger` CHAR(16) NOT NULL DEFAULT 'LOCAL',
`remote_oj` char(16) not NULL DEFAULT '',
`remote_id` char(32) not NULL DEFAULT '',
PRIMARY KEY (`solution_id`),
KEY `uid` (`user_id`),
KEY `pid` (`problem_id`),
KEY `res` (`result`),
KEY `cid` (`contest_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `source_code` (
`solution_id` int(11) NOT NULL,
`source` text NOT NULL,
PRIMARY KEY (`solution_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS source_code_user like source_code;
CREATE TABLE IF NOT EXISTS `topic` (
`tid` int(11) NOT NULL AUTO_INCREMENT,
`title` varbinary(60) NOT NULL,
`status` int(2) NOT NULL DEFAULT '0',
`top_level` int(2) NOT NULL DEFAULT '0',
`cid` int(11) DEFAULT NULL,
`pid` int(11) NOT NULL,
`author_id` varchar(48) NOT NULL,
PRIMARY KEY (`tid`),
KEY `cid` (`cid`,`pid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `users` (
`user_id` varchar(48) NOT NULL DEFAULT '',
`email` varchar(100) DEFAULT NULL,
`submit` int(11) DEFAULT '0',
`solved` int(11) DEFAULT '0',
`defunct` char(1) NOT NULL DEFAULT 'N',
`ip` varchar(46) NOT NULL DEFAULT '',
`accesstime` datetime DEFAULT NULL,
`volume` int(11) NOT NULL DEFAULT '1',
`language` int(11) NOT NULL DEFAULT '1',
`password` varchar(32) DEFAULT NULL,
`reg_time` datetime DEFAULT NULL,
`nick` varchar(20) NOT NULL DEFAULT '',
`school` varchar(20) NOT NULL DEFAULT '',
`group_name` varchar(16) not null default '',
`activecode` varchar(16) not null default '',
`starred` int(11) not null default '0',
PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `online` (
`hash` varchar(32) NOT NULL,
`ip` varchar(46) NOT NULL default '',
`ua` varchar(255) NOT NULL default '',
`refer` varchar(255) default NULL,
`lastmove` int(10) NOT NULL,
`firsttime` int(10) default NULL,
`uri` varchar(255) default NULL,
PRIMARY KEY (`hash`),
UNIQUE KEY `hash` (`hash`)
) ENGINE=MEMORY DEFAULT CHARSET=utf8mb4 ;
CREATE TABLE IF NOT EXISTS `runtimeinfo` (
`solution_id` int(11) NOT NULL DEFAULT 0,
`error` text,
PRIMARY KEY (`solution_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `custominput` (
`solution_id` int(11) NOT NULL DEFAULT 0,
`input_text` text,
PRIMARY KEY (`solution_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `printer` (
`printer_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` char(48) NOT NULL,
`in_date` datetime NOT NULL DEFAULT '2018-03-13 19:38:00',
`status` smallint(6) NOT NULL DEFAULT '0',
`worktime` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`printer` CHAR(16) NOT NULL DEFAULT 'LOCAL',
`content` text NOT NULL ,
PRIMARY KEY (`printer_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `balloon` (
`balloon_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` char(48) NOT NULL,
`sid` int(11) NOT NULL ,
`cid` int(11) NOT NULL ,
`pid` int(11) NOT NULL ,
`status` smallint(6) NOT NULL DEFAULT '0',
PRIMARY KEY (`balloon_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `share_code` (
`share_id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` varchar(48) DEFAULT NULL,
`title` varchar(32) DEFAULT NULL,
`share_code` text DEFAULT NULL,
`language` varchar(32) DEFAULT NULL,
`share_time` datetime DEFAULT NULL,
PRIMARY KEY (`share_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8mb4;
delimiter //
drop trigger if exists simfilter//
create trigger simfilter
before insert on sim
for each row
begin
declare new_user_id varchar(64);
declare old_user_id varchar(64);
select user_id from solution where solution_id=new.s_id into new_user_id;
select user_id from solution where solution_id=new.sim_s_id into old_user_id;
if old_user_id=new_user_id then
set new.s_id=0;
end if;
end//
CREATE PROCEDURE DEFAULT_ADMINISTRATOR(user_name VARCHAR(48))
BEGIN
DECLARE privileged_count INT DEFAULT 0;
SET privileged_count=(SELECT COUNT(1) FROM `privilege`);
IF privileged_count=0 THEN
INSERT INTO privilege values(user_name, 'administrator', 'true', 'N');
end if;
end//
delimiter ;

29
install/default.conf Executable file
View File

@@ -0,0 +1,29 @@
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
index index.php;
root /home/judge/src/web;
location / {
}
location ~ \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
client_max_body_size 80m;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

46
install/docker.sh Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/bash
cd /home/judge/src/install || exit 1
dpkg --configure -a
while ! apt-get install -y docker.io containerd
do
service docker start
echo "Network fail, retry... you might want to make sure docker.io is available in your apt source"
done
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://yczv4b52.mirror.aliyuncs.com",
"https://docker.m.daocloud.io",
"https://huecker.io",
"https://dockerhub.timeweb.cloud",
"https://registry.cn-hangzhou.aliyuncs.com"
],
"live-restore": true,
"log-opts": {
"max-size": "512m",
"max-file": "3"
}
}
EOF
bash add_dns_to_docker.sh
systemctl restart docker
if ! docker build -t hustoj .
then
echo "Network fail, retry... you might want to make sure https://hub.docker.com/ is available"
echo "Docker image failed, try download from temporary site ... "
while ! wget -O hustoj.docker.tar.bz2 http://dl3.hustoj.com/docker/hustoj.docker.tar.bz2
do
echo "Download archive image file fail , try again..."
done
bzip2 -d hustoj.docker.tar.bz2
docker load < hustoj.docker.tar
fi
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_PYTHON_FREE=0/OJ_PYTHON_FREE=1/g" /home/judge/etc/judge.conf
pkill -9 judged
/usr/bin/judged

24
install/fixdb.sh Executable file
View File

@@ -0,0 +1,24 @@
#!/bin/bash
DATE=`date +%Y%m%d%H%M`
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
WWW=`grep www /etc/passwd|awk -F: '{print $1}'`
echo "DROP USER $USER;" | mysql
echo "CREATE USER $USER identified by '$PASSWORD';" | mysql
echo "grant all privileges on jol.* to $USER ;flush privileges;" | mysql
if [ `whoami` = "root" ];then
cd /home/judge/
if test -e src/web/include/db_info.inc.php ;then
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\".*\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php|grep DB_USER
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\".*\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php|grep DB_PASS
fi
chown $WWW:$WWW -R src
if test -e etc/judge.conf ;then
sed -i "s/OJ_USER_NAME[[:space:]]*=[[:space:]]*.*/OJ_USER_NAME=$USER/g" etc/judge.conf|grep OJ_USER_NAME
sed -i "s/OJ_PASSWORD[[:space:]]*=[[:space:]]*.*/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf|grep OJ_PASSWORD
pkill -9 judged
judged
fi
else
echo "usage: sudo $0"
fi

28
install/fixext.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/bash
# fixing data reward.in1 reward.ou1
# usage
MAX="20"
MAIN="reward"
if [ -n "$1" ]; then
MAIN=$1
else
echo "fixing filenames"
echo "usage: $0 <mainfilename>"
echo "example: $0 reward"
exit 1;
fi
for i in `seq 1 $MAX`
do
echo $i
if [ $i -lt 10 ]; then
mv "$MAIN.in$i" "data0$i.in"
mv "$MAIN.ou$i" "data0$i.out"
else
mv "$MAIN$i.txt" "data$i.in"
mv "$MAIN$i.txt" "data$i.out"
fi
done

20
install/fixextxt.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
MAX="20"
if [ -n "$1" ]; then
MAX=$1
fi
for i in `seq 1 $MAX`
do
echo $i
if [ $i -lt 10 ]; then
mv "ex_input$i.txt" "data0$i.in"
mv "ex_output$i.txt" "data0$i.out"
else
mv "ex_input$i.txt" "data$i.in"
mv "ex_output$i.txt" "data$i.out"
fi
done

43
install/fixing.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
DATE=`date +%Y%m%d%H%M`
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
WWW=`grep www /etc/passwd|awk -F: '{print $1}'`
if [ `whoami` = "root" ];then
cd /home/judge/
chsh judge -s /sbin/nologin
mkdir new
cd new
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
mv src/* ./
cd ..
chmod +x new/install/*.sh
if test -e /home/judge/src/web/include/db_info.inc.php ;then
echo 'db_info.inc.php exists !';
new/install/merge.sh src/web/include/db_info.inc.php new/web/include/db_info.inc.php
else
echo 'db_info.inc.php not found';
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" new/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" new/web/include/db_info.inc.php
fi
cp -a src/web/upload/* new/web/upload/
mv src "old.$DATE"
echo "Your old files are moved to old.$DATE , find them if you need ."
mv new src
chmod +x src/install/*.sh
sed -i "s/OJ_INTERNAL_CLIENT=1/OJ_INTERNAL_CLIENT=0/g" /home/judge/etc/judge.conf
pkill -9 judged
cd src/core
bash make.sh
judged
cd /home/judge
#不要合并必须重新进入否则执行的update.sql是老版本没有更新
cd src/install
bash mysql.sh < update.sql
cd ../..
chown $WWW:$WWW -R src
else
echo "usage: sudo $0"
fi

20
install/fixtxt.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
MAX="20"
if [ -n "$1" ]; then
MAX=$1
fi
for i in `seq 1 $MAX`
do
echo $i
if [ $i -lt 10 ]; then
mv "input$i.txt" "data0$i.in"
mv "output$i.txt" "data0$i.out"
else
mv "input$i.txt" "data$i.in"
mv "output$i.txt" "data$i.out"
fi
done

9
install/g++.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
PWD=$1
SHELL=/bin/bash
TERM=xterm
USER=www-data
#echo $1
cd $1
/usr/bin/g++ -lm -o Main Main.cc 2>&1

9
install/gcc.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
PWD=$1
SHELL=/bin/bash
TERM=xterm
USER=www-data
#echo $1
cd $1
/usr/bin/gcc -o Main Main.c -lm 2>&1

69
install/hustoj Executable file
View File

@@ -0,0 +1,69 @@
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: hustoj
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $network $time
# Should-Stop: $network $time
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop the hustoj database server daemon
# Description: Controls the main MySQL database server daemon "hustojd"
# and its wrapper script "judged".
### END INIT INFO
#
set -e
set -u
${DEBIAN_SCRIPT_DEBUG:+ set -v -x}
test -x /usr/bin/judged || exit 0
. /lib/lsb/init-functions
SELF=$(cd $(dirname $0); pwd -P)/$(basename $0)
CONF=/home/judge/etc/judge.conf
# Safeguard (relative paths, core dumps..)
cd /
umask 077
# hustojadmin likes to read /root/.my.cnf. This is usually not what I want
# as many admins e.g. only store a password without a username there and
# so break my scripts.
export HOME=/home/judge
## Checks if there is a server running and if so if it is accessible.
#
# check_dead also fails if there is a lost hustojd in the process list
#
# main()
#
case "${1:-''}" in
'start')
# Start daemon
export LANG=zh_CN.UTF-8
/usr/bin/judged
;;
'stop')
pkill -9 judged
;;
'restart'|'reload'|'force-reload')
pkill -9 judged
sleep 3
/usr/bin/judged
;;
'status')
ps aux|grep judged
;;
*)
echo "Usage: $SELF start|stop|restart|reload|force-reload|status"
exit 1
;;
esac
# Some success paths end up returning non-zero so exit 0 explicitly. See
# bug #739846.
exit 0

32
install/install+.sh Executable file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/bash
centos7=`cat /etc/os-release | grep PRETTY_NAME | grep CentOS | grep 7 `
ubuntu14=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 14`
ubuntu16=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 16`
ubuntu18=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 18`
ubuntu20=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 20`
# remind: centos7 doesn't install wget with minimal installation and ubuntu doesn't install curl by default !!!
if [ -n "${centos7}" ];then
echo "CentOS7.* detected" ;
sudo curl https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-centos7.sh | sudo bash ;
elif [ -n "${ubuntu14}" ];then
echo "Ubuntu14.* detected" ;
sudo apt-get -y install curl ;
sudo curl https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu14.04.sh | sudo bash ;
elif [ -n "${ubuntu16}" ];then
echo "Ubuntu16.* detected" ;
sudo apt-get -y install curl ;
sudo curl https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu16+.sh | sudo bash ;
elif [ -n "${ubuntu18}" ];then
echo "Ubuntu18.* detected" ;
sudo apt-get -y install curl ;
sudo curl https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu18.04.sh | sudo bash ;
elif [ -n "${ubuntu20}" ];then
echo "Ubuntu18.* detected" ;
sudo apt-get -y install curl ;
sudo curl https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu20.04.sh | sudo bash ;
else
echo "Not support yet system release"
fi

141
install/install-KylinV10.sh Executable file
View File

@@ -0,0 +1,141 @@
#!/bin/bash
apt-get update
/usr/sbin/useradd -m -u 1536 -s /bin/false judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
for PKG in make flex g++ clang mariadb-client libmysqlclient-dev libmysql++-dev php-fpm nginx php-mysql php-common php-gd php-zip php-yaml fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml mariadb-server libmariadb-dev libmariadbclient-dev libmariadb-dev default-libmysqlclient-dev
do
apt-get install -y $PKG
done
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chown www-data -R /home/judge
chgrp judge -R /home/judge
chmod 755 -R /home/judge
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql < src/install/db.sql
echo "CREATE USER '$USER'@'localhost' identified by '$PASSWORD';grant all privileges on jol.* to '$USER'@'localhost' ; flush privileges;"|mysql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql
PHP_VER=`ls /etc/php | head -1`
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "hustoj nginx config added!"
else
sed -i "s/php7.4/php$PHP_VER/g" /etc/nginx/sites-enabled/default
sed -i "s#/var/www/html;#/home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
fi
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php$PHP_VER-fpm restart
service php$PHP_VER-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
cd /home/judge/src/install/
sed -i "s/ubuntu:22.04/debian12.2/g" Dockerfile
sed -i "s/libmysqlclient-dev/default-libmysqlclient-dev/" Dockerfile
sed -i "s/openjdk-17-jdk/gcc/" Dockerfile
bash docker.sh
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable nginx
systemctl enable mysql
systemctl enable php$PHP_VER-fpm
systemctl enable judged
echo "Note: skip-networking is needed for Andorid based Linux Deploy to start mariadb "
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 或者 http://$IP 或者 http://$LIP 注册用户admin获得管理员权限。"
echo "如果无法打开页面或无法注册用户,请检查上方数据库账号是否能正常连接数据库。"
echo "如果发现数据库账号登录错误可用sudo bash /home/judge/src/install/fixdb.sh 尝试修复。"
echo "遇到服务器内部错误500查看/var/log/nginx/error.log末尾寻找详细原因。"
echo "更多问题请查阅http://hustoj.com/"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"

136
install/install-centos7-bt.sh Executable file
View File

@@ -0,0 +1,136 @@
#!/bin/bash
echo "Welcome to install HUSTOJ on your BT panel,please prepare your database account!"
echo "Press Ctrl+C to Stop..."
echo "Input your database username:"
read DBUSER
echo "Input your database password:"
read DBPASS
DBNAME="jol"
CPU=`cat /proc/cpuinfo| grep "processor"| wc -l`
yum -y update
# avoid minimal installation no wget
yum -y install wget
yum -y install epel-release yum-utils
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install gcc-c++ mysql-devel glibc-static libstdc++-static flex java-1.8.0-openjdk java-1.8.0-openjdk-devel
# install semanage to setup selinux
yum -y install policycoreutils-python
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
service docker start
systemctl start mariadb.service
/usr/sbin/useradd -m -u 1536 -s /bin/false judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
cd src/install
docker build -t hustoj .
mysql -h localhost -uroot < db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -uroot
# mysqladmin -u root password $DBPASS
cd ../../
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown www run0 run1 run2 run3
fi
# sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
# sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$DBPASS/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
# sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
# sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$DBPASS\"/g" src/web/include/db_info.inc.php
sed -i "s+//date_default_timezone_set(\"PRC\");+date_default_timezone_set(\"PRC\");+g" src/web/include/db_info.inc.php
sed -i "s+//pdo_query(\"SET time_zone ='\+8:00'\");+pdo_query(\"SET time_zone ='\+8:00'\");+g" src/web/include/db_info.inc.php
chmod 750 -R /home/judge/data && chown -R www /home/judge/data
chmod 700 src/web/include/db_info.inc.php
chown www src/web/include/db_info.inc.php
chown www src/web/upload data run0 run1 run2 run3
# open http/https services.
firewall-cmd --permanent --add-service=http --add-service=https --zone=public
# reload firewall config
firewall-cmd --reload
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php.ini
# clean up
echo "clean up selinux module output files"
rm -rf my-phpfpm.mod my-phpfpm.pp
rm -rf my-ifconfig.mod my-ifconfig.pp
# restart nginx.service
systemctl restart nginx.service
# restart php-fpm.service.
systemctl restart php-fpm.service
chmod 755 /home/judge
chown www -R /home/judge/src/web/
cd /home/judge/src/core
chmod +x make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
chmod +x /etc/rc.d/rc.local
sed -i "s/exit 0//g" /etc/rc.d/rc.local
echo "/usr/bin/judged" >> /etc/rc.d/rc.local
echo "exit 0" >> /etc/rc.d/rc.local
fi
/usr/bin/judged
# change pwd
cd /home/judge/
# write password at the end of install
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$DBPASS/g" etc/judge.conf
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$DBPASS\"/g" src/web/include/db_info.inc.php
cd /home/judge/src/install
if docker build -t hustoj . ;then
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_PYTHON_FREE=0/OJ_PYTHON_FREE=1/g" /home/judge/etc/judge.conf
pkill -9 judged
/usr/bin/judged
fi
mkdir /var/log/hustoj/
chown www -R /var/log/hustoj/
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:root"
echo "password:$DBPASS"

176
install/install-centos7.sh Executable file
View File

@@ -0,0 +1,176 @@
#!/bin/bash
DBNAME="jol"
DBUSER="root"
DBPASS=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`cat /proc/cpuinfo| grep "processor"| wc -l`
yum -y update
# avoid minimal installation no wget
yum -y install wget
# install nginx
wget http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.14.0-1.el7_4.ngx.x86_64.rpm
rpm -ivh nginx-1.14.0-1.el7_4.ngx.x86_64.rpm
rm -rf nginx-1.14.0-1.el7_4.ngx.x86_64.rpm
yum -y install epel-release yum-utils
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum-config-manager --enable remi-php72
yum -y install nginx php-fpm php-mysqlnd php-xml php-gd php-mbstring gcc-c++ mysql-devel glibc-static libstdc++-static flex java-1.8.0-openjdk java-1.8.0-openjdk-devel
yum -y install mariadb mariadb-devel mariadb-server
# install semanage to setup selinux
yum -y install policycoreutils-python
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
service docker start
systemctl start mariadb.service
/usr/sbin/useradd -m -u 1536 -s /bin/false judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
cd src/install
docker build -t hustoj .
mysql -h localhost -uroot < db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -uroot
# mysqladmin -u root password $DBPASS
cd ../../
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown apache run0 run1 run2 run3
fi
# sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
# sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$DBPASS/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
# sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
# sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$DBPASS\"/g" src/web/include/db_info.inc.php
sed -i "s+//date_default_timezone_set(\"PRC\");+date_default_timezone_set(\"PRC\");+g" src/web/include/db_info.inc.php
sed -i "s+//pdo_query(\"SET time_zone ='\+8:00'\");+pdo_query(\"SET time_zone ='\+8:00'\");+g" src/web/include/db_info.inc.php
chmod 775 -R /home/judge/data && chgrp -R apache /home/judge/data
chmod 700 src/web/include/db_info.inc.php
chown apache src/web/include/db_info.inc.php
chown apache src/web/upload data run0 run1 run2 run3
# cp /etc/nginx/nginx.conf /home/judge/src/install/nginx.origin
mv /etc/nginx/conf.d/default.conf /home/judge/src/install/default.conf.bak
cp /home/judge/src/install/default.conf /etc/nginx/conf.d/default.conf
# startup nginx.service when booting.
systemctl enable nginx.service
# open http/https services.
firewall-cmd --permanent --add-service=http --add-service=https --zone=public
# reload firewall config
firewall-cmd --reload
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php.ini
# startup php-fpm.service when booting.
systemctl enable php-fpm.service
# startup mariadb.service when booting.
systemctl enable mariadb.service
# check module selinux policy modules
checkmodule /home/judge/src/install/my-phpfpm.te -M -m -o my-phpfpm.mod
checkmodule /home/judge/src/install/my-ifconfig.te -M -m -o my-ifconfig.mod
# package policy modules
semodule_package -m my-phpfpm.mod -o my-phpfpm.pp
semodule_package -m my-ifconfig.mod -o my-ifconfig.pp
# install policy modules
semodule -i my-phpfpm.pp
semodule -i my-ifconfig.pp
# clean up
echo "clean up selinux module output files"
rm -rf my-phpfpm.mod my-phpfpm.pp
rm -rf my-ifconfig.mod my-ifconfig.pp
# restart nginx.service
systemctl restart nginx.service
# restart php-fpm.service.
systemctl restart php-fpm.service
chmod 755 /home/judge
chown apache -R /home/judge/src/web/
mkdir /var/lib/php/session
chown apache /var/lib/php/session
cd /home/judge/src/core
chmod +x make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
chmod +x /etc/rc.d/rc.local
sed -i "s/exit 0//g" /etc/rc.d/rc.local
echo "/usr/bin/judged" >> /etc/rc.d/rc.local
echo "exit 0" >> /etc/rc.d/rc.local
fi
/usr/bin/judged
# change pwd
cd /home/judge/
# write password at the end of install
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$DBPASS/g" etc/judge.conf
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$DBPASS\"/g" src/web/include/db_info.inc.php
# change database password at the end of install
mysqladmin -u root password $DBPASS
mkdir /var/log/hustoj/
chown apache -R /var/log/hustoj/
# mono install for c#
yum -y install yum-utils
rpm --import "http://keyserver.Ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
yum-config-manager --add-repo http://download.mono-project.com/repo/centos/
yum -y update
yum -y install mono
ln -s /usr/bin/mcs /usr/bin/gmcs
#free pascal
wget https://download.sourceforge.net/project/freepascal/Linux/3.0.4/fpc-3.0.4-1.x86_64.rpm
rpm -ivh fpc-3.0.4-1.x86_64.rpm
rm -rf fpc-3.0.4-1.x86_64.rpm
# Go language
yum -y install golang
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:root"
echo "password:$DBPASS"

112
install/install-debian10+.sh Executable file
View File

@@ -0,0 +1,112 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /bin/false judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
for PKG in make flex g++ clang mariadb-client libmysqlclient-dev libmysql++-dev php-fpm nginx php-mysql php-common php-gd php-zip php-yaml fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml mariadb-server libmariadb-dev libmariadbclient-dev libmariadb-dev default-libmysqlclient-dev
do
apt-get install -y $PKG
done
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql < src/install/db.sql
echo "CREATE USER '$USER'@'localhost' identified by '$PASSWORD';grant all privileges on jol.* to '$USER'@'localhost' ; flush privileges;"|mysql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql
PHP_VER=`ls /etc/php | head -1`
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "hustoj nginx config added!"
else
sed -i "s/php7.4/php$PHP_VER/g" /etc/nginx/sites-enabled/default
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
fi
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php$PHP_VER-fpm restart
service php$PHP_VER-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
cd /home/judge/src/install/
sed -i "s/ubuntu:22.04/debian12.2/g" Dockerfile
sed -i "s/libmysqlclient-dev/default-libmysqlclient-dev/" Dockerfile
sed -i "s/openjdk-17-jdk/gcc/" Dockerfile
bash docker.sh
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable nginx
systemctl enable mysql
systemctl enable php$PHP_VER-fpm
systemctl enable judged
echo "Note: skip-networking is needed for Andorid based Linux Deploy to start mariadb "
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"

141
install/install-debian12.sh Executable file
View File

@@ -0,0 +1,141 @@
#!/bin/bash
apt-get update
/usr/sbin/useradd -m -u 1536 -s /bin/false judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
for PKG in make flex g++ clang mariadb-client libmysqlclient-dev libmysql++-dev php-fpm nginx php-mysql php-common php-gd php-zip php-yaml fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml mariadb-server libmariadb-dev libmariadbclient-dev libmariadb-dev default-libmysqlclient-dev
do
apt-get install -y $PKG
done
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chown www-data -R /home/judge
chgrp judge -R /home/judge
chmod 755 -R /home/judge
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql < src/install/db.sql
echo "CREATE USER '$USER'@'localhost' identified by '$PASSWORD';grant all privileges on jol.* to '$USER'@'localhost' ; flush privileges;"|mysql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql
PHP_VER=`ls /etc/php | head -1`
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "hustoj nginx config added!"
else
sed -i "s/php7.4/php$PHP_VER/g" /etc/nginx/sites-enabled/default
sed -i "s#/var/www/html;#/home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
fi
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php$PHP_VER-fpm restart
service php$PHP_VER-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
cd /home/judge/src/install/
sed -i "s/ubuntu:22.04/debian12.2/g" Dockerfile
sed -i "s/libmysqlclient-dev/default-libmysqlclient-dev/" Dockerfile
sed -i "s/openjdk-17-jdk/gcc/" Dockerfile
bash docker.sh
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable nginx
systemctl enable mysql
systemctl enable php$PHP_VER-fpm
systemctl enable judged
echo "Note: skip-networking is needed for Andorid based Linux Deploy to start mariadb "
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 或者 http://$IP 或者 http://$LIP 注册用户admin获得管理员权限。"
echo "如果无法打开页面或无法注册用户,请检查上方数据库账号是否能正常连接数据库。"
echo "如果发现数据库账号登录错误可用sudo bash /home/judge/src/install/fixdb.sh 尝试修复。"
echo "遇到服务器内部错误500查看/var/log/nginx/error.log末尾寻找详细原因。"
echo "更多问题请查阅http://hustoj.com/"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"

159
install/install-deepin23.sh Executable file
View File

@@ -0,0 +1,159 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
cd /home/judge/
chgrp www-data /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
for PKG in build-essential libmariadb++-dev php-fpm nginx mariadb-server php-mysql php-common php-gd php-zip php-mbstring php-xml php-yaml
do
apt-get install -y $PKG
apt-get install -f
done
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown -R www-data src/web/ data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
service mariadb start
mysql < src/install/db.sql
echo "grant all privileges on jol.* to '$USER' identified by '$PASSWORD';\n flush privileges;\n"|mysql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql
PHP_VER=`find /etc/init.d -name "php*"|grep -e '[[:digit:]]\.[[:digit:]]' -o`
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "hustoj nginx config added!"
else
sed -i "s#listen 80 default_server;#listen 80 default_server backlog=4096;#g" /etc/nginx/sites-enabled/default
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
#sed -i "s:php7.0:php7.2:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.0/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
fi
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf`
/etc/init.d/php$PHP_VER-fpm restart
service php$PHP_VER-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable nginx
systemctl enable mariadb
systemctl enable php$PHP_VER-fpm
systemctl enable hustoj
cd /home/judge/src/install
if test -f /.dockerenv ;then
echo "Already in docker, skip docker installation, install some compilers ... "
apt-get intall -f flex fp-compiler openjdk-14-jdk mono-devel
else
./docker.sh
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_PYTHON_FREE=0/OJ_PYTHON_FREE=1/g" /home/judge/etc/judge.conf
fi
cls
reset
IP=`curl http://hustoj.com/ip.php`
LIP=`ip a|grep inet|grep brd|head -1|awk '{print $2}'|awk -F/ '{print $1}'`
clear
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 或者 http://$IP 或者 http://$LIP 注册用户admin获得管理员权限。"
echo "如果无法打开页面或无法注册用户,请检查上方数据库账号是否能正常连接数据库。"
echo "如果发现数据库账号登录错误可用sudo bash /home/judge/src/install/fixdb.sh 尝试修复。"
echo "遇到服务器内部错误500查看/var/log/nginx/error.log末尾寻找详细原因。"
echo "更多问题请查阅http://hustoj.com/"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"

View File

@@ -0,0 +1,157 @@
#!/bin/bash
DBNAME="jol"
DBUSER="root"
DBPASS=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`cat /proc/cpuinfo| grep "processor"| wc -l`
yum -y update
# avoid minimal installation no wget
yum -y install wget
# install nginx
yum -y install nginx
yum -y install epel-release yum-utils
yum -y install nginx php-fpm php-mysqlnd php-xml php-gd php-mbstring gcc-c++ mysql-devel glibc-static libstdc++-static flex java-1.8.0-openjdk java-1.8.0-openjdk-devel
yum -y install mariadb mariadb-devel mariadb-server
# install semanage to setup selinux
yum -y install policycoreutils-python
systemctl start mariadb.service
/usr/sbin/useradd -m -u 1536 -s /bin/false judge
cd /home/judge/
yum -y install subversion
svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
cd src/install
mysql -h localhost -uroot < db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -uroot
# mysqladmin -u root password $DBPASS
cd ../../
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown apache run0 run1 run2 run3
fi
# sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
# sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$DBPASS/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
# sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
# sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$DBPASS\"/g" src/web/include/db_info.inc.php
sed -i "s+//date_default_timezone_set(\"PRC\");+date_default_timezone_set(\"PRC\");+g" src/web/include/db_info.inc.php
sed -i "s+//pdo_query(\"SET time_zone ='\+8:00'\");+pdo_query(\"SET time_zone ='\+8:00'\");+g" src/web/include/db_info.inc.php
chmod 775 -R /home/judge/data && chgrp -R apache /home/judge/data
chmod 700 src/web/include/db_info.inc.php
chown apache src/web/include/db_info.inc.php
chown apache src/web/upload data run0 run1 run2 run3
# cp /etc/nginx/nginx.conf /home/judge/src/install/nginx.origin
mv /etc/nginx/conf.d/default.conf /home/judge/src/install/default.conf.bak
cp /home/judge/src/install/default.conf /etc/nginx/conf.d/default.conf
# startup nginx.service when booting.
systemctl enable nginx.service
# open http/https services.
firewall-cmd --permanent --add-service=http --add-service=https --zone=public
# reload firewall config
firewall-cmd --reload
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php.ini
# startup php-fpm.service when booting.
systemctl enable php-fpm.service
# startup mariadb.service when booting.
systemctl enable mariadb.service
# check module selinux policy modules
checkmodule /home/judge/src/install/my-phpfpm.te -M -m -o my-phpfpm.mod
checkmodule /home/judge/src/install/my-ifconfig.te -M -m -o my-ifconfig.mod
# package policy modules
semodule_package -m my-phpfpm.mod -o my-phpfpm.pp
semodule_package -m my-ifconfig.mod -o my-ifconfig.pp
# install policy modules
semodule -i my-phpfpm.pp
semodule -i my-ifconfig.pp
# clean up
echo "clean up selinux module output files"
rm -rf my-phpfpm.mod my-phpfpm.pp
rm -rf my-ifconfig.mod my-ifconfig.pp
# restart nginx.service
systemctl restart nginx.service
# restart php-fpm.service.
systemctl restart php-fpm.service
chmod 755 /home/judge
chown apache -R /home/judge/src/web/
mkdir /var/lib/php/session
chown apache /var/lib/php/session
cd /home/judge/src/core
chmod +x make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.d/rc.local ; then
echo "auto start judged added!"
else
chmod +x /etc/rc.d/rc.local
sed -i "s/exit 0//g" /etc/rc.d/rc.local
echo "/usr/bin/judged" >> /etc/rc.d/rc.local
echo "exit 0" >> /etc/rc.d/rc.local
fi
/usr/bin/judged
# change pwd
cd /home/judge/
# write password at the end of install
sed -i "s/OJ_PASSWORD[[:space:]]*=[[:space:]]*root/OJ_PASSWORD=$DBPASS/g" etc/judge.conf
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$DBPASS\"/g" src/web/include/db_info.inc.php
# change database password at the end of install
mysqladmin -u root password $DBPASS
# mono install for c#
yum -y install yum-utils
rpm --import "http://keyserver.Ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
yum-config-manager --add-repo http://download.mono-project.com/repo/centos/
yum -y update
yum -y install mono
ln -s /usr/bin/mcs /usr/bin/gmcs
#free pascal
wget https://download.sourceforge.net/project/freepascal/Linux/3.0.4/fpc-3.0.4.mipsel-linux.tar
#to be continue
# Go language
yum -y install golang
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:root"
echo "password:$DBPASS"

53
install/install-judge.sh Executable file
View File

@@ -0,0 +1,53 @@
#!/bin/bash
# usage : sudo ./install-judge.sh <ojurl> <judger_name> <judger_password> <localpath>
# example :
# step 0: registe a new user name judger1 on OJ web (http://10.1.2.100/) ,password :judg3r_p@ss
# step 1: add http_judge privilege to judger1
# step 2: install a new ubuntu on another node in same LAN , and open a new console to execute step 3
# step 3: sudo ./install-judge.sh http://10.1.2.100/ judger1 judg3r_p@ss /home/judge/
if [ $# != 4 ] ; then
head -7 $0
exit 1;
fi
URL=$1
USER=$2
PASSWORD=$3
TARGET=$4
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
mkdir -p $TARGET
cd $TARGET/
mkdir src
svn co https://github.com/zhblue/hustoj/trunk/trunk/core src/core
svn co https://github.com/zhblue/hustoj/trunk/trunk/install src/install
apt-get install -y make flex g++ libmysqlclient-dev libmysql++-dev
cd src/install
sudo bash docker.sh
cd ../..
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log
cp src/install/java0.policy $TARGET/etc
cp src/install/judge.conf $TARGET/etc
chmod +x src/install/ans2out
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_HTTP_JUDGE=0/OJ_HTTP_JUDGE=1/g" etc/judge.conf
sed -i "s|OJ_HTTP_BASEURL=http://127.0.0.1/JudgeOnline|OJ_HTTP_BASEURL=$URL|g" etc/judge.conf
sed -i "s/OJ_HTTP_USERNAME=admin/OJ_HTTP_USERNAME=$USER/g" etc/judge.conf
sed -i "s/OJ_HTTP_PASSWORD=admin/OJ_HTTP_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
COMPENSATION=`grep 'mips' /proc/cpuinfo|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" etc/judge.conf
cd src/core
chmod +x ./make.sh
if [ ! -e /usr/bin/judged ] ; then
bash ./make.sh
fi
/usr/bin/judged $TARGET

86
install/install-raspbian10.sh Executable file
View File

@@ -0,0 +1,86 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /bin/false judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
PHP_VER=`apt-cache search php-fpm|grep -e '[[:digit:]]\.[[:digit:]]' -o`
if [ "$PHP_VER" = "" ] ; then PHP_VER="7.4"; fi
for PKG in make flex g++ clang libmariadb++-dev mariadb-server php${PHP_VER}-fpm php${PHP_VER}-memcache php-zip php-xml php-mbstring memcached nginx php${PHP_VER}-mysql php${PHP_VER}-gd fp-compiler openjdk-9-jdk
do
apt-get install -y $PKG
done
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
mkdir etc data log
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
mkdir run0 run1 run2 run3
chown judge run0 run1 run2 run3
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql < src/install/db.sql
echo "CREATE USER '$USER'@'localhost' identified by '$PASSWORD';grant all privileges on jol.* to '$USER'@'localhost' ;\n flush privileges;\n"|mysql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
#cp src/install/nginx.default /etc/nginx/sites-available/default
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
echo "modify the default site"
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.0:php${PHP_VER}:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php${PHP_VER}/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php${PHP_VER}/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf`
/etc/init.d/php${PHP_VER}-fpm restart
service php${PHP_VER}-fpm restart
cd src/core
bash ./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
/usr/bin/judged

168
install/install-ubuntu-bt.sh Executable file
View File

@@ -0,0 +1,168 @@
#!/bin/bash
#detect and refuse to run under WSL
if [ -d /mnt/c ]; then
echo "WSL is NOT supported."
exit 1
fi
echo "Welcome to install HUSTOJ on your BT panel,please prepare your database account!"
echo "Press Ctrl+C to Stop..."
echo "Input your database username:"
read USER
echo "Input your database password:"
read PASSWORD
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
apt-get update && apt-get -y upgrade
apt-get install -y software-properties-common
add-apt-repository universe
add-apt-repository multiverse
add-apt-repository restricted
# 解决宝塔收集用户信息问题
chattr +i /www/server/panel/script/site_task.py
chattr +i -R /www/server/panel/logs/request
apt-get update && apt-get -y upgrade
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
cd /home/judge/ || exit
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
#手工解决阿里云软件源的包依赖问题
apt install libssl1.1=1.1.1f-1ubuntu2.8 -y --allow-downgrades
apt-get install -y libmysqlclient-dev
apt-get install -y libmysql++-dev
for pkg in net-tools make g++ mysql-client
do
while ! apt-get install -y "$pkg"
do
echo "Network fail, retry... you might want to change another apt source for install"
echo "Or you might need to add [universe] [multiverse] to your /etc/apt/sources.list"
done
done
CPU=$(grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}')
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chgrp www /home/judge
chown -R www src/web/
chown -R root:root src/web/.svn
chmod 750 -R src/web/.svn
chown www:judge src/web/upload
chown www:judge data
chmod 711 -R data
mysql -h localhost -u"$USER" -p"$PASSWORD" < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
COMPENSATION=$(grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}')
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
cd src/core || exit
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
#systemctl enable judged
PHP_INI=`find /www/ -name php.ini`
sed -i 's/passthru,exec,system,/passthru,exec,/g' $PHP_INI
#shutdown warning message for php in BT Panel
sed -i 's#//ini_set("display_errors", "On");#ini_set("display_errors", "Off");#g' /home/judge/src/web/include/db_info.inc.php
mkdir /var/log/hustoj/
chown www -R /var/log/hustoj/
cd /home/judge/src/install
if test -f /.dockerenv ;then
echo "Already in docker, skip docker installation, install some compilers ... "
apt-get intall -y flex fp-compiler openjdk-14-jdk mono-devel
else
bash docker.sh
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_PYTHON_FREE=0/OJ_PYTHON_FREE=1/g" /home/judge/etc/judge.conf
fi
clear
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 注册用户admin获得管理员权限。"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"
echo " 使用Java前请重启服务器sudo reboot"

149
install/install-ubuntu18.04.sh Executable file
View File

@@ -0,0 +1,149 @@
#!/bin/bash
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
for pkg in "net-tools make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm nginx mysql-server php-mysql php-common php-gd php-zip fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml php-curl php-intl php-xmlrpc php-soap php-yaml"
do
while ! apt-get install -y $pkg
do
echo "Network fail, retry... you might want to change another apt source for install"
done
done
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data src/web/
chown -R root:root src/web/.svn
chmod 750 -R src/web/.svn
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u$USER -p$PASSWORD
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
echo "modify the default site"
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.0:php7.2:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.2/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.2/fpm/php.ini
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' `find /etc/php -name www.conf`
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/3000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
/etc/init.d/php7.2-fpm restart
service php7.2-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable hustoj
systemctl enable nginx
systemctl enable mysql
systemctl enable php7.2-fpm
mkdir /var/log/hustoj/
chown www-data -R /var/log/hustoj/
cls
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFOMANTION ON ANY PUBLIC CHANNEL!"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ 扫码加群 "

196
install/install-ubuntu20.04.sh Executable file
View File

@@ -0,0 +1,196 @@
#!/bin/bash
#detect and refuse to run under WSL
if [ -d /mnt/c ]; then
echo "WSL is NOT recommended."
# exit 1
fi
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
sed -i 's/cn.archive.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list
apt-get update && apt-get -y upgrade
apt-get install -y software-properties-common
add-apt-repository universe
add-apt-repository multiverse
add-apt-repository restricted
apt-get update && apt-get -y upgrade
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
cd /home/judge/ || exit
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
#手工解决阿里云软件源的包依赖问题
apt-get install -y libmysqlclient-dev
apt-get install -y libmysql++-dev
apt-get install -y libmariadb-dev libmariadbclient-dev libmariadb-dev
for pkg in net-tools make flex g++ php-fpm nginx mariadb-server php-mysql php-common php-gd php-zip php-mbstring php-xml php-curl php-intl php-xmlrpc php-soap php-yaml tzdata
do
while ! apt-get install -y "$pkg"
do
echo "Network fail, retry... you might want to change another apt source for install"
echo "Or you might need to add [universe] [multiverse] to your /etc/apt/sources.list"
done
done
USER=$(grep user /etc/mysql/debian.cnf|head -1|awk '{print $3}')
PASSWORD=$(grep password /etc/mysql/debian.cnf|head -1|awk '{print $3}')
CPU=$(grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}')
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data src/web/
chown -R root:root src/web/.svn
chmod 750 -R src/web/.svn
chown www-data:judge src/web/upload
chown www-data:judge data
chmod 711 -R data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
mysql -h localhost -u"$USER" -p"$PASSWORD" < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
echo "insert into jol.privilege values('admin','source_browser','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
echo "modify the default site"
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.0:php7.4:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.4/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.4/fpm/php.ini
WWW_CONF=$(find /etc/php -name www.conf)
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' "$WWW_CONF"
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' "$WWW_CONF"
COMPENSATION=$(grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/3000)}')
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
PHP_FPM=$(find /etc/init.d/ -name "php*-fpm")
$PHP_FPM restart
PHP_FPM=$(service --status-all|grep php|awk '{print $4}')
if [ "$PHP_FPM" != "" ]; then service "$PHP_FPM" restart ;else echo "NO PHP FPM";fi;
cd src/core || exit
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
service cron reload
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable hustoj
systemctl enable nginx
systemctl enable mysql
systemctl enable php7.4-fpm
#systemctl enable judged
sed -i "s#interactive_timeout=120#interactive_timeout=20#g" /etc/mysql/mysql.conf.d/mysqld.cnf
sed -i "s#wait_timeout=120#wait_timeout=20#g" /etc/mysql/mysql.conf.d/mysqld.cnf
/etc/init.d/mysql restart
mkdir /var/log/hustoj/
chown www-data -R /var/log/hustoj/
cd /home/judge/src/install
if test -f /.dockerenv ;then
echo "Already in docker, skip docker installation, install some compilers ... "
apt-get intall -y flex fp-compiler openjdk-17-jdk mono-devel
else
bash docker.sh
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_PYTHON_FREE=0/OJ_PYTHON_FREE=1/g" /home/judge/etc/judge.conf
fi
cls
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 注册用户admin获得管理员权限。"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"

175
install/install-ubuntu22.04-bt.sh Executable file
View File

@@ -0,0 +1,175 @@
#!/bin/bash
#detect and refuse to run under WSL
if [ -d /mnt/c ]; then
echo "WSL is NOT supported."
exit 1
fi
echo "Welcome to install HUSTOJ on your BT panel,please prepare your database account!"
echo "Press Ctrl+C to Stop..."
echo "Input your database username:"
read USER
echo "Input your database password:"
read PASSWORD
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
sed -i 's/cn.archive.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list
sed -i "s|#\$nrconf{restart} = 'i'|\$nrconf{restart} = 'a'|g" /etc/needrestart/needrestart.conf
apt-get update && apt-get -y upgrade
apt-get install -y software-properties-common
add-apt-repository universe
add-apt-repository multiverse
add-apt-repository restricted
# 解决宝塔收集用户信息问题
chattr +i /www/server/panel/script/site_task.py
chattr +i -R /www/server/panel/logs/request
apt-get update && apt-get -y upgrade
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
cd /home/judge/ || exit
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
#手工解决阿里云软件源的包依赖问题
apt install libssl1.1=1.1.1f-1ubuntu2.8 -y --allow-downgrades
apt-get install -y libmysqlclient-dev
apt-get install -y libmysql++-dev
for pkg in net-tools make g++ mysql-client
do
while ! apt-get install -y "$pkg"
do
echo "Network fail, retry... you might want to change another apt source for install"
echo "Or you might need to add [universe] [multiverse] to your /etc/apt/sources.list"
done
done
CPU=$(grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}')
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chgrp www /home/judge
chown -R www src/web/
chown -R root:root src/web/.svn
chmod 750 -R src/web/.svn
chown www:judge src/web/upload
chown www:judge data
chmod 711 -R data
mysql -h localhost -u"$USER" -p"$PASSWORD" < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
echo "insert into jol.privilege values('admin','source_browser','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
COMPENSATION=$(grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}')
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
cd src/core || exit
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
#systemctl enable judged
PHP_INI=`find /www/ -name php.ini`
sed -i 's/passthru,exec,system,/passthru,exec,/g' $PHP_INI
#shutdown warning message for php in BT Panel
sed -i 's#//ini_set("display_errors", "Off");#ini_set("display_errors", "Off");#g' /home/judge/src/web/include/db_info.inc.php
mkdir /var/log/hustoj/
chown www -R /var/log/hustoj/
cd /home/judge/src/install
if test -f /.dockerenv ;then
echo "Already in docker, skip docker installation, install some compilers ... "
apt-get intall -y flex fp-compiler openjdk-14-jdk mono-devel
else
sed -i 's/ubuntu:20/ubuntu:22/g' Dockerfile
sed -i 's|/usr/include/c++/9|/usr/include/c++/11|g' Dockerfile
bash docker.sh
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_PYTHON_FREE=0/OJ_PYTHON_FREE=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_INTERNAL_CLIENT=1/OJ_INTERNAL_CLIENT=0/g" /home/judge/etc/judge.conf
sed -i "s|OJ_DOCKER_PATH=/usr/bin/docker|OJ_DOCKER_PATH=/usr/bin/docker|g" /home/judge/etc/judge.conf
fi
clear
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 注册用户admin获得管理员权限。"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"
echo " 使用Java前请重启服务器sudo reboot"

View File

@@ -0,0 +1,246 @@
#!/bin/bash
#detect and refuse to run under WSL
if [ -d /mnt/c ]; then
echo "WSL is NOT supported."
exit 1
fi
MEM=`free -m|grep Mem|awk '{print $2}'`
if [ "$MEM" -lt "1000" ] ; then
echo "Memory size less than 1GB."
if grep 'swap' /etc/fstab ; then
echo "already has swap"
else
dd if=/dev/zero of=/swap bs=1M count=1024
chmod 600 /swap
mkswap /swap
swapon /swap
echo "/swap none swap defaults 0 0 " >> /etc/fstab
/etc/init.d/multipath-tools stop
screen -d -m watch pkill -9 snapd
screen -d -m watch pkill -9 ds-identify
fi
else
echo "Memory size : $MEM MB"
fi
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
sed -i 's/cn.archive.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list
sed -i "s|#\$nrconf{restart} = 'i'|\$nrconf{restart} = 'a'|g" /etc/needrestart/needrestart.conf
apt-get update && apt-get -y upgrade
apt-get install -y software-properties-common
add-apt-repository -y universe
add-apt-repository -y multiverse
add-apt-repository -y restricted
apt-get update && apt-get -y upgrade
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
cd /home/judge/ || exit
#using tgz src files
if git clone https://gitee.com/zhblue/hustoj.git git ; then
cp -a git/trunk src
else
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
fi
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
#手工解决阿里云软件源的包依赖问题 apt install libssl1.1=1.1.1f-1ubuntu2.8 -y --allow-downgrades
apt-get install -y libmysqlclient-dev
apt-get install -y libmysql++-dev
apt-get install -y libmariadb-dev libmariadbclient-dev libmariadb-dev
PHP_VER=`apt-cache search php-fpm|grep -e '[[:digit:]]\.[[:digit:]]' -o`
if [ "$PHP_VER" = "" ] ; then PHP_VER="8.1"; fi
for pkg in net-tools make g++ php$PHP_VER-fpm nginx php$PHP_VER-mysql php$PHP_VER-common php$PHP_VER-gd php$PHP_VER-zip php$PHP_VER-mbstring php$PHP_VER-xml php$PHP_VER-curl php$PHP_VER-intl php$PHP_VER-xmlrpc php$PHP_VER-soap php-yaml php-apcu tzdata
do
while ! apt-get install -y "$pkg"
do
dpkg --configure -a
apt-get install -f
echo "Network fail, retry... you might want to change another apt source for install"
done
done
apt-get install -y mariadb-server
service php$PHP_VER-fpm start
service mariadb start
service nginx start
chgrp www-data /home/judge
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
mysql < src/install/db.sql
echo "CREATE USER $USER identified by '$PASSWORD';grant all privileges on jol.* to $USER ;flush privileges;"|mysql
CPU=$(grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}')
MEM=`free -m|grep Mem|awk '{print $2}'`
if [ "$MEM" -lt "1000" ] ; then
echo "Memory size less than 1GB."
if grep 'key_buffer_size = 1M' /etc/fstab ; then
echo "already trim config"
else
sed -i 's/#key_buffer_size = 128M/key_buffer_size = 1M/' /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i 's/#table_cache = 64/#table_cache = 5/' /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i 's/#skip-name-resolve/skip-name-resolve/' /etc/mysql/mariadb.conf.d/50-server.cnf
service mariadb restart
free -h
fi
else
echo "Memory size : $MEM MB"
fi
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out /home/judge/src/install/*.sh
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
chown -R root:root etc
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data:www-data src/web/
chown -R root:root src/web/.svn
chmod 750 -R src/web/.svn
chown www-data:www-data src/web/upload
chown www-data:judge data
chmod 750 -R data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 280m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
echo "insert into jol.privilege values('admin','source_browser','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
echo "modify the default site"
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.4:php$PHP_VER:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
sed -i "s|fastcgi_pass 127.0.0.1:9000;|fastcgi_pass 127.0.0.1:9000;\n\t\tfastcgi_buffer_size 256k;\n\t\tfastcgi_buffers 32 64k;|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 180M/g" /etc/php/$PHP_VER/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 180M/g" /etc/php/$PHP_VER/fpm/php.ini
WWW_CONF=$(find /etc/php -name www.conf)
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' "$WWW_CONF"
sed -i 's/pm.max_children = 5/pm.max_children = 600/g' "$WWW_CONF"
COMPENSATION=$(grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/3000)}')
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
PHP_FPM=$(find /etc/init.d/ -name "php*-fpm")
$PHP_FPM restart
PHP_FPM=$(service --status-all|grep php|awk '{print $4}')
if [ "$PHP_FPM" != "" ]; then service "$PHP_FPM" restart ;else echo "NO PHP FPM";fi;
cd src/core || exit
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
/etc/init.d/cron reload
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable hustoj
systemctl enable nginx
systemctl enable mariadb
systemctl enable php$PHP_VER-fpm
#systemctl enable judged
/etc/init.d/mariadb start
mkdir /var/log/hustoj/
chown www-data -R /var/log/hustoj/
cd /home/judge/src/install
if test -f /.dockerenv ;then
echo "Already in docker, skip docker installation, install some compilers ... "
apt-get intall -y flex fp-compiler openjdk-14-jdk mono-devel
else
sed -i 's/ubuntu:20/ubuntu:22/g' Dockerfile
sed -i 's|/usr/include/c++/9|/usr/include/c++/11|g' Dockerfile
bash docker.sh
fi
IP=`curl http://hustoj.com/ip.php`
LIP=`ip a|grep inet|grep brd|head -1|awk '{print $2}'|awk -F/ '{print $1}'`
clear
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 或者 http://$IP 或者 http://$LIP 注册用户admin获得管理员权限。"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"

262
install/install-ubuntu22.04.sh Executable file
View File

@@ -0,0 +1,262 @@
#!/bin/bash
#detect and refuse to run under WSL
if [ -d /mnt/c ]; then
echo "WSL is NOT recommended."
# exit 1
fi
MEM=`free -m|grep Mem|awk '{print $2}'`
if [ "$MEM" -lt "2000" ] ; then
echo "Memory size less than 2GB."
if grep 'swap' /etc/fstab ; then
echo "already has swap"
else
dd if=/dev/zero of=/swap bs=2M count=1024
chmod 600 /swap
mkswap /swap
swapon /swap
echo "/swap none swap defaults 0 0 " >> /etc/fstab
/etc/init.d/multipath-tools stop
pkill -9 snapd
pkill -9 ds-identify
fi
else
echo "Memory size : $MEM MB"
fi
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
sed -i 's/cn.archive.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list
sed -i "s|#\$nrconf{restart} = 'i'|\$nrconf{restart} = 'a'|g" /etc/needrestart/needrestart.conf
apt autoremove -y --purge needrestart
apt-get update && apt-get -y upgrade
apt-get install -y software-properties-common
add-apt-repository -y universe
add-apt-repository -y multiverse
add-apt-repository -y restricted
apt-get update && apt-get -y upgrade
#apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
cd /home/judge/ || exit
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
#svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
#手工解决阿里云软件源的包依赖问题 apt install libssl1.1=1.1.1f-1ubuntu2.8 -y --allow-downgrades
apt-get install -y libmysqlclient-dev
apt-get install -y libmysql++-dev
apt-get install -y libmariadb-dev libmariadbclient-dev libmariadb-dev
PHP_VER=`apt-cache search php-fpm|grep -e '[[:digit:]]\.[[:digit:]]' -o`
if [ "$PHP_VER" = "" ] ; then PHP_VER="8.1"; fi
for pkg in net-tools make g++ php$PHP_VER-fpm nginx php$PHP_VER-mysql php$PHP_VER-common php$PHP_VER-gd php$PHP_VER-zip php$PHP_VER-mbstring php$PHP_VER-xml php$PHP_VER-curl php$PHP_VER-intl php$PHP_VER-xmlrpc php$PHP_VER-soap php-yaml php-apcu tzdata
do
while ! apt-get install -y "$pkg"
do
dpkg --configure -a
apt-get install -f
echo "Network fail, retry... you might want to change another apt source for install"
done
done
apt-get install -y mariadb-server
service php$PHP_VER-fpm start
service mariadb start
service nginx start
chgrp www-data /home/judge
chmod +x /home/judge/src/install/*
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
mysql < src/install/db.sql
echo "DROP USER $USER;" | mysql
echo "CREATE USER $USER identified by '$PASSWORD';grant all privileges on jol.* to $USER ;flush privileges;"|mysql
CPU=$(grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}')
MEM=`free -m|grep Mem|awk '{print $2}'`
if [ "$MEM" -lt "1000" ] ; then
echo "Memory size less than 1GB."
if grep 'key_buffer_size = 1M' /etc/mysql/mariadb.conf.d/50-server.cnf ; then
echo "already trim config"
else
sed -i 's/#key_buffer_size = 128M/key_buffer_size = 1M/' /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i 's/#table_cache = 64/#table_cache = 5/' /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i 's/#skip-name-resolve/skip-name-resolve/' /etc/mysql/mariadb.conf.d/50-server.cnf
service mariadb restart
free -h
fi
else
echo "Memory size : $MEM MB"
fi
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out /home/judge/src/install/*.sh
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=.*/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=.*/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
chown -R root:root etc
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\".*\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\".*\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data:www-data src/web/
chown -R root:root src/web/.svn
chmod 750 -R src/web/.svn
chown www-data:www-data src/web/upload
chown www-data:judge data
chmod 750 -R data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i 's/# multi_accept on;/ multi_accept on;/' /etc/nginx/nginx.conf
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 500m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
echo "insert into jol.privilege values('admin','source_browser','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
echo "modify the default site"
sed -i "s#listen 80 default_server;#listen 80 default_server backlog=4096;#g" /etc/nginx/sites-enabled/default
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.4:php$PHP_VER:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
sed -i "s|fastcgi_pass 127.0.0.1:9000;|fastcgi_pass 127.0.0.1:9000;\n\t\tfastcgi_buffer_size 256k;\n\t\tfastcgi_buffers 32 64k;|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 500M/g" /etc/php/$PHP_VER/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 500M/g" /etc/php/$PHP_VER/fpm/php.ini
if grep "opcache.jit_buffer_size" /etc/php/$PHP_VER/fpm/php.ini ; then
echo "opcache for jit is already enabled ... "
else
sed -i "s|opcache.lockfile_path=/tmp|opcache.lockfile_path=/tmp\nopcache.jit_buffer_size=16M|g" /etc/php/$PHP_VER/fpm/php.ini
fi
WWW_CONF=$(find /etc/php -name www.conf)
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' "$WWW_CONF"
sed -i 's/pm.max_children = 5/pm.max_children = 600/g' "$WWW_CONF"
sed -i 's/;listen.backlog = 511/listen.backlog = 4096/g' "$WWW_CONF"
COMPENSATION=$(grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/3000)}')
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
PHP_FPM=$(find /etc/init.d/ -name "php*-fpm")
$PHP_FPM restart
PHP_FPM=$(service --status-all|grep php|awk '{print $4}')
if [ "$PHP_FPM" != "" ]; then service "$PHP_FPM" restart ;else echo "NO PHP FPM";fi;
cd src/core || exit
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf
echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf
echo "0 * * * * /home/judge/src/install/oomsaver.sh" >> conf
crontab conf
rm -f conf
/etc/init.d/cron reload
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable hustoj
systemctl enable nginx
systemctl enable mariadb
systemctl enable php$PHP_VER-fpm
#systemctl enable judged
/etc/init.d/mariadb start
mkdir /var/log/hustoj/
chown www-data -R /var/log/hustoj/
cd /home/judge/src/install
if test -f /.dockerenv ;then
echo "Already in docker, skip docker installation, install some compilers ... "
apt-get intall -y flex fp-compiler openjdk-14-jdk mono-devel
else
sed -i 's/ubuntu:20/ubuntu:22/g' Dockerfile
sed -i 's|/usr/include/c++/9|/usr/include/c++/11|g' Dockerfile
bash docker.sh
fi
IP=`curl http://hustoj.com/ip.php`
LIP=`ip a|grep inet|grep brd|head -1|awk '{print $2}'|awk -F/ '{print $1}'`
clear
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 或者 http://$IP 或者 http://$LIP 注册用户admin获得管理员权限。"
echo "如果无法打开页面或无法注册用户,请检查上方数据库账号是否能正常连接数据库。"
echo "如果发现数据库账号登录错误可用sudo bash /home/judge/src/install/fixdb.sh 尝试修复。"
echo "遇到服务器内部错误500查看/var/log/nginx/error.log末尾寻找详细原因。"
echo "更多问题请查阅http://hustoj.com/"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"

267
install/install-ubuntu24.04.sh Executable file
View File

@@ -0,0 +1,267 @@
#!/bin/bash
#detect and refuse to run under WSL
if [ -d /mnt/c ]; then
echo "WSL is NOT recommended."
# exit 1
fi
MEM=`free -m|grep Mem|awk '{print $2}'`
NBUFF=512
if [ "$MEM" -lt "2000" ] ; then
echo "Memory size less than 2GB."
NBUFF=128
if grep 'swap' /etc/fstab ; then
echo "already has swap"
else
dd if=/dev/zero of=/swap bs=2M count=1024
chmod 600 /swap
mkswap /swap
swapon /swap
echo "/swap none swap defaults 0 0 " >> /etc/fstab
/etc/init.d/multipath-tools stop
pkill -9 snapd
pkill -9 ds-identify
fi
else
echo "Memory size : $MEM MB"
fi
sed -i 's/tencentyun/aliyun/g' /etc/apt/sources.list
sed -i 's/cn.archive.ubuntu/mirrors.aliyun/g' /etc/apt/sources.list
sed -i "s|#\$nrconf{restart} = 'i'|\$nrconf{restart} = 'a'|g" /etc/needrestart/needrestart.conf
apt autoremove -y --purge needrestart
apt-get update && apt-get -y upgrade
apt-get install -y software-properties-common
add-apt-repository -y universe
add-apt-repository -y multiverse
add-apt-repository -y restricted
apt-get update && apt-get -y upgrade
#apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /sbin/nologin judge
cd /home/judge/ || exit
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
#svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
#手工解决阿里云软件源的包依赖问题 apt install libssl1.1=1.1.1f-1ubuntu2.8 -y --allow-downgrades
apt-get install -y libmysqlclient-dev
apt-get install -y libmysql++-dev
apt-get install -y libmariadb-dev libmariadbclient-dev
PHP_VER=`apt-cache search php-fpm|grep -e '[[:digit:]]\.[[:digit:]]' -o`
if [ "$PHP_VER" = "" ] ; then PHP_VER="8.1"; fi
for pkg in net-tools make g++ php$PHP_VER-fpm nginx php$PHP_VER-mysql php$PHP_VER-common php$PHP_VER-gd php$PHP_VER-zip php$PHP_VER-mbstring php$PHP_VER-xml php$PHP_VER-curl php$PHP_VER-intl php$PHP_VER-xmlrpc php$PHP_VER-soap php-yaml php-apcu tzdata
do
while ! apt-get install -y "$pkg"
do
dpkg --configure -a
apt-get install -f
echo "Network fail, retry... you might want to change another apt source for install"
done
done
apt-get install -y mariadb-server
service php$PHP_VER-fpm start
service mariadb start
service nginx start
chgrp www-data /home/judge
chmod +x /home/judge/src/install/*
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
mysql < src/install/db.sql
echo "DROP USER $USER;" | mysql
echo "CREATE USER $USER identified by '$PASSWORD';grant all privileges on jol.* to $USER ;flush privileges;"|mysql
CPU=$(grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}')
MEM=`free -m|grep Mem|awk '{print $2}'`
if [ "$MEM" -lt "1000" ] ; then
echo "Memory size less than 1GB."
if grep 'key_buffer_size = 1M' /etc/mysql/mariadb.conf.d/50-server.cnf ; then
echo "already trim config"
else
sed -i 's/#key_buffer_size = 128M/key_buffer_size = 1M/' /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i 's/#table_cache = 64/#table_cache = 5/' /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i 's/#skip-name-resolve/skip-name-resolve/' /etc/mysql/mariadb.conf.d/50-server.cnf
service mariadb restart
free -h
fi
else
echo "Memory size : $MEM MB"
fi
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out /home/judge/src/install/*.sh
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=.*/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=.*/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
chown -R root:root etc
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\".*\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\".*\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown -R www-data:www-data src/web/
chown -R root:root src/web/.svn
chmod 750 -R src/web/.svn
chown www-data:www-data src/web/upload
chown www-data:judge data
chmod 750 -R data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i 's/# multi_accept on;/ multi_accept on;/' /etc/nginx/nginx.conf
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 500m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
echo "insert into jol.privilege values('admin','source_browser','true','N');"|mysql -h localhost -u"$USER" -p"$PASSWORD"
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "default site modified!"
else
echo "modify the default site"
sed -i "s#listen 80 default_server;#listen 80 default_server backlog=4096;#g" /etc/nginx/sites-enabled/default
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added by hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.4:php$PHP_VER:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
sed -i "s|fastcgi_pass 127.0.0.1:9000;|fastcgi_pass 127.0.0.1:9000;\n\t\tfastcgi_buffer_size 256k;\n\t\tfastcgi_buffers $NBUFF 64k;|g" /etc/nginx/sites-enabled/default
fi
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 500M/g" /etc/php/$PHP_VER/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 500M/g" /etc/php/$PHP_VER/fpm/php.ini
if grep 'date.timezone = PRC' /etc/php/$PHP_VER/fpm/php.ini ; then
echo "date.timezone = PRC is already set ... "
else
sed -i 's/;date.timezone =/date.timezone = PRC/' /etc/php/$PHP_VER/fpm/php.ini
fi
if grep "opcache.jit_buffer_size" /etc/php/$PHP_VER/fpm/php.ini ; then
echo "opcache for jit is already enabled ... "
else
sed -i "s|opcache.lockfile_path=/tmp|opcache.lockfile_path=/tmp\nopcache.jit_buffer_size=16M|g" /etc/php/$PHP_VER/fpm/php.ini
fi
WWW_CONF=$(find /etc/php -name www.conf)
sed -i 's/;request_terminate_timeout = 0/request_terminate_timeout = 128/g' "$WWW_CONF"
sed -i 's/pm.max_children = 5/pm.max_children = 600/g' "$WWW_CONF"
sed -i 's/;listen.backlog = 511/listen.backlog = 4096/g' "$WWW_CONF"
COMPENSATION=$(grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/3000)}')
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
PHP_FPM=$(find /etc/init.d/ -name "php*-fpm")
$PHP_FPM restart
PHP_FPM=$(service --status-all|grep php|awk '{print $4}')
if [ "$PHP_FPM" != "" ]; then service "$PHP_FPM" restart ;else echo "NO PHP FPM";fi;
cd src/core || exit
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf
echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf
echo "0 * * * * /home/judge/src/install/oomsaver.sh" >> conf
crontab conf
rm -f conf
/etc/init.d/cron reload
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable hustoj
systemctl enable nginx
systemctl enable mariadb
systemctl enable php$PHP_VER-fpm
#systemctl enable judged
/etc/init.d/mariadb start
mkdir /var/log/hustoj/
chown www-data -R /var/log/hustoj/
cd /home/judge/src/install
if test -f /.dockerenv ;then
echo "Already in docker, skip docker installation, install some compilers ... "
apt-get intall -y flex fp-compiler openjdk-14-jdk mono-devel
else
sed -i 's/ubuntu:20/ubuntu:22/g' Dockerfile
sed -i 's|/usr/include/c++/9|/usr/include/c++/11|g' Dockerfile
bash docker.sh
fi
IP=`curl http://hustoj.com/ip.php`
LIP=`ip a|grep inet|grep brd|head -1|awk '{print $2}'|awk -F/ '{print $1}'`
clear
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 或者 http://$IP 或者 http://$LIP 注册用户admin获得管理员权限。"
echo "如果无法打开页面或无法注册用户,请检查上方数据库账号是否能正常连接数据库。"
echo "如果发现数据库账号登录错误可用sudo bash /home/judge/src/install/fixdb.sh 尝试修复。"
echo "遇到服务器内部错误500查看/var/log/nginx/error.log末尾寻找详细原因。"
echo "更多问题请查阅http://hustoj.com/"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"

153
install/install-uos20.sh Executable file
View File

@@ -0,0 +1,153 @@
#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 -s /bin/false judge
cd /home/judge/
#using tgz src files
wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz
tar xzf hustoj.tar.gz
svn up src
#svn co https://github.com/zhblue/hustoj/trunk/trunk/ src
for PKG in build-essential make g++ clang libmariadb++-dev php-fpm nginx mariadb-server php-mysql php-common php-gd php-zip php-mbstring php-xml php-yaml
do
apt-get install -y $PKG
apt-get install -f
done
chgrp www-data /home/judge
USER="hustoj"
PASSWORD=`tr -cd '[:alnum:]' < /dev/urandom | fold -w30 | head -n1`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
mkdir etc data log backup
cp src/install/java0.policy /home/judge/etc
cp src/install/judge.conf /home/judge/etc
chmod +x src/install/ans2out
# create enough runX dirs for each CPU core
if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
for N in `seq 0 $(($CPU-1))`
do
mkdir run$N
chown judge run$N
done
fi
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf
chmod 700 backup
chmod 700 etc/judge.conf
sed -i "s/DB_USER[[:space:]]*=[[:space:]]*\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS[[:space:]]*=[[:space:]]*\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown www-data src/web/upload data
if grep "client_max_body_size" /etc/nginx/nginx.conf ; then
echo "client_max_body_size already added" ;
else
sed -i "s:include /etc/nginx/mime.types;:client_max_body_size 80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi
service mariadb start
mysql < src/install/db.sql
echo "grant all privileges on jol.* to '$USER' identified by '$PASSWORD';\n flush privileges;\n"|mysql
echo "insert into jol.privilege values('admin','administrator','true','N');"|mysql
PHP_VER=`grep 'php.*fpm\.sock' /etc/nginx/sites-enabled/default |awk -F/ '{print $4}'|awk -F- '{print $1}'|cut -c4-6`
if grep "added by hustoj" /etc/nginx/sites-enabled/default ; then
echo "hustoj nginx config added!"
else
echo "modify the default site"
sed -i "s#root /var/www/html;#root /home/judge/src/web;#g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s:php7.0:php$PHP_VER:g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/$PHP_VER/fpm/php.ini
fi
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf
sed -i 's/pm.max_children = 5/pm.max_children = 200/g' `find /etc/php -name www.conf`
/etc/init.d/php$PHP_VER-fpm restart
service php$PHP_VER-fpm restart
cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
echo "auto start judged added!"
else
sed -i "s/exit 0//g" /etc/rc.local
echo "/usr/bin/judged" >> /etc/rc.local
echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
echo "auto backup added!"
else
crontab -l > conf && echo "1 0 * * * /home/judge/src/install/bak.sh" >> conf && crontab conf && rm -f conf
fi
ln -s /usr/bin/mcs /usr/bin/gmcs
/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults
systemctl enable nginx
systemctl enable mariadb
systemctl enable php$PHP_VER-fpm
systemctl enable judged
cd /home/judge/src/install
if test -f /.dockerenv ;then
echo "Already in docker, skip docker installation, install some compilers ... "
apt-get intall -f flex fp-compiler openjdk-14-jdk mono-devel
else
./docker.sh
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_PYTHON_FREE=0/OJ_PYTHON_FREE=1/g" /home/judge/etc/judge.conf
fi
cls
reset
echo "Remember your database account for HUST Online Judge:"
echo "username:$USER"
echo "password:$PASSWORD"
echo "DO NOT POST THESE INFORMATION ON ANY PUBLIC CHANNEL!"
echo "Register a user as 'admin' on http://127.0.0.1/ "
echo "打开http://127.0.0.1/ 注册用户admin获得管理员权限。"
echo "不要在QQ群或其他地方公开发送以上信息否则可能导致系统安全受到威胁。"
echo "█████████████████████████████████████████"
echo "████ ▄▄▄▄▄ ██▄▄ ▀ █▀█▄▄██ ███ ▄▄▄▄▄ ████"
echo "████ █ █ █▀▄ █▀██ ██▄▄ █▄█ █ █ ████"
echo "████ █▄▄▄█ █▄▀ █▄█▀█ ▄▄█▀▀▄██ █▄▄▄█ ████"
echo "████▄▄▄▄▄▄▄█▄▀▄█ █ █▄█▄▀ █ ▀▄█▄▄▄▄▄▄▄████"
echo "████ ▄▀▀█▄▄ █▄ █▄▄▄█▄█▀███▄ ██▀ ▄▀▀█████"
echo "████▀█▀▀▀▀▄▀▀▄▀ ▄▄█▄ █▀▀ ▄▀▀▄ █▄▄▀▄█████"
echo "████▄█ ▀▄▀▄▄ ▄ █▀█▀█ ▄▀▄ █▀▀▄█ ███ ████"
echo "████▄ █▄ █▄▀▀▄██▀▄ ▄ ▄▄█▄█▀█▀ ▄█▀▄▀████"
echo "████▄▄█ ▄▄██ █▄▄▀ ▄▀█▀▀▀ ▄█▀▄▄▀█ ▀████"
echo "█████▄ ▀▄▄█ ▄▀▄▄▀▄▄▄▀▄▀█▀ ▀▀█▄█▀█▄████"
echo "████ ▀ █▄▀▄▄█▀▀▄▀▀▄▄▄ ▀▀█▀ ▀▄▄█▀ ▀█ █████"
echo "████ █▀ ▄ ▄ ▀█▀▄█ █▄▄███▀██▀▀██ ▀▄█████"
echo "████▄▄▄██▄▄█ ▀█▄▄▄▀█ █▀▀█▀ █ ▄▄▄ █▀▄▀████"
echo "████ ▄▄▄▄▄ █ ▄ ▄▄▀ ▄ ▀▄▄▄▄ █▄█ ▄█████"
echo "████ █ █ ██ ▄▄▀▀█ ▀▀▀▀▀ ▄▀ ▄ ▀███████"
echo "████ █▄▄▄█ █▀▄▄▄▀▀█ ▀▄ ▄▀██▄█ ██ █ █▄████"
echo "████▄▄▄▄▄▄▄█▄███▄█▄▄▄████▄▄▄▄▄▄█▄██▄█████"
echo "█████████████████████████████████████████"
echo " QQ扫码加官方群"

38
install/install.sh Executable file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
IN_SCREEN=no
if echo "$TERM"|grep "screen" ; then
IN_SCREEN=yes;
fi
if [ "$IN_SCREEN" == "no" ] ;then
echo "not in screen";
apt update
apt install screen -y
chmod +x $0
screen bash $0 $*
else
echo "in screen";
OSID=`lsb_release -is|tr 'UDC' 'udc'`
OSRS=`lsb_release -rs`
INSTALL="install-$OSID$OSRS.sh"
URL="http://dl.hustoj.com/$INSTALL"
wget -O "$INSTALL" "$URL"
chmod +x "$INSTALL"
ALIPING=`LANG=c ping -c 5 mirrors.aliyun.com|grep ttl|awk '{print $8}'|awk -F= '{print $2*1000}'|sort -n|head -1`
NEPING=`LANG=c ping -c 5 mirrors.163.com|grep ttl|awk '{print $8}'|awk -F= '{print $2*1000}'|sort -n|head -1`
echo "aliyun:$ALIPING"
echo "netease:$NEPING"
if [ "$ALIPING" -gt "$NEPING" ] ; then
echo "163 is faster"
sed -i 's/aliyun/163/g' "./$INSTALL"
else
echo "aliyun is faster"
fi
"./$INSTALL"
echo "不要重复运行这个脚本如果不能访问检查80端口是否打开ip地址是否正确。"
echo "公网地址可能是http://"`curl http://hustoj.com/ip.php`
sleep 60;
fi

5
install/java0.policy Executable file
View File

@@ -0,0 +1,5 @@
grant {
permission java.io.FilePermission "./-", "read,write";
permission java.io.FilePermission "/usr/lib/jvm", "read";
};

BIN
install/jol.tar.gz Executable file

Binary file not shown.

80
install/judge.conf Executable file
View File

@@ -0,0 +1,80 @@
#Database Config
OJ_HOST_NAME=127.0.0.1
OJ_USER_NAME=root
OJ_PASSWORD=root
OJ_DB_NAME=jol
OJ_PORT_NUMBER=3306
#CPU cores Config
OJ_RUNNING=1
#Query Interval/UDP timeout
OJ_SLEEP_TIME=1
#Multi-Judger Task Divider
OJ_TOTAL=1
OJ_MOD=0
#Java and Other VM language bonus
OJ_JAVA_TIME_BONUS=2
OJ_JAVA_MEMORY_BONUS=64
#JVM Compiler Settings
OJ_JAVA_XMS=-Xms64M
OJ_JAVA_XMX=-Xmx128M
#Ignore the ending space of each line, change to 0 for more strict " Presentation Error "
OJ_IGNORE_ESOL=1
#Similarity Tester from Dick Grune
OJ_SIM_ENABLE=0
#show the right answer in reinfo for "choice type" spj problem
OJ_RAW_TEXT_DIFF=1
#Using HTTP for distributed judgers
OJ_HTTP_JUDGE=0
# HUSTOJ
OJ_HTTP_BASEURL=http://127.0.0.1/
OJ_HTTP_APIPATH=/admin/problem_judge.php
OJ_HTTP_LOGINPATH=/login.php
OJ_HTTP_USERNAME=admin
OJ_HTTP_PASSWORD=admin
# define the method using for testdata download 0:nothing 1:wget 2:rsync.sh
# the rsync.sh script should be put in judgehome (default: /home/judge/rsync.sh)
OJ_HTTP_DOWNLOAD=1
#Using Redis for solutions queue
OJ_REDISENABLE=0
OJ_REDISSERVER=127.0.0.1
OJ_REDISPORT=6379
OJ_REDISAUTH=123456
OJ_REDISQNAME=hustoj
#Judge all test data even solution fails
OJ_OI_MODE=1
#Using /dev/shm as working directory
OJ_SHM_RUN=0
#Using the longest case of test as final time
OJ_USE_MAX_TIME=0
#Judge TLE by total time
OJ_TIME_LIMIT_TO_TOTAL=1
#Judge only listed languages,encoded in const.inc.php array
OJ_LANG_SET=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
#Using Chroot to prevent compile time attack (#include</dev/random>)
OJ_COMPILE_CHROOT=1
#Jump some middle status update for faster judge
OJ_TURBO_MODE=0
#Bigger setting Slow down time on fast CPU, smaller setting Speed up time on slow CPU
OJ_CPU_COMPENSATION=1.0
#Using UDP for submission notification, to receive remote UDP task message set OJ_UDP_SERVER=0.0.0.0 or your IP on lan.
OJ_UDP_ENABLE=1
OJ_UDP_SERVER=127.0.0.1
OJ_UDP_PORT=1536
#Let Python Free
OJ_PYTHON_FREE=0
#allow NOIP using data.in as input file
OJ_COPY_DATA=0
#use docker to contain judge_client, run "sudo bash docker.sh" in /home/judge/src/install
OJ_USE_DOCKER=0
#replace docker with podman by setting OJ_DOCKER_PATH=/usr/bin/podman
OJ_DOCKER_PATH=/usr/bin/docker
#use docker interal judge_client to judge
OJ_INTERNAL_CLIENT=1
#using this server only for judge without any other task
OJ_DEDICATED=0
#use next two lines to overide C/C++ standard
#OJ_CC_STD=-std=c99
#OJ_CPP_STD=-std=c++17
#OJ_CC_OPT=-O2

BIN
install/judge_client Executable file

Binary file not shown.

168
install/judged Executable file
View File

@@ -0,0 +1,168 @@
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Author: Foo Bar <foobar@baz.org>
#
# Please remove the "Author" lines above and replace them
# with your own name if you copy and modify this script.
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
export LANG="zh_CN.UTF-8"
export LANGUAGE="zh_CN:zh"
export PATH="/home/judge/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DESC="Judge Service of HUST Online Judge"
NAME=judged
DAEMON=/usr/bin/$NAME
DAEMON_ARGS=""
PIDFILE=/home/judge/etc/judge.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Load the VERBOSE setting and other rcS variables
if test -e /lib/init/vars.sh
then
. /lib/init/vars.sh
fi
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
if test -e /lib/lsb/init-functions
then
. /lib/lsb/init-functions
fi
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
kill -9 `cat $PIDFILE`
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=10 --pidfile $PIDFILE
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac
:

20
install/makeout.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
ulimit -t 10
if [ "$1" = "" ]; then
echo "Usage: $0 standard-execute-binary"
echo "Example: after compiled your standard program by 'gcc -o main main.cc' "
echo " TYPE ---> '$0 main' "
echo " will generate .out files for each .in files in "`pwd`
exit 1
fi
EXEC=./$1
for INFILE in `ls *.in`
do
OUTFILE=`basename -s .in $INFILE`.out
if $EXEC < $INFILE > $OUTFILE ; then
echo "make out for $INFILE -> $OUTFILE <br>"
else
echo "make out for $INFILE .....failed"
fi
done

40
install/merge.sh Executable file
View File

@@ -0,0 +1,40 @@
#/bin/bash
OLD=$1
NEW=$2
if test ! -f "$OLD" ; then
echo "$OLD does not exist."
echo "Usage: $0 OLD_PATH/db_info.inc.php NEW_PATH/db_info.inc.php "
exit
fi
if test -z $2 ; then
echo "Usage: $0 OLD_PATH/db_info.inc.php NEW_PATH/db_info.inc.php "
exit
fi
if test ! -f "$NEW" ; then
echo "$NEW does not exist."
echo "Usage: $0 OLD_PATH/db_info.inc.php NEW_PATH/db_info.inc.php "
exit
fi
VARLIST=`grep static $OLD | awk -F\; '{print $1}' |grep =`
rm merge.sed
for VAR in $VARLIST
do
if [[ $VAR =~ "\$" ]] ; then
IFS='=' read -r KEY VALUE<<< $VAR
if [[ $KEY =~ "AI" ]] ; then continue; fi
if [[ $KEY =~ "FANCY" ]] ; then continue; fi
if [[ $KEY =~ "BLOCKLY" ]] ; then continue; fi
if [[ $KEY =~ "LOG" ]] ; then continue; fi
VALUE=$( echo "$VALUE" | sed 's|"|\\"|g' )
# echo $VALUE
echo -e 's|\'$KEY'=.*;|\'$KEY'='$VALUE';|' >> merge.sed
fi
done
sed -i -f merge.sed $NEW
rm merge.sed

69
install/moodle.sql Executable file
View File

@@ -0,0 +1,69 @@
DELIMITER $$
DROP trigger IF EXISTS `jol`.`tri_moodle` $$
create trigger tri_moodle
after update on solution
for each row
begin
declare mark int;
declare total int;
select count(1) into total from contest_problem where contest_id=new.contest_id;
if total>0 then
select sum(ac)/total*100 into mark
from (select max(pass_rate) ac from solution where user_id=new.user_id and contest_id=new.contest_id and problem_id>0 group by problem_id) s;
call update_moodle(new.contest_id,new.user_id,mark);
end if;
end $$
CREATE PROCEDURE `update_moodle`(IN `cid` INT, IN `user_id` VARCHAR(20), IN `mark` INT)
top:BEGIN
declare as_id int;
declare u_id int;
declare nowtime int;
declare oldid int;
set nowtime=UNIX_TIMESTAMP(now());
set as_id=0;
select m.id into as_id from
moodle.mdl_assign m
where m.name = concat('[OJ]-C',cid);
if as_id=0 then
leave top;
end if;
set u_id =-1;
select m.id into u_id from moodle.mdl_user m where username=user_id;
select mag.grade into oldid from moodle.mdl_assign_grades mag
where assignment=as_id and userid=u_id;
set oldid=-1;
select id into oldid from moodle.mdl_assign_submission m
where assignment=as_id and userid=u_id;
if oldid =-1 then
insert into moodle.mdl_assign_submission
(assignment,userid,timecreated,timemodified,status,attemptnumber)
values( as_id ,u_id ,nowtime ,nowtime ,'new' ,0);
insert into moodle.mdl_assign_grades(assignment,userid,timecreated,timemodified,grader,grade,attemptnumber)
select ma.id,mas.userid,UNIX_TIMESTAMP( NOW( ) ),UNIX_TIMESTAMP( NOW( ) ),2,mark,mas.attemptnumber
from moodle.mdl_assign ma
inner join moodle.mdl_assign_submission mas on
mas.assignment=ma.id and mas.status='new'
where concat(ma.id,',',mas.userid) not in (select concat(assignment,',',userid) from moodle.mdl_assign_grades);
else
update moodle.mdl_assign_grades
set grade=mark,timemodified=nowtime where
assignment=as_id and userid=u_id;
end if;
END$$
DELIMITER ;

15
install/multiOJ.sh Executable file
View File

@@ -0,0 +1,15 @@
function judge_round(){
for config in `sudo find -O2 "$1" -maxdepth 4 -name judge.conf`
do
etc=`dirname "$config"`
home=`dirname "$etc"`
sudo judged "$home" debug 1
sleep 1
done
}
while [ 1 ]
do
judge_round $1
sleep 2
done

11
install/my-ifconfig.te Executable file
View File

@@ -0,0 +1,11 @@
module my-ifconfig 1.0;
require {
type ifconfig_t;
type user_home_t;
class file { read write };
}
#============= ifconfig_t ==============
allow ifconfig_t user_home_t:file { read write };

29
install/my-phpfpm.te Executable file
View File

@@ -0,0 +1,29 @@
module my-phpfpm 1.0;
require {
type httpd_t;
type user_home_t;
type smtp_port_t;
class process execmem;
class tcp_socket name_connect;
class dir { add_name create read remove_name rename write };
class file { create open read rename setattr unlink write };
}
#============= httpd_t ==============
#!!!! This avc can be allowed using the boolean 'httpd_execmem'
allow httpd_t self:process execmem;
#!!!! This avc can be allowed using one of the these booleans:
# httpd_can_network_connect, httpd_can_sendmail, nis_enabled
allow httpd_t smtp_port_t:tcp_socket name_connect;
allow httpd_t user_home_t:dir rename;
#!!!! This avc is allowed in the current policy
allow httpd_t user_home_t:dir { add_name create read remove_name write };
allow httpd_t user_home_t:file { rename setattr };
#!!!! This avc is allowed in the current policy
allow httpd_t user_home_t:file { create open read unlink write };

12
install/mysql.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
config="/home/judge/etc/judge.conf"
VIRTUAL="/var/www/virtual/"
SERVER=`cat $config|grep 'OJ_HOST_NAME' |awk -F= '{print $2}'`
USER=`cat $config|grep 'OJ_USER_NAME' |awk -F= '{print $2}'`
PASSWORD=`cat $config|grep 'OJ_PASSWORD' |awk -F= '{print $2}'`
DATABASE=`cat $config|grep 'OJ_DB_NAME' |awk -F= '{print $2}'`
PORT=`cat $config|grep 'OJ_PORT_NUMBER' |awk -F= '{print $2}'`
echo "mysql -u${USER} -p{PASSWORD_HIDDEN} ${DBNAME} "
mysql -h $SERVER -P $PORT -u$USER -p$PASSWORD $DATABASE

102
install/nginx.conf Executable file
View File

@@ -0,0 +1,102 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 80m;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
index index.php;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
root /home/judge/src/web;
location / {
}
location ~ \.php$ {
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
# # With php5-fpm:
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2 default_server;
# listen [::]:443 ssl http2 default_server;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# location / {
# }
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}

8
install/oomsaver.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
pgrep -f "/usr/sbin/sshd" | while read PID;do echo -17 > /proc/$PID/oom_score_adj;done
pgrep -f "php-fpm" | while read PID;do echo -17 > /proc/$PID/oom_score_adj;done
pgrep -f "mysql" | while read PID;do echo -17 > /proc/$PID/oom_score_adj;done
if test -e /swap ;then swapon /swap ;fi
echo 100 > /proc/sys/vm/swappiness
echo "set global connection_memory_limit=20971520;" | mysql

20
install/podman.sh Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
cd /home/judge/src/install || exit 1
while ! apt-get install -y podman containerd
do
echo "Network fail, retry... you might want to make sure podman is available in your apt source"
done
IP=`curl http://hustoj.com/ip.php`
while ! podman build -t hustoj .
do
echo "Visit http://$IP to regist your admin account of HUSTOJ instance."
echo "Left this console working on retry ... podman activation."
echo "Network fail, retry... you might want to make sure podman image source is available"
done
sed -i "s/OJ_USE_DOCKER=0/OJ_USE_DOCKER=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_PYTHON_FREE=0/OJ_PYTHON_FREE=1/g" /home/judge/etc/judge.conf
sed -i "s/OJ_INTERNAL_CLIENT=1/OJ_INTERNAL_CLIENT=0/g" /home/judge/etc/judge.conf
sed -i "s|OJ_DOCKER_PATH=/usr/bin/docker|OJ_DOCKER_PATH=/usr/bin/podman|g" /home/judge/etc/judge.conf
pkill -9 judged
/usr/bin/judged

97
install/restore+.sh Executable file
View File

@@ -0,0 +1,97 @@
#!/usr/bin/bash
if lsb_release -a|grep Ubuntu ; then
echo "This script is designed for CentOS"
echo "Ubuntu use restore.sh instead, please."
exit 1
fi
# Get backup archive file
if [ ${#} -gt 0 ];then
archive=${1};
else
archive=`ls -r /home/judge/backup | head -1`;
fi
echo "restore archive ${archive}"
# Get database password
OJ_USERNAME=`cat /home/judge/etc/judge.conf | grep OJ_USER_NAME`
OJ_PASSWORD=`cat /home/judge/etc/judge.conf | grep OJ_PASSWORD`
DB_USERNAME=`echo ${OJ_USERNAME:13}`
DB_PASSWORD=`echo ${OJ_PASSWORD:12}`
# create temp directory
mkdir /home/judge/backup/temp
# save database config if interrupted
touch /home/judge/backup/temp/db.conf
echo DB_USERNAME=${DB_USERNAME} >> /home/judge/backup/temp/db.conf
echo DB_PASSWORD=${DB_PASSWORD} >> /home/judge/backup/temp/db.conf
# clear old files
rm -rf /home/judge/data
rm -rf /home/judge/etc
rm -rf /home/judge/src/web
# start restore
tar -xf /home/judge/backup/${archive} -C /home/judge/backup/temp
# restore database
echo "restore database"
mysql -u${DB_USERNAME} -p${DB_PASSWORD} < /home/judge/backup/temp/jol.sql
# restore data directory
echo "restore data directory"
cp -r /home/judge/backup/temp/data /home/judge/data
# restore config files
echo "restore config files"
cp -r /home/judge/backup/temp/etc /home/judge/etc
# restore web files
cp -r /home/judge/backup/temp/src/web /home/judge/src/web
# adjustment judge config file
echo "adjustment judge config file"
CPU=`cat /proc/cpuinfo| grep "processor"| wc -l`
cdbusername=`cat /home/judge/etc/judge.conf | grep OJ_USER_NAME`
cdbpassword=`cat /home/judge/etc/judge.conf | grep OJ_PASSWORD`
ccpu=`cat /home/judge/etc/judge.conf | grep OJ_RUNNING`
sed -i "s/${cdbusername}/OJ_USER_NAME=${DB_USERNAME}/g" /home/judge/etc/judge.conf
sed -i "s/${cdbpassword}/OJ_PASSWORD=${DB_PASSWORD}/g" /home/judge/etc/judge.conf
sed -i "s/${ccpu}/OJ_RUNNING=${CPU}/g" /home/judge/etc/judge.conf
# adjustment web config file
echo "adjustment web config file"
cdbuser=`cat /home/judge/src/web/include/db_info.inc.php | grep static |grep DB_USER`
cdbpass=`cat /home/judge/src/web/include/db_info.inc.php | grep static |grep DB_PASS`
sed -i "s|${cdbuser}|static\ \ \$DB_USER=\"${DB_USERNAME}\";|g" /home/judge/src/web/include/db_info.inc.php
sed -i "s|${cdbpass}|static\ \ \$DB_PASS=\"${DB_PASSWORD}\";|g" /home/judge/src/web/include/db_info.inc.php
chmod 775 -R /home/judge/data
chmod 700 /home/judge/etc/judge.conf
chmod 700 /home/judge/src/web/include/db_info.inc.php
centos7=`cat /etc/os-release | grep PRETTY_NAME | grep CentOS | grep 7 `
ubuntu14=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 14`
ubuntu16=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 16`
ubuntu18=`cat /etc/os-release | grep PRETTY_NAME | grep Ubuntu | grep 18`
if [ -n "${centos7}" ];then
own=apache;
elif [ -n "${ubuntu14}" ];then
own=judge;
elif [ -n "${ubuntu16}" ];then
own=www-data;
elif [ -n "${ubuntu18}" ];then
own=www-data;
fi
chown -R ${own}:${own} /home/judge/data
chown ${own} /home/judge/src/web/include/db_info.inc.php
chown ${own} /home/judge/src/web/upload
# clear temp directory
rm -rf /home/judge/backup/temp

38
install/restore.sh Executable file
View File

@@ -0,0 +1,38 @@
#/bin/bash
TARBZNAME=`find -name "hustoj_*.tar.bz2"`
if [ $# != 1 ] ; then
echo "USAGE: sudo $0 $TARBZNAME"
echo " e.g.: sudo $0 hustoj_xxxxxxx.tar.bz2"
echo " tar.bz2 should be created by bak.sh, default location : /var/backups/ "
exit 1;
fi
DATE=`date +%Y%m%d%H%M%S`
BAKDATE=`echo $1 |awk -F\. '{print $1}'|awk -F_ '{print $2}'`
config="/home/judge/etc/judge.conf"
SERVER=`cat $config|grep 'OJ_HOST_NAME' |awk -F= '{print $2}'`
USER=`cat $config|grep 'OJ_USER_NAME' |awk -F= '{print $2}'`
PASSWORD=`cat $config|grep 'OJ_PASSWORD' |awk -F= '{print $2}'`
DATABASE=`cat $config|grep 'OJ_DB_NAME' |awk -F= '{print $2}'`
mkdir hustoj-restore
cd hustoj-restore
MAIN="../$1"
/home/judge/src/install/bak.sh
tar xjf $MAIN
mv /home/judge/data /home/judge/data.del.$DATE
mv home/judge/data /home/judge/
chown www-data -R /home/judge/data
mv /home/judge/src/web/upload /home/judge/src/web/upload.del.$DATE
mv home/judge/src/web/upload /home/judge/src/web/
chown www-data -R /home/judge/src/web/
bzip2 -d var/backups/db_${BAKDATE}.sql.bz2
sed -i 's/COLLATE=utf8mb4_0900_ai_ci//g' var/backups/db_${BAKDATE}.sql
sed -i 's/COLLATE utf8mb4_0900_ai_ci//g' var/backups/db_${BAKDATE}.sql
sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' var/backups/db_${BAKDATE}.sql
if ! mysql -h $SERVER -u$USER -p$PASSWORD $DATABASE < var/backups/db_${BAKDATE}.sql ; then
mysql $DATABASE < var/backups/db_${BAKDATE}.sql
fi
if ! mysql -h $SERVER -u$USER -p$PASSWORD $DATABASE < /home/judge/src/install/update.sql ; then
mysql $DATABASE < /home/judge/src/install/update.sql
fi

14
install/rsync.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/bash
#judge_client gives PID as 1st parameter
#this file will be executed when OJ_HTTP_DOWNLOAD=2
if test -z $1 ;then
echo "Example: $0 <Problem_id>"
exit
fi
PID=$1
#source data should be on webserver
WEBSERVER=172.10.2.101
#ssh may using different port
PORT=22
#call rsync to get all data for this problem, id_rsa.pub should be installed to WEBSERVER's /home/judge/.ssh/authorized_keys
rsync -vzrtopg --progress --delete -e "ssh -p $PORT" judge@$WEBSERVER:/home/judge/data/$PID /home/judge/data/

16
install/selinux.sh Executable file
View File

@@ -0,0 +1,16 @@
# check module selinux policy modules
checkmodule /home/judge/src/install/my-phpfpm.te -M -m -o my-phpfpm.mod
checkmodule /home/judge/src/install/my-ifconfig.te -M -m -o my-ifconfig.mod
# package policy modules
semodule_package -m my-phpfpm.mod -o my-phpfpm.pp
semodule_package -m my-ifconfig.mod -o my-ifconfig.pp
# install policy modules
semodule -i my-phpfpm.pp
semodule -i my-ifconfig.pp
# clean up
echo "clean up selinux module output files"
rm -rf my-phpfpm.mod my-phpfpm.pp
rm -rf my-ifconfig.mod my-ifconfig.pp

63
install/sources.list.sh Executable file
View File

@@ -0,0 +1,63 @@
#!/usr/bin/bash
codename=`cat /etc/os-release | grep UBUNTU_CODENAME | awk -F '=' '{print $2}'`
mv /etc/apt/sources.list /etc/apt/sources.list.bak
cat >/etc/apt/sources.list <<EOF
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb https://mirrors.aliyun.com/ubuntu/ ${codename} main restricted
# deb-src https://mirrors.aliyun.com/ubuntu/ ${codename} main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb https://mirrors.aliyun.com/ubuntu/ ${codename}-updates main restricted
# deb-src https://mirrors.aliyun.com/ubuntu/ ${codename}-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb https://mirrors.aliyun.com/ubuntu/ ${codename} universe
# deb-src https://mirrors.aliyun.com/ubuntu/ ${codename} universe
deb https://mirrors.aliyun.com/ubuntu/ ${codename}-updates universe
# deb-src https://mirrors.aliyun.com/ubuntu/ ${codename}-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb https://mirrors.aliyun.com/ubuntu/ ${codename} multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ ${codename} multiverse
deb https://mirrors.aliyun.com/ubuntu/ ${codename}-updates multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ ${codename}-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb https://mirrors.aliyun.com/ubuntu/ ${codename}-backports main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ ${codename}-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu ${codename} partner
# deb-src http://archive.canonical.com/ubuntu ${codename} partner
deb https://mirrors.aliyun.com/ubuntu/ ${codename}-security main restricted
# deb-src https://mirrors.aliyun.com/ubuntu ${codename}-security main restricted
deb https://mirrors.aliyun.com/ubuntu/ ${codename}-security universe
# deb-src https://mirrors.aliyun.com/ubuntu ${codename}-security universe
deb https://mirrors.aliyun.com/ubuntu/ ${codename}-security multiverse
# deb-src https://mirrors.aliyun.com/ubuntu ${codename}-security multiverse
# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.
EOF

7
install/stop.sh Executable file
View File

@@ -0,0 +1,7 @@
pkill -9 judged
/etc/init.d/tomcat7 stop
/etc/init.d/php5-fpm stop
/etc/init.d/mysql stop
/etc/init.d/memcached stop
/etc/init.d/nginx stop
/etc/init.d/lightdm stop

18
install/uninstall.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/bash
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`
pkill -9 judged
service php7.2-fpm stop
service mysql stop
service nginx stop
service memcache stop
echo "drop database jol;"|mysql -h localhost -u$USER -p$PASSWORD
docker rmi hustoj
for PKG in docker.io make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm nginx mysql-server php-mysql php-common php-gd php-zip fp-compiler openjdk-11-jdk mono-devel php-mbstring php-xml
do
apt-get purge -y $PKG
done
userdel -r judge

30
install/update-by-download Executable file
View File

@@ -0,0 +1,30 @@
#!/bin/bash
DATE=`date +%Y%m%d`
if [ `whoami` = "root" ];then
cd /home/judge/
cp src/web/include/db_info.inc.php etc/
if wget -O hustoj.tar.gz http://dl.hustoj.com/hustoj.tar.gz; then
mv src old.$DATE
if tar xzf hustoj.tar.gz ;then
cp etc/db_info.inc.php src/web/include/
cp -a old.$DATE/src/upload/* src/web/upload
chown -R www-data src
cd /home/judge/src/core
pkill -9 judged
bash make.sh
cd ../install
mysql jol< update.sql
judged
else
mv old.$DATE src
echo "Extraction of source tgz failed!"
fi
web_user=`ls -l /home/judge/src/web/include/db_info.inc.php | awk -F ' ' '{print $3}'`
mkdir /var/log/hustoj/
chown -R $web_user /var/log/hustoj
fi
else
echo "Usage:sudo $0"
fi

23
install/update-hustoj Executable file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
cd /home/judge/git
git pull .
echo "SVN not available from github any more "
echo "using 'sudo bash fixing.sh' to get update from dl.hustoj.com "
exit 1
cd /home/judge/src/core
pkill -9 judged
bash make.sh
cd ../install
chmod +x g++.sh gcc.sh makeout.sh
mysql jol< update.sql
judged
web_user=`grep www /etc/passwd|awk -F: '{print $1}'`
mkdir /var/log/hustoj/
chown -R $web_user /var/log/hustoj
chmod 770 /home/judge/src/web/upload
chown $web_user -R /home/judge/src/web/upload

View File

@@ -0,0 +1,9 @@
#!/bin/bash
# Official
sed -i 's@//.*archive.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list
sed -i 's@//security.ubuntu.com@//mirrors.aliyun.com@g' /etc/apt/sources.list
# Tencent Cloud
sed -i 's@//mirrors.tencentyun.com@//mirrors.aliyun.com@g' /etc/apt/sources.list
apt update

31
install/update.old.sql Executable file
View File

@@ -0,0 +1,31 @@
CREATE TABLE `topic` ( `tid` int(11) NOT NULL auto_increment, `title` varbinary(60) NOT NULL, `status` int(2) NOT NULL default '0', `top_level` int(2) NOT NULL default '0', `cid` int(11) default NULL, `pid` int(11) NOT NULL, `author_id` varchar(20) NOT NULL, PRIMARY KEY (`tid`), KEY `cid` (`cid`,`pid`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
CREATE TABLE `reply` ( `rid` int(11) NOT NULL auto_increment, `author_id` varchar(20) NOT NULL, `time` datetime NOT NULL default '2000-01-01 00:00:01', `content` text NOT NULL, `topic_id` int(11) NOT NULL, `status` int(2) NOT NULL default '0', `ip` varchar(30) NOT NULL, PRIMARY KEY (`rid`), KEY `author_id` (`author_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
ALTER TABLE `problem` DROP COLUMN `sample_Program`, DROP COLUMN `ratio`, DROP COLUMN `error`, DROP COLUMN `difficulty`, DROP COLUMN `submit_user`, DROP COLUMN `case_time_limit`;
CREATE TABLE `sim` ( `s_id` int(11) NOT NULL, `sim_s_id` int(11) NULL, `sim` int(11) NULL, PRIMARY KEY (`s_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE `mail` ( `mail_id` int(11) NOT NULL auto_increment, `to_user` varchar(20) NOT NULL default '', `from_user` varchar(20) NOT NULL default '', `title` varchar(200) NOT NULL default '', `content` text, `new_mail` tinyint(1) NOT NULL default '1', `reply` tinyint(4) default '0', `in_date` datetime default NULL, `defunct` char(1) NOT NULL default 'N', PRIMARY KEY (`mail_id`), KEY `uid` (`to_user`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1000 ;
ALTER TABLE `solution` MODIFY COLUMN `pass_rate` DECIMAL(3,2) UNSIGNED NOT NULL DEFAULT 0,MODIFY COLUMN in_date datetime not null default '2009-06-13 19:00:00', MODIFY COLUMN `user_id` CHAR(48) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,MODIFY COLUMN `ip` CHAR(15) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;
ALTER TABLE `solution` DROP COLUMN `className`;
select langmask from contest limit 1;
ALTER TABLE `contest` ADD COLUMN `langmask` TINYINT NOT NULL DEFAULT 0 COMMENT 'bits for LANG to mask' AFTER `private`;
optimize table `compileinfo`,`contest` ,`contest_problem` ,`loginlog`,`news`,`privilege`,`problem` ,`solution`,`source_code`,`users`,`topic`,`reply`,`online`,`sim`,`mail`;
ALTER TABLE `contest` MODIFY COLUMN `langmask` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT 'bits for LANG to mask';
CREATE TABLE `runtimeinfo` ( `solution_id` int(11) NOT NULL DEFAULT '0', `error` text, PRIMARY KEY (`solution_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; ;
ALTER TABLE `solution` ADD COLUMN `pass_rate` DECIMAL(3,2) UNSIGNED NOT NULL DEFAULT 0 AFTER `judgetime`;
ALTER TABLE `users` MODIFY COLUMN `user_id` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id';
ALTER TABLE `topic` MODIFY COLUMN `author_id` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id';
ALTER TABLE `mail` MODIFY COLUMN `to_user` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id',MODIFY COLUMN `from_user` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id';
ALTER TABLE `reply` MODIFY COLUMN `author_id` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id';
ALTER TABLE `news` MODIFY COLUMN `user_id` varchar(48) NOT NULL DEFAULT '' COMMENT 'user_id';
ALTER TABLE `sim` ADD INDEX `Index_sim_id`(`sim_s_id`);
ALTER TABLE `contest_problem` ADD INDEX `Index_contest_id`(`contest_id`);
CREATE TABLE `custominput` ( `solution_id` int(11) NOT NULL DEFAULT '0', `input_text` text, PRIMARY KEY (`solution_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;
ALTER TABLE `loginlog` ADD INDEX `user_time_index`(`user_id`, `time`);
ALTER TABLE `contest` ADD `password` CHAR( 16 ) NOT NULL DEFAULT '' AFTER `langmask` ;
create TABLE `source_code_user` like source_code;
insert into source_code_user select * from source_code where solution_id not in (select solution_id from source_code_user) ;
ALTER TABLE `solution` ADD `judger` CHAR(16) NOT NULL DEFAULT 'LOCAL' ; ;
alter table solution modify column pass_rate decimal(3,2) NOT NULL DEFAULT 0;
ALTER TABLE `solution` CHANGE `ip` `ip` CHAR( 46 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';
CREATE TABLE `printer` ( `printer_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` char(48) NOT NULL, `in_date` datetime NOT NULL DEFAULT '2018-03-13 19:38:00', `status` smallint(6) NOT NULL DEFAULT '0', `worktime` timestamp NULL DEFAULT CURRENT_TIMESTAMP, `printer` CHAR(16) NOT NULL DEFAULT 'LOCAL', `content` text NOT NULL , PRIMARY KEY (`printer_id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
CREATE TABLE `balloon` ( `balloon_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` char(48) NOT NULL, `sid` int(11) NOT NULL , `cid` int(11) NOT NULL , `pid` int(11) NOT NULL , `status` smallint(6) NOT NULL DEFAULT '0', PRIMARY KEY (`balloon_id`) ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
create TABLE `share_code` ( `share_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` varchar(48) COLLATE utf8_unicode_ci DEFAULT NULL, `title` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, `share_code` text COLLATE utf8_unicode_ci, `language` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, `share_time` datetime DEFAULT NULL, PRIMARY KEY (`share_id`) ) ENGINE=MyISAM AUTO_INCREMENT=1000 DEFAULT CHARSET=utf8;

31
install/update.sql Normal file
View File

@@ -0,0 +1,31 @@
update contest set start_time='2000-01-01 00:00:00' where start_time<'1000-01-01 00:00:00';
update contest set end_time='2099-01-01 00:00:00' where end_time<'1000-01-01 00:00:00';
alter TABLE `contest` ADD `user_id` CHAR( 48 ) NOT NULL DEFAULT 'admin' AFTER `password` ;
update contest c inner JOIN (SELECT * FROM privilege WHERE rightstr LIKE 'm%') p ON concat('m',contest_id)=rightstr set c.user_id=p.user_id;
alter TABLE `contest_problem` ADD `c_accepted` INT NOT NULL DEFAULT '0' AFTER `num` ,ADD `c_submit` INT NOT NULL DEFAULT '0' AFTER `c_accepted` ;
update contest_problem cp inner join (select count(1) submit,contest_id cid,num from solution where contest_id>0 group by contest_id,num) sb on cp.contest_id=sb.cid and cp.num=sb.num set cp.c_submit=sb.submit;update contest_problem cp inner join (select count(1) ac,contest_id cid,num from solution where contest_id>0 and result=4 group by contest_id,num) sb on cp.contest_id=sb.cid and cp.num=sb.num set cp.c_accepted =sb.ac;
alter table solution add column nick char(20) not null default '' after user_id ;
update solution s inner join users u on s.user_id=u.user_id set s.nick=u.nick;
alter table privilege add index user_id_index(user_id);
ALTER TABLE `problem` CHANGE `time_limit` `time_limit` DECIMAL(10,3) NOT NULL DEFAULT '0';
alter table privilege add column valuestr char(11) not null default 'true' after rightstr;
alter table news modify column `time` datetime NOT NULL DEFAULT '2016-05-13 19:24:00';
ALTER TABLE `news` ADD COLUMN `menu` int(11) NOT NULL DEFAULT 0 AFTER `importance`;
alter table solution modify column pass_rate decimal(4,3) not null default 0.0;
alter table problem add column remote_oj varchar(16) default NULL after solved;
alter table problem add column remote_id varchar(32) default NULL after remote_oj;
alter table solution add column remote_oj char(16) not null default '' after judger;
alter table solution add column remote_id char(32) not null default '' after remote_oj;
alter table news modify content mediumtext not null;
alter table problem modify description mediumtext not null, modify input mediumtext not null, modify output mediumtext not null, modify hint mediumtext not null;
alter table users add column activecode varchar(16) not null default '' after school;
alter table users add column group_name varchar(16) not null default '' after school;
alter table loginlog add column log_id int not null auto_increment primary key first;
alter table problem add index key_p_def(defunct);
alter table contest add index key_c_def(defunct);
alter table contest add index key_c_end(end_time);
alter table contest add index key_c_dend(defunct,end_time);
alter table users add column starred int default 0 after activecode ;
#create fulltext index problem_title_source_index on problem(title,source);