-
Notifications
You must be signed in to change notification settings - Fork 2
/
kickstart
executable file
·93 lines (81 loc) · 3.84 KB
/
kickstart
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
81
82
83
84
85
86
87
88
89
90
91
92
#!/bin/bash
# Iguana Coin Synchronization Tool
# Usage: ./kickstart COIN
# Manual operator attended version
RTNUMBER=""
HEIGHT=""
SUPPORTED=(BTC BTCD DOGE LTC DGB GMC SYS MZC UNO ZET BTM CARB ANC FRK)
RESULTS=kickstart.log
COINLC=$(echo "$1" | tr '[:upper:]' '[:lower:]')
CURPROC=$(echo "../agents/iguana coins/gen$COINLC.json")
CURPID=$(pidof $CURPROC)
COMMIT=$(git rev-parse HEAD)
wget https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -O jq; chmod +x jq
if [[ " ${SUPPORTED[@]} " =~ " $1 " ]]; then
ps ax | grep -q "[i]guana coins/gen$COINLC.json" && { echo "Synchronization for $1 was already running! Please stop it and try again if you want to proceed"; exit 1; }
echo Starting $1 Synchronization.
else
echo ">>> Argument error. Please run ./kickstart COIN"
echo "Currently supported coins: BTC, BTCD, DOGE, LTC, DGB, GMC, SYS, MZC, UNO, ZET, BTM, CARB, ANC, FRK"
exit 1
fi
echo WARNING: This will remove any existing DB and tmp sub-folders for $1 under the current working directory.
read -p " >>> Start synchronization from scratch ? (y/n) " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo; exit 1
fi
if [[ "${COINLC}" == "btc" ]]; then
cat coins/genbtc.json | ./jq '.minconfirms=3' > coins/genbtc.kick.json
MINCONFIRMS=3
else
cat coins/gen$COINLC.json | ./jq '.minconfirms=10' > coins/gen$COINLC.kick.json
MINCONFIRMS=10
fi
echo
rm -rf tmp/$1 DB/$1 DB/purgeable/$1 >/dev/null
rm $1.sync.log >/dev/null
echo "Running commit $COMMIT"
echo "Running parameters:"
cat coins/gen$COINLC.kick.json
echo
../agents/iguana coins/gen$COINLC.kick.json > $1.sync.log 2>&1 &
SECONDS=0
STARTTIME=$(date +%T)
echo " >>> $1 Monitored Synchronization started at $STARTTIME." >> debug.log
echo " >>> Synchronization started at $STARTTIME."
echo " >>> You can follow this synchronization log at $1.sync.log. $1 status lines will also appear in debug.log"
echo " >>> Monitoring the log. Leave this process open to get a report in $RESULTS when $1 is fully synchronized."
echo "$1 synchronization started at $STARTTIME" >> $RESULTS
while sleep .5; do
ENDTIME=$(date +%T)
ps ax | grep "[a]gents/iguana coins/gen$COINLC.kick.json" >/dev/null || { echo -e "\n$1 Synchronization process exited before finishing. Check $1.sync.log for details.\n"; echo "$1 synchronization finished prematurely at $ENDTIME" >> $RESULTS; echo "--------------------------------------------------------" >> $RESULTS; exit 1; }
LASTLINE=$(tac debug.log |egrep -m 1 .)
printf 'Time elapsed: %s minutes and %02d%s seconds \r' "$(($SECONDS / 60))" "$((SECONDS % 60))"
if [[ "${LASTLINE}" == "${1}.RT"* ]]; then
printf '\n Last %s status line: %s \r\033[2A' "$1" "$LASTLINE"
else
LASTLINE="$1.RT0 u.0+c.0 b.0 v.0 (0+0/1 1st.0).s0 to 1 N[1] h.0 r.0 c.0"
fi
RTNUMBERPR=${LASTLINE% u.*}
RTNUMBER=${RTNUMBERPR##*RT}
HEIGHTPR=${LASTLINE% r.*}
HEIGHT=${HEIGHTPR##*] h.}
if [[ "$((RTNUMBER + MINCONFIRMS - 1))" == "$((HEIGHT))" ]]; then
echo " $1 synchronization finished at $ENDTIME" | tee -a $RESULTS
echo "Total time: $((SECONDS / 3600)) hours, $((($SECONDS % 3600) / 60)) minutes and $((SECONDS % 60)) seconds" | tee -a $RESULTS
echo "Last status line: $LASTLINE" | tee -a $RESULTS
COMMIT=$(git rev-parse HEAD)
echo "Running commit: $COMMIT" | tee -a $RESULTS
echo "--------------------------------------------------------" | tee -a $RESULTS
echo; read -p " >>> Stop $1 Iguana process and remove generated data ? (y/n) " -n 1 -r
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Leaving $1 Iguana process running and preserving $1 DB and tmp data."; exit 0;
else
echo "Stopping $1 Iguana process and removing $1 DB and tmp data."
kill $CURPID; sleep 1
rm -rf tmp/$1 DB/$1 DB/purgeable/$1 >/dev/null
exit 0;
fi
fi
done
exit $?