G1sms/shell/manual_BILLETS_PERIMES.sh

59 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
# Search for old G1Billets to transfer G1 & destroy them
source ./shell/init.sh
source ./shell/functions.sh
# Existence days number can be $1
if [[ "$1" ]]; then vieux="$1"; else vieux=210; fi
if [[ "$2" ]]; then dest="$2"; else dest=$MASTERPUB; fi
echo "Recherche de G1Billets plus vieux que $vieux jours."
Nbillets=$(find billets/ -daystart -mtime +$vieux -type f -name "*.pubkey" | wc -l)
echo "$Nbillets G1Billets trouvés..."
for result in $(find billets/ -daystart -mtime +$vieux -type d -name "*"); do
billetname=$(echo $result | cut -d '/' -f 2)
((Nbillets --))
if [[ $billetname && "$billetname" != "MEMBERS" ]]; then
code=$(echo $billetname | sed s/_/\ /g )
creator=$(cat $result/*.creator)
value=$(cat "$result/note.value")
unit=$(cat "$result/note.unit")
pubkey=$(cat "$result/note.pubkey")
salt=$(cat "$result/note.salt")
secret=$(cat "$result/note.secret")
virement=$(/usr/local/bin/silkaj -p duniter-g1.p2p.legal:443 balance $pubkey | grep Quantitative | cut -d '=' -f 2 | cut -d ' ' -f 2)
echo ">>> $billetname $pubkey créé par $creator, valeur $virement G1."
echo ">>> Virer à $dest $virement G1 du G1billet !! ID / Pass:"
echo $code
echo $secret $salt
echo "/usr/local/bin/silkaj tx --amount=\"$virement\" --output=\"$dest\""
if [[ "$virement" == "0.0" ]]; then
echo "G1Billet déjà vide, suppression de $result"; rm -Rf $result;
else
PAY=$(/usr/local/bin/silkaj -p duniter-g1.p2p.legal:443 tx --amount="$virement" --output="$dest" -y)
if [[ ! $(echo $PAY | grep "successfully sent") ]]; then
echo "!!!! ERREUR: $virement Something Wrong happened with $result. Moving to /tmp/$billetname"
mkdir -p /tmp/$billetname
mv $result /tmp/$billetname
else
echo $PAY
echo "OK! On supprime $result et continue avec le billet $Nbillets"
echo
rm -Rf $result
fi
fi
else
echo "MEMBER:" $result
fi
done