astroport/g1sms/sms_DESTROY.sh

77 lines
3.5 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 "${c_yellow}__SUB:sms_DESTROY.sh: START ($1=phone, $2=uid)$c_"
PHONE="$1"
MEMBERUID="$2"
TODAY=$(date '+%Y%m%d')
if [[ -f "/home/$YOU/.zen/g1sms/$PHONE/VIREMENTS" ]]; then
# CHECK IF ALL DONE.
log "__SUB:sms_DESTROY.sh: FOUND "/home/$YOU/.zen/g1sms/$PHONE/VIREMENTS" decrypting with Node key"
echo "${IPFSPrivKey}" | gpg -d -q --output "/tmp/VIREMENTS.$PHONE" --yes --pinentry-mode loopback --passphrase-fd 0 "/home/$YOU/.zen/g1sms/$PHONE/VIREMENTS.gpg"
for next in $(cat /tmp/VIREMENTS.$PHONE | cut -d ' ' -f 1); do
if [[ $next -ge $TODAY ]]; then
log "__SUB:sms_DESTROY.sh: VIREMENT $next >= $TODAY"
sms_ERROR "$PHONE" "Votre portefeuille comporte des virements non réglés... FERMETURE IMPOSSIBLE!"
exit
else
log "__SUB:sms_DESTROY.sh: VIREMENT $next ${c_green}OK$c_"
fi
done
fi
# Initialise PHONE, PIN, PUBKEY, UNIT ...
sms_INIT_ACCOUNT "$PHONE"
if [[ "$MEMBERUID" == "DON" || "$MEMBERUID" == "" || "$MEMBERUID" == "$MEMBER" ]]; then
# OK THAT GUYS KNOWS something (TODO Secure better with double authentification, with email or second phone number...)
# IF no Dest PubKey (no member) or DON, then NODE_G1PUBKEY is collecting LOVE money.
if [[ $MEMRIB == "" || "$MEMBERUID" == "DON" ]]; then MEMBER=$ADMINPSEUDO; MEMRIB=$NODE_G1PUBKEY; fi
AMOUNTG1=$(silkaj_balance $PUBKEY)
GETLIMIT=$(bc <<< "$AMOUNTG1 - $LIMIT")
duniter_server=$($MY_PATH/tools/duniter_getnode.sh)
PAY=$(silkaj -p "$duniter_server" -af --file /home/$YOU/.zen/g1sms/$PHONE/secret.dunikey tx --output "$MEMRIB" --amount "$GETLIMIT" --comment "[G1sms+] Wallet DESTROY $MEMBER $MEMBERUID" -y)
sleep 5
back=$(silkaj -p "$duniter_server" -af --file /home/$YOU/.zen/g1sms/$PHONE/secret.dunikey tx --output "$NODE_G1PUBKEY" --amount "$LIMIT" --comment "[G1sms+] Wallet DESTROY Send $LIMIT To NODE" -y)
# TODO DEBUG :: echo $PAY
if [[ "$(echo $PAY | grep 'successful')" != "" && "$PAY" != "" && "$(echo $back | grep 'successful')" != "" ]]; then
# DESTROY FILESYSTEM AND G1sms WALLET SWARM REFERENCE
if [[ "$PHONE" != "" ]]; then
# SEND SMS BEFORE DELETE FOLDER
mess="[G1sms+] $PAY
Portefeuille détruit!
Viré vers $MEMBER
$MEMRIB
Merci, à bientôt.
$ADMINPSEUDO @ $NODEUIDNA
$back"
sms_SEND "$PHONE" "$mess"
rm -Rf /home/$YOU/.zen/g1sms/$PHONE;
rm -Rf /home/$YOU/.zen/ipfs/$(echo -n $PHONE | sha256sum | cut -d ' ' -f 1)@$(echo -n $MASTERPHONE | sha256sum | cut -d ' ' -f 1)
log "__SUB:sms_DESTROY.sh: WALLET DESTROYED : $PHONE / $UIDNA / $MEMBER : ${c_green}OK$c_"
fi
else
sms_ERROR "$PHONE" "Problème de payement $PAY";
log "${c_red}__SUB:sms_DESTROY.sh: END WITH ERRORS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~$c_"
exit
fi
fi
# Remove contact from database
rm_contact $PHONE $MEMBERUID && log "${c_green}Contact has been deleted from database$c_" || log "${c_red}Contact can't be deleted database$c_"
log "${c_yellow}__SUB:sms_DESTROY.sh: END ~~~~~~~~~~~~~~~~~~~~~~~~~~~~$c_"
exit