diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index 2be5b5a..30a6475 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -69,12 +69,23 @@ fi if [ "${state}" = "presync" ]; then # stopping the pre-sync echo "" - echo "********************************************" - echo "Stopping pre-sync ... pls wait (up to 1min)" - echo "********************************************" - sudo -u root bitcoin-cli -conf=/home/admin/assets/bitcoin.conf stop - echo "bitcoind called to stop .." - sleep 50 + # analyse if blockchain was detected broken by pre-sync + blockchainBroken=$(sudo tail /mnt/hdd/bitcoin/debug.log | grep -c "Please restart with -reindex or -reindex-chainstate to recover.") + if [ ${blockchainBroken} -eq 1 ]; then + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "Detected corrupted blockchain on pre-sync !" + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + echo "Deleting blockchain data ..." + echo "(needs to get downloaded fresh during setup)" + sudo rm -f -r /mnt/hdd/bitcoin + else + echo "********************************************" + echo "Stopping pre-sync ... pls wait (up to 1min)" + echo "********************************************" + sudo -u root bitcoin-cli -conf=/home/admin/assets/bitcoin.conf stop + echo "bitcoind called to stop .." + sleep 50 + fi # unmount the temporary mount echo "Unmount HDD .." diff --git a/home.admin/_bootstrap.sh b/home.admin/_bootstrap.sh index c68a53a..2c29191 100644 --- a/home.admin/_bootstrap.sh +++ b/home.admin/_bootstrap.sh @@ -245,6 +245,8 @@ if [ ${hddIsAutoMounted} -eq 0 ]; then # check if pre-sync was already activated on last power-on #presyncActive=$(systemctl status bitcoind | grep -c 'could not be found') echo "starting pre-sync in background" >> $logFile + # make sure that debug file is clean, so just pre-sync gets analysed on stop + sudo rm /mnt/hdd/bitcoin/debug.log # starting in background, because this scripts is part of systemd # so to change systemd needs to happen after delay in seperate process sudo chown -R bitcoin:bitcoin /mnt/hdd/bitcoin 2>> $logFile