2019-07-16 06:13:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
getAptPackage(){
|
|
|
|
printf "\n\n==> Getting environment packages\n"
|
|
|
|
export DEBIAN_FRONTEND=noninteractive
|
2022-03-19 13:18:21 +00:00
|
|
|
apt-get update && apt-get install -y vim ntp zip unzip curl wget build-essential fp-compiler python2.7 python3.8 python3-requests
|
2019-07-16 06:13:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setJudgeConf(){
|
|
|
|
printf "\n\n==> Setting judger files\n"
|
2022-03-16 12:10:44 +00:00
|
|
|
#specify environment
|
|
|
|
cat > /etc/environment <<UOJEOF
|
|
|
|
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
|
|
|
UOJEOF
|
2019-07-16 06:13:28 +00:00
|
|
|
#Add judger user
|
|
|
|
adduser judger --gecos "" --disabled-password
|
|
|
|
#Set uoj_data path
|
|
|
|
mkdir /var/uoj_data_copy && chown judger /var/uoj_data_copy
|
|
|
|
#Compile uoj_judger and set runtime
|
2022-03-16 09:00:39 +00:00
|
|
|
chown -R judger:judger /opt/uoj_judger
|
2019-07-16 06:13:28 +00:00
|
|
|
su judger <<EOD
|
2022-03-16 09:00:39 +00:00
|
|
|
ln -s /var/uoj_data_copy /opt/uoj_judger/uoj_judger/data
|
|
|
|
cd /opt/uoj_judger && chmod +x judge_client
|
2019-07-16 06:13:28 +00:00
|
|
|
cat >uoj_judger/include/uoj_work_path.h <<UOJEOF
|
2022-03-16 09:00:39 +00:00
|
|
|
#define UOJ_WORK_PATH "/opt/uoj_judger/uoj_judger"
|
2019-07-16 06:13:28 +00:00
|
|
|
#define UOJ_JUDGER_BASESYSTEM_UBUNTU1804
|
2022-03-16 12:43:41 +00:00
|
|
|
#define UOJ_JUDGER_PYTHON3_VERSION "3.8"
|
2019-07-16 06:13:28 +00:00
|
|
|
#define UOJ_JUDGER_FPC_VERSION "3.0.4"
|
|
|
|
UOJEOF
|
|
|
|
cd uoj_judger && make -j$(($(nproc) + 1))
|
|
|
|
EOD
|
|
|
|
}
|
|
|
|
|
|
|
|
initProgress(){
|
|
|
|
printf "\n\n==> Doing initial config and start service\n"
|
2022-03-16 09:00:39 +00:00
|
|
|
# Check envs
|
2019-07-16 06:13:28 +00:00
|
|
|
if [ -z "$UOJ_PROTOCOL" -o -z "$UOJ_HOST" -o -z "$JUDGER_NAME" -o -z "$JUDGER_PASSWORD" -o -z "$SOCKET_PORT" -o -z "$SOCKET_PASSWORD" ]; then
|
|
|
|
echo "!! Environment variables not set! Please edit config file by yourself!"
|
|
|
|
else
|
2022-03-16 09:00:39 +00:00
|
|
|
# Set judge_client config file
|
|
|
|
cat >.conf.json <<UOJEOF
|
2019-07-16 06:13:28 +00:00
|
|
|
{
|
|
|
|
"uoj_protocol": "$UOJ_PROTOCOL",
|
|
|
|
"uoj_host": "$UOJ_HOST",
|
|
|
|
"judger_name": "$JUDGER_NAME",
|
|
|
|
"judger_password": "$JUDGER_PASSWORD",
|
|
|
|
"socket_port": $SOCKET_PORT,
|
|
|
|
"socket_password": "$SOCKET_PASSWORD"
|
|
|
|
}
|
|
|
|
UOJEOF
|
2022-03-16 09:00:39 +00:00
|
|
|
chmod 600 .conf.json && chown judger .conf.json
|
|
|
|
chown -R judger:judger ./log
|
2019-07-16 06:13:28 +00:00
|
|
|
#Start services
|
|
|
|
service ntp restart
|
2022-03-16 09:00:39 +00:00
|
|
|
su judger -c '/opt/uoj_judger/judge_client start'
|
2019-07-16 06:13:28 +00:00
|
|
|
echo "please modify the database after getting the judger server ready:"
|
|
|
|
echo "insert into judger_info (judger_name, password, ip) values ('$JUDGER_NAME', '$JUDGER_PASSWORD', '__judger_ip_here__');"
|
|
|
|
printf "\n\n***Installation complete. Enjoy!***\n"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
prepProgress(){
|
|
|
|
getAptPackage;setJudgeConf
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ $# -le 0 ]; then
|
|
|
|
echo 'Installing UOJ System judger...'
|
|
|
|
prepProgress;initProgress
|
|
|
|
fi
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case "$1" in
|
|
|
|
-p | --prep)
|
|
|
|
echo 'Preparing UOJ System judger environment...'
|
|
|
|
prepProgress
|
|
|
|
;;
|
|
|
|
-i | --init)
|
|
|
|
echo 'Initing UOJ System judger...'
|
|
|
|
initProgress
|
|
|
|
;;
|
|
|
|
-? | --*)
|
|
|
|
echo "Illegal option $1"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift $(( $#>0?1:0 ))
|
|
|
|
done
|