-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsync-chain.sh
executable file
·55 lines (51 loc) · 1.58 KB
/
sync-chain.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
#!/bin/bash
echo "Mount shared drive if needed..."
if ! df -h | grep /shared ; then
export USER_ID=`id -u`
export GROUP_ID=`id -g`
sudo mount -t vboxsf -o umask=0022,gid=$GROUP_ID,uid=$USER_ID shared ~/shared
fi
if ! which bitcoind ; then
if [ ! -d src/bitcoin-local ]; then
echo "Installing Bitcoin Core on this VM..."
git clone https://github.com/bitcoin/bitcoin.git src/bitcoin-local
pushd src/bitcoin-local
git checkout v0.17.0
# TODO: check git hash
./autogen.sh
./configure --disable-tests --disable-bench --disable-wallet --without-gui
make
echo "Sudo password required to finish install:"
sudo make install
popd
else
echo "Previous installation attempt failed?"
exit 1
fi
fi
bitcoind -daemon -prune=5000 -datadir=`pwd`/shared/bitcoin
echo "Waiting for chain to catch up..."
OPTS=-datadir=`pwd`/shared/bitcoin
set -o pipefail
while sleep 60
do
if BLOCKHEIGHT=`bitcoin-cli $OPTS getblockchaininfo | jq '.blocks'`; then
if bitcoin-cli $OPTS getblockchaininfo | jq -e '.initialblockdownload==false'; then
echo "Almost caught up, wait 15 minutes..."
sleep 900
BLOCKHEIGHT=`bitcoin-cli $OPTS getblockchaininfo | jq '.blocks'`
echo "Pruning to height $BLOCKHEIGHT..."
bitcoin-cli $OPTS pruneblockchain $BLOCKHEIGHT
bitcoin-cli $OPTS stop
while sleep 10
do # Wait for shutdown
if [ ! -f ~/.bitcoin/bitcoind.pid ] && [ ! -f ~/.bitcoin/testnet3/bitcoind.pid ]; then
break
fi
done
break
else
echo "At block $BLOCKHEIGHT..."
fi
fi
done