Fix relative path

This commit is contained in:
poka 2019-11-24 05:10:39 +01:00
parent 022cf49eea
commit 65fa534743
1 changed files with 11 additions and 10 deletions

View File

@ -1,17 +1,18 @@
#!/bin/bash #!/bin/bash
## TODO: Prendre en compte les transactions déjà appliqués [ "$EUID" -ne 0 ] && sudo="sudo" || sudo=""
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
start=`date +%s` start=`date +%s`
date=$(date +'%d-%m-%y à %H:%M') date=$(date +'%d-%m-%y à %H:%M')
echo "### $date ###" echo "### $date ###"
## Initialisation ## Initialisation
DUNITER=$(grep g1_node ../config/config.php | awk '{ print $3}' | tr -d ';' | tr -d "'") DUNITER=$(grep g1_node $SCRIPTPATH/../config/config.php | awk '{ print $3}' | tr -d ';' | tr -d "'")
TXBLOCKS=$(curl -s $DUNITER/blockchain/with/tx | jq '.result.blocks[]') TXBLOCKS=$(curl -s $DUNITER/blockchain/with/tx | jq '.result.blocks[]')
TXBLOCKS=$(echo "$TXBLOCKS" | tail -n 2 | tr '\n' ' ') TXBLOCKS=$(echo "$TXBLOCKS" | tail -n 2 | tr '\n' ' ')
keyword="\[Achat GMarche] : " keyword="\[Achat GMarche] : "
[ ! -e .loc_hash ] && touch .loc_hash [ ! -e $SCRIPTPATH/.loc_hash ] && touch $SCRIPTPATH/.loc_hash
## Récupération des transactions avec commentaire GMarche ## Récupération des transactions avec commentaire GMarche
@ -19,9 +20,9 @@ for i in $TXBLOCKS; do
result=$(curl -s $DUNITER/blockchain/block/$i | jq '.transactions[].hash, .transactions[].comment' | grep -v '""' | tr -d '"' | grep -B1 "$keyword") result=$(curl -s $DUNITER/blockchain/block/$i | jq '.transactions[].hash, .transactions[].comment' | grep -v '""' | tr -d '"' | grep -B1 "$keyword")
rhash=$(echo "$result" | head -n1) rhash=$(echo "$result" | head -n1)
rcom=$(echo "$result" | tail -n1) rcom=$(echo "$result" | tail -n1)
if [[ ! -z $result && -z $(grep $rhash .loc_hash) ]]; then if [[ ! -z $result && -z $(grep $rhash $SCRIPTPATH/.loc_hash) ]]; then
isSell+=$(echo -e "$rcom;") isSell+=$(echo -e "$rcom;")
echo "$rhash" >> .loc_hash echo "$rhash" >> $SCRIPTPATH/.loc_hash
fi fi
sleep 1 sleep 1
done done
@ -29,15 +30,15 @@ done
## Ajout des transactions en piscine pour les users GMarche ## Ajout des transactions en piscine pour les users GMarche
req="SELECT pubkey FROM users;" req="SELECT pubkey FROM users;"
usersPubkeys=$(sudo mysql --database gmarche -e "$req" | grep .) usersPubkeys=$($sudo mysql --database gmarche -e "$req" | grep .)
for i in $usersPubkeys; do for i in $usersPubkeys; do
result=$(curl -s $DUNITER/tx/history/$i/pending | jq '. | select(.history.sending == [])' | jq '.history.pending[].hash,.history.pending[].comment' | tr -d '"') result=$(curl -s $DUNITER/tx/history/$i/pending | jq '. | select(.history.sending == [])' | jq '.history.pending[].hash,.history.pending[].comment' | tr -d '"')
rhash=$(echo "$result" | head -n1) rhash=$(echo "$result" | head -n1)
rcom=$(echo "$result" | tail -n1) rcom=$(echo "$result" | tail -n1)
if [[ ! -z $result && -z $(grep $rhash .loc_hash) ]]; then if [[ ! -z $result && -z $(grep $rhash $SCRIPTPATH/.loc_hash) ]]; then
isSell+=$(echo -e "$rcom;") isSell+=$(echo -e "$rcom;")
echo "$rhash" >> .loc_hash echo "$rhash" >> $SCRIPTPATH/.loc_hash
fi fi
done done
@ -51,10 +52,10 @@ IFS=';'; ADDR=($isSell); unset IFS;
for i in "${ADDR[@]}"; do for i in "${ADDR[@]}"; do
#req="UPDATE products SET status = 'solde' WHERE name = '$i';" #req="UPDATE products SET status = 'solde' WHERE name = '$i';"
req="UPDATE products SET quantite = CASE WHEN quantite = 0 THEN quantite ELSE quantite - 1 END WHERE name = '$i';" req="UPDATE products SET quantite = CASE WHEN quantite = 0 THEN quantite ELSE quantite - 1 END WHERE name = '$i';"
sudo mysql --database gmarche -e "$req" $sudo mysql --database gmarche -e "$req"
done done
#sudo mysql --database gmarche -e "SELECT name,status FROM products;" #$sudo mysql --database gmarche -e "SELECT name,status FROM products;"
end=`date +%s` end=`date +%s`
runtime=$((end-start)) runtime=$((end-start))