You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

94 lines
3.9 KiB

#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
# Effectue les payements récurrents et enlève le vérrou (DESTROY)
# TAKES CARE OF DOING RECURRENT PAYEMENTS EVERY DAY FOR ITS $PHONE G1Wallets
# TODO: Add SMS Alert if G1sms Wallet is low...
source ./shell/init.sh
source ./shell/functions.sh
log "__SUB:cron_VIR.reccurent.sh: START"
rm -f /tmp/VIR*
echo "" > /tmp/VIR
TODAY=$(date '+%Y%m%d')
log "__SUB:cron_VIR.reccurent.sh: Searching payements to do for $TODAY"
for file in ./wallets/*/VIREMENTS.gpg ; do
if [[ -f $file ]]; then
log "__SUB:cron_VIR.reccurent.sh: FOUND $file decrypting with Node key"
echo "${GPGPASS}" | gpg -d -q --output "/tmp/VIREMENTS" --yes --pinentry-mode loopback --passphrase-fd 0 "$file"
cat /tmp/VIREMENTS | sort >> /tmp/VIR$TODAY
else
continue
fi
done
############################################
if [[ -f /tmp/VIR$TODAY ]]; then
############################################
while read line
do virement=(${line});
if [[ ${virement[0]} == ${TODAY} ]]; then
log "__SUB:cron_VIR.reccurent.sh: PAYING !!! ${line}"
PHONE=${virement[2]}
VIR=${virement[3]}
DESTRIB=${virement[4]}
DESTUID=${virement[5]}
REF=${virement[6]}
NB=${virement[7]}
sms_INIT_ACCOUNT "$PHONE" "NOSMS"
# echo -salt="$PHONE" -password="$PIN" --amount="$VIR" --output="$DESTRIB" --comment="[G1sms+] VIR $REF / $NB"
PAY=$(./silkaj/silkaj transaction --auth-scrypt -salt="$PHONE" -password="$PIN" --amount="$VIR" --output="$DESTRIB" --comment="[G1sms+] VIR $REF / $NB" -y)
if [[ "$(echo $PAY | cut -d '|' -f 1)" == "KO" ]]; then
new=$(./shell/checknodes.sh "BAN")
sms_ERROR "$PHONE" "Il est survenu un problème avec votre virement. Retour silkaj: $PAY ... $new";
else
new=$(./shell/checknodes.sh)
sms_SEND "$PHONE" "$TODAY Virement automatique $REF vers $DESTUID : $PAY (Reste $NB)"
cents=$(echo $(bc -l <<< "scale=0; $VIR * 100") | cut -d '.' -f 1)
move_g1cents "$PHONE" "$DESTRIB" "$cents"
fi
log "__SUB:cron_VIR.reccurent.sh: $TODAY VIR DONE.... Rotation Silkaj : $new "
else
virement=""
echo "$(declare -p virement)"
fi
done < /tmp/VIR$TODAY
# CHECK FOR LAST VIREMENTS AND CLEAN IT?
for virfile in "./wallets/*/VIREMENTS.gpg"; do
phone=$(echo $virfile | cut -d '/' -f 3)
if [[ "$phone" == "*" ]]; then exit; fi
echo "${GPGPASS}" | gpg -d -q --output "/tmp/$phone.VIREMENTS" --yes --pinentry-mode loopback --passphrase-fd 0 "./wallets/$phone/VIREMENTS.gpg"
nv=0; tot=0;
while read ligne
do virs=(${ligne});
if [[ ${virs[0]} -gt ${TODAY} ]]; then
# Some other payments are to be done in the future
((nv++))
tot=$((tot + {virs[3]}))
fi
done < /tmp/$phone.VIREMENTS
# NO FUTURE PAYMENTS. REMOVE VIREMENTS files
if [[ $nv -eq 0 ]]; then
log "__SUB:cron_VIR.reccurent.sh: Plus AUCUN payement récurrent !!"
sms_SEND "$phone" "Plus AUCUN payement récurrent"
rm -f "./wallets/$phone/VIREMENTS.gpg"
rm -f "./wallets/$phone/VIREMENTS"
I=$(ipfs_node_wallets_add)
else
log "__SUB:cron_VIR.reccurent.sh: Encore $nv payements récurrents à réaliser pour $tot G1"
# TODO Verify Wallet Amount is not too low... To send alert (sms, email)
# cts=$(echo $(bc -l <<< "scale=0; $tot * 100") | cut -d '.' -f 1)
sms_SEND "$phone" "Encore $nv payements récurrents à réaliser pour $tot G1. Approvisionnez votre solde en conséqence..."
fi
rm -f "/tmp/$phone.VIREMENTS"
done
############################################
fi
############################################