mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2024-11-19 01:40:16 +01:00
#68 basic settings and bootstrap service
This commit is contained in:
parent
28ab642000
commit
dc0f659bcb
43
background_raspiblitzSettings.md
Normal file
43
background_raspiblitzSettings.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Background: RaspiBlitz Settings
|
||||
|
||||
## Before Version 1.0
|
||||
|
||||
The RaspiBlitz started as small collection of shell scripts to setup a bitcoin+lightning node. At this time it was not needed to have settings file. The idea was that the scripts analyse the system state and make the changes required - automatically trying to catch up. That was OK as long RaspiBlitz was just a helper to setup your Lightning node and the rest was up to you.
|
||||
|
||||
Over time users that are running a RaspiBlitz expected that it can handle more complex setup and customization. Also it should be easy to update the system (exchange sd card with a newer image) and should be able to have the same configuration afterwards - keeping its state. Thats why starting from version 1.0 there will be a raspiblitz config file stored on the HDD that stores stores the config state.
|
||||
|
||||
## The Config File
|
||||
|
||||
The RaspiBlitz config file is stored on the HDD root:
|
||||
|
||||
`/mnt/hdd/raspiblitz.conf`
|
||||
|
||||
Its simple structure is: one key-value pair per line. In the end its bash-script syntax to define varibales. The RaspiBlitz shell scripts can import this file with:
|
||||
|
||||
`source /mnt/hdd/raspiblitz.conf`
|
||||
|
||||
After this line all the config values are available and can be worked with. I prefer to call this line in scripts explicitly and not setting this values as environment variables, because when you read as a newbie such a script, you get an idea where the config file is stored.
|
||||
|
||||
## The Config Values
|
||||
|
||||
So see what config parameters are available check the comments in the following script:
|
||||
|
||||
`/home/admin/00enforceConfig.sh`
|
||||
|
||||
## Adding new Config Values
|
||||
|
||||
If you extend the RaspiBlitz scripts and you have the need to add a new config key-value add it to the `/home/admin/00enforceConfig.sh` script. There is a section for default values and setting them in the config file, if they dont exist there yet. Because this script runs on every startup, you can be sure that the default value is then available to your extended script - especially if people update their system.
|
||||
|
||||
## Enforcing the Config
|
||||
|
||||
On every start of the RaspiBlitz take the config file and check if the system is running as stated in the config file and when needed make changes to the system. This is done by calling this script on startuo with systemd:
|
||||
|
||||
`/home/admin/00enforceConfig.sh`
|
||||
|
||||
So if you change the config by hand or you write a script that changes the config, then simply trigger a restart the RaspiBliz.
|
||||
|
||||
Having this script checking the system on every startup, the user can easily update the SD card with a fresh image and the system will automatically establish the old state.
|
||||
|
||||
## What to put into the config file and what not
|
||||
|
||||
All values users put into setup or setting dialogs and that is not stored on the HDD (for example in the config files of lnd or bitcoin) is a hot cadidate to put into the raspi config file. Some values make sense to get stored as a duplicate (for performance or easy of access) - but dont get to wild.
|
@ -388,6 +388,14 @@ echo "*** HARDENING ***"
|
||||
# fail2ban (no config required)
|
||||
sudo apt-get install -y fail2ban
|
||||
|
||||
# *** BOOTSTRAP ***
|
||||
# see background README for details
|
||||
echo ""
|
||||
echo "*** RASPI BOOSTRAP SERVICE ***"
|
||||
sudo chmod +x /home/admin/_bootstrap.sh
|
||||
sudo cp ./assets/bootstrap.service /etc/systemd/system/bootstrap.service
|
||||
sudo systemctl enable bootstrap
|
||||
|
||||
# *** RASPIBLITZ IMAGE READY ***
|
||||
echo ""
|
||||
echo "**********************************************"
|
||||
|
@ -1,5 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
# load code software version
|
||||
source /home/admin/_version.info
|
||||
|
||||
# set colors
|
||||
color_red='\033[0;31m'
|
||||
color_green='\033[0;32m'
|
||||
@ -200,7 +203,7 @@ ${color_yellow} ${color_gray}${ln_channelInfo}
|
||||
${color_yellow}
|
||||
${color_yellow}${ln_external}
|
||||
" \
|
||||
"RaspiBlitz v0.93" \
|
||||
"RaspiBlitz v${codeVersion}" \
|
||||
"-------------------------------------------" \
|
||||
"load average:${load##up*, }" "${temp}" \
|
||||
"${hdd}" "${sync_percentage}"
|
||||
|
43
home.admin/00settingsMenuServices.sh
Normal file
43
home.admin/00settingsMenuServices.sh
Normal file
@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
# get raspiblitz config
|
||||
source /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# show select dialog
|
||||
CHOICES=$(dialog --checklist "Choose OS:" 15 40 5 \
|
||||
1 "Channel Autopilot" ${autoPilot} \
|
||||
#2 "Seed Torrent Blockchain" ${torrentSeeding} \
|
||||
#3 "RTL Webinterface" ${rtlWebinterface} \
|
||||
#4 "Electrum Server" ${electrumServer} \
|
||||
2>&1 >/dev/tty)
|
||||
clear
|
||||
|
||||
# check if user canceled dialog
|
||||
if [ ${#CHOICES} -eq 0 ]; then
|
||||
echo "user canceled"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# AUTOPILOT process choice
|
||||
choice="off"; check=$(echo "${CHOICES}" | grep -c "1")
|
||||
if [ ${check} -eq 1 ]; then choice="on"; fi
|
||||
sudo sed -i "s/^autoPilot=.*/autoPilot=${choice}/g" /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# TORRENTSEED process choice
|
||||
#choice="off"; check=$(echo "${CHOICES}" | grep -c "2")
|
||||
#if [ ${check} -eq 1 ]; then choice="on"; fi
|
||||
#sudo sed -i "s/^torrentSeeding=.*/torrentSeeding=${choice}/g" /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# RTLWEBINTERFACE process choice
|
||||
#choice="off"; check=$(echo "${CHOICES}" | grep -c "3")
|
||||
#if [ ${check} -eq 1 ]; then choice="on"; fi
|
||||
#sudo sed -i "s/^rtlWebinterface=.*/rtlWebinterface=${choice}/g" /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# ELECTRUMSERVER process choice
|
||||
#choice="off"; check=$(echo "${CHOICES}" | grep -c "4")
|
||||
#if [ ${check} -eq 1 ]; then choice="on"; fi
|
||||
#sudo sed -i "s/^electrumServer=.*/electrumServer=${choice}/g" /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# show password info dialog
|
||||
dialog --backtitle "Rebooting" --msgbox "To activate the settings a reboot is needed." 6 52
|
||||
sudo shutdown -r now
|
86
home.admin/_bootstrap.sh
Normal file
86
home.admin/_bootstrap.sh
Normal file
@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script runs on every start and makes sure the system
|
||||
# is configured like the default values or as in the config
|
||||
# file /mnt/hdd/raspiblitz.cfg
|
||||
# For more details see background_raspiblitzSettings.md
|
||||
|
||||
# load codeVersion
|
||||
source /home/admin/_version.info
|
||||
|
||||
logfile="/home/admin/raspiblitz.log"
|
||||
echo "Writing logs to: ${logfile}"
|
||||
echo "" >> $logfile
|
||||
echo "***********************************************" >> $logfile
|
||||
echo "Running RaspiBlitz Bootstrap ${codeVersion}" >> $logfile
|
||||
date >> $logfile
|
||||
echo "***********************************************" >> $logfile
|
||||
|
||||
# check if the HDD is mounted
|
||||
# TODO -> send to basic setup
|
||||
|
||||
################################
|
||||
# CONFIGFILE BASICS
|
||||
################################
|
||||
|
||||
# check if there is a config file
|
||||
configFile="/mnt/hdd/raspiblitz.conf"
|
||||
configExists=$(ls ${configFile} >/dev/null | grep -c '.conf')
|
||||
if [ ${configExists} -eq 0 ]; then
|
||||
|
||||
# create new config
|
||||
echo "creating config file: ${configFile}" >> $logfile
|
||||
echo "# RASPIBLITZ CONFIG FILE" > $configExists
|
||||
echo "raspiBlitzVersion='${version}'" >> $configExists
|
||||
|
||||
else
|
||||
|
||||
# load & check config version
|
||||
source $configExists
|
||||
if [ "${raspiBlitzVersion}" != "${raspiBlitzVersion}" ]; then
|
||||
echo "detected version change ... starting migration script" >> $logfile
|
||||
/home/admin/_migrateVersion.sh
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
################################
|
||||
# DEFAULT VALUES
|
||||
################################
|
||||
|
||||
# AUTOPILOT
|
||||
# autoPilot=off|on
|
||||
if [ ${#autoPilot} -eq 0 ]; then
|
||||
echo "autoPilot=off" >> $configExists
|
||||
fi
|
||||
|
||||
# after all default values written to config - reload config
|
||||
source $configExists
|
||||
|
||||
|
||||
################################
|
||||
# AUTOPILOT
|
||||
################################
|
||||
|
||||
# check if autopilot is actibe in LND config
|
||||
echo "** AUTOPILOT" >> $logfile
|
||||
lndAutopilot=$( grep -c "autopilot.active=1" /mnt/hdd/lnd/lnd.conf )
|
||||
echo "confAutopilot(${autoPilot})" >> $logfile
|
||||
echo "lndAutopilot(${lndAutopilot})" >> $logfile
|
||||
|
||||
# switch on
|
||||
if [ ${lndAutopilot} -eq 0 ] && [ "${autoPilot}" = "on" ]; then
|
||||
echo "switching the LND autopilot ON" >> $logfile
|
||||
sudo sed -i "s/^autopilot.active=.*/autopilot.active=1/g" /mnt/hdd/lnd/lnd.conf
|
||||
fi
|
||||
|
||||
# switch off
|
||||
if [ ${lndAutopilot} -eq 1 ] && [ "${autoPilot}" = "off" ]; then
|
||||
echo "switching the LND autopilot OFF" >> $logfile
|
||||
sudo sed -i "s/^autopilot.active=.*/autopilot.active=0/g" /mnt/hdd/lnd/lnd.conf
|
||||
fi
|
||||
|
||||
echo "" >> $logfile
|
||||
echo "DONE BOOTSTRAP" >> $logfile
|
||||
date >> $logfile
|
||||
echo "***********************************************" >> $logfile
|
17
home.admin/_migration.sh
Normal file
17
home.admin/_migration.sh
Normal file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
# load codeVersion
|
||||
source ./_version.info
|
||||
|
||||
# load raspiblitz config
|
||||
source /mnt/hdd/raspiblitz.conf
|
||||
|
||||
echo ""
|
||||
echo "*****************************"
|
||||
echo "Version Migration RaspiBlitz"
|
||||
echo "*****************************"
|
||||
echo "Version Code: ${codeVersion}"
|
||||
echo "Version Data: ${raspiBlitzVersion}"
|
||||
|
||||
echo "TODO: Update Migration check ..."
|
||||
echo ""
|
2
home.admin/_version.info
Normal file
2
home.admin/_version.info
Normal file
@ -0,0 +1,2 @@
|
||||
# RaspiBlitz Version - always [main].[sub]
|
||||
codeVersion="0.95"
|
16
home.admin/assets/bootstrap.service
Normal file
16
home.admin/assets/bootstrap.service
Normal file
@ -0,0 +1,16 @@
|
||||
# Boostrap the RaspiBlitz
|
||||
# /etc/systemd/system/bootstrap.service
|
||||
|
||||
[Unit]
|
||||
Description=setting up RaspiBlitz and enforcing the config on every startup
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
Type=oneshot
|
||||
ExecStart=/home/admin/_bootstrap.sh
|
||||
StandardOutput=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -3,7 +3,8 @@
|
||||
|
||||
[Unit]
|
||||
Description=getpublicip.sh: get public ip address from ipinfo.io
|
||||
After=network.target
|
||||
Wants=bootstrap.service
|
||||
After=bootstrap.service
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
|
Loading…
Reference in New Issue
Block a user