#!/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 <|${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 <|${1}.html
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 }