当前位置: 代码迷 >> 综合 >> HUSTOJ-shell安装脚本解析学习
  详细解决方案

HUSTOJ-shell安装脚本解析学习

热度:70   发布时间:2023-12-23 07:40:30.0

https://github.com/zhblue/hustoj/blob/master/trunk/install/install-ubuntu14.04.sh

本篇解析纯属个人理解,学习所用,有不对的地方,欢迎提出建议!

 
 
#!/bin/bash
apt-get update
apt-get install -y subversion   //安装svn
/usr/sbin/useradd -m -u 1536 judge   //创建用户,-m(指定用户目录,默认在/home下) -u(指定用户ID)
cd /home/judge/   //切换到用户目录
svn co https://github.com/zhblue/hustoj/trunk/trunk/ src   //将作者的项目克下来,并存在src目录下echo 'mysql-server-5.5 mysql-server/root_password password ""' | sudo debconf-set-selections  //静默安装命令,这里就是在MySQL安装前指定它的密码
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}'`//awk 在没有-F指定以什么分隔的情况下,以空格分隔的数据的第$n个数
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk  '{print $3}'`//将数据库密码缓存
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`    //将服务器cpu数据缓存
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 //将配置文件copy到etc目录
cp src/install/judge.conf  /home/judge/etc
chmod +x src/install/ans2outif grep "OJ_SHM_RUN=0" etc/judge.conf ; then//查看配置文件,判断是否使用/dev/shm的共享内存虚拟磁盘来运行答案,如果启用则能提高判题速度,但需要较多内存mkdir run0 run1 run2 run3chown judge run0 run1 run2 run3
fi
//直接编辑文件选项-i,-s 替换文本中的字符串  -g全面替换标记,下面四行就是将上面缓存的数据写进判题机的配置文件
sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf//会匹配etc/judge.conf文件中每一行的第一个OJ_USER_NAME=root替换为OJ_USER_NAME=$USER
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.confsed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.phpchown www-data src/web/upload data//创建用户组www-adta
if grep client_max_body_size /etc/nginx/nginx.conf ; then echo "client_max_body_size already added" ;
elsesed -i "s:include /etc/nginx/mime.types;:client_max_body_size    80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf//sed 的界定符 / 并不是固定,你可以使用任意界定符号,例如 :,|,*,因为匹配的字符串里有/为了避免转义,这里作者在上面一行没有用/而换成了:
fimysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql//导入数据库
echo "insert into jol.privilege values('admin','administrator','N');"|mysql -h localhost -u$USER -p$PASSWORD //插入管理员
//下面8行是配置nginx的脚本命令,后面几行是配置nginx与php相关联的内容
sed -i "s:root /usr/share/nginx/html;:root /home/judge/src/web;:g" /etc/nginx/sites-enabled/default//修改nginx的配置文件将web服务目录更换到/home/judge/src/web下
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default    //加入 index.php
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     //重启nginx
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php5/fpm/php.ini//配置php.ini,修改post请求数据大小限制
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php5/fpm/php.ini   //修改上传文件的限制
/etc/init.d/php5-fpm restart  //重启php
service php5-fpm restart     //一遍不过瘾,再重启一遍
cd src/core 
chmod +x ./make.sh
./make.sh//执行脚本,编译judge判题机
if grep "/usr/bin/judged" /etc/rc.local ; then  //rc.local是系统启动加载文件,自定义开机自启,如果文件有/usr/bin/judged,则输出添加成功echo "auto start judged added!"
elsesed -i "s/exit 0//g" /etc/rc.localecho "/usr/bin/judged" >> /etc/rc.local// >>输出重定向echo "exit 0" >> /etc/rc.localfi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then    //判断自动备份是否已经添加echo "auto backup added!"
elseecho "1 0 * * * /home/judge/src/install/bak.sh" >> /var/spool/cron/crontabs/root
fi
/usr/bin/judged    //运行判题机? 2018 GitHub, Inc.

 

 

 

  相关解决方案