astroport/g1sms/sms_COUNT.sh

82 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 1.0
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
source $MY_PATH/init.sh
source $MY_PATH/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 /home/$YOU/.zen/g1sms/$PHONE/VIREMENTS.gpg ]]; then
echo "FOUND $file decrypting with Node key"
echo "${IPFSPrivKey}" | 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
else
sms_ERROR "$PHONE" "Problème de dialogue silkaj... Essayez dans qq minutes SVP..."
fi
else
echo $AMOUNTG1
fi
[[ -d /home/$YOU/.zen/g1sms/$PHONE ]] && [[ $(whoami) == "root" ]] && chown -R $YOU /home/$YOU/.zen/g1sms/$PHONE
log "END sms_COUNT.sh"
log "~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
exit