diff --git a/installer/install-opensuse.sh b/installer/install-opensuse.sh new file mode 100644 --- /dev/null +++ b/installer/install-opensuse.sh @@ -0,0 +1,179 @@ +#!/bin/sh + +echo "This script will install and configure Cafe grader." + +RUBY_VERSION=2.1.2 +echo "This will install Ruby $RUBY_VERSION under RVM" + +echo "Installing required apts" + +sudo zypper install \ + g++ gcc libmysqlclient18 build-essential \ + git-core openssl libreadline6 libreadline6-devel \ + zlib1g zlib1g-devel libssl37 libyaml-devel sqlite3-devel \ + sqlite3 libxml2-devel libxslt-devel autoconf libc6-devel \ + ncurses-devel automake libtool bison subversion \ + pkg-config curl nodejs unzip pyflakes java-1_8_0-openjdk \ + libmysqld-devel mercurial python-setuptools python-devel + + +echo "Installing Ruby $RUBY_VERSION in RVM" + +rvm install $RUBY_VERSION +rvm use $RUBY_VERSION + +echo "Fetching Cafe Grader from Git repositories" + +echo "Fetching web interface" + +mkdir cafe_grader +cd cafe_grader +#git clone -q git://github.com/jittat/cafe-grader-web.git web +hg clone git+ssh://git@github.com/nattee/cafe-grader-web.git web + +echo "Configuring rails app" + +cp web/config/application.rb.SAMPLE web/config/application.rb +cp web/config/initializers/cafe_grader_config.rb.SAMPLE web/config/initializers/cafe_grader_config.rb + +#replace UTC in application.rb with the system timezone +timezone='UTC' +if [ -f '/etc/timezone' ]; then + timezone=\"`cat /etc/timezone`\" +else + if [ -f '/etc/sysconfig/clock' ]; then + timezone=`grep -e '^TIMEZONE' /etc/sysconfig/clock | grep -o -e '\".*\"'` + fi +fi +replace="s!'UTC'!$timezone!g" +sed -i $replace web/config/application.rb + +echo "At this point we will need MySQL user and database." +echo "Have you created MySQL user and database for Cafe grader? (Y/N) " +read ch + +if [ "$ch" = "n" -o "$ch" = "N" ] +then + echo "Please open another terminal and create the user and database for Cafe grader." + echo "Don't forget to grant access to that database for the user." + echo "Please have username, password, and database name ready before continue." + echo + echo "The following are instructions:" + echo "1. Run mysql:" + echo + echo " mysql -u root -p" + echo + echo " if you have just installed mysql, the root password is the one that you have just entered" + echo "2. Create a new database, a new user, and grant access to grader database:" + echo + echo " create user 'USERNAME'@'localhost' identified by 'PASSWORD';" + echo " create database \`DATABASENEME\`;" + echo " grant all on \`DATABASENAME\`.* to 'USERNAME'@'localhost';" + echo + echo " Replace USERNAME, PASSWORD, and DATABASENAME accordingly." + echo + echo "Hit enter when ready..." + read dummy +fi + +CAFE_PATH=`pwd` + +cd web + +echo "Please provide grader database:" +read database + +echo "Please provide grader username:" +read username + +echo "Please provide $username password:" +read password + +echo "development:" > config/database.yml +echo " adapter: mysql2" >> config/database.yml +echo " encoding: utf8" >> config/database.yml +echo " reconnect: false" >> config/database.yml +echo " database: $database" >> config/database.yml +echo " pool: 5" >> config/database.yml +echo " username: $username" >> config/database.yml +echo " password: $password" >> config/database.yml +echo " host: localhost" >> config/database.yml +echo " socket: /run/mysql/mysql.sock" >> config/database.yml +echo "" >> config/database.yml +echo "production:" >> config/database.yml +echo " adapter: mysql2" >> config/database.yml +echo " encoding: utf8" >> config/database.yml +echo " reconnect: false" >> config/database.yml +echo " database: $database" >> config/database.yml +echo " pool: 5" >> config/database.yml +echo " username: $username" >> config/database.yml +echo " password: $password" >> config/database.yml +echo " host: localhost" >> config/database.yml +echo " socket: /run/mysql/mysql.sock" >> config/database.yml + +echo "Object.instance_eval{remove_const :GRADER_ROOT_DIR}" >> config/initializers/cafe_grader_config.rb +echo "Object.instance_eval{remove_const :GRADING_RESULT_DIR}" >> config/initializers/cafe_grader_config.rb +echo "GRADER_ROOT_DIR = '$CAFE_PATH/judge'" >> config/initializers/cafe_grader_config.rb +echo "GRADING_RESULT_DIR = '$CAFE_PATH/judge/result'" >> config/initializers/cafe_grader_config.rb + +echo "Installing required gems" +gem install bundler +bundle install + +echo "Running rake tasks to initialize database" + +rake db:migrate +rake db:seed + +echo "Running rake tasks to precompile the assets" + +rake assets:precompile + +echo "Intalling web interface complete..." +echo +echo "Fetching grader" + +cd .. + +mkdir judge +cd judge +#git clone -q git://github.com/jittat/cafe-grader-judge-scripts.git scripts +hg clone git+ssh://git@github.com/nattee/cafe-grader-judge-scripts.git scripts +mkdir raw +mkdir ev-exam +mkdir ev +mkdir result +mkdir log + +echo "Configuring grader" + +cp scripts/config/env_exam.rb.SAMPLE scripts/config/env_exam.rb +cp scripts/config/env_grading.rb.SAMPLE scripts/config/env_grading.rb + +# create new environment.rb file +echo "RAILS_ROOT = '$CAFE_PATH/web'" > scripts/config/environment.rb +echo "GRADER_ROOT = '$CAFE_PATH/judge/scripts'" >> scripts/config/environment.rb +echo "require File.join(File.dirname(__FILE__),'../lib/boot')" >> scripts/config/environment.rb +echo "require File.dirname(__FILE__) + \"/env_#{GRADER_ENV}.rb\"" >> scripts/config/environment.rb + +# compiling box +MACHINE_TYPE=`uname -m` +if [ ${MACHINE_TYPE} == 'x86_64' ]; then + gcc -std=c99 -o scripts/std-script/box scripts/std-script/box64-new.c +else + g++ -o scripts/std-script/box scripts/std-script/box.cc +fi + + +cd .. + +echo "Now you are ready to run cafe grader...." +echo +echo "Try:" +echo +echo " cd web" +echo " rails s" +echo +echo "and access web at http://localhost:3000/" +echo "The root username is 'root', its password is 'ioionrails'." + diff --git a/installer/install.sh b/installer/install.sh --- a/installer/install.sh +++ b/installer/install.sh @@ -9,12 +9,13 @@ sudo apt-get update sudo apt-get install mysql-server mysql-client \ - g++ gcc apache2 libmysqlclient15-dev build-essential \ + g++ gcc apache2 libmysqlclient20 build-essential \ git-core openssl libreadline6 libreadline6-dev \ zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev \ sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev \ ncurses-dev automake libtool bison subversion \ - pkg-config curl nodejs unzip pyflakes ruby default-jdk + pkg-config curl nodejs unzip pyflakes ruby default-jdk \ + libmysqld-dev mercurial python-setuptools python-dev python3-numpy echo "Installing RVM" curl -k -L https://get.rvm.io | bash -s stable diff --git a/std-script/box64-new.c b/std-script/box64-new.c --- a/std-script/box64-new.c +++ b/std-script/box64-new.c @@ -603,6 +603,18 @@ /* 311 */ [ __NR_process_vm_writev ] = "process_vm_writev", /* 312 */ [ __NR_kcmp ] = "kcmp", /* 313 */ [ __NR_finit_module ] = "finit_module", +/* 314 */ [ __NR_sched_setattr ] = "sched_setattr", +/* 315 */ [ __NR_sched_getattr ] = "sched_getattr", +/* 316 */ [ __NR_renameat2 ] = "renameat2", +/* 317 */ [ __NR_seccomp ] = "seccomp", +/* 318 */ [ __NR_getrandom ] = "getrandom", +/* 319 */ [ __NR_memfd_create ] = "memfd_create", +/* 320 */ [ __NR_kexec_file_load ] = "kexec_file_load", +/* 321 */ [ __NR_bpf ] = "bpf", +/* 322 */ [ __NR_execveat ] = "execveat", +/* 323 */ [ __NR_userfaultfd ] = "userfaultfd", +/* 324 */ [ __NR_membarrier ] = "membarrier", +/* 325 */ [ __NR_mlock2 ] = "mlock2", }; #define NUM_SYSCALLS ARRAY_SIZE(syscall_names) #define NUM_ACTIONS (NUM_SYSCALLS+64) diff --git a/std-script/compile b/std-script/compile --- a/std-script/compile +++ b/std-script/compile @@ -147,20 +147,22 @@ end when "python" - command = "#{PYTHON_CHECKER} #{params[:source_file]}" - if system(command, out: params[:message_file]) + #command = "#{PYTHON_CHECKER} #{params[:source_file]}" + #if system(command, out: params[:message_file]) #compile to python bytecode command = "#{PYTHON_INTERPRETER} -c \"import py_compile; py_compile.compile('#{params[:source_file]}','#{params[:source_file]}c');\"" puts "compile: #{command}" - system(command) - puts "pwd: " + Dir.pwd - Dir.new('.').each {|file| puts file} - File.open(params[:output_file],"w") do |out_file| - out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" + system(command, err: params[:message_file]) + if FileTest.exists?("#{params[:source_file]}c") + puts "pwd: " + Dir.pwd + Dir.new('.').each {|file| puts file} + File.open(params[:output_file],"w") do |out_file| + out_file.puts "#!#{PYTHON_INTERPRETER} #{params[:source_file]}c" + end + File.chmod(0755, params[:output_file]) + FileUtils.cp("#{params[:source_file]}c",params[:output_file]) end - File.chmod(0755, params[:output_file]) - FileUtils.cp("#{params[:source_file]}c",params[:output_file]) - end + #end when "php" command = "#{PHP_INTERPRETER} #{PHP_OPTIONS} #{params[:source_file]}" diff --git a/std-script/run b/std-script/run --- a/std-script/run +++ b/std-script/run @@ -92,7 +92,7 @@ JAVA_OPTION = "-s set_robust_list -s futex -s clone -s getppid -s clone -s wait4 -p /usr/bin/ -p ./" RUBY_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /lib64/ -p /dev/urandom -p #{sandbox_dir}/#{program_name} -p #{sandbox_dir}/ -s set_robust_list -s sched_getaffinity -s clock_gettime -s sigaltstack -s pipe2 -s clone -s futex -s openat -s pipe" -PYTHON_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /usr/bin/ -p /lib64/ -p /dev/urandom -p /usr/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p #{sandbox_dir}/#{source_name} -p /proc/sys/crypto/fips_enabled -p /proc/mounts -p /var/lib/dpkg/status -s statfs -s set_robust_list -s openat -s sysinfo -s recvmsg -s connect -s socket -s sendto -s futex -s sigaltstack -E PYTHONNOUSERSITE=yes" +PYTHON_OPTION = "-p /usr/lib64/ -p /usr/local/lib64/ -p /usr/local/lib/ -p /usr/bin/ -p /lib64/ -p /dev/urandom -p /usr/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p #{sandbox_dir}/#{source_name} -p /proc/sys/crypto/fips_enabled -p /proc/self/status -p /proc/mounts -p /var/lib/dpkg/status -s statfs -s set_robust_list -s openat -s sysinfo -s recvmsg -s connect -s socket -s sendto -s futex -s sigaltstack -s getrandom -E PYTHONNOUSERSITE=yes" PHP_OPTION = "-p /usr/lib64/ -p/lib64/ -p /usr/bin/ -p #{sandbox_dir}/#{program_name} -p ./#{program_name} -p /usr/share/ -s setfsuid -s setfsgid -s openat -s set_robust_list -s futex -s clone -s socket -s connect" HASKELL_OPTION = "-s set_robust_list -s clock_gettime -s sysinfo -s timer_create -s timer_settime -s futex -s timer_delete"