315 lines
6.2 KiB
Bash
315 lines
6.2 KiB
Bash
#!/bin/bash
|
|
# Auteur: Pascal Anelli
|
|
# 06 juin 2019
|
|
|
|
set -u
|
|
|
|
log="$(mktemp)"
|
|
res=0
|
|
|
|
#===================================================================
|
|
function xfinish
|
|
{
|
|
echo "";
|
|
echo "Interruption de l evaluateur";
|
|
exit 1;
|
|
}
|
|
trap xfinish SIGINT SIGTERM
|
|
|
|
|
|
catch() {
|
|
echo "Erreur $1 a la ligne $2"
|
|
}
|
|
#trap 'catch $? $LINENO' ERR
|
|
#===================================================================
|
|
|
|
|
|
#---------------------------------------------
|
|
# global var: line
|
|
function readline
|
|
{
|
|
read -e -p 'Tapez votre commande maintenant $ ' -r line
|
|
}
|
|
|
|
|
|
#---------------------------------------------
|
|
# argument 1: challenge name
|
|
# global var: log
|
|
function banniere {
|
|
clear
|
|
echo "** Evaluation du challenge $1 **" | tee $log
|
|
}
|
|
|
|
#---------------------------------------------
|
|
# global var: challenge, log, rep, scriptname
|
|
function firstcheck {
|
|
banniere $challenge
|
|
echo "** Debut evaluation ***" |tee -a $log
|
|
|
|
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, res
|
|
# 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
|
|
|
|
# output message
|
|
echo "Pas: $res" "$2 : $etat" |tee -a $log
|
|
|
|
if $fatal && ! $1 ; then
|
|
echo -e " ERREUR Fatale : Votre reponse ne respecte pas les consignes. \n La suite de l'evaluation ne peut etre effectuee - recommencez le challenge"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
|
|
#---------------------------------------------
|
|
# argument 1: String to check
|
|
# return true if the argument is an integer
|
|
function isinteger {
|
|
[[ "$1" =~ ^[-+]?[0-9]+$ ]]
|
|
}
|
|
|
|
#---------------------------------------------
|
|
# argument: string to hash
|
|
function code() {
|
|
echo -n $(echo "$1" | md5sum| cut -c4-6)
|
|
}
|
|
|
|
#---------------------------------------------
|
|
# argument 1: the string to hash by md5sum
|
|
function status() {
|
|
echo "Le code de l'evaluation a saisir est : " $(code "$1")
|
|
}
|
|
|
|
# argument: target directory
|
|
function isrep {
|
|
if [ "$1" != $(pwd) ]
|
|
then
|
|
echo "Le repertoire 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 -n "listcode = [ '000'"
|
|
for ((i=1; i<=$1; i++)); do
|
|
echo -n ", " \'$(code "${2}_$i")\'
|
|
done
|
|
echo " ]"
|
|
exit 0
|
|
}
|
|
|
|
#=====================================================================
|
|
function mkfiledata () {
|
|
cat <<EOF >|${1}.csv
|
|
Province/State,Country/Region,Last Update,Confirmed,Deaths,Recovered
|
|
Hubei,China,2020-03-17T11:53:10,67799,3111,56003
|
|
,Italy,2020-03-17T18:33:02,31506,2503,2941
|
|
,Iran,2020-03-17T15:13:09,16169,988,5389
|
|
,Spain,2020-03-17T20:53:02,11748,533,1028
|
|
,Germany,2020-03-17T18:53:02,9257,24,67
|
|
,Korea South,2020-03-17T10:33:03,8320,81,1407
|
|
France,France,2020-03-17T19:13:08,7652,148,12
|
|
,Switzerland,2020-03-17T16:33:04,2700,27,4
|
|
United Kingdom,United Kingdom,2020-03-17T15:13:09,1950,55,52
|
|
New York,US,2020-03-17T22:53:03,1706,13,0
|
|
Netherlands,Netherlands,2020-03-17T15:13:11,1705,43,2
|
|
,Norway,2020-03-17T19:53:02,1463,3,1
|
|
Guangdong,China,2020-03-17T01:53:03,1364,8,1307
|
|
,Austria,2020-03-17T15:33:06,1332,3,1
|
|
Henan,China,2020-03-14T09:53:08,1273,22,1250
|
|
,Belgium,2020-03-17T15:33:06,1243,10,1
|
|
Zhejiang,China,2020-03-17T02:13:21,1232,1,1216
|
|
EOF
|
|
}
|
|
|
|
function mkfilehtml
|
|
{
|
|
cat <<EOF >|${1}.html
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
</head>
|
|
<style>
|
|
table { border-collapse:collapse; }
|
|
td { border-width:1px; border-style:solid; border-color:black; }
|
|
</style>
|
|
<body>
|
|
<table>
|
|
<tr>
|
|
<td> Province/State </td>
|
|
<td> Country/Region </td>
|
|
<td> Last Update </td>
|
|
<td> Confirmed </td>
|
|
<td> Deaths </td>
|
|
<td> Recovered </td>
|
|
</tr>
|
|
<tr>
|
|
<td> Hubei </td>
|
|
<td> China </td>
|
|
<td> 2020-03-17T11:53:10 </td>
|
|
<td> 67799 </td>
|
|
<td> 3111 </td>
|
|
<td> 56003 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Italy </td>
|
|
<td> 2020-03-17T18:33:02 </td>
|
|
<td> 31506 </td>
|
|
<td> 2503 </td>
|
|
<td> 2941 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Iran </td>
|
|
<td> 2020-03-17T15:13:09 </td>
|
|
<td> 16169 </td>
|
|
<td> 988 </td>
|
|
<td> 5389 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Spain </td>
|
|
<td> 2020-03-17T20:53:02 </td>
|
|
<td> 11748 </td>
|
|
<td> 533 </td>
|
|
<td> 1028 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Germany </td>
|
|
<td> 2020-03-17T18:53:02 </td>
|
|
<td> 9257 </td>
|
|
<td> 24 </td>
|
|
<td> 67 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Korea South </td>
|
|
<td> 2020-03-17T10:33:03 </td>
|
|
<td> 8320 </td>
|
|
<td> 81 </td>
|
|
<td> 1407 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> France </td>
|
|
<td> France </td>
|
|
<td> 2020-03-17T19:13:08 </td>
|
|
<td> 7652 </td>
|
|
<td> 148 </td>
|
|
<td> 12 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Switzerland </td>
|
|
<td> 2020-03-17T16:33:04 </td>
|
|
<td> 2700 </td>
|
|
<td> 27 </td>
|
|
<td> 4 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> United Kingdom </td>
|
|
<td> United Kingdom </td>
|
|
<td> 2020-03-17T15:13:09 </td>
|
|
<td> 1950 </td>
|
|
<td> 55 </td>
|
|
<td> 52 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> New York </td>
|
|
<td> US </td>
|
|
<td> 2020-03-17T22:53:03 </td>
|
|
<td> 1706 </td>
|
|
<td> 13 </td>
|
|
<td> 0 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> Netherlands </td>
|
|
<td> Netherlands </td>
|
|
<td> 2020-03-17T15:13:11 </td>
|
|
<td> 1705 </td>
|
|
<td> 43 </td>
|
|
<td> 2 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Norway </td>
|
|
<td> 2020-03-17T19:53:02 </td>
|
|
<td> 1463 </td>
|
|
<td> 3 </td>
|
|
<td> 1 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> Guangdong </td>
|
|
<td> China </td>
|
|
<td> 2020-03-17T01:53:03 </td>
|
|
<td> 1364 </td>
|
|
<td> 8 </td>
|
|
<td> 1307 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Austria </td>
|
|
<td> 2020-03-17T15:33:06 </td>
|
|
<td> 1332 </td>
|
|
<td> 3 </td>
|
|
<td> 1 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> Henan </td>
|
|
<td> China </td>
|
|
<td> 2020-03-14T09:53:08 </td>
|
|
<td> 1273 </td>
|
|
<td> 22 </td>
|
|
<td> 1250 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> </td>
|
|
<td> Belgium </td>
|
|
<td> 2020-03-17T15:33:06 </td>
|
|
<td> 1243 </td>
|
|
<td> 10 </td>
|
|
<td> 1 </td>
|
|
</tr>
|
|
<tr>
|
|
<td> Zhejiang </td>
|
|
<td> China </td>
|
|
<td> 2020-03-17T02:13:21 </td>
|
|
<td> 1232 </td>
|
|
<td> 1 </td>
|
|
<td> 1216 </td>
|
|
</tr>
|
|
</table>
|
|
</body>
|
|
</html>
|
|
EOF
|
|
}
|