Improve scripts; Change GPATH name; Add generateDebugCache.sh

This commit is contained in:
poka 2020-09-24 21:54:55 +02:00
parent 80a468b537
commit bfc23f3e52
11 changed files with 87 additions and 54 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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

12
scripts/backup-cache.sh Executable file
View File

@ -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

View File

@ -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

View File

@ -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

12
scripts/generateDebugCache.sh Executable file
View File

@ -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

View File

@ -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

21
scripts/restore-cache.sh Executable file
View File

@ -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