install.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/bin/bash
  2. genRandStr(){
  3. cat /dev/urandom | tr -dc [:alnum:] | head -c $1
  4. }
  5. #Set some vars
  6. _judger_socket_port_="${JUDGER_SOCKET_PORT:-2333}"
  7. _uoj_protocol_="${UOJ_PROTOCOL:-http}"
  8. getAptPackage(){
  9. printf "\n\n==> Getting environment packages\n"
  10. # Update apt sources and install
  11. export DEBIAN_FRONTEND=noninteractive
  12. dpkg -s gnupg 2>/dev/null || (apt-get update && apt-get install -y gnupg)
  13. echo "deb http://ppa.launchpad.net/stesie/libv8/ubuntu bionic main" | tee /etc/apt/sources.list.d/stesie-libv8.list && apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D858A0DF
  14. apt-get update && apt-get install -y git vim ntp zip unzip curl wget apache2 libapache2-mod-xsendfile libapache2-mod-php php php-dev php-pear php-zip php-mysql php-mbstring php-gd php-intl php-xsl g++ make re2c libv8-7.5-dev libyaml-dev
  15. # Install PHP extensions
  16. yes | pecl install yaml
  17. git clone https://github.com/phpv8/v8js.git --depth=1 -b 4c026f3fb291797c109adcabda6aeba6491fe44f /tmp/pear/download/v8js-master && cd /tmp/pear/download/v8js-master
  18. phpize && ./configure --with-php-config=/usr/bin/php-config --with-v8js=/opt/libv8-7.5 && make install && cd -
  19. }
  20. setLAMPConf(){
  21. printf "\n\n==> Setting LAMP configs\n"
  22. #Set Apache UOJ site conf
  23. cat >/etc/apache2/sites-available/000-uoj.conf <<UOJEOF
  24. <VirtualHost *:80>
  25. #ServerName local_uoj.ac
  26. ServerAdmin opensource@uoj.ac
  27. DocumentRoot /var/www/uoj
  28. SetEnvIf Request_URI "^/judge/.*$" judgelog
  29. #LogLevel info ssl:warn
  30. ErrorLog \${APACHE_LOG_DIR}/uoj_error.log
  31. CustomLog \${APACHE_LOG_DIR}/uoj_judge.log common env=judgelog
  32. CustomLog \${APACHE_LOG_DIR}/uoj_access.log combined env=!judgelog
  33. XSendFile On
  34. XSendFilePath /var/uoj_data
  35. XSendFilePath /var/www/uoj/app/storage
  36. XSendFilePath /opt/uoj/judger/uoj_judger/include
  37. </VirtualHost>
  38. UOJEOF
  39. #Enable modules and make UOJ site conf enabled
  40. a2ensite 000-uoj.conf && a2dissite 000-default.conf
  41. a2enmod rewrite headers && sed -i -e '172s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
  42. #Create UOJ session save dir and make PHP extensions available
  43. mkdir --mode=733 /var/lib/php/uoj_sessions && chmod +t /var/lib/php/uoj_sessions
  44. sed -i -e '912a\extension=v8js.so\nextension=yaml.so' /etc/php/7.4/apache2/php.ini
  45. sed -i 's|;sys_temp_dir = "/tmp"|sys_temp_dir = "/tmp"|g' /etc/php/7.4/apache2/php.ini
  46. }
  47. setWebConf(){
  48. printf "\n\n==> Setting web files\n"
  49. # Set webroot path
  50. ln -sf /opt/uoj/web /var/www/uoj
  51. chown -R www-data /var/www/uoj/app/storage
  52. # Set web config file
  53. php -a <<UOJEOF
  54. \$config = include '/var/www/uoj/app/.default-config.php';
  55. \$config['judger']['socket']['port']='$_judger_socket_port_';
  56. file_put_contents('/var/www/uoj/app/.config.php', "<?php\nreturn ".str_replace('\'_httpHost_\'','UOJContext::httpHost()',var_export(\$config, true)).";\n");
  57. UOJEOF
  58. # Prepare local sandbox
  59. cd /opt/uoj/judger/uoj_judger
  60. cat >include/uoj_work_path.h <<UOJEOF
  61. #define UOJ_WORK_PATH "/opt/uoj/judger/uoj_judger"
  62. #define UOJ_JUDGER_BASESYSTEM_UBUNTU1804
  63. #define UOJ_JUDGER_PYTHON3_VERSION "3.6"
  64. #define UOJ_JUDGER_FPC_VERSION "3.0.4"
  65. UOJEOF
  66. make runner -j$(($(nproc) + 1)) && cd /opt/uoj/web
  67. }
  68. initProgress(){
  69. printf "\n\n==> Doing initial config and start service\n"
  70. #Set uoj_data path
  71. mkdir -p /var/uoj_data/upload
  72. chown -R www-data:www-data /var/uoj_data
  73. #Using cli upgrade to latest
  74. php /var/www/uoj/app/cli.php upgrade:latest
  75. #Start services
  76. service ntp restart
  77. service apache2 restart
  78. #Touch SetupDone flag file
  79. touch /var/uoj_data/.UOJSetupDone
  80. mkdir -p /opt/uoj/web/app/storage/submission
  81. mkdir -p /opt/uoj/web/app/storage/tmp
  82. mkdir -p /opt/uoj/web/app/storage/paste
  83. chmod -R 777 /opt/uoj/web/app/storage
  84. printf "\n\n***Installation complete. Enjoy!***\n"
  85. }
  86. prepProgress(){
  87. setLAMPConf;setWebConf
  88. }
  89. if [ $# -le 0 ]; then
  90. echo 'Installing UOJ System web...'
  91. getAptPackage;prepProgress;initProgress
  92. fi
  93. while [ $# -gt 0 ]; do
  94. case "$1" in
  95. -p | --prep)
  96. echo 'Preparing UOJ System web environment...'
  97. prepProgress
  98. ;;
  99. -i | --init)
  100. echo 'Initing UOJ System web...'
  101. initProgress
  102. ;;
  103. -? | --*)
  104. echo "Illegal option $1"
  105. ;;
  106. esac
  107. shift $(( $#>0?1:0 ))
  108. done