109 lines
2.3 KiB
Bash
109 lines
2.3 KiB
Bash
|
#!/bin/bash
|
||
|
# Auteur: Pascal Anelli
|
||
|
# 06 juin 2020
|
||
|
|
||
|
set -u
|
||
|
|
||
|
log="$(mktemp)"
|
||
|
res=0
|
||
|
|
||
|
#===================================================================
|
||
|
function xfinish
|
||
|
{
|
||
|
echo "";
|
||
|
echo "Interruption de l evaluateur";
|
||
|
exit 1;
|
||
|
}
|
||
|
|
||
|
#===================================================================
|
||
|
|
||
|
trap xfinish SIGINT SIGTERM
|
||
|
|
||
|
# global var: line
|
||
|
function readline
|
||
|
{
|
||
|
read -e -p 'Tapez votre commande maintenant $ ' -r line
|
||
|
}
|
||
|
|
||
|
# argument 1: challenge name
|
||
|
# global var: log
|
||
|
function banniere {
|
||
|
echo "** Evaluation du challenge $1 **" | tee $log
|
||
|
}
|
||
|
|
||
|
# global var: challenge, log, rep, scriptname
|
||
|
function firstcheck {
|
||
|
banniere $challenge
|
||
|
step false "debut - retour sous la forme oui ou"
|
||
|
|
||
|
if [ ! -f $rep/$scriptname ] || [ ! -x $rep/$scriptname ]
|
||
|
then
|
||
|
echo "Attention: Votre script doit s'appeler $scriptname, etre dans le repertoire $rep et etre executable" >&2
|
||
|
exit 1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
function vraifaux {
|
||
|
if test "$1" -eq 0 ; then
|
||
|
echo "true"
|
||
|
else
|
||
|
echo "false"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# argument 1: cmd or (true, false) (State for this step)
|
||
|
# argument 2: Associated message to step
|
||
|
# argument 3: Optional, true for a fatal error = exit from eval
|
||
|
# global var: log
|
||
|
# step must be true to continue to be incremented
|
||
|
function step() {
|
||
|
local fatal=${3:-false}
|
||
|
local etat=non
|
||
|
|
||
|
# step return : true or false
|
||
|
$1 && { etat="oui" ; ((res++)) ; } #number of steps good
|
||
|
|
||
|
echo "Pas: $res" "$2 : $etat" |tee -a $log
|
||
|
if $fatal && ! $1 ; then
|
||
|
echo " ERREUR Fatale : la suite de l'evaluation ne peut etre effectuee"
|
||
|
exit 1
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
|
||
|
# argument 1: String to check
|
||
|
# return true if the argument is an integer
|
||
|
function isinteger {
|
||
|
[[ "$1" =~ ^-?[0-9]+$ ]]
|
||
|
}
|
||
|
|
||
|
|
||
|
# argument 1: the string to hash by md5sum
|
||
|
function status() {
|
||
|
echo "Le code de l'evaluation a saisir est : " $(echo "$1" | md5sum| cut -c4-6)
|
||
|
}
|
||
|
|
||
|
# argument: target directory
|
||
|
function isrep {
|
||
|
if [ "$1" = $(pwd) ]
|
||
|
then
|
||
|
echo "Le répertoire courant doit etre $1"
|
||
|
echo " ERREUR Fatale : la suite de l'evaluation ne peut etre effectuee"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
}
|
||
|
|
||
|
# argument 1 : max step number
|
||
|
# argument 2: Prefix string
|
||
|
function codechecker {
|
||
|
echo "#---- evaluation code"
|
||
|
for ((i=1; i<=$1; i++)); do
|
||
|
echo "# pas $i ==>" $(status "${2}_$i")
|
||
|
done
|
||
|
echo "#-----"
|
||
|
exit 0
|
||
|
}
|
||
|
#=====================================================================
|
||
|
|