From bfc23f3e529415bee0571a3e53465e5b56f936cd Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 24 Sep 2020 21:54:55 +0200 Subject: [PATCH] Improve scripts; Change GPATH name; Add generateDebugCache.sh --- explorer.sh | 6 +++++- g1-stats.sh | 16 ++++++++-------- lib/functions.sh | 8 ++++---- lib/scanTxWallets.sh | 10 +++++----- scripts/backup-actual.sh | 11 ----------- scripts/backup-cache.sh | 12 ++++++++++++ scripts/checkMissingDate.sh | 15 ++++++++++++--- scripts/compareMass.sh | 13 ++++++++----- scripts/generateDebugCache.sh | 12 ++++++++++++ scripts/restore-bk.sh | 17 ----------------- scripts/restore-cache.sh | 21 +++++++++++++++++++++ 11 files changed, 87 insertions(+), 54 deletions(-) delete mode 100755 scripts/backup-actual.sh create mode 100755 scripts/backup-cache.sh create mode 100755 scripts/generateDebugCache.sh delete mode 100755 scripts/restore-bk.sh create mode 100755 scripts/restore-cache.sh diff --git a/explorer.sh b/explorer.sh index f988742..ff99a8a 100755 --- a/explorer.sh +++ b/explorer.sh @@ -1,6 +1,10 @@ #!/bin/bash -jsonFile="db/daily.json" +# Récupération du chemin absolut du répertoir du script actuel +GPATH="$( cd "$(dirname "$0")" ; pwd -P )" +source $GPATH/.env + +jsonFile="$GPATH/db/daily.json" dateRange=$2 [[ -z $dateRange ]] && dateRange=$(jq -r '.[].date' $jsonFile | tail -n1) lineNbr=$(grep -n "$dateRange" $jsonFile | cut -d : -f 1) diff --git a/g1-stats.sh b/g1-stats.sh index c97fa32..a0f764c 100755 --- a/g1-stats.sh +++ b/g1-stats.sh @@ -12,8 +12,8 @@ set -e # Récupération du chemin absolut du répertoir du script actuel -SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" -if [[ -e $SCRIPTPATH/.env ]]; then source $SCRIPTPATH/.env; else echo "Veuillez créer votre fichier .env inspiré de .env.example" && exit 1; fi +GPATH="$( cd "$(dirname "$0")" ; pwd -P )" +if [[ -e $GPATH/.env ]]; then source $GPATH/.env; else echo "Veuillez créer votre fichier .env inspiré de .env.example" && exit 1; fi ### Initialisation des données ### startTime=$(date +'%H:%M') @@ -23,9 +23,9 @@ echo -e "\n############# $day à $startTime #############\n" [[ -z $(which jq) || -z $(which bc) || -z $(which curl) ]] && sudo apt update && sudo apt install jq bc curl echo "Initialisation ..." if $debug; then - TXBLOCKS=$(cat $SCRIPTPATH/db/debug/txblocs) - membresPubkeys=$(cat $SCRIPTPATH/db/debug/membresPubkeys) - udBlocs=$(cat $SCRIPTPATH/db/debug/udblocs) + TXBLOCKS=$(cat $GPATH/db/debug/txblocs) + membresPubkeys=$(cat $GPATH/db/debug/membresPubkeys) + udBlocs=$(cat $GPATH/db/debug/udblocs) echo # To clean next progress view else TXBLOCKS=$(curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]') @@ -43,11 +43,11 @@ unset 'TXBLOCKS[${#TXBLOCKS[@]}-1]' nbrMembers=$(echo "$membresPubkeys" | wc -l) lastBloc=${TXBLOCKS[-1]} isWeb=$1 -jsonFile="$SCRIPTPATH/db/daily.json" +jsonFile="$GPATH/db/daily.json" ### On source les fonctions -source $SCRIPTPATH/lib/functions.sh -source $SCRIPTPATH/lib/scanTxWallets.sh +source $GPATH/lib/functions.sh +source $GPATH/lib/scanTxWallets.sh ### Extraction des adresses Ḡ1 actives scanTxWallets diff --git a/lib/functions.sh b/lib/functions.sh index 1f8ec0e..3fa9c30 100755 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -26,10 +26,10 @@ addMembers() { web() { [ ! -d $WEBPATH/history/ ] && mkdir -p $WEBPATH/history/ [ ! -d $WEBPATH/graph/ ] && mkdir -p $WEBPATH/graph/ - [ ! -d $WEBPATH/css ] && cp -r $SCRIPTPATH/tpl/css $WEBPATH/ - [ ! -d $WEBPATH/js ] && cp -r $SCRIPTPATH/tpl/js $WEBPATH/ + [ ! -d $WEBPATH/css ] && cp -r $GPATH/tpl/css $WEBPATH/ + [ ! -d $WEBPATH/js ] && cp -r $GPATH/tpl/js $WEBPATH/ indexhtml="$WEBPATH/index.html" - cp $SCRIPTPATH/tpl/index.html $indexhtml + cp $GPATH/tpl/index.html $indexhtml datePrevious=$(date +'%y-%m-%d' -d "$day -1 day") [[ -z $(ls -l $WEBPATH/history/ | grep $datePrevious) && -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/class=\"previous\"/style=\"display:none;\" class=\"previous\"/g" $indexhtml @@ -70,7 +70,7 @@ web() { fi # Export JSON for graph - source $SCRIPTPATH/lib/transform_json.sh + source $GPATH/lib/transform_json.sh # chown www-data for nginx needs chown -R www-data:www-data $WEBPATH >/dev/null 2>&1 diff --git a/lib/scanTxWallets.sh b/lib/scanTxWallets.sh index e855e6b..7896ae9 100755 --- a/lib/scanTxWallets.sh +++ b/lib/scanTxWallets.sh @@ -3,8 +3,8 @@ scanTxWallets() { local REGEX_PUBKEYS="[a-zA-Z0-9]{42,44}" # On vérifie le cache existant et on démarre au dernier bloc en cache - if ls $SCRIPTPATH/cache/walletsUp-* > /dev/null 2>&1; then - local startFile=$(ls $SCRIPTPATH/cache/walletsUp-* | tail -n1) + if ls $GPATH/cache/walletsUp-* > /dev/null 2>&1; then + local startFile=$(ls $GPATH/cache/walletsUp-* | tail -n1) local startIter=$(echo "$startFile" | awk -F '-' '{ print $NF }') ((startIter++)) local startBloc=$(head -n1 "$startFile") @@ -91,7 +91,7 @@ scanTxWallets() { [[ -z $nbrWallets ]] && nbrWallets=0 [[ -z $UDToday ]] && UDToday=0 - local jsonTPL=$(sed s/_DATE/$blockDateLast/g $SCRIPTPATH/tpl/daily.json) + local jsonTPL=$(sed s/_DATE/$blockDateLast/g $GPATH/tpl/daily.json) jsonTPL=$(sed s/_UDTODAY/$UDToday/g <<< $jsonTPL) jsonTPL=$(sed s/_RWALLETS/$valueReceivedW/g <<< $jsonTPL) jsonTPL=$(sed s/_SWALLETS/$valueSentW/g <<< $jsonTPL) @@ -245,6 +245,6 @@ scanTxWallets() { # On supprime les doublons et les lignes vides wallets=$(echo -e "$wallets" | sort -u | awk 'NF') # On écrit les pubkeys avec transaction dans un fichier de cache pour la prochaine itération - [[ ! -d $SCRIPTPATH/cache ]] && mkdir $SCRIPTPATH/cache - echo -e "$lastBloc\n$wallets\n---\n$walletsAuj\n---\n$nbrMembersYesterday|$blockDateLast|$nbrDays" > $SCRIPTPATH/cache/walletsUp-$i + [[ ! -d $GPATH/cache ]] && mkdir $GPATH/cache + echo -e "$lastBloc\n$wallets\n---\n$walletsAuj\n---\n$nbrMembersYesterday|$blockDateLast|$nbrDays" > $GPATH/cache/walletsUp-$i } diff --git a/scripts/backup-actual.sh b/scripts/backup-actual.sh deleted file mode 100755 index abb9b72..0000000 --- a/scripts/backup-actual.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" - -cacheFile=$(ls $SCRIPTPATH/../cache/walletsUp-*) -cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }') - -#rm -f cache/bk-walletsUp-* -cp $cacheFile $SCRIPTPATH/../cache/bk-walletsUp-$cacheID -cp $SCRIPTPATH/../db/daily.json $SCRIPTPATH/../db/bk-daily.json-$cacheID - diff --git a/scripts/backup-cache.sh b/scripts/backup-cache.sh new file mode 100755 index 0000000..d248a2e --- /dev/null +++ b/scripts/backup-cache.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Récupération du chemin absolut du répertoir du script actuel +GPATH="$( cd "$(dirname "$0")" ; pwd -P )/.." + +cacheFile=$(ls $GPATH/cache/walletsUp-*) +cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }') + +#rm -f cache/bk-walletsUp-* +cp $cacheFile $GPATH/cache/bk-walletsUp-$cacheID +cp $GPATH/db/daily.json $GPATH/db/bk-daily.json-$cacheID + diff --git a/scripts/checkMissingDate.sh b/scripts/checkMissingDate.sh index f14907b..952b275 100755 --- a/scripts/checkMissingDate.sh +++ b/scripts/checkMissingDate.sh @@ -1,10 +1,19 @@ #!/bin/bash +# Récupération du chemin absolut du répertoir du script actuel +GPATH="$( cd "$(dirname "$0")" ; pwd -P )/.." +source $GPATH/.env + +lastDate=$(jq -r .[].date $GPATH/db/daily.json | tail -n1) j=0 -for i in $(jq -r .[].date db/daily.json); do +for i in $(jq -r .[].date $GPATH/db/daily.json); do ((j++)) + [[ $j == $lastDate ]] && break date=$(awk -F '-' '{ print $3"-"$2"-"$1 }' <<<"$i") - if ! [[ $(grep $(date -d "$date+1day" '+%d-%m-%y') <<<$(jq -r .[].date db/daily.json)) ]]; then - echo "$(date -d "$date+1day" '+%d-%m-%y'): $j" + if ! [[ $(grep $(date -d "$date+1day" '+%d-%m-%y') <<<$(jq -r .[].date $GPATH/db/daily.json)) ]]; then + tput cuu1 + echo -e "\nDate manquante: $(date -d "$date+1day" '+%d-%m-%y'): $j" + else + ! (( $j % 3 )) && echo -en "\rScan en cours ... $i" fi done diff --git a/scripts/compareMass.sh b/scripts/compareMass.sh index f41cfb2..5948c20 100755 --- a/scripts/compareMass.sh +++ b/scripts/compareMass.sh @@ -1,9 +1,12 @@ #!/bin/bash -source .env + +# Récupération du chemin absolut du répertoir du script actuel +GPATH="$( cd "$(dirname "$0")" ; pwd -P )/.." +source $GPATH/.env day=$1 -[[ -z $day ]] && day=$(jq .[].date db/daily.json | wc -l) -#bloc=$(grep -n . db/debug/udblocs | grep -E "^$day:" | cut -d: -f2) +[[ -z $day ]] && day=$(jq .[].date $GPATH/db/daily.json | wc -l) +#bloc=$(grep -n . $GPATH/db/debug/udblocs | grep -E "^$day:" | cut -d: -f2) bloc=$(curl -s ${DUNITER}/blockchain/with/ud | jq '.result.blocks[]' | grep -n . | grep -E "^$day:" | cut -d: -f2) chainData=$(curl -s ${DUNITER}/blockchain/block/$bloc | jq '.membersCount,.monetaryMass') chainMass=$(tail -n1 <<<"$chainData" | xargs -i echo "scale=2; {}/100" | bc) @@ -11,9 +14,9 @@ chainMbr=$(head -n1 <<<"$chainData") ((day--)) Date=$(date -d "17-03-08+${day}day" '+%d-%m-%y') -jsonMass=$(./explorer.sh mass $Date) +jsonMass=$($GPATH/explorer.sh mass $Date) -jsonMbr=$(./explorer.sh cumulate $Date | jq .nbrMembers) +jsonMbr=$($GPATH/explorer.sh cumulate $Date | jq .nbrMembers) #if [[ $jsonMbr != $chainMbr ]]; then echo "$Date - $bloc - $day diff --git a/scripts/generateDebugCache.sh b/scripts/generateDebugCache.sh new file mode 100755 index 0000000..114c698 --- /dev/null +++ b/scripts/generateDebugCache.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Récupération du chemin absolut du répertoir du script actuel +GPATH="$( cd "$(dirname "$0")" ; pwd -P )/.." +source $GPATH/.env + +echo "Génération du cache txblocs..." +curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]' > $GPATH/db/debug/txblocs +echo "Génération du cache membersPubkeys..." +curl -s ${DUNITER}/wot/members | jq -r '.results[].pubkey' > $GPATH/db/debug/membresPubkeys +echo "Génération du cache udblocs..." +curl -s ${DUNITER}/blockchain/with/ud | jq '.result.blocks[]' > $GPATH/db/debug/udblocs diff --git a/scripts/restore-bk.sh b/scripts/restore-bk.sh deleted file mode 100755 index 733ec2f..0000000 --- a/scripts/restore-bk.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" - -if [[ $1 ]]; then - cacheID=$1 - cacheFile="$SCRIPTPATH/../cache/bk-walletsUp-$cacheID" -else - cacheFile=$(ls $SCRIPTPATH/../cache/bk-walletsUp-* | tail -n1) - cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }') -fi - -[[ -f $cacheFile ]] && rm -f $SCRIPTPATH/../cache/walletsUp-* - -cp $cacheFile $SCRIPTPATH/../cache/walletsUp-$cacheID -cp $SCRIPTPATH/../db/bk-daily.json-$cacheID $SCRIPTPATH/../db/daily.json - diff --git a/scripts/restore-cache.sh b/scripts/restore-cache.sh new file mode 100755 index 0000000..c71701b --- /dev/null +++ b/scripts/restore-cache.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Récupération du chemin absolut du répertoir du script actuel +GPATH="$( cd "$(dirname "$0")" ; pwd -P )/.." + +if [[ $1 ]]; then + cacheID=$1 + cacheFile="$GPATH/cache/bk-walletsUp-$cacheID" +else + cacheFile=$(ls $GPATH/cache/bk-walletsUp-* | tail -n1) + cacheID=$(echo $cacheFile | awk -F '-' '{ print $NF }') +fi + +if [[ -f $cacheFile ]]; then + rm -f $GPATH/cache/walletsUp-* + cp $cacheFile $GPATH/cache/walletsUp-$cacheID + cp $GPATH/db/bk-daily.json-$cacheID $GPATH/db/daily.json +else + echo "Aucun cache existant au bloc $cacheID" + exit 1 +fi