raspiblitz/home.admin/_bootstrap.sh

583 lines
20 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.
# For more details see background_raspiblitzSettings.md
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"
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
2020-01-24 21:46:51 +01:00
lcd2hdmi="off"
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
# 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
2019-01-21 00:25:32 +01:00
echo "network=${network}" >> $infoFile
echo "chain=${chain}" >> $infoFile
echo "fsexpanded=${fsexpanded}" >> $infoFile
2020-01-24 21:46:51 +01:00
echo "lcd2hdmi=${lcd2hdmi}" >> $infoFile
2019-01-21 00:25:32 +01:00
echo "setupStep=${setupStep}" >> $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
2019-04-23 16:22:42 +02:00
# resetting start count files
2019-04-24 13:47:58 +02:00
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
2019-04-23 16:22:42 +02:00
# Emergency cleaning logs when over 1GB (to prevent SD card filling up)
2019-03-13 16:04:09 +01:00
# 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
echo "OK - logs are at ${logsMegaByte} MB - within safety limit"
fi
echo ""
2019-03-13 16:04:09 +01:00
###############################
# RAID data check (BRTFS)
###############################
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467698260
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
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
################################
# 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
randnum=$(shuf -i 0-7 -n 1)
sudo fbi -a -T 1 -d /dev/fb1 --noverbose /home/admin/raspiblitz/pictures/startlogo${randnum}.png
sleep 5
sudo killall -3 fbi
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
################################
# AFTER BOOT SCRIPT
# when a process needs to
# execute stuff after a reboot
2018-11-27 04:19:57 +01:00
# it should in file
2018-10-16 12:50:36 +02:00
# /home/admin/setup.sh
2018-10-15 22:31:56 +02:00
################################
# check for after boot script
2018-10-16 12:50:36 +02:00
afterSetupScriptExists=$(ls /home/admin/setup.sh 2>/dev/null | grep -c setup.sh)
2018-10-15 22:31:56 +02:00
if [ ${afterSetupScriptExists} -eq 1 ]; then
echo "*** SETUP SCRIPT DETECTED ***"
# echo out script to journal logs
2018-10-16 12:50:36 +02:00
sudo cat /home/admin/setup.sh
2018-10-15 22:31:56 +02:00
# execute the after boot script
2018-10-16 12:50:36 +02:00
sudo /home/admin/setup.sh
2018-10-15 22:31:56 +02:00
# delete the after boot script
2018-10-16 12:50:36 +02:00
sudo rm /home/admin/setup.sh
2018-10-15 22:31:56 +02:00
# reboot again
echo "DONE wait 6 secs ... one more reboot needed ... "
sudo shutdown -r now
sleep 100
fi
2020-01-24 21:46:51 +01: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)
2020-01-24 21:46:51 +01:00
if [ ${forceHDMIoutput} -eq 1 ]; then
# delete that file (to prevent loop)
2020-03-18 15:57:31 -07:00
sudo rm /boot/hdmi*
2020-01-24 21:46:51 +01:00
# switch to HDMI what will trigger reboot
sudo /home/admin/config.scripts/blitz.lcd.sh hdmi on
exit 0
fi
2020-03-18 14:07:27 -07:00
################################
# SSH SERVER CERTS RESET
# if a file called 'ssh.reset' gets
# placed onto the boot part of
# the sd card - switch to hdmi
################################
sshReset=$(sudo ls /boot/ssh.reset* 2>/dev/null | grep -c reset)
2020-03-18 14:07:27 -07:00
if [ ${sshReset} -eq 1 ]; then
# delete that file (to prevent loop)
2020-03-18 15:57:31 -07:00
sudo rm /boot/ssh.reset*
2020-03-18 14:07:27 -07:00
# show info ssh reset
sed -i "s/^state=.*/state=sshreset/g" ${infoFile}
sed -i "s/^message=.*/message='resetting SSH & reboot'/g" ${infoFile}
# delete ssh certs
sudo systemctl stop sshd
sudo rm /mnt/hdd/ssh/ssh_host*
sudo ssh-keygen -A
sudo /home/admin/XXshutdown.sh reboot
exit 0
fi
2019-12-11 13:47:21 +01:00
################################
# WAIT FOR LOCAL NETWORK
################################
# wait until raspberry pi gets a local IP
gotLocalIP=0
until [ ${gotLocalIP} -eq 1 ]
do
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
if [ ${#localip} -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}
elif [ "${localip:0:4}" = "169." ]; then
# display user waiting for DHCP
sed -i "s/^state=.*/state=noDCHP/g" ${infoFile}
sed -i "s/^message=.*/message='Waiting for DHCP'/g" ${infoFile}
else
gotLocalIP=1
fi
sleep 1
done
2018-10-16 12:50:36 +02:00
################################
2018-11-27 04:19:57 +01:00
# HDD CHECK & PRE-INIT
2018-10-16 12:50:36 +02:00
################################
2018-11-27 04:19:57 +01:00
# wait loop until HDD is connected
until [ ${isMounted} -eq 1 ] || [ ${#hddCandidate} -gt 0 ]
do
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
if [ ${isMounted} -eq 0 ] && [ ${#hddCandidate} -eq 0 ]; then
2019-12-11 13:47:21 +01:00
sed -i "s/^state=.*/state=noHDD/g" ${infoFile}
2018-12-10 14:48:02 +01:00
sed -i "s/^message=.*/message='Connect the Hard Drive'/g" ${infoFile}
fi
sleep 2
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}
# get fresh info about data drive to continue
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
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" >> $logFile
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddCandidate})
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
echo "state=recovered" >> /home/admin/raspiblitz.recover.info
2018-12-06 17:39:06 +01:00
# save log file for inspection before reboot
2018-12-10 16:04:48 +01:00
cp $logFile /home/admin/raspiblitz.recover.log
echo "shutdown in 1min" >> $logFile
sync
sudo shutdown -r -F +1
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
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}
2019-04-03 02:58:10 +01:00
freshPublicIP=""
# determine the publicIP/domain that LND should announce
if [ ${#lndAddress} -gt 3 ]; then
# use domain as PUBLICIP
freshPublicIP="${lndAddress}"
2018-12-11 00:53:07 +01:00
2019-03-14 14:19:00 +01:00
else
2019-04-03 02:58:10 +01:00
# update public IP on boot
# wait otherwise looking for publicIP fails
sleep 5
freshPublicIP=$(curl -s http://v4.ipv6-test.com/api/myip.php)
# sanity check on IP data
# see https://github.com/rootzoll/raspiblitz/issues/371#issuecomment-472416349
2019-04-09 23:32:14 +01:00
echo "-> sanity check of IP data:"
2019-04-03 02:58:10 +01:00
if [[ $freshPublicIP =~ ^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$ ]]; then
echo "OK IPv6"
elif [[ $freshPublicIP =~ ^([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]{1,2}|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$ ]]; then
echo "OK IPv4"
else
echo "FAIL - not an IPv4 or IPv6 address"
freshPublicIP=""
fi
2019-04-03 02:58:10 +01:00
if [ ${#freshPublicIP} -eq 0 ]; then
# prevent having no publicIP set at all and LND getting stuck
# https://github.com/rootzoll/raspiblitz/issues/312#issuecomment-462675101
if [ ${#publicIP} -eq 0 ]; then
localIP=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
echo "WARNING: No publicIP information at all - working with placeholder: ${localIP}" >> $logFile
freshPublicIP="${localIP}"
fi
fi
fi
2019-04-03 02:58:10 +01:00
# set publicip value in raspiblitz.conf
2019-01-21 21:40:48 +01:00
if [ ${#freshPublicIP} -eq 0 ]; then
2019-04-03 02:58:10 +01:00
echo "WARNING: Was not able to determine external IP/domain on startup." >> $logFile
2018-12-11 00:53:07 +01:00
else
2019-01-21 21:40:48 +01:00
publicIPValueExists=$( sudo cat ${configFile} | grep -c 'publicIP=' )
if [ ${publicIPValueExists} -gt 1 ]; then
# remove one
echo "more then one publiIp entry - removing one" >> $logFile
sed -i "s/^publicIP=.*//g" ${configFile}
publicIPValueExists=$( sudo cat ${configFile} | grep -c 'publicIP=' )
fi
if [ ${publicIPValueExists} -eq 0 ]; then
echo "create value (${freshPublicIP})" >> $logFile
2019-04-03 02:58:10 +01:00
echo "publicIP='${freshPublicIP}'" >> $configFile
2019-01-21 21:40:48 +01:00
else
echo "update value (${freshPublicIP})" >> $logFile
2019-04-03 02:58:10 +01:00
sed -i "s/^publicIP=.*/publicIP='${freshPublicIP}'/g" ${configFile}
2019-01-21 21:40:48 +01:00
fi
2018-12-11 00:53:07 +01:00
fi
2018-10-16 12:50:36 +02:00
fi
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
#################################
# 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
2018-12-12 16:23:09 +01:00
################################
# DETECT FRESHLY RECOVERED SD
################################
recoveredInfoExists=$(ls /home/admin/raspiblitz.recover.info | grep -c '.info')
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}
source /mnt/hdd/bitcoin/bitcoin.conf
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 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
#####################################
# 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
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
################################
# IDENTIFY CPU ARCHITECTURE
################################
cpu="?"
isARM=$(uname -m | grep -c 'arm')
isAARCH64=$(uname -m | grep -c 'aarch64')
isX86_64=$(uname -m | grep -c 'x86_64')
if [ ${isARM} -gt 0 ]; then
cpu="arm"
elif [ ${isAARCH64} -gt 0 ]; then
cpu="aarch64"
elif [ ${isX86_64} -gt 0 ]; then
cpu="x86_64"
fi
echo "cpu=${cpu}" >> $infoFile
2019-04-10 02:45:37 +01:00
################################
# IDENTIFY BASEIMAGE
2019-04-10 02:45:37 +01:00
################################
baseImage="?"
isDietPi=$(uname -n | grep -c 'DietPi')
isRaspbian=$(cat /etc/os-release 2>/dev/null | grep -c 'Raspbian')
isArmbian=$(cat /etc/os-release 2>/dev/null | grep -c 'Debian')
isUbuntu=$(cat /etc/os-release 2>/dev/null | grep -c 'Ubuntu')
if [ ${isRaspbian} -gt 0 ]; then
baseImage="raspbian"
fi
if [ ${isArmbian} -gt 0 ]; then
baseImage="armbian"
fi
if [ ${isUbuntu} -gt 0 ]; then
baseImage="ubuntu"
fi
if [ ${isDietPi} -gt 0 ]; then
baseImage="dietpi"
fi
echo "baseimage=${baseImage}" >> $infoFile
################################
# STRESSTEST RASPBERRY PI
################################
2019-04-10 02:45:37 +01:00
if [ "${baseImage}" = "raspbian" ] ; then
# generate stresstest report on every startup (in case hardware has changed)
sed -i "s/^state=.*/state=stresstest/g" ${infoFile}
sed -i "s/^message=.*/message='Testing Hardware 60s'/g" ${infoFile}
sudo /home/admin/config.scripts/blitz.stresstest.sh /home/admin/stresstest.report
2019-06-13 14:44:02 +02:00
source /home/admin/stresstest.report
if [ "${powerWARN}" = "0" ]; then
2019-06-13 15:15:17 +02:00
# https://github.com/rootzoll/raspiblitz/issues/576
echo "" > /var/log/syslog
2019-06-13 14:44:02 +02:00
fi
2019-05-29 15:50:37 +01:00
fi
# mark that node is ready now
sed -i "s/^state=.*/state=ready/g" ${infoFile}
sed -i "s/^message=.*/message='Node Running'/g" ${infoFile}
2019-05-29 15:50:37 +01:00
echo "DONE BOOTSTRAP" >> $logFile
exit 0