G1sms/shell/sms_COUNT.sh

78 lines
2.1 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/)
################################################################################
source ./shell/init.sh
source ./shell/functions.sh
log "X sms_COUNT.sh ($1=phone $2=NOSMS)"
PHONE=$1
TODAY=$(date '+%Y%m%d')
# Initialise PHONE, PIN, PUBKEY, UNIT
sms_INIT_ACCOUNT "$PHONE" "NOSMS"
if [[ $UNKNOWN == "unknown" && "$PHONE" != "" ]]; then
sms_ERROR "$PHONE" "Porte-monnaie inconnu. Envoyez N (suivi de votre Pseudo membre) pour le créer."
exit
fi
# Check account amount
declare -a accounting
accounting=($(check_account))
log "$(declare -p accounting)"
AMOUNTG1=${accounting[0]}
AMOUNT=${accounting[1]}
UNIT=${accounting[2]}
# SEARCH FOR VIREMENT
if [[ -f ./wallets/$PHONE/VIREMENTS.gpg ]]; then
echo "FOUND $file decrypting with Node key"
echo "${GPGPASS}" | gpg -d -q --output "/tmp/VIREMENTS.$PHONE" --yes --pinentry-mode loopback --passphrase-fd 0 "$file"
declare -a LIST
num=0
cat /tmp/VIREMENTS.$PHONE | while read LIST; do
if [[ ${LIST[0]} -gt $TODAY ]]; then
((num++))
todo="$todo
${LIST[0]}: ${LIST[3]} G1 vers ${LIST[5]}"
fi
done
rm "/tmp/VIREMENTS.$PHONE"
fi
# LOG
log "Solde = $AMOUNTG1 ($UNIT)"
# If script control only run: NOSMS
if [ "$2" != "NOSMS" ]; then
if [[ "$AMOUNT" != "" ]]; then
mess="[G1sms+]
ID: $UIDNA
$AMOUNT $UNIT ($AMOUNTG1 G1)
=> $MEMBER
$MEMRIB
https://cesium.app"
# Send response SMS
sms_SEND "$PHONE" "$mess"
sms_SEND "$PHONE" "$PUBKEY"
# CHECK NEXT VIREMENTS
if [[ $num -gt 0 ]]; then
sms_SEND "$PHONE" "Reste $num Virements récurrents
$(echo $todo | head -n 2)
...
$(echo $todo | tail -n 1)";
fi
log_history $PHONE "SOLDE, $AMOUNTG1"
else
sms_ERROR "$PHONE" "Problème de dialogue silkaj, Serveur $NEWDUNITER... Essayez dans 1 minute SVP..."
fi
else
echo $AMOUNTG1
fi
log "END sms_COUNT.sh"
log "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
exit