diff options
| author | Bruno Ribas <brunoribas@gmail.com> | 2016-10-31 15:04:39 +0000 |
|---|---|---|
| committer | Bruno Ribas <brunoribas@gmail.com> | 2016-10-31 15:04:39 +0000 |
| commit | 82f4e8fcae75551a79f3463ad5e97186059ca98a (patch) | |
| tree | f1c2314c03cf08520fbff3b733253492c4eb4e96 | |
| parent | d74b515925ba838e87988edf510582dee4d5c80b (diff) | |
| download | boca-82f4e8fcae75551a79f3463ad5e97186059ca98a.tar.gz boca-82f4e8fcae75551a79f3463ad5e97186059ca98a.zip | |
tools/boca-submit-run{,-aux,-cron,-root}: Updated
Files updated to the last version used in Brazillian Regionals
Signed-off-by: Cassio de Campos <cassiopc@gmail.com>
Signed-off-by: Bruno Ribas <brunoribas@gmail.com>
| -rwxr-xr-x | tools/boca-submit-run | 70 | ||||
| -rwxr-xr-x | tools/boca-submit-run-aux | 38 | ||||
| -rwxr-xr-x | tools/boca-submit-run-cron | 16 | ||||
| -rwxr-xr-x | tools/boca-submit-run-root | 50 |
4 files changed, 116 insertions, 58 deletions
diff --git a/tools/boca-submit-run b/tools/boca-submit-run index 1502c07..b746a29 100755 --- a/tools/boca-submit-run +++ b/tools/boca-submit-run @@ -1,18 +1,47 @@ #!/bin/bash -[ -x /etc/icpc/bocaserver.sh ] && . /etc/icpc/bocaserver.sh -if [ "$BOCASERVER" != "" ]; then +export PATH="/bin:/sbin:/usr/bin:/usr/sbin" + +if [[ ! -e /etc/bocaip ]] ; then + echo "O IP do servidor boca nao configurado. Abort." + exit 1 +fi + +#Check if this script is running in a user in sudo group or root +if groups | egrep -q "(sudo|root)" ; then + echo "Este script deve ser executado por um usuario normal" + echo "Na Maratona este usuario, geralmente, é o 'icpc'" + exit 1 +fi + +runroot=`which boca-submit-run-root-wrapper` +if [ "$runroot" == "" ]; then + runroot=/usr/bin/boca-submit-run-root-wrapper +fi + +if [ "`basename $0`" == "boca-submit-oldlist" ]; then + $runroot list old list list list list list +else + +if [ "`basename $0`" == "boca-submit-list" ]; then + $runroot list list list list list list list +else + + source /etc/bocaip + BOCASERVER=$BOCAIP + + if [ "$BOCASERVER" != "" ]; then if [ "$BOCASERVERS" == "" ]; then BOCASERVERS=$BOCASERVER else BOCASERVERS="$BOCASERVERS;$BOCASERVER" fi -fi + fi -if [ "$BOCASERVERS" == "" ]; then + if [ "$BOCASERVERS" == "" ]; then echo "This computer has no configured BOCA server. Ask an admin to update /etc/icpc/bocaserver.sh (usually resetting everything is an easy way)" exit 1 -fi + fi for i in uuencode wget tr perl sha256sum cut; do @@ -24,7 +53,6 @@ for i in uuencode wget tr perl sha256sum cut; do exit 1 fi done -temp=/tmp/.temp.`date +%s%N`.txt if [ "$1" == "" ]; then echo "Usage: $0 USER PASSWORD PROBLEM LANGUAGE FILE" @@ -40,36 +68,14 @@ if [ "$1" == "" ]; then exit 1 fi -runaux=`which boca-submit-run-aux` -if [ "$runaux" == "" ]; then - runaux=/usr/bin/boca-submit-run-aux -fi -runroot=`which boca-submit-run-root-wrapper` -if [ "$runroot" == "" ]; then - runroot=/usr/bin/boca-submit-run-root-wrapper -fi - if [ -r "$5" ]; then nom=`echo -n "$5" | perl -MURI::Escape -lne 'print uri_escape($_)'` for BOCASERVER in `echo $BOCASERVERS | tr ';' ' '`; do - echo "BOCASERVER=$BOCASERVER" > $temp - echo "user=$1" >> $temp - echo "pass=$2" >> $temp - echo "problem=$3" >> $temp - echo "language=$4" >> $temp - echo "name=`basename $5`" >> $temp - uniq=`sha256sum "$5" | cut -f1 -d' '` - echo "uniq=$uniq" >> $temp - echo -en "data=\"" >> $temp - uuencode -m zzzzzzzzzz < "$5" | grep -v "begin-base64.*zzzzzzzzzz" >> $temp - echo -e "\"" >> $temp - $runaux $temp - if [ "$?" == "2" ]; then - echo "$BOCASERVER: time-out - this will automatically retry soon, you should not worry" - $runroot "$BOCASERVER" "$1" "$2" "$3" "$4" "`basename $5`" "$5" - fi - [ -f "$temp" ] && rm -f $temp + $runroot "$BOCASERVER" "$1" "$2" "$3" "$4" "`basename $5`" "$5" done else echo "file $5 not found/readable" fi + +fi +fi diff --git a/tools/boca-submit-run-aux b/tools/boca-submit-run-aux index 1be0945..1398899 100755 --- a/tools/boca-submit-run-aux +++ b/tools/boca-submit-run-aux @@ -1,5 +1,7 @@ #!/bin/bash +export PATH="/bin:/sbin:/usr/bin:/usr/sbin" + [ -r "$1" ] && . "$1" if [ "$BOCASERVER" == "" -o "$user" == "" -o "$pass" == "" -o "$data" == "" -o "$name" == "" ]; then echo "parameters missing in file $1" @@ -35,7 +37,7 @@ if [ "$?" == "0" ]; then rm -f ${temp}.cookie.txt exit 3 else - echo -n "name=`echo $name | perl -MURI::Escape -lne 'print uri_escape($_)'`" > $temp + echo -n "name=`echo -n $name | perl -MURI::Escape -lne 'print uri_escape($_)'`" > $temp if [ "$uniq" != "" ]; then echo -n "&pastcode=$uniq" >> $temp if [ "$code" != "" ]; then @@ -45,33 +47,39 @@ if [ "$?" == "0" ]; then echo -n "&pastabs=${dateerr}" >> $temp let "dateerr = `date +%s` - $dateerr" echo -n "&pastval=${dateerr}" >> $temp + comp="error" + if [ -r /root/submissions/comp ]; then + comp=`cat /root/submissions/comp` + fi + echo -n "&comp=${comp}" >> $temp if [ -r /root/submissions/code ]; then code=`cat /root/submissions/code` - res=`echo -n "${code}${uniq}${dateerr}" | sha256sum - | cut -f1 -d' '` + res=`echo -n "${code}${uniq}${comp}${dateerr}" | sha256sum - | cut -f1 -d' '` echo -n "&pastvalhash=${res}" >> $temp fi fi fi - echo -n "&problem=`echo $problem | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp - echo -n "&language=`echo $language | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp - echo -n "&data=`echo $data | tr -d ' ' | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp + echo -n "&problem=`echo -n $problem | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp + echo -n "&language=`echo -n $language | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp + echo -n "&data=`echo -n $data | tr -d ' ' | perl -MURI::Escape -lne 'print uri_escape($_)'`" >> $temp wget -t 2 -T 5 "http://$BOCASERVER/boca/team/run.php" --load-cookies ${temp}.cookie.txt --keep-session-cookies -O ${temp}.out --post-file=$temp >/dev/null 2>/dev/null res=`tail -n1 ${temp}.out` echo $res | grep -q "RESULT:" if [ "$?" == "0" ]; then - if [ "$uniq" == "" ]; then +# if [ "$uniq" == "" ]; then echo "$BOCASERVER : $res" - else - echo "$BOCASERVER : run $uniq dateerr $dateerr : $res" - fi +# else +# echo "$BOCASERVER : run code $uniq dateerr $dateerr : $res" +# fi else - if [ "$uniq" == "" ]; then - echo "$BOCASERVER : error to upload the run, will NOT try again, check details" - else - echo "$BOCASERVER : run $uniq dateerr $dateerr : error to upload the run, will NOT try again, check details:" - cat ${temp}.out - fi +# if [ "$uniq" == "" ]; then + echo "$BOCASERVER : error to upload the run, will NOT try again, check details at /tmp/boca-submit.err" +# else +# echo "$BOCASERVER : run $uniq dateerr $dateerr : error to upload the run, will NOT try again, check details at /tmp/boca-submit.err" + cat ${temp}.out > /tmp/boca-submit.err + chmod 400 /tmp/boca-submit.err +# fi rm -f ${temp}.out exit 4 fi diff --git a/tools/boca-submit-run-cron b/tools/boca-submit-run-cron index 64d55ee..81ff6a2 100755 --- a/tools/boca-submit-run-cron +++ b/tools/boca-submit-run-cron @@ -6,23 +6,23 @@ if [ "`id -u`" != "0" ]; then fi if [ -d /root/submissions ]; then - touch /root/submissions/placeholder.bocarun - runaux=`which boca-submit-run-aux` - if [ "$runaux" == "" ]; then - runaux=/var/www/boca/tools/boca-submit-run-aux - fi - + touch /root/submissions/placeholder.bocarun + runaux=/usr/bin/boca-submit-run-aux + if [ ! -f "$runaux" ]; then + echo "Error: could not find aux script" + else for i in `ls /root/submissions/*.bocarun`; do if [ "$i" != "/root/submissions/placeholder.bocarun" ]; then - $runaux "$i" + $runaux "$i" > ${i}.result res=$? if [ "$res" == "2" ]; then - echo "$i: time-out - this will automatically retry soon" + echo "time-out - this will automatically retry soon" > ${i}.result fi if [ "$res" == "0" ]; then mv "$i" "${i}.processed" fi fi done + fi fi diff --git a/tools/boca-submit-run-root b/tools/boca-submit-run-root index 4cc2231..0fac460 100755 --- a/tools/boca-submit-run-root +++ b/tools/boca-submit-run-root @@ -1,10 +1,41 @@ #!/bin/bash +export PATH="/bin:/sbin:/usr/bin:/usr/sbin" + if [ "`id -u`" != "0" ]; then echo "Must be run as root" exit 1 fi +if [ "$1" == "list" ]; then + if [ -d /root/submissions ]; then + touch /root/submissions/placeholder.bocarun + if [ "$2" == "old" ]; then + for i in `ls /root/submissions/*.bocarun.processed`; do + if [ "$i" != "/root/submissions/placeholder.bocarun" ]; then + prob=`grep ^problem $i` + lang=`grep ^language $i` + nam=`grep ^name $i` + res="" + resf="/root/submissions/`basename ${i} .processed`.result" + [ -r "$resf" ] && res=`cat "$resf"` + echo "RUN DONE: $prob $lang $nam $res" + fi + done + else + for i in `ls /root/submissions/*.bocarun`; do + if [ "$i" != "/root/submissions/placeholder.bocarun" ]; then + prob=`grep ^problem $i` + lang=`grep ^language $i` + nam=`grep ^name $i` + res="" + [ -r "${i}.result" ] && res=`cat ${i}.result` + echo "RUN AWAITING: $prob $lang $nam $res" + fi + done + fi + fi +else if [ "$7" != "" ]; then mkdir -p /root/submissions chown root /root/submissions @@ -18,7 +49,7 @@ if [ "$7" != "" ]; then echo "language=`echo $5 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom" echo "name=`echo $6 | tr -cd '[[:alnum:]]._+-/'`" >> "$nom" echo -en "data=\"" >> "$nom" - uuencode -m zzzzzzzzzz < `echo "$7" | tr -cd '[[:alnum:]]._+-/'` | grep -v "begin-base64.*zzzzzzzzzz" >> "$nom" + uuencode -m zzzzzzzzzz < `echo -n "$7" | tr -cd '[[:alnum:]]._+-/'` | grep -v "begin-base64.*zzzzzzzzzz" >> "$nom" echo "\"" >> "$nom" dateerr=`date +%s` echo "dateerr=$dateerr" >> "$nom" @@ -26,8 +57,21 @@ if [ "$7" != "" ]; then # uniq=`echo $uniq | sha256sum - | cut -f1 -d' '` uniq=`sha256sum "$7" | cut -f1 -d' '` code=`cat /root/submissions/code` - res=`echo -n "${code}${uniq}${dateerr}" | sha256sum - | cut -f1 -d' '` + comp="error" + if [ -r /root/submissions/comp ]; then + comp=`cat /root/submissions/comp` + fi + res=`echo -n "${code}${uniq}${comp}${dateerr}" | sha256sum - | cut -f1 -d' '` echo "uniq=$uniq" >> "$nom" echo "code=$res" >> "$nom" - mv "$nom" "/root/submissions/`basename $nom .tmp`" + echo "comp=$comp" >> "$nom" + + /usr/bin/boca-submit-run-aux $nom + if [ "$?" == "2" ]; then + mv "$nom" "/root/submissions/`basename $nom .tmp`" + echo "Run submission included in the queue -- it shall appear in the system later when connection is available" + else + [ -f "$nom" ] && rm -f $nom + fi +fi fi |