raspiblitz/home.admin/50syncHDD.sh

99 lines
3.4 KiB
Bash
Raw Normal View History

2018-12-05 00:07:58 +01:00
#!/bin/bash
2018-07-17 13:12:03 +02:00
2018-12-06 14:36:02 +01:00
## get basic info
2019-02-13 02:33:27 +01:00
source /home/admin/raspiblitz.info
2018-07-17 13:12:03 +02:00
2018-07-29 01:33:54 +02:00
# only show warning when bitcoin
if [ "$network" = "bitcoin" ]; then
# detect hardware version of RaspberryPi
# https://www.unixtutorial.org/command-to-confirm-raspberry-pi-model
raspberryPi=$(cat /proc/device-tree/model | cut -d " " -f 3 | sed 's/[^0-9]*//g')
if [ ${#raspberryPi} -eq 0 ]; then
raspberryPi=0
fi
echo "RaspberryPi Model Version: ${raspberryPi}"
if [ ${raspberryPi} -lt 4 ]; then
# raspberryPi 3 and lower
msg=" This old RaspberryPi has very limited CPU power.\n"
msg="$msg To sync & validate the complete blockchain\n"
msg="$msg can take multiple days - even weeks\n"
msg="$msg Its recommended to use another option.\n"
msg="$msg \n"
msg="$msg So do you really want start syncing now?"
dialog --title " WARNING " --yesno "${msg}" 11 57
response=$?
case $response in
0) echo "--> OK";;
1) exit 1;;
255) exit 1;;
esac
fi
2019-08-08 20:13:48 +02:00
fi
2019-08-08 20:13:48 +02:00
# ask if really sync behind TOR
if [ "${runBehindTor}" = "on" ]; then
whiptail --title ' Sync Blockchain from behind TOR? ' --yes-button='Public-Sync' --no-button='TOR-Sync' --yesno "You decided to run your node behind TOR and validate the blockchain with your RaspiBlitz - thats good. But downloading the complete blockchain thru TOR can add some extra time (maybe a day) to the process and adds a heavy load on the TOR network.\n
Your RaspiBlitz can just run the initial blockchain download with your public IP (Public-Sync) but keep your Lighting node safe behind TOR.
It would speed up the self-validation while not revealing your Lightning node identity. But for most privacy choose (TOR-Sync).
" 15 76
2019-08-08 20:13:48 +02:00
if [ $? -eq 0 ]; then
# set flag to not run bitcoin behind TOR during IDB
echo "ibdBehindTor=off" >> /home/admin/raspiblitz.info
fi
2019-08-08 20:13:48 +02:00
fi
2019-08-08 20:13:48 +02:00
echo "**********************************"
echo "Dont Trust, verify - starting sync"
echo "**********************************"
echo ""
sleep 3
2018-07-17 13:12:03 +02:00
2019-08-08 02:15:44 +02:00
echo "*** Optimizing RAM for Sync ***"
kbSizeRAM=$(cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g')
echo "dont forget to reduce dbcache once IBD is done" > "/home/admin/selfsync.flag"
# RP4 4GB
if [ ${kbSizeRAM} -gt 3500000 ]; then
echo "Detected RAM >=4GB --> optimizing ${network}.conf"
2019-08-08 04:49:17 +02:00
sudo sed -i "s/^dbcache=.*/dbcache=3072/g" /home/admin/assets/${network}.conf
2019-08-08 02:15:44 +02:00
# RP4 2GB
elif [ ${kbSizeRAM} -gt 1500000 ]; then
echo "Detected RAM >=2GB --> optimizing ${network}.conf"
2019-08-08 04:49:17 +02:00
sudo sed -i "s/^dbcache=.*/dbcache=1536/g" /home/admin/assets/${network}.conf
2019-08-08 02:15:44 +02:00
# RP3/4 1GB
else
echo "Detected RAM <=1GB --> optimizing ${network}.conf"
sudo sed -i "s/^dbcache=.*/dbcache=512/g" /home/admin/assets/${network}.conf
2019-08-08 02:15:44 +02:00
fi
2019-08-08 20:14:51 +02:00
echo ""
2018-07-17 13:12:03 +02:00
echo "*** Activating Blockain Sync ***"
2019-06-30 22:47:47 +02:00
2019-06-30 21:15:16 +02:00
sudo mkdir /mnt/hdd/${network} 2>/dev/null
2019-07-01 01:33:13 +02:00
sudo /home/admin/XXcleanHDD.sh -blockchain -force
2019-12-14 02:36:18 +01:00
sudo -u bitcoin mkdir /mnt/hdd/${network}/blocks 2>/dev/null
sudo -u bitcoin mkdir /mnt/hdd/${network}/chainstate 2>/dev/null
2019-06-30 22:47:47 +02:00
# set so that 10raspiblitz.sh has a flag to see that resync is running
2019-07-01 00:24:36 +02:00
sudo touch /mnt/hdd/${network}/blocks/.selfsync
2019-07-01 01:30:25 +02:00
sudo sed -i "s/^state=.*/state=sync/g" /home/admin/raspiblitz.info
2019-06-30 22:47:47 +02:00
2018-07-17 13:12:03 +02:00
echo "OK - sync is activated"
2019-06-30 21:15:16 +02:00
if [ "${setupStep}" = "100" ]; then
2018-07-17 13:12:03 +02:00
2019-06-30 21:57:05 +02:00
# start servives
2019-07-01 02:33:37 +02:00
echo "reboot needed: shutdown -r now"
2019-06-30 21:57:05 +02:00
2019-06-30 21:15:16 +02:00
else
# set SetupState
sudo sed -i "s/^setupStep=.*/setupStep=50/g" /home/admin/raspiblitz.info
# continue setup
./60finishHDD.sh
fi