forked from ReneSmeekes/storj_earnings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storj_payments.sh
executable file
·80 lines (55 loc) · 2.82 KB
/
storj_payments.sh
1
2
3
4
5
6
7
8
9
10
11
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash -e
# -u option: exits if error on unset variables
# -e option: exits if any commands exits non-zero
# This script will evaluate the amount to be paid for being a Storage Node on Storj Network and send a pushbullet notification about it.
# The script is based on storj_earnings script by ReneSmeekes.
# This script has been developed by Jeremy Fritzen. Thank you for sharing and keeping author name in it.
# Use this script with a user authorized to run Docker commands.
###############################################
############## SCRIPT PARAMETERS ##############
###############################################
# Do not change these variables
SCRIPT_DIR=$(cd $( dirname ${BASH_SOURCE[0]}) && pwd )
DATE=$(date +%Y-%m-%d-%H-%M)
##############################################
############## SCRIPT EXECUTION ##############
##############################################
earnings_recap="Gains potentiels à date pour le mois en cours"
total_earnings=0
for conf_file in `ls $SCRIPT_DIR/*.conf`
do
. $conf_file
INFODB_DIR=$SCRIPT_DIR/earnings_data/$CONTAINER_NAME/infodbcopy
HISTORY_DIR=$SCRIPT_DIR/earnings_data/$CONTAINER_NAME/history
[[ -d $INFODB_DIR ]] || mkdir -p $INFODB_DIR
[[ -d $HISTORY_DIR ]] || mkdir -p $HISTORY_DIR
[[ `docker ps --format '{{.Names}}'` == *$CONTAINER_NAME* ]] || continue
docker stop -t 300 $CONTAINER_NAME
cp $STORAGE_DIR/bandwidth.db $INFODB_DIR/
cp $STORAGE_DIR/storage_usage.db $INFODB_DIR/
cp $STORAGE_DIR/piece_spaced_used.db $INFODB_DIR/
cp $STORAGE_DIR/reputation.db $INFODB_DIR/
cp $STORAGE_DIR/heldamount.db $INFODB_DIR/
docker start $CONTAINER_NAME
python $SCRIPT_DIR/storj_earnings/earnings.py $INFODB_DIR $1 | tee $HISTORY_DIR/payment-$DATE $HISTORY_DIR/last
node_earnings=$(awk '/^TOTAL/ {print $9}' $HISTORY_DIR/payment-$DATE)
total_earnings=$(echo ${node_earnings} + ${total_earnings} | bc)
earnings_recap="${earnings_recap}\n${STORAGENODE_NAME} : $(awk '/^TOTAL/ {print $8,$9}' $HISTORY_DIR/payment-$DATE)"
done
earnings_delta=$(echo ${total_earnings} - $(cat $SCRIPT_DIR/last_earnings) | bc)
earnings_recap="${earnings_recap}\n\nTOTAL : $ ${total_earnings} (+ $ ${earnings_delta})"
if [[ $(date +%m) = $(date --date "tomorrow" +%m) ]];then
echo "${total_earnings}" > $SCRIPT_DIR/last_earnings
else
echo "0" > $SCRIPT_DIR/last_earnings
fi
if [ "$PUSHBULLET_DEVICE" -eq "" ]; then
curl -s -u $PUSHBULLET_KEY: -X POST https://api.pushbullet.com/v2/pushes \
--header 'Content-Type: application/json' \
--data-binary '{"type": "note", "title": "'"Storj earnings"'", "body": "'"${earnings_recap}"'"}'
else
curl -s -u $PUSHBULLET_KEY: -X POST https://api.pushbullet.com/v2/pushes \
--header 'Content-Type: application/json' \
--data-binary '{"type": "note", "title": "'"Storj earnings"'", "body": "'"${earnings_recap}"'", "device_iden": "'"$PUSHBULLET_DEVICE"'"}'
fi
exit 0