G1sms/shell/sms_DESTROY.sh

79 lines
3.5 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 "${c_yellow}__SUB:sms_DESTROY.sh: START ($1=phone, $2=uid)$c_"
PHONE="$1"
MEMBERUID="$2"
TODAY=$(date '+%Y%m%d')
if [[ -f "./wallets/$PHONE/VIREMENTS" ]]; then
# CHECK IF ALL DONE.
log "__SUB:sms_DESTROY.sh: FOUND "./wallets/$PHONE/VIREMENTS" decrypting with Node key"
echo "${GPGPASS}" | gpg -d -q --output "/tmp/VIREMENTS.$PHONE" --yes --pinentry-mode loopback --passphrase-fd 0 "./wallets/$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/silkaj amount "$PUBKEY")
GETLIMIT=$(bc <<< "$AMOUNTG1 - $LIMIT")
PAY=$(./silkaj/silkaj transaction --auth-scrypt -salt="$PHONE" -password="$PIN" --amount="$GETLIMIT" --output="$MEMRIB" --comment="[G1sms+] Wallet DESTROY $MEMBER $MEMBERUID" -y)
sleep 5
back=$(./silkaj/silkaj transaction --auth-scrypt -salt="$PHONE" -password="$PIN" --amount="$LIMIT" --output="$NODEPUB" --comment="[G1sms+] Wallet DESTROY Send $LIMIT To NODE" -y)
if [[ "$(echo $PAY | cut -d '|' -f 1)" != "KO" && "$PAY" != "" && "$(echo $back | cut -d '|' -f 1)" != "KO" ]]; 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 ./wallets/$PHONE;
rm -Rf ./wallets_swarm/$PHONE;
cents=$(echo $(bc -l <<< "scale=0; $GETLIMIT * 100") | cut -d '.' -f 1)
move_g1cents "$PHONE" "$MEMRIB" "$cents"
cents=$(echo $(bc -l <<< "scale=0; $LIMIT * 100") | cut -d '.' -f 1)
move_g1cents "$PHONE" "$NODEPUB" "$cents"
I=$(ipfs_node_wallets_add)
log "__SUB:sms_DESTROY.sh: WALLET DESTROYED : $PHONE / $UIDNA / $MEMBER : ${c_green}OK$c_"
fi
else
new=$(./shell/checknodes.sh "BAN")
sms_ERROR "$PHONE" "Problème de payement avec silkaj (changement de serveur $new): $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