From 6d161b380415446a984eb88e759bcf4b41f87d51 Mon Sep 17 00:00:00 2001 From: MEUNIER Thibaud Date: Fri, 19 Aug 2022 13:03:23 +0200 Subject: [PATCH] =?UTF-8?q?priorit=C3=A9=20nonce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonce/robot.php | 30 ++++++++++++++++++ scripts/blocks2.sh | 36 +++++++++++++++------ scripts/clean_data.sh | 4 +-- scripts/known_blocks.sh | 1 + scripts/nonce.sh | 69 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+), 12 deletions(-) create mode 100644 nonce/robot.php create mode 100755 scripts/nonce.sh diff --git a/nonce/robot.php b/nonce/robot.php new file mode 100644 index 0000000..67d13ea --- /dev/null +++ b/nonce/robot.php @@ -0,0 +1,30 @@ +nonce; + +?> diff --git a/scripts/blocks2.sh b/scripts/blocks2.sh index 4afbceb..b73cbc1 100755 --- a/scripts/blocks2.sh +++ b/scripts/blocks2.sh @@ -1,5 +1,6 @@ #!/bin/bash -lescript=blocks2 +lescript=`basename $0 .sh` +flag=$TMP_PATH/bot_$lescript.flag # # TOOLS @@ -56,16 +57,26 @@ while IFS='' read -r line || [[ -n "$line" ]]; do fi touch $flag - # - # CHOISIR UNE METHODE2 AU HASARD - # - # LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | shuf` - # LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | shuf | head -n 1` - # en rajoutant le head, on ne fait qu'un seul dessin - LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | shuf | head -n 1` - if [ $HEIGHT -eq 1 ] + if [ ! -f $DATA_PATH/nonce/$BLOCK.png ] then - LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v treemap | grep -v robot | shuf | head -n 1` + # + # Si c'est la première fois que l'on dessine le block + # On choisit la méthode qui découle du nonce + # + cd $APPS_PATH/nonce + nbmethodes=`cat $DATA_PATH/nonce_methods_list.txt | wc -l` + lenonce=`php robot.php $BLOCK` + lamethode=$((lenonce % nbmethodes)) + if [ $lamethode -eq 0 ] + then + lamethode=$nbmethodes + fi + LISTE_METHODE=`cat $DATA_PATH/nonce_methods_list.txt | head -n $lamethode | tail -1` + else + # + # CHOISIR UNE METHODE2 AU HASARD + # + LISTE_METHODE=`ls $APPS_PATH/methode2 | grep -v robot | shuf | head -n 1` fi cd $APPS_PATH/methode2 @@ -89,6 +100,11 @@ while IFS='' read -r line || [[ -n "$line" ]]; do cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png fi + if [ ! -f $DATA_PATH/nonce/$BLOCK.png ] + then + cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/nonce/$BLOCK.png + fi + rm -f $flag done < $DATA_PATH/block_list.txt diff --git a/scripts/clean_data.sh b/scripts/clean_data.sh index ae8e22c..acc04a8 100755 --- a/scripts/clean_data.sh +++ b/scripts/clean_data.sh @@ -13,8 +13,8 @@ if [ "$#" -eq "0" ] then if [ -d $DATA_PATH ] then - find $DATA_PATH -mtime +1 -type f -name *.png -exec rm -f {} \; - find $DATA_PATH -mtime +1 -type f -name *.zip -exec rm -f {} \; + find $DATA_PATH -mtime +3 -type f -name *.png -exec rm -f {} \; + find $DATA_PATH -mtime +3 -type f -name *.zip -exec rm -f {} \; find $TMP_PATH -mtime +3 -type f -name *.flag -exec rm -f {} \; fi diff --git a/scripts/known_blocks.sh b/scripts/known_blocks.sh index 45f6782..1c4c1ad 100755 --- a/scripts/known_blocks.sh +++ b/scripts/known_blocks.sh @@ -72,6 +72,7 @@ while IFS='' read -r line || [[ -n "$line" ]]; do echo $BLOCK $NAME $METHODE if [ ! -f $DATA_PATH/$METHODE/$BLOCK.png ] then + echo Drawing $BLOCK $METHODE php robot.php $METHODE $BLOCK $((RANDOM % 6)) $2 cp $DATA_PATH/last/$BLOCK.png $DATA_PATH/$METHODE/$BLOCK.png fi diff --git a/scripts/nonce.sh b/scripts/nonce.sh new file mode 100755 index 0000000..12b6d5c --- /dev/null +++ b/scripts/nonce.sh @@ -0,0 +1,69 @@ +#!/bin/bash +lescript=`basename $0 .sh` +flag=$TMP_PATH/bot_$lescript.flag + +# +# TOOLS +# +function debug +{ + if [ -f $FLAG_PATH/debug ] + then + echo $1 + fi +} + +function sortie +{ + if [ -f $flag ] + then + rm -f $flag + fi + exit $1 +} + +function succes +{ + debug "SUCCES" + sortie 0 +} + +function echec +{ + debug "ECHEC" + sortie 1 +} + +# +# TEST DU FLAG +# +if [ -f $flag ] +then + debug "$0 is already running !" + exit 1 +fi +touch $flag + +# +# DO IT ! +# +while IFS='' read -r line || [[ -n "$line" ]]; do + # + # On choisit la méthode qui découle du nonce + # + cd $APPS_PATH/nonce + nbmethodes=`ls $APPS_PATH/methode2 | grep -v robot | wc -l` + lenonce=`php robot.php $BLOCK` + lamethode=$((lenonce%nbmethodes)) + [ $lamethode -eq 0 ] ; lamethode=$nbmethodes + METHODE=`ls $APPS_PATH/methode2 | grep -v robot | head -n $lamethode` + if [ -f $DATA_PATH/$METHODE/$BLOCK.png ] + then + cp $DATA_PATH/$METHODE/$BLOCK.png $DATA_PATH/nonce/$BLOCK.png + fi +done < $DATA_PATH/block_list.txt + +# +# SORTIE AVEC SUCCES +# +succes