raspiblitz/home.admin/10setupBlitz.sh

208 lines
5.7 KiB
Bash
Raw Normal View History

2018-07-17 13:12:03 +02:00
#!/bin/sh
echo ""
2018-07-29 01:33:54 +02:00
# load network
network=`cat .network`
2018-08-24 02:25:21 +02:00
# check chain
chain="test"
2018-08-24 03:14:22 +02:00
isMainChain=$(sudo cat /mnt/hdd/${network}/${network}.conf 2>/dev/null | grep "#testnet=1" -c)
2018-08-24 02:25:21 +02:00
if [ ${isMainChain} -gt 0 ];then
chain="main"
fi
2018-08-24 12:51:15 +02:00
# get setup progress
setupStep=$(sudo -u admin cat /home/admin/.setup)
if [ ${#setupStep} -eq 0 ];then
setupStep=0
fi
# if setup if ready --> REBOOT
if [ ${setupStep} -gt 89 ];then
2018-08-24 12:59:45 +02:00
echo "FINISH by setupstep(${setupStep})"
sleep 3
./90finishSetup.sh
exit 0
2018-08-24 12:51:15 +02:00
fi
2018-07-17 13:12:03 +02:00
# CHECK WHAT IS ALREADY WORKING
# check list from top down - so ./10setupBlitz.sh
# and re-enters the setup process at the correct spot
# in case it got interrupted
# check if lightning is running
2018-08-23 23:19:01 +02:00
lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running)
2018-07-17 13:12:03 +02:00
if [ ${lndRunning} -eq 1 ]; then
2018-08-24 02:45:04 +02:00
echo "LND is running ..."
sleep 1
2018-07-17 13:12:03 +02:00
2018-08-24 02:25:21 +02:00
# check if LND is locked
2018-08-24 02:35:56 +02:00
walletExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${chain}net/wallet.db 2>/dev/null | grep wallet.db -c)
locked=0
# only when a wallet exists - it can be locked
if [ ${walletExists} -eq 1 ];then
2018-08-24 02:48:48 +02:00
echo "lnd wallet exists ... checking if locked"
sleep 2
2018-08-24 02:35:56 +02:00
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock)
fi
2018-07-17 13:12:03 +02:00
if [ ${locked} -gt 0 ]; then
# LND wallet is locked
2018-07-27 18:30:53 +02:00
./AAunlockLND.sh
2018-07-17 13:12:03 +02:00
./10setupBlitz.sh
2018-08-24 02:25:21 +02:00
exit 0
fi
2018-08-24 12:55:04 +02:00
# check if blockchain still syncing (during sync sometimes CLI returns with error at this point)
chainInfo=$(sudo -u bitcoin ${network}-cli getblockchaininfo 2>/dev/null | grep 'initialblockdownload')
2018-08-24 02:25:21 +02:00
chainSyncing=1
if [ ${#chainInfo} -gt 0 ];then
chainSyncing=$(echo "${chainInfo}" | grep "true" -c)
fi
if [ ${chainSyncing} -eq 1 ]; then
2018-08-24 03:16:33 +02:00
echo "Sync Chain ..."
sleep 3
2018-07-17 13:12:03 +02:00
./70initLND.sh
2018-08-24 02:25:21 +02:00
exit 0
2018-07-17 13:12:03 +02:00
fi
2018-08-24 02:25:21 +02:00
# check if lnd is scanning blockchain
lndInfo=$(sudo -u bitcoin /usr/local/bin/lncli getinfo | grep "synced_to_chain")
lndSyncing=1
if [ ${#lndInfo} -gt 0 ];then
lndSyncing=$(echo "${chainInfo}" | grep "false" -c)
fi
if [ ${lndSyncing} -eq 1 ]; then
2018-08-24 03:16:33 +02:00
echo "Sync LND ..."
sleep 3
2018-08-24 02:25:21 +02:00
./70initLND.sh
exit 0
fi
# if unlocked, blockchain synced and LND synced to chain .. finisch Setup
2018-08-24 03:16:33 +02:00
echo "FINSIH ... "
sleep 3
2018-08-24 02:25:21 +02:00
./90finishSetup.sh
exit 0
2018-07-17 13:12:03 +02:00
fi
# check if bitcoin is running
2018-08-24 02:25:21 +02:00
bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running)
2018-08-24 23:38:42 +02:00
if [ ${bitcoinRunning} -eq 0 ]; then
# double check
bitcoinRunning=$(${network}-cli getblockchaininfo | grep "initialblockdownload" -c)
fi
2018-07-17 13:12:03 +02:00
if [ ${bitcoinRunning} -eq 1 ]; then
2018-07-29 01:33:54 +02:00
echo "OK - ${network}d is running"
2018-07-17 13:12:03 +02:00
echo "Next step run Lightning"
./70initLND.sh
exit 1
fi
# check if HDD is mounted
2018-07-29 01:33:54 +02:00
mountOK=$( df | grep -c /mnt/hdd )
2018-07-17 13:12:03 +02:00
if [ ${mountOK} -eq 1 ]; then
2018-07-29 01:33:54 +02:00
# are there any signs of blockchain data
if [ -d "/mnt/hdd/${network}" ]; then
echo "UNKOWN STATE - there is blockain data folder, but blockchaind is not running"
2018-07-17 13:12:03 +02:00
echo "It seems that something went wrong during sync/download/copy of the blockchain."
2018-08-24 23:40:37 +02:00
echo "If you want start fresh --> sudo rm -r /mnt/hdd/${network}"
echo "Or something with the config is not correct."
exit 1
fi
# check if there is a download to continue
downloadProgressExists=$(sudo ls /home/admin/.Download.out 2>/dev/null | grep ".Download.out" -c)
if [ ${downloadProgressExists} -eq 1 ]; then
echo "found download in progress .."
./50downloadHDD.sh
2018-07-17 13:12:03 +02:00
exit 1
fi
# HDD is empty - ask how to get Blockchain
2018-07-29 01:33:54 +02:00
#Bitcoin
if [ ${network} = "bitcoin" ]; then
echo "Bitcoin Options"
menuitem=$(dialog --clear --beep --backtitle "RaspiBlitz" --title "Getting the Blockchain" \
--menu "You need a copy of the Bitcoin Blockchain - you have 3 options:" 13 75 4 \
2018-08-23 21:19:19 +02:00
T "TORRENT --> TESTNET + MAINNET thru Torrent (DEFAULT)" \
D "DOWNLOAD --> TESTNET + MAINNET per FTP (FALLBACK)" \
2018-07-29 12:21:52 +02:00
C "COPY --> TESTNET + MAINNET from another HDD (TRICKY+FAST)" \
2018-07-29 21:43:16 +02:00
S "SYNC --> JUST TESTNET thru Bitoin Network (FALLBACK+SLOW)" 2>&1 >/dev/tty)
2018-07-29 01:33:54 +02:00
# Litecoin
elif [ ${network} = "litecoin" ]; then
echo "Litecoin Options"
menuitem=$(dialog --clear --beep --backtitle "RaspiBlitz" --title "Getting the Blockchain" \
--menu "You need a copy of the Litecoin Blockchain - you have 3 options:" 13 75 4 \
2018-08-23 21:19:19 +02:00
T "TORRENT --> MAINNET thru Torrent (DEFAULT)" \
D "DOWNLOAD --> MAINNET per FTP (FALLBACK)" \
2018-07-29 12:21:52 +02:00
C "COPY --> MAINNET from another HDD (TRICKY+FAST)" \
S "SYNC --> MAINNET thru Litecoin Network (FALLBACK+SLOW)" 2>&1 >/dev/tty)
2018-07-29 01:33:54 +02:00
# error
else
echo "FAIL Unkown network(${network})"
exit 1
fi
# set SetupState
echo "50" > /home/admin/.setup
2018-07-17 13:12:03 +02:00
clear
case $menuitem in
2018-07-29 12:21:52 +02:00
T)
./50torrentHDD.sh
;;
C)
./50copyHDD.sh
;;
S)
2018-07-17 13:12:03 +02:00
./50syncHDD.sh
;;
2018-07-29 12:21:52 +02:00
D)
2018-07-17 13:12:03 +02:00
./50downloadHDD.sh
;;
esac
exit 1
fi
2018-07-29 01:33:54 +02:00
2018-07-17 13:12:03 +02:00
# the HDD is not mounted --> very early stage of setup
# if the script is called for the first time
if [ ! -f "home/admin/.setup" ]; then
# run initial user dialog
./20initDialog.sh
# set SetupState to 10
echo "20" > /home/admin/.setup
# update system
echo ""
echo "*** Update System ***"
sudo apt-mark hold raspberrypi-bootloader
sudo apt-get update
sudo apt-get upgrade -f -y --force-yes
echo "OK - System is now up to date"
fi
# the HDD is already ext4 formated and called blockchain
formatExt4OK=$(lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL | grep BLOCKCHAIN | grep -c ext4)
if [ ${formatExt4OK} -eq 1 ]; then
echo "HDD was already inited or prepared"
echo "Now needs to be mounted"
./40addHDD.sh
exit 1
fi
# the HDD had no init yet
echo "HDD needs init"
./30initHDD.sh
exit 1