-
Notifications
You must be signed in to change notification settings - Fork 0
/
ord-index.sh
executable file
·140 lines (96 loc) · 3 KB
/
ord-index.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if [ ! -f "$SCRIPT_DIR/.ord-index-config" ]
then
echo "No config file found.."
exit
fi
source "$SCRIPT_DIR/.ord-index-config"
RUNNING=$(ps -fu $UID | grep "ord" | grep "data-dir" | grep -v "$SNAPSHOT_DATA_DIR" | grep "index-sats index")
if [ ! -z "${RUNNING}" ]; then
echo "Still running.."
exit
fi
if test -f "$ALT_DATA_DIR$NETWORK/lock"; then
echo "Process not finished.."
exit
fi
mkdir -p $ALT_DATA_DIR$NETWORK
mkdir -p $SNAPSHOT_DATA_DIR$NETWORK
# LOCK
touch "$ALT_DATA_DIR$NETWORK/lock"
# == SETUP
if [ ! -f $ALT_DATA_DIR$NETWORK"/index.redb" ]
then
rsync -a $DEFAULT_DATA_DIR$NETWORK"/index.redb" $ALT_DATA_DIR$NETWORK"/index.redb"
fi
if [ ! -f $SNAPSHOT_DATA_DIR$NETWORK"/index.redb" ]
then
rsync -a $DEFAULT_DATA_DIR$NETWORK"/index.redb" $SNAPSHOT_DATA_DIR$NETWORK"/index.redb"
fi
# ==
mkdir -p $ALT_DUP_DATA_DIR$NETWORK
if [ ! -f $ALT_DUP_DATA_DIR$NETWORK"/index.redb" ]
then
rsync -a $DEFAULT_DATA_DIR$NETWORK"/index.redb" $ALT_DUP_DATA_DIR$NETWORK"/index.redb"
fi
# ==
BITCOIN_CLI_OPTIONS=()
ORD_CLI_OPTIONS=()
if [ ! -z "${NETWORK}" ]; then
if [ $NETWORK = "regtest" ]; then
BITCOIN_CLI_OPTIONS=( --regtest )
ORD_CLI_OPTIONS=( -r )
elif [ $NETWORK = "testnet3" ]; then
BITCOIN_CLI_OPTIONS=( --testnet )
ORD_CLI_OPTIONS=( -t )
else
echo "Invalid network"
exit
fi
fi
# SETUP END ==
HEIGHT=$(bitcoin-cli "${BITCOIN_CLI_OPTIONS[@]}" getblockcount)
echo "HEIGHT is $HEIGHT"
# HARDLINK SWITCHER - 2
rm $DEFAULT_DATA_DIR$NETWORK"/index.redb"
ln $ALT_DUP_DATA_DIR$NETWORK"/index.redb" $DEFAULT_DATA_DIR$NETWORK"/index.redb"
sleep 1
echo "Begin indexing.."
echo "indexing" > $ALT_DATA_DIR$NETWORK"/height"
REORG=$(ord@cake "${ORD_CLI_OPTIONS[@]}" --data-dir=$ALT_DATA_DIR --index-sats index 2>&1 | grep -P 'reorg')
echo "$HEIGHT" > $ALT_DATA_DIR$NETWORK"/height"
echo "REORG is $REORG"
if [ -z "$REORG" ]
then
sleep 1
# HARDLINK SWITCHER - 1
rm $DEFAULT_DATA_DIR$NETWORK"/index.redb"
ln $ALT_DATA_DIR$NETWORK"/index.redb" $DEFAULT_DATA_DIR$NETWORK"/index.redb"
sleep 1
RUNNING=$(ps -fu $UID | grep "ord" | grep "data-dir" | grep -v "$SNAPSHOT_DATA_DIR" | grep "index-sats index")
if [ ! -z "${RUNNING}" ]; then
echo "Still running.."
# UNLOCK
rm "$ALT_DATA_DIR$NETWORK/lock"
exit
fi
echo "indexing" > $ALT_DUP_DATA_DIR$NETWORK"/height"
REORG=$(ord@cake "${ORD_CLI_OPTIONS[@]}" --data-dir=$ALT_DUP_DATA_DIR --index-sats index 2>&1 | grep -P 'reorg')
echo "$HEIGHT" > $ALT_DUP_DATA_DIR$NETWORK"/height"
sleep 1
# HARDLINK SWITCHER - 2
rm $DEFAULT_DATA_DIR$NETWORK"/index.redb"
ln $ALT_DUP_DATA_DIR$NETWORK"/index.redb" $DEFAULT_DATA_DIR$NETWORK"/index.redb"
sleep 1
# UNLOCK
rm "$ALT_DATA_DIR$NETWORK/lock"
if test -f "$ALT_DATA_DIR$NETWORK/reorg"; then
rm "$ALT_DATA_DIR$NETWORK/reorg"
fi
echo "Done.."
else
echo "PENDING: Perform self reorg recovery"
touch "$ALT_DATA_DIR$NETWORK/reorg"
echo "Has reorg.."
fi