2019-01-30 09:48:25 +00:00
#!/bin/bash
## get basic info
2019-02-13 02:33:27 +01:00
source /home/admin/raspiblitz.info
2019-01-30 09:48:25 +00:00
# get local ip
2020-10-14 18:52:31 +02:00
localip = $( ip addr | grep 'state UP' -A2 | egrep -v 'docker0|veth' | grep 'eth0\|wlan0\|enp0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/' )
2019-01-30 09:48:25 +00:00
2019-03-15 18:12:22 +01:00
# Basic Options
2020-06-17 12:42:06 +02:00
OPTIONS = ( WINDOWS "Windows" \
MACOS "Apple MacOSX" \
LINUX "Linux" \
2020-06-17 15:13:00 +02:00
BLITZ "RaspiBlitz"
2019-03-15 18:12:22 +01:00
)
2020-06-17 13:14:02 +02:00
CHOICE = $( dialog --clear --title " Copy Blockchain from another laptop/node over LAN " --menu "\nWhich system is running on the other laptop/node you want to copy the blockchain from?\n " 14 60 9 " ${ OPTIONS [@] } " 2>& 1 >/dev/tty)
2019-03-15 18:12:22 +01:00
clear
case $CHOICE in
2020-06-17 12:42:06 +02:00
MACOS) echo "Steve" ; ;
2020-06-17 14:03:29 +02:00
LINUX) echo "Linus" ; ;
2019-03-15 18:12:22 +01:00
WINDOWS) echo "Bill" ; ;
2020-06-17 12:42:06 +02:00
BLITZ) echo "Satoshi" ; ;
2019-03-15 18:12:22 +01:00
*) exit 1; ;
esac
2019-02-15 12:01:08 +01:00
# additional prep if this is used to replace corrupted blockchain
if [ " ${ setupStep } " = "100" ] ; then
# make sure services are not running
2020-05-24 16:46:40 +02:00
echo "stopping services ..."
2020-10-13 22:25:35 +02:00
sudo systemctl stop background
2019-02-15 12:01:08 +01:00
sudo systemctl stop lnd
2019-02-16 00:19:39 +01:00
sudo systemctl stop bitcoind
2019-02-16 01:17:39 +01:00
sudo cp -f /mnt/hdd/bitcoin/bitcoin.conf /home/admin/assets/bitcoin.conf
2020-10-13 22:25:35 +02:00
else
# make sure bitcoind is not running
sudo systemctl stop background <2 /dev/null
sudo systemctl stop bitcoind <2 /dev/null
2019-02-15 12:01:08 +01:00
fi
2020-06-17 15:13:00 +02:00
# check if old blockchain data exists
hasOldBlockchainData = 0
sizeBlocks = $( sudo du -s /mnt/hdd/bitcoin/blocks 2>/dev/null | tr -dc '[0-9]' )
if [ ${# sizeBlocks } -gt 0 ] && [ ${ sizeBlocks } -gt 0 ] ; then
hasOldBlockchainData = 1
fi
sizeChainstate = $( sudo du -s /mnt/hdd/bitcoin/chainstate 2>/dev/null | tr -dc '[0-9]' )
if [ ${# sizeChainstate } -gt 0 ] && [ ${ sizeChainstate } -gt 0 ] ; then
hasOldBlockchainData = 1
fi
if [ ${ hasOldBlockchainData } -eq 1 ] && [ " $1 " != "stop-after-script" ] ; then
2020-10-01 17:30:17 +02:00
dialog --title " Old Blockchain Data Found " --yesno "\nDo you want to delete the existing blockchain data now?" 7 60
2019-03-18 00:46:15 +01:00
response = $?
echo " response( ${ response } ) "
2019-03-18 00:48:32 +01:00
if [ " ${ response } " = "1" ] ; then
2019-03-18 00:46:15 +01:00
echo "OK - keep old blockchain - just try to repair by copying over it"
sleep 3
else
echo "OK - delete old blockchain"
2020-06-17 15:13:00 +02:00
sudo rm -rfv /mnt/hdd/bitcoin/blocks/* 2>/dev/null
sudo rm -rfv /mnt/hdd/bitcoin/chainstate/* 2>/dev/null
2019-03-18 00:46:15 +01:00
sleep 3
fi
fi
2019-02-15 12:01:08 +01:00
2019-02-15 23:19:43 +01:00
# make sure /mnt/hdd/bitcoin exists
sudo mkdir /mnt/hdd/bitcoin 2>/dev/null
2019-03-15 17:56:06 +01:00
# allow all users write to it
2019-02-15 23:19:43 +01:00
sudo chmod 777 /mnt/hdd/bitcoin
2019-01-30 09:48:25 +00:00
2019-03-17 03:58:53 +01:00
echo
2019-01-30 09:48:25 +00:00
clear
2019-03-15 17:56:06 +01:00
if [ " ${ CHOICE } " = "WINDOWS" ] ; then
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2020-06-17 14:03:29 +02:00
echo "Instructions to COPY/TRANSFER SYNCED BLOCKCHAIN from a WINDOWS computer"
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2020-06-17 14:03:29 +02:00
echo ""
2020-06-17 15:38:00 +02:00
echo "ON YOUR WINDOWS COMPUTER download and validate the blockchain with the Bitcoin"
echo "Core wallet software (>=0.17.1) from: bitcoincore.org/en/download"
echo "If the Bitcoin Blockchain is synced up - make sure that your Windows computer &"
2020-06-17 14:03:29 +02:00
echo "your RaspiBlitz are in the same local network."
echo ""
2020-06-17 15:38:00 +02:00
echo "Open a fresh terminal on your Windows computer & change into the directory that"
echo "contains the blockchain data - should see folders named 'blocks' & 'chainstate'"
2020-06-17 14:03:29 +02:00
echo "there. Normally on Windows thats: C:\Users\YourUserName\Appdata\Roaming\Bitcoin"
echo "Make sure that the Bitcoin Core Wallet is not running in the background anymore."
echo ""
2020-06-17 15:38:00 +02:00
echo "COPY, PASTE & EXECUTE the following command on your Windows computer terminal:"
echo " scp -r ./chainstate ./blocks bitcoin@ ${ localip } :/mnt/hdd/bitcoin "
2020-06-17 14:03:29 +02:00
echo ""
2020-06-17 15:38:00 +02:00
echo "If asked for a password use PASSWORD A (or 'raspiblitz')."
2020-06-17 14:03:29 +02:00
fi
if [ " ${ CHOICE } " = "MACOS" ] ; then
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2020-06-17 14:03:29 +02:00
echo "Instructions to COPY/TRANSFER SYNCED BLOCKCHAIN from a MacOSX computer"
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2020-06-17 14:03:29 +02:00
echo ""
2020-06-17 15:38:00 +02:00
echo "ON YOUR MacOSX COMPUTER download and validate the blockchain with the Bitcoin"
echo "Core wallet software (>=0.17.1) from: bitcoincore.org/en/download"
echo "If the Bitcoin Blockchain is synced up - make sure that your MacOSX computer &"
2020-06-17 14:03:29 +02:00
echo "your RaspiBlitz are in the same local network."
echo ""
echo "Open a fresh terminal on your MacOSX computer and change into the directory that"
2020-06-17 15:38:00 +02:00
echo "contains the blockchain data - should see folders named 'blocks' & 'chainstate'"
2020-06-17 14:03:29 +02:00
echo "there. Normally on MacOSX thats: cd ~/Library/Application Support/Bitcoin/"
echo "Make sure that the Bitcoin Core Wallet is not running in the background anymore."
echo ""
echo "COPY, PASTE & EXECUTE the following command on your MacOSX terminal:"
2019-06-29 18:55:13 +02:00
echo " sudo rsync -avhW --progress ./chainstate ./blocks bitcoin@ ${ localip } :/mnt/hdd/bitcoin "
2020-06-17 14:03:29 +02:00
echo ""
2020-06-17 15:38:00 +02:00
echo "You will be asked for passwords. First can be the user password of your MacOSX"
2020-06-17 14:03:29 +02:00
echo "computer and the last is the PASSWORD A (or 'raspiblitz') of this RaspiBlitz."
2019-03-15 18:20:16 +01:00
fi
2020-06-17 14:03:29 +02:00
if [ " ${ CHOICE } " = "LINUX" ] ; then
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2020-06-17 14:03:29 +02:00
echo "Instructions to COPY/TRANSFER SYNCED BLOCKCHAIN from a LINUX computer"
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2020-06-17 14:03:29 +02:00
echo ""
2020-06-17 15:38:00 +02:00
echo "ON YOUR LINUX COMPUTER download and validate the blockchain with the Bitcoin"
echo "Core wallet software (>=0.17.1) from: bitcoincore.org/en/download"
echo "If the Bitcoin Blockchain is synced up - make sure that your Linux computer &"
2020-06-17 14:03:29 +02:00
echo "your RaspiBlitz are in the same local network."
echo ""
echo "Open a fresh terminal on your Linux computer and change into the directory that"
2020-06-17 15:38:00 +02:00
echo "contains the blockchain data - should see folders named 'blocks' & 'chainstate'"
2020-06-17 14:03:29 +02:00
echo "there. Normally on Linux thats: cd ~/.bitcoin/"
echo "Make sure that the Bitcoin Core Wallet is not running in the background anymore."
echo ""
echo "COPY, PASTE & EXECUTE the following command on your Linux terminal:"
echo " sudo rsync -avhW --progress ./chainstate ./blocks bitcoin@ ${ localip } :/mnt/hdd/bitcoin "
echo ""
2020-06-17 15:38:00 +02:00
echo "You will be asked for passwords. First can be the user password of your Linux"
2020-06-17 14:03:29 +02:00
echo "computer and the last is the PASSWORD A (or 'raspiblitz') of this RaspiBlitz."
2020-02-16 23:36:58 +01:00
fi
2020-06-17 14:03:29 +02:00
if [ " ${ CHOICE } " = "BLITZ" ] ; then
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2020-06-17 14:03:29 +02:00
echo "Instructions to COPY/TRANSFER SYNCED BLOCKCHAIN from another RaspiBlitz"
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2020-06-17 14:03:29 +02:00
echo ""
2020-06-17 22:33:45 +02:00
echo "The other RaspiBlitz needs a minimum version of 1.6 (if lower, update first)."
2020-06-17 14:03:29 +02:00
echo "Make sure that the other RaspiBlitz is on the same local network."
echo ""
echo "Open a fresh terminal and login per SSH into that other RaspiBlitz."
echo "Once in the main menu go: MAINMENU > REPAIR > COPY-SOURCE"
echo "Follow the given instructions ..."
2020-06-17 15:13:00 +02:00
echo ""
2020-06-17 22:36:08 +02:00
echo " The LOCAL IP of this target RaspiBlitz is: ${ localip } "
2020-06-17 14:03:29 +02:00
fi
echo ""
2019-01-30 09:48:25 +00:00
echo "It can take multiple hours until transfer is complete - be patient."
2020-06-18 16:30:25 +02:00
echo "****************************************************************************"
2019-10-18 21:25:04 +02:00
echo "PRESS ENTER if transfers is done OR if you want to choose another option."
2019-02-10 20:13:12 +01:00
sleep 2
2019-01-30 09:48:25 +00:00
read key
# make quick check if data is there
anyDataAtAll = 0
quickCheckOK = 1
2020-01-03 12:04:00 +00:00
count = $( sudo find /mnt/hdd/bitcoin/ -iname *.dat -type f | wc -l)
2019-01-30 09:48:25 +00:00
if [ ${ count } -gt 0 ] ; then
echo "Found data in /mnt/hdd/bitcoin/blocks"
anyDataAtAll = 1
fi
2020-01-03 12:04:00 +00:00
if [ ${ count } -lt 300 ] ; then
2020-01-03 12:09:56 +00:00
echo " FAIL: transfer seems invalid - less then 300 .dat files ( ${ count } ) "
2019-01-30 09:48:25 +00:00
quickCheckOK = 0
fi
2020-01-03 12:04:00 +00:00
count = $( sudo find /mnt/hdd/bitcoin/ -iname *.ldb -type f | wc -l)
2019-01-30 09:48:25 +00:00
if [ ${ count } -gt 0 ] ; then
echo "Found data in /mnt/hdd/bitcoin/chainstate"
anyDataAtAll = 1
fi
2020-01-03 12:04:00 +00:00
if [ ${ count } -lt 700 ] ; then
2020-01-03 12:09:56 +00:00
echo " FAIL: transfer seems invalid - less then 700 .ldb files ( ${ count } ) "
2019-01-30 09:48:25 +00:00
quickCheckOK = 0
fi
2019-02-15 23:19:43 +01:00
echo "*********************************************"
echo "QUICK CHECK RESULT"
echo "*********************************************"
2019-01-30 09:48:25 +00:00
# just if any data transferred ..
if [ ${ anyDataAtAll } -eq 1 ] ; then
2019-01-30 12:16:25 +00:00
# data was invalid - ask user to keep?
2019-01-30 09:48:25 +00:00
if [ ${ quickCheckOK } -eq 0 ] ; then
2019-02-15 23:19:43 +01:00
echo "FAIL -> DATA seems incomplete."
else
echo "OK -> DATA LOOKS GOOD :D"
2019-07-08 10:54:06 +02:00
sudo rm /mnt/hdd/bitcoin/debug.log 2>/dev/null
2019-02-15 23:19:43 +01:00
2019-01-30 09:48:25 +00:00
fi
else
2019-02-15 23:19:43 +01:00
echo "CANCEL -> NO DATA was copied."
quickCheckOK = 0
fi
echo "*********************************************"
2020-02-15 23:29:07 +01:00
# if started with parameter "stop-after-script" - quit here
if [ " $1 " = = "stop-after-script" ] ; then
echo "DONE Copy"
exit 0
fi
2019-02-15 23:19:43 +01:00
# if started after intial setup - quit here
if [ " ${ setupStep } " = "100" ] ; then
2019-02-16 00:39:32 +01:00
sudo cp /home/admin/assets/bitcoin.conf /mnt/hdd/bitcoin/bitcoin.conf
sudo systemctl enable bitcoind
2019-03-18 00:18:30 +01:00
echo "DONE - rebooting: sudo shutdown -r now"
sudo shutdown -r now
2019-02-15 23:19:43 +01:00
exit 0
fi
# REACT ON QUICK CHECK DURING INITAL SETUP
if [ ${ quickCheckOK } -eq 0 ] ; then
echo "*********************************************"
echo "There seems to be an invalid transfer."
echo "Wait 5 secs ..."
sleep 5
2020-10-01 17:30:17 +02:00
dialog --title " INVALID TRANSFER - TRY AGAIN?" --yesno "Quickcheck shows the data you transferred is invalid/incomplete. Maybe transfere was interrupted and not completed.\n\nDo you want retry/proceed the copy process?" 8 70
response = $?
echo " response( ${ response } ) "
if [ " ${ response } " = = "0" ] ; then
/home/admin/50copyHDD.sh
exit 0
fi
2020-07-24 17:53:38 +02:00
dialog --title " INVALID TRANSFER - DELETE DATA?" --yesno "Quickcheck shows the data you transferred is invalid/incomplete. This can lead further RaspiBlitz setup to get stuck in error state.\nDo you want to reset/delete data?" 8 60
2019-02-15 23:19:43 +01:00
response = $?
echo " response( ${ response } ) "
case $response in
1) quickCheckOK = 1 ; ;
esac
2019-01-30 09:48:25 +00:00
2019-02-15 23:19:43 +01:00
fi
if [ ${ quickCheckOK } -eq 0 ] ; then
echo "Deleting invalid Data ... "
2019-01-30 09:48:25 +00:00
sudo rm -rf /mnt/hdd/bitcoin
2019-02-10 20:11:47 +01:00
sleep 2
2019-01-30 09:48:25 +00:00
fi
2019-02-15 23:19:43 +01:00
# setup script will decide the next logical step
/home/admin/10setupBlitz.sh