diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..52dbfc8 --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +DUNITER="http://192.168.9.54:45000" # Adresse du noeud Duniter qui sera scanné +DUNITER2="https://g1.duniter.org" # Seconde adresse par sécurité +DUNITER3="https://duniter.g1.1000i100.fr" # Troisième adresse par sécurité +ESNODE="http://g1.data.duniter.fr" # Adresse du noeud ElasticSearch qui sera scanné +WEBPATH="/var/www/g1-stats" # Dossier qui sera créé si vous choisissez l'option web pour la mise en ligne des données (nécessite une configuration apache ou nginx) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/README.md b/README.md index 238a1cb..327bb42 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,13 @@ *Ce code n'a pas été testé dans un autre environement que le miens, il est publié par simple soucis de transparence et d'audit* Utilise l'API BMA pour l'extraction des clés publiques ḡ1 membres et non membres, ainsi que l'API ElasticSearch de Cesium+ pour la récupération des soldes par soucis d'optimisation. -Les variables d'environnements se trouvent simplement en début de script. Il est nécessaire de les modifier avant l'execution. A exécuter dans un environnement Bash Debian/Ubuntu. +## Prérequis + +Copiez le fichier .env.example en .env et adaptez les variables selon votre usage. + ## Exécution `./g1-stats.sh` diff --git a/g1-stats.sh b/g1-stats.sh index bf60888..35a75b9 100755 --- a/g1-stats.sh +++ b/g1-stats.sh @@ -1,19 +1,13 @@ #!/bin/bash -### Variable ### -DUNITER="http://192.168.9.54:45000" -DUNITER2="https://g1.duniter.org" -DUNITER3="https://duniter.g1.1000i100.fr" -ESNODE="http://g1.data.duniter.fr" -webLocation="/var/www/g1-stats" -scriptLocation="/opt/g1-stats" -### +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 ### Initialisation des données ### startTime=$(date +'%H:%M') day=$(date +'%d-%m-%y') id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1) -indexhtml="$webLocation/index.html" +indexhtml="$WEBPATH/index.html" echo -e "\n############# $day à $startTime #############\n" [[ -z $(which jq) || -z $(which bc) ]] && apt update && apt install jq bc echo "Initialisation ..." @@ -28,6 +22,7 @@ nbrMembers=${#MEMBERS[@]} lastBloc=${TXBLOCKS[-1]} isWeb=$1 +exit ### Extraction des adresses Ḡ1 actives ### loopWalletUp() { @@ -100,18 +95,18 @@ pourcentWallets=$(echo "scale=1; $nbrSimpleWallets*100/$nbrTotalWallets/1" | bc) ### Renseignement de l'index web et indexation de l'historique ### web() { - [ ! -d $webLocation/history/ ] && mkdir -p $webLocation/history/ - [ ! -d $webLocation/css ] && cp -r $scriptLocation/css $webLocation/ - cp $scriptLocation/index-stats.html $indexhtml + [ ! -d $WEBPATH/history/ ] && mkdir -p $WEBPATH/history/ + [ ! -d $WEBPATH/css ] && cp -r $SCRIPTPATH/css $WEBPATH/ + cp $SCRIPTPATH/index-stats.html $indexhtml datePrevious=$(echo $day | awk -F '-' '{ print $3 "-" $2 "-" $1 }') datePrevious=$(date +'%y-%m-%d' -d "$datePrevious -1 day") datePrevious=$(echo $datePrevious | awk -F '-' '{ print $3 "-" $2 "-" $1 }') - [[ -z $(ls -l $webLocation/history/ | grep $datePrevious) && -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/class=\"previous\"/style=\"display:none;\" class=\"previous\"/g" $indexhtml + [[ -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 dateNext=$(echo $day | awk -F '-' '{ print $3 "-" $2 "-" $1 }') dateNext=$(date +'%y-%m-%d' -d "$dateNext +1 day") dateNext=$(echo $dateNext | awk -F '-' '{ print $3 "-" $2 "-" $1 }') - [[ -z $(ls -l $webLocation/history/ | grep $dateNext) && -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/class=\"next\"/style=\"display:none;\" class=\"next\"/g" $indexhtml + [[ -z $(ls -l $WEBPATH/history/ | grep $dateNext) && -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/class=\"next\"/style=\"display:none;\" class=\"next\"/g" $indexhtml sed -i "s/_nbrTotalWallets/$nbrTotalWallets/g" $indexhtml sed -i "s/_nbrSimpleWallets/$nbrSimpleWallets/g" $indexhtml @@ -133,17 +128,17 @@ web() { [[ -z $(grep '"display:none;" class="previous"' $indexhtml) ]] && sed -i "s/_datePrevious/$datePrevious/g" $indexhtml [[ -z $(grep '"display:none;" class="next"' $indexhtml) ]] && sed -i "s/_dateNext/$dateNext/g" $indexhtml - cat "$outFile" | grep . > $webLocation/wallets-g1.txt - echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > $webLocation/wallets-g1-membres.txt - echo -e "$simpleWallets" > $webLocation/wallets-g1-simple.txt + cat "$outFile" | grep . > $WEBPATH/wallets-g1.txt + echo -e "${MEMBERS[@]}" | sed 's/ /\n/g' > $WEBPATH/wallets-g1-membres.txt + echo -e "$simpleWallets" > $WEBPATH/wallets-g1-simple.txt if [[ "$startTime" == "00:00" ]]; then - cp $indexhtml $webLocation/history/index_$day.html - sed -i "s/css\/style.css/..\/css\/style.css/g" $webLocation/history/index_$day.html - sed -i "s/_dateNext/$day/g" $webLocation/history/index_$datePrevious.html - sed -i "s/style=\"display:none;\" class=\"next\"/class=\"next\"/g" $webLocation/history/index_$datePrevious.html + cp $indexhtml $WEBPATH/history/index_$day.html + sed -i "s/css\/style.css/..\/css\/style.css/g" $WEBPATH/history/index_$day.html + sed -i "s/_dateNext/$day/g" $WEBPATH/history/index_$datePrevious.html + sed -i "s/style=\"display:none;\" class=\"next\"/class=\"next\"/g" $WEBPATH/history/index_$datePrevious.html fi - chown -R www-data:www-data $webLocation + chown -R www-data:www-data $WEBPATH } ### Affichage du nombre de wallets ###