sms_COUNT.sh 1.13 KB
Newer Older
zicmama's avatar
zicmama committed
1 2 3 4
#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
5
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
zicmama's avatar
zicmama committed
6 7 8 9 10
################################################################################
source /root/G1SMS/shell/init.sh
source /root/G1SMS/shell/functions.sh
log "X sms_COUNT.sh ($1=phone $2=NOSMS)"
PHONE=$1
11

zicmama's avatar
zicmama committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
# Initialise PHONE, PIN, PUBKEY, UNIT, HIST
sms_INIT_ACCOUNT "$PHONE" "NOSMS"
if [[ $UNKNOWN == "unknown" ]]; then
	sms_ERROR "$PHONE" "Porte-monnaie inconnu. Envoyez N pour le créer."
	exit
fi

# Check account amount
AMOUNTG1=$(./silkaj/silkaj amount --auth-scrypt -salt="$PHONE" -password="$PIN")
AMOUNTDU=$(bc <<< "scale=2; $AMOUNTG1 / $DUFACTOR")
AMOUNTLOVE=$(bc <<< "$AMOUNTG1 * 100 / $DUFACTOR")

case "$UNIT" in
	G1)
		AMOUNT=$AMOUNTG1
		;;
	DU)
		AMOUNT=$AMOUNTDU
		;;
	*)
		AMOUNT=$AMOUNTLOVE
		;;
esac

# LOG
log "Solde = $AMOUNT ($UNIT)"

# If script control only run: NOSMS
if [ "$2" != "NOSMS" ]; then
	mess="[G1SMS]
42 43
Compte: $PHONE
Solde: $AMOUNT $UNIT
zicmama's avatar
zicmama committed
44 45 46 47 48 49 50 51
"
	# Send response SMS
	sms_SEND "$PHONE" "$mess"
else
	echo $AMOUNTG1
fi

exit