raspiblitz/home.admin/10setupBlitz.sh

268 lines
8.3 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 03:32:19 +01: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
echo "checking setup script"
2018-07-29 01:33:54 +02:00
2018-12-06 03:32:19 +01:00
# INFOFILE on SD - state data from bootstrap & setup
infoFile="/home/admin/raspiblitz.info"
2018-12-06 15:42:39 +01:00
source ${infoFile}
2018-08-24 02:25:21 +02:00
2018-12-06 18:26:06 +01:00
echo "network(${network})"
echo "chain(${chain})"
echo "setupStep(${setupStep})"
2018-12-06 18:42:49 +01:00
if [ ${#network} -eq 0 ]; then
echo "FAIL: Something is wrong. There is no value for network in ${infoFile}."
echo "Should be at least default value. EXIT"
exit 1
fi
2018-12-06 03:32:19 +01:00
# if no setup step in info file init with 0
2018-08-24 12:51:15 +02:00
if [ ${#setupStep} -eq 0 ];then
2018-12-06 18:26:06 +01:00
echo "Init setupStep=0"
2018-12-06 03:32:19 +01:00
echo "setupStep=0" >> ${infoFile}
2018-08-24 12:51:15 +02:00
setupStep=0
fi
2019-04-25 15:47:13 +02:00
# check if LND needs re-setup
if [ ${setupStep} -gt 79 ];then
source <(sudo /home/admin/config.scripts/lnd.check.sh basic-setup)
if [ ${wallet} -eq 0 ] || [ ${macaroon} -eq 0 ] || [ ${config} -eq 0 ] || [ ${tls} -eq 0 ]; then
echo "WARN: LND needs re-setup"
sudo /home/admin/70initLND.sh
exit 0
fi
fi
2018-08-24 12:51:15 +02:00
# 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
2019-04-25 15:47:13 +02:00
sudo /home/admin/90finishSetup.sh
sudo /home/admin/95finalSetup.sh
2018-08-24 12:59:45 +02:00
exit 0
2018-08-24 12:51:15 +02:00
fi
2018-07-17 13:12:03 +02:00
# 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-12-06 03:32:19 +01:00
# check if LND wallet exists and if 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
2019-04-25 15:47:13 +02:00
/home/admin/AAunlockLND.sh
/home/admin/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
2018-12-20 19:56:18 +01:00
echo "check chaininfo"
2018-08-24 02:25:21 +02:00
chainSyncing=$(echo "${chainInfo}" | grep "true" -c)
2018-12-20 19:56:18 +01:00
else
echo "chaininfo is zero"
2018-08-24 02:25:21 +02:00
fi
if [ ${chainSyncing} -eq 1 ]; then
2018-08-24 03:16:33 +02:00
echo "Sync Chain ..."
sleep 3
2019-04-25 15:47:13 +02:00
/home/admin/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
2019-04-26 14:20:25 +02:00
lndInfo=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} getinfo 2>/dev/null | grep "synced_to_chain")
2018-08-24 02:25:21 +02:00
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
2019-04-25 15:47:13 +02:00
/home/admin/70initLND.sh
2018-08-24 02:25:21 +02:00
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
2019-04-25 15:47:13 +02:00
sudo /home/admin/90finishSetup.sh
sudo /home/admin/95finalSetup.sh
2018-08-24 02:25:21 +02:00
exit 0
2018-12-06 03:32:19 +01:00
fi #end - when lighting is running
2018-07-17 13:12:03 +02:00
# 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
2019-02-09 18:32:03 +01:00
seconds=120
if [ ${setupStep} -lt 60 ]; then
seconds=10
fi
dialog --pause " Double checking for ${network}d - please wait .." 8 58 ${seconds}
2018-08-24 23:38:42 +02:00
bitcoinRunning=$(${network}-cli getblockchaininfo | grep "initialblockdownload" -c)
2018-12-20 19:56:18 +01:00
else
echo "${network} is running"
2018-08-24 23:38:42 +02:00
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"
2019-04-25 15:47:13 +02:00
/home/admin/70initLND.sh
2018-07-17 13:12:03 +02:00
exit 1
2018-12-20 19:56:18 +01:00
else
echo "${network} still not running"
2018-12-06 03:32:19 +01:00
fi #end - when bitcoin is running
2018-07-17 13:12:03 +02:00
2018-12-06 03:32:19 +01:00
# check if HDD is auto-mounted
mountOK=$( sudo cat /etc/fstab | 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
# FAILSAFE: check if raspiblitz.conf is available
configExists=$(ls /mnt/hdd/raspiblitz.conf | grep -c '.conf')
if [ ${configExists} -eq 0 ]; then
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FAIL: /mnt/hdd/raspiblitz.conf should exists at this point, but not found!"
echo "Please report to: https://github.com/rootzoll/raspiblitz/issues/293"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Press ENTER to EXIT."
read key
exit 1
fi
2018-12-06 18:26:06 +01:00
# are there any signs of blockchain data and activity
# setup running with admin user, but has no permission to read /mnt/hdd/bitcoin/blocks/, sudo needed
blockchainDataExists=$(sudo ls /mnt/hdd/${network}/blocks/blk00000.dat 2>/dev/null | grep -c '.dat')
2018-12-06 18:26:06 +01:00
configExists=$(sudo ls /mnt/hdd/${network}/${network}.conf | grep -c '.conf')
if [ ${blockchainDataExists} -eq 1 ]; then
if [ ${configExists} -eq 1 ]; then
2019-04-25 15:47:13 +02:00
/home/admin/XXdebugLogs.sh
2018-12-06 18:26:06 +01:00
echo "UNKOWN STATE - there is blockain data config, but blockchain service is not running"
echo "It seems that something went wrong during sync/download/copy of the blockchain."
echo "Or something with the config is not correct."
echo "Sometimes a reboot helps --> sudo shutdown -r now"
exit 1
else
2019-01-30 17:44:12 +00:00
echo "Got mounted blockchain, but no config and running service yet --> finish HDD"
2019-04-25 15:47:13 +02:00
/home/admin/60finishHDD.sh
2018-12-06 18:26:06 +01:00
exit 1
fi
fi
2019-02-09 19:15:40 +01:00
# check if there is torrent data to continue
2019-01-21 00:25:32 +01:00
torrentProgressExists=$(sudo ls /mnt/hdd/ 2>/dev/null | grep "torrent" -c)
if [ ${torrentProgressExists} -eq 1 ]; then
2019-02-09 19:15:40 +01:00
# check if there is a running screen session to return to
noScreenSession=$(screen -ls | grep -c "No Sockets found")
if [ ${noScreenSession} -eq 0 ]; then
echo "found torrent data .. resuming"
2019-04-25 15:47:13 +02:00
/home/admin/50torrentHDD.sh
2019-02-09 19:15:40 +01:00
exit 1
fi
2019-01-21 00:25:32 +01:00
fi
2019-02-09 19:15:40 +01:00
# check if there is ftp data to continue
2019-01-21 00:25:32 +01:00
downloadProgressExists=$(sudo ls /mnt/hdd/ 2>/dev/null | grep "download" -c)
if [ ${downloadProgressExists} -eq 1 ]; then
2019-02-09 19:15:40 +01:00
# check if there is a running screen session to return to
noScreenSession=$(screen -ls | grep -c "No Sockets found")
if [ ${noScreenSession} -eq 0 ]; then
echo "found download in data .. resuming"
2019-04-25 15:47:13 +02:00
/home/admin/50downloadHDD.sh
2019-02-09 19:15:40 +01:00
exit 1
fi
2018-07-17 13:12:03 +02:00
fi
2018-12-06 15:42:39 +01:00
# HDD is empty - 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" \
2019-01-30 14:11:27 +00:00
--menu "You need a copy of the Bitcoin Blockchain - you have 5 options:" 13 75 5 \
2019-01-30 09:48:25 +00:00
T "TORRENT --> MAINNET + TESTNET thru Torrent (DEFAULT)" \
2019-01-30 17:44:12 +00:00
C "COPY --> BLOCKCHAINDATA from another node with SCP" \
2019-02-09 18:23:08 +01:00
N "CLONE --> BLOCKCHAINDATA from 2nd HDD (extra cable)"\
2019-01-30 14:11:27 +00:00
S "SYNC --> MAINNET thru Bitcoin Network (ULTRA 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)" \
2018-07-29 12:21:52 +02:00
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
2018-12-06 03:32:19 +01:00
sudo sed -i "s/^setupStep=.*/setupStep=50/g" ${infoFile}
2018-07-17 13:12:03 +02:00
clear
case $menuitem in
2018-07-29 12:21:52 +02:00
T)
2019-02-10 20:11:47 +01:00
/home/admin/50torrentHDD.sh
2018-07-29 12:21:52 +02:00
;;
C)
2019-02-10 20:11:47 +01:00
/home/admin/50copyHDD.sh
2018-07-29 12:21:52 +02:00
;;
2019-02-09 18:23:08 +01:00
N)
2019-02-10 20:11:47 +01:00
/home/admin/50cloneHDD.sh
2019-01-30 14:11:27 +00:00
;;
2018-07-29 12:21:52 +02:00
S)
2019-02-10 20:11:47 +01:00
/home/admin/50syncHDD.sh
2018-07-17 13:12:03 +02:00
;;
esac
exit 1
2018-12-06 03:32:19 +01:00
fi # end HDD is already auto-mountes
2018-07-17 13:12:03 +02:00
2018-07-29 01:33:54 +02:00
2018-12-06 03:32:19 +01:00
# the HDD is not auto-mounted --> very early stage of setup
2018-07-17 13:12:03 +02:00
# if the script is called for the first time
2018-12-06 03:32:19 +01:00
if [ ${setupStep} -eq 0 ]; then
2018-07-17 13:12:03 +02:00
# run initial user dialog
2019-04-25 15:47:13 +02:00
/home/admin/20setupDialog.sh
2018-07-17 13:12:03 +02:00
2018-12-06 03:32:19 +01:00
# set SetupState
sudo sed -i "s/^setupStep=.*/setupStep=20/g" ${infoFile}
2018-07-17 13:12:03 +02:00
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
2019-01-16 21:17:44 +01:00
echo "HDD was already initialized/prepared"
2018-07-17 13:12:03 +02:00
echo "Now needs to be mounted"
2019-04-25 15:47:13 +02:00
/home/admin/40addHDD.sh
2018-07-17 13:12:03 +02:00
exit 1
fi
# the HDD had no init yet
2019-02-09 19:00:02 +01:00
echo "init HDD ..."
2019-04-25 15:47:13 +02:00
/home/admin/30initHDD.sh
2018-07-17 13:12:03 +02:00
exit 1