2019-06-15 23:02:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# mynode_quicksync.sh
|
|
|
|
# Downloads blockchain up through Feb 2019 for MUCH faster syncing
|
|
|
|
# Seeds afterwards if not disabled
|
|
|
|
# Dependencies: Must run after mynode script so HDD is mounted
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -x
|
|
|
|
|
|
|
|
source /usr/share/mynode/mynode_config.sh
|
|
|
|
|
|
|
|
mkdir -p $QUICKSYNC_DIR
|
|
|
|
mkdir -p $QUICKSYNC_CONFIG_DIR
|
|
|
|
|
|
|
|
cp -f /usr/share/quicksync/settings.json $QUICKSYNC_CONFIG_DIR/settings.json
|
|
|
|
|
2019-08-01 00:47:04 +00:00
|
|
|
# Check if quicksync was disabled
|
|
|
|
while [ -f $QUICKSYNC_DIR/.quicksync_disabled || -f /home/bitcoin/.mynode/.quicksync_disabled ]; do
|
|
|
|
sleep 1d
|
|
|
|
done
|
|
|
|
|
2019-06-15 23:02:44 +00:00
|
|
|
# Make sure folder exists
|
|
|
|
mkdir -p $QUICKSYNC_DIR
|
|
|
|
if [ ! -f $QUICKSYNC_DIR/.quicksync_download_complete ]; then
|
|
|
|
echo "quicksync_download" > $MYNODE_DIR/.mynode_status
|
|
|
|
fi
|
|
|
|
echo "Starting quicksync..."
|
|
|
|
|
|
|
|
# Download finished, but failed during copy, recopy
|
|
|
|
if [ ! -f $QUICKSYNC_DIR/.quicksync_complete ] && [ -f $QUICKSYNC_DIR/.quicksync_download_complete ]; then
|
|
|
|
echo "Quicksync download complete, needs copy"
|
|
|
|
/usr/bin/mynode_quicksync_complete.sh
|
|
|
|
fi
|
|
|
|
# Check if quicksync was completed
|
|
|
|
if [ -f $QUICKSYNC_DIR/.quicksync_complete ]; then
|
|
|
|
echo "stable" > $MYNODE_DIR/.mynode_status
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Download torrent
|
|
|
|
rm -rf $QUICKSYNC_DIR/blockchain_temp.torrent
|
|
|
|
wget -O $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_TORRENT_URL
|
2019-06-21 00:40:19 +00:00
|
|
|
sync
|
|
|
|
sleep 1
|
2019-06-15 23:02:44 +00:00
|
|
|
|
|
|
|
if [ ! -f $QUICKSYNC_DIR/blockchain_temp.torrent ]; then
|
|
|
|
echo "Torrent download failed...."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if new torrent is updated
|
|
|
|
if [ ! -f $QUICKSYNC_DIR/blockchain.torrent ]; then
|
|
|
|
cp $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_DIR/blockchain.torrent
|
|
|
|
else
|
|
|
|
# Run commands as long as torrents are different (last command updates torrent file)
|
|
|
|
COMPLETED=0
|
|
|
|
if [ -f $QUICKSYNC_DIR/.quicksync_complete ]; then
|
|
|
|
COMPLETED=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
NEW_TORRENT=0
|
|
|
|
cmp --silent $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_DIR/blockchain.torrent || NEW_TORRENT=1
|
|
|
|
if [ $NEW_TORRENT -eq 1 ]; then
|
|
|
|
# Delete old QuickSync data+config and start new one
|
|
|
|
rm -f $QUICKSYNC_DIR/*
|
|
|
|
rm -rf $QUICKSYNC_CONFIG_DIR
|
|
|
|
mkdir -p $QUICKSYNC_CONFIG_DIR
|
|
|
|
cp -f /usr/share/quicksync/settings.json $QUICKSYNC_CONFIG_DIR/settings.json
|
|
|
|
cp $QUICKSYNC_DIR/blockchain_temp.torrent $QUICKSYNC_DIR/blockchain.torrent
|
|
|
|
sync
|
|
|
|
|
|
|
|
# If download had been completed
|
|
|
|
if [ $COMPLETED -eq 1 ]; then
|
|
|
|
touch $QUICKSYNC_DIR/.quicksync_download_complete
|
|
|
|
touch $QUICKSYNC_DIR/.quicksync_complete
|
|
|
|
|
|
|
|
# Since this will start/continue a background download, wait so everything else boots smoothly
|
|
|
|
sleep 5m
|
|
|
|
/usr/bin/wait_on_bitcoin.sh
|
|
|
|
sleep 10m
|
|
|
|
fi
|
|
|
|
sync
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Start torrent
|
|
|
|
echo "Running torrent..."
|
|
|
|
transmission-cli \
|
|
|
|
--download-dir $QUICKSYNC_DIR \
|
2019-07-13 18:26:00 +00:00
|
|
|
--config-dir $QUICKSYNC_CONFIG_DIR \
|
2019-06-15 23:02:44 +00:00
|
|
|
--finish=/usr/bin/mynode_quicksync_complete.sh \
|
|
|
|
$QUICKSYNC_DIR/blockchain.torrent
|