2019-10-29 04:55:50 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-10-30 14:02:43 +01:00
|
|
|
startTime=$(date +'%T')
|
|
|
|
day=$(date +'%d-%m-%y')
|
|
|
|
id=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
|
|
|
de=$(cat /dev/urandom | tr -dc '0-9' | fold -w 1 | head -n 1)
|
2019-10-29 04:55:50 +01:00
|
|
|
### Variable ###
|
2019-10-30 14:02:43 +01:00
|
|
|
|
|
|
|
if [ $de -le 3 ]; then
|
|
|
|
DUNITER="http://192.168.9.54:45000"
|
|
|
|
elif [ $de -le 6 ]; then
|
|
|
|
DUNITER="https://g1.duniter.org"
|
|
|
|
else
|
|
|
|
DUNITER="https://duniter.g1.1000i100.fr"
|
|
|
|
fi
|
|
|
|
|
|
|
|
indexhtml="/var/www/g1-stats/index-$day-$startTime-$id.html"
|
2019-10-29 04:55:50 +01:00
|
|
|
###
|
|
|
|
|
2019-10-30 14:02:43 +01:00
|
|
|
echo "######"
|
2019-10-29 05:29:10 +01:00
|
|
|
[[ -z $(which jq) || -z $(which bc) ]] && apt update && apt install jq bc
|
2019-10-29 04:55:50 +01:00
|
|
|
echo "Initialisation ..."
|
2019-10-30 14:02:43 +01:00
|
|
|
outFile="/tmp/g1-stats-$day-$startTime_$id"
|
2019-10-29 04:55:50 +01:00
|
|
|
TXBLOCKS=($(curl -s ${DUNITER}/blockchain/with/tx | jq '.result.blocks[]' | awk '{printf $1" "}'))
|
|
|
|
MEMBERS=($(curl -s ${DUNITER}/wot/members | jq '.results[].pubkey' | tr -d '"'))
|
|
|
|
nbrMembers=${#MEMBERS[@]}
|
|
|
|
lastBloc=${TXBLOCKS[-1]}
|
|
|
|
|
|
|
|
for i in ${TXBLOCKS[*]}; do
|
|
|
|
|
|
|
|
[[ -z ${TXBLOCKS[$i]} ]] && break
|
|
|
|
WALLETS=$(curl -s ${DUNITER}/blockchain/block/${TXBLOCKS[$i]} | jq '.transactions[].outputs[]' | tr -d '"' | awk -F '(' '{ print $2 }' | tr -d ')')
|
|
|
|
bloc=${TXBLOCKS[$i]}
|
|
|
|
wallets+=$(echo -e "$WALLETS \n" | sed 's/ /\\n/g')
|
|
|
|
|
|
|
|
progress=$(echo "scale=1; $bloc*100/$lastBloc/1" | bc)
|
2019-10-30 14:02:43 +01:00
|
|
|
sleep 1
|
2019-10-29 04:55:50 +01:00
|
|
|
|
2019-10-30 14:02:43 +01:00
|
|
|
if [[ $1 != "web" ]]; then
|
|
|
|
clear
|
|
|
|
echo "Heure de début: $startTime"
|
|
|
|
echo
|
|
|
|
echo "Scan en cours: $progress% - $bloc/$lastBloc"
|
|
|
|
fi
|
2019-10-29 04:55:50 +01:00
|
|
|
|
|
|
|
((iter++))
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
echo -e "$(echo -e "$wallets" | sort -u)" > $outFile
|
|
|
|
|
|
|
|
iter=0
|
|
|
|
for i in ${MEMBERS[*]}; do
|
|
|
|
|
|
|
|
progress=$(echo "scale=0; $iter*100/$nbrMembers/1" | bc)
|
|
|
|
if [[ $progress =~ ^(0|10|20|30|40|50|60|70|80|90|99)$ ]]; then
|
|
|
|
[[ $progress == 99 ]] && progress=100
|
2019-10-30 14:02:43 +01:00
|
|
|
if [[ $1 != "web" ]]; then
|
|
|
|
clear
|
|
|
|
echo "Heure de début: $startTime"
|
|
|
|
echo
|
|
|
|
echo "Scan en cours: 100% - $bloc/$lastBloc"
|
|
|
|
echo "Ajouts des comptes membres ... $progress%"
|
|
|
|
fi
|
2019-10-29 04:55:50 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $(grep "$i" $outFile) ]]; then
|
|
|
|
echo -e "$i" >> $outFile
|
|
|
|
fi
|
|
|
|
|
|
|
|
((iter++))
|
|
|
|
done
|
|
|
|
|
|
|
|
nbrTotalWallets=$(cat $outFile | wc -l)
|
|
|
|
nbrSimpleWallets=$(echo "$nbrTotalWallets-$nbrMembers" | bc)
|
|
|
|
pourcentMbrs=$(echo "scale=1; $nbrMembers*100/$nbrTotalWallets/1" | bc)
|
|
|
|
pourcentWallets=$(echo "scale=1; $nbrSimpleWallets*100/$nbrTotalWallets/1" | bc)
|
|
|
|
|
2019-10-29 05:18:10 +01:00
|
|
|
web() {
|
2019-10-30 14:02:43 +01:00
|
|
|
cp /opt/g1-stats/stats.html $indexhtml
|
2019-10-29 05:18:10 +01:00
|
|
|
sed -i "s/_nbrTotalWallets/$nbrTotalWallets/g" $indexhtml
|
|
|
|
sed -i "s/_nbrSimpleWallets/$nbrSimpleWallets/g" $indexhtml
|
2019-10-30 14:02:43 +01:00
|
|
|
sed -i "s/_nbrMembers/$nbrMembers/g" $indexhtml
|
2019-10-29 05:18:10 +01:00
|
|
|
sed -i "s/_pourcentMbrs/$pourcentMbrs/g" $indexhtml
|
2019-10-30 14:02:43 +01:00
|
|
|
sed -i "s/_pourcentWallets/$pourcentWallets/g" $indexhtml
|
|
|
|
sed -i "s/_node/"$DUNITER"/g" $indexhtml
|
|
|
|
sed -i "s/_heure/$startTime/g" $indexhtml
|
2019-10-29 05:18:10 +01:00
|
|
|
|
|
|
|
chown www-data:www-data $indexhtml 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
[[ $1 == "web" ]] && web
|
|
|
|
|
2019-10-29 04:55:50 +01:00
|
|
|
echo -e "\n ---"
|
2019-10-30 14:02:43 +01:00
|
|
|
echo "Noeud: $DUNITER"
|
2019-10-29 04:55:50 +01:00
|
|
|
echo "Nombre total de wallet: $nbrTotalWallets"
|
|
|
|
echo "Nombre de membres: $nbrMembers (${pourcentMbrs}%)"
|
|
|
|
echo "Nombre de simple portefeuille: $nbrSimpleWallets (${pourcentWallets}%)"
|
2019-10-30 14:02:43 +01:00
|
|
|
echo " ---"
|
2019-10-29 04:55:50 +01:00
|
|
|
|
|
|
|
rm $outFile
|
|
|
|
echo "Heure de fin: $(date +'%T')"
|