raspiblitz/home.admin/_bootstrap.sh

653 lines
22 KiB
Bash
Raw Normal View History

#!/bin/bash
# This script runs on every start called by boostrap.service
2018-10-15 22:31:56 +02:00
# It makes sure that the system is configured like the
# default values or as in the config.
2019-12-11 13:47:21 +01:00
################################
# BASIC SETTINGS
2019-12-11 13:47:21 +01:00
################################
# load codeVersion
source /home/admin/_version.info
2018-11-27 04:19:57 +01:00
# CONFIGFILE - configuration of RaspiBlitz
# used by fresh SD image to recover configuration
# and delivers basic config info for scripts
2019-02-05 10:33:34 +00:00
# make raspiblitz.conf if not there
sudo touch /mnt/hdd/raspiblitz.conf
2018-11-27 04:19:57 +01:00
configFile="/mnt/hdd/raspiblitz.conf"
# LOGFILE - store debug logs of bootstrap
# resets on every start
logFile="/home/admin/raspiblitz.log"
# INFOFILE - state data from bootstrap
# used by display and later setup steps
infoFile="/home/admin/raspiblitz.info"
2021-05-03 23:54:55 +02:00
# Init boostrap log file
2018-11-27 04:19:57 +01:00
echo "Writing logs to: ${logFile}"
echo "" > $logFile
echo "***********************************************" >> $logFile
echo "Running RaspiBlitz Bootstrap ${codeVersion}" >> $logFile
date >> $logFile
echo "***********************************************" >> $logFile
2019-01-21 00:25:32 +01:00
# set default values for raspiblitz.info
network=""
chain=""
setupStep=0
fsexpanded=0
2021-04-08 00:02:57 +02:00
# see https://github.com/rootzoll/raspiblitz/issues/1265#issuecomment-813369284
displayClass="lcd"
displayType=""
fundRecovery=0
2019-01-21 00:25:32 +01:00
2021-05-03 23:54:55 +02:00
################################
# INIT raspiblitz.info
################################
2019-01-21 00:25:32 +01:00
# try to load old values if available (overwrites defaults)
2019-01-21 00:49:30 +01:00
source ${infoFile} 2>/dev/null
2019-01-21 00:25:32 +01:00
2021-04-08 00:02:57 +02:00
# try to load config values if available (config overwrites info)
source ${configFile} 2>/dev/null
2021-05-04 01:05:50 +02:00
# get first basic network info
source <(/home/admin/config.scripts/internet.sh status)
2019-01-21 00:25:32 +01:00
# resetting info file
2018-11-27 04:19:57 +01:00
echo "Resetting the InfoFile: ${infoFile}"
echo "state=starting" > $infoFile
2018-12-12 16:12:30 +01:00
echo "message=" >> $infoFile
echo "baseimage=${baseimage}" >> $infoFile
echo "cpu=${cpu}" >> $infoFile
2019-01-21 00:25:32 +01:00
echo "network=${network}" >> $infoFile
echo "chain=${chain}" >> $infoFile
2021-05-04 01:05:50 +02:00
echo "localip='${localip}'" >> $infoFile
echo "online='${online}'" >> $infoFile
echo "fsexpanded=${fsexpanded}" >> $infoFile
2021-04-08 00:02:57 +02:00
echo "displayClass=${displayClass}" >> $infoFile
echo "displayType=${displayType}" >> $infoFile
2019-01-21 00:25:32 +01:00
echo "setupStep=${setupStep}" >> $infoFile
echo "fundRecovery=${fundRecovery}" >> $infoFile
if [ "${setupStep}" != "100" ]; then
echo "hostname=${hostname}" >> $infoFile
fi
2018-11-27 05:58:53 +01:00
sudo chmod 777 ${infoFile}
2018-10-15 22:31:56 +02:00
2021-05-03 23:54:55 +02:00
######################################
# SECTION FOR POSSIBLE REBOOT ACTIONS
systemInitReboot=0
2019-04-23 16:22:42 +02:00
2021-05-03 23:54:55 +02:00
################################
# FORCED SWITCH TO HDMI
# if a file called 'hdmi' gets
# placed onto the boot part of
# the sd card - switch to hdmi
################################
forceHDMIoutput=$(sudo ls /boot/hdmi* 2>/dev/null | grep -c hdmi)
if [ ${forceHDMIoutput} -eq 1 ]; then
# delete that file (to prevent loop)
sudo rm /boot/hdmi*
# switch to HDMI what will trigger reboot
echo "HDMI switch found ... activating HDMI display output & reboot" >> $logFile
sudo /home/admin/config.scripts/blitz.display.sh set-display hdmi >> $logFile
systemInitReboot=1
else
2021-05-03 23:54:55 +02:00
echo "No HDMI switch found. " >> $logFile
fi
2019-03-13 16:04:09 +01:00
2021-05-03 23:54:55 +02:00
################################
# SSH SERVER CERTS RESET
# if a file called 'ssh.reset' gets
# placed onto the boot part of
# the sd card - delete old ssh data
################################
2021-05-03 23:54:55 +02:00
sshReset=$(sudo ls /boot/ssh.reset* 2>/dev/null | grep -c reset)
if [ ${sshReset} -eq 1 ]; then
# delete that file (to prevent loop)
sudo rm /boot/ssh.reset* >> $logFile
# delete ssh certs
echo "SSHRESET switch found ... stopping SSH and deleting old certs" >> $logFile
sudo systemctl stop sshd >> $logFile
sudo rm /mnt/hdd/ssh/ssh_host* >> $logFile
sudo ssh-keygen -A >> $logFile
systemInitReboot=1
else
echo "No SSHRESET switch found. " >> $logFile
fi
################################
# FS EXPAND
# if a file called 'ssh.reset' gets
# placed onto the boot part of
# the sd card - delete old ssh data
################################
source <(sudo /home/admin/config.scripts/blitz.bootdrive.sh status)
if [ "${needsExpansion}" == "1" ] && [ "${fsexpanded}" == "0" ]; then
echo "FSEXPAND needed ... starting process" >> $logFile
sudo /home/admin/config.scripts/blitz.bootdrive.sh status >> $logFile
sudo /home/admin/config.scripts/blitz.bootdrive.sh fsexpand >> $logFile
systemInitReboot=1
2021-05-04 01:35:48 +02:00
elif [ "${tooSmall}" == "1" ]; then
echo "!!! FAIL !!!!!!!!!!!!!!!!!!!!" >> $logFile
echo "SDCARD TOO SMALL 16G minimum" >> $logFile
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >> $logFile
sed -i "s/^state=.*/state=sdtoosmall/g" ${infoFile}
echo "System stopped. Please cut power." >> $logFile
sleep 6000
sudo shutdown -r now
slepp 100
exit 1
2021-05-03 23:54:55 +02:00
else
echo "No FS EXPAND needed. needsExpansion(${needsExpansion}) fsexpanded(${fsexpanded})" >> $logFile
fi
################################
# UASP FIX - first try
# if HDD is connected on start
################################
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh uasp-fix)
if [ "${neededReboot}" == "1" ]; then
echo "UASP FIX applied (1st-try) ... reboot needed." >> $logFile
systemInitReboot=1
else
echo "No UASP FIX needed (1st-try)." >> $logFile
fi
######################################
# CHECK IF REBOOT IS NEEDED
# from actions above
if [ "${systemInitReboot}" == "1" ]; then
sudo cp ${logFile} ${logFile}.systeminit
sudo sed -i "s/^state=.*/state=reboot/g" ${infoFile}
sudo shutdown -r now
sleep 100
exit 0
fi
################################
# BOOT LOGO
################################
# display 3 secs logo - try to kickstart LCD
# see https://github.com/rootzoll/raspiblitz/issues/195#issuecomment-469918692
# see https://github.com/rootzoll/raspiblitz/issues/647
# see https://github.com/rootzoll/raspiblitz/pull/1580
randnum=$(shuf -i 0-7 -n 1)
2021-04-08 00:02:57 +02:00
/home/admin/config.scripts/blitz.display.sh image /home/admin/raspiblitz/pictures/startlogo${randnum}.png
sleep 5
/home/admin/config.scripts/blitz.display.sh hide
2019-01-15 02:37:14 +01:00
################################
# GENERATE UNIQUE SSH PUB KEYS
# on first boot up
################################
numberOfPubKeys=$(sudo ls /etc/ssh/ | grep -c 'ssh_host_')
if [ ${numberOfPubKeys} -eq 0 ]; then
echo "*** Generating new SSH PubKeys" >> $logFile
sudo dpkg-reconfigure openssh-server
echo "OK" >> $logFile
fi
2018-10-15 22:31:56 +02:00
################################
2021-05-03 23:54:55 +02:00
# CLEANING BOOT SYSTEM
2018-10-15 22:31:56 +02:00
################################
2021-05-03 23:54:55 +02:00
# resetting start count files
echo "SYSTEMD RESTART LOG: blockchain (bitcoind/litecoind)" > /home/admin/systemd.blockchain.log
echo "SYSTEMD RESTART LOG: lightning (LND)" > /home/admin/systemd.lightning.log
sudo chmod 777 /home/admin/systemd.blockchain.log
sudo chmod 777 /home/admin/systemd.lightning.log
2020-01-24 21:46:51 +01:00
2021-05-03 23:54:55 +02:00
# Emergency cleaning logs when over 1GB (to prevent SD card filling up)
# see https://github.com/rootzoll/raspiblitz/issues/418#issuecomment-472180944
echo "*** Checking Log Size ***"
logsMegaByte=$(sudo du -c -m /var/log | grep "total" | awk '{print $1;}')
if [ ${logsMegaByte} -gt 1000 ]; then
echo "WARN !! Logs /var/log in are bigger then 1GB"
echo "ACTION --> DELETED ALL LOGS"
if [ -d "/var/log/nginx" ]; then
nginxLog=1
echo "/var/log/nginx is present"
fi
sudo rm -r /var/log/*
if [ $nginxLog == 1 ]; then
sudo mkdir /var/log/nginx
echo "Recreated /var/log/nginx"
fi
sleep 3
echo "WARN !! Logs in /var/log in were bigger then 1GB and got emergency delete to prevent fillup."
echo "If you see this in the logs please report to the GitHub issues, so LOG config needs to hbe optimized."
else
2021-05-03 23:54:55 +02:00
echo "OK - logs are at ${logsMegaByte} MB - within safety limit"
2020-01-24 21:46:51 +01:00
fi
2021-05-03 23:54:55 +02:00
echo ""
2020-01-24 21:46:51 +01:00
2021-05-03 23:54:55 +02:00
###############################
# WAIT FOR ALL SERVICES
2020-03-18 14:07:27 -07:00
2021-05-03 23:54:55 +02:00
# get the state of data drive
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
2020-03-18 14:07:27 -07:00
2018-10-16 12:50:36 +02:00
################################
2021-05-04 01:05:50 +02:00
# WAIT LOOP: HDD CONNECTED
2018-10-16 12:50:36 +02:00
################################
2021-05-03 23:54:55 +02:00
2021-05-04 01:44:03 +02:00
echo "Waiting for HDD/SSD ..." >> $logFile
until [ ${isMounted} -eq 1 ] || [ ${#hddCandidate} -gt 0 ]
do
2021-05-04 01:44:03 +02:00
# recheck HDD/SSD
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
2021-05-04 01:44:03 +02:00
echo "isMounted: $isMounted"
echo "hddCandidate: $hddCandidate"
if [ ${isMounted} -eq 0 ] && [ ${#hddCandidate} -eq 0 ]; then
2019-12-11 13:47:21 +01:00
sed -i "s/^state=.*/state=noHDD/g" ${infoFile}
fi
2021-05-04 01:44:03 +02:00
# get latest network info & update raspiblitz.info
source <(/home/admin/config.scripts/internet.sh status)
sed -i "s/^localip=.*/localip='${localip}'/g" ${infoFile}
# wait for next check
sleep 2
2021-05-04 01:44:03 +02:00
done
2021-05-04 01:44:03 +02:00
echo "HDD/SSD connected: ${$hddCandidate}" >> $logFile
2019-12-12 16:06:07 +01:00
2021-05-03 23:54:55 +02:00
####################################
# WIFI RESTORE from HDD works with
# mem copy from datadrive inspection
####################################
# check if there is a WIFI configuration to backup or restore
/home/admin/config.scripts/internet.wifi.sh backup-restore >> $logFile
################################
# UASP FIX - second try
# when HDD gets connected later
################################
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh uasp-fix)
if [ "${neededReboot}" == "1" ]; then
echo "UASP FIX applied (2st-try) ... reboot needed." >> $logFile
sudo cp ${logFile} ${logFile}.uasp
sudo sed -i "s/^state=.*/state=reboot/g" ${infoFile}
sudo shutdown -r now
sleep 100
exit 0
else
echo "No UASP FIX needed (2st-try)." >> $logFile
fi
2021-05-04 01:05:50 +02:00
###################################
# WAIT LOOP: LOCALNET / INTERNET
# after HDD > can contain WIFI conf
###################################
2021-05-03 23:54:55 +02:00
gotLocalIP=0
until [ ${gotLocalIP} -eq 1 ]
do
2021-05-04 01:05:50 +02:00
2021-05-04 01:44:03 +02:00
# get latest network info & update raspiblitz.info
2021-05-03 23:54:55 +02:00
source <(/home/admin/config.scripts/internet.sh status)
2021-05-04 01:05:50 +02:00
sed -i "s/^localip=.*/localip='${localip}'/g" ${infoFile}
# check state of network
2021-05-03 23:54:55 +02:00
if [ ${dhcp} -eq 0 ]; then
# display user waiting for DHCP
sed -i "s/^state=.*/state=noDCHP/g" ${infoFile}
sed -i "s/^message=.*/message='Waiting for DHCP'/g" ${infoFile}
elif [ ${#localip} -eq 0 ]; then
if [ ${configWifiExists} -eq 0 ]; then
# display user to connect LAN
sed -i "s/^state=.*/state=noIP/g" ${infoFile}
sed -i "s/^message=.*/message='Connect the LAN/WAN'/g" ${infoFile}
else
# display user that wifi settings are not working
sed -i "s/^state=.*/state=noIP/g" ${infoFile}
sed -i "s/^message=.*/message='WIFI Settings not working'/g" ${infoFile}
fi
elif [ ${online} -eq 0 ]; then
# display user that wifi settings are not working
sed -i "s/^state=.*/state=noInternet/g" ${infoFile}
sed -i "s/^message=.*/message='No connection to Internet'/g" ${infoFile}
else
gotLocalIP=1
fi
sleep 1
done
2019-12-12 16:06:07 +01:00
# write info for LCD
sed -i "s/^state=.*/state=booting/g" ${infoFile}
sed -i "s/^message=.*/message='please wait'/g" ${infoFile}
2021-05-03 23:54:55 +02:00
# TODO: REMOVE LATER AGAIN
echo "DEBUG EXIT BREAK" >> $logFile
exit 1
# get fresh info about data drive to continue
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
echo "isMounted: $isMounted" >> $logFile
2018-11-27 04:19:57 +01:00
2018-12-10 14:48:02 +01:00
# check if the HDD is auto-mounted ( auto-mounted = setup-done)
if [ ${isMounted} -eq 0 ]; then
echo "HDD is there but not AutoMounted yet - checking Setup" >> $logFile
2018-11-27 04:19:57 +01:00
# when format is not EXT4 or BTRFS - stop bootstrap and await user setup
if [ "${hddFormat}" != "ext4" ] && [ "${hddFormat}" != "btrfs" ]; then
echo "HDD is NOT formatted in ${hddFormat} .. awaiting user setup." >> $logFile
2018-12-10 14:48:02 +01:00
sed -i "s/^state=.*/state=waitsetup/g" ${infoFile}
sed -i "s/^message=.*/message='HDD needs SetUp (1)'/g" ${infoFile}
2018-12-08 22:43:27 +01:00
exit 0
2018-11-27 04:19:57 +01:00
fi
# when error on analysing HDD - stop bootstrap and await user setup
if [ ${#hddError} -gt 0 ]; then
echo "FAIL - error on HDD analysis: ${hddError}" >> $logFile
2018-12-10 14:48:02 +01:00
sed -i "s/^state=.*/state=waitsetup/g" ${infoFile}
2019-12-13 19:30:09 +01:00
sed -i "s/^message=.*/message='${hddError}'/g" ${infoFile}
2018-12-08 22:43:27 +01:00
exit 0
2018-11-27 04:19:57 +01:00
fi
# temp mount the HDD
echo "Temp mounting data drive ($hddCandidate)" >> $logFile
if [ "${hddFormat}" != "btrfs" ]; then
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddPartitionCandidate})
else
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddCandidate})
fi
if [ ${#error} -gt 0 ]; then
echo "Failed to tempmount the HDD .. awaiting user setup." >> $logFile
sed -i "s/^state=.*/state=waitsetup/g" ${infoFile}
sed -i "s/^message=.*/message='${error}'/g" ${infoFile}
exit 0
fi
# make sure all links between directories/drives are correct
echo "Refreshing links between directories/drives .." >> $logFile
sudo /home/admin/config.scripts/blitz.datadrive.sh link
2018-11-27 04:19:57 +01:00
# check if HDD contains already a configuration
2018-11-27 18:33:14 +01:00
configExists=$(ls ${configFile} | grep -c '.conf')
echo "HDD contains already a configuration: ${configExists}" >> $logFile
2018-11-27 04:19:57 +01:00
if [ ${configExists} -eq 1 ]; then
2018-12-06 17:39:06 +01:00
echo "Found existing configuration" >> $logFile
2018-12-11 19:37:32 +01:00
source ${configFile}
# check if config files contains basic: version
if [ ${#raspiBlitzVersion} -eq 0 ]; then
echo "Invalid Config: missing raspiBlitzVersion in (${configFile})!" >> ${logFile}
configExists=0
fi
# check if config files contains basic: network
if [ ${#network} -eq 0 ]; then
echo "Invalid Config: missing network in (${configFile})!" >> ${logFile}
configExists=0
fi
# check if config files contains basic: chain
if [ ${#chain} -eq 0 ]; then
echo "Invalid Config: missing chain in (${configFile})!" >> ${logFile}
configExists=0
fi
2018-12-11 20:12:21 +01:00
if [ ${configExists} -eq 0 ]; then
echo "Moving invalid config to raspiblitz.invalid.conf" >> ${logFile}
2020-01-15 11:48:41 +01:00
sudo mv ${configFile} /mnt/hdd/raspiblitz.invalid.conf 2>/dev/null
2018-12-11 20:12:21 +01:00
fi
2018-12-11 19:37:32 +01:00
fi
2019-12-11 01:25:18 +01:00
2019-12-12 17:32:26 +01:00
# UPDATE MIGRATION & CONFIG PROVISIONING
2018-12-11 19:37:32 +01:00
if [ ${configExists} -eq 1 ]; then
echo "Found valid configuration" >> $logFile
2018-12-10 14:48:02 +01:00
sed -i "s/^state=.*/state=recovering/g" ${infoFile}
sed -i "s/^message=.*/message='Starting Recover'/g" ${infoFile}
sed -i "s/^chain=.*/chain=${chain}/g" ${infoFile}
sed -i "s/^network=.*/network=${network}/g" ${infoFile}
2018-12-06 17:39:06 +01:00
echo "Calling Data Migration .." >> $logFile
sudo /home/admin/_bootstrap.migration.sh
echo "Calling Provisioning .." >> $logFile
sudo /home/admin/_bootstrap.provision.sh
2020-01-08 12:48:10 +01:00
sed -i "s/^state=.*/state=reboot/g" ${infoFile}
2018-12-10 14:48:02 +01:00
sed -i "s/^message=.*/message='Done Recover'/g" ${infoFile}
2018-12-06 17:39:06 +01:00
echo "rebooting" >> $logFile
2018-12-12 16:23:09 +01:00
# set flag that system is freshly recovered and needs setup dialogs
sudo touch /home/admin/recover.flag
echo "state=recovered" >> /home/admin/recover.flag
2020-11-25 20:27:15 +01:00
echo "shutdown in 1min" >> $logFile
2018-12-06 17:39:06 +01:00
# save log file for inspection before reboot
echo "REBOOT FOR SSH CERTS RESET ..." >> $logFile
sudo cp ${logFile} ${logFile}.recover
sync
2020-11-25 20:27:15 +01:00
sudo shutdown -r -F -t 60
2018-12-08 22:43:27 +01:00
exit 0
2018-11-27 04:19:57 +01:00
else
echo "OK - No config file found: ${configFile}" >> $logFile
fi
# if it got until here: HDD is empty ext4
echo "Waiting for SetUp." >> $logFile
2018-12-10 14:48:02 +01:00
sed -i "s/^state=.*/state=waitsetup/g" ${infoFile}
sed -i "s/^message=.*/message='HDD needs SetUp (2)'/g" ${infoFile}
# unmount HDD to be ready for auto-mount during setup
sudo umount -l /mnt/hdd
2018-12-08 22:43:27 +01:00
exit 0
2018-11-27 04:19:57 +01:00
fi # END - no automount - after this HDD is mounted
2020-07-22 21:20:11 +02:00
# if a WIFI config exists backup to HDD
configWifiExists=$(sudo cat /etc/wpa_supplicant/wpa_supplicant.conf 2>/dev/null| grep -c "network=")
if [ ${configWifiExists} -eq 1 ]; then
2020-07-22 21:20:11 +02:00
echo "Making Backup Copy of WIFI config to HDD" >> $logFile
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /mnt/hdd/app-data/wpa_supplicant.conf
2020-07-22 21:20:11 +02:00
fi
2019-12-12 17:32:26 +01:00
# config should exist now
configExists=$(ls ${configFile} | grep -c '.conf')
if [ ${configExists} -eq 0 ]; then
sed -i "s/^state=.*/state=waitsetup/g" ${infoFile}
sed -i "s/^message=.*/message='no config'/g" ${infoFile}
exit 0
fi
2018-12-11 00:53:07 +01:00
#####################################
# UPDATE HDD CONFIG FILE (if exists)
2018-12-11 13:15:15 +01:00
# needs to be done before starting LND
# so that environment info is fresh
2018-12-11 00:53:07 +01:00
#####################################
echo "Check if HDD contains configuration .." >> $logFile
configExists=$(ls ${configFile} | grep -c '.conf')
if [ ${configExists} -eq 1 ]; then
2019-04-03 02:58:10 +01:00
# make sure lndAddress & lndPort exist
valueExists=$(cat ${configFile} | grep -c 'lndPort=')
if [ ${valueExists} -eq 0 ]; then
lndPort=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep "^listen=*" | cut -f2 -d':')
if [ ${#lndPort} -eq 0 ]; then
lndPort="9735"
fi
echo "lndPort='${lndPort}'" >> ${configFile}
fi
valueExists=$(cat ${configFile} | grep -c 'lndAddress=')
if [ ${valueExists} -eq 0 ]; then
echo "lndAddress=''" >> ${configFile}
fi
2018-12-11 00:53:07 +01:00
# load values
echo "load and update publicIP" >> $logFile
source ${configFile}
# if not running TOR before starting LND internet connection with a valid public IP is needed
waitForPublicIP=1
if [ "${runBehindTor}" = "on" ] || [ "${runBehindTor}" = "1" ]; then
echo "# no need to wait for internet - public Tor address already known" >> $logFile
waitForPublicIP=0
fi
while [ ${waitForPublicIP} -eq 1 ]
do
source <(/home/admin/config.scripts/internet.sh status)
if [ ${online} -eq 0 ]; then
echo "# (loop) waiting for internet ... " >> $logFile
sed -i "s/^state=.*/state=nointernet/g" ${infoFile}
sed -i "s/^message=.*/message='Waiting for Internet'/g" ${infoFile}
sleep 4
else
echo "# OK internet detected ... continue" >> $logFile
waitForPublicIP=0
fi
done
2019-04-03 02:58:10 +01:00
# update public IP on boot - set to domain is available
/home/admin/config.scripts/internet.sh update-publicip ${lndAddress}
2018-12-11 00:53:07 +01:00
2018-10-16 12:50:36 +02:00
fi
######################################################################
# MAKE SURE LND RPC/REST ports are standard & open to all connections
######################################################################
sudo sed -i "s/^rpclisten=.*/rpclisten=0.0.0.0:10009/g" /mnt/hdd/lnd/lnd.conf
sudo sed -i "s/^restlisten=.*/restlisten=0.0.0.0:8080/g" /mnt/hdd/lnd/lnd.conf
2019-01-09 21:10:35 +01:00
#################################
# FIX BLOCKCHAINDATA OWNER (just in case)
# https://github.com/rootzoll/raspiblitz/issues/239#issuecomment-450887567
#################################
sudo chown bitcoin:bitcoin -R /mnt/hdd/bitcoin 2>/dev/null
#################################
# FIX BLOCKING FILES (just in case)
# https://github.com/rootzoll/raspiblitz/issues/1901#issue-774279088
# https://github.com/rootzoll/raspiblitz/issues/1836#issue-755342375
2021-04-17 22:01:26 +02:00
sudo rm -f /mnt/hdd/bitcoin/bitcoind.pid 2>/dev/null
sudo rm -f /mnt/hdd/bitcoin/.lock 2>/dev/null
#################################
# MAKE SURE USERS HAVE LATEST LND CREDENTIALS
#################################
source ${configFile}
if [ ${#network} -gt 0 ] && [ ${#chain} -gt 0 ]; then
2019-04-27 23:04:20 +02:00
echo "running LND users credentials update" >> $logFile
sudo /home/admin/config.scripts/lnd.credentials.sh sync >> $logFile
2020-02-10 20:44:41 +01:00
else
echo "skipping LND credientials sync" >> $logFile
fi
################################
# MOUNT BACKUP DRIVE
# if "localBackupDeviceUUID" is set in
# raspiblitz.conf mount it on boot
################################
source ${configFile}
2020-07-04 01:57:12 +02:00
echo "Checking if additional backup device is configured .. (${localBackupDeviceUUID})" >> $logFile
2020-07-12 11:03:44 +01:00
if [ "${localBackupDeviceUUID}" != "" ] && [ "${localBackupDeviceUUID}" != "off" ]; then
2020-07-04 01:57:12 +02:00
echo "Yes - Mounting BackupDrive: ${localBackupDeviceUUID}" >> $logFile
2020-07-04 13:00:35 +02:00
sudo /home/admin/config.scripts/blitz.backupdevice.sh mount >> $logFile
2020-07-04 01:17:22 +02:00
else
2020-07-04 01:47:24 +02:00
echo "No additional backup device was configured." >> $logFile
fi
2018-12-12 16:23:09 +01:00
################################
# DETECT FRESHLY RECOVERED SD
################################
recoveredInfoExists=$(ls /home/admin/recover.flag | grep -c '.flag')
2018-12-12 18:37:13 +01:00
if [ ${recoveredInfoExists} -eq 1 ]; then
2018-12-12 16:23:09 +01:00
sed -i "s/^state=.*/state=recovered/g" ${infoFile}
sed -i "s/^message=.*/message='login to finish'/g" ${infoFile}
exit 0
fi
################################
2018-12-11 00:53:07 +01:00
# SD INFOFILE BASICS
################################
# state info
2018-12-12 18:53:01 +01:00
sed -i "s/^state=.*/state=ready/g" ${infoFile}
2018-12-06 18:36:34 +01:00
sed -i "s/^message=.*/message='waiting login'/g" ${infoFile}
# determine network and chain from system
# check for BITCOIN
loaded=$(sudo systemctl status bitcoind | grep -c 'loaded')
if [ ${loaded} -gt 0 ]; then
2019-02-02 23:27:13 +01:00
sed -i "s/^network=.*/network=bitcoin/g" ${infoFile}
2020-09-07 12:07:39 +02:00
source /mnt/hdd/bitcoin/bitcoin.conf >/dev/null 2>&1
if [ ${testnet} -gt 0 ]; then
sed -i "s/^chain=.*/chain=test/g" ${infoFile}
else
sed -i "s/^chain=.*/chain=main/g" ${infoFile}
fi
fi
# check for LITECOIN
loaded=$(sudo systemctl status litecoind | grep -c 'loaded')
if [ ${loaded} -gt 0 ]; then
2019-02-02 23:27:13 +01:00
sed -i "s/^network=.*/network=litecoin/g" ${infoFile}
sed -i "s/^chain=.*/chain=main/g" ${infoFile}
fi
################################
# DELETE LOG & LOCK FILES
################################
# LND and Blockchain Errors will be still in systemd journals
# /mnt/hdd/bitcoin/debug.log
sudo rm /mnt/hdd/${network}/debug.log 2>/dev/null
# /mnt/hdd/lnd/logs/bitcoin/mainnet/lnd.log
sudo rm /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null
# https://github.com/rootzoll/raspiblitz/issues/1700
sudo rm /mnt/storage/app-storage/electrs/db/mainnet/LOCK 2>/dev/null
#####################################
# CLEAN HDD TEMP
#####################################
echo "CLEANING TEMP DRIVE/FOLDER" >> $logFile
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh clean temp)
if [ ${#error} -gt 0 ]; then
echo "FAIL: ${error}" >> $logFile
else
echo "OK: Temp cleaned" >> $logFile
fi
2021-05-03 23:54:55 +02:00
###############################
# RAID data check (BRTFS)
###############################
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467698260
if [ ${isRaid} -eq 1 ]; then
echo "TRIGGERING BTRFS RAID DATA CHECK ..."
echo "Check status with: sudo btrfs scrub status /mnt/hdd/"
sudo btrfs scrub start /mnt/hdd/
fi
2020-05-26 19:07:40 +02:00
######################################
# PREPARE SUBSCRIPTIONS DATA DIRECTORY
######################################
if [ -d "/mnt/hdd/app-data/subscrptions" ]; then
echo "OK: subscription data directory exists"
else
echo "CREATE: subscription data directory"
sudo mkdir /mnt/hdd/app-data/subscriptions
sudo chown admin:admin /mnt/hdd/app-data/subscriptions
fi
# mark that node is ready now
sed -i "s/^state=.*/state=ready/g" ${infoFile}
sed -i "s/^message=.*/message='Node Running'/g" ${infoFile}
2020-06-17 22:20:06 +02:00
# make sure that bitcoin service is active
sudo systemctl enable ${network}d
2019-05-29 15:50:37 +01:00
echo "DONE BOOTSTRAP" >> $logFile
exit 0