From 85b0c97d41b5dcc79c24df02f5a4470dc3d0cbbc Mon Sep 17 00:00:00 2001 From: /rootzoll Date: Tue, 14 Dec 2021 23:34:35 +0100 Subject: [PATCH] big merge of 2388redis & 2669tor (#2790) --- .shellcheckrc | 2 + FAQ.md | 9 +- .../amd64/packer/scripts/init_vagrant.sh | 2 +- build_sdcard.sh | 979 +++++------------- home.admin/00infoBlitz.sh | 610 +++++------ home.admin/00infoLCD.sh | 18 +- home.admin/00mainMenu.sh | 14 +- home.admin/00parallelChainsMenu.sh | 3 - home.admin/00raspiblitz.sh | 126 ++- home.admin/00settingsMenuBasics.sh | 28 +- home.admin/98repairMenu.sh | 2 +- home.admin/99clMenu.sh | 5 +- home.admin/99clRepairMenu.sh | 10 +- home.admin/99connectMenu.sh | 19 +- home.admin/99lndMenu.sh | 5 +- home.admin/99updateMenu.sh | 23 +- home.admin/BBcashoutWallet.sh | 4 + home.admin/BBcloseAllChannels.sh | 5 + home.admin/BBconnectPeer.sh | 3 + home.admin/BBcreateInvoice.sh | 4 +- home.admin/BBfundWallet.sh | 4 + home.admin/BBopenChannel.sh | 5 + home.admin/BBpayInvoice.sh | 3 + home.admin/_background.scan.sh | 938 +++++++++++++++++ home.admin/_background.sh | 214 ++-- home.admin/_bootstrap.sh | 683 ++++++------ home.admin/_cache.sh | 474 +++++++++ home.admin/_commands.sh | 26 +- home.admin/_provision.migration.sh | 40 +- home.admin/_provision.setup.sh | 170 ++- home.admin/_provision.update.sh | 100 +- home.admin/_provision_.sh | 161 +-- home.admin/_tmux_alias.sh | 6 +- home.admin/_tmux_chain.sh | 6 +- home.admin/_tmux_network.sh | 8 +- home.admin/config.scripts/bitcoin.install.sh | 39 +- home.admin/config.scripts/bitcoin.monitor.sh | 309 ++++++ home.admin/config.scripts/bitcoin.update.sh | 33 +- .../config.scripts/blitz.backupdevice.sh | 10 +- home.admin/config.scripts/blitz.bootdrive.sh | 2 +- home.admin/config.scripts/blitz.cache.sh | 52 - home.admin/config.scripts/blitz.conf.sh | 78 ++ home.admin/config.scripts/blitz.datadrive.sh | 46 +- home.admin/config.scripts/blitz.debug.sh | 18 +- home.admin/config.scripts/blitz.display.sh | 119 +-- home.admin/config.scripts/blitz.docker.sh | 9 +- home.admin/config.scripts/blitz.error.sh | 66 ++ home.admin/config.scripts/blitz.migration.sh | 15 +- home.admin/config.scripts/blitz.notify.sh | 52 +- .../config.scripts/blitz.preparerelease.sh | 16 +- home.admin/config.scripts/blitz.shutdown.sh | 18 +- home.admin/config.scripts/blitz.ssh.sh | 20 +- home.admin/config.scripts/blitz.statusscan.sh | 327 ------ home.admin/config.scripts/blitz.systemd.sh | 6 +- .../config.scripts/blitz.touchscreen.sh | 9 +- home.admin/config.scripts/blitz.ups.sh | 5 +- home.admin/config.scripts/blitz.web.sh | 3 + .../config.scripts/bonus.angular_cli.sh | 9 +- home.admin/config.scripts/bonus.bos.sh | 11 +- .../config.scripts/bonus.btc-rpc-explorer.sh | 31 +- .../config.scripts/bonus.btcpayserver.sh | 43 +- home.admin/config.scripts/bonus.chantools.sh | 9 +- .../config.scripts/bonus.circuitbreaker.sh | 11 +- home.admin/config.scripts/bonus.electrs.sh | 49 +- home.admin/config.scripts/bonus.faraday.sh | 8 +- home.admin/config.scripts/bonus.fullynoded.sh | 6 +- home.admin/config.scripts/bonus.joinmarket.sh | 9 +- .../config.scripts/bonus.kindle-display.sh | 5 +- .../config.scripts/bonus.letsencrypt.sh | 12 +- home.admin/config.scripts/bonus.lit.sh | 41 +- home.admin/config.scripts/bonus.lnbits.sh | 25 +- home.admin/config.scripts/bonus.lndmanage.sh | 9 +- home.admin/config.scripts/bonus.loop.sh | 11 +- home.admin/config.scripts/bonus.mempool.sh | 26 +- home.admin/config.scripts/bonus.pool.sh | 13 +- home.admin/config.scripts/bonus.pyblock.sh | 11 +- home.admin/config.scripts/bonus.rtl.sh | 36 +- home.admin/config.scripts/bonus.specter.sh | 47 +- .../config.scripts/bonus.sphinxrelay.sh | 35 +- .../bonus.stacking-sats-kraken.sh | 4 +- home.admin/config.scripts/bonus.suez.sh | 9 +- home.admin/config.scripts/bonus.telegraf.sh | 21 +- home.admin/config.scripts/bonus.thunderhub.sh | 33 +- home.admin/config.scripts/bonus.typescript.sh | 9 +- home.admin/config.scripts/bonus.whitepaper.sh | 9 +- home.admin/config.scripts/bonus.zerotier.sh | 9 +- home.admin/config.scripts/cl-plugin.backup.sh | 4 +- home.admin/config.scripts/cl-plugin.clboss.sh | 16 +- .../config.scripts/cl-plugin.feeadjuster.sh | 16 +- home.admin/config.scripts/cl-plugin.http.sh | 28 +- home.admin/config.scripts/cl-plugin.sparko.sh | 36 +- .../cl-plugin.standard-python.sh | 2 +- home.admin/config.scripts/cl.backup.sh | 4 +- home.admin/config.scripts/cl.check.sh | 6 +- home.admin/config.scripts/cl.hsmtool.sh | 34 +- .../config.scripts/cl.install-service.sh | 2 +- home.admin/config.scripts/cl.install.sh | 20 +- home.admin/config.scripts/cl.monitor.sh | 240 +++++ home.admin/config.scripts/cl.rest.sh | 14 +- home.admin/config.scripts/cl.setname.sh | 11 +- home.admin/config.scripts/cl.spark.sh | 28 +- home.admin/config.scripts/cl.update.sh | 9 +- home.admin/config.scripts/dropbox.upload.sh | 7 +- home.admin/config.scripts/internet.dns.sh | 9 +- .../config.scripts/internet.dyndomain.sh | 10 +- home.admin/config.scripts/internet.sh | 135 ++- home.admin/config.scripts/internet.tor.sh | 409 -------- home.admin/config.scripts/internet.wifi.sh | 6 +- home.admin/config.scripts/lnd.autonat.sh | 7 +- home.admin/config.scripts/lnd.autopilot.sh | 7 +- home.admin/config.scripts/lnd.autounlock.sh | 21 +- home.admin/config.scripts/lnd.install.sh | 30 +- home.admin/config.scripts/lnd.keysend.sh | 11 +- home.admin/config.scripts/lnd.monitor.sh | 289 ++++++ home.admin/config.scripts/lnd.setaddress.sh | 36 +- home.admin/config.scripts/lnd.setname.sh | 31 +- home.admin/config.scripts/lnd.setport.sh | 9 +- home.admin/config.scripts/lnd.unlock.sh | 1 + home.admin/config.scripts/lnd.update.sh | 12 +- home.admin/config.scripts/network.chain.sh | 4 +- home.admin/config.scripts/network.monitor.sh | 186 ---- home.admin/config.scripts/network.reindex.sh | 12 +- home.admin/config.scripts/network.upnp.sh | 9 +- home.admin/config.scripts/network.wallet.sh | 1 + home.admin/config.scripts/nextcloud.upload.sh | 37 +- home.admin/config.scripts/tor.install.sh | 258 +++++ home.admin/config.scripts/tor.network.sh | 211 ++++ ....hiddenservice.sh => tor.onion-service.sh} | 37 +- .../setup.scripts/controlFinalDialog.sh | 18 +- .../setup.scripts/controlSetupDialog.sh | 45 +- .../setup.scripts/eventBlockchainSync.sh | 146 +-- home.admin/setup.scripts/eventInfoWait.sh | 25 +- 132 files changed, 4895 insertions(+), 4106 deletions(-) create mode 100644 .shellcheckrc create mode 100755 home.admin/_background.scan.sh create mode 100755 home.admin/_cache.sh create mode 100755 home.admin/config.scripts/bitcoin.monitor.sh delete mode 100755 home.admin/config.scripts/blitz.cache.sh create mode 100755 home.admin/config.scripts/blitz.conf.sh create mode 100755 home.admin/config.scripts/blitz.error.sh delete mode 100755 home.admin/config.scripts/blitz.statusscan.sh create mode 100755 home.admin/config.scripts/cl.monitor.sh delete mode 100755 home.admin/config.scripts/internet.tor.sh create mode 100755 home.admin/config.scripts/lnd.monitor.sh delete mode 100755 home.admin/config.scripts/network.monitor.sh create mode 100755 home.admin/config.scripts/tor.install.sh create mode 100755 home.admin/config.scripts/tor.network.sh rename home.admin/config.scripts/{internet.hiddenservice.sh => tor.onion-service.sh} (67%) diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 00000000..14d65b28 --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,2 @@ +shell=bash +source=/dev/null diff --git a/FAQ.md b/FAQ.md index d90f4e01..b4d505fb 100644 --- a/FAQ.md +++ b/FAQ.md @@ -390,6 +390,14 @@ If your RaspiBlitz is not working correctly and you like to get help from the co *PLEASE NOTICE: It's possible that these logs can contain private information (like IPs, node IDs, ...) - just share publicly what you feel OK with.* +### Can I run my RaspiBlitz on Solar Energy? + +Yes - take a look at the project of [Chimezie Chuta](https://twitter.com/mezie16/status/1264513274080636928?s=20) + +![RaspiSolar](pictures/raspisolar.jpg) + +More details in his book ["A-Z of Building your own Full Bitcoin Lightning Node: A hand Book for Enthusiasts"](https://blockspace.shop/products/a-z-of-building-your-own-full-bitcoin-lightning-node-a-hand-book-for-enthusiasts) + ### Why is my "final sync" taking so long? First of all if you see a final sync over 90% and you can see from time to time small increase - you should be OK ... this can take a looong time to catch up with the network. Only in the case that you actively choose the `SYNC` option in the `Getting the Blockchain` is a final sync under 90% OK. If you did a torrent or a copy from another computer and you are seeing under 90% something went wrong, and the setup process is ignoring your prepared Blockchain and doing a full sync - which can almost take forever on a raspberryPi. @@ -909,7 +917,6 @@ It is currently considered completely fine to leave this field empty and not pro The `acme.sh` script is installed in `/home/admin/.acme.sh/` - the configuration and the certificates are stored on the external hard disk in `/mnt/hdd/app-data/letsencrypt`. - ### What is this mnemonic seed word list? With the 24 word list given you by LND upon wallet creation you can recover your private key. You should write it down and store it at a safe place. Bear in mind that *this 24 word mnemonic seed is not based on the BIP 39* and therefore cannot be recovered using a Bitcoin wallet. diff --git a/alternative.platforms/amd64/packer/scripts/init_vagrant.sh b/alternative.platforms/amd64/packer/scripts/init_vagrant.sh index ed01e8e7..91b9c186 100644 --- a/alternative.platforms/amd64/packer/scripts/init_vagrant.sh +++ b/alternative.platforms/amd64/packer/scripts/init_vagrant.sh @@ -10,7 +10,7 @@ cp /vagrant/home.admin/config.scripts/blitz.github.sh /home/admin/config.scripts # execute 'patch' command to sync laptop with VM /home/admin/config.scripts/blitz.github.sh -run -source <(/home/admin/config.scripts/internet.sh status) +source <(/home/admin/config.scripts/internet.sh status local) echo echo "************* NEXT ********************" diff --git a/build_sdcard.sh b/build_sdcard.sh index 0f9705c0..5c86e0ff 100755 --- a/build_sdcard.sh +++ b/build_sdcard.sh @@ -1,18 +1,17 @@ -#!/bin/bash +#!/usr/bin/env bash + ######################################################################### -# Build your SD card image based on: -# 2021-10-30-raspios-bullseye-arm64.zip +# Build your SD card image based on: 2021-10-30-raspios-bullseye-arm64.zip # https://downloads.raspberrypi.org/raspios_arm64/images/raspios_arm64-2021-11-08/ # SHA256: b35425de5b4c5b08959aa9f29b9c0f730cd0819fe157c3e37c56a6d0c5c13ed8 -########################################################################## +# PGP fingerprint: 8738CD6B956F460C +# PGP key: https://www.raspberrypi.org/raspberrypi_downloads.gpg.key # setup fresh SD card with image above - login per SSH and run this script: ########################################################################## -defaultBranchVersion="v1.7" - -echo +defaultBranch="v1.7" echo "*****************************************" -echo "* RASPIBLITZ SD CARD IMAGE SETUP ${defaultBranchVersion}.1 *" +echo "* RASPIBLITZ SD CARD IMAGE SETUP *" echo "*****************************************" echo "For details on optional parameters - see build script source code:" @@ -20,17 +19,12 @@ echo "For details on optional parameters - see build script source code:" # ---------------------------------------- # When 'true' then no questions will be asked on building .. so it can be used in build scripts # for containers or as part of other build scripts (default is false) - -noInteraction="$1" -if [ ${#noInteraction} -eq 0 ]; then - noInteraction="false" -fi +noInteraction="${1:-false}" if [ "${noInteraction}" != "true" ] && [ "${noInteraction}" != "false" ]; then echo "ERROR: NO-INTERACTION parameter needs to be either 'true' or 'false'" exit 1 -else - echo "1) will use NO-INTERACTION --> '${noInteraction}'" fi +echo "1) NO-INTERACTION --> '${noInteraction}'" # 2nd optional parameter: FATPACK # ------------------------------- @@ -40,73 +34,53 @@ fi # When 'false' it will just install the bare minimum and additional apps will just # install needed frameworks and libraries on demand when activated by user. # Use 'false' if you want to run your node without: go, dot-net, nodejs, docker, ... - -fatpack="$2" -if [ ${#fatpack} -eq 0 ]; then - fatpack="false" -fi +fatpack="${2:-false}" if [ "${fatpack}" != "true" ] && [ "${fatpack}" != "false" ]; then echo "ERROR: FATPACK parameter needs to be either 'true' or 'false'" exit 1 -else - echo "2) will use FATPACK --> '${fatpack}'" fi +echo "2) FATPACK --> '${fatpack}'" # 3rd optional parameter: GITHUB-USERNAME # --------------------------------------- # could be any valid github-user that has a fork of the raspiblitz repo - 'rootzoll' is default -# The 'raspiblitz' repo of this user is used to provisioning sd card +# The 'raspiblitz' repo of this user is used to provisioning sd card # with raspiblitz assets/scripts later on. # If this parameter is set also the branch needs to be given (see next parameter). -githubUser="$3" -if [ ${#githubUser} -eq 0 ]; then - githubUser="rootzoll" -fi -echo "3) will use GITHUB-USERNAME --> '${githubUser}'" +githubUser="${3:-rootzoll}" +echo "3) GITHUB-USERNAME --> '${githubUser}'" # 4th optional parameter: GITHUB-BRANCH # ------------------------------------- -# could be any valid branch of the given GITHUB-USERNAME forked raspiblitz repo - take ${defaultBranchVersion} is default -githubBranch="$4" -if [ ${#githubBranch} -eq 0 ]; then - githubBranch="${defaultBranchVersion}" -fi -echo "4) will use GITHUB-BRANCH --> '${githubBranch}'" +# could be any valid branch or tag of the given GITHUB-USERNAME forked raspiblitz repo +# https://github.com/rootzoll/raspiblitz/tags +githubBranch="${4:-"${defaultBranch}"}" +echo "4) GITHUB-BRANCH --> '${githubBranch}'" # 5th optional parameter: DISPLAY-CLASS # ---------------------------------------- # Could be 'hdmi', 'headless' or 'lcd' (lcd is default) # On 'false' the standard video output is used (HDMI) by default. # https://github.com/rootzoll/raspiblitz/issues/1265#issuecomment-813369284 -displayClass="$5" -if [ ${#displayClass} -eq 0 ]; then - displayClass="lcd" -fi -if [ "${displayClass}" == "false" ]; then - displayClass="hdmi" -fi +displayClass="${5:-lcd}" +[ "${displayClass}" = "false" ] && displayClass="hdmi" if [ "${displayClass}" != "hdmi" ] && [ "${displayClass}" != "lcd" ] && [ "${displayClass}" != "headless" ]; then echo "ERROR: DISPLAY-CLASS parameter needs to be 'lcd', 'hdmi' or 'headless'" exit 1 -else - echo "5) will use DISPLAY-CLASS --> '${displayClass}'" fi +echo "5) DISPLAY-CLASS --> '${displayClass}'" # 6th optional parameter: TWEAK-BOOTDRIVE # --------------------------------------- # could be 'true' (default) or 'false' # If 'true' it will try (based on the base OS) to optimize the boot drive. # If 'false' this will skipped. -tweakBootdrives="$6" -if [ ${#tweakBootdrives} -eq 0 ]; then - tweakBootdrives="true" -fi +tweakBootdrives="${6:-true}" if [ "${tweakBootdrives}" != "true" ] && [ "${tweakBootdrives}" != "false" ]; then echo "ERROR: TWEAK-BOOTDRIVE parameter needs to be either 'true' or 'false'" exit 1 -else - echo "6) will use TWEAK-BOOTDRIVE --> '${tweakBootdrives}'" fi +echo "6) TWEAK-BOOTDRIVE --> '${tweakBootdrives}'" # 7th optional parameter: WIFI # --------------------------------------- @@ -114,210 +88,160 @@ fi # If 'false' WIFI will be deactivated by default # If 'true' WIFI will be activated by with default country code 'US' # If any valid wifi country code Wifi will be activated with that country code by default -modeWifi="$7" -if [ ${#modeWifi} -eq 0 ] || [ "${modeWifi}" == "true" ]; then - modeWifi="US" -fi -echo "7) will use WIFI --> '${modeWifi}'" +modeWifi="${7:-US}" +[ "${modeWifi}" = "true" ] && modeWifi="US" +echo "7) WIFI --> '${modeWifi}'" # AUTO-DETECTION: CPU-ARCHITECTURE # --------------------------------------- -cpu="?" -if [ "$(uname -m | grep -c 'arm')" -gt 0 ]; then - cpu="arm" -elif [ "$(uname -m | grep -c 'aarch64')" -gt 0 ]; then - cpu="aarch64" -elif [ "$(uname -m | grep -c 'x86_64')" -gt 0 ]; then - cpu="x86_64" -else - echo "!!! FAIL !!!" - echo "Can only build on ARM, aarch64, x86_64 not on:" - uname -m - exit 1 -fi -echo "X) will use CPU-ARCHITECTURE --> '${cpu}'" +cpu="$(uname -m)" +architecture="$(dpkg --print-architecture)" +case "${cpu}" in + arm*|aarch64|x86_64|amd64);; + *) echo -e "!!! FAIL !!!\nCan only build on ARM, aarch64, x86_64 not on: cpu=${cpu}"; exit 1;; +esac +echo "X) CPU-ARCHITECTURE --> '${cpu} (${architecture})'" # AUTO-DETECTION: OPERATINGSYSTEM # --------------------------------------- -# keep in mind that DietPi for Raspberry is also a stripped down Raspbian -baseimage="?" -if [ $(grep -c 'Raspbian' /etc/os-release 2>/dev/null) -gt 0 ]; then - baseimage="raspbian" -elif [ $(grep -c 'Debian' /etc/os-release 2>/dev/null) -gt 0 ]; then - if [ $(uname -n | grep -c 'rpi') -gt 0 ] && [ "${cpu}" = aarch64 ]; then - baseimage="debian_rpi64" - elif [ $(uname -n | grep -c 'raspberrypi') -gt 0 ] && [ "${cpu}" = aarch64 ]; then +if [ $(grep -c 'Debian' /etc/os-release 2>/dev/null) -gt 0 ]; then + if [ $(uname -n | grep -c 'raspberrypi') -gt 0 ] && [ "${cpu}" = aarch64 ]; then + # default image for RaspberryPi baseimage="raspios_arm64" - elif [ "${cpu}" = "arm" ] || [ "${cpu}" = "aarch64" ] ; then + elif [ $(uname -n | grep -c 'rpi') -gt 0 ] && [ "${cpu}" = aarch64 ]; then + # experimental: a clean alternative image of debian for RaspberryPi + baseimage="debian_rpi64" + elif [ "${cpu}" = "arm" ] || [ "${cpu}" = "aarch64" ]; then + # experimental: fallback for all debian on arm baseimage="armbian" else + # experimental: fallback for all debian on other CPUs baseimage="debian" fi elif [ $(grep -c 'Ubuntu' /etc/os-release 2>/dev/null) -gt 0 ]; then baseimage="ubuntu" -elif [ $(uname -n | grep -c 'DietPi') -gt 0 ]; then - baseimage="dietpi" -elif [ "${baseimage}" = "?" ]; then +else cat /etc/os-release 2>/dev/null + uname -a echo "!!! FAIL: Base Image cannot be detected or is not supported." exit 1 fi -echo "X) will use OPERATINGSYSTEM ---> '${baseimage}'" +echo "X) OPERATING-SYSTEM ---> '${baseimage}'" # USER-CONFIRMATION if [ "${noInteraction}" != "true" ]; then - echo -n "Do you agree with all parameters above? (yes/no) " - read installRaspiblitzAnswer - if [ "$installRaspiblitzAnswer" != "yes" ] ; then - exit 1 - fi + echo -n "# Do you agree with all parameters above? (yes/no) " + read -r installRaspiblitzAnswer + [ "$installRaspiblitzAnswer" != "yes" ] && exit 1 fi -echo "Building RaspiBlitz ..." -echo -sleep 3 +echo -e "Building RaspiBlitz ...\n" +sleep 3 ## give time to cancel -# INSTALL TOR -echo "*** INSTALL TOR BY DEFAULT ***" -echo -sudo apt install -y dirmngr -echo "*** Adding KEYS deb.torproject.org ***" -# fix for v1.6 base image https://github.com/rootzoll/raspiblitz/issues/1906#issuecomment-755299759 -wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | sudo gpg --import -sudo gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add - -torKeyAvailable=$(sudo gpg --list-keys | grep -c "A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89") -if [ ${torKeyAvailable} -eq 0 ]; then - echo "!!! FAIL: Was not able to import deb.torproject.org key" - exit 1 -fi -echo "- OK key added" - -echo "*** Adding Tor Sources to sources.list ***" -torSourceListAvailable=$(sudo grep -c 'https://deb.torproject.org/torproject.org' /etc/apt/sources.list) -echo "torSourceListAvailable=${torSourceListAvailable}" -if [ ${torSourceListAvailable} -eq 0 ]; then - echo "- adding TOR sources ..." - if [ "${baseimage}" = "raspbian" ] || [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "armbian" ] || [ "${baseimage}" = "dietpi" ] || [ "${baseimage}" = "debian" ]; then - echo "- using https://deb.torproject.org/torproject.org bullseye" - echo "deb https://deb.torproject.org/torproject.org bullseye main" | sudo tee -a /etc/apt/sources.list - echo "deb-src https://deb.torproject.org/torproject.org bullseye main" | sudo tee -a /etc/apt/sources.list - elif [ "${baseimage}" = "ubuntu" ]; then - echo "- using https://deb.torproject.org/torproject.org focal" - echo "deb https://deb.torproject.org/torproject.org focal main" | sudo tee -a /etc/apt/sources.list - echo "deb-src https://deb.torproject.org/torproject.org focal main" | sudo tee -a /etc/apt/sources.list - else - echo "!!! FAIL: No Tor sources for os: ${baseimage}" - exit 1 - fi - echo "- OK sources added" -else - echo "Tor sources are available" -fi - -echo "*** Install & Enable Tor ***" -sudo apt update -y -sudo apt install tor tor-arm torsocks -y -echo +export DEBIAN_FRONTEND=noninteractive # FIXING LOCALES # https://github.com/rootzoll/raspiblitz/issues/138 # https://daker.me/2014/10/how-to-fix-perl-warning-setting-locale-failed-in-raspbian.html # https://stackoverflow.com/questions/38188762/generate-all-locales-in-a-docker-image -if [ "${baseimage}" = "raspbian" ] || [ "${baseimage}" = "dietpi" ] || \ - [ "${baseimage}" = "raspios_arm64" ]||[ "${baseimage}" = "debian_rpi64" ]; then - echo - echo "*** FIXING LOCALES FOR BUILD ***" +if [ "${baseimage}" = "raspios_arm64" ]||[ "${baseimage}" = "debian_rpi64" ]; then + echo -e "\n*** FIXING LOCALES FOR BUILD ***" sudo sed -i "s/^# en_US.UTF-8 UTF-8.*/en_US.UTF-8 UTF-8/g" /etc/locale.gen sudo sed -i "s/^# en_US ISO-8859-1.*/en_US ISO-8859-1/g" /etc/locale.gen sudo locale-gen export LANGUAGE=en_US.UTF-8 export LANG=en_US.UTF-8 - if [ "${baseimage}" = "raspbian" ] || [ "${baseimage}" = "dietpi" ]; then - export LC_ALL=en_US.UTF-8 - - # https://github.com/rootzoll/raspiblitz/issues/684 - sudo sed -i "s/^ SendEnv LANG LC.*/# SendEnv LANG LC_*/g" /etc/ssh/ssh_config - - # remove unnecessary files - sudo rm -rf /home/pi/MagPi - # https://www.reddit.com/r/linux/comments/lbu0t1/microsoft_repo_installed_on_all_raspberry_pis/ - sudo rm -f /etc/apt/sources.list.d/vscode.list - sudo rm -f /etc/apt/trusted.gpg.d/microsoft.gpg - fi if [ ! -f /etc/apt/sources.list.d/raspi.list ]; then echo "# Add the archive.raspberrypi.org/debian/ to the sources.list" echo "deb http://archive.raspberrypi.org/debian/ bullseye main" | sudo tee /etc/apt/sources.list.d/raspi.list fi fi -echo "*** Remove not needed packages ***" -sudo apt remove -y --purge libreoffice* oracle-java* chromium-browser nuscratch scratch sonic-pi minecraft-pi plymouth python2 vlc -sudo apt clean -sudo apt -y autoremove +echo "*** Remove unnecessary packages ***" +sudo apt remove --purge -y libreoffice* oracle-java* chromium-browser nuscratch scratch sonic-pi plymouth python2 vlc +sudo apt clean -y +sudo apt autoremove -y -echo -echo "*** Python DEFAULT libs & dependencies ***" +echo -e "\n*** UPDATE Debian***" +sudo apt update -y +sudo apt upgrade -f -y -if [ -f "/usr/bin/python3.8" ]; then - # make sure /usr/bin/python exists (and calls Python3.7 in bullseye) - sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 - echo "python calls python3.8" -elif [ -f "/usr/bin/python3.9" ]; then +echo -e "\n*** SOFTWARE UPDATE ***" +# based on https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html#software-update +# htop git curl bash-completion vim jq dphys-swapfile bsdmainutils -> helpers +# autossh telnet vnstat -> network tools bandwidth monitoring for future statistics +# parted dosfstolls -> prepare for format data drive +# btrfs-progs -> prepare for BTRFS data drive raid +# fbi -> prepare for display graphics mode. https://github.com/rootzoll/raspiblitz/pull/334 +# sysbench -> prepare for powertest +# build-essential -> check for build dependencies on Ubuntu, Armbian +# dialog -> dialog bc python3-dialog +# rsync -> is needed to copy from HDD +# net-tools -> ifconfig +# xxd -> display hex codes +# netcat -> for proxy +# openssh-client openssh-sftp-server sshpass -> install OpenSSH client + server +# psmisc -> install killall, fuser +# ufw -> firewall +# sqlite3 -> database +general_utils="htop git curl bash-completion vim jq dphys-swapfile bsdmainutils autossh telnet vnstat parted dosfstools btrfs-progs fbi sysbench build-essential dialog bc python3-dialog" +python_dependencies="python3-venv python3-dev python3-wheel python3-jinja2 python3-pip" +server_utils="rsync net-tools xxd netcat openssh-client openssh-sftp-server sshpass psmisc ufw sqlite3" +[ "${baseimage}" = "armbian" ] && armbian_dependencies="armbian-config" # add armbian-config +sudo apt install -y ${general_utils} ${python_dependencies} ${server_utils} ${armbian_dependencies} +sudo apt clean -y +sudo apt autoremove -y + +echo -e "\n*** Python DEFAULT libs & dependencies ***" +# make sure /usr/bin/pip exists (and calls pip3 in Debian Buster) +sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 +# 1. libs (for global python scripts) +# grpcio==1.42.0 googleapis-common-protos==1.53.0 toml==0.10.2 j2cli==0.3.10 requests[socks]==2.21.0 +# 2. For TorBox bridges python scripts (pip3) https://github.com/radio24/TorBox/blob/master/requirements.txt +# pytesseract mechanize PySocks urwid Pillow requests +# 3. Nyx +# setuptools +python_libs="grpcio==1.42.0 googleapis-common-protos==1.53.0 toml==0.10.2 j2cli==0.3.10 requests[socks]==2.21.0" +torbox_libs="pytesseract mechanize PySocks urwid Pillow requests setuptools" +sudo -H python3 -m pip install --upgrade pip +sudo -H python3 -m pip install ${python_libs} ${torbox_libs} + +if [ -f "/usr/bin/python3.9" ]; then # use python 3.9 if available sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9 1 - sudo ln -s /usr/bin/python3.9 /usr/bin/python3.8 echo "python calls python3.9" +elif [ -f "/usr/bin/python3.10" ]; then + # use python 3.10 if available + sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1 + sudo ln -s /usr/bin/python3.10 /usr/bin/python3.9 + echo "python calls python3.10" else echo "!!! FAIL !!!" echo "There is no tested version of python present" exit 1 fi -# for setup shell scripts -sudo apt -y install dialog bc python3-dialog - -# libs (for global python scripts) -sudo -H python3 -m pip install --upgrade pip -sudo -H python3 -m pip install grpcio==1.38.1 -sudo -H python3 -m pip install googleapis-common-protos==1.53.0 -sudo -H python3 -m pip install toml==0.10.1 -sudo -H python3 -m pip install j2cli==0.3.10 -sudo -H python3 -m pip install requests[socks]==2.21.0 - -echo -echo "*** UPDATE Debian***" -sudo apt update -y -sudo apt upgrade -f -y - -echo -echo "*** PREPARE ${baseimage} ***" +echo -e "\n*** PREPARE ${baseimage} ***" # make sure the pi user is present -if [ "$(compgen -u | grep -c dietpi)" -gt 0 ];then - echo "# Renaming dietpi user to pi" - sudo usermod -l pi dietpi -elif [ "$(compgen -u | grep -c pi)" -eq 0 ];then +if [ "$(compgen -u | grep -c pi)" -eq 0 ];then echo "# Adding the user pi" sudo adduser --disabled-password --gecos "" pi sudo adduser pi sudo fi # special prepare when Raspbian -if [ "${baseimage}" = "raspbian" ]||[ "${baseimage}" = "raspios_arm64" ]||\ - [ "${baseimage}" = "debian_rpi64" ]; then +if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then - echo - echo "*** PREPARE RASPBIAN ***" - sudo apt install -y raspi-config + echo -e "\n*** PREPARE RASPBERRY OS VARIANTS ***" + sudo apt install -y raspi-config # do memory split (16MB) sudo raspi-config nonint do_memory_split 16 # set to wait until network is available on boot (0 seems to yes) sudo raspi-config nonint do_boot_wait 0 # set WIFI country so boot does not block - if [ "${modeWifi}" != "false" ]; then - # this will undo the softblock of rfkill on RaspiOS - sudo raspi-config nonint do_wifi_country $modeWifi - fi + # this will undo the softblock of rfkill on RaspiOS + [ "${modeWifi}" != "false" ] && sudo raspi-config nonint do_wifi_country $modeWifi # see https://github.com/rootzoll/raspiblitz/issues/428#issuecomment-472822840 configFile="/boot/config.txt" @@ -370,8 +294,7 @@ if [ $(uname -a | grep -c 'tegra') -gt 0 ] ; then sudo systemctl set-default multi-user.target fi -echo -echo "*** CONFIG ***" +echo -e "\n*** CONFIG ***" # based on https://raspibolt.github.io/raspibolt/raspibolt_20_pi.html#raspi-config # set new default password for root user @@ -379,9 +302,8 @@ echo "root:raspiblitz" | sudo chpasswd echo "pi:raspiblitz" | sudo chpasswd # prepare auto-start of 00infoLCD.sh script on pi user login (just kicks in if auto-login of pi is activated in HDMI or LCD mode) -if [ "${baseimage}" = "raspbian" ]||[ "${baseimage}" = "raspios_arm64" ]||\ - [ "${baseimage}" = "debian_rpi64" ]||[ "${baseimage}" = "armbian" ]||\ - [ "${baseimage}" = "ubuntu" ]; then +if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ] || \ + [ "${baseimage}" = "armbian" ] || [ "${baseimage}" = "ubuntu" ]; then homeFile=/home/pi/.bashrc autostartDone=$(grep -c "automatic start the LCD" $homeFile) if [ ${autostartDone} -eq 0 ]; then @@ -396,188 +318,118 @@ if [ "${baseimage}" = "raspbian" ]||[ "${baseimage}" = "raspios_arm64" ]||\ else echo "autostart LCD already in $homeFile" fi -elif [ "${baseimage}" = "dietpi" ]; then - homeFile=/home/dietpi/.bashrc - autostartDone=$(grep -c "automatic start the LCD" $homeFile) - if [ ${autostartDone} -eq 0 ]; then - # bash autostart for dietpi - sudo bash -c 'echo "# automatic start the LCD info loop" >> /home/dietpi/.bashrc' - sudo bash -c 'echo "SCRIPT=/home/admin/00infoLCD.sh" >> /home/dietpi/.bashrc' - sudo bash -c 'echo "# replace shell with script => logout when exiting script" >> /home/dietpi/.bashrc' - sudo bash -c 'echo "exec \$SCRIPT" >> /home/dietpi/.bashrc' - echo "autostart LCD added to $homeFile" - else - echo "autostart LCD already in $homeFile" - fi else echo "WARN: Script Autostart not available for baseimage(${baseimage}) - may just run on 'headless'" fi # change log rotates # see https://github.com/rootzoll/raspiblitz/issues/394#issuecomment-471535483 -echo "/var/log/syslog" >> ./rsyslog -echo "{" >> ./rsyslog -echo " rotate 7" >> ./rsyslog -echo " daily" >> ./rsyslog -echo " missingok" >> ./rsyslog -echo " notifempty" >> ./rsyslog -echo " delaycompress" >> ./rsyslog -echo " compress" >> ./rsyslog -echo " postrotate" >> ./rsyslog -echo " invoke-rc.d rsyslog rotate > /dev/null" >> ./rsyslog -echo " endscript" >> ./rsyslog -echo "}" >> ./rsyslog -echo >> ./rsyslog -echo "/var/log/mail.info" >> ./rsyslog -echo "/var/log/mail.warn" >> ./rsyslog -echo "/var/log/mail.err" >> ./rsyslog -echo "/var/log/mail.log" >> ./rsyslog -echo "/var/log/daemon.log" >> ./rsyslog -echo "{" >> ./rsyslog -echo " rotate 4" >> ./rsyslog -echo " size=100M" >> ./rsyslog -echo " missingok" >> ./rsyslog -echo " notifempty" >> ./rsyslog -echo " compress" >> ./rsyslog -echo " delaycompress" >> ./rsyslog -echo " sharedscripts" >> ./rsyslog -echo " postrotate" >> ./rsyslog -echo " invoke-rc.d rsyslog rotate > /dev/null" >> ./rsyslog -echo " endscript" >> ./rsyslog -echo "}" >> ./rsyslog -echo >> ./rsyslog -echo "/var/log/kern.log" >> ./rsyslog -echo "/var/log/auth.log" >> ./rsyslog -echo "{" >> ./rsyslog -echo " rotate 4" >> ./rsyslog -echo " size=100M" >> ./rsyslog -echo " missingok" >> ./rsyslog -echo " notifempty" >> ./rsyslog -echo " compress" >> ./rsyslog -echo " delaycompress" >> ./rsyslog -echo " sharedscripts" >> ./rsyslog -echo " postrotate" >> ./rsyslog -echo " invoke-rc.d rsyslog rotate > /dev/null" >> ./rsyslog -echo " endscript" >> ./rsyslog -echo "}" >> ./rsyslog -echo >> ./rsyslog -echo "/var/log/user.log" >> ./rsyslog -echo "/var/log/lpr.log" >> ./rsyslog -echo "/var/log/cron.log" >> ./rsyslog -echo "/var/log/debug" >> ./rsyslog -echo "/var/log/messages" >> ./rsyslog -echo "{" >> ./rsyslog -echo " rotate 4" >> ./rsyslog -echo " weekly" >> ./rsyslog -echo " missingok" >> ./rsyslog -echo " notifempty" >> ./rsyslog -echo " compress" >> ./rsyslog -echo " delaycompress" >> ./rsyslog -echo " sharedscripts" >> ./rsyslog -echo " postrotate" >> ./rsyslog -echo " invoke-rc.d rsyslog rotate > /dev/null" >> ./rsyslog -echo " endscript" >> ./rsyslog -echo "}" >> ./rsyslog +echo " +/var/log/syslog +{ + rotate 7 + daily + missingok + notifempty + delaycompress + compress + postrotate + invoke-rc.d rsyslog rotate > /dev/null + endscript +} + +/var/log/mail.info +/var/log/mail.warn +/var/log/mail.err +/var/log/mail.log +/var/log/daemon.log +{ + rotate 4 + size=100M + missingok + notifempty + compress + delaycompress + sharedscripts + postrotate + invoke-rc.d rsyslog rotate > /dev/null + enscript +} + + +/var/log/kern.log +/var/log/auth.log +{ + rotate 4 + size=100M + missingok + notifempty + compress + delaycompress + sharedscripts + postrotate + invoke-rc.d rsyslog rotate > /dev/null + endscript +} + +/var/log/user.log +/var/log/lpr.log +/var/log/cron.log +/var/log/debug +/var/log/messages +{ + rotate 4 + weekly + missingok + notifempty + compress + delaycompress + sharedscripts + postrotate + invoke-rc.d rsyslog rotate > /dev/null + endscript +} +" | sudo tee ./rsyslog sudo mv ./rsyslog /etc/logrotate.d/rsyslog sudo chown root:root /etc/logrotate.d/rsyslog sudo service rsyslog restart -echo -echo "*** SOFTWARE UPDATE ***" -# based on https://raspibolt.github.io/raspibolt/raspibolt_20_pi.html#software-update - -# installs like on RaspiBolt -sudo apt install -y htop git curl bash-completion vim jq dphys-swapfile bsdmainutils - -# installs bandwidth monitoring for future statistics -sudo apt install -y vnstat - -# prepare for format data drive -sudo apt install -y parted dosfstools - -# prepare for BTRFS data drive raid -sudo apt install -y btrfs-progs - -# network tools -sudo apt install -y autossh telnet - -# prepare for display graphics mode -# see https://github.com/rootzoll/raspiblitz/pull/334 -sudo apt install -y fbi - -# prepare for powertest -sudo apt install -y sysbench - -# check for dependencies on DietPi, Ubuntu, Armbian -sudo apt install -y build-essential - -# add armbian-config -if [ "${baseimage}" = "armbian" ]; then - # add armbian config - sudo apt install armbian-config -y -fi - -# dependencies for python -sudo apt install -y python3-venv python3-dev python3-wheel python3-jinja2 python3-pip - -# make sure /usr/bin/pip exists (and calls pip3 in Debian bullseye) -sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 - -# rsync is needed to copy from HDD -sudo apt install -y rsync -# install ifconfig -sudo apt install -y net-tools -#to display hex codes -sudo apt install -y xxd -# setuptools needed for Nyx -sudo pip install setuptools -# netcat for 00infoBlitz.sh -sudo apt install -y netcat -# install OpenSSH client + server -sudo apt install -y openssh-client -sudo apt install -y openssh-sftp-server -sudo apt install -y sshpass -# install killall, fuser -sudo apt install -y psmisc -# install firewall -sudo apt install -y ufw -# make sure sqlite3 is available -sudo apt install -y sqlite3 - -sudo apt clean -sudo apt -y autoremove - -echo -echo "*** ADDING MAIN USER admin ***" -# based on https://raspibolt.org/system-configuration.html#add-users +echo -e "\n*** ADDING MAIN USER admin ***" +# based on https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html#add-users # using the default password 'raspiblitz' sudo adduser --disabled-password --gecos "" admin echo "admin:raspiblitz" | sudo chpasswd sudo adduser admin sudo sudo chsh admin -s /bin/bash - # configure sudo for usage without password entry echo '%sudo ALL=(ALL) NOPASSWD:ALL' | sudo EDITOR='tee -a' visudo +# check if group "admin" was created +if [ $(sudo cat /etc/group | grep -c "^admin") -lt 1 ]; then + echo -e "\nMissing group admin - creating it ..." + sudo /usr/sbin/groupadd --force --gid 1002 admin + sudo usermod -a -G admin admin +else + echo -e "\nOK group admin exists" +fi -# WRITE BASIC raspiblitz.info to sdcard -# if further info gets added .. make sure to keep that on: blitz.preparerelease.sh -echo "baseimage=${baseimage}" > /home/admin/raspiblitz.info -echo "cpu=${cpu}" >> /home/admin/raspiblitz.info -echo "displayClass=headless" >> /home/admin/raspiblitz.info -sudo mv ./raspiblitz.info /home/admin/raspiblitz.info -sudo chmod 755 /home/admin/raspiblitz.info - -echo -echo "*** ADDING SERVICE USER bitcoin" -# based on https://raspibolt.org/system-configuration.html#add-users +echo -e "\n*** ADDING SERVICE USER bitcoin" +# based on https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html#add-users # create user and set default password for user sudo adduser --disabled-password --gecos "" bitcoin echo "bitcoin:raspiblitz" | sudo chpasswd # make home directory readable sudo chmod 755 /home/bitcoin -echo -echo "*** ADDING GROUPS FOR CREDENTIALS STORE ***" +# WRITE BASIC raspiblitz.info to sdcard +# if further info gets added .. make sure to keep that on: blitz.preparerelease.sh +sudo touch /home/admin/raspiblitz.info +echo "baseimage=${baseimage}" | tee raspiblitz.info +echo "cpu=${cpu}" | tee -a raspiblitz.info +echo "displayClass=headless" | tee -a raspiblitz.info +sudo mv raspiblitz.info /home/admin/ +sudo chmod 755 /home/admin/raspiblitz.info + +echo -e "\n*** ADDING GROUPS FOR CREDENTIALS STORE ***" # access to credentials (e.g. macaroon files) in a central location is managed with unix groups and permissions sudo /usr/sbin/groupadd --force --gid 9700 lndadmin sudo /usr/sbin/groupadd --force --gid 9701 lndinvoice @@ -588,64 +440,45 @@ sudo /usr/sbin/groupadd --force --gid 9705 lndsigner sudo /usr/sbin/groupadd --force --gid 9706 lndwalletkit sudo /usr/sbin/groupadd --force --gid 9707 lndrouter -echo -echo "*** SHELL SCRIPTS & ASSETS ***" - +echo -e "\n*** SHELL SCRIPTS & ASSETS ***" # copy raspiblitz repo from github cd /home/admin/ || exit 1 sudo -u admin git config --global user.name "${githubUser}" sudo -u admin git config --global user.email "johndoe@example.com" -sudo rm -rf /home/admin/raspiblitz -sudo -u admin git clone -b ${githubBranch} https://github.com/${githubUser}/raspiblitz.git -sudo -u admin cp -r /home/admin/raspiblitz/home.admin/assets /home/admin/ +sudo -u admin rm -rf /home/admin/raspiblitz +sudo -u admin git clone -b "${githubBranch}" https://github.com/${githubUser}/raspiblitz.git +sudo -u admin cp -r /home/admin/raspiblitz/home.admin/*.* /home/admin sudo -u admin cp /home/admin/raspiblitz/home.admin/.tmux.conf /home/admin -sudo -u admin cp /home/admin/raspiblitz/home.admin/*.* /home/admin -sudo -u admin chmod 755 *.sh +sudo -u admin cp -r /home/admin/raspiblitz/home.admin/assets /home/admin/ +sudo -u admin chmod +x *.sh sudo -u admin cp -r /home/admin/raspiblitz/home.admin/config.scripts /home/admin/ -sudo -u admin chmod 755 /home/admin/config.scripts/*.sh +sudo -u admin chmod +x /home/admin/config.scripts/*.sh sudo -u admin cp -r /home/admin/raspiblitz/home.admin/setup.scripts /home/admin/ -sudo -u admin chmod 755 /home/admin/setup.scripts/*.sh +sudo -u admin chmod +x /home/admin/setup.scripts/*.sh # install newest version of BlitzPy -blitzpy_wheel=$(ls -tR /home/admin/raspiblitz/home.admin/BlitzPy/dist | grep -E "*any.whl" | tail -n 1) -blitzpy_version=$(echo ${blitzpy_wheel} | grep -oE "([0-9]\.[0-9]\.[0-9])") -echo -echo "*** INSTALLING BlitzPy Version: ${blitzpy_version} ***" -sudo -H /usr/bin/python -m pip install "/home/admin/raspiblitz/home.admin/BlitzPy/dist/${blitzpy_wheel}" >/dev/null 2>&1 +blitzpy_wheel=$(ls -tR /home/admin/raspiblitz/home.admin/BlitzPy/dist | grep -E "any.whl" | tail -n 1) +blitzpy_version=$(echo "${blitzpy_wheel}" | grep -oE "([0-9]\.[0-9]\.[0-9])") +echo -e "\n*** INSTALLING BlitzPy Version: ${blitzpy_version} ***" +sudo -H /usr/bin/python -m pip install "/home/admin/raspiblitz/home.admin/BlitzPy/dist/${blitzpy_wheel}" >/dev/null 2>&1 # make sure lndlibs are patched for compatibility for both Python2 and Python3 -if ! grep -Fxq "from __future__ import absolute_import" /home/admin/config.scripts/lndlibs/rpc_pb2_grpc.py; then - sed -i -E '1 a from __future__ import absolute_import' /home/admin/config.scripts/lndlibs/rpc_pb2_grpc.py -fi -if ! grep -Eq "^from . import.*" /home/admin/config.scripts/lndlibs/rpc_pb2_grpc.py; then - sed -i -E 's/^(import.*_pb2)/from . \1/' /home/admin/config.scripts/lndlibs/rpc_pb2_grpc.py -fi +file="/home/admin/config.scripts/lndlibs/rpc_pb2_grpc.py" +! grep -Fxq "from __future__ import absolute_import" "${file}" && sed -i -E '1 a from __future__ import absolute_import' "${file}" +! grep -Eq "^from . import.*" "${file}" && sed -i -E 's/^(import.*_pb2)/from . \1/' "${file}" # add /sbin to path for all sudo bash -c "echo 'PATH=\$PATH:/sbin' >> /etc/profile" # replace boot splash image when raspbian -if [ "${baseimage}" == "raspbian" ]; then - echo "* replacing boot splash" - sudo cp /home/admin/raspiblitz/pictures/splash.png /usr/share/plymouth/themes/pix/splash.png -fi +[ "${baseimage}" = "raspios_arm64" ] && { echo "* replacing boot splash"; sudo cp /home/admin/raspiblitz/pictures/splash.png /usr/share/plymouth/themes/pix/splash.png; } -echo -echo "*** RASPIBLITZ EXTRAS ***" +echo -e "\n*** RASPIBLITZ EXTRAS ***" -# for background processes -sudo apt -y install screen - -# for multiple (detachable/background) sessions when using SSH -# https://github.com/rootzoll/raspiblitz/issues/990 -sudo apt -y install tmux - -# optimization for torrent download -sudo bash -c "echo 'net.core.rmem_max = 4194304' >> /etc/sysctl.conf" -sudo bash -c "echo 'net.core.wmem_max = 1048576' >> /etc/sysctl.conf" - -# install a command-line fuzzy finder (https://github.com/junegunn/fzf) -sudo apt -y install fzf +# screen for background processes +# tmux for multiple (detachable/background) sessions when using SSH https://github.com/rootzoll/raspiblitz/issues/990 +# fzf install a command-line fuzzy finder (https://github.com/junegunn/fzf) +sudo apt -y install tmux screen fzf sudo bash -c "echo '' >> /home/admin/.bashrc" sudo bash -c "echo '# https://github.com/rootzoll/raspiblitz/issues/1784' >> /home/admin/.bashrc" @@ -662,10 +495,9 @@ if ! grep -Eq "^[[:space:]]*PS1.*₿" /home/admin/.bashrc; then sudo sed -i '/^unset color_prompt force_color_prompt$/i fi' /home/admin/.bashrc fi +echo -e "\n*** FUZZY FINDER KEY BINDINGS ***" homeFile=/home/admin/.bashrc -keyBindings="source /usr/share/doc/fzf/examples/key-bindings.bash" -keyBindingsDone=$(grep -c "$keyBindings" $homeFile) - +keyBindingsDone=$(grep -c "source /usr/share/doc/fzf/examples/key-bindings.bash" $homeFile) if [ ${keyBindingsDone} -eq 0 ]; then sudo bash -c "echo 'source /usr/share/doc/fzf/examples/key-bindings.bash' >> /home/admin/.bashrc" echo "key-bindings added to $homeFile" @@ -673,10 +505,9 @@ else echo "key-bindings already in $homeFile" fi +echo -e "\n*** AUTOSTART ADMIN SSH MENUS ***" homeFile=/home/admin/.bashrc -autostart="automatically start main menu" -autostartDone=$(grep -c "$autostart" $homeFile) - +autostartDone=$(grep -c "automatically start main menu" $homeFile) if [ ${autostartDone} -eq 0 ]; then # bash autostart for admin sudo bash -c "echo '# shortcut commands' >> /home/admin/.bashrc" @@ -684,71 +515,58 @@ if [ ${autostartDone} -eq 0 ]; then sudo bash -c "echo '# automatically start main menu for admin unless' >> /home/admin/.bashrc" sudo bash -c "echo '# when running in a tmux session' >> /home/admin/.bashrc" sudo bash -c "echo 'if [ -z \"\$TMUX\" ]; then' >> /home/admin/.bashrc" - sudo bash -c "echo ' ./00raspiblitz.sh' >> /home/admin/.bashrc" + sudo bash -c "echo ' ./00raspiblitz.sh newsshsession' >> /home/admin/.bashrc" sudo bash -c "echo 'fi' >> /home/admin/.bashrc" echo "autostart added to $homeFile" else echo "autostart already in $homeFile" fi -sudo bash -c "echo '' >> /home/admin/.bashrc" -sudo bash -c "echo '# Raspiblitz' >> /home/admin/.bashrc" - -echo -echo "*** SWAP FILE ***" -# based on https://raspibolt.github.io/raspibolt/raspibolt_20_pi.html#move-swap-file +echo -e "\n*** SWAP FILE ***" +# based on https://stadicus.github.io/RaspiBolt/raspibolt_20_pi.html#move-swap-file # but just deactivating and deleting old (will be created alter when user adds HDD) - sudo dphys-swapfile swapoff sudo dphys-swapfile uninstall -echo -echo "*** INCREASE OPEN FILE LIMIT ***" -# based on https://raspibolt.github.io/raspibolt/raspibolt_21_security.html#increase-your-open-files-limit - +echo -e "\n*** INCREASE OPEN FILE LIMIT ***" +# based on https://stadicus.github.io/RaspiBolt/raspibolt_21_security.html#increase-your-open-files-limit sudo sed --in-place -i "56s/.*/* soft nofile 128000/" /etc/security/limits.conf sudo bash -c "echo '* hard nofile 128000' >> /etc/security/limits.conf" sudo bash -c "echo 'root soft nofile 128000' >> /etc/security/limits.conf" sudo bash -c "echo 'root hard nofile 128000' >> /etc/security/limits.conf" sudo bash -c "echo '# End of file' >> /etc/security/limits.conf" - sudo sed --in-place -i "23s/.*/session required pam_limits.so/" /etc/pam.d/common-session - sudo sed --in-place -i "25s/.*/session required pam_limits.so/" /etc/pam.d/common-session-noninteractive sudo bash -c "echo '# end of pam-auth-update config' >> /etc/pam.d/common-session-noninteractive" - # *** fail2ban *** # based on https://raspibolt.github.io/raspibolt/raspibolt_21_security.html#fail2ban echo "*** HARDENING ***" -sudo apt install -y --no-install-recommends python3-systemd fail2ban +sudo apt install -y --no-install-recommends python3-systemd fail2ban -# *** CACHE DISK IN RAM *** +# *** CACHE DISK IN RAM & KEYVALUE-STORE*** echo "Activating CACHE RAM DISK ... " -sudo /home/admin/config.scripts/blitz.cache.sh on +sudo /home/admin/_cache.sh ramdisk on +sudo /home/admin/_cache.sh keyvalue on + +# *** Wifi, Bluetooth & other RaspberryPi configs *** +if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then -# *** Wifi, Bluetooth & other configs *** -if [ "${baseimage}" = "raspbian" ]||[ "${baseimage}" = "raspios_arm64" ]||\ - [ "${baseimage}" = "debian_rpi64" ]; then - if [ "${modeWifi}" == "false" ]; then - echo - echo "*** DISABLE WIFI ***" + echo -e "\n*** DISABLE WIFI ***" sudo systemctl disable wpa_supplicant.service sudo ifconfig wlan0 down fi - echo - echo "*** DISABLE BLUETOOTH ***" - + echo -e "\n*** DISABLE BLUETOOTH ***" configFile="/boot/config.txt" disableBT="dtoverlay=disable-bt" disableBTDone=$(grep -c "$disableBT" $configFile) - if [ ${disableBTDone} -eq 0 ]; then + if [ "${disableBTDone}" -eq 0 ]; then # disable bluetooth module - echo >> $configFile - echo "# Raspiblitz" >> $configFile + echo "" | sudo tee -a $configFile + echo "# Raspiblitz" | sudo tee -a $configFile echo 'dtoverlay=pi3-disable-bt' | sudo tee -a $configFile echo 'dtoverlay=disable-bt' | sudo tee -a $configFile else @@ -761,27 +579,24 @@ if [ "${baseimage}" = "raspbian" ]||[ "${baseimage}" = "raspios_arm64" ]||\ # remove bluetooth packages sudo apt remove -y --purge pi-bluetooth bluez bluez-firmware - echo # disable audio - echo "*** DISABLE AUDIO (snd_bcm2835) ***" + echo -e "\n*** DISABLE AUDIO (snd_bcm2835) ***" sudo sed -i "s/^dtparam=audio=on/# dtparam=audio=on/g" /boot/config.txt - echo - + # disable DRM VC4 V3D - echo "*** DISABLE DRM VC4 V3D driver ***" + echo -e "\n*** DISABLE DRM VC4 V3D driver ***" dtoverlay=vc4-fkms-v3d - sudo sed -i "s/^dtoverlay=vc4-fkms-v3d/# dtoverlay=vc4-fkms-v3d/g" /boot/config.txt - echo + sudo sed -i "s/^dtoverlay=${dtoverlay}/# dtoverlay=${dtoverlay}/g" /boot/config.txt # I2C fix (make sure dtparam=i2c_arm is not on) # see: https://github.com/rootzoll/raspiblitz/issues/1058#issuecomment-739517713 - sudo sed -i "s/^dtparam=i2c_arm=.*//g" /boot/config.txt + sudo sed -i "s/^dtparam=i2c_arm=.*//g" /boot/config.txt fi # *** FATPACK *** (can be activated by parameter - see details at start of script) if [ "${fatpack}" == "true" ]; then - echo "*** FATPACK ***" + echo -e "\n*** FATPACK ***" echo "* Adding nodeJS Framework ..." sudo /home/admin/config.scripts/bonus.nodejs.sh on if [ "$?" != "0" ]; then @@ -789,27 +604,13 @@ if [ "${fatpack}" == "true" ]; then exit 1 fi echo "* Optional Packages (may be needed for extended features)" - sudo apt-get install -y qrencode - sudo apt-get install -y btrfs-tools - sudo apt-get install -y secure-delete - sudo apt-get install -y fbi - sudo apt-get install -y ssmtp - sudo apt-get install -y unclutter xterm python3-pyqt5 - sudo apt-get install -y xfonts-terminus - sudo apt-get install -y nginx apache2-utils - sudo apt-get install -y nginx - sudo apt-get install -y python3-jinja2 - sudo apt-get install -y socat - sudo apt-get install -y libatlas-base-dev - sudo apt-get install -y mariadb-server mariadb-client - sudo apt-get install -y hexyl - sudo apt-get install -y autossh + sudo apt install -y qrencode btrfs-tools secure-delete fbi ssmtp unclutter xterm python3-pyqt5 xfonts-terminus apache2-utils nginx python3-jinja2 socat libatlas-base-dev hexyl autossh # *** UPDATE FALLBACK NODE LIST (only as part of fatpack) *** see https://github.com/rootzoll/raspiblitz/issues/1888 echo "*** FALLBACK NODE LIST ***" sudo -u admin curl -H "Accept: application/json; indent=4" https://bitnodes.io/api/v1/snapshots/latest/ -o /home/admin/fallback.nodes byteSizeList=$(sudo -u admin stat -c %s /home/admin/fallback.nodes) - if [ ${#byteSizeList} -eq 0 ] || [ ${byteSizeList} -lt 10240 ]; then + if [ ${#byteSizeList} -eq 0 ] || [ ${byteSizeList} -lt 10240 ]; then echo "WARN: Failed downloading fresh FALLBACK NODE LIST --> https://bitnodes.io/api/v1/snapshots/latest/" sudo rm /home/admin/fallback.nodes 2>/dev/null sudo cp /home/admin/assets/fallback.nodes /home/admin/fallback.nodes @@ -821,19 +622,26 @@ else fi # *** BOOTSTRAP *** -echo -echo "*** RASPI BOOTSTRAP SERVICE ***" +echo -e "\n*** RASPI BOOTSTRAP SERVICE ***" sudo chmod +x /home/admin/_bootstrap.sh sudo cp /home/admin/assets/bootstrap.service /etc/systemd/system/bootstrap.service sudo systemctl enable bootstrap -# *** BACKGROUND *** -echo -echo "*** RASPI BACKGROUND SERVICE ***" +# *** BACKGROUND TASKS *** +echo -e "\n*** RASPI BACKGROUND SERVICE ***" sudo chmod +x /home/admin/_background.sh sudo cp /home/admin/assets/background.service /etc/systemd/system/background.service sudo systemctl enable background +# *** BACKGROUND SCAN *** +/home/admin/_background.scan.sh install + +####### +# TOR # +####### +echo +/home/admin/config.scripts/tor.install.sh install || exit 1 + ########### # BITCOIN # ########### @@ -844,263 +652,38 @@ echo # LND # ####### echo -/home/admin/config.scripts/lnd.install.sh install || exit 1 +#if [ "${fatpack}" == "true" ]; then + /home/admin/config.scripts/lnd.install.sh install || exit 1 +#else +# echo -e "\nSkipping LND install - let user install later if needed ..." +#fi ############### # C-LIGHTNING # ############### echo -/home/admin/config.scripts/cl.install.sh install || exit 1 +#if [ "${fatpack}" == "true" ]; then + /home/admin/config.scripts/cl.install.sh install || exit 1 +#else +# echo -e "\nSkipping c-lightning install - let user install later if needed ..." +#fi echo echo "*** raspiblitz.info ***" sudo cat /home/admin/raspiblitz.info # *** RASPIBLITZ IMAGE READY INFO *** -echo -echo "**********************************************" +echo -e "\n**********************************************" echo "BASIC SD CARD BUILD DONE" -echo "**********************************************" -echo +echo -e "**********************************************\n" echo "Your SD Card Image for RaspiBlitz is ready (might still do display config)." echo "Take the chance & look thru the output above if you can spot any errors or warnings." -echo -echo "IMPORTANT IF WANT TO MAKE A RELEASE IMAGE FROM THIS BUILD:" +echo -e "\nIMPORTANT IF WANT TO MAKE A RELEASE IMAGE FROM THIS BUILD:" echo "1. login fresh --> user:admin password:raspiblitz" -echo "2. run --> release" -echo +echo -e "2. run --> release\n" # (do last - because might trigger reboot) -if [ "${displayClass}" != "headless" ] || [ "${baseimage}" = "raspbian" ] || [ "${baseimage}" = "raspios_arm64" ]; then - echo "*** ADDITIONAL DISPLAY OPTIONS ***" - echo "- calling: blitz.display.sh set-display ${displayClass}" - sudo /home/admin/config.scripts/blitz.display.sh set-display ${displayClass} - sudo /home/admin/config.scripts/blitz.display.sh rotate 1 -fi - -echo "# BUILD DONE - see above" - -# optimization for torrent download -sudo bash -c "echo 'net.core.rmem_max = 4194304' >> /etc/sysctl.conf" -sudo bash -c "echo 'net.core.wmem_max = 1048576' >> /etc/sysctl.conf" - -# install a command-line fuzzy finder (https://github.com/junegunn/fzf) -sudo apt -y install fzf - -sudo bash -c "echo '' >> /home/admin/.bashrc" -sudo bash -c "echo '# https://github.com/rootzoll/raspiblitz/issues/1784' >> /home/admin/.bashrc" -sudo bash -c "echo 'NG_CLI_ANALYTICS=ci' >> /home/admin/.bashrc" - -homeFile=/home/admin/.bashrc -keyBindings="source /usr/share/doc/fzf/examples/key-bindings.bash" -keyBindingsDone=$(grep -c "$keyBindings" $homeFile) - -if [ ${keyBindingsDone} -eq 0 ]; then - sudo bash -c "echo 'source /usr/share/doc/fzf/examples/key-bindings.bash' >> /home/admin/.bashrc" - echo "key-bindings added to $homeFile" -else - echo "key-bindings already in $homeFile" -fi - -homeFile=/home/admin/.bashrc -autostart="automatically start main menu" -autostartDone=$(grep -c "$autostart" $homeFile) - -if [ ${autostartDone} -eq 0 ]; then - # bash autostart for admin - sudo bash -c "echo '# shortcut commands' >> /home/admin/.bashrc" - sudo bash -c "echo 'source /home/admin/_commands.sh' >> /home/admin/.bashrc" - sudo bash -c "echo '# automatically start main menu for admin unless' >> /home/admin/.bashrc" - sudo bash -c "echo '# when running in a tmux session' >> /home/admin/.bashrc" - sudo bash -c "echo 'if [ -z \"\$TMUX\" ]; then' >> /home/admin/.bashrc" - sudo bash -c "echo ' ./00raspiblitz.sh' >> /home/admin/.bashrc" - sudo bash -c "echo 'fi' >> /home/admin/.bashrc" - echo "autostart added to $homeFile" -else - echo "autostart already in $homeFile" -fi - -sudo bash -c "echo '' >> /home/admin/.bashrc" -sudo bash -c "echo '# Raspiblitz' >> /home/admin/.bashrc" - -echo -echo "*** SWAP FILE ***" -# based on https://raspibolt.github.io/raspibolt/raspibolt_20_pi.html#move-swap-file -# but just deactivating and deleting old (will be created alter when user adds HDD) - -sudo dphys-swapfile swapoff -sudo dphys-swapfile uninstall - -echo -echo "*** INCREASE OPEN FILE LIMIT ***" -# based on https://raspibolt.github.io/raspibolt/raspibolt_21_security.html#increase-your-open-files-limit - -sudo sed --in-place -i "56s/.*/* soft nofile 128000/" /etc/security/limits.conf -sudo bash -c "echo '* hard nofile 128000' >> /etc/security/limits.conf" -sudo bash -c "echo 'root soft nofile 128000' >> /etc/security/limits.conf" -sudo bash -c "echo 'root hard nofile 128000' >> /etc/security/limits.conf" -sudo bash -c "echo '# End of file' >> /etc/security/limits.conf" - -sudo sed --in-place -i "23s/.*/session required pam_limits.so/" /etc/pam.d/common-session - -sudo sed --in-place -i "25s/.*/session required pam_limits.so/" /etc/pam.d/common-session-noninteractive -sudo bash -c "echo '# end of pam-auth-update config' >> /etc/pam.d/common-session-noninteractive" - - -# *** fail2ban *** -# based on https://raspibolt.github.io/raspibolt/raspibolt_21_security.html#fail2ban -echo "*** HARDENING ***" -sudo apt install -y --no-install-recommends python3-systemd fail2ban - -# *** CACHE DISK IN RAM *** -echo "Activating CACHE RAM DISK ... " -sudo /home/admin/config.scripts/blitz.cache.sh on - -# *** Wifi, Bluetooth & other configs *** -if [ "${baseimage}" = "raspbian" ]||[ "${baseimage}" = "raspios_arm64" ]||\ - [ "${baseimage}" = "debian_rpi64" ]; then - - if [ "${modeWifi}" == "false" ]; then - echo - echo "*** DISABLE WIFI ***" - sudo systemctl disable wpa_supplicant.service - sudo ifconfig wlan0 down - fi - - echo - echo "*** DISABLE BLUETOOTH ***" - - configFile="/boot/config.txt" - disableBT="dtoverlay=disable-bt" - disableBTDone=$(grep -c "$disableBT" $configFile) - - if [ ${disableBTDone} -eq 0 ]; then - # disable bluetooth module - echo >> $configFile - echo "# Raspiblitz" >> $configFile - echo 'dtoverlay=pi3-disable-bt' | sudo tee -a $configFile - echo 'dtoverlay=disable-bt' | sudo tee -a $configFile - else - echo "disable BT already in $configFile" - fi - - # remove bluetooth services - sudo systemctl disable bluetooth.service - sudo systemctl disable hciuart.service - - # remove bluetooth packages - sudo apt remove -y --purge pi-bluetooth bluez bluez-firmware - echo - - # disable audio - echo "*** DISABLE AUDIO (snd_bcm2835) ***" - sudo sed -i "s/^dtparam=audio=on/# dtparam=audio=on/g" /boot/config.txt - echo - - # disable DRM VC4 V3D - echo "*** DISABLE DRM VC4 V3D driver ***" - dtoverlay=vc4-fkms-v3d - sudo sed -i "s/^dtoverlay=vc4-fkms-v3d/# dtoverlay=vc4-fkms-v3d/g" /boot/config.txt - echo - - # I2C fix (make sure dtparam=i2c_arm is not on) - # see: https://github.com/rootzoll/raspiblitz/issues/1058#issuecomment-739517713 - sudo sed -i "s/^dtparam=i2c_arm=.*//g" /boot/config.txt -fi - -# *** FATPACK *** (can be activated by parameter - see details at start of script) -if [ "${fatpack}" == "true" ]; then - echo "*** FATPACK ***" - echo "* Adding nodeJS Framework ..." - sudo /home/admin/config.scripts/bonus.nodejs.sh on - if [ "$?" != "0" ]; then - echo "FATPACK FAILED" - exit 1 - fi - echo "* Optional Packages (may be needed for extended features)" - sudo apt-get install -y qrencode - sudo apt-get install -y btrfs-tools - sudo apt-get install -y secure-delete - sudo apt-get install -y fbi - sudo apt-get install -y ssmtp - sudo apt-get install -y unclutter xterm python3-pyqt5 - sudo apt-get install -y xfonts-terminus - sudo apt-get install -y nginx apache2-utils - sudo apt-get install -y nginx - sudo apt-get install -y python3-jinja2 - sudo apt-get install -y socat - sudo apt-get install -y libatlas-base-dev - sudo apt-get install -y mariadb-server mariadb-client - sudo apt-get install -y hexyl - sudo apt-get install -y autossh - - # *** UPDATE FALLBACK NODE LIST (only as part of fatpack) *** see https://github.com/rootzoll/raspiblitz/issues/1888 - echo "*** FALLBACK NODE LIST ***" - sudo -u admin curl -H "Accept: application/json; indent=4" https://bitnodes.io/api/v1/snapshots/latest/ -o /home/admin/fallback.nodes - byteSizeList=$(sudo -u admin stat -c %s /home/admin/fallback.nodes) - if [ ${#byteSizeList} -eq 0 ] || [ ${byteSizeList} -lt 10240 ]; then - echo "WARN: Failed downloading fresh FALLBACK NODE LIST --> https://bitnodes.io/api/v1/snapshots/latest/" - sudo rm /home/admin/fallback.nodes 2>/dev/null - sudo cp /home/admin/assets/fallback.nodes /home/admin/fallback.nodes - fi - sudo chown admin:admin /home/admin/fallback.nodes - -else - echo "* skipping FATPACK" -fi - -# *** BOOTSTRAP *** -echo -echo "*** RASPI BOOTSTRAP SERVICE ***" -sudo chmod +x /home/admin/_bootstrap.sh -sudo cp /home/admin/assets/bootstrap.service /etc/systemd/system/bootstrap.service -sudo systemctl enable bootstrap - -# *** BACKGROUND *** -echo -echo "*** RASPI BACKGROUND SERVICE ***" -sudo chmod +x /home/admin/_background.sh -sudo cp /home/admin/assets/background.service /etc/systemd/system/background.service -sudo systemctl enable background - -########### -# BITCOIN # -########### -echo -/home/admin/config.scripts/bitcoin.install.sh install || exit 1 - -####### -# LND # -####### -echo -/home/admin/config.scripts/lnd.install.sh install || exit 1 - -############### -# C-LIGHTNING # -############### -echo -/home/admin/config.scripts/cl.install.sh install || exit 1 - -echo -echo "*** raspiblitz.info ***" -sudo cat /home/admin/raspiblitz.info - -# *** RASPIBLITZ IMAGE READY INFO *** -echo -echo "**********************************************" -echo "BASIC SD CARD BUILD DONE" -echo "**********************************************" -echo -echo "Your SD Card Image for RaspiBlitz is ready (might still do display config)." -echo "Take the chance & look thru the output above if you can spot any errors or warnings." -echo -echo "IMPORTANT IF WANT TO MAKE A RELEASE IMAGE FROM THIS BUILD:" -echo "1. login fresh --> user:admin password:raspiblitz" -echo "2. run --> release" -echo - -# (do last - because might trigger reboot) -if [ "${displayClass}" != "headless" ] || [ "${baseimage}" = "raspbian" ] || [ "${baseimage}" = "raspios_arm64" ]; then +if [ "${displayClass}" != "headless" ] || [ "${baseimage}" = "raspios_arm64" ]; then echo "*** ADDITIONAL DISPLAY OPTIONS ***" echo "- calling: blitz.display.sh set-display ${displayClass}" sudo /home/admin/config.scripts/blitz.display.sh set-display ${displayClass} diff --git a/home.admin/00infoBlitz.sh b/home.admin/00infoBlitz.sh index a59ea441..3a35bc71 100755 --- a/home.admin/00infoBlitz.sh +++ b/home.admin/00infoBlitz.sh @@ -1,9 +1,72 @@ #!/bin/bash -# 00infoBlitz.sh +source <(/home/admin/_cache.sh get \ + state \ + setupPhase \ + network \ + chain \ + lightning \ + codeVersion \ + hostname \ + undervoltageReports \ + hdd_used_info \ + internet_localip \ + internet_public_ip_clean \ + internet_rx \ + internet_tx \ + system_ram_available_mb \ + system_ram_mb \ + system_ups_status \ + system_cpu_load \ + system_temp_celsius \ + system_temp_fahrenheit \ + runBehindTor \ + ups \ + ElectRS \ + BTCRPCexplorer \ +) -# load code software version -source /home/admin/_version.info +# PARAMETER 1: forcing view on a lightning implementation +PARAMETER_LIGHTNING=$1 +if [ "${PARAMETER_LIGHTNING}" == "lnd" ]; then + lightning="lnd" +fi +if [ "${PARAMETER_LIGHTNING}" == "cl" ]; then + lightning="cl" +fi +if [ "${PARAMETER_LIGHTNING}" == "none" ]; then + lightning="" +fi + +# PARAMETER 2: forcing view on a given network +PARAMETER_CHAIN=$2 +if [ "${PARAMETER_CHAIN}" == "mainnet" ]; then + chain="main" +fi +if [ "${PARAMETER_CHAIN}" == "testnet" ]; then + chain="test" +fi +if [ "${PARAMETER_CHAIN}" == "signet" ]; then + chain="sig" +fi + +# generate netprefix +netprefix=${chain:0:1} +if [ "${netprefix}" == "m" ]; then + netprefix="" +fi + +## get UPS info +upsInfo="" +if [ "${system_ups_status}" = "ONLINE" ]; then + upsInfo="${color_gray}${upsBattery}" +fi +if [ "$system_ups_status}" = "ONBATT" ]; then + upsInfo="${color_red}${upsBattery}" +fi +if [ "${system_ups_status}" = "SHUTTING DOWN" ]; then + upsInfo="${color_red}DOWN" +fi # set colors color_red='\033[0;31m' @@ -12,33 +75,6 @@ color_amber='\033[0;33m' color_yellow='\033[1;93m' color_gray='\033[0;37m' -## get basic info -source /home/admin/raspiblitz.info 2>/dev/null -source /mnt/hdd/raspiblitz.conf 2>/dev/null - -source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) - -## get HDD/SSD info -source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) -hdd="${hddUsedInfo}" - -## get internet info -source <(sudo /home/admin/config.scripts/internet.sh status) -cleanip=$(echo "${publicIP}" | tr -d '[]') - -## get UPS info -source <(/home/admin/config.scripts/blitz.ups.sh status) -upsInfo="" -if [ "${upsStatus}" = "ONLINE" ]; then - upsInfo="${color_gray}${upsBattery}" -fi -if [ "${upsStatus}" = "ONBATT" ]; then - upsInfo="${color_red}${upsBattery}" -fi -if [ "${upsStatus}" = "SHUTTING DOWN" ]; then - upsInfo="${color_red}DOWN" -fi - # check hostname if [ ${#hostname} -eq 0 ]; then hostname="raspiblitz"; fi @@ -48,347 +84,175 @@ if [ ${#chain} -eq 0 ]; then chain="main" fi -# set datadir -lnd_dir="/home/bitcoin/.lnd" -lnd_macaroon_dir="/home/bitcoin/.lnd/data/chain/${network}/${chain}net" - -# get uptime & load -load=$(w | head -n 1 | cut -d 'v' -f2 | cut -d ':' -f2) - -# get CPU temp - no measurement in a VM -cpu=0 -if [ -d "/sys/class/thermal/thermal_zone0/" ]; then - cpu=$(cat /sys/class/thermal/thermal_zone0/temp) -fi -if [ $cpu = 0 ];then - tempC="" - tempF="" -else - tempC=$((cpu/1000)) - tempF=$(((tempC * 18 + 325) / 10)) -fi -# get memory -ram_avail=$(free -m | grep Mem | awk '{ print $7 }') -ram=$(printf "%sM / %sM" "${ram_avail}" "$(free -m | grep Mem | awk '{ print $2 }')") - -if [ ${ram_avail} -lt 50 ]; then +# ram info string +ram=$(printf "%sM / %sM" "${system_ram_available_mb}" "${system_ram_mb}") +if [ "${system_ram_available_mb}" != "" ] && [ ${system_ram_available_mb} -lt 50 ]; then color_ram="${color_red}\e[7m" else color_ram=${color_green} fi -# Bitcoin blockchain -btc_path=$(command -v ${network}-cli) -blockInfo="-" -if [ -n "${btc_path}" ]; then - btc_title=$network - blockchaininfo="$($bitcoincli_alias getblockchaininfo 2>/dev/null)" - if [ ${#blockchaininfo} -gt 0 ]; then - btc_title="${btc_title} (${chain}net)" - - # get sync status - headers="$(echo "${blockchaininfo}" | jq -r '.headers')" - block_verified="$(echo "${blockchaininfo}" | jq -r '.blocks')" - block_diff=$(expr ${headers} - ${block_verified}) - blockInfo="${block_verified}/${headers}" - - progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')" - sync_percentage=$(echo $progress | awk '{printf( "%.2f%%", 100 * $1)}') - - if [ ${block_diff} -eq 0 ]; then # fully synced - sync="OK" - sync_color="${color_green}" - sync_behind=" " - elif [ ${block_diff} -eq 1 ]; then # fully synced - sync="OK" - sync_color="${color_green}" - sync_behind="-1 block" - elif [ ${block_diff} -le 10 ]; then # <= 2 blocks behind - sync="" - sync_color="${color_red}" - sync_behind="-${block_diff} blocks" - else - sync="" - sync_color="${color_red}" - sync_behind="${sync_percentage}" - fi - - # get last known block - if [ ! -z "${last_block}" ]; then - btc_line2="${btc_line2} ${color_gray}(block ${last_block})" - fi - - # get mem pool transactions - mempool="$($bitcoincli_alias getmempoolinfo 2>/dev/null | jq -r '.size')" - - else - btc_line2="${color_red}NOT RUNNING\t\t" - fi -fi - -# get IP address & port -networkInfo=$($bitcoincli_alias getnetworkinfo 2>/dev/null) -local_ip="${localip}" # from internet.sh -public_ip="${cleanip}" -public_port="$(echo ${networkInfo} | jq -r '.localaddresses [0] .port')" -if [ "${public_port}" = "null" ]; then - if [ "${chain}" = "test" ]; then - public_port="18333" - else - public_port="8333" - fi -fi - -# check if RTL web interface is installed -webinterfaceInfo="" -runningRTL=$(systemctl status ${netprefix}${typeprefix}RTL.service 2>/dev/null | grep -c active) -if [ ${runningRTL} -eq 1 ]; then - if [ "${lightning}" == "cl" ]; then - RTLHTTP=${portprefix}7000 - elif [ "${lightning}" == "lnd" ];then - RTLHTTP=${portprefix}3000 - fi - webinterfaceInfo="Web admin --> ${color_green}http://${local_ip}:${RTLHTTP}" -fi - -# CHAIN NETWORK -public_addr_pre="Public " -public_addr="??" +# Tor info string torInfo="" -# Version -networkVersion=$($bitcoincli_alias -version 2>/dev/null | cut -d ' ' -f6) -# TOR or IP -networkConnections=$(echo ${networkInfo} | jq -r '.connections') -networkConnectionsInfo="${color_green}${networkConnections} ${color_gray}connections" - if [ "${runBehindTor}" = "on" ]; then - - # TOR address - onionAddress=$(echo ${networkInfo} | jq -r '.localaddresses [0] .address') - networkConnectionsInfo="${color_green}${networkConnections} ${color_gray}peers" - public_addr="${onionAddress}:${public_port}" - public="" - public_color="${color_green}" torInfo="+ Tor" - -else - - # IP address - networkConnectionsInfo="${color_green}${networkConnections} ${color_gray}connections" - public_addr="${publicIP}:${public_port}" - public_check=$(nc -z -w6 ${cleanip} ${public_port} 2>/dev/null; echo $?) - if [ $public_check = "0" ] || [ "${ipv6}" == "on" ] ; then - public="" - # only set yellow/normal because netcat can only say that the port is open - not that it points to this device for sure - public_color="${color_amber}" - else - public="" - public_color="${color_red}" - fi - - # DynDomain - if [ ${#dynDomain} -gt 0 ]; then - - #check if dynamic domain resolves to correct IP - ipOfDynDNS=$(getent hosts ${dynDomain} | awk '{ print $1 }') - if [ "${ipOfDynDNS}:${public_port}" != "${public_addr}" ]; then - public_color="${color_red}" - else - public_color="${color_amber}" - fi - - # replace IP display with dynDN - public_addr_pre="DynDN " - public_addr="${dynDomain}" - fi - - if [ ${#public_addr} -gt 25 ]; then - # if a IPv6 address dont show peers to save space - networkConnectionsInfo="" - fi - - if [ ${#public_addr} -gt 35 ]; then - # if a LONG IPv6 address dont show "Public" in front to save space - public_addr_pre="" - fi - fi -# LIGHTNING NETWORK -if [ "${lightning}" == "cl" ]; then - ln_getInfo=$($lightningcli_alias getinfo 2>/dev/null) - ln_baseInfo="-" - ln_channelInfo="\n" - ln_external="\n" - ln_alias="$(sudo cat "${CLCONF}" | grep "^alias=*" | cut -f2 -d=)" - if [ ${#ln_alias} -eq 0 ];then - ln_alias=$(echo "${ln_getInfo}" | grep '"alias":' | cut -d '"' -f4) - fi - if [ ${#ln_alias} -eq 0 ];then - ln_alias=${hostname} - fi - ln_publicColor="" - ln_port=$(sudo cat "${CLCONF}" | grep "^bind-addr=*" | cut -f2 -d':') - if [ ${#ln_port} -eq 0 ]; then - ln_port=$(echo "${ln_getInfo}" | grep '"port":' | cut -d: -f2 | tail -1 | bc) - fi - wallet_unlocked=0 #TODO - if [ "$wallet_unlocked" -gt 0 ] ; then - ln_alias="Wallet Locked" - else - pubkey=$(echo "${ln_getInfo}" | grep '"id":' | cut -d '"' -f4) - address=$(echo "${ln_getInfo}" | grep '.onion' | cut -d '"' -f4) - if [ ${#address} -eq 0 ];then - address=$(echo "${ln_getInfo}" | grep '"ipv4"' -A 1 | tail -1 | cut -d '"' -f4) - fi - ln_external="${pubkey}@${address}:${ln_port}" - ln_tor=$(echo "${ln_external}" | grep -c ".onion") - if [ ${ln_tor} -eq 1 ]; then - ln_publicColor="${color_green}" - else - public_check=$(nc -z -w6 ${public_ip} ${ln_port} 2>/dev/null; echo $?) - if [ $public_check = "0" ] || [ "${ipv6}" == "on" ]; then - # only set yellow/normal because netcat can only say that the port is open - not that it points to this device for sure - ln_publicColor="${color_amber}" - else - ln_publicColor="${color_red}" - fi +####################### +# BITCOIN INFO + +# get block data - use meta on cache to call dynamic variable name +source <(/home/admin/_cache.sh meta btc_${chain}net_blocks_headers) +btc_blocks_headers="${value}" +source <(/home/admin/_cache.sh meta btc_${chain}net_blocks_verified) +btc_blocks_verified="${value}" +source <(/home/admin/_cache.sh meta btc_${chain}net_blocks_behind) +btc_blocks_behind="${value}" +source <(/home/admin/_cache.sh meta btc_${chain}net_sync_percentage) +if [ "${value}" != "" ]; then + sync_percentage="${value}%" +fi + +# construct blockinfo string +if [ "${btc_blocks_behind}" == "" ]; then + sync="WAIT" + sync_color="${color_yellow}" +elif [ ${btc_blocks_behind} -lt 2 ]; then + sync="OK" + sync_color="${color_green}" +else + sync="" + sync_color="${color_red}" +fi +blockInfo="Blocks ${btc_blocks_verified}/${btc_blocks_headers} ${color_gray}Sync ${sync_color}${sync}" +if [ "${btc_blocks_headers}" == "" ]; then + blockInfo="${color_red}Not Started | Not Ready Yet | No Data${color_gray}" +fi + +# get address data - use meta on cache to call dynamic variable name +source <(/home/admin/_cache.sh meta btc_${chain}net_version) +networkVersion="${value} " +source <(/home/admin/_cache.sh meta btc_${chain}net_peers) +btc_peers=${value} +if [ "${btc_peers}" == "" ]; then + networkConnectionsInfo="" +elif [ ${btc_peers} -gt 0 ]; then + networkConnectionsInfo="${color_green}${btc_peers} ${color_gray}peers" +else + networkConnectionsInfo="${color_red}${btc_peers} ${color_gray}peers" +fi + +####################### +# LIGHTNING INFO + +# default values +ln_alias=${hostname} +ln_baseInfo="-" +ln_channelInfo="\n" +ln_external="\n" +ln_feeReport="" +ln_peersInfo="" +ln_version="" +ln_publicColor="${color_green}" + +if [ "${lightning}" != "" ]; then + + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_version) + ln_version="${value}" + + # get alias + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_alias) + if [ "${value}" != "" ]; then + ln_alias="${value}" fi - BLOCKHEIGHT=$(echo "$blockchaininfo"|grep blocks|awk '{print $2}'|cut -d, -f1) - CLHEIGHT=$(echo "${ln_getInfo}" | jq .blockheight) - if [ "$BLOCKHEIGHT" == "$CLHEIGHT" ];then - ln_sync=1 - else - ln_sync=0 + + # consider tor address green for public + # when not Tor use yellow because not sure if public + if [ "${runBehindTor}" != "on" ]; then + ln_publicColor="${color_yellow}" fi - ln_version=$($lightningcli_alias -V) - if [ ${ln_sync} -eq 0 ]; then - if [ ${#ln_getInfo} -eq 0 ]; then - ln_baseInfo="${color_red} Not Started | Not Ready Yet" - else - ln_baseInfo=" - ${color_amber}Scanning blocks: ${CLHEIGHT}/${BLOCKHEIGHT}" - fi - else - ln_walletbalance=0 - cl_listfunds=$($lightningcli_alias listfunds 2>/dev/null) - for i in $(echo "$cl_listfunds" \ - |jq .outputs[]|jq 'select(.status=="confirmed")'|grep value|awk '{print $2}'|cut -d, -f1);do - ln_walletbalance=$((ln_walletbalance+i)) - done - for i in $(echo "$cl_listfunds" \ - |jq .outputs[]|jq 'select(.status=="unconfirmed")'|grep value|awk '{print $2}'|cut -d, -f1);do - ln_walletbalance_wait=$((ln_walletbalance_wait+i)) - done - # ln_closedchannelbalance: "state": "ONCHAIN" funds in channels - for i in $(echo "$cl_listfunds" \ - |jq .channels[]|jq 'select(.state=="ONCHAIN")'|grep channel_sat|awk '{print $2}'|cut -d, -f1);do - ln_closedchannelbalance=$((ln_closedchannelbalance+i)) - done - # ln_pendingonchain: waiting onchain + waiting closed channel funds - ln_pendingonchain=$((ln_walletbalance_wait+ln_closedchannelbalance)) - if [ "${ln_pendingonchain}" = "0" ]; then ln_pendingonchain=""; fi - if [ ${#ln_pendingonchain} -gt 0 ]; then ln_pendingonchain="(+${ln_pendingonchain})"; fi - # ln_channelbalance: "state": "CHANNELD_NORMAL" funds in channels - for i in $(echo "$cl_listfunds" \ - |jq .channels[]|jq 'select(.state=="CHANNELD_NORMAL")'|grep channel_sat|awk '{print $2}'|cut -d, -f1);do - ln_channelbalance=$((ln_channelbalance+i)) - done - if [ ${#ln_channelbalance} -eq 0 ];then - ln_channelbalance=0 - fi - # ln_channelbalance_all: all funds in channels - for i in $(echo "$cl_listfunds" \ - |jq .channels[]|grep channel_sat|awk '{print $2}'|cut -d, -f1);do - ln_channelbalance_all=$((ln_channelbalance_all+i)) - done - ln_channelbalance_pending=$((ln_channelbalance_all-ln_channelbalance-ln_closedchannelbalance)) - if [ "${ln_channelbalance_pending}" = "0" ]; then ln_channelbalance_pending=""; fi - if [ ${#ln_channelbalance_pending} -gt 0 ]; then ln_channelbalance_pending=" (+${ln_channelbalance_pending})"; fi - # - **num_peers** (u32): The total count of peers, connected or with channels - # - **num_pending_channels** (u32): The total count of channels being opened - # - **num_active_channels** (u32): The total count of channels in normal state - # - **num_inactive_channels** (u32): The total count of channels waiting for opening or closing - ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null - cl_num_pending_channels="$(echo "${ln_getInfo}" | jq -r '.num_pending_channels')" 2>/dev/null - cl_num_inactive_channels="$(echo "${ln_getInfo}" | jq -r '.num_inactive_channels')" 2>/dev/null - ln_channels_total=$((ln_channels_online+cl_num_pending_channels+cl_num_inactive_channels)) - ln_baseInfo="${color_gray}Wallet ${ln_walletbalance} ${netprefix}sat ${ln_pendingonchain}" - ln_peers="$(echo "${ln_getInfo}" | jq -r '.num_peers')" 2>/dev/null - ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} ${netprefix}sat${ln_channelbalance_pending}" - ln_peersInfo="${color_green}${ln_peers} ${color_gray}peers" - # - **fees_collected_msat** (msat): Total routing fees collected by this node - #ln_dailyfees="$($lncli_alias feereport | jq -r '.day_fee_sum')" 2>/dev/null - #ln_weeklyfees="$($lncli_alias feereport | jq -r '.week_fee_sum')" 2>/dev/null - #ln_monthlyfees="$($lncli_alias feereport | jq -r '.month_fee_sum')" 2>/dev/null - #ln_feeReport="Fee Report (D-W-M): ${color_green}${ln_dailyfees}-${ln_weeklyfees}-${ln_monthlyfees} ${color_gray}sat" - ln_feeReport="Fees collected: $(echo "${ln_getInfo}" | jq -r '.fees_collected_msat')" - fi - fi - -elif [ "${lightning}" == "lnd" ];then - ln_baseInfo="-" - ln_channelInfo="\n" - ln_external="\n" - ln_alias="$(sudo cat /mnt/hdd/lnd/${netprefix}lnd.conf | grep "^alias=*" | cut -f2 -d=)" - if [ ${#ln_alias} -eq 0 ];then - ln_alias=${hostname} - fi - ln_publicColor="" - ln_port=$(sudo cat /mnt/hdd/lnd/${netprefix}lnd.conf | grep "^listen=*" | cut -f2 -d':') - if [ ${#ln_port} -eq 0 ]; then - ln_port="9735" - fi - wallet_unlocked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2> /dev/null | grep -c unlock) - if [ "$wallet_unlocked" -gt 0 ] ; then - ln_alias="Wallet Locked" - else - ln_getInfo=$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>/dev/null) - ln_external=$(echo "${ln_getInfo}" | grep "uris" -A 1 | tr -d '\n' | cut -d '"' -f4) - ln_tor=$(echo "${ln_external}" | grep -c ".onion") - if [ ${ln_tor} -eq 1 ]; then - ln_publicColor="${color_green}" - else - public_check=$(nc -z -w6 ${public_ip} ${ln_port} 2>/dev/null; echo $?) - if [ $public_check = "0" ] || [ "${ipv6}" == "on" ]; then - # only set yellow/normal because netcat can only say that the port is open - not that it points to this device for sure - ln_publicColor="${color_amber}" - else - ln_publicColor="${color_red}" - fi + + # get the public address/URI + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_address) + ln_external="${value}" + + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_peers) + if [ "${value}" != "" ]; then + ln_peersInfo="${color_green}${value} ${color_gray}peers" fi - ln_sync=$(echo "${ln_getInfo}" | grep "synced_to_chain" | grep "true" -c) - ln_version=$(echo "${ln_getInfo}" | jq -r '.version' | cut -d' ' -f1) - if [ ${ln_sync} -eq 0 ]; then - if [ ${#ln_getInfo} -eq 0 ]; then - ln_baseInfo="${color_red} Not Started | Not Ready Yet" - else - ln_baseInfo="${color_amber} Waiting for Chain Sync" - fi - else - lnd_walletbalance=$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance 2>/dev/null) - ln_walletbalance="$(echo "$lnd_walletbalance" | jq -r '.confirmed_balance')" 2>/dev/null - ln_walletbalance_wait="$(echo "$lnd_walletbalance" | jq -r '.unconfirmed_balance')" 2>/dev/null - if [ "${ln_walletbalance_wait}" = "0" ]; then ln_walletbalance_wait=""; fi - if [ ${#ln_walletbalance_wait} -gt 0 ]; then ln_walletbalance_wait="(+${ln_walletbalance_wait})"; fi - lnd_channelbalance=$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance 2>/dev/null) - ln_channelbalance="$(echo "$lnd_channelbalance" | jq -r '.balance')" 2>/dev/null - ln_channelbalance_pending="$(echo "$lnd_channelbalance" | jq -r '.pending_open_balance')" 2>/dev/null - if [ "${ln_channelbalance_pending}" = "0" ]; then ln_channelbalance_pending=""; fi - if [ ${#ln_channelbalance_pending} -gt 0 ]; then ln_channelbalance_pending=" (+${ln_channelbalance_pending})"; fi - ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null - ln_channels_total="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert listchannels | jq '.[] | length')" 2>/dev/null - ln_baseInfo="${color_gray}wallet ${ln_walletbalance} ${netprefix}sat ${ln_walletbalance_wait}" - ln_peers="$(echo "${ln_getInfo}" | jq -r '.num_peers')" 2>/dev/null - ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} ${netprefix}sat${ln_channelbalance_pending}" - ln_peersInfo="${color_green}${ln_peers} ${color_gray}peers" - lnd_feereport=$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport 2>/dev/null) - ln_dailyfees="$(echo "$lnd_feereport" | jq -r '.day_fee_sum')" 2>/dev/null - ln_weeklyfees="$(echo "$lnd_feereport" | jq -r '.week_fee_sum')" 2>/dev/null - ln_monthlyfees="$(echo "$lnd_feereport" | jq -r '.month_fee_sum')" 2>/dev/null - ln_feeReport="Fee Report (D-W-M): ${color_green}${ln_dailyfees}-${ln_weeklyfees}-${ln_monthlyfees} ${color_gray}sat" - fi - fi + + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_ready) + ln_ready="${value}" + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_sync_chain) + ln_sync="${value}" + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_locked) + ln_locked="${value}" + + # lightning is still starting + if [ "${ln_ready}" != "1" ]; then + + ln_baseInfo="\n ${color_red}Not Started | Not Ready Yet | No Data" + ln_peersInfo="" + + # lightning is still syncing + elif [ "${ln_locked}" == "1" ]; then + + ln_baseInfo="${color_amber}Wallet Locked" + ln_peersInfo="" + + # lightning is still syncing + elif [ "${ln_sync}" != "1" ]; then + + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_sync_progress) + ln_syncprogress="${value}" + ln_baseInfo="${color_amber}Scanning blocks: ${ln_syncprogress}" + ln_peersInfo="" + + # OK lightning is ready - get more details + else + + # create fee report + if [ "${lightning}" == "lnd" ]; then + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_fees_daily) + ln_dailyfees="${value}" + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_fees_weekly) + ln_weeklyfees="${value}" + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_fees_month) + ln_monthlyfees="${value}" + ln_feeReport="Fee Report (D-W-M): ${color_green}${ln_dailyfees}-${ln_weeklyfees}-${ln_monthlyfees} ${color_gray}${netprefix}sat" + else + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_fees_total) + ln_totalfees="${value}" + ln_feeReport="Fee Report: ${color_green}${ln_totalfees} ${color_gray}${netprefix}sat" + fi + + # on-chain wallet info + ln_pendingonchain="" + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_wallet_onchain_pending) + ln_onchain_pending="${value}" + if [ "${ln_onchain_pending}" != "" ] && [ ${ln_onchain_pending} -gt 0 ]; then ln_pendingonchain=" (+${ln_onchain_pending})"; fi + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_wallet_onchain_balance) + ln_walletbalance="${value}" + ln_baseInfo="${color_gray}Wallet ${ln_walletbalance} ${netprefix}sat ${ln_pendingonchain}" + + # channel pending info + ln_channelbalance_pending="" + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_wallet_channels_pending) + ln_channels_pending="${value}" + if [ "${ln_channels_pending}" != "" ] && [ ${ln_channels_pending} -gt 0 ]; then ln_channelbalance_pending=" (+${ln_channels_pending})"; fi + + # get channel infos + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_wallet_channels_balance) + ln_channels_balance="${value}" + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_channels_active) + ln_channels_online="${value}" + source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_channels_total) + ln_channels_total="${value}" + + # construct channel info string + ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channels_balance} ${netprefix}sat${ln_channelbalance_pending}" + fi + fi # show JoinMarket stats in place of the LND URI only if the Yield Generator is running @@ -411,28 +275,19 @@ else lastLine="\ ${color_yellow} ${color_yellow}${ln_publicColor}${ln_external}${color_gray}" - fi +fi -if [ "${lightning}" == "cl" ];then - LNline="C-LIGHTNING ${color_green}${ln_version}\n ${ln_baseInfo}" -elif [ "${lightning}" == "lnd" ];then +if [ "${lightning}" == "cl" ]; then + LNline="C-LIGHTNING ${color_green}${ln_version} ${ln_baseInfo}" +elif [ "${lightning}" == "lnd" ]; then LNline="LND ${color_green}${ln_version} ${ln_baseInfo}" fi -if [ $cpu = 0 ];then - templine="on $(uname -m) VM%s%s" -else - templine="temp %s°C %s°F" -fi -sleep 5 - LNinfo=" + Lightning Network" if [ "${lightning}" == "" ]; then LNinfo="" fi -## get uptime and current date & time -uptime=$(uptime --pretty) datetime=$(date -R) stty sane @@ -449,10 +304,10 @@ ${color_yellow} ,/ ${color_yellow}%s ${color_yellow} ,'/ ${color_gray}%s ${color_yellow} ,' / ${color_gray}%s, temp %s°C %s°F ${color_yellow} ,' /_____ ${color_gray}Free Mem ${color_ram}${ram} ${color_gray} HDDuse ${color_hdd}%s${color_gray} -${color_yellow},'_____ ,' ${color_gray}SSH admin@${color_green}${local_ip}${color_gray} d${network_rx} u${network_tx} -${color_yellow} / ,' ${color_gray}${webinterfaceInfo} -${color_yellow} / ,' ${color_gray}${network} ${color_green}${networkVersion} ${color_gray}${chain}net ${networkConnectionsInfo} -${color_yellow} /,' ${color_gray}Blocks ${blockInfo} ${color_gray}Sync ${sync_color}${sync} %s +${color_yellow},'_____ ,' ${color_gray}SSH admin@${color_green}${internet_localip}${color_gray} d${internet_rx} u${internet_tx} +${color_yellow} / ,' ${color_gray} +${color_yellow} / ,' ${color_gray}${network} ${color_green}${networkVersion}${color_gray}${chain}net ${networkConnectionsInfo} +${color_yellow} /,' ${color_gray}${blockInfo} %s ${color_yellow} /' ${color_gray} ${color_yellow} ${color_gray}${LNline} ${color_yellow} ${color_gray}${ln_channelInfo} ${ln_peersInfo} @@ -462,8 +317,8 @@ $lastLine "RaspiBlitz v${codeVersion}" \ "-------------------------------------------" \ "Refreshed: ${datetime}" \ -"CPU load${load##up*, }" "${tempC}" "${tempF}" \ -"${hdd}" "${sync_percentage}" +"CPU load${system_cpu_load##up*, }" "${system_temp_celsius}" "${system_temp_fahrenheit}" \ +"${hdd_used_info}" "${sync_percentage}" if [ ${#undervoltageReports} -gt 0 ] && [ "${undervoltageReports}" != "0" ]; then echo "${undervoltageReports} undervoltage reports - run 'Hardware Test' in menu" @@ -500,4 +355,3 @@ else fi -# EOF diff --git a/home.admin/00infoLCD.sh b/home.admin/00infoLCD.sh index 7289431a..c9f194ab 100755 --- a/home.admin/00infoLCD.sh +++ b/home.admin/00infoLCD.sh @@ -86,6 +86,8 @@ while : # get config info if already available (with state value) source ${infoFile} + source <(/home/admin/_cache.sh get state message) + configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf') if [ ${configExists} -eq 1 ]; then source ${configFile} @@ -101,18 +103,24 @@ while : fi - # TODO: ALSO SEPARATE GUI/ACTION FOR THE SCANNING / WALLET UNLOCK / ERROR DETECTION # if lightning is syncing or scanning - source <(sudo /home/admin/config.scripts/blitz.statusscan.sh $lightning) - if [ "${walletLocked}" == "1" ] || [ "${CLwalletLocked}" == "1" ]; then + source <(/home/admin/_cache.sh get \ + lightning \ + ln_default_locked \ + btc_default_synced \ + btc_default_sync_initialblockdownload \ + btc_default_blocks_behind \ + ) + + if [ "${lightning}" != "" ] && [ "${lightning}" != "none" ] && [ "${ln_default_locked}" == "1" ]; then /home/admin/setup.scripts/eventInfoWait.sh "walletlocked" "" lcd sleep 3 continue fi - if [ "${syncedToChain}" != "1" ]; then + if [ "${btc_default_synced}" != "1" ]; then /home/admin/setup.scripts/eventBlockchainSync.sh lcd - sleep 10 + sleep 3 continue fi diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index e7d9c850..621cbb9e 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -2,15 +2,9 @@ echo "Starting the main menu ..." -# CONFIGFILE - configuration of RaspiBlitz -configFile="/mnt/hdd/raspiblitz.conf" - -# INFOFILE - state data from bootstrap -infoFile="/home/admin/raspiblitz.info" - # MAIN MENU AFTER SETUP -source ${infoFile} -source ${configFile} +source /home/admin/raspiblitz.info +source /mnt/hdd/raspiblitz.conf # FUNCTIONS @@ -38,7 +32,7 @@ confirmation() } # get the local network IP to be displayed on the LCD -source <(/home/admin/config.scripts/internet.sh status local) +source <(/home/admin/_cache.sh get internet_localip) if [ ${chain} = test ];then netprefix="t" @@ -64,7 +58,7 @@ fi if [ ${#lightning} -gt 0 ]; then plus="/ ${lightning} ${plus}" fi -BACKTITLE="${localip} / ${hostname} / ${network} ${plus}" +BACKTITLE="${internet_localip} / ${hostname} / ${network} ${plus}" # Basic Options OPTIONS+=(INFO "RaspiBlitz Status Screen") diff --git a/home.admin/00parallelChainsMenu.sh b/home.admin/00parallelChainsMenu.sh index 3a392ba3..d770212d 100644 --- a/home.admin/00parallelChainsMenu.sh +++ b/home.admin/00parallelChainsMenu.sh @@ -6,9 +6,6 @@ source /home/admin/raspiblitz.info source /mnt/hdd/raspiblitz.conf -# get the local network IP to be displayed on the LCD -source <(/home/admin/config.scripts/internet.sh status local) - # BASIC MENU INFO WIDTH=64 BACKTITLE="RaspiBlitz" diff --git a/home.admin/00raspiblitz.sh b/home.admin/00raspiblitz.sh index 0495d01c..05fa7639 100755 --- a/home.admin/00raspiblitz.sh +++ b/home.admin/00raspiblitz.sh @@ -8,23 +8,24 @@ echo "Starting SSH user interface ... (please wait)" # CONFIGFILE - configuration of RaspiBlitz -configFile="/mnt/hdd/raspiblitz.conf" -source ${configFile} 2>/dev/null +source /mnt/hdd/raspiblitz.conf 2>/dev/null # INFOFILE - state data from bootstrap infoFile="/home/admin/raspiblitz.info" - -# check if raspiblitz.info exists -systemInfoExists=$(ls ${infoFile} | grep -c "${infoFile}") -if [ "${systemInfoExists}" != "1" ]; then - echo "systemInfoExists(${systemInfoExists})" - echo "FAIL: ${infoFile} does not exist .. which it should at this point." - echo "Check logs & bootstrap.service for errors and report to devs." - exit 1 -fi - -# get system state information raspiblitz.info source ${infoFile} +source <(/home/admin/_cache.sh get state message) + +# only check when first pramater is "newsshsession" (calling from bash.rc) +if [ "$1" == "newsshsession" ]; then + # if already one ssh session is open - ask on the second to exit to terminal + source <(sudo /home/admin/config.scripts/blitz.ssh.sh sessions) + if [ "${ssh_session_count}" != "" ] && [ "${ssh_session_count}" != "1" ]; then + echo "####################################################################" + echo "# You already have another SSH session open ... exiting to terminal." + echo "# To open main menu type command: raspiblitz" + exit 0 + fi +fi # check that basic system phase/state information is available if [ "${setupPhase}" == "" ] || [ "${state}" == "" ]; then @@ -74,13 +75,6 @@ if [ "${state}" = "copystation" ]; then exit fi -# prepare status file -# TODO: this is to be replaced and unified together with raspiblitz.info -# when we move to a background monitoring thread & redis for WebUI with v1.8 -sudo touch /var/cache/raspiblitz/raspiblitz.status -sudo chown admin:admin /var/cache/raspiblitz/raspiblitz.status -sudo chmod 740 /var/cache/raspiblitz/raspiblitz.status - ##################################### # SSH MENU LOOP # this loop runs until user exits or @@ -96,6 +90,11 @@ trap quit INT trap quit TERM echo "# start ssh menu loop" +# put some values on higher scan rate for 10 minute +/home/admin/_cache.sh focus ln_default_locked 2 600 >/dev/null +/home/admin/_cache.sh focus btc_default_synced 2 600 >/dev/null + +echo "# starting ssh menu loop ... " exitMenuLoop=0 doneIBD=0 while [ ${exitMenuLoop} -eq 0 ] @@ -105,56 +104,47 @@ do # Access fresh system info on every loop # refresh system state information - source ${infoFile} - - # gather fresh status scan and store results in memory - # TODO: move this into background loop and unify with redis data storage later - #echo "# blitz.statusscan.sh" - - firstStatusScanExists=$(ls /var/cache/raspiblitz/raspiblitz.status | grep -c "raspiblitz.status") - #echo "firstStatusScanExists(${firstStatusScanExists})" - if [ ${firstStatusScanExists} -eq 1 ]; then - - # run statusscan with timeout - if status scan was not killed it will copy over the - timeout 15 /home/admin/config.scripts/blitz.statusscan.sh ${lightning} > /var/cache/raspiblitz/raspiblitz.status.tmp - result=$? - #echo "result(${result})" - if [ "${result}" == "0" ]; then - # statusscan finished in under 10 seconds - use results - cp /var/cache/raspiblitz/raspiblitz.status.tmp /var/cache/raspiblitz/raspiblitz.status - else - # statusscan blocked and was killed - fallback to old results - echo "statusscan blocked (${result}) - fallback to old results" - sleep 1 - fi - - else - - # first time run statusscan without timeout - echo "# running statusscan for the first time ... can take time" - /home/admin/config.scripts/blitz.statusscan.sh ${lightning} > /var/cache/raspiblitz/raspiblitz.status + source <(/home/admin/_cache.sh get \ + systemscan_runtime \ + state \ + setupPhase \ + btc_default_synced \ + ln_default_locked \ + message \ + network \ + chain \ + lightning \ + internet_localip \ + system_vm_vagrant \ + ) + # background.scan is not ready yet + if [ "${systemscan_runtime}" == "" ]; then + echo "# background.scan not ready yet ... (please wait)" + sleep 4 + continue fi - # load statusscan results - source /var/cache/raspiblitz/raspiblitz.status 2>/dev/null - ##################################### # ALWAYS: Handle System States ##################################### ############################ - # LND Wallet Unlock + # Wallet Unlock - if [ "${lndActive}" == "1" ] && [ "${walletLocked}" == "1" ] && [ "${state}" == "ready" ] && [ "${setupPhase}" == "done" ]; then - #echo "# lnd.unlock.sh" - /home/admin/config.scripts/lnd.unlock.sh - fi + if [ "${state}" == "ready" ] && [ "${setupPhase}" == "done" ] && [ "${ln_default_locked}" == "1" ]; then + + # unlock lnd + if [ "${lightning}" == "lnd" ]; then + /home/admin/config.scripts/lnd.unlock.sh + fi + + # unlock c-lightning + if [ "${lightning}" == "cl" ]; then + /home/admin/config.scripts/cl.hsmtool.sh unlock + sleep 5 + fi - # CL Wallet Unlock - if [ "${CLwalletLocked}" == "1" ] && [ "${state}" == "ready" ] && [ "${setupPhase}" == "done" ]; then - /home/admin/config.scripts/cl.hsmtool.sh unlock - sleep 5 fi ##################################### @@ -194,7 +184,7 @@ do echo "***********************************************************" if [ "${state}" == "reboot" ]; then echo "SSH again into system with:" - echo "ssh admin@${localip}" + echo "ssh admin@${internet_localip}" echo "Use your password A" echo "***********************************************************" fi @@ -203,12 +193,11 @@ do fi ##################################### - # INITIAL BLOCKCHAIN SYNC (SUBLOOP) + # MAKE SURE BLOCKCHAIN IS SYNC ##################################### - if [ "${lightning}" == "" ]; then syncedToChain=1; fi - if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ] && [ "${syncedToChain}" != "1" ]; then + if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ] && [ "${btc_default_synced}" != "1" ]; then /home/admin/setup.scripts/eventBlockchainSync.sh ssh - sleep 10 + sleep 3 continue fi @@ -219,6 +208,9 @@ do # when setup is done & state is ready .. jump to main menu if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ]; then # MAIN MENU + # remove higher scan rate on values + /home/admin/_cache.sh focus ln_default_locked -1 + /home/admin/_cache.sh focus btc_default_synced -1 echo "# 00mainMenu.sh" /home/admin/00mainMenu.sh # use the exit code from main menu as signal if menu loop should exited @@ -236,7 +228,7 @@ do #echo "# DURING SETUP: Handle System State (${state})" # when no HDD on Vagrant - just print info & exit (admin info & exit) - if [ "${state}" == "noHDD" ] && [ ${vagrant} -gt 0 ]; then + if [ "${state}" == "noHDD" ] && [ ${system_vm_vagrant} != "0" ]; then echo "***********************************************************" echo "VAGRANT INFO" echo "***********************************************************" @@ -338,4 +330,4 @@ fi echo "Blitz command line options: blitzhelp" echo "Back to menus use command: raspiblitz" echo -exit 0 +exit 0 \ No newline at end of file diff --git a/home.admin/00settingsMenuBasics.sh b/home.admin/00settingsMenuBasics.sh index 59965c19..d00a55f5 100755 --- a/home.admin/00settingsMenuBasics.sh +++ b/home.admin/00settingsMenuBasics.sh @@ -110,8 +110,8 @@ OPTIONS=() # LCD options (only when running with LCD screen) if [ "${displayClass}" == "lcd" ]; then - OPTIONS+=(s 'Touchscreen' ${touchscreenMenu}) - OPTIONS+=(r 'LCD Rotate' ${lcdrotateMenu}) + OPTIONS+=(s 'Touchscreen' ${touchscreenMenu}) + OPTIONS+=(r 'LCD Rotate' ${lcdrotateMenu}) fi # Important basic options @@ -120,24 +120,24 @@ OPTIONS+=(z 'ZeroTier' ${zerotierSwitch}) if [ ${#runBehindTor} -eq 0 ] || [ "${runBehindTor}" = "off" ]; then OPTIONS+=(y ${dynDomainMenu} ${domainValue}) - OPTIONS+=(b 'BTC UPnP (AutoNAT)' ${networkUPnP}) + OPTIONS+=(b 'BTC UPnP (AutoNAT)' ${networkUPnP}) fi OPTIONS+=(p 'Parallel Testnet/Signet' ${parallelTestnets}) # LND & options (only when running LND) -OPTIONS+=(m 'LND LIGHTNING LABS NODE' ${lndNode}) +OPTIONS+=(m 'LND LIGHTNING LABS NODE' ${lndNode}) if [ "${lndNode}" == "on" ]; then - OPTIONS+=(a '-LND Channel Autopilot' ${autoPilot}) - OPTIONS+=(k '-LND Accept Keysend' ${keysend}) - OPTIONS+=(c '-LND Circuitbreaker (firewall)' ${circuitbreaker}) - OPTIONS+=(u '-LND Auto-Unlock' ${autoUnlock}) + OPTIONS+=(a '-LND Channel Autopilot' ${autoPilot}) + OPTIONS+=(k '-LND Accept Keysend' ${keysend}) + OPTIONS+=(c '-LND Circuitbreaker (firewall)' ${circuitbreaker}) + OPTIONS+=(u '-LND Auto-Unlock' ${autoUnlock}) OPTIONS+=(x '-LND StaticChannelBackup on Nextcloud' ${NextcloudBackup}) OPTIONS+=(e '-LND StaticChannelBackup USB Drive' ${LocalBackup}) OPTIONS+=(l '-LND UPnP (AutoNAT)' ${autoNatDiscovery}) fi # C-Lightning & options/PlugIns -OPTIONS+=(n 'CL C-LIGHTNING NODE' ${clNode}) +OPTIONS+=(n 'CL C-LIGHTNING NODE' ${clNode}) if [ "${clNode}" == "on" ]; then OPTIONS+=(o '-CL CLBOSS Automatic Node Manager' ${clbossMenu}) OPTIONS+=(h '-CL Wallet Encryption' ${clEncryptedHSMMenu}) @@ -254,7 +254,7 @@ Please keep in mind that thru your LND node id & your previous IP history with y # change Tor anychange=1 - sudo /home/admin/config.scripts/internet.tor.sh ${choice} + sudo /home/admin/config.scripts/tor.network.sh ${choice} needsReboot=1 else @@ -272,7 +272,7 @@ if [ "${autoUnlock}" != "${choice}" ] && [ "${lndNode}" == "on" ]; then l1="AUTO-UNLOCK IS NOW OFF" if [ "${choice}" = "on" ]; then l1="AUTO-UNLOCK IS NOW ACTIVE" - fi + fi dialog --title 'OK' --msgbox "\n${l1}\n" 9 50 needsReboot=1 fi @@ -378,7 +378,7 @@ if [ "${zerotierSwitch}" != "${choice}" ]; then else dialog --msgbox "ZeroTier is now OFF." 5 46 fi - + else echo "ZeroTier setting unchanged." fi @@ -496,9 +496,9 @@ if [ "${testnet}" != "${choice}" ] || \ if [ "${lightning}" == "cl" ] || [ "${cl}" == "on" ]; then /home/admin/config.scripts/cl.install.sh on testnet /home/admin/config.scripts/cl.install.sh on signet - fi + fi else - # just turn al lightning testnets off (even if not on before) + # just turn all lightning testnets off (even if not on before) /home/admin/config.scripts/lnd.install.sh off testnet /home/admin/config.scripts/lnd.install.sh off signet /home/admin/config.scripts/cl.install.sh off testnet diff --git a/home.admin/98repairMenu.sh b/home.admin/98repairMenu.sh index 861c8f0c..0a191470 100755 --- a/home.admin/98repairMenu.sh +++ b/home.admin/98repairMenu.sh @@ -130,7 +130,7 @@ case $CHOICE in # make sure host is named like in the raspiblitz config echo "Setting the Name/Alias/Hostname .." sudo /home/admin/config.scripts/lnd.setname.sh mainnet ${result} - sudo sed -i "s/^hostname=.*/hostname=${result}/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set hostname "${result}" echo "stopping lnd ..." sudo systemctl stop lnd diff --git a/home.admin/99clMenu.sh b/home.admin/99clMenu.sh index 1e8a0e9c..a37373f1 100644 --- a/home.admin/99clMenu.sh +++ b/home.admin/99clMenu.sh @@ -7,9 +7,6 @@ source /mnt/hdd/raspiblitz.conf source <(/home/admin/config.scripts/network.aliases.sh getvars cl $1) -# get the local network IP to be displayed on the LCD -source <(/home/admin/config.scripts/internet.sh status local) - # BASIC MENU INFO WIDTH=64 BACKTITLE="RaspiBlitz" @@ -108,7 +105,7 @@ case $CHOICE in clear echo # setting value in the raspiblitz.conf - sudo sed -i "s/^lightning=.*/lightning=cl/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set lightning "cl" echo "# OK - lightning=cl is set in /mnt/hdd/raspiblitz.conf" echo echo "Press ENTER to return to main menu." diff --git a/home.admin/99clRepairMenu.sh b/home.admin/99clRepairMenu.sh index c94588a0..32d7e8fe 100644 --- a/home.admin/99clRepairMenu.sh +++ b/home.admin/99clRepairMenu.sh @@ -7,8 +7,6 @@ source /mnt/hdd/raspiblitz.conf source <(/home/admin/config.scripts/network.aliases.sh getvars cl $1) -# get the local network IP to be displayed on the LCD -source <(/home/admin/config.scripts/internet.sh status local) NETclEncryptedHSM="${netprefix}clEncryptedHSM" # BASIC MENU INFO @@ -100,12 +98,8 @@ case $CHOICE in sudo rm /home/bitcoin/.lightning/${CLNETWORK}/hsm_secret sudo rm /home/bitcoin/.lightning/${CLNETWORK}/*.* # make sure the new hsm_secret is treated as unencrypted and clear autounlock - sudo sed -i \ - "s/^${netprefix}clEncryptedHSM=.*/${netprefix}clEncryptedHSM=off/g" \ - /mnt/hdd/raspiblitz.conf - sudo sed -i \ - "s/^${netprefix}clAutoUnlock=.*/${netprefix}clEncryptedHSM=off/g" \ - /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set ${netprefix}clEncryptedHSM "off" + /home/admin/config.scripts/blitz.conf.sh set ${netprefix}clAutoUnlock "off" # new /home/admin/config.scripts/cl.hsmtool.sh new $CHAIN # set the lightningd service file on each active network diff --git a/home.admin/99connectMenu.sh b/home.admin/99connectMenu.sh index cce5fe81..e6b8c0a6 100644 --- a/home.admin/99connectMenu.sh +++ b/home.admin/99connectMenu.sh @@ -5,8 +5,9 @@ echo "get raspiblitz config" source /home/admin/raspiblitz.info source /mnt/hdd/raspiblitz.conf -# get the local network IP to be displayed on the LCD -source <(/home/admin/config.scripts/internet.sh status local) +source <(/home/admin/_cache.sh get internet_localip internet_localiprange) +localIP="${internet_localip}" +localIPrange="${internet_localiprange}" # BASIC MENU INFO WIDTH=64 @@ -163,10 +164,6 @@ HiddenServicePort 8333 127.0.0.1:8333" | sudo tee -a /etc/tor/torrc fi echo "# Running on ${chain}net" echo - localIPrange=$(ip addr | grep 'state UP' -A2 | grep -E -v 'docker0|veth' |\ - grep 'eth0\|wlan0\|enp0\|inet' | tail -n1 | awk '{print $2}' |\ - awk -F. '{print $1"."$2"."$3".0/24"}') - localIP=$(hostname -I | awk '{print $1}') allowIPrange=$(grep -c "rpcallowip=$localIPrange" < /mnt/hdd/${network}/${network}.conf) bindIP=$(grep -c "${chain}.rpcbind=$localIP" < /mnt/hdd/${network}/${network}.conf) rpcTorService=$(grep -c "HiddenServicePort ${BITCOINRPCPORT} 127.0.0.1:${BITCOINRPCPORT}" < /etc/tor/torrc) @@ -226,10 +223,10 @@ HiddenServicePort 8333 127.0.0.1:8333" | sudo tee -a /etc/tor/torrc case $CHOICE in ADDRPCLAN) - clear + clear echo "# Make sure the bitcoind wallet is on" /home/admin/config.scripts/network.wallet.sh on - + restartCore=0 if [ $allowIPrange -eq 0 ]; then echo "rpcallowip=$localIPrange" | sudo tee -a /mnt/hdd/${network}/${network}.conf @@ -254,7 +251,7 @@ HiddenServicePort 8333 127.0.0.1:8333" | sudo tee -a /etc/tor/torrc clear echo "# Make sure the bitcoind wallet is on" /home/admin/config.scripts/network.wallet.sh on - /home/admin/config.scripts/internet.hiddenservice.sh bitcoin${BITCOINRPCPORT} ${BITCOINRPCPORT} ${BITCOINRPCPORT} + /home/admin/config.scripts/tor.onion-service.sh bitcoin${BITCOINRPCPORT} ${BITCOINRPCPORT} ${BITCOINRPCPORT} echo echo "The address of the local node is: $TorRPCaddress" echo @@ -267,7 +264,7 @@ HiddenServicePort 8333 127.0.0.1:8333" | sudo tee -a /etc/tor/torrc CREDENTIALS) clear showRPCcredentials - echo + echo echo "Press ENTER to return to the menu." read key ;; @@ -275,7 +272,7 @@ HiddenServicePort 8333 127.0.0.1:8333" | sudo tee -a /etc/tor/torrc # remove old entry sudo sed -i "/# Hidden Service for BITCOIN RPC (mainnet, testnet, signet)/,/^\s*$/{d}" /etc/tor/torrc # remove Hidden Service - /home/admin/config.scripts/internet.hiddenservice.sh off bitcoin${BITCOINRPCPORT} + /home/admin/config.scripts/tor.onion-service.sh off bitcoin${BITCOINRPCPORT} sudo ufw deny from $localIPrange to any port ${BITCOINRPCPORT} restartCore=0 if [ $allowIPrange -gt 0 ]; then diff --git a/home.admin/99lndMenu.sh b/home.admin/99lndMenu.sh index 4632c35f..918e3655 100644 --- a/home.admin/99lndMenu.sh +++ b/home.admin/99lndMenu.sh @@ -5,9 +5,6 @@ echo "get raspiblitz config" source /home/admin/raspiblitz.info source /mnt/hdd/raspiblitz.conf -# get the local network IP to be displayed on the LCD -source <(/home/admin/config.scripts/internet.sh status local) - source <(/home/admin/config.scripts/network.aliases.sh getvars lnd $1) # make sure lnd wallet is unlocked @@ -136,7 +133,7 @@ case $CHOICE in clear echo # setting value in raspi blitz config - sudo sed -i "s/^lightning=.*/lightning=lnd/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set lightning "lnd" echo "# OK - lightning=lnd is set in /mnt/hdd/raspiblitz.conf" echo echo "Press ENTER to return to main menu." diff --git a/home.admin/99updateMenu.sh b/home.admin/99updateMenu.sh index 336f2c2a..bfbcccfd 100755 --- a/home.admin/99updateMenu.sh +++ b/home.admin/99updateMenu.sh @@ -14,7 +14,7 @@ release() - Download the new SD card image to your laptop: https://github.com/rootzoll/raspiblitz - Flash that SD card image to a new SD card (best) - or override old SD card after shutdown (fallback) + or override old SD card after shutdown (fallback) - Choose 'Start Update' below. No need to close channels or download blockchain again. @@ -100,9 +100,9 @@ patchNotice() It means it will sync the program code with the GitHub repo for your version branch v${codeVersion}. -This can be useful if there are important updates +This can be useful if there are important updates in between releases to fix severe bugs. It can also -be used to sync your own code with your RaspiBlitz +be used to sync your own code with your RaspiBlitz if you are developing on your own GitHub Repo. BUT BEWARE: This means RaspiBlitz will contact GitHub, @@ -268,7 +268,7 @@ grab the latest LND release published on the LND GitHub page (also release candi There will be no security checks on signature, etc. This update mode is only recommended for testing and -development nodes with no serious funding. +development nodes with no serious funding. Do you really want to update LND now? " 16 58 @@ -337,7 +337,7 @@ grab the latest C-lightning release published on the C-lightning GitHub page (al There will be no security checks on signature, etc. This update mode is only recommended for testing and -development nodes with no serious funding. +development nodes with no serious funding. Do you really want to update C-lightning now? " 16 58 @@ -404,9 +404,8 @@ Do you really want to update Bitcoin Core now? source <(sudo -u admin /home/admin/config.scripts/bitcoin.update.sh tested) if [ ${#error} -gt 0 ]; then whiptail --title "ERROR" --msgbox "${error}" 8 30 - else - sleep 8 fi + /home/admin/config.scripts/blitz.shutdown.sh reboot ;; RECKLESS) whiptail --title "UNTESTED Bitcoin Core update to ${bitcoinLatestVersion}" --yes-button "Cancel" \ @@ -426,12 +425,12 @@ Do you really want to update Bitcoin Core now? source <(sudo -u admin /home/admin/config.scripts/bitcoin.update.sh reckless) if [ ${#error} -gt 0 ]; then whiptail --title "ERROR" --msgbox "${error}" 8 30 - else - sleep 8 fi + /home/admin/config.scripts/blitz.shutdown.sh reboot ;; CUSTOM) sudo -u admin /home/admin/config.scripts/bitcoin.update.sh custom + /home/admin/config.scripts/blitz.shutdown.sh reboot ;; esac } @@ -490,7 +489,7 @@ if [ "${runBehindTor}" == "on" ]; then fi CHOICE_HEIGHT=$(("${#OPTIONS[@]}/2+1")) -HEIGHT=$((CHOICE_HEIGHT+6)) +HEIGHT=$((CHOICE_HEIGHT+6)) CHOICE=$(dialog --clear \ --backtitle "" \ --title " Update Options " \ @@ -536,9 +535,9 @@ case $CHOICE in /home/admin/config.scripts/bonus.pyblock.sh update ;; TOR) - sudo /home/admin/config.scripts/internet.tor.sh update + sudo /home/admin/config.scripts/tor.network.sh update ;; MEMPOOL) - /home/admin/config.scripts/bonus.mempool.sh update + /home/admin/config.scripts/bonus.mempool.sh update ;; esac diff --git a/home.admin/BBcashoutWallet.sh b/home.admin/BBcashoutWallet.sh index 55b13783..774a6cb7 100755 --- a/home.admin/BBcashoutWallet.sh +++ b/home.admin/BBcashoutWallet.sh @@ -90,6 +90,10 @@ echo "******************************" echo "Sweep all possible Funds" echo "******************************" +# raise high focus on onchain wallet balance & pending for the next 15min +/home/admin/_cache.sh focus ln_${LNTYPE}_${$chain}net_wallet_onchain_pending 0 900 +/home/admin/_cache.sh focus ln_${LNTYPE}_${$chain}net_wallet_onchain_balance 0 900 + # execute command if [ ${LNTYPE} = "cl" ];then # withdraw destination satoshi [feerate] [minconf] [utxos] diff --git a/home.admin/BBcloseAllChannels.sh b/home.admin/BBcloseAllChannels.sh index 3437ec41..b69fba68 100755 --- a/home.admin/BBcloseAllChannels.sh +++ b/home.admin/BBcloseAllChannels.sh @@ -67,6 +67,11 @@ else echo "# OK - the chain is synced" fi +# raise high focus on lightning channels next 1 hour +/home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_channels_active 0 3600 +/home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_channels_inactive 0 3600 +/home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_channels_total 0 3600 + echo "#####################################" echo "# Closing All Channels (EXPERIMENTAL)" echo "#####################################" diff --git a/home.admin/BBconnectPeer.sh b/home.admin/BBconnectPeer.sh index 75edfb96..baba1a3b 100755 --- a/home.admin/BBconnectPeer.sh +++ b/home.admin/BBconnectPeer.sh @@ -16,6 +16,9 @@ fi source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) +# raise high focus on lightning peers next 5min +/home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_peers 0 300 + # let user enter a @host l1="Enter the node pubkey address with host information:" l2="example -----> 024ddf33[...]1f5f9f3@91.65.1.38:9735" diff --git a/home.admin/BBcreateInvoice.sh b/home.admin/BBcreateInvoice.sh index 66374a50..e2934283 100755 --- a/home.admin/BBcreateInvoice.sh +++ b/home.admin/BBcreateInvoice.sh @@ -17,7 +17,6 @@ if [ ${#chain} -eq 0 ]; then fi source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) - source <(/home/admin/config.scripts/network.aliases.sh getvars $LNTYPE ${chain}net) # check if chain is in sync @@ -127,6 +126,9 @@ else sudo apt-get install qrencode -y > /dev/null fi + # raise high focus on lightning channel balance next 5min + /home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_channels_balance 0 300 + echo echo "********************" echo "Here is your invoice" diff --git a/home.admin/BBfundWallet.sh b/home.admin/BBfundWallet.sh index 48160616..6c7090bb 100755 --- a/home.admin/BBfundWallet.sh +++ b/home.admin/BBfundWallet.sh @@ -81,6 +81,10 @@ fi echo "generating QR code ... please wait" /home/admin/config.scripts/blitz.display.sh qr "$network:${address}" +# raise high focus on onchain wallet balance & pending for the next 15min +/home/admin/_cache.sh focus ln_${LNTYPE}_${$chain}net_wallet_onchain_pending 0 900 +/home/admin/_cache.sh focus ln_${LNTYPE}_${$chain}net_wallet_onchain_balance 0 900 + # dialog with instructions while QR code is shown on LCD whiptail --backtitle "Fund your onchain wallet" \ --title "Send ${coininfo}" \ diff --git a/home.admin/BBopenChannel.sh b/home.admin/BBopenChannel.sh index 8890d117..98448364 100755 --- a/home.admin/BBopenChannel.sh +++ b/home.admin/BBopenChannel.sh @@ -79,6 +79,11 @@ if [ ${numConnectedPeers} -eq 0 ]; then exit 0 fi +# raise high focus on lightning channels next 1 hour +/home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_channels_pending 0 3600 +/home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_channels_total 0 3600 +/home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_channels_active 0 3600 + # let user pick a peer to open a channels with OPTIONS=() if [ $LNTYPE = cl ];then diff --git a/home.admin/BBpayInvoice.sh b/home.admin/BBpayInvoice.sh index 2fb2a361..57630d32 100755 --- a/home.admin/BBpayInvoice.sh +++ b/home.admin/BBpayInvoice.sh @@ -104,6 +104,9 @@ elif [ $LNTYPE = lnd ];then command="$lncli_alias sendpayment --force --pay_req=${invoice}" fi +# raise high focus on lightning channel balance next 5min +/home/admin/_cache.sh focus ln_${LNTYPE}_${$CHAIN}_channels_balance 0 300 + # info output clear echo "************************************************************" diff --git a/home.admin/_background.scan.sh b/home.admin/_background.scan.sh new file mode 100755 index 00000000..43c63a2f --- /dev/null +++ b/home.admin/_background.scan.sh @@ -0,0 +1,938 @@ +#!/bin/bash + +# This script will loop in the background to gather basic system information. +# It will place those values in the `_cache.sh` system and take care about updates. +# You can use `_cache.sh focus` to make the scanning of a certain value more often. + +# LOGS see: sudo journalctl -f -u background.scan + +# start with parameter "only-one-loop" (use for testing) +ONLY_ONE_LOOP="0" +if [ "$1" == "only-one-loop" ]; then + ONLY_ONE_LOOP="1" +fi +# start with parameter "install" (to setup service as systemd background running) +if [ "$1" == "install" ]; then + + # write systemd service + cat > /etc/systemd/system/background.scan.service </dev/null)" + fi + + ################# + # UPS (uninterruptible power supply) + + source <(/home/admin/_cache.sh valid system_ups_status) + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then + echo "updating: /home/admin/config.scripts/blitz.ups.sh status" + source <(/home/admin/config.scripts/blitz.ups.sh status) + /home/admin/_cache.sh set system_ups_status "${upsStatus}" + fi + + ################# + # DATADRIVE + + source <(/home/admin/_cache.sh valid \ + hdd_mounted \ + hdd_ssd \ + hdd_btrfs \ + hdd_raid \ + hdd_uasp \ + hdd_capacity_bytes \ + hdd_capacity_gb \ + hdd_free_bytes \ + hdd_free_gb \ + hdd_used_info \ + hdd_blockchain_data \ + ) + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE2} ]; then + echo "updating: /home/admin/config.scripts/blitz.datadrive.sh status" + source <(/home/admin/config.scripts/blitz.datadrive.sh status) + /home/admin/_cache.sh set hdd_mounted "${isMounted}" + /home/admin/_cache.sh set hdd_ssd "${isSSD}" + /home/admin/_cache.sh set hdd_btrfs "${isBTRFS}" + /home/admin/_cache.sh set hdd_raid "${isRaid}" + /home/admin/_cache.sh set hdd_uasp "${hddAdapterUSAP}" + /home/admin/_cache.sh set hdd_capacity_bytes "${hddBytes}" + /home/admin/_cache.sh set hdd_capacity_gb "${hddGigaBytes}" + /home/admin/_cache.sh set hdd_free_bytes "${hddDataFreeBytes}" + /home/admin/_cache.sh set hdd_free_gb "${hddDataFreeGB}" + /home/admin/_cache.sh set hdd_used_info "${hddUsedInfo}" + /home/admin/_cache.sh set hdd_blockchain_data "${hddBlocksBitcoin}" + fi + + ################# + # INTERNET + + # GLOBAL & PUBLIC IP + source <(/home/admin/_cache.sh get runBehindTor) + if [ "${runBehindTor}" == "off" ]; then + source <(/home/admin/_cache.sh valid \ + internet_public_ipv6 \ + internet_public_ip_detected \ + internet_public_ip_forced \ + internet_public_ip_clean \ + ) + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${HOUR} ]; then + echo "updating: /home/admin/config.scripts/internet.sh status global" + source <(/home/admin/config.scripts/internet.sh status global) + /home/admin/_cache.sh set internet_public_ipv6 "${ipv6}" + # globalip --> ip detected from the outside + /home/admin/_cache.sh set internet_public_ip_detected "${globalip}" + # publicip --> may consider the static IP overide by raspiblitz config + /home/admin/_cache.sh set internet_public_ip_forced "${publicip}" + # cleanip --> the publicip with no brackets like used on IPv6 + /home/admin/_cache.sh set internet_public_ip_clean "${cleanip}" + fi + fi + + # LOCAL IP & data + source <(/home/admin/_cache.sh valid \ + internet_localip \ + internet_localiprange \ + internet_dhcp \ + internet_rx \ + internet_tx \ + ) + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then + echo "updating: /home/admin/config.scripts/internet.sh status local" + source <(/home/admin/config.scripts/internet.sh status local) + /home/admin/_cache.sh set internet_localip "${localip}" + /home/admin/_cache.sh set internet_localiprange "${localiprange}" + /home/admin/_cache.sh set internet_dhcp "${dhcp}" + /home/admin/_cache.sh set internet_rx "${network_rx}" + /home/admin/_cache.sh set internet_tx "${network_tx}" + fi + + # connection to internet + source <(/home/admin/_cache.sh valid internet_online) + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${HOURQUATER} ]; then + echo "updating: /home/admin/config.scripts/internet.sh status online" + source <(/home/admin/config.scripts/internet.sh status online) + /home/admin/_cache.sh set internet_online "${online}" + fi + + # exit if still setup or higher system stopped + source <(/home/admin/_cache.sh get setupPhase state) + if [ "${setupPhase}" != "done" ] || + [ "${state}" == "" ] || + [ "${state}" == "copysource" ] || + [ "${state}" == "copytarget" ]; then + + # dont skip when setup/recovery is in "waitsync" state + if [ "${state}" != "waitsync" ]; then + endTime=$(date +%s) + runTime=$((${endTime}-${startTime})) + # write info on scan runtime into cache (use as signal that the first systemscan worked) + /home/admin/_cache.sh set systemscan_runtime "${runTime}" + echo "Skipping deeper system scan - setupPhase(${setupPhase}) state(${state})" + sleep 1 + continue + fi + + fi + + #################################################################### + # LOOP DATA (DEEPER SYSTEM) + # data that may be based on setup phase or configuration + #################################################################### + + # by default will only scan the btc & lightning instances that are set to default + # but can scan/monitor all that are switched on when `system_scan_all=on` in config + + # read/update config values + source /mnt/hdd/raspiblitz.conf + + # check if a one time `system_scan_all_once=1` is set on cache + # will trigger a scan_all for one loop + source <(/home/admin/_cache.sh get system_scan_all_once) + if [ "${system_scan_all_once}" == "1" ]; then + echo "system_scan_all_once found --> TRIGGER system_scan_all for one loop" + /home/admin/_cache.sh set system_scan_all_once "0" + system_scan_all="on" + fi + + # check if a temporary `system_scan_all_temp=1` is set on cache + # will trigger a scan_all until its gone or `0` + source <(/home/admin/_cache.sh get system_scan_all_temp) + if [ "${system_scan_all_temp}" == "1" ]; then + echo "system_scan_all_temp found --> TRIGGER system_scan_all" + system_scan_all="on" + fi + + ################### + # BITCOIN + + if [ "${network}" == "bitcoin" ]; then + + # loop thru mainet, testnet & signet + networks=( "main" "test" "sig" ) + for CHAIN in "${networks[@]}" + do + + # check if is default chain (multiple networks can run at the same time - but only one is default) + isDefaultChain=$(echo "${CHAIN}" | grep -c "${chain}") + + # skip if network is not on by config + if [ "${CHAIN}" == "main" ] && [ "${mainnet}" != "on" ] && [ "${isDefaultChain}" != "1" ]; then + #echo "skip btc ${CHAIN}net scan - because its off" + continue + fi + if [ "${CHAIN}" == "test" ] && [ "${testnet}" != "on" ]; then + #echo "skip btc ${CHAIN}net scan - because its off" + continue + fi + if [ "${CHAIN}" == "sig" ] && [ "${signet}" != "on" ]; then + #echo "skip btc ${CHAIN}net scan - because its off" + continue + fi + + # only scan non defaults when set by parameter from config + if [ "${system_scan_all}" != "on" ]; then + if [ "${isDefaultChain}" != "1" ]; then + #echo "skip btc ${CHAIN}net scan - because its not default" + continue + fi + fi + + # update basic status values always + source <(/home/admin/_cache.sh valid \ + btc_${CHAIN}net_version \ + btc_${CHAIN}net_running \ + btc_${CHAIN}net_ready \ + btc_${CHAIN}net_online \ + btc_${CHAIN}net_error_short \ + btc_${CHAIN}net_error_full \ + ) + if [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + btc_default_version \ + btc_default_running \ + btc_default_ready \ + btc_default_online \ + btc_default_error_short \ + btc_default_error_full \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt 30 ]; then + echo "updating: /home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net status" + source <(/home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net status) + /home/admin/_cache.sh set btc_${CHAIN}net_activated "1" + /home/admin/_cache.sh set btc_${CHAIN}net_version "${btc_version}" + /home/admin/_cache.sh set btc_${CHAIN}net_running "${btc_running}" + /home/admin/_cache.sh set btc_${CHAIN}net_ready "${btc_ready}" + /home/admin/_cache.sh set btc_${CHAIN}net_online "${btc_online}" + /home/admin/_cache.sh set btc_${CHAIN}net_error_short "${btc_error_short}" + /home/admin/_cache.sh set btc_${CHAIN}net_error_full "${btc_error_full}" + + # when default chain transfere values + if [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set btc_default_activated "1" + /home/admin/_cache.sh set btc_default_version "${btc_version}" + /home/admin/_cache.sh set btc_default_running "${btc_running}" + /home/admin/_cache.sh set btc_default_ready "${btc_ready}" + /home/admin/_cache.sh set btc_default_online "${btc_online}" + /home/admin/_cache.sh set btc_default_error_short "${btc_error_short}" + /home/admin/_cache.sh set btc_default_error_full "${btc_error_full}" + fi + fi + + # update detail infos only when ready (get as value from cache) + source <(/home/admin/_cache.sh meta btc_${CHAIN}net_ready) + if [ "${value}" == "1" ]; then + + # check if network needs update + source <(/home/admin/_cache.sh valid \ + btc_${CHAIN}net_synced \ + btc_${CHAIN}net_blocks_headers \ + btc_${CHAIN}net_blocks_verified \ + btc_${CHAIN}net_blocks_behind \ + btc_${CHAIN}net_sync_progress \ + btc_${CHAIN}net_sync_percentage \ + btc_${CHAIN}net_sync_initialblockdownload \ + ) + if [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + btc_default_synced \ + btc_default_blocks_headers \ + btc_default_blocks_verified \ + btc_default_blocks_behind \ + btc_default_sync_progress \ + btc_default_sync_percentage \ + btc_default_sync_initialblockdownload \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then + error="" + echo "updating: /home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net info" + source <(/home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net info) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set btc_${CHAIN}net_synced "${btc_synced}" + /home/admin/_cache.sh set btc_${CHAIN}net_blocks_headers "${btc_blocks_headers}" + /home/admin/_cache.sh set btc_${CHAIN}net_blocks_verified "${btc_blocks_verified}" + /home/admin/_cache.sh set btc_${CHAIN}net_blocks_behind "${btc_blocks_behind}" + /home/admin/_cache.sh set btc_${CHAIN}net_sync_progress "${btc_sync_progress}" + /home/admin/_cache.sh set btc_${CHAIN}net_sync_percentage "${btc_sync_percentage}" + /home/admin/_cache.sh set btc_${CHAIN}net_sync_initialblockdownload "${btc_sync_initialblockdownload}" + if [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set btc_default_synced "${btc_synced}" + /home/admin/_cache.sh set btc_default_blocks_headers "${btc_blocks_headers}" + /home/admin/_cache.sh set btc_default_blocks_verified "${btc_blocks_verified}" + /home/admin/_cache.sh set btc_default_blocks_behind "${btc_blocks_behind}" + /home/admin/_cache.sh set btc_default_sync_progress "${btc_sync_progress}" + /home/admin/_cache.sh set btc_default_sync_percentage "${btc_sync_percentage}" + /home/admin/_cache.sh set btc_default_sync_initialblockdownload "${btc_sync_initialblockdownload}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + + # check if network needs update + source <(/home/admin/_cache.sh valid \ + btc_${CHAIN}net_peers \ + btc_${CHAIN}net_address \ + btc_${CHAIN}net_port \ + ) + if [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + btc_default_peers \ + btc_default_address \ + btc_default_port \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then + error="" + echo "updating: /home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net network" + source <(/home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net network) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set btc_${CHAIN}net_peers "${btc_peers}" + /home/admin/_cache.sh set btc_${CHAIN}net_address "${btc_address}" + /home/admin/_cache.sh set btc_${CHAIN}net_port "${btc_port}" + if [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set btc_default_peers "${btc_peers}" + /home/admin/_cache.sh set btc_default_address "${btc_address}" + /home/admin/_cache.sh set btc_default_port "${btc_port}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + + # check if mempool needs update + source <(/home/admin/_cache.sh valid \ + btc_${CHAIN}net_mempool_transactions \ + ) + if [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + btc_default_mempool_transactions \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE5} ]; then + error="" + echo "updating: /home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net mempool" + source <(/home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net mempool) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set btc_${CHAIN}net_mempool_transactions "${btc_mempool_transactions}" + if [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set btc_default_mempool_transactions "${btc_mempool_transactions}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + fi + done + fi + + ################### + # Lightning (lnd) + + # loop thru mainet, testnet & signet + networks=( "main" "test" "sig" ) + for CHAIN in "${networks[@]}" + do + + # skip if network is not on by config + if [ "${CHAIN}" == "main" ] && [ "${lnd}" != "on" ]; then + #echo "skip lnd ${CHAIN}net scan - because its off" + continue + fi + if [ "${CHAIN}" == "test" ] && [ "${tlnd}" != "on" ]; then + #echo "skip lnd ${CHAIN}net scan - because its off" + continue + fi + if [ "${CHAIN}" == "sig" ] && [ "${slnd}" != "on" ]; then + #echo "skip lnd ${CHAIN}net scan - because its off" + continue + fi + + # check if default chain & lightning + isDefaultChain=$(echo "${CHAIN}" | grep -c "${chain}") + isDefaultLightning=$(echo "${lightning}" | grep -c "lnd") + + # only scan non defaults when set by parameter from config + if [ "${system_scan_all}" != "on" ]; then + if [ "${isDefaultChain}" != "1" ] || [ ${isDefaultLightning} != "1" ]; then + #echo "skip lnd ${CHAIN}net scan - because its not default" + continue + fi + fi + + # update basic status values always + source <(/home/admin/_cache.sh valid \ + ln_lnd_${CHAIN}net_locked \ + ln_lnd_${CHAIN}net_version \ + ln_lnd_${CHAIN}net_running \ + ln_lnd_${CHAIN}net_ready \ + ln_lnd_${CHAIN}net_online \ + ln_lnd_${CHAIN}net_error_short \ + ln_lnd_${CHAIN}net_error_full \ + ) + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + ln_default_locked \ + ln_default_version \ + ln_default_running \ + ln_default_ready \ + ln_default_online \ + ln_default_error_short \ + ln_default_error_full \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt 30 ]; then + echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net status" + source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net status) + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_activated "1" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_locked "${ln_lnd_locked}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_version "${ln_lnd_version}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_running "${ln_lnd_running}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_ready "${ln_lnd_ready}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_online "${ln_lnd_online}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_error_short "${ln_lnd_error_short}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_error_full "${ln_lnd_error_full}" + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set ln_default_activated "1" + /home/admin/_cache.sh set ln_default_locked "${ln_lnd_locked}" + /home/admin/_cache.sh set ln_default_version "${ln_lnd_version}" + /home/admin/_cache.sh set ln_default_running "${ln_lnd_running}" + /home/admin/_cache.sh set ln_default_ready "${ln_lnd_ready}" + /home/admin/_cache.sh set ln_default_online "${ln_lnd_online}" + /home/admin/_cache.sh set ln_default_error_short "${ln_lnd_error_short}" + /home/admin/_cache.sh set ln_default_error_full "${ln_lnd_error_full}" + fi + fi + + # update detail infos only when ready + source <(/home/admin/_cache.sh meta ln_lnd_${CHAIN}net_ready) + if [ "${value}" == "1" ]; then + + # check if config needs update + source <(/home/admin/_cache.sh valid ln_lnd_${CHAIN}net_alias) + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE5} ]; then + error="" + echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net config" + source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net config) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_alias "${ln_lnd_alias}" + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set ln_default_alias "${ln_lnd_alias}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + + # check if info needs update + source <(/home/admin/_cache.sh valid \ + ln_lnd_${CHAIN}net_address \ + ln_lnd_${CHAIN}net_tor \ + ln_lnd_${CHAIN}net_sync_chain \ + ln_lnd_${CHAIN}net_sync_graph \ + ln_lnd_${CHAIN}net_channels_pending \ + ln_lnd_${CHAIN}net_channels_active \ + ln_lnd_${CHAIN}net_channels_inactive \ + ln_lnd_${CHAIN}net_channels_total \ + ln_lnd_${CHAIN}net_peers \ + ) + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + ln_default_address \ + ln_default_tor \ + ln_default_sync_chain \ + ln_default_sync_progress \ + ln_default_channels_pending \ + ln_default_channels_active \ + ln_default_channels_inactive \ + ln_default_channels_total \ + ln_default_peers \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then + error="" + echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net info" + source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net info) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_address "${ln_lnd_address}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_tor "${ln_lnd_tor}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_sync_chain "${ln_lnd_sync_chain}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_sync_progress "${ln_lnd_sync_progress}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_sync_graph "${ln_lnd_sync_graph}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_channels_pending "${ln_lnd_channels_pending}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_channels_active "${ln_lnd_channels_active}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_channels_inactive "${ln_lnd_channels_inactive}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_channels_total "${ln_lnd_channels_total}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_peers "${ln_lnd_peers}" + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set ln_default_address "${ln_lnd_address}" + /home/admin/_cache.sh set ln_default_tor "${ln_lnd_tor}" + /home/admin/_cache.sh set ln_default_sync_chain "${ln_lnd_sync_chain}" + /home/admin/_cache.sh set ln_default_sync_progress "${ln_lnd_sync_progress}" + /home/admin/_cache.sh set ln_default_channels_pending "${ln_lnd_channels_pending}" + /home/admin/_cache.sh set ln_default_channels_active "${ln_lnd_channels_active}" + /home/admin/_cache.sh set ln_default_channels_inactive "${ln_lnd_channels_inactive}" + /home/admin/_cache.sh set ln_default_channels_total "${ln_lnd_channels_total}" + /home/admin/_cache.sh set ln_default_peers "${ln_lnd_peers}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + + # check if wallet needs update + source <(/home/admin/_cache.sh valid \ + ln_lnd_${CHAIN}net_wallet_onchain_balance \ + ln_lnd_${CHAIN}net_wallet_onchain_pending \ + ln_lnd_${CHAIN}net_wallet_channels_balance \ + ln_lnd_${CHAIN}net_wallet_channels_pending \ + ) + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + ln_default_wallet_onchain_balance \ + ln_default_wallet_onchain_pending \ + ln_default_wallet_channels_balance \ + ln_default_wallet_channels_pending \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt 22 ]; then + error="" + echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net wallet" + source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net wallet) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_wallet_onchain_balance "${ln_lnd_wallet_onchain_balance}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_wallet_onchain_pending "${ln_lnd_wallet_onchain_pending}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_wallet_channels_balance "${ln_lnd_wallet_channels_balance}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_wallet_channels_pending "${ln_lnd_wallet_channels_pending}" + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set ln_default_wallet_onchain_balance "${ln_lnd_wallet_onchain_balance}" + /home/admin/_cache.sh set ln_default_wallet_onchain_pending "${ln_lnd_wallet_onchain_pending}" + /home/admin/_cache.sh set ln_default_wallet_channels_balance "${ln_lnd_wallet_channels_balance}" + /home/admin/_cache.sh set ln_default_wallet_channels_pending "${ln_lnd_wallet_channels_pending}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + + # check if fees needs update + source <(/home/admin/_cache.sh valid \ + ln_lnd_${CHAIN}net_fees_daily \ + ln_lnd_${CHAIN}net_fees_weekly \ + ln_lnd_${CHAIN}net_fees_month \ + ln_lnd_${CHAIN}net_fees_total \ + ) + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + ln_default_fees_total \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE5} ]; then + error="" + echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net fees" + source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net fees) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_fees_daily "${ln_lnd_fees_daily}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_fees_weekly "${ln_lnd_fees_weekly}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_fees_month "${ln_lnd_fees_month}" + /home/admin/_cache.sh set ln_lnd_${CHAIN}net_fees_total "${ln_lnd_fees_total}" + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set ln_default_fees_total "${ln_lnd_fees_total}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + fi + done + + ################### + # Lightning (c-lightning) + + # loop thru mainet, testnet & signet + networks=( "main" "test" "sig" ) + for CHAIN in "${networks[@]}" + do + + # skip if network is not on by config + if [ "${CHAIN}" == "main" ] && [ "${cl}" != "on" ]; then + #echo "skip c-lightning mainnet scan - because its off" + continue + fi + if [ "${CHAIN}" == "test" ] && [ "${tcl}" != "on" ]; then + #echo "skip c-lightning testnet scan - because its off" + continue + fi + if [ "${CHAIN}" == "sig" ] && [ "${scl}" != "on" ]; then + #echo "skip c-lightning signet scan - because its off" + continue + fi + + # check if default chain & lightning + isDefaultChain=$(echo "${CHAIN}" | grep -c "${chain}") + isDefaultLightning=$(echo "${lightning}" | grep -c "cl") + + # only scan non defaults when set by parameter from config + if [ "${system_scan_all}" != "on" ]; then + if [ "${isDefaultChain}" != "1" ] || [ ${isDefaultLightning} != "1" ]; then + #echo "skip cl ${CHAIN}net scan - because its not default" + continue + fi + fi + + # TODO: c-lightning is seen as "always unlocked" for now - needs to be implemented later #2691 + + # update basic status values always + source <(/home/admin/_cache.sh valid \ + ln_cl_${CHAIN}net_version \ + ln_cl_${CHAIN}net_running \ + ln_cl_${CHAIN}net_ready \ + ln_cl_${CHAIN}net_online \ + ln_cl_${CHAIN}net_error_short \ + ln_cl_${CHAIN}net_error_full \ + ) + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + ln_default_version \ + ln_default_running \ + ln_default_ready \ + ln_default_online \ + ln_default_error_short \ + ln_default_error_full \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt 30 ]; then + echo "updating: /home/admin/config.scripts/cl.monitor.sh ${CHAIN}net status" + source <(/home/admin/config.scripts/cl.monitor.sh ${CHAIN}net status) + /home/admin/_cache.sh set ln_cl_${CHAIN}net_activated "1" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_version "${ln_cl_version}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_running "${ln_cl_running}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_ready "${ln_cl_ready}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_online "${ln_cl_online}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_locked "0" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_error_short "${ln_cl_error_short}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_error_full "${ln_cl_error_full}" + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set ln_default_activated "1" + /home/admin/_cache.sh set ln_default_version "${cl_lnd_version}" + /home/admin/_cache.sh set ln_default_running "${lc_running}" + /home/admin/_cache.sh set ln_default_ready "${cl_ready}" + /home/admin/_cache.sh set ln_default_online "${cl_online}" + /home/admin/_cache.sh set ln_default_locked "0" + /home/admin/_cache.sh set ln_default_error_short "${cl_error_short}" + /home/admin/_cache.sh set ln_default_error_full "${cl_error_full}" + fi + fi + + # update detail infos only when ready + source <(/home/admin/_cache.sh meta ln_cl_${CHAIN}net_ready) + if [ "${value}" == "1" ]; then + + # check if info needs update + source <(/home/admin/_cache.sh valid \ + ln_cl_${CHAIN}net_alias \ + ln_cl_${CHAIN}net_address \ + ln_cl_${CHAIN}net_tor \ + ln_cl_${CHAIN}net_peers \ + ln_cl_${CHAIN}net_sync_chain \ + ln_cl_${CHAIN}net_channels_pending \ + ln_cl_${CHAIN}net_channels_active \ + ln_cl_${CHAIN}net_channels_inactive \ + ln_cl_${CHAIN}net_channels_total \ + ln_cl_${CHAIN}net_fees_total \ + ) + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + ln_default_alias \ + ln_default_address \ + ln_default_tor \ + ln_default_peers \ + ln_default_sync_chain \ + ln_default_channels_pending \ + ln_default_channels_active \ + ln_default_channels_inactive \ + ln_default_channels_total \ + ln_default_fees_total \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then + error="" + echo "updating: /home/admin/config.scripts/cl.monitor.sh ${CHAIN}net info" + source <(/home/admin/config.scripts/cl.monitor.sh ${CHAIN}net info) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set ln_cl_${CHAIN}net_alias "${ln_cl_alias}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_address "${ln_cl_address}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_tor "${ln_cl_tor}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_peers "${ln_cl_peers}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_sync_chain "${ln_cl_sync_chain}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_sync_progress "${ln_cl_sync_progress}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_channels_pending "${ln_cl_channels_pending}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_channels_active "${ln_cl_channels_active}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_channels_inactive "${ln_cl_channels_inactive}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_channels_total "${ln_cl_channels_total}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_fees_total "${ln_cl_fees_total}" + + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set ln_default_alias "${ln_cl_alias}" + /home/admin/_cache.sh set ln_default_address "${ln_cl_address}" + /home/admin/_cache.sh set ln_default_tor "${ln_cl_tor}" + /home/admin/_cache.sh set ln_default_peers "${ln_cl_fees_total}" + /home/admin/_cache.sh set ln_default_sync_chain "${ln_cl_sync_chain}" + /home/admin/_cache.sh set ln_default_sync_progress "${ln_cl_sync_progress}" + /home/admin/_cache.sh set ln_default_hannels_pending "${ln_cl_channels_pending}" + /home/admin/_cache.sh set ln_default_channels_active "${ln_cl_channels_active}" + /home/admin/_cache.sh set ln_default_channels_inactive "${ln_cl_channels_inactive}" + /home/admin/_cache.sh set ln_default_channels_total "${ln_cl_channels_total}" + /home/admin/_cache.sh set ln_default_fees_total "${ln_cl_fees_total}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + + # check if wallet needs update + source <(/home/admin/_cache.sh valid \ + ln_cl_${CHAIN}net_wallet_onchain_balance \ + ln_cl_${CHAIN}net_wallet_onchain_pending \ + ln_cl_${CHAIN}net_wallet_channels_balance \ + ln_cl_${CHAIN}net_wallet_channels_pending \ + ) + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then + source <(/home/admin/_cache.sh valid \ + ln_default_wallet_onchain_balance \ + ln_default_wallet_onchain_pending \ + ln_default_wallet_channels_balance \ + ln_default_wallet_channels_pending \ + ) + fi + if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then + error="" + echo "updating: /home/admin/config.scripts/cl.monitor.sh ${CHAIN}net wallet" + source <(/home/admin/config.scripts/cl.monitor.sh ${CHAIN}net wallet) + if [ "${error}" == "" ]; then + /home/admin/_cache.sh set ln_cl_${CHAIN}net_wallet_onchain_balance "${ln_cl_wallet_onchain_balance}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_wallet_onchain_pending "${ln_cl_wallet_onchain_pending}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_wallet_channels_balance "${ln_cl_wallet_channels_balance}" + /home/admin/_cache.sh set ln_cl_${CHAIN}net_wallet_channels_pending "${ln_cl_wallet_channels_pending}" + if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then + /home/admin/_cache.sh set ln_default_wallet_onchain_balance "${ln_cl_wallet_onchain_balance}" + /home/admin/_cache.sh set ln_default_wallet_onchain_pending "${ln_cl_wallet_onchain_pending}" + /home/admin/_cache.sh set ln_default_wallet_channels_balance "${ln_cl_wallet_channels_balance}" + /home/admin/_cache.sh set ln_default_wallet_channels_pending "${ln_cl_wallet_channels_pending}" + fi + else + echo "!! ERROR --> ${error}" + fi + fi + fi + done + + ################# + # DONE + + # calculate how many seconds the script was running + endTime=$(date +%s) + runTime=$((${endTime}-${startTime})) + + # write info on scan runtime into cache (use as signal that the first systemscan worked) + /home/admin/_cache.sh set systemscan_runtime "${runTime}" + echo "SystemScan Loop done in ${runTime} seconds" + + # log warning if script took too long + if [ ${runTime} -gt ${MINUTE} ]; then + echo "WARNING: HANGING SYSTEM ... systemscan loop took too long (${runTime} seconds)!" 1>&2 + /home/admin/_cache.sh increment system_count_longscan + fi + + # small sleep before next loop + sleep 2 + + # if was started with special parameter + if [ "${ONLY_ONE_LOOP}" == "1" ]; then + echo "Exiting because ONLY_ONE_LOOP==1" + exit 0 + fi + +done \ No newline at end of file diff --git a/home.admin/_background.sh b/home.admin/_background.sh index 59f06512..a5cb4eef 100755 --- a/home.admin/_background.sh +++ b/home.admin/_background.sh @@ -12,19 +12,11 @@ configFile="/mnt/hdd/raspiblitz.conf" # LOGS see: sudo journalctl -f -u background -# Check if HDD contains configuration -configExists=$(ls ${configFile} | grep -c '.conf') -if [ ${configExists} -eq 1 ]; then - source ${configFile} -else - source ${infoFile} -fi - echo "_background.sh STARTED" # global vars blitzTUIHeartBeatLine="" -blitzTUIRestarts=0 +/home/admin/_cache.sh set blitzTUIRestarts "0" counter=0 while [ 1 ] @@ -47,8 +39,10 @@ do # gather the uptime seconds upSeconds=$(cat /proc/uptime | grep -o '^[0-9]\+') - # source info file fresh on every loop + # source info & config file fresh on every loop source ${infoFile} 2>/dev/null + source ${configFile} 2>/dev/null + source <(/home/admin/_cache.sh get state setupPhase) #################################################### # SKIP BACKGROUND TASK LOOP ON CERTAIN SYSTEM STATES @@ -61,16 +55,6 @@ do continue fi - #################################################### - # CHECK IF LOCAL IP CHANGED - #################################################### - oldLocalIP="${localip}"; - source <(/home/admin/config.scripts/internet.sh status) - if [ "${oldLocalIP}" != "${localip}" ]; then - echo "local IP changed old(${oldLocalIP}) new(${localip}) - updating in raspiblitz.info" - sed -i "s/^localip=.*/localip='${localip}'/g" ${infoFile} - fi - #################################################### # SKIP REST OF THE TASKS IF STILL IN SETUP PHASE #################################################### @@ -98,32 +82,13 @@ do # detect a missing DHCP config if [ "${localip:0:4}" = "169." ]; then echo "Missing DHCP detected ... trying emergency reboot" - sudo /home/admin/config.scripts/blitz.shutdown.sh reboot + /home/admin/config.scripts/blitz.shutdown.sh reboot else echo "DHCP OK" fi fi - #################################################### - # CHECK FOR UNDERVOLTAGE REPORTS - # every 1 hour scan for undervoltage reports - #################################################### - recheckUndervoltage=$(($counter % 3600)) - if [ ${recheckUndervoltage} -eq 1 ]; then - echo "*** RECHECK UNDERVOLTAGE ***" - countReports=$(sudo cat /var/log/syslog | grep -c "Under-voltage detected!") - echo "${countReports} undervoltage reports found in syslog" - if ! grep -Eq "^undervoltageReports=" ${infoFile}; then - # write new value to info file - undervoltageReports="${countReports}" - echo "undervoltageReports=${undervoltageReports}" >> ${infoFile} - else - # update value in info file - sed -i "s/^undervoltageReports=.*/undervoltageReports=${countReports}/g" ${infoFile} - fi - fi - #################################################### # RECHECK PUBLIC IP # @@ -136,6 +101,7 @@ do # every 15min - not too often # because its a ping to external service recheckPublicIP=$((($counter % 900)+1)) + # prevent when lndAddress is set if [ ${#lndAddress} -gt 3 ]; then recheckPublicIP=0 @@ -151,9 +117,7 @@ do echo "*** RECHECK PUBLIC IP ***" # execute only after setup when config exists - if [ ${configExists} -eq 1 ]; then - publicIPChanged=$(/home/admin/config.scripts/internet.sh update-publicip | grep -c 'ip_changed=1') - fi + publicIPChanged=$(/home/admin/config.scripts/internet.sh update-publicip | grep -c 'ip_changed=1') # check if changed if [ ${publicIPChanged} -gt 0 ]; then @@ -178,18 +142,18 @@ do # and we will get more connections if this matches our real IP address # otherwise the bitcoin-node connections will slowly decline echo "IPv6 only is enabled => restart bitcoind to pickup up new publicIP as local IP" - sudo systemctl stop bitcoind + systemctl stop bitcoind sleep 3 - sudo systemctl start bitcoind + systemctl start bitcoind # if BTCRPCexplorer is currently running # it needs to be restarted to pickup the new IP for its "Node Status Page" # but this is only needed in IPv6 only mode - breIsRunning=$(sudo systemctl status btc-rpc-explorer 2>/dev/null | grep -c 'active (running)') + breIsRunning=$(systemctl status btc-rpc-explorer 2>/dev/null | grep -c 'active (running)') if [ ${breIsRunning} -eq 1 ]; then echo "BTCRPCexplorer is running => restart BTCRPCexplorer to pickup up new publicIP for the bitcoin node" - sudo systemctl stop btc-rpc-explorer - sudo systemctl start btc-rpc-explorer + systemctl stop btc-rpc-explorer + systemctl start btc-rpc-explorer else echo "new publicIP but no BTCRPCexplorer restart because not running" fi @@ -205,8 +169,8 @@ do if [ "${autoUnlock}" = "on" ]; then if [ "${publicIP_Old}" != "::1" ] && [ "${publicIP_New}" != "::1" ]; then echo "restart LND to pickup up new publicIP" - sudo systemctl stop lnd - sudo systemctl start lnd + systemctl stop lnd + systemctl start lnd else echo "publicIP_Old OR publicIP_New is equal ::1 => no need to restart LND" fi @@ -223,18 +187,39 @@ do fi + ############################### + # UPDATE DYNAMIC DOMAIN + # like afraid.org + # ! experimental + ############################### + + # if not activated above, update every 6 hours + if [ ${updateDynDomain} -eq 0 ]; then + # dont +1 so that it gets executed on first loop + updateDynDomain=$(($counter % 21600)) + fi + if [ ${updateDynDomain} -eq 1 ]; then + echo "*** UPDATE DYNAMIC DOMAIN ***" + # check if update URL for dyn Domain is set + if [ ${#dynUpdateUrl} -gt 0 ]; then + /home/admin/config.scripts/internet.dyndomain.sh update + else + echo "'dynUpdateUrl' not set in ${configFile}" + fi + fi + ############################### # Blockchain Sync Monitor ############################### # check every 1min recheckSync=$(($counter % 60)) - if [ ${recheckSync} -eq 1 ]; then - source <(sudo /home/admin/config.scripts/network.monitor.sh peer-status) + if [ ${recheckSync} -eq 1 ] && [ "${chain}" == "main" ]; then + source <(/home/admin/config.scripts/bitcoin.monitor.sh mainnet network) echo "Blockchain Sync Monitoring: peers=${peers}" - if [ "${peers}" == "0" ] && [ "${running}" == "1" ]; then + if [ "${btc_peers}" == "0" ] && [ "${btc_running}" == "1" ]; then echo "Blockchain Sync Monitoring: ZERO PEERS DETECTED .. doing out-of-band kickstart" - sudo /home/admin/config.scripts/network.monitor.sh peer-kickstart + /home/admin/config.scripts/bitcoin.monitor.sh mainnet peer-kickstart fi fi @@ -245,23 +230,20 @@ do # check every 30sec recheckBlitzTUI=$(($counter % 30)) if [ "${touchscreen}" == "1" ] && [ ${recheckBlitzTUI} -eq 1 ]; then + echo "BlitzTUI Monitoring Check" if [ -d "/var/cache/raspiblitz" ]; then - latestHeartBeatLine=$(sudo tail -n 300 /var/cache/raspiblitz/pi/blitz-tui.log | grep beat | tail -n 1) + latestHeartBeatLine=$(tail -n 300 /var/cache/raspiblitz/pi/blitz-tui.log | grep beat | tail -n 1) else - latestHeartBeatLine=$(sudo tail -n 300 /home/pi/blitz-tui.log | grep beat | tail -n 1) + latestHeartBeatLine=$(tail -n 300 /home/pi/blitz-tui.log | grep beat | tail -n 1) fi if [ ${#blitzTUIHeartBeatLine} -gt 0 ]; then #echo "blitzTUIHeartBeatLine(${blitzTUIHeartBeatLine})" #echo "latestHeartBeatLine(${latestHeartBeatLine})" if [ "${blitzTUIHeartBeatLine}" == "${latestHeartBeatLine}" ]; then echo "FAIL - still no new heart beat .. restarting BlitzTUI" - blitzTUIRestarts=$(($blitzTUIRestarts +1)) - if [ $(sudo cat /home/admin/raspiblitz.info | grep -c 'blitzTUIRestarts=') -eq 0 ]; then - echo "blitzTUIRestarts=0" >> /home/admin/raspiblitz.info - fi - sudo sed -i "s/^blitzTUIRestarts=.*/blitzTUIRestarts=${blitzTUIRestarts}/g" /home/admin/raspiblitz.info - sudo init 3 ; sleep 2 ; sudo init 5 + source <(/home/admin/_cache.sh increment system_count_start_tui) + init 3 ; sleep 2 ; init 5 fi else echo "blitzTUIHeartBeatLine is empty - skipping check" @@ -273,15 +255,19 @@ do # SCB Monitoring ############################### - # check every 1min - recheckSCB=$(($counter % 60)) + # check every 1min (only when lnd active) + recheckSCB=0 + if [ "${lightning}" == "lnd" ] || [ "${lnd}" == "on" ]; then + recheckSCB=$(($counter % 60)) + fi if [ ${recheckSCB} -eq 1 ]; then #echo "SCB Monitoring ..." source ${configFile} # check if channel.backup exists scbPath=/mnt/hdd/lnd/data/chain/${network}/${chain}net/channel.backup - scbExists=$(sudo ls $scbPath 2>/dev/null | grep -c 'channel.backup') + scbExists=$(ls $scbPath 2>/dev/null | grep -c 'channel.backup') if [ ${scbExists} -eq 1 ]; then + # timestamp backup filename timestampedFileName=channel-$(date "+%Y%m%d-%H%M%S").backup localBackupDir=/home/admin/backups/scb @@ -289,16 +275,16 @@ do localTimestampedPath=${localBackupDir}/${timestampedFileName} #echo "Found Channel Backup File .. check if changed .." - md5checksumORG=$(sudo md5sum $scbPath 2>/dev/null | head -n1 | cut -d " " -f1) - md5checksumCPY=$(sudo md5sum $localBackupPath 2>/dev/null | head -n1 | cut -d " " -f1) + md5checksumORG=$(md5sum $scbPath 2>/dev/null | head -n1 | cut -d " " -f1) + md5checksumCPY=$(md5sum $localBackupPath 2>/dev/null | head -n1 | cut -d " " -f1) if [ "${md5checksumORG}" != "${md5checksumCPY}" ]; then echo "--> Channel Backup File changed" # make copy to sd card (as local basic backup) - sudo mkdir -p /home/admin/backups/scb/ 2>/dev/null - sudo cp $scbPath $localBackupPath - sudo cp $scbPath $localTimestampedPath - sudo cp $scbPath /boot/channel.backup + mkdir -p /home/admin/backups/scb/ 2>/dev/null + cp $scbPath $localBackupPath + cp $scbPath $localTimestampedPath + cp $scbPath /boot/channel.backup echo "OK channel.backup copied to '${localBackupPath}' and '{$localTimestampedPath}' and '/boot/channel.backup'" # check if a additional local backup target is set @@ -310,8 +296,8 @@ do if [ ${backupDeviceExists} -gt 0 ]; then echo "--> Additional Local Backup Device" - sudo cp ${localBackupPath} /mnt/backup/ - sudo cp ${localTimestampedPath} /mnt/backup/ + cp ${localBackupPath} /mnt/backup/ + cp ${localTimestampedPath} /mnt/backup/ # check results result=$? @@ -337,11 +323,11 @@ do echo "--> Offsite-Backup SCP Server" if [ "${scpBackupOptions}" == "" ]; then scpBackupOptions="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" - fi + fi # its ok to ignore known host, because data is encrypted (worst case of MiM would be: no offsite channel backup) # but its more likely that without ignoring known host, script might not run thru and that way: no offsite channel backup - sudo scp ${scpBackupOptions} ${localBackupPath} ${scpBackupTarget}/ - sudo scp ${scpBackupOptions} ${localTimestampedPath} ${scpBackupTarget}/ + scp ${scpBackupOptions} ${localBackupPath} ${scpBackupTarget}/ + scp ${scpBackupOptions} ${localTimestampedPath} ${scpBackupTarget}/ result=$? if [ ${result} -eq 0 ]; then echo "OK - SCP Backup exited with 0" @@ -350,27 +336,11 @@ do fi fi - # check if a DropBox backup target is set - # parameter in raspiblitz.conf: - # dropboxBackupTarget='[DROPBOX-APP-OAUTH2-TOKEN]' - # see dropbox setup: https://gist.github.com/vindard/e0cd3d41bb403a823f3b5002488e3f90 - if [ ${#dropboxBackupTarget} -gt 0 ]; then - echo "--> Offsite-Backup Dropbox" - source <(sudo /home/admin/config.scripts/dropbox.upload.sh upload ${dropboxBackupTarget} ${localBackupPath}) - source <(sudo /home/admin/config.scripts/dropbox.upload.sh upload ${dropboxBackupTarget} ${localTimestampedPath}) - if [ ${#err} -gt 0 ]; then - echo "FAIL - ${err}" - echo "${errMore}" - else - echo "OK - ${upload}" - fi - fi - # check if Nextcloud backups are enabled if [ $nextcloudBackupServer ] && [ $nextcloudBackupUser ] && [ $nextcloudBackupPassword ]; then echo "--> Offsite-Backup Nextcloud" - source <(sudo /home/admin/config.scripts/nextcloud.upload.sh upload ${localBackupPath}) - source <(sudo /home/admin/config.scripts/nextcloud.upload.sh upload ${localTimestampedPath}) + source <(/home/admin/config.scripts/nextcloud.upload.sh upload ${localBackupPath}) + source <(/home/admin/config.scripts/nextcloud.upload.sh upload ${localTimestampedPath}) if [ ${#err} -gt 0 ]; then echo "FAIL - ${err}" else @@ -406,14 +376,11 @@ do recheckRAID=$((($counter % 3600)+1)) if [ ${recheckRAID} -eq 1 ]; then - # check if raid is active - source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) - if [ ${isRaid} -eq 1 ]; then - - # will run in the background + # check if BTRTFS raid is active & scrub + source <(/home/admin/config.scripts/blitz.datadrive.sh status) + if [ "${isBTRFS}" == "1" ] && [ "${isRaid}" == "1" ]; then echo "STARTING BTRFS RAID DATA CHECK ..." - sudo btrfs scrub start /mnt/hdd/ - + btrfs scrub start /mnt/hdd/ fi fi @@ -422,8 +389,11 @@ do # LND AUTO-UNLOCK ############################### - # check every 10secs - recheckAutoUnlock=$((($counter % 10)+1)) + # check every 10secs (only if LND is active) + recheckAutoUnlock=0 + if [ "${lightning}" == "lnd" ] || [ "${lnd}" == "on" ]; then + recheckAutoUnlock=$((($counter % 10)+1)) + fi if [ ${recheckAutoUnlock} -eq 1 ]; then # check if auto-unlock feature if activated @@ -434,33 +404,12 @@ do if [ "${locked}" != "0" ]; then echo "STARTING AUTO-UNLOCK ..." - sudo /home/admin/config.scripts/lnd.unlock.sh + /home/admin/config.scripts/lnd.unlock.sh fi fi fi - ############################### - # UPDATE DYNAMIC DOMAIN - # like afraid.org - # ! experimental - ############################### - - # if not activated above, update every 6 hours - if [ ${updateDynDomain} -eq 0 ]; then - # dont +1 so that it gets executed on first loop - updateDynDomain=$(($counter % 21600)) - fi - if [ ${updateDynDomain} -eq 1 ]; then - echo "*** UPDATE DYNAMIC DOMAIN ***" - # check if update URL for dyn Domain is set - if [ ${#dynUpdateUrl} -gt 0 ]; then - /home/admin/config.scripts/internet.dyndomain.sh update - else - echo "'dynUpdateUrl' not set in ${configFile}" - fi - fi - #################################################### # CHECK FOR END OF IBD (self validation) #################################################### @@ -478,18 +427,22 @@ do echo "CHECK FOR END OF IBD --> reduce RAM for next reboot" # remove flag - sudo rm /mnt/hdd/${network}/blocks/selfsync.flag + rm /mnt/hdd/${network}/blocks/selfsync.flag # set dbcache back to normal (to give room for other apps after reboot in the future) - kbSizeRAM=$(sudo cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g') + kbSizeRAM=$(cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g') + if [ ${kbSizeRAM} -gt 1500000 ]; then echo "Detected RAM >1GB --> optimizing ${network}.conf" - sudo sed -i "s/^dbcache=.*/dbcache=512/g" /mnt/hdd/${network}/${network}.conf + sed -i "s/^dbcache=.*/dbcache=512/g" /mnt/hdd/${network}/${network}.conf else echo "Detected RAM 1GB --> optimizing ${network}.conf" - sudo sed -i "s/^dbcache=.*/dbcache=128/g" /mnt/hdd/${network}/${network}.conf + sed -i "s/^dbcache=.*/dbcache=128/g" /mnt/hdd/${network}/${network}.conf fi + # relax sanning on sync progress (after 30 more secs) + /home/admin/_cache.sh focus btc_default_sync_progress 10 30 + fi fi fi @@ -501,5 +454,4 @@ do # sleep 1 sec sleep 1 -done - +done \ No newline at end of file diff --git a/home.admin/_bootstrap.sh b/home.admin/_bootstrap.sh index d4653798..083b51e5 100755 --- a/home.admin/_bootstrap.sh +++ b/home.admin/_bootstrap.sh @@ -35,73 +35,78 @@ echo "Running RaspiBlitz Bootstrap ${codeVersion}" >> $logFile date >> $logFile echo "***********************************************" >> $logFile -# set default values for raspiblitz.info -network="" -chain="" -setupStep=0 -setupPhase='boot' -fsexpanded=0 -# see https://github.com/rootzoll/raspiblitz/issues/1265#issuecomment-813369284 -displayClass="lcd" -displayType="" -fundRecovery=0 +# make sure SSH server is configured & running +sudo /home/admin/config.scripts/blitz.ssh.sh checkrepair >> ${logFile} ################################ # INIT raspiblitz.info ################################ +# raspiblitz.info contains the persisted system state +# that either given by build or has to survive a reboot +echo "## INIT raspiblitz.info" >> $logFile -# try to load old values if available (overwrites defaults) +# set default values for raspiblitz.info (that are not set by build_sdcard.sh) +setupPhase='boot' +setupStep=0 +fsexpanded=0 +fundRecovery=0 + +# load already persisted valued (overwriting defaults if exist) source ${infoFile} 2>/dev/null +# write fresh raspiblitz.info file +echo "baseimage=${baseimage}" > $infoFile +echo "cpu=${cpu}" >> $infoFile +echo "displayClass=${displayClass}" >> $infoFile +echo "displayType=${displayType}" >> $infoFile +echo "setupPhase=${setupPhase}" >> $infoFile +echo "setupStep=${setupStep}" >> $infoFile +echo "fundRecovery=${fundRecovery}" >> $infoFile +echo "fsexpanded=${fsexpanded}" >> $infoFile +echo "state=starting" >> $infoFile +sudo chmod 664 ${infoFile} + +# write content of raspiblitz.info to logs +cat $infoFile >> $logFile + +######################### +# INIT RaspiBlitz Cache +######################### + +echo "## INIT RaspiBlitz Cache ... wait background.scan.service to finsih first scan loop" >> $logFile +systemscan_runtime="" +while [ "${systemscan_runtime}" == "" ] +do + sleep 1 + source <(/home/admin/_cache.sh get systemscan_runtime) + echo "- waiting for background.scan.service --> systemscan_runtime(${systemscan_runtime})" >> $logFile +done + +# make sure latest info file is imported +/home/admin/_cache.sh import $infoFile + +# setting basic status info +/home/admin/_cache.sh set state "starting" +/home/admin/_cache.sh set message "bootstrap" + # try to load config values if available (config overwrites info) source ${configFile} 2>/dev/null -# get first basic network info -source <(/home/admin/config.scripts/internet.sh status) - -# get basic hardware info -source <(/home/admin/config.scripts/blitz.hardware.sh status) - -# get basic dns info -source <(sudo /home/admin/config.scripts/internet.dns.sh test nodialog) - -# resetting info file -echo "Resetting the InfoFile: ${infoFile}" -echo "state=starting" > $infoFile -echo "message=" >> $infoFile -echo "baseimage=${baseimage}" >> $infoFile -echo "cpu=${cpu}" >> $infoFile -echo "board=${board}" >> $infoFile -echo "ramMB=${ramMB}" >> $infoFile -echo "ramGB=${ramGB}" >> $infoFile -echo "network=${network}" >> $infoFile -echo "chain=${chain}" >> $infoFile -echo "localip='${localip}'" >> $infoFile -echo "online='${online}'" >> $infoFile -echo "dnsworking=${dnsworking}" >> $infoFile -echo "fsexpanded=${fsexpanded}" >> $infoFile -echo "displayClass=${displayClass}" >> $infoFile -echo "displayType=${displayType}" >> $infoFile -echo "setupStep=${setupStep}" >> $infoFile -echo "setupPhase=${setupPhase}" >> $infoFile -echo "fundRecovery=${fundRecovery}" >> $infoFile -if [ "${setupStep}" != "100" ]; then - echo "hostname=${hostname}" >> $infoFile -fi -sudo chmod 664 ${infoFile} +# monitor LAN connection fast to display local IP changes +/home/admin/_cache.sh focus internet_localip 0 ###################################### -# CHECK SD CARD INCONSISTENT STATE - -# make sure SSH server is configured & running -sudo /home/admin/config.scripts/blitz.ssh.sh checkrepair >> ${logFile} +# CHECK SD CARD STATE # when a file 'stop' is on the sd card boot partition - stop for manual provision flagExists=$(sudo ls /boot/stop | grep -c 'stop') if [ "${flagExists}" == "1" ]; then + # remove flag sudo rm /boot/stop - sed -i "s/^state=.*/state=stop/g" ${infoFile} - sed -i "s/^message=.*/message='stopped for manual provision'/g" ${infoFile} + # set state info + /home/admin/_cache.sh set state "stop" + /home/admin/_cache.sh set message "stopped for manual provision" + # log info echo "INFO: 'bootstrap stopped - run release after manual provison'" >> ${logFile} exit 0 fi @@ -110,13 +115,84 @@ fi provisionFlagExists=$(sudo ls /home/admin/provision.flag | grep -c 'provision.flag') if [ "${provisionFlagExists}" == "1" ]; then sudo systemctl stop ${network}d 2>/dev/null - sudo systemctl stop lnd 2>/dev/null - sed -i "s/^state=.*/state=inconsistentsystem/g" ${infoFile} - sed -i "s/^message=.*/message='provision did not ran thru'/g" ${infoFile} + /home/admin/_cache.sh set state "inconsistentsystem" + /home/admin/_cache.sh set message "provision did not ran thru" echo "FAIL: 'provision did not ran thru' - need fresh sd card!" >> ${logFile} exit 1 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) +/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 + +################################ +# CLEANING BOOT SYSTEM +################################ + +# 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" >> $logFile + # dont delete directories - can make services crash + sudo rm /var/log/* + sudo service rsyslog restart + /home/admin/_cache.sh set message "WARNING: /var/log/ >1GB" + echo "WARN !! Logs in /var/log in were bigger then 1GB and got emergency delete to prevent fillup." >> $logFile + echo "If you see this in the logs please report to the GitHub issues, so LOG config needs to be optimized." >> $logFile + sleep 10 +else + echo "OK - logs are at ${logsMegaByte} MB - within safety limit" >> $logFile +fi +echo "" + +# get the state of data drive +source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) + +################################ +# WAIT LOOP: HDD CONNECTED +################################ + +echo "Waiting for HDD/SSD ..." >> $logFile +sudo ls -la /etc/ssh >> $logFile +until [ ${isMounted} -eq 1 ] || [ ${#hddCandidate} -gt 0 ] +do + + # recheck HDD/SSD + source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) + echo "isMounted: $isMounted" >> $logFile + echo "hddCandidate: $hddCandidate" >> $logFile + + # in case of HDD analyse ERROR + if [ "${hddError}" != "" ]; then + echo "FAIL - error on HDD analysis: ${hddError}" >> $logFile + /home/admin/_cache.sh set state "errorHDD" + /home/admin/_cache.sh set message "${hddError}" + elif [ "${isMounted}" == "0" ] && [ "${hddCandidate}" == "" ]; then + /home/admin/_cache.sh set state "noHDD" + /home/admin/_cache.sh set message ">=1TB" + fi + + # wait for next check + sleep 2 + +done +echo "HDD/SSD connected: ${$hddCandidate}" >> $logFile + +# write info for LCD +/home/admin/_cache.sh set state "system-init" +/home/admin/_cache.sh set message "please wait" + ###################################### # SECTION FOR POSSIBLE REBOOT ACTIONS systemInitReboot=0 @@ -136,7 +212,7 @@ if [ ${forceHDMIoutput} -eq 1 ]; then echo "HDMI switch found ... activating HDMI display output & reboot" >> $logFile sudo /home/admin/config.scripts/blitz.display.sh set-display hdmi >> $logFile systemInitReboot=1 - sed -i "s/^message=.*/message='HDMI'/g" ${infoFile} + /home/admin/_cache.sh set message "HDMI" else echo "No HDMI switch found. " >> $logFile fi @@ -152,12 +228,12 @@ if [ "${needsExpansion}" == "1" ] && [ "${fsexpanded}" == "0" ]; then sudo /home/admin/config.scripts/blitz.bootdrive.sh status >> $logFile sudo /home/admin/config.scripts/blitz.bootdrive.sh fsexpand >> $logFile systemInitReboot=1 - sed -i "s/^message=.*/message='FSEXPAND'/g" ${infoFile} + /home/admin/_cache.sh set message "FSEXPAND" elif [ "${tooSmall}" == "1" ]; then echo "!!! FAIL !!!!!!!!!!!!!!!!!!!!" >> $logFile echo "SDCARD TOO SMALL 16G minimum" >> $logFile echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >> $logFile - sed -i "s/^state=.*/state=sdtoosmall/g" ${infoFile} + /home/admin/_cache.sh set state "sdtoosmall" echo "System stopped. Please cut power." >> $logFile sleep 6000 sudo shutdown -r now @@ -167,6 +243,36 @@ else echo "No FS EXPAND needed. needsExpansion(${needsExpansion}) fsexpanded(${fsexpanded})" >> $logFile fi +# now that HDD/SSD is connected ... if relevant data from a previous RaspiBlitz was available +# /var/cache/raspiblitz/hdd-inspect exists with copy of config data to init system with +# NOTE: /var/cache/raspiblitz/hdd-inspect will not exist when HDD/SSD is already regulary mounted + +#################################### +# WIFI RESTORE from HDD works with +# mem copy from datadrive inspection +#################################### + +# check if there is a WIFI configuration to backup or restore +if [ -f "/var/cache/raspiblitz/hdd-inspect/wpa_supplicant.conf" ]; then + echo "WIFI RESTORE from /var/cache/raspiblitz/hdd-inspect/wpa_supplicant.conf" >> $logFile + /home/admin/config.scripts/internet.wifi.sh backup-restore >> $logFile +else + echo "No WIFI RESTORE because no /var/cache/raspiblitz/hdd-inspect/wpa_supplicant.conf" >> $logFile +fi + +################################ +# SSH SERVER CERTS RESTORE +# if backup is available on HDD/SSD +################################ + +if [ -d "/var/cache/raspiblitz/hdd-inspect/ssh" ]; then + # INIT OLD SSH HOST KEYS on Update/Recovery to prevent "Unknown Host" on ssh client + echo "SSH SERVER CERTS RESTORE activating old SSH host keys" >> $logFile + /home/admin/config.scripts/blitz.ssh.sh restore /var/cache/raspiblitz/hdd-inspect >> $logFile +else + echo "No SSH SERVER CERTS RESTORE because no /var/cache/raspiblitz/hdd-inspect/ssh" >> $logFile +fi + ################################ # SSH SERVER CERTS RESET # if a file called 'ssh.reset' gets @@ -177,29 +283,57 @@ fi 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 + rm /boot/ssh.reset* >> $logFile # delete ssh certs echo "SSHRESET switch found ... stopping SSH and deleting old certs" >> $logFile - sudo /home/admin/config.scripts/blitz.ssh.sh renew >> $logFile - sudo /home/admin/config.scripts/blitz.ssh.sh backup >> $logFile - sudo ufw allow ssh + /home/admin/config.scripts/blitz.ssh.sh renew >> $logFile + /home/admin/config.scripts/blitz.ssh.sh backup >> $logFile systemInitReboot=1 - sed -i "s/^message=.*/message='SSHRESET'/g" ${infoFile} + /home/admin/_cache.sh set message "SSHRESET" else echo "No SSHRESET switch found. " >> $logFile fi +################################## +# DISPLAY RESTORE (if needed) +################################## +if [ -f "/var/cache/raspiblitz/hdd-inspect/raspiblitz.conf" ]; then + + echo "check that display class in raspiblitz.conf from HDD is different from as it is ow in raspiblitz.info ..." >> $logFile + + # get display class value from raspiblitz.info + source <(cat ${infoFile} | grep "^displayClass=") + infoFileDisplayClass="${displayClass}" + echo "infoFileDisplayClass(${infoFileDisplayClass})" >> $logFile + + # get display class value from raspiblitz.conf + source <(cat /var/cache/raspiblitz/hdd-inspect/raspiblitz.conf | grep "^displayClass=") + confFileDisplayClass="${displayClass}" + echo "confFileDisplayClass(${confFileDisplayClass})" >> $logFile + + # check if values are different and need to change + if [ "${confFileDisplayClass}" != "" ] && [ "${infoFileDisplayClass}" != "${displayClass}" ]; then + echo "DISPLAY RESTORE - need to update displayClass from (${infoFileDisplayClass}) to (${confFileDisplayClass})'" >> ${logFile} + /home/admin/config.scripts/blitz.display.sh set-display ${confFileDisplayClass} >> ${logFile} + systemInitReboot=1 + else + echo "No DISPLAY RESTORE because no need to change" >> $logFile + fi + +else + echo "No DISPLAY RESTORE because no /var/cache/raspiblitz/hdd-inspect/raspiblitz.conf" >> $logFile +fi + ################################ -# UASP FIX - first try -# if HDD is connected on start +# UASP FIX ################################ +/home/admin/_cache.sh set message "checking HDD" source <(sudo /home/admin/config.scripts/blitz.datadrive.sh uasp-fix) if [ "${neededReboot}" == "1" ]; then - echo "UASP FIX applied (1st-try) ... reboot needed." >> $logFile - sed -i "s/^message=.*/message='UASP'/g" ${infoFile} + echo "UASP FIX applied ... reboot needed." >> $logFile systemInitReboot=1 else - echo "No UASP FIX needed (1st-try)." >> $logFile + echo "No UASP FIX needed" >> $logFile fi ###################################### @@ -208,127 +342,13 @@ fi if [ "${systemInitReboot}" == "1" ]; then sudo cp ${logFile} /home/admin/raspiblitz.systeminit.log - sudo sed -i "s/^state=.*/state=reboot/g" ${infoFile} + /home/admin/_cache.sh set state "reboot" sleep 8 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) -/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 - -################################ -# CLEANING BOOT SYSTEM -################################ - -# resetting start count files -echo "SYSTEMD RESTART LOG: blockchain (bitcoind)" > /home/admin/systemd.blockchain.log -echo "SYSTEMD RESTART LOG: lightning (LND)" > /home/admin/systemd.lightning.log -sudo chmod 666 /home/admin/systemd.blockchain.log -sudo chmod 666 /home/admin/systemd.lightning.log - -# 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/* - sudo service rsyslog restart - 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 be optimized." -else - echo "OK - logs are at ${logsMegaByte} MB - within safety limit" -fi -echo "" - -############################### -# WAIT FOR ALL SERVICES - -# get the state of data drive -source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) - -################################ -# WAIT LOOP: HDD CONNECTED -################################ - -echo "Waiting for HDD/SSD ..." >> $logFile -sudo ls -la /etc/ssh >> $logFile -until [ ${isMounted} -eq 1 ] || [ ${#hddCandidate} -gt 0 ] -do - - # recheck HDD/SSD - source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) - echo "isMounted: $isMounted" - echo "hddCandidate: $hddCandidate" - - # in case of HDD analyse ERROR - if [ "${hddError}" != "" ]; then - echo "FAIL - error on HDD analysis: ${hddError}" >> $logFile - sed -i "s/^state=.*/state=errorHDD/g" ${infoFile} - sed -i "s/^message=.*/message='${hddError}'/g" ${infoFile} - elif [ "${isMounted}" == "0" ] && [ "${hddCandidate}" == "" ]; then - sed -i "s/^state=.*/state=noHDD/g" ${infoFile} - sed -i "s/^message=.*/message='>=1TB'/g" ${infoFile} - fi - - # wait for next check - sleep 2 - -done -echo "HDD/SSD connected: ${hddCandidate}" >> $logFile - -# write info for LCD -sed -i "s/^state=.*/state=system-init/g" ${infoFile} -sed -i "s/^message=.*/message='please wait'/g" ${infoFile} - -#################################### -# 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 -################################ -sed -i "s/^message=.*/message='checking HDD'/g" ${infoFile} -source <(sudo /home/admin/config.scripts/blitz.datadrive.sh uasp-fix) -if [ "${neededReboot}" == "1" ]; then - echo "UASP FIX applied (2nd-try) ... reboot needed." >> $logFile - sudo cp ${logFile} ${logFile}.uasp - sudo sed -i "s/^state=.*/state=reboot/g" ${infoFile} - sleep 8 - sudo shutdown -r now - sleep 100 - exit 0 -else - echo "No UASP FIX needed (2nd-try)." >> $logFile -fi - ################################### # WAIT LOOP: LOCALNET / INTERNET # after HDD > can contain WIFI conf @@ -337,30 +357,28 @@ gotLocalIP=0 until [ ${gotLocalIP} -eq 1 ] do - # get latest network info & update raspiblitz.info - source <(/home/admin/config.scripts/internet.sh status) - sed -i "s/^localip=.*/localip='${localip}'/g" ${infoFile} + # get latest network info directly + source <(/home/admin/config.scripts/internet.sh status online) # check state of network if [ ${dhcp} -eq 0 ]; then # display user waiting for DHCP - sed -i "s/^state=.*/state=noDHCP/g" ${infoFile} - sed -i "s/^message=.*/message='Waiting for DHCP'/g" ${infoFile} + /home/admin/_cache.sh set state "noDHCP" + /home/admin/_cache.sh set message "Waiting for DHCP" elif [ ${#localip} -eq 0 ]; then - configWifiExists=$(sudo cat /etc/wpa_supplicant/wpa_supplicant.conf 2>/dev/null| grep -c "network=") if [ ${configWifiExists} -eq 0 ]; then # display user to connect LAN - sed -i "s/^state=.*/state=noIP-LAN/g" ${infoFile} - sed -i "s/^message=.*/message='Connect the LAN/WAN'/g" ${infoFile} + /home/admin/_cache.sh set state "noIP-LAN" + /home/admin/_cache.sh set message "Connect the LAN/WAN" else # display user that wifi settings are not working - sed -i "s/^state=.*/state=noIP-WIFI/g" ${infoFile} - sed -i "s/^message=.*/message='WIFI Settings not working'/g" ${infoFile} + /home/admin/_cache.sh set state "noIP-WIFI" + /home/admin/_cache.sh set message "WIFI Settings not working" 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} + /home/admin/_cache.sh set state "noInternet" + /home/admin/_cache.sh set message "No connection to Internet" else gotLocalIP=1 fi @@ -368,40 +386,14 @@ do done # write info for LCD -sed -i "s/^state=.*/state=inspect-hdd/g" ${infoFile} -sed -i "s/^message=.*/message='please wait'/g" ${infoFile} +/home/admin/_cache.sh set state "inspect-hdd" +/home/admin/_cache.sh set message "please wait" # get fresh info about data drive to continue source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) echo "isMounted: $isMounted" >> $logFile -# check if UASP is already deactivated (on RaspiOS) -# https://www.pragmaticlinux.com/2021/03/fix-for-getting-your-ssd-working-via-usb-3-on-your-raspberry-pi/ -cmdlineExists=$(sudo ls /boot/cmdline.txt 2>/dev/null | grep -c "cmdline.txt") -if [ ${cmdlineExists} -eq 1 ] && [ ${#hddAdapterUSB} -gt 0 ] && [ ${hddAdapterUSAP} -eq 0 ]; then - echo "Checking for UASP deactivation ..." >> $logFile - usbQuirkActive=$(sudo cat /boot/cmdline.txt | grep -c "usb-storage.quirks=") - # check if its maybe other device - usbQuirkDone=$(sudo cat /boot/cmdline.txt | grep -c "usb-storage.quirks=${hddAdapterUSB}:u") - if [ ${usbQuirkActive} -gt 0 ] && [ ${usbQuirkDone} -eq 0 ]; then - # remove old usb-storage.quirks - sudo sed -i "s/usb-storage.quirks=[^ ]* //g" /boot/cmdline.txt - fi - if [ ${usbQuirkDone} -eq 0 ]; then - # add new usb-storage.quirks - sudo sed -i "1s/^/usb-storage.quirks=${hddAdapterUSB}:u /" /boot/cmdline.txt - sudo cat /boot/cmdline.txt >> $logFile - # go into reboot to activate new setting - echo "DONE deactivating UASP for ${hddAdapterUSB} ... one more reboot needed ... " >> $logFile - sudo cp ${logFile} ${logFile}.uasp - sudo shutdown -r now - sleep 100 - fi -else - echo "Skipping UASP deactivation ... cmdlineExists(${cmdlineExists}) hddAdapterUSB(${hddAdapterUSB}) hddAdapterUSAP(${hddAdapterUSAP})" >> $logFile -fi - # check if the HDD is auto-mounted ( auto-mounted = setup-done) echo "HDD already part of system: $isMounted" >> $logFile @@ -422,10 +414,11 @@ if [ ${isMounted} -eq 0 ]; then echo "Temp mounting (1) result: ${isMounted}" >> $logFile # write data needed for setup process into raspiblitz.info - echo "hddCandidate='${hddCandidate}'" >> ${infoFile} - echo "hddGigaBytes=${hddGigaBytes}" >> ${infoFile} - echo "hddBlocksBitcoin=${hddBlocksBitcoin}" >> ${infoFile} - echo "hddGotMigrationData=${hddGotMigrationData}" >> ${infoFile} + /home/admin/_cache.sh set hddCandidate "${hddCandidate}" + /home/admin/_cache.sh set hddGigaBytes "${hddGigaBytes}" + /home/admin/_cache.sh set hddBlocksBitcoin "${hddBlocksBitcoin}" + /home/admin/_cache.sh set hddBlocksLitecoin "${hddBlocksLitecoin}" + /home/admin/_cache.sh set hddGotMigrationData "${hddGotMigrationData}" echo "" echo "HDD is there but not AutoMounted yet - Waiting for user Setup/Update" >> $logFile @@ -445,10 +438,6 @@ if [ ${isMounted} -eq 0 ]; then setupPhase="migration" elif [ "${hddRaspiData}" == "1" ]; then - # INIT OLD SSH HOST KEYS on Update/Recovery to prevent "Unknown Host" on ssh client - echo "COPY und Activating old SSH host keys" >> $logFile - /home/admin/config.scripts/blitz.ssh.sh restore >> $logFile - # determine if this is a recovery or an update # TODO: improve version/update detection later isRecovery=$(echo "${hddRaspiVersion}" | grep -c "${codeVersion}") @@ -464,9 +453,9 @@ if [ ${isMounted} -eq 0 ]; then # signal "WAIT LOOP: SETUP" to LCD, SSH & WEBAPI echo "Displaying Info Message: ${infoMessage}" >> $logFile - sed -i "s/^state=.*/state=waitsetup/g" ${infoFile} - sed -i "s/^message=.*/message='${infoMessage}'/g" ${infoFile} - sed -i "s/^setupPhase=.*/setupPhase='${setupPhase}'/g" ${infoFile} + /home/admin/_cache.sh set state "waitsetup" + /home/admin/_cache.sh set message "${infoMessage}" + /home/admin/_cache.sh set setupPhase "${setupPhase}" ############################################# # WAIT LOOP: USER SETUP/UPDATE/MIGRATION @@ -480,19 +469,16 @@ if [ ${isMounted} -eq 0 ]; then # get fresh info about data drive (in case the hdd gets disconnected) source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) if [ "${hddCandidate}" == "" ]; then - echo "!!! WARNING !!! Lost HDD connection .. triggering reboot, to restart system-init." >> ${logFile} - sed -i "s/^state=.*/state=errorHDD/g" ${infoFile} - sed -i "s/^message=.*/message='lost HDD - rebooting'/g" ${infoFile} - sudo cp ${logFile} ${logFile}.error + /home/admin/config.scripts/blitz.error.sh _bootstrap.sh "lost-hdd" "Lost HDD connection .. triggering reboot." "happened during WAIT LOOP: USER SETUP/UPDATE/MIGRATION" ${logFile} sleep 8 sudo shutdown -r now sleep 100 exit 0 fi - # detect if network get deconnected again + # detect if network get deconnected again (call directly instead of cache) # --> "removing network cable" can be used as signal to shutdown clean on test startup - source <(/home/admin/config.scripts/internet.sh status) + source <(/home/admin/config.scripts/internet.sh status local) if [ "${localip}" == "" ]; then sed -i "s/^state=.*/state=errorNetwork/g" ${infoFile} sleep 8 @@ -504,9 +490,8 @@ if [ ${isMounted} -eq 0 ]; then # give the loop a little bed time sleep 4 - # check info file for updated values - # especially the state for checking loop - source ${infoFile} + # check for updated state value from SSH-UI or WEB-UI for loop + source <(/home/admin/_cache.sh get state) done @@ -515,7 +500,7 @@ if [ ${isMounted} -eq 0 ]; then ############################################# # refresh data from info file - source ${infoFile} + source <(/home/admin/_cache.sh get state setupPhase) echo "# PROVISION PROCESS with setupPhase(${setupPhase})" >> ${logFile} # mark system on sd card as in setup process @@ -548,17 +533,12 @@ if [ ${isMounted} -eq 0 ]; then sudo cp /var/cache/raspiblitz/temp/raspiblitz.conf ${configFile} fi - # kick-off provision process - sed -i "s/^state=.*/state=provision/g" ${infoFile} - sed -i "s/^message=.*/message='Starting Provision'/g" ${infoFile} + # enable tor service + sudo /home/admin/config.scripts/tor.install.sh enable >> ${logFile} - # load setup data - echo "# Sourcing ${configFile} " >> ${logFile} - source ${configFile} - cat ${configFile} >> ${logFile} - echo "# Sourcing ${setupFile} " >> ${logFile} - source ${setupFile} - sed -e '/^password/d' ${setupFile} >> ${logFile} + # kick-off provision process + /home/admin/_cache.sh set state "provision" + /home/admin/_cache.sh set message "Starting Provision" # add some debug info to logfile echo "# df " >> ${logFile} @@ -566,30 +546,45 @@ if [ ${isMounted} -eq 0 ]; then echo "# lsblk -o NAME,FSTYPE,LABEL " >> ${logFile} lsblk -o NAME,FSTYPE,LABEL >> ${logFile} - # make sure basic info is in raspiblitz.info - echo "# Update ${infoFile} " >> ${logFile} - sudo sed -i "s/^network=.*/network=${network}/g" ${infoFile} - sudo sed -i "s/^chain=.*/chain=${chain}/g" ${infoFile} - sudo sed -i "s/^lightning=.*/lightning=${lightning}/g" ${infoFile} - cat ${infoFile} >> ${logFile} - # if migrationFile was uploaded - now import it echo "# migrationFile(${migrationFile})" >> ${logFile} if [ "${migrationFile}" != "" ]; then + + # unpack sed -i "s/^message=.*/message='Unpacking Migration Data'/g" ${infoFile} - /home/admin/config.scripts/blitz.migration.sh import "${migrationFile}" >> ${logFile} - sed -i "s/^setupPhase=.*/setupPhase='recovery'/g" ${infoFile} + source <(/home/admin/config.scripts/blitz.migration.sh import "${migrationFile}") + + # check for errors + if [ "${error}" != "" ]; then + /home/admin/config.scripts/blitz.error.sh _bootstrap.sh "migration-import-error" "blitz.migration.sh import exited with error" "/home/admin/config.scripts/blitz.migration.sh import ${migrationFile} --> ${error}" ${logFile} + exit 1 + fi + + # signal recovery provision phase setupPhase="recovery" + /home/admin/_cache.sh set setupPhase "${setupPhase}" fi + # load fresh config data + echo "# Sourcing ${configFile} " >> ${logFile} + cat ${configFile} >> ${logFile} + source ${configFile} + + # load fresh setup data + echo "# Sourcing ${setupFile} " >> ${logFile} + cat ${setupFile} >> ${logFile} + source ${setupFile} + + # make sure basic info is in raspiblitz.info + /home/admin/_cache.sh set network "${network}" + /home/admin/_cache.sh set chain "${chain}" + /home/admin/_cache.sh set lightning "${lightning}" + ################################### # Set Password A (in all cases) if [ "${passwordA}" == "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='config: missing passwordA'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: missing passwordA in (${setupFile})!" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _bootstrap.sh "missing-passworda" "missing passwordA in (${setupFile})" "" ${logFile} exit 1 fi @@ -605,10 +600,11 @@ if [ ${isMounted} -eq 0 ]; then errorState=$? sudo cat /home/admin/raspiblitz.provision-setup.log if [ "$errorState" != "0" ]; then - echo "EXIT _provision.setup.sh BECAUSE OF ERROR STATE ($errorState)" >> $logFile - echo "This can also happen if _provision.setup.sh has syntax errors" >> $logFile - sed -i "s/^state=.*/state='error'/g" ${infoFile} - sed -i "s/^message=.*/message='_provision.setup.sh fail'/g" ${infoFile} + # only trigger an error message if the script hasnt itself triggered an error message already + source <(/home/admin/_cache.sh get state) + if [ "${state}" != "error" ]; then + /home/admin/config.scripts/blitz.error.sh _bootstrap.sh "provision-setup-exit" "unknown or syntax error on (${errorState}) _provision.setup.sh" "" ${logFile} + fi exit 1 fi fi @@ -621,10 +617,11 @@ if [ ${isMounted} -eq 0 ]; then errorState=$? cat /home/admin/raspiblitz.provision-migration.log if [ "$errorState" != "0" ]; then - echo "EXIT _provision.migration.sh BECAUSE OF ERROR STATE ($errorState)" >> $logFile - echo "This can also happen if _provision.migration.sh has syntax errros" >> $logFile - sed -i "s/^state=.*/state='error'/g" ${infoFile} - sed -i "s/^message=.*/message='_provision.migration.sh fail'/g" ${infoFile} + # only trigger an error message if the script hasnt itself triggered an error message already + source <(/home/admin/_cache.sh get state) + if [ "${state}" != "error" ]; then + /home/admin/config.scripts/blitz.error.sh _bootstrap.sh "provision-migration-exit" "unknown or syntax error on (${errorState}) _provision.migration.sh" "" ${logFile} + fi exit 1 fi fi @@ -637,10 +634,11 @@ if [ ${isMounted} -eq 0 ]; then errorState=$? cat /home/admin/raspiblitz.provision-update.log if [ "$errorState" != "0" ]; then - echo "EXIT _provision.update.sh BECAUSE OF ERROR STATE ($errorState)" >> $logFile - echo "This can also happen if _provision.update.sh has syntax errors" >> $logFile - sed -i "s/^state=.*/state='error'/g" ${infoFile} - sed -i "s/^message=.*/message='_provision.update.sh fail'/g" ${infoFile} + # only trigger an error message if the script hasnt itself triggered an error message already + source <(/home/admin/_cache.sh get state) + if [ "${state}" != "error" ]; then + /home/admin/config.scripts/blitz.error.sh _bootstrap.sh "provision-update-exit" "unknown or syntax error on (${errorState}) _provision.update.sh" "" ${logFile} + fi exit 1 fi fi @@ -651,30 +649,32 @@ if [ ${isMounted} -eq 0 ]; then /home/admin/_provision_.sh errorState=$? if [ "$errorState" != "0" ]; then - echo "EXIT _provision_.sh BECAUSE OF ERROR STATE ($errorState)" >> $logFile - echo "This can also happen if _provision_.sh has syntax errors" >> $logFile - sed -i "s/^state=.*/state='error'/g" ${infoFile} - sed -i "s/^message=.*/message='_provision_.sh fail'/g" ${infoFile} + # only trigger an error message if the script hasnt itself triggered an error message already + source <(/home/admin/_cache.sh get state) + if [ "${state}" != "error" ]; then + /home/admin/config.scripts/blitz.error.sh _bootstrap.sh "provision-exit" "unknown or syntax error on (${errorState}) _provision_.sh" "" ${logFile} + fi exit 1 fi # everyone can read the config but it can only be # edited/written by root ot admin user (part of group sudo) - sudo chown root:sudo ${configFile} - sudo chmod 664 ${configFile} + chown root:sudo ${configFile} + chmod 664 ${configFile} # delete provision in progress flag - sudo rm /home/admin/provision.flag + rm /home/admin/provision.flag # mark provision process done - sed -i "s/^message=.*/message='Provision Done'/g" ${infoFile} + /home/admin/_cache.sh set message "Provision Done" # wait until syncProgress is available (neeed for final dialogs) - while [ "${syncProgress}" == "" ] + /home/admin/_cache.sh set state "waitsync" + btc_default_ready="0" + while [ "${btc_default_ready}" != "1" ] do - echo "# Waiting for blockchain sync progress info ..." >> $logFile - source <(sudo /home/admin/config.scripts/blitz.statusscan.sh) - sed -i "s/^state=.*/state=waitsync/g" ${infoFile} + source <(/home/admin/_cache.sh get btc_default_ready) + echo "# waitsync loop ... btc_default_ready(${btc_default_ready})" >> $logFile sleep 2 done @@ -683,8 +683,8 @@ if [ ${isMounted} -eq 0 ]; then ################################################### echo "# HANDOVER TO FINAL SETUP CONTROLLER ..." >> $logFile - sed -i "s/^state=.*/state=waitfinal/g" ${infoFile} - sed -i "s/^message=.*/message='Setup Done'/g" ${infoFile} + /home/admin/_cache.sh set state "waitfinal" + /home/admin/_cache.sh set message "Setup Done" # system has to wait before reboot to present like seed words and other info/options to user echo "BOOTSTRAP EXIT ... waiting for final setup controller to initiate final reboot." >> $logFile @@ -702,14 +702,14 @@ else # 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 + 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 - sudo rm -f /mnt/hdd/bitcoin/bitcoind.pid 2>/dev/null - sudo rm -f /mnt/hdd/bitcoin/.lock 2>/dev/null + rm -f /mnt/hdd/bitcoin/bitcoind.pid 2>/dev/null + rm -f /mnt/hdd/bitcoin/.lock 2>/dev/null ################################ # DELETE LOG & LOCK FILES @@ -717,11 +717,11 @@ else # 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 + 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 + 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 + rm /mnt/storage/app-storage/electrs/db/mainnet/LOCK 2>/dev/null fi @@ -729,57 +729,23 @@ fi ############################## # BOOSTRAP IN EVERY SITUATION ############################## - -sed -i "s/^setupPhase=.*/setupPhase='starting'/g" ${infoFile} - -# 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 - 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 -fi - -# make sure lndAddress & lndPort exist in configfile -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 +/home/admin/_cache.sh set setupPhase "starting" # load data from config file fresh echo "load configfile data" >> $logFile source ${configFile} -# update public IP on boot - set to domain if available -/home/admin/config.scripts/internet.sh update-publicip ${lndAddress} - -# make constant UASP entry in raspiblitz.conf if still done by flag file -# uaspForced comes from blitz.datadrive.sh status -if [ ${uaspForced} -eq 1 ]; then - entryExists=$(cat /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c 'forceUasp=on') - if [ ${entryExists} -eq 0 ]; then - sudo sed -i '/forceUasp=.*/d' /mnt/hdd/raspiblitz.conf - echo "forceUasp=on" >> /mnt/hdd/raspiblitz.conf - echo "DONE forceUasp=on recorded in raspiblitz.conf" >> $logFile - fi +# if a WIFI config exists backup to HDD +source <(/home/admin/config.scripts/internet.sh status) +if [ ${configWifiExists} -eq 1 ]; then + echo "Making Backup Copy of WIFI config to HDD" >> $logFile + cp /etc/wpa_supplicant/wpa_supplicant.conf /mnt/hdd/app-data/wpa_supplicant.conf fi -################################# -# MAKE SURE USERS HAVE LATEST LND CREDENTIALS -################################# -source ${configFile} -if [ ${#network} -gt 0 ] && [ ${#chain} -gt 0 ]; then - +# make sure users have latest credentials (if lnd is on) +if [ "${lightning}" == "lnd" ] || [ "${lnd}" == "on" ]; then echo "running LND users credentials update" >> $logFile - sudo /home/admin/config.scripts/lnd.credentials.sh sync >> $logFile - + /home/admin/config.scripts/lnd.credentials.sh sync >> $logFile else echo "skipping LND credentials sync" >> $logFile fi @@ -789,11 +755,10 @@ fi # if "localBackupDeviceUUID" is set in # raspiblitz.conf mount it on boot ################################ -source ${configFile} echo "Checking if additional backup device is configured .. (${localBackupDeviceUUID})" >> $logFile if [ "${localBackupDeviceUUID}" != "" ] && [ "${localBackupDeviceUUID}" != "off" ]; then echo "Yes - Mounting BackupDrive: ${localBackupDeviceUUID}" >> $logFile - sudo /home/admin/config.scripts/blitz.backupdevice.sh mount >> $logFile + /home/admin/config.scripts/blitz.backupdevice.sh mount >> $logFile else echo "No additional backup device was configured." >> $logFile fi @@ -801,7 +766,6 @@ fi ##################################### # 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 @@ -818,7 +782,17 @@ fi 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/ + btrfs scrub start /mnt/hdd/ +fi + + +#################### +# FORCE UASP FLAG +#################### +# if uasp.force flag was set on sd card - now move into raspiblitz.conf +if [ -f "/boot/uasp.force" ]; then + /home/admin/config.scripts/blitz.conf.sh set forceUasp "on" + echo "DONE forceUasp=on recorded in raspiblitz.conf" >> $logFile fi ###################################### @@ -830,18 +804,27 @@ if [ -d "/mnt/hdd/app-data/subscriptions" ]; then sudo chown admin:admin /mnt/hdd/app-data/subscriptions else echo "CREATE: subscription data directory" - sudo mkdir /mnt/hdd/app-data/subscriptions - sudo chown admin:admin /mnt/hdd/app-data/subscriptions + mkdir /mnt/hdd/app-data/subscriptions + chown admin:admin /mnt/hdd/app-data/subscriptions fi # make sure that bitcoin service is active sudo systemctl enable ${network}d # make sure setup/provision is marked as done -sudo rm /home/admin/provision.flag -sed -i "s/^setupPhase=.*/setupPhase='done'/g" ${infoFile} -sed -i "s/^state=.*/state=ready/g" ${infoFile} -sed -i "s/^message=.*/message='Node Running'/g" ${infoFile} +/home/admin/_cache.sh set setupPhase "done" +/home/admin/_cache.sh set state "ready" +/home/admin/_cache.sh set message "Node Running" + +# relax systemscan on certain values +/home/admin/_cache.sh focus internet_localip -1 + +# if node is stil in inital blockchain download +source <(/home/admin/_cache.sh get btc_default_sync_initialblockdownload) +if [ "${btc_default_sync_initialblockdownload}" == "1" ]; then + echo "Node is still in IBD .. refresh btc_default_sync_progress faster" >> $logFile + /home/admin/_cache.sh focus btc_default_sync_progress 0 +fi echo "DONE BOOTSTRAP" >> $logFile exit 0 diff --git a/home.admin/_cache.sh b/home.admin/_cache.sh new file mode 100755 index 00000000..e4f2b7b2 --- /dev/null +++ b/home.admin/_cache.sh @@ -0,0 +1,474 @@ +#!/usr/bin/env bash + +# the cache concept of RaspiBlitz has two options +# 1) RAMDISK for files under /var/cache/raspiblitz +# 2) KEY-VALUE STORE for system state infos (REDIS) + +# SECURITY NOTE: The files on the RAMDISK can be set with unix file permissions and so restrict certain users access. +# But all data stored in the KEY-VALUE STORE has to be asumed as system-wide public information. + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then + echo "RaspiBlitz Cache" + echo + echo "_cache.sh ramdisk [on|off]" + echo "_cache.sh keyvalue [on|off]" + echo + echo "_cache.sh set [key] [value] [?expire-seconds]" + echo "_cache.sh get [key1] [?key2] [?key3] ..." + echo + echo "_cache.sh increment [key1]" + echo + echo "_cache.sh focus [key] [update-seconds] [?duration-seconds]" + echo "# set in how many seconds value is marked to be rescanned" + echo "# -1 = slowest default update cycle" + echo "# 0 = update on every cycle" + echo "# set a 'duration-seconds' after defaults to -1 (optional)" + echo + echo "_cache.sh meta [key] [?default]" + echo "# get single key with additional metadata:" + echo "# updateseconds= see above" + echo "# stillvalid=0/1 if value is still valid or outdated" + echo "# lasttouch= last update timestamp in unix seconds" + echo + echo "_cache.sh valid [key1] [?key2] [?key3] ..." + echo "# check multiple keys if all are still not outdated" + echo "# use for example to check if a complex call needs" + echo "# to be made that covers multiple single data points" + echo + echo "_cache.sh import [bash-keyvalue-file]" + echo "# import a bash style key-value file into store" + echo + echo "_cache.sh export [?key-prefix]" + echo "# export bash-style key-value to stdout" + echo "# can be used with a key-prefix just get a subset" + echo + exit 1 +fi + +# BACKGROUND: we need to build outdated meta info manually, +# because there is nothing as "AGE" in redis: https://github.com/redis/redis/issues/1147 +# only feature that can be used uis the EXPIRE feature to determine if a value is still valid + +# postfixes for metadata in key/value store +META_OUTDATED_SECONDS=":out" +META_LASTTOUCH_TS=":ts" +META_VALID_FLAG=":val" + +# path of the raspiblitz.info file (persiting cache values) +infoFile="/home/admin/raspiblitz.info" + +################### +# RAMDISK +# will be available under /var/cache/raspiblitz +################### + +# install +if [ "$1" = "ramdisk" ] && [ "$2" = "on" ]; then + + echo "# Turn ON: RAMDISK" + + if ! grep -Eq '^tmpfs.*/var/cache/raspiblitz' /etc/fstab; then + + if grep -Eq '/var/cache/raspiblitz' /etc/fstab; then + # entry is in file but most likely just disabled -> re-enable it + sudo sed -i -E 's|^#(tmpfs.*/var/cache/raspiblitz.*)$|\1|g' /etc/fstab + else + # missing -> add + echo "" | sudo tee -a /etc/fstab >/dev/null + echo "tmpfs /var/cache/raspiblitz tmpfs nodev,nosuid,size=32M 0 0" | sudo tee -a /etc/fstab >/dev/null + fi + fi + + if ! findmnt -l /var/cache/raspiblitz >/dev/null; then + sudo mkdir -p /var/cache/raspiblitz + sudo mount /var/cache/raspiblitz + fi + + +# uninstall +elif [ "$1" = "ramdisk" ] && [ "$2" = "off" ]; then + + echo "# Turn OFF: RAMDISK" + + if grep -Eq '/var/cache/raspiblitz' /etc/fstab; then + sudo sed -i -E 's|^(tmpfs.*/var/cache/raspiblitz.*)$|#\1|g' /etc/fstab + fi + + if findmnt -l /var/cache/raspiblitz >/dev/null; then + sudo umount /var/cache/raspiblitz + fi + +################### +# KEYVALUE (REDIS) +################### + +# install +elif [ "$1" = "keyvalue" ] && [ "$2" = "on" ]; then + + echo "# Turn ON: KEYVALUE-STORE (REDIS)" + sudo apt install -y redis-server + + # edit config: dont save to disk + sudo sed -i "/^save .*/d" /etc/redis/redis.conf + + # restart with new config + sudo systemctl restart redis-server + + # clean old databases if exist + sudo rm /var/lib/redis/dump.rdb 2>/dev/null + + # restart again this time there is no old data dump to load + sudo systemctl restart redis-server + +# uninstall +elif [ "$1" = "keyvalue" ] && [ "$2" = "off" ]; then + + echo "# Turn OFF: KEYVALUE-STORE (REDIS)" + sudo apt remove -y redis-server + +################### +# SET/GET/IMPORT +# basic key value +################### + +# set +elif [ "$1" = "set" ]; then + + # get parameters + keystr=$2 + valuestr=$3 + expire=$4 + + # check that key & value are given + if [ "${keystr}" == "" ]; then + echo "# Fail: missing parameter" + exit 1 + fi + + # filter from expire just numbers + expire="${expire//[^0-9.]/}" + + # add an expire flag if given + additionalParams="" + if [ "${expire}" != "" ]; then + additionalParams="EX ${expire}" + fi + + # set in redis key value cache + redis-cli set ${keystr} "${valuestr}" ${additionalParams} 1>/dev/null + + # set in redis the timestamp + timestamp=$(date +%s) + redis-cli set ${keystr}${META_LASTTOUCH_TS} "${timestamp}" ${additionalParams} 1>/dev/null + #echo "# lasttouch(${timestamp})" + + # check if the value has a outdate policy + outdatesecs=$(redis-cli get ${keystr}${META_OUTDATED_SECONDS}) + if [ "${outdatesecs}" == "" ]; then + outdatesecs="-1" + fi + #echo "# outdatesecs(${outdatesecs})" + if [ "${outdatesecs}" != "-1" ]; then + # set exipire valid flag (if its gone - value is considered as outdated) + redis-cli set ${keystr}${META_VALID_FLAG} "1" EX ${outdatesecs} 1>/dev/null + fi + + # also update value if part of raspiblitz.info (persiting values to survice boot) + persistKey=$(cat ${infoFile} | grep -c "^${keystr}=") + if [ ${persistKey} -gt 0 ]; then + sudo sed -i "s/^${keystr}=.*/${keystr}='${valuestr}'/g" ${infoFile} + fi + +# get +elif [ "$1" = "get" ]; then + + position=0 + for keystr in $@ + do + + # skip first parameter + ((position++)) + if [ $position -eq 1 ]; then + echo "# _cache.sh $@" + continue + fi + + # get redis value + valuestr=$(redis-cli get ${keystr}) + + # output key value in bash script compatible way + echo "${keystr}=\"${valuestr}\"" + done + +# import values from bash key-value store +elif [ "$1" = "import" ]; then + + # get parameter + filename=$2 + + # source values from given file (to be used for import later) + source ${filename} + + # read file and go thru line by line + n=1 + while read line; do + + # skip comment lines + isComment=$(echo "${line}" | grep -c "^#") + if [ ${isComment} -eq 1 ]; then + continue + fi + + # skip if not a value line + isValueLine=$(echo "${line}" | grep -c "=") + if [ ${isValueLine} -eq 0 ]; then + continue + fi + + # import key from line & value from source above (that way quotes are habdled correctly) + keyValue=$(echo "$line" | cut -d "=" -f1) + echo "# redis-cli set ${keyValue} ${!keyValue}" + redis-cli set ${keyValue} "${!keyValue}" 1>/dev/null + + # also set the timestamp on import for each value + timestamp=$(date +%s) + redis-cli set ${keyValue}${META_LASTTOUCH_TS} "${timestamp}" 1>/dev/null + + done < $filename + +# import values from bash key-value store +elif [ "$1" = "export" ]; then + + # get parameter + keyfilter="${2}*" + + # go thru all keys by keyfilter + keylist=$(redis-cli KEYS "${keyfilter}") + readarray -t arr <<< "${keylist}" + for key in "${arr[@]}";do + + # skip empty keys + if [ "${key}" == "" ]; then + continue + fi + + # skip metadata keys + isMeta=$(echo "${key}" | grep -c ":") + if [ ${isMeta} -gt 0 ]; then + continue + fi + + # print out key/value + value=$(redis-cli get "${key}") + echo "${key}=\"${value}\"" + done + +################################## +# COUNT +# count value up +################################## + +# set +elif [ "$1" = "increment" ]; then + + # get parameters + keystr=$2 + + # check that key & value are given + if [ "${keystr}" == "" ]; then + echo "# Fail: missing parameter" + exit 1 + fi + # set in redis key value cache + redis-cli incr ${keystr} 1>/dev/null + + # set in redis the timestamp + timestamp=$(date +%s) + redis-cli set ${keystr}${META_LASTTOUCH_TS} "${timestamp}" 1>/dev/null + + +################################## +# FOCUS +# signal update rate on value +################################## + +# focus (set outdated policy) +elif [ "$1" = "focus" ]; then + + # get parameters + keystr=$2 + outdatesecs=$3 + durationsecs=$4 + + # if no further parameters - list all values with running focus + if [ "${keystr}" == "" ]; then + echo "# cache values with active focus:" + keylist=$(redis-cli KEYS "*:out") + readarray -t arr <<< "${keylist}" + for key in "${arr[@]}";do + if [ "${key}" == "" ]; then + continue + fi + keyClean=$(echo $key | cut -d ":" -f1) + value=$(redis-cli get "${key}") + echo "${keyClean}=${value}" + done + exit + fi + + # delete outdate policy field ==> default + if [ "${outdatesecs}" == "-1" ]; then + echo "# redis-cli del ${keystr}${META_OUTDATED_SECONDS}" + redis-cli del ${keystr}${META_OUTDATED_SECONDS} + exit + fi + + # sanatize parameters (if not -1) + outdatesecs="${outdatesecs//[^0-9.]/}" + + # check that key & value are given + if [ "${outdatesecs}" == "" ]; then + echo "# Fail: missing parameter" + exit 1 + fi + + # add an expire flag if given + additionalParams="" + if [ "${durationsecs//[^0-9.]/}" != "" ]; then + additionalParams="EX ${durationsecs//[^0-9.]/}" + fi + + # store the seconds policy + echo "# redis-cli set ${keystr}${META_OUTDATED_SECONDS} ${outdatesecs} ${additionalParams}" + redis-cli set ${keystr}${META_OUTDATED_SECONDS} "${outdatesecs}" ${additionalParams} + + # set/renew exipire valid flag (important in case the key had before no expire) + redis-cli set ${keystr}${META_VALID_FLAG} "1" EX ${outdatesecs} 1>/dev/null + +################################## +# META +# metadata on values +################################## + +# meta +elif [ "$1" = "meta" ]; then + + # get parameters + keystr=$2 + default=$3 + + # check that key & value are given + if [ "${keystr}" == "" ]; then + echo "# Fail: missing parameter" + exit 1 + fi + + # get redis basic value + valuestr=$(redis-cli get ${keystr}) + echo "value=\"${valuestr}\"" + + # get META_LASTTOUCH_TS + lasttouch=$(redis-cli get ${keystr}${META_LASTTOUCH_TS}) + if [ "${lasttouch}" == "" ]; then + echo "initiated=0" + exit 0 + fi + echo "initiated=1" + echo "lasttouch=\"${lasttouch}\"" + + # get META_OUTDATED_SECONDS + outdatesecs=$(redis-cli get ${keystr}${META_OUTDATED_SECONDS}) + if [ "${outdatesecs}" == "" ]; then + # default is -1 --> never outdate + outdatesecs="-1" + fi + echo "outdatesecs=\"${outdatesecs}\"" + + # get META_VALID_FLAG + valuestr=$(redis-cli get ${keystr}${META_VALID_FLAG}) + if [ "${valuestr}" == "" ] && [ "${outdatesecs}" != "-1" ]; then + stillvalid=0 + else + stillvalid=1 + fi + echo "stillvalid=\"${stillvalid}\"" + +################################## +# VALID +# check if a value needs update +################################## + +# valid +elif [ "$1" = "valid" ]; then + + position=0 + lasttouch_overall="" + for keystr in $@ + do + + # skip first parameter from script - thats the action string + ((position++)) + if [ $position -eq 1 ]; then + echo "# _cache.sh $@" + continue + fi + + # check lasttouch for value + lasttouch=$(redis-cli get ${keystr}${META_LASTTOUCH_TS}) + #echo "# lasttouch(${lasttouch})" + + # no lasttouch entry ==> was not initiated ==> not valid + if [ "${lasttouch}" == "" ]; then + # break loop on first unvalid value found + echo "stillvalid=\"0\"" + exit 0 + fi + + # record the smallest timestamp (oldest date) of all values + if [ "${lasttouch}" != "" ]; then + # find smallest lasttouch + if [ "${lasttouch_overall}" == "" ] || [ ${lasttouch_overall} -gt ${lasttouch} ]; then + lasttouch_overall="${lasttouch}" + fi + fi + + # get outdate police of value (outdated = not valid anymore) + outdatesecs=$(redis-cli get ${keystr}${META_OUTDATED_SECONDS}) + #echo "# ${keystr}${META_OUTDATED_SECONDS}=\"${outdatesecs}\"" + + # if outdate policy is default or -1 ==> never outdated + if [ "${outdatesecs}" == "" ] || [ "${outdatesecs}" == "-1" ]; then + continue + fi + + # so outdate policy is active - check if valid flag exists + validflag=$(redis-cli get ${keystr}${META_VALID_FLAG}) + #echo "# ${keystr}${META_VALID_FLAG}=\"${validflag}\"" + + # if valid flag exists this value is valid + if [ "${valuestr}" != "" ]; then + continue + fi + + # so valid flag does not exists anymore + # ==> this means value is outdated + # break loop and + echo "stillvalid=\"0\"" + exit 0 + + done + + # so if all were valid + echo "stillvalid=\"1\"" + + # calculate age in seconds of oldest entry + if [ "${lasttouch_overall}" != "" ]; then + timestamp=$(date +%s) + age=$(($timestamp-$lasttouch_overall)) + echo "age=\"${age}\"" + fi + +else + echo "# FAIL: parameter not known - run with -h for help" +fi diff --git a/home.admin/_commands.sh b/home.admin/_commands.sh index 23b28e63..bea2a857 100755 --- a/home.admin/_commands.sh +++ b/home.admin/_commands.sh @@ -33,6 +33,7 @@ function blitzhelp() { echo " debug print debug logs" echo " debug -l print debug logs with bin link" echo " patch sync scripts with latest set github and branch" + echo " cache check on chache system state" echo " github jumping directly into the options to change branch/repo/pr" echo echo "Power:" @@ -157,6 +158,11 @@ function headless() { restart } +# command: cache +function cache() { + sudo /home/admin/_cache.sh $@ +} + # command: torthistx function torthistx() { if [ $(cat /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "runBehindTor=on") -eq 1 ]; then @@ -164,14 +170,18 @@ function torthistx() { curl --socks5-hostname localhost:9050 -d $1 -X POST http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/api/tx else echo "Not running behind Tor - to install run:" - echo "sudo /home/admin/config.scripts/internet.tor.sh on" + echo "sudo /home/admin/config.scripts/tor.network.sh on" fi } # command: status # start the status screen in the terminal function status() { - echo "Gathering data - please wait a moment..." + echo + echo "Keep X pressed to EXIT loop ... (please wait)" + echo + /home/admin/_cache.sh set system_scan_all_temp "1" + sleep 4 while : do # show the same info as on LCD screen @@ -181,10 +191,10 @@ function status() { #echo #echo -en "Screen is updating in a loop .... press 'x' now to get back to menu." read -n 1 -t 6 keyPressed - #echo -en "\rGathering information to update info ... please wait. \n" # check if user wants to abort session if [ "${keyPressed}" = "x" ]; then echo + /home/admin/_cache.sh set system_scan_all_temp "0" echo "Returning to menu ....." sleep 4 break @@ -294,10 +304,10 @@ if [ -f "/mnt/hdd/raspiblitz.conf" ] && [ $(grep -c "lit=on" < /mnt/hdd/raspibl --tlscertpath=/home/lit/.lit/tls.cert \ --macaroonpath=/home/lit/.faraday/${chain}net/faraday.macaroon" alias lit-loop="sudo -u lit loop --rpcserver=localhost:8443 \\ - --tlscertpath=/home/lit/.lit/tls.cert \\ + --tlscertpath=/home/lit/.lit/tls.cert \\ --macaroonpath=/home/lit/.loop/${chain}net/loop.macaroon" alias lit-pool="sudo -u lit pool --rpcserver=localhost:8443 \ - --tlscertpath=/home/lit/.lit/tls.cert \ + --tlscertpath=/home/lit/.lit/tls.cert \ --macaroonpath=/home/lit/.pool/${chain}net/pool.macaroon" fi @@ -316,7 +326,7 @@ function gettx() { # command: watchtx # try to retrieve transaction from mempool or blockchain until certain confirmation target -# is reached and then exit cleanly. Default is to wait for 2 confs and to sleep for 60 secs. +# is reached and then exit cleanly. Default is to wait for 2 confs and to sleep for 60 secs. # $ watchtx "f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16" 6 30 function watchtx() { tx_id="${1}" @@ -348,8 +358,8 @@ function watchtx() { } # command: notifyme -# A wrapper for blitz.notify.sh that will send a notification using the configured -# method and settings. +# A wrapper for blitz.notify.sh that will send a notification using the configured +# method and settings. # This makes sense when waiting for commands to finish and then sending a notification. # $ notifyme "Hello there..!" # $ ./run_job_which_takes_long.sh && notifyme "I'm done." diff --git a/home.admin/_provision.migration.sh b/home.admin/_provision.migration.sh index 2c9cd0ee..0b6ef9e2 100755 --- a/home.admin/_provision.migration.sh +++ b/home.admin/_provision.migration.sh @@ -1,5 +1,11 @@ #!/bin/bash +# check if started with sudo +if [ "$EUID" -ne 0 ]; then + echo "error='run as root'" + exit 1 +fi + # LOGFILE - store debug logs of bootstrap logFile="/home/admin/raspiblitz.provision-migration.log" @@ -10,26 +16,20 @@ source ${infoFile} # SETUPFILE - data from setup process source /var/cache/raspiblitz/temp/raspiblitz.setup -# CONFIGFILE - configuration of RaspiBlitz -configFile="/mnt/hdd/raspiblitz.conf" - # log header echo "" > ${logFile} echo "###################################" >> ${logFile} echo "# _provision.migration.sh" >> ${logFile} echo "###################################" >> ${logFile} -sudo sed -i "s/^message=.*/message='Provision Migration'/g" ${infoFile} +/home/admin/_cache.sh set message "Provision Migration" + +source <(/home/admin/config.scripts/blitz.datadrive.sh status) if [ "${hddGotMigrationData}" == "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='config: missing hddGotMigrationData'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: missing hddGotMigrationData in (${infoFile})!" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.migration.sh "missing-hostnamemigrationdata" "missing hddGotMigrationData" "" ${logFile} exit 2 fi -source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) - err="" nodenameUpperCase=$(echo "${hddGotMigrationData}" | tr "[a-z]" "[A-Z]") echo "**************************************************" >> ${logFile} @@ -38,16 +38,13 @@ echo "**************************************************" >> ${logFile} echo "- started ..." >> ${logFile} source <(sudo /home/admin/config.scripts/blitz.migration.sh migration-${hddGotMigrationData}) if [ "${err}" != "" ]; then - echo "MIGRATION FAILED: ${err}" >> ${logFile} - echo "Format data disk on laptop & recover funds with fresh sd card using seed words + static channel backup." >> ${logFile} - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='migration failed'/g" ${infoFile} + /home/admin/config.scripts/blitz.error.sh _provision.migration.sh "migration-failed" "${err}" "Recover funds with fresh sd card using seed words + static channel backup." ${logFile} exit 3 fi # make sure for the rest of the seup info is set correctly -sudo sed -i "s/^network=.*/network=bitcoin/g" ${infoFile} -sudo sed -i "s/^chain=.*/chain=main/g" ${infoFile} +/home/admin/config.scripts/blitz.conf.sh set network "bitcoin" +/home/admin/config.scripts/blitz.conf.sh set chain "main" # set Password B echo "## SETTING PASSWORD B" >> ${logFile} @@ -57,20 +54,21 @@ if [ "${setPasswordB}" == "1" ]; then echo "# setting PASSWORD B" >> ${logFile} /home/admin/config.scripts/blitz.setpassword.sh b "${passwordB}" >> ${logFile} else - echo "FAIL: Password B should be set but was empty! Running with default." >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.migration.sh "missing-passwordb" "FAIL: Password B should be set but was empty! Running with default." "" ${logFile} + exit 4 fi else - echo "WARN: setPasswordB!=1 this not normal on migration! Running with default." >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.migration.sh "missing-setpasswordb" "setPasswordB!=1 this not normal on migration! Running with default." "" ${logFile} + exit 5 fi # if free space is lower than 100GB (100000000) delete backup files if [ "${hddDataFreeKB}" != "" ] && [ ${hddDataFreeKB} -lt 407051412 ]; then echo "- free space of data disk is low ... deleting 'backup_migration'" >> ${logFile} - sudo rm -R /mnt/hdd/backup_migration + rm -R /mnt/hdd/backup_migration else echo "- old data of ${nodenameUpperCase} can be found in '/mnt/hdd/backup_migration'" >> ${logFile} fi echo "OK MIGRATION" >> ${logFile} echo "END Migration" >> ${logFile} -exit 0 - +exit 0 \ No newline at end of file diff --git a/home.admin/_provision.setup.sh b/home.admin/_provision.setup.sh index 4ab9f257..06cb8ce3 100755 --- a/home.admin/_provision.setup.sh +++ b/home.admin/_provision.setup.sh @@ -1,5 +1,11 @@ #!/bin/bash +# check if started with sudo +if [ "$EUID" -ne 0 ]; then + echo "error='run as root'" + exit 1 +fi + # this provision file is just executed on fresh setups # not on recoveries or updates @@ -23,35 +29,29 @@ echo "" > ${logFile} echo "###################################" >> ${logFile} echo "# _provision.setup.sh" >> ${logFile} echo "###################################" >> ${logFile} -sudo sed -i "s/^message=.*/message='Provision Setup'/g" ${infoFile} ################################### # Preserve SSH keys # just copy dont link anymore # see: https://github.com/rootzoll/raspiblitz/issues/1798 -sed -i "s/^message=.*/message='SSH Keys'/g" ${infoFile} +/home/admin/_cache.sh set message "SSH Keys" # link ssh directory from SD card to HDD /home/admin/config.scripts/blitz.ssh.sh backup ################################### # Prepare Blockchain Service -sed -i "s/^message=.*/message='Blockchain Setup'/g" ${infoFile} +/home/admin/_cache.sh set message "Blockchain Setup" +source <(/home/admin/_cache.sh get network chain hddBlocksBitcoin) if [ "${network}" == "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='config: missing network'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: missing network in (${setupFile})!" >> ${logFile} - exit 20 + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-network" "" "" ${logFile} + exit 2 fi if [ "${chain}" == "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='config: missing chain'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: missing chain in (${setupFile})!" >> ${logFile} - exit 2 + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-chain" "" "" ${logFile} + exit 3 fi # copy configs files and directories @@ -74,7 +74,7 @@ chown -R admin:admin /home/admin/.${network} >>${logFile} 2>&1 confExists=$(sudo ls /mnt/hdd/${network}/${network}.conf | grep -c "${network}.conf") echo "File Exists: /mnt/hdd/${network}/${network}.conf --> ${confExists}" >> ${logFile} -# set password B as RPC password +# set password B as RPC password (from setup file) echo "# setting PASSWORD B" >> ${logFile} /home/admin/config.scripts/blitz.setpassword.sh b "${passwordB}" >> ${logFile} @@ -119,9 +119,7 @@ do sync loopcount=$(($loopcount +1)) if [ ${loopcount} -gt 50 ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: failed ${network}'/g" ${infoFile} - echo "FAIL: setup: failed ${network}" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "btc-testrun-fail" "${network}d not running" "sudo -u bitcoin ${network}-cli getblockchaininfo | grep "initialblockdownload" -c --> ${bitcoinRunning}" ${logFile} exit 4 fi done @@ -130,14 +128,20 @@ echo "OK ${network} startup successful " >> ${logFile} ################################### # Prepare Lightning +source /mnt/hdd/raspiblitz.conf echo "Prepare Lightning (${lightning})" >> ${logFile} +if [ "${hostname}" == "" ]; then + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-hostname" "" "" ${logFile} + exit 41 +fi + if [ "${lightning}" != "lnd" ]; then ################################### # Remove LND from systemd echo "Remove LND" >> ${logFile} - sudo sed -i "s/^message=.*/message='Deactivate Lightning'/g" ${infoFile} + /home/admin/_cache.sh set message "Deactivate Lightning" sudo systemctl disable lnd sudo rm /etc/systemd/system/lnd.service 2>/dev/null sudo systemctl daemon-reload @@ -148,30 +152,24 @@ if [ "${lightning}" == "lnd" ]; then ################################### # LND echo "############## Setup LND" >> ${logFile} - sudo sed -i "s/^message=.*/message='LND Setup'/g" ${infoFile} + /home/admin/_cache.sh set message "LND Setup" + # password C (raspiblitz.setup) if [ "${passwordC}" == "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='config: missing passwordC'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: missing passwordC in (${setupFile})!" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-passwordc" "config: missing passwordC" "" ${logFile} exit 5 fi - # if user uploaded an LND rescue file + # if user uploaded an LND rescue file (raspiblitz.setup) if [ "${lndrescue}" != "" ]; then echo "Restore LND data from uploaded rescue file ${lndrescue} ..." >> ${logFile} source <(sudo /home/admin/config.scripts/lnd.backup.sh lnd-import ${lndrescue}) if [ "${error}" != "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: lnd import backup failed'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: setup: lnd import backup failed" >> ${logFile} - echo "${error}" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lndrescue-import" "setup: lnd import backup failed" "${error}" ${logFile} exit 6 fi else - # preparing new LND config + # preparing new LND config (raspiblitz.setup) echo "Creating new LND config ..." >> ${logFile} sudo -u bitcoin mkdir /mnt/hdd/lnd 2> /dev/null sudo cp /home/admin/assets/lnd.bitcoin.conf /mnt/hdd/lnd/lnd.conf @@ -186,16 +184,13 @@ if [ "${lightning}" == "lnd" ]; then # check if now a config exists configLinkedCorrectly=$(sudo ls sudo ls /home/bitcoin/.lnd/lnd.conf | grep -c "lnd.conf") if [ "${configLinkedCorrectly}" != "1" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: lnd conf link broken'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: setup: lnd conf link broken" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-link-broken" "link /home/bitcoin/.lnd/lnd.conf broken" "" ${logFile} exit 7 fi # Init LND service & start echo "*** Init LND Service & Start ***" >> ${logFile} - sudo sed -i "s/^message=.*/message='LND Testrun'/g" ${infoFile} + /home/admin/_cache.sh set message "LND Testrun" # just in case sudo systemctl stop lnd 2>/dev/null @@ -208,13 +203,14 @@ if [ "${lightning}" == "lnd" ]; then echo "Starting LND Service ..." >> ${logFile} sudo systemctl enable lnd >> ${logFile} sudo systemctl start lnd >> ${logFile} + echo "Starting LND Service ... executed" >> ${logFile} # check that lnd started lndRunning=0 loopcount=0 while [ ${lndRunning} -eq 0 ] do - lndRunning=$(sudo systemctl status lnd.service | grep -c running) + lndRunning=$(systemctl status lnd.service | grep -c running) if [ ${lndRunning} -eq 0 ]; then date +%s >> ${logFile} echo "LND not ready yet ... waiting another 60 seconds." >> ${logFile} @@ -222,10 +218,7 @@ if [ "${lightning}" == "lnd" ]; then fi loopcount=$(($loopcount +1)) if [ ${loopcount} -gt 100 ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: failed lnd start'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: setup: failed lnd start" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-start-fail" "lnd service not getting to running status" "sudo systemctl status lnd.service | grep -c running --> ${lndRunning}" ${logFile} exit 8 fi done @@ -233,25 +226,18 @@ if [ "${lightning}" == "lnd" ]; then sleep 10 # Check LND health/fails (to be extended) - tlsExists=$(sudo ls /mnt/hdd/lnd/tls.cert 2>/dev/null | grep -c "tls.cert") + tlsExists=$(ls /mnt/hdd/lnd/tls.cert 2>/dev/null | grep -c "tls.cert") if [ ${tlsExists} -eq 0 ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: missing lnd tls'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: setup: missing lnd tls" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-no-tls" "lnd not created TLS cert" "no /mnt/hdd/lnd/tls.cert" ${logFile} exit 9 fi # import static channel backup if was uploaded if [ "${staticchannelbackup}" != "" ]; then echo "Preparing static channel backup file ${staticchannelbackup} ..." >> ${logFile} - source <(sudo /home/admin/config.scripts/lnd.backup.sh scb-import ${staticchannelbackup}) + source <(/home/admin/config.scripts/lnd.backup.sh scb-import ${staticchannelbackup}) if [ "${error}" != "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: lnd import SCB failed'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: setup: lnd import SCB failed" >> ${logFile} - echo "${error}" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-scb-import" "lnd.backup.sh scb-import returned error" "/home/admin/config.scripts/lnd.backup.sh scb-import ${staticchannelbackup} --> ${error}" ${logFile} exit 10 fi fi @@ -260,33 +246,23 @@ if [ "${lightning}" == "lnd" ]; then if [ "${seedWords}" != "" ] && [ "${staticchannelbackup}" != "" ]; then echo "WALLET --> SEED + SCB " >> ${logFile} - sudo sed -i "s/^message=.*/message='LND Wallet (SEED & SCB)'/g" ${infoFile} - if ! pip list | grep grpc; then sudo -H python3 -m pip install grpcio==1.38.1; fi - sudo /home/admin/config.scripts/lnd.initwallet.py scb mainnet ${passwordC} "${seedWords}" "${staticchannelbackup}" ${seedPassword} + /home/admin/_cache.sh set message "LND Wallet (SEED & SCB)" + if ! pip list | grep grpc; then sudo -H python3 -m pip install grpcio==1.38.1; fi + source <(/home/admin/config.scripts/lnd.initwallet.py scb mainnet ${passwordC} "${seedWords}" "${staticchannelbackup}" ${seedPassword}) if [ "${err}" != "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: lnd wallet SCB failed'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: setup: lnd wallet SCB failed" >> ${logFile} - echo "${err}" >> ${logFile} - echo "${errMore}" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-wallet-seed+scb" "lnd.initwallet.py scb returned error" "/home/admin/config.scripts/lnd.initwallet.py scb mainnet ... --> ${err} + ${errMore}" ${logFile} exit 11 fi # WALLET --> SEED elif [ "${seedWords}" != "" ]; then - echo "WALLET --> SEED" >> ${logFile} - sudo sed -i "s/^message=.*/message='LND Wallet (SEED)'/g" ${infoFile} + echo "WALLET --> SEED" >> ${logFile} + /home/admin/_cache.sh set message "LND Wallet (SEED)" if ! pip list | grep grpc; then sudo -H python3 -m pip install grpcio==1.38.1; fi - sudo /home/admin/config.scripts/lnd.initwallet.py seed mainnet ${passwordC} "${seedWords}" ${seedPassword} + source <(/home/admin/config.scripts/lnd.initwallet.py seed mainnet ${passwordC} "${seedWords}" ${seedPassword}) if [ "${err}" != "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: lnd wallet SEED failed'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: setup: lnd wallet SEED failed" >> ${logFile} - echo "${err}" >> ${logFile} - echo "${errMore}" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-wallet-seed" "lnd.initwallet.py seed returned error" "/home/admin/config.scripts/lnd.initwallet.py seed mainnet ... --> ${err} + ${errMore}" ${logFile} exit 12 fi @@ -294,14 +270,15 @@ if [ "${lightning}" == "lnd" ]; then else echo "WALLET --> NEW" >> ${logFile} - sudo sed -i "s/^message=.*/message='LND Wallet (NEW)'/g" ${infoFile} - if ! pip list | grep grpc; then sudo -H python3 -m pip install grpcio==1.38.1; fi - source <(sudo /home/admin/config.scripts/lnd.initwallet.py new mainnet ${passwordC}) + /home/admin/_cache.sh set message "LND Wallet (NEW)" + if ! pip list | grep grpc; then sudo -H python3 -m pip install grpcio==1.38.1; fi + source <(/home/admin/config.scripts/lnd.initwallet.py new mainnet ${passwordC}) if [ "${err}" != "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: lnd wallet SEED failed'/g" ${infoFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-wallet-new" "lnd.initwallet.py new returned error" "/home/admin/config.scripts/lnd.initwallet.py new mainnet ... --> ${err} + ${errMore}" ${logFile} + /home/admin/_cache.sh set state "error" + /home/admin/_cache.sh set message "setup: lnd wallet NEW failed" echo "FAIL see ${logFile}" - echo "FAIL: setup: lnd wallet SEED failed" >> ${logFile} + echo "FAIL: setup: lnd wallet SEED failed (2)" >> ${logFile} echo "${err}" >> ${logFile} echo "${errMore}" >> ${logFile} exit 13 @@ -315,14 +292,12 @@ if [ "${lightning}" == "lnd" ]; then # sync macaroons & TLS to other users echo "*** Copy LND Macaroons to user admin ***" >> ${logFile} - sudo sed -i "s/^message=.*/message='LND Credentials'/g" ${infoFile} + /home/admin/_cache.sh set message "LND Credentials" # check if macaroon exists now - if not fail macaroonExists=$(sudo -u bitcoin ls -la /home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon 2>/dev/null | grep -c admin.macaroon) if [ ${macaroonExists} -eq 0 ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: lnd no macaroons'/g" ${infoFile} - echo "FAIL: setup: lnd no macaroons" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-no-macaroons" "lnd did not create macaroons" "/home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon --> missing" ${logFile} exit 14 fi @@ -332,10 +307,7 @@ if [ "${lightning}" == "lnd" ]; then # make a final lnd check source <(/home/admin/config.scripts/lnd.check.sh basic-setup) if [ "${err}" != "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: lnd wallet SEED failed'/g" ${infoFile} - echo "FAIL: setup: lnd wallet SEED failed" >> ${logFile} - echo "${err}" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "lnd-check-error" "lnd.check.sh basic-setup with error" "/home/admin/config.scripts/lnd.check.sh basic-setup --> ${err}" ${logFile} exit 15 fi @@ -351,21 +323,17 @@ if [ "${lightning}" == "cl" ]; then # c-lightning echo "############## c-lightning" >> ${logFile} - sudo sed -i "s/^message=.*/message='C-Lightning Install'/g" ${infoFile} + /home/admin/_cache.sh set message "C-Lightning Install" sudo /home/admin/config.scripts/cl.install.sh on mainnet >> ${logFile} - sudo sed -i "s/^message=.*/message='C-Lightning Setup'/g" ${infoFile} + /home/admin/_cache.sh set message "C-Lightning Setup" # OLD WALLET FROM CLIGHTNING RESCUE if [ "${clrescue}" != "" ]; then echo "Restore CL data from uploaded rescue file ${clrescue} ..." >> ${logFile} - source <(sudo /home/admin/config.scripts/cl.backup.sh cl-import ${clrescue}) + source <(/home/admin/config.scripts/cl.backup.sh cl-import ${clrescue}) if [ "${error}" != "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: cl import backup failed'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: setup: cl import backup failed" >> ${logFile} - echo "${error}" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "cl-import-backup" "cl.backup.sh cl-import with error" "/home/admin/config.scripts/cl.backup.sh cl-import ${clrescue} --> ${error}" ${logFile} exit 16 fi @@ -373,14 +341,12 @@ if [ "${lightning}" == "cl" ]; then elif [ "${seedWords}" != "" ]; then echo "Restore CL wallet from seedWords ..." >> ${logFile} - source <(sudo /home/admin/config.scripts/cl.hsmtool.sh seed-force mainnet "${seedWords}" "${seedPassword}") + source <(/home/admin/config.scripts/cl.hsmtool.sh seed-force mainnet "${seedWords}" "${seedPassword}") # check if wallet really got created - walletExistsNow=$(sudo ls /home/bitcoin/.lightning/bitcoin/hsm_secret 2>/dev/null | grep -c "hsm_secret") + walletExistsNow=$(ls /home/bitcoin/.lightning/bitcoin/hsm_secret 2>/dev/null | grep -c "hsm_secret") if [ $walletExistsNow -eq 0 ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: seed maybe wrong'/g" ${infoFile} - echo "FAIL: setup: no cl wallet created - seed maybe wrong" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "cl-wallet-seed" "cl.hsmtool.sh seed-force not created wallet" "ls /home/bitcoin/.lightning/bitcoin/hsm_secret --> 0" ${logFile} exit 17 fi @@ -390,22 +356,18 @@ if [ "${lightning}" == "cl" ]; then echo "Generate new CL wallet ..." >> ${logFile} # generate new wallet - source <(sudo /home/admin/config.scripts/cl.hsmtool.sh new-force mainnet) + source <(/home/admin/config.scripts/cl.hsmtool.sh new-force mainnet) # check if got new seedwords if [ "${seedwords}" == "" ] || [ "${seedwords6x4}" == "" ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: no cl seedwords'/g" ${infoFile} - echo "FAIL: setup: no cl seedwords" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "cl-wallet-new-noseeds" "cl.hsmtool.sh new-force did not returned seedwords" "/home/admin/config.scripts/cl.hsmtool.sh new-force mainnet --> seedwords=''" ${logFile} exit 18 fi # check if wallet really got created walletExistsNow=$(sudo ls /home/bitcoin/.lightning/bitcoin/hsm_secret 2>/dev/null | grep -c "hsm_secret") if [ $walletExistsNow -eq 0 ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='setup: no cl wallet created'/g" ${infoFile} - echo "FAIL: setup: no cl wallet created" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.setup.sh "cl-wallet-new-nowallet" "cl.hsmtool.sh new-force did not created wallet" "/home/bitcoin/.lightning/bitcoin/hsm_secret --> missing" ${logFile} exit 19 fi @@ -425,6 +387,6 @@ fi echo "stopping bitcoind for the rest provision again (will start on next boot)" >> ${logFile} systemctl stop bitcoind >> ${logFile} -sudo sed -i "s/^message=.*/message='Provision Setup Finish'/g" ${infoFile} +/home/admin/_cache.sh set message "Provision Setup Finish" echo "END Setup" >> ${logFile} exit 0 \ No newline at end of file diff --git a/home.admin/_provision.update.sh b/home.admin/_provision.update.sh index 7aa9effd..6de22caf 100755 --- a/home.admin/_provision.update.sh +++ b/home.admin/_provision.update.sh @@ -1,5 +1,11 @@ #!/bin/bash +# check if started with sudo +if [ "$EUID" -ne 0 ]; then + echo "error='run as root'" + exit 1 +fi + # LOGFILE - store debug logs of bootstrap logFile="/home/admin/raspiblitz.provision-update.log" @@ -18,7 +24,7 @@ echo "" > ${logFile} echo "###################################" >> ${logFile} echo "# _provision.update.sh" >> ${logFile} echo "###################################" >> ${logFile} -sudo sed -i "s/^message=.*/message='Running Data Update'/g" ${infoFile} +/home/admin/_cache.sh set message "Running Data Update" # HDD BTRFS RAID REPAIR IF NEEDED source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) @@ -40,15 +46,13 @@ source ${configFile} # check if config files contains basic: hostname if [ ${#hostname} -eq 0 ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='config: missing hostname'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: missing hostname in (${configFile})!" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.update.sh "missing-hostname" "${setupFile} or ${configFile} contains no hostname" "" ${logFile} exit 1 fi -# check if config files contain lightning (lnd is default) -if [ "${lightning}" == "" ]; then +# check if config files contain lightning (lnd is default) introduced in v1.7.1 +entryExists=$(cat ${configFile} | grep -c "^lightning=") +if [ "${entryExists}" != "1" ]; then lightning="lnd" echo "lightning=${lightning}" >> ${configFile} fi @@ -58,10 +62,7 @@ source /home/admin/_version.info # check if code version was loaded if [ ${#codeVersion} -eq 0 ]; then - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='missing /home/admin/_version.info'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: no code version (/home/admin/_version.info) found!" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision.update.sh "missing-version" "missing /home/admin/_version.info" "" ${logFile} exit 1 fi @@ -143,7 +144,7 @@ if [ "${raspiBlitzVersion}" != "${codeVersion}" ]; then echo "detected version change ... starting migration script" >> ${logFile} # nothing specific here yet echo "OK Done - Updating version in config" - sudo sed -i "s/^raspiBlitzVersion=.*/raspiBlitzVersion='${codeVersion}'/g" ${configFile} + /home/admin/config.scripts/blitz.conf.sh set raspiBlitzVersion "${codeVersion}" else echo "OK - version of config data is up to date" >> ${logFile} fi @@ -151,26 +152,25 @@ fi # start network service echo "" echo "*** Start ${network} (UPDATE) ***" >> ${logFile} -sudo sed -i "s/^message=.*/message='Blockchain Testrun'/g" ${infoFile} +/home/admin/_cache.sh set message "Blockchain Testrun" echo "- This can take a while .." >> ${logFile} -sudo chown -R bitcoin:bitcoin /mnt/hdd/${network} >>${logFile} 2>&1 -sudo cp /home/admin/assets/${network}d.service /etc/systemd/system/${network}d.service -sudo systemctl daemon-reload >> ${logFile} -sudo systemctl enable ${network}d.service >> ${logFile} -sudo systemctl start ${network}d.service >> ${logFile} +chown -R bitcoin:bitcoin /mnt/hdd/${network} >>${logFile} 2>&1 +cp /home/admin/assets/${network}d.service /etc/systemd/system/${network}d.service +systemctl daemon-reload >> ${logFile} +systemctl enable ${network}d.service >> ${logFile} +systemctl start ${network}d.service >> ${logFile} # INSTALL LND on Upadte/Recovery -if [ "${lightning}" == "lnd" ]; then +if [ "${lightning}" == "lnd" ] || [ "${lnd}" == "on" ]; then # prepare lnd service - sudo cp /home/admin/assets/lnd.service /etc/systemd/system/lnd.service >> ${logFile} 2>&1 + cp /home/admin/assets/lnd.service /etc/systemd/system/lnd.service >> ${logFile} 2>&1 # convert old keysend by lndExtraParameter to raspiblitz.conf setting (will be enforced by lnd.check.sh prestart) since 1.7.1 if [ "${lndExtraParameter}" == "--accept-keysend" ]; then echo "# MIGRATION KEYSEND from lndExtraParameter --> raspiblitz.conf" >> ${logFile} - sudo sed -i '/lndKeysend=.*/d' /mnt/hdd/raspiblitz.conf - echo "lndKeysend=on" >> /mnt/hdd/raspiblitz.conf - sudo sed -i "/^lndExtraParameter=/d" /mnt/hdd/raspiblitz.conf 2>/dev/null + /home/admin/config.scripts/blitz.conf.sh set lndKeysend "on" + /home/admin/config.scripts/blitz.conf.sh delete lndExtraParameter fi # if old lnd.conf exists ... @@ -178,61 +178,61 @@ if [ "${lightning}" == "lnd" ]; then if [ ${configExists} -eq 1 ]; then # make sure correct file permisions are set - sudo chown bitcoin:bitcoin /mnt/hdd/lnd/lnd.conf - sudo chmod 664 /mnt/hdd/lnd/lnd.conf + chown bitcoin:bitcoin /mnt/hdd/lnd/lnd.conf + chmod 664 /mnt/hdd/lnd/lnd.conf # make sure additional values are added to [Application Options] since v1.7 echo "- lnd.conf --> checking additional [Application Options] since v1.7" >> ${logFile} - applicationOptionsLineNumber=$(sudo grep -n "\[Application Options\]" /mnt/hdd/lnd/lnd.conf | cut -d ":" -f1) + applicationOptionsLineNumber=$(grep -n "\[Application Options\]" /mnt/hdd/lnd/lnd.conf | cut -d ":" -f1) if [ "${applicationOptionsLineNumber}" != "" ]; then applicationOptionsLineNumber="$(($applicationOptionsLineNumber+1))" # Avoid historical graph data sync # ignore-historical-gossip-filters=1 - configParamExists=$(sudo grep -c "^ignore-historical-gossip-filters=" /mnt/hdd/lnd/lnd.conf) + configParamExists=$(grep -c "^ignore-historical-gossip-filters=" /mnt/hdd/lnd/lnd.conf) if [ "${configParamExists}" == "0" ]; then echo " - ADDING 'ignore-historical-gossip-filters'" >> ${logFile} - sudo sed -i "${applicationOptionsLineNumber}iignore-historical-gossip-filters=1" /mnt/hdd/lnd/lnd.conf + sed -i "${applicationOptionsLineNumber}iignore-historical-gossip-filters=1" /mnt/hdd/lnd/lnd.conf else echo " - OK 'ignore-historical-gossip-filters' exists (${configParamExists})" >> ${logFile} fi # Avoid slow startup time # sync-freelist=1 - configParamExists=$(sudo grep -c "^sync-freelist=" /mnt/hdd/lnd/lnd.conf) + configParamExists=$(grep -c "^sync-freelist=" /mnt/hdd/lnd/lnd.conf) if [ "${configParamExists}" == "0" ]; then echo " - ADDING 'sync-freelist'" >> ${logFile} - sudo sed -i "${applicationOptionsLineNumber}isync-freelist=1" /mnt/hdd/lnd/lnd.conf + sed -i "${applicationOptionsLineNumber}isync-freelist=1" /mnt/hdd/lnd/lnd.conf else echo " - OK 'sync-freelist' exists (${configParamExists})" >> ${logFile} fi # Avoid high startup overhead # stagger-initial-reconnect=1 - configParamExists=$(sudo grep -c "^stagger-initial-reconnect=" /mnt/hdd/lnd/lnd.conf) + configParamExists=$(grep -c "^stagger-initial-reconnect=" /mnt/hdd/lnd/lnd.conf) if [ "${configParamExists}" == "0" ]; then echo " - ADDING 'stagger-initial-reconnect'" >> ${logFile} - sudo sed -i "${applicationOptionsLineNumber}istagger-initial-reconnect=1" /mnt/hdd/lnd/lnd.conf + sed -i "${applicationOptionsLineNumber}istagger-initial-reconnect=1" /mnt/hdd/lnd/lnd.conf else echo " - OK 'stagger-initial-reconnect' exists (${configParamExists})" >> ${logFile} fi # Delete and recreate RPC TLS certificate when details change or cert expires # tlsautorefresh=1 - configParamExists=$(sudo grep -c "^tlsautorefresh=" /mnt/hdd/lnd/lnd.conf) + configParamExists=$(grep -c "^tlsautorefresh=" /mnt/hdd/lnd/lnd.conf) if [ "${configParamExists}" == "0" ]; then echo " - ADDING 'tlsautorefresh'" >> ${logFile} - sudo sed -i "${applicationOptionsLineNumber}itlsautorefresh=1" /mnt/hdd/lnd/lnd.conf + sed -i "${applicationOptionsLineNumber}itlsautorefresh=1" /mnt/hdd/lnd/lnd.conf else echo " - OK 'tlsautorefresh' exists (${configParamExists})" >> ${logFile} fi # Do not include IPs in the RPC TLS certificate # tlsdisableautofill=1 - configParamExists=$(sudo grep -c "^tlsdisableautofill=" /mnt/hdd/lnd/lnd.conf) + configParamExists=$(grep -c "^tlsdisableautofill=" /mnt/hdd/lnd/lnd.conf) if [ "${configParamExists}" == "0" ]; then echo " - ADDING 'tlsdisableautofill'" >> ${logFile} - sudo sed -i "${applicationOptionsLineNumber}itlsdisableautofill=1" /mnt/hdd/lnd/lnd.conf + sed -i "${applicationOptionsLineNumber}itlsdisableautofill=1" /mnt/hdd/lnd/lnd.conf else echo " - OK 'tlsdisableautofill' exists (${configParamExists})" >> ${logFile} fi @@ -246,29 +246,19 @@ if [ "${lightning}" == "lnd" ]; then # start LND service echo "Starting LND Service ..." >> ${logFile} - sudo systemctl enable lnd >> ${logFile} - sudo systemctl start lnd >> ${logFile} + systemctl enable lnd >> ${logFile} + systemctl start lnd >> ${logFile} -elif [ "${lightning}" == "cl" ]; then +fi + +if [ "${lightning}" == "cl" ] || [ "${cl}" == "on" ]; then echo "Install C-lightning on update" >> ${logFile} - sudo sed -i "s/^message=.*/message='C-Lightning Install'/g" ${infoFile} - sudo /home/admin/config.scripts/cl.install.sh on mainnet >> ${logFile} - sudo sed -i "s/^message=.*/message='C-Lightning Setup'/g" ${infoFile} + /home/admin/_cache.sh set message "C-Lightning Install" + /home/admin/config.scripts/cl.install.sh on mainnet >> ${logFile} + /home/admin/_cache.sh set message "C-Lightning Setup" -elif [ "${lightning}" == "none" ]; then - - echo "No Lightning" >> ${logFile} - -else - - sed -i "s/^state=.*/state=error/g" ${infoFile} - sed -i "s/^message=.*/message='unknown lightning (${lightning})'/g" ${infoFile} - echo "FAIL see ${logFile}" - echo "FAIL: unknown lightning (${lightning}) in (${configFile})!" >> ${logFile} - exit 1 - -fi +fi echo "END Migration/Init" >> ${logFile} diff --git a/home.admin/_provision_.sh b/home.admin/_provision_.sh index 3256dfd3..3e7eef9d 100755 --- a/home.admin/_provision_.sh +++ b/home.admin/_provision_.sh @@ -1,5 +1,11 @@ #!/bin/bash +# check if started with sudo +if [ "$EUID" -ne 0 ]; then + echo "error='run as root'" + exit 1 +fi + # This script gets called from a fresh SD card # starting up that has an config file on HDD # from old RaspiBlitz or manufacturer to @@ -10,7 +16,6 @@ logFile="/home/admin/raspiblitz.log" # INFOFILE - state data from bootstrap infoFile="/home/admin/raspiblitz.info" -infoFileDisplayClass="${displayClass}" # CONFIGFILE - configuration of RaspiBlitz configFile="/mnt/hdd/raspiblitz.conf" @@ -25,78 +30,24 @@ echo "" >> ${logFile} echo "###################################" >> ${logFile} echo "# _provision_.sh" >> ${logFile} echo "###################################" >> ${logFile} -sudo sed -i "s/^message=.*/message='Provisioning from Config'/g" ${infoFile} +/home/admin/_cache.sh set message "Provisioning from Config" # check if there is a config file configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf') if [ ${configExists} -eq 0 ]; then - echo "FAIL: no config file (${configFile}) found to run provision!" >> ${logFile} + /home/admin/config.scripts/blitz.error.sh _provision_.sh "missing-config" "no config file (${configFile}) found to run provision" "" ${logFile} exit 1 fi # import config values source ${configFile} -########################## -# DISPLAY SETTINGS -########################## - -# check if the raspiblitz config has a different display mode than the build image -echo "### DISPLAY SETTINGS ###" >> ${logFile} - -# OLD: when nothing is set in raspiblitz.conf (<1.7) -existsDisplayClass=$(sudo cat ${configFile} | grep -c "displayClass=") -if [ "${existsDisplayClass}" == "0" ]; then - displayClass="lcd" -fi - -# OLD: lcd2hdmi (deprecated) -if [ "${lcd2hdmi}" == "on" ]; then - echo "Convert lcd2hdmi=on to displayClass='hdmi'" >> ${logFile} - sudo sed -i "s/^lcd2hdmi=.*//g" ${configFile} - echo "displayClass=hdmi" >> ${configFile} - displayClass="hdmi" -elif [ "${lcd2hdmi}" != "" ]; then - echo "Remove old lcd2hdmi pramater from config" >> ${logFile} - sudo sed -i "s/^lcd2hdmi=.*//g" ${configFile} - displayClass="lcd" -fi - -# OLD: headless (deprecated) -if [ "${headless}" == "on" ]; then - echo "Convert headless=on to displayClass='headless'" >> ${logFile} - sudo sed -i "s/^headless=.*//g" ${configFile} - echo "displayClass=headless" >> ${configFile} - displayClass="headless" -elif [ "${headless}" != "" ]; then - echo "Remove old headless parameter from config" >> ${logFile} - sudo sed -i "s/^headless=.*//g" ${configFile} - displayClass="lcd" -fi - -# NEW: decide by displayClass -echo "raspiblitz.info(${infoFileDisplayClass}) raspiblitz.conf(${displayClass})" >> ${logFile} -if [ "${infoFileDisplayClass}" != "" ] && [ "${displayClass}" != "" ]; then - if [ "${infoFileDisplayClass}" != "${displayClass}" ]; then - echo "Need to update displayClass from (${infoFileDisplayClass}) to (${displayClass})'" >> ${logFile} - sudo /home/admin/config.scripts/blitz.display.sh set-display ${displayClass} >> ${logFile} - echo "going into reboot" >> ${logFile} - sudo cp ${logFile} ${logFile}.display.recover - sudo shutdown -r now - exit 0 - else - echo "Display Setting is correct ... no need for change" >> ${logFile} - fi -else - echo "WARN values in raspiblitz info and/or conf file seem broken" >> ${logFile} -fi - ########################## # BASIC SYSTEM SETTINGS ########################## echo "### BASIC SYSTEM SETTINGS ###" >> ${logFile} -sudo sed -i "s/^message=.*/message='Setup System .'/g" ${infoFile} +/home/admin/_cache.sh set message "Setup System ." echo "# Make sure the user bitcoin is in the debian-tor group" sudo usermod -a -G debian-tor bitcoin @@ -160,7 +111,7 @@ echo "" >> ${logFile} ########################## # finish setup (SWAP, Benus, Firewall, Update, ..) -sudo sed -i "s/^message=.*/message='Setup System ..'/g" ${infoFile} +/home/admin/_cache.sh set message "Setup System .." # add bonus scripts (auto install deactivated to reduce third party repos) mkdir /home/admin/tmpScriptDL @@ -231,7 +182,7 @@ sudo sed -i "s/^setupStep=.*/setupStep=100/g" /home/admin/raspiblitz.info ########################## # PROVISIONING SERVICES ########################## -sudo sed -i "s/^message=.*/message='Installing Services'/g" ${infoFile} +/home/admin/_cache.sh set message "Installing Services" echo "### RUNNING PROVISIONING SERVICES ###" >> ${logFile} @@ -241,7 +192,7 @@ echo "Provisioning BLITZ WEB SERVICE - run config script" >> ${logFile} # BITCOIN INTERIMS UPDATE if [ ${#bitcoinInterimsUpdate} -gt 0 ]; then - sudo sed -i "s/^message=.*/message='Provisioning Bitcoin Core update'/g" ${infoFile} + /home/admin/_cache.sh set message "Provisioning Bitcoin Core update" if [ "${bitcoinInterimsUpdate}" == "reckless" ]; then # recklessly update Bitcoin Core to latest release on GitHub echo "Provisioning Bitcoin Core reckless interims update" >> ${logFile} @@ -250,7 +201,7 @@ if [ ${#bitcoinInterimsUpdate} -gt 0 ]; then # when installing the same sd image - this will re-trigger the secure interims update # if this a update with a newer RaspiBlitz version .. interims update will be ignored # because standard Bitcoin Core version is most more up to date - echo "Provisioning BItcoin Core tested interims update" >> ${logFile} + echo "Provisioning Bitcoin Core tested interims update" >> ${logFile} sudo /home/admin/config.scripts/bitcoin.update.sh tested ${bitcoinInterimsUpdate} >> ${logFile} fi else @@ -259,7 +210,7 @@ fi # LND INTERIMS UPDATE if [ ${#lndInterimsUpdate} -gt 0 ]; then - sudo sed -i "s/^message=.*/message='Provisioning LND update'/g" ${infoFile} + /home/admin/_cache.sh set message "Provisioning LND update" if [ "${lndInterimsUpdate}" == "reckless" ]; then # recklessly update LND to latest release on GitHub (just for test & dev nodes) echo "Provisioning LND reckless interims update" >> ${logFile} @@ -277,7 +228,7 @@ fi # CL INTERIMS UPDATE if [ ${#clInterimsUpdate} -gt 0 ]; then - sudo sed -i "s/^message=.*/message='Provisioning CL update'/g" ${infoFile} + /home/admin/_cache.sh set message "Provisioning CL update" if [ "${clInterimsUpdate}" == "reckless" ]; then # recklessly update CL to latest release on GitHub (just for test & dev nodes) echo "Provisioning CL reckless interims update" >> ${logFile} @@ -364,16 +315,16 @@ fi # TOR if [ "${runBehindTor}" == "on" ]; then echo "Provisioning TOR - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Tor (takes time)'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Tor (takes time)" sudo /home/admin/config.scripts/internet.tor.sh on >> ${logFile} 2>&1 else - echo "Provisioning TOR - keep default" >> ${logFile} + echo "Provisioning Tor - keep default" >> ${logFile} fi # AUTO PILOT if [ "${autoPilot}" = "on" ]; then echo "Provisioning AUTO PILOT - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup AutoPilot'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup AutoPilot" sudo /home/admin/config.scripts/lnd.autopilot.sh on >> ${logFile} 2>&1 else echo "Provisioning AUTO PILOT - keep default" >> ${logFile} @@ -382,7 +333,7 @@ fi # NETWORK UPNP if [ "${networkUPnP}" = "on" ]; then echo "Provisioning NETWORK UPnP - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup UPnP'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup UPnP" sudo /home/admin/config.scripts/network.upnp.sh on >> ${logFile} 2>&1 else echo "Provisioning NETWORK UPnP - keep default" >> ${logFile} @@ -391,7 +342,7 @@ fi # LND AUTO NAT DISCOVERY if [ "${autoNatDiscovery}" = "on" ]; then echo "Provisioning LND AUTO NAT DISCOVERY - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup AutoNAT'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup AutoNAT" sudo /home/admin/config.scripts/lnd.autonat.sh on >> ${logFile} 2>&1 else echo "Provisioning AUTO NAT DISCOVERY - keep default" >> ${logFile} @@ -400,7 +351,7 @@ fi # DYNAMIC DOMAIN if [ "${#dynDomain}" -gt 0 ]; then echo "Provisioning DYNAMIC DOMAIN - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup DynamicDomain'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup DynamicDomain" sudo /home/admin/config.scripts/internet.dyndomain.sh on ${dynDomain} ${dynUpdateUrl} >> ${logFile} 2>&1 else echo "Provisioning DYNAMIC DOMAIN - keep default" >> ${logFile} @@ -409,7 +360,7 @@ fi # RTL (LND) if [ "${rtlWebinterface}" = "on" ]; then echo "Provisioning RTL LND - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup RTL (takes time)'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup RTL LND (takes time)" sudo -u admin /home/admin/config.scripts/bonus.rtl.sh on lnd mainnet >> ${logFile} 2>&1 else echo "Provisioning RTL LND - keep default" >> ${logFile} @@ -418,7 +369,7 @@ fi # RTL (CL) if [ "${crtlWebinterface}" = "on" ]; then echo "Provisioning RTL CL - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup RTL (takes time)'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup RTL CL (takes time)" sudo -u admin /home/admin/config.scripts/bonus.rtl.sh on cl mainnet >> ${logFile} 2>&1 else echo "Provisioning RTL CL - keep default" >> ${logFile} @@ -427,7 +378,7 @@ fi # SPARKO if [ "${sparko}" = "on" ]; then echo "Provisioning Sparko - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup SPARKO'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup SPARKO" sudo -u admin /home/admin/config.scripts/cl-plugin.sparko.sh on mainnet >> ${logFile} 2>&1 else echo "Provisioning Sparko - keep default" >> ${logFile} @@ -436,7 +387,7 @@ fi # clHTTPplugin if [ "${clHTTPplugin}" = "on" ]; then echo "Provisioning clHTTPplugin - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup clHTTPplugin'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup clHTTPplugin" sudo -u admin /home/admin/config.scripts/cl-plugin.http.sh on >> ${logFile} 2>&1 else echo "Provisioning clHTTPplugin - keep default" >> ${logFile} @@ -445,7 +396,7 @@ fi # SPARK if [ "${spark}" = "on" ]; then echo "Provisioning Spark Wallet - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup SPARK WALLET'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup SPARK WALLET" sudo -u admin /home/admin/config.scripts/cl.spark.sh on mainnet >> ${logFile} 2>&1 else echo "Provisioning Spark Wallet - keep default" >> ${logFile} @@ -454,7 +405,7 @@ fi #LOOP - install only if LiT won't be installed if [ "${loop}" = "on" ] && [ "${lit}" != "on" ]; then echo "Provisioning Lightning Loop - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Lightning Loop'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Lightning Loop" sudo -u admin /home/admin/config.scripts/bonus.loop.sh on >> ${logFile} 2>&1 else echo "Provisioning Lightning Loop - keep default" >> ${logFile} @@ -463,7 +414,7 @@ fi #BTC RPC EXPLORER if [ "${BTCRPCexplorer}" = "on" ]; then echo "Provisioning BTCRPCexplorer - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup BTCRPCexplorer (takes time)'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup BTCRPCexplorer (takes time)" sudo -u admin /home/admin/config.scripts/bonus.btc-rpc-explorer.sh on >> ${logFile} 2>&1 else echo "Provisioning BTCRPCexplorer - keep default" >> ${logFile} @@ -472,19 +423,19 @@ fi #ELECTRS if [ "${ElectRS}" = "on" ]; then echo "Provisioning ElectRS - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup ElectRS (takes time)'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup ElectRS (takes time)" sudo -u admin /home/admin/config.scripts/bonus.electrs.sh on >> ${logFile} 2>&1 else echo "Provisioning ElectRS - keep default" >> ${logFile} fi -# BTCPAYSERVER +# BTCPAYSERVER if [ "${BTCPayServer}" = "on" ]; then echo "Provisioning BTCPAYSERVER on TOR - running setup" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup BTCPay (takes time)'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup BTCPay (takes time)" sudo -u admin /home/admin/config.scripts/bonus.btcpayserver.sh on >> ${logFile} 2>&1 - + else echo "Provisioning BTCPayServer - keep default" >> ${logFile} fi @@ -493,7 +444,7 @@ fi # LNDMANAGE #if [ "${lndmanage}" = "on" ]; then # echo "Provisioning lndmanage - run config script" >> ${logFile} -# sudo sed -i "s/^message=.*/message='Setup lndmanage '/g" ${infoFile} +# /home/admin/_cache.sh set message "Setup lndmanage" # sudo -u admin /home/admin/config.scripts/bonus.lndmanage.sh on >> ${logFile} 2>&1 #else # echo "Provisioning lndmanage - not active" >> ${logFile} @@ -526,6 +477,7 @@ fi # CHANTOOLS if [ "${chantools}" == "on" ]; then echo "Provisioning chantools - run config script" >> ${logFile} + /home/admin/_cache.sh set message "Setup Chantools" sudo /home/admin/config.scripts/bonus.chantools.sh on >> ${logFile} 2>&1 else echo "Provisioning chantools - keep default" >> ${logFile} @@ -534,7 +486,7 @@ fi # SSH TUNNEL if [ "${#sshtunnel}" -gt 0 ]; then echo "Provisioning SSH Tunnel - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup SSH Tunnel'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup SSH Tunnel" sudo /home/admin/config.scripts/internet.sshtunnel.py restore ${sshtunnel} >> ${logFile} 2>&1 else echo "Provisioning SSH Tunnel - not active" >> ${logFile} @@ -543,7 +495,7 @@ fi # ZEROTIER if [ "${#zerotier}" -gt 0 ] && [ "${zerotier}" != "off" ]; then echo "Provisioning ZeroTier - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup ZeroTier'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup ZeroTier" sudo /home/admin/config.scripts/bonus.zerotier.sh on ${zerotier} >> ${logFile} 2>&1 else echo "Provisioning ZeroTier - not active" >> ${logFile} @@ -556,7 +508,7 @@ if [ ${#lcdrotate} -eq 0 ]; then fi if [ "${lcdrotate}" == "0" ]; then echo "Provisioning LCD rotate - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='LCD Rotate'/g" ${infoFile} + /home/admin/_cache.sh set message "LCD Rotate" sudo /home/admin/config.scripts/blitz.display.sh rotate ${lcdrotate} >> ${logFile} 2>&1 else echo "Provisioning LCD rotate - not needed, keep default rotate on" >> ${logFile} @@ -565,7 +517,7 @@ fi # TOUCHSCREEN if [ "${#touchscreen}" -gt 0 ]; then echo "Provisioning Touchscreen - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Touchscreen'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Touchscreen" sudo /home/admin/config.scripts/blitz.touchscreen.sh ${touchscreen} >> ${logFile} 2>&1 else echo "Provisioning Touchscreen - not active" >> ${logFile} @@ -574,7 +526,7 @@ fi # UPS if [ "${#ups}" -gt 0 ]; then echo "Provisioning UPS - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup UPS'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup UPS" sudo /home/admin/config.scripts/blitz.ups.sh on ${ups} >> ${logFile} 2>&1 else echo "Provisioning UPS - not active" >> ${logFile} @@ -583,7 +535,7 @@ fi # LNbits if [ "${LNBits}" = "on" ]; then echo "Provisioning LNbits - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup LNbits '/g" ${infoFile} + /home/admin/_cache.sh set message "Setup LNbits" sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh on >> ${logFile} 2>&1 else echo "Provisioning LNbits - keep default" >> ${logFile} @@ -592,7 +544,7 @@ fi # JoinMarket if [ "${joinmarket}" = "on" ]; then echo "Provisioning JoinMarket - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup JoinMarket'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup JoinMarket" sudo /home/admin/config.scripts/bonus.joinmarket.sh on >> ${logFile} 2>&1 else echo "Provisioning JoinMarket - keep default" >> ${logFile} @@ -601,7 +553,7 @@ fi # Specter if [ "${specter}" = "on" ]; then echo "Provisioning Specter - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Specter'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Specter" sudo -u admin /home/admin/config.scripts/bonus.specter.sh on >> ${logFile} 2>&1 else echo "Provisioning Specter - keep default" >> ${logFile} @@ -610,7 +562,7 @@ fi # Faraday if [ "${faraday}" = "on" ]; then echo "Provisioning Faraday - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Faraday'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Faraday" sudo -u admin /home/admin/config.scripts/bonus.faraday.sh on >> ${logFile} 2>&1 else echo "Provisioning Faraday - keep default" >> ${logFile} @@ -619,7 +571,7 @@ fi # BOS if [ "${bos}" = "on" ]; then echo "Provisioning Balance of Satoshis - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Balance of Satoshis'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Balance of Satoshis" sudo -u admin /home/admin/config.scripts/bonus.bos.sh on >> ${logFile} 2>&1 else echo "Provisioning Balance of Satoshis - keep default" >> ${logFile} @@ -628,7 +580,7 @@ fi # thunderhub if [ "${thunderhub}" = "on" ]; then echo "Provisioning ThunderHub - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup ThunderHub'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup ThunderHub" sudo -u admin /home/admin/config.scripts/bonus.thunderhub.sh on >> ${logFile} 2>&1 else echo "Provisioning ThunderHub - keep default" >> ${logFile} @@ -637,7 +589,7 @@ fi # mempool space if [ "${mempoolExplorer}" = "on" ]; then echo "Provisioning MempoolSpace - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Mempool Space'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Mempool Space" sudo -u admin /home/admin/config.scripts/bonus.mempool.sh on >> ${logFile} 2>&1 else echo "Provisioning Mempool Explorer - keep default" >> ${logFile} @@ -646,7 +598,7 @@ fi # letsencrypt if [ "${letsencrypt}" = "on" ]; then echo "Provisioning letsencrypt - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup letsencrypt'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup letsencrypt" sudo -u admin /home/admin/config.scripts/bonus.letsencrypt.sh on >> ${logFile} 2>&1 else echo "Provisioning letsencrypt - keep default" >> ${logFile} @@ -655,7 +607,7 @@ fi # kindle-display if [ "${kindleDisplay}" = "on" ]; then echo "Provisioning kindle-display - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup kindle-display'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup kindle-display" sudo -u admin /home/admin/config.scripts/bonus.kindle-display.sh on >> ${logFile} 2>&1 else echo "Provisioning kindle-display - keep default" >> ${logFile} @@ -664,7 +616,7 @@ fi # pyblock if [ "${pyblock}" = "on" ]; then echo "Provisioning pyblock - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup pyblock'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup pyblock" sudo -u admin /home/admin/config.scripts/bonus.pyblock.sh on >> ${logFile} 2>&1 else echo "Provisioning pyblock - keep default" >> ${logFile} @@ -673,7 +625,7 @@ fi # stacking-sats-kraken if [ "${stackingSatsKraken}" = "on" ]; then echo "Provisioning Stacking Sats Kraken - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Stacking Sats Kraken'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Stacking Sats Kraken" sudo -u admin /home/admin/config.scripts/bonus.stacking-sats-kraken.sh on >> ${logFile} 2>&1 else echo "Provisioning Stacking Sats Kraken - keep default" >> ${logFile} @@ -682,7 +634,7 @@ fi # Pool - install only if LiT won't be installed if [ "${pool}" = "on" ] && [ "${lit}" != "on" ]; then echo "Provisioning Pool - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Pool'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Pool" sudo -u admin /home/admin/config.scripts/bonus.pool.sh on >> ${logFile} 2>&1 else echo "Provisioning Pool - keep default" >> ${logFile} @@ -691,7 +643,7 @@ fi # lit (make sure to be installed after RTL) if [ "${lit}" = "on" ]; then echo "Provisioning LIT - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup LIT'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup LIT" sudo -u admin /home/admin/config.scripts/bonus.lit.sh on >> ${logFile} 2>&1 else echo "Provisioning LIT - keep default" >> ${logFile} @@ -700,7 +652,7 @@ fi # sphinxrelay if [ "${sphinxrelay}" = "on" ]; then echo "Sphinx-Relay - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup Sphinx-Relay'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup Sphinx-Relay" sudo -u admin /home/admin/config.scripts/bonus.sphinxrelay.sh on >> ${logFile} 2>&1 else echo "Sphinx-Relay - keep default" >> ${logFile} @@ -709,7 +661,7 @@ fi # circuitbreaker if [ "${circuitbreaker}" = "on" ]; then echo "Provisioning CircuitBreaker - run config script" >> ${logFile} - sudo sed -i "s/^message=.*/message='Setup CircuitBreaker'/g" ${infoFile} + /home/admin/_cache.sh set message "Setup CircuitBreaker" sudo -u admin /home/admin/config.scripts/bonus.circuitbreaker.sh on >> ${logFile} 2>&1 else echo "Provisioning CircuitBreaker - keep default" >> ${logFile} @@ -719,6 +671,7 @@ fi customInstallAvailable=$(sudo ls /mnt/hdd/app-data/custom-installs.sh 2>/dev/null | grep -c "custom-installs.sh") if [ ${customInstallAvailable} -gt 0 ]; then echo "Running the custom install script .." >> ${logFile} + /home/admin/_cache.sh set message "Running Custom Install Script" # copy script over to admin (in case HDD is not allowing exec) sudo cp -av /mnt/hdd/app-data/custom-installs.sh /home/admin/custom-installs.sh >> ${logFile} # make sure script is executable @@ -760,7 +713,7 @@ if [ ${confExists} -eq 0 ]; then fi # signal setup done -sudo sed -i "s/^message=.*/message='Setup Done'/g" ${infoFile} +/home/admin/_cache.sh set message "Setup Done" # set the local network hostname (just if set in config - will not be set anymore by default in newer version) # have at the end - see https://github.com/rootzoll/raspiblitz/issues/462 @@ -811,7 +764,7 @@ if [ "${lightning}" == "lnd" ];then oldPasswordC=$(sudo cat /mnt/hdd/passwordc.flag) if ! pip list | grep grpc; then sudo -H python3 -m pip install grpcio==1.38.1; fi sudo /home/admin/config.scripts/lnd.initwallet.py change-password mainnet "${oldPasswordC}" "${passwordC}" >> ${logFile} - sudo shred -u /mnt/hdd/passwordc.flag + sudo shred -u /mnt/hdd/passwordc.flag else echo "No /mnt/hdd/passwordc.flag" >> ${logFile} fi diff --git a/home.admin/_tmux_alias.sh b/home.admin/_tmux_alias.sh index 135891fa..177f24dc 100755 --- a/home.admin/_tmux_alias.sh +++ b/home.admin/_tmux_alias.sh @@ -1,10 +1,8 @@ #!/bin/bash # script for custom tmux status bar -configFile="/mnt/hdd/raspiblitz.conf" - -if [ -f "$configFile" ]; then - source ${configFile} 2>/dev/null +if [ -f "/mnt/hdd/raspiblitz.conf" ]; then + source /mnt/hdd/raspiblitz.conf 2>/dev/null echo "${hostname}" else #echo "$configFile does not exist" diff --git a/home.admin/_tmux_chain.sh b/home.admin/_tmux_chain.sh index 46280358..3cf7208d 100755 --- a/home.admin/_tmux_chain.sh +++ b/home.admin/_tmux_chain.sh @@ -1,10 +1,8 @@ #!/bin/bash # script for custom tmux status bar -configFile="/mnt/hdd/raspiblitz.conf" - -if [ -f "$configFile" ]; then - source ${configFile} 2>/dev/null +if [ -f "/mnt/hdd/raspiblitz.conf" ]; then + source /mnt/hdd/raspiblitz.conf 2>/dev/null echo " ${chain}net " else #echo "$configFile does not exist" diff --git a/home.admin/_tmux_network.sh b/home.admin/_tmux_network.sh index b0604d40..91278af2 100755 --- a/home.admin/_tmux_network.sh +++ b/home.admin/_tmux_network.sh @@ -1,12 +1,10 @@ #!/bin/bash # script for custom tmux status bar -configFile="/mnt/hdd/raspiblitz.conf" - -if [ -f "$configFile" ]; then - source ${configFile} 2>/dev/null +if [ -f "/mnt/hdd/raspiblitz.conf" ]; then + source /mnt/hdd/raspiblitz.conf 2>/dev/null echo " ${network} " else #echo "$configFile does not exist" echo " unknown " -fi +fi \ No newline at end of file diff --git a/home.admin/config.scripts/bitcoin.install.sh b/home.admin/config.scripts/bitcoin.install.sh index f402ce2d..85e7661d 100644 --- a/home.admin/config.scripts/bitcoin.install.sh +++ b/home.admin/config.scripts/bitcoin.install.sh @@ -185,48 +185,48 @@ datadir=/mnt/hdd/bitcoin fi # make sure rpcbind is correctly configured - sudo sed -i s/^rpcbind=/main.rpcbind=/g /mnt/hdd/${network}/${network}.conf - if [ $(grep -c "rpcallowip" < /mnt/hdd/${network}/${network}.conf) -gt 0 ];then - if [ $(grep -c "${bitcoinprefix}.rpcbind=" < /mnt/hdd/${network}/${network}.conf) -eq 0 ];then + sudo sed -i s/^rpcbind=/main.rpcbind=/g /mnt/hdd/bitcoin/bitcoin.conf + if [ $(grep -c "rpcallowip" < /mnt/hdd/bitcoin/bitcoin.conf) -gt 0 ];then + if [ $(grep -c "${bitcoinprefix}.rpcbind=" < /mnt/hdd/bitcoin/bitcoin.conf) -eq 0 ];then echo "\ ${bitcoinprefix}.rpcbind=127.0.0.1"|\ - sudo tee -a /mnt/hdd/${network}/${network}.conf + sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf fi fi # correct rpcport entry - sudo sed -i s/^rpcport=/main.rpcport=/g /mnt/hdd/${network}/${network}.conf - if [ $(grep -c "${bitcoinprefix}.rpcport" < /mnt/hdd/${network}/${network}.conf) -eq 0 ];then + sudo sed -i s/^rpcport=/main.rpcport=/g /mnt/hdd/bitcoin/bitcoin.conf + if [ $(grep -c "${bitcoinprefix}.rpcport" < /mnt/hdd/bitcoin/bitcoin.conf) -eq 0 ];then echo "\ ${bitcoinprefix}.rpcport=${rpcprefix}8332"|\ - sudo tee -a /mnt/hdd/${network}/${network}.conf + sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf fi # correct zmq entry - sudo sed -i s/^zmqpubraw/main.zmqpubraw/g /mnt/hdd/${network}/${network}.conf - if [ $(grep -c "${bitcoinprefix}.zmqpubrawblock" < /mnt/hdd/${network}/${network}.conf) -eq 0 ];then + sudo sed -i s/^zmqpubraw/main.zmqpubraw/g /mnt/hdd/bitcoin/bitcoin.conf + if [ $(grep -c "${bitcoinprefix}.zmqpubrawblock" < /mnt/hdd/bitcoin/bitcoin.conf) -eq 0 ];then echo "\ ${bitcoinprefix}.zmqpubrawblock=tcp://127.0.0.1:${zmqprefix}332 ${bitcoinprefix}.zmqpubrawtx=tcp://127.0.0.1:${zmqprefix}333"|\ - sudo tee -a /mnt/hdd/${network}/${network}.conf + sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf fi # addnode if [ ${bitcoinprefix} = signet ];then - if [ $(grep -c "${bitcoinprefix}.addnode" < /mnt/hdd/${network}/${network}.conf) -eq 0 ];then + if [ $(grep -c "${bitcoinprefix}.addnode" < /mnt/hdd/bitcoin/bitcoin.conf) -eq 0 ];then echo "\ signet.addnode=s7fcvn5rblem7tiquhhr7acjdhu7wsawcph7ck44uxyd6sismumemcyd.onion:38333 signet.addnode=6megrst422lxzsqvshkqkg6z2zhunywhyrhy3ltezaeyfspfyjdzr3qd.onion:38333 signet.addnode=jahtu4veqnvjldtbyxjiibdrltqiiighauai7hmvknwxhptsb4xat4qd.onion:38333 signet.addnode=f4kwoin7kk5a5kqpni7yqe25z66ckqu6bv37sqeluon24yne5rodzkqd.onion:38333 signet.addnode=nsgyo7begau4yecc46ljfecaykyzszcseapxmtu6adrfagfrrzrlngyd.onion:38333"|\ - sudo tee -a /mnt/hdd/${network}/${network}.conf + sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf fi fi removeParallelService if [ ${CHAIN} = mainnet ];then - sudo cp /home/admin/assets/${network}d.service /etc/systemd/system/${network}d.service + sudo cp /home/admin/assets/bitcoind.service /etc/systemd/system/bitcoind.service else # /etc/systemd/system/${prefix}bitcoind.service echo " @@ -281,7 +281,8 @@ alias ${prefix}bitcoinlog=\"sudo tail -n 30 -f ${bitcoinlogpath}\"\ fi sudo chown admin:admin /home/admin/_aliases - source /home/admin/raspiblitz.info + source <(/home/admin/_cache.sh get state) + if [ "${state}" == "ready" ]; then echo "# OK - the ${prefix}bitcoind.service is enabled, system is ready so starting service" sudo systemctl start ${prefix}bitcoind @@ -307,17 +308,11 @@ alias ${prefix}bitcoinlog=\"sudo tail -n 30 -f ${bitcoinlogpath}\"\ source /mnt/hdd/raspiblitz.conf -# add default value to raspi config if needed -if ! grep -Eq "^${CHAIN}=" /mnt/hdd/raspiblitz.conf; then - NEWENTRY="${CHAIN}=off" - sudo /bin/sh -c "echo '$NEWENTRY' >> /mnt/hdd/raspiblitz.conf" -fi - # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then installParallelService # setting value in raspi blitz config - sudo sed -i "s/^${CHAIN}=.*/${CHAIN}=on/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set ${CHAIN} "on" exit 0 fi @@ -326,7 +321,7 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then echo "# Uninstall Bitcoin Core instance on ${CHAIN}" removeParallelService # setting value in raspi blitz config - sudo sed -i "s/^${CHAIN}=.*/${CHAIN}=off/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set ${CHAIN} "off" exit 0 fi diff --git a/home.admin/config.scripts/bitcoin.monitor.sh b/home.admin/config.scripts/bitcoin.monitor.sh new file mode 100755 index 00000000..75068267 --- /dev/null +++ b/home.admin/config.scripts/bitcoin.monitor.sh @@ -0,0 +1,309 @@ +#!/bin/bash + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "monitor and troubleshot the bitcoin network" + echo "bitcoin.monitor.sh [mainnet|testnet|signet] status" + echo "bitcoin.monitor.sh [mainnet|testnet|signet] info" + echo "bitcoin.monitor.sh [mainnet|testnet|signet] mempool" + echo "bitcoin.monitor.sh [mainnet|testnet|signet] network" + echo "bitcoin.monitor.sh [mainnet] peer-kickstart [ipv4|ipv6|tor|auto]" + echo "bitcoin.monitor.sh [mainnet] peer-disconnectall" + exit 1 +fi + +# check if started with sudo +if [ "$EUID" -ne 0 ]; then + echo "error='run as root'" + exit 1 +fi + +# set based on network type +if [ "$1" == "mainnet" ]; then + bitcoincli_alias="/usr/local/bin/bitcoin-cli -datadir=/home/bitcoin/.bitcoin -rpcport=8332" + service_alias="bitcoind" +elif [ "$1" == "testnet" ]; then + bitcoincli_alias="/usr/local/bin/bitcoin-cli -datadir=/home/bitcoin/.bitcoin -rpcport=18332" + service_alias="tbitcoind" +elif [ "$1" == "signet" ]; then + bitcoincli_alias="/usr/local/bin/bitcoin-cli -datadir=/home/bitcoin/.bitcoin -rpcport=38332" + service_alias="sbitcoind" +else + echo "error='not supported net'" + exit 1 +fi + +###################################################### +# STATUS +# check general status info +###################################################### + +if [ "$2" = "status" ]; then + + btc_version=$($bitcoincli_alias -version 2>/dev/null | cut -d ' ' -f6) + btc_running=$(systemctl status $service_alias 2>/dev/null | grep -c "active (running)") + btc_ready="0" + btc_online="0" + btc_error_short="" + btc_error_full="" + + if [ "${btc_running}" != "0" ]; then + btc_running="1" + + # test connection - record win & fail info + randStr=$(echo "$RANDOM") + rm /var/cache/raspiblitz/.bitcoind-${randStr}.out 2>/dev/null + rm /var/cache/raspiblitz/.bitcoind-${randStr}.error 2>/dev/null + touch /var/cache/raspiblitz/.bitcoind-${randStr}.out + touch /var/cache/raspiblitz/.bitcoind-${randStr}.error + $bitcoincli_alias getnetworkinfo 1>/var/cache/raspiblitz/.bitcoind-${randStr}.out 2>/var/cache/raspiblitz/.bitcoind-${randStr}.error + winData=$(cat /var/cache/raspiblitz/.bitcoind-${randStr}.out 2>/dev/null) + failData=$(cat /var/cache/raspiblitz/.bitcoind-${randStr}.error 2>/dev/null) + rm /var/cache/raspiblitz/.bitcoind-${randStr}.out + rm /var/cache/raspiblitz/.bitcoind-${randStr}.error + + # check for errors + if [ "${failData}" != "" ]; then + btc_ready="0" + btc_error_short=$(echo ${failData/error*:/} | sed 's/[^a-zA-Z0-9 ]//g') + btc_error_full=$(echo ${failData} | tr -d "'" | tr -d '"') + btc_ready="0" + + # check results if proof for online + else + btc_ready="1" + connections=$( echo "${winData}" | grep "connections\"" | tr -cd '[[:digit:]]') + if [ "${connections}" != "" ] && [ "${connections}" != "0" ]; then + btc_online="1" + fi + fi + + fi + + # print results + echo "btc_version='${btc_version}'" + echo "btc_running='${btc_running}'" + echo "btc_ready='${btc_ready}'" + echo "btc_online='${btc_online}'" + echo "btc_error_short='${btc_error_short}'" + echo "btc_error_full='${btc_error_full}'" + + exit 0 +fi + +###################################################### +# NETWORK +###################################################### + +if [ "$2" = "network" ]; then + + # get data + getnetworkinfo=$($bitcoincli_alias getnetworkinfo 2>/dev/null) + if [ "${getnetworkinfo}" == "" ]; then + echo "error='no data'" + exit 1 + fi + + # parse data + btc_peers=$(echo "${getnetworkinfo}" | grep "connections\"" | tr -cd '[[:digit:]]') + btc_address=$(echo ${getnetworkinfo} | jq -r '.localaddresses [0] .address') + btc_port=$(echo "${getnetworkinfo}" | jq -r '.localaddresses [0] .port') + + # print data + echo "btc_peers='${btc_peers}'" + echo "btc_address='${btc_address}'" + echo "btc_port='${btc_port}'" + exit 0 + +fi + +###################################################### +# INFO +###################################################### + +if [ "$2" = "info" ]; then + + # get data + blockchaininfo=$($bitcoincli_alias getblockchaininfo 2>/dev/null) + if [ "${blockchaininfo}" == "" ]; then + echo "error='no data'" + exit 1 + fi + + # parse data + btc_blocks_headers=$(echo "${blockchaininfo}" | jq -r '.headers') + btc_blocks_verified=$(echo "${blockchaininfo}" | jq -r '.blocks') + btc_blocks_behind=$((${btc_blocks_headers} - ${btc_blocks_verified})) + btc_sync_initialblockdownload=$(echo "${blockchaininfo}" | jq -r '.initialblockdownload' | grep -c 'true') + btc_sync_progress=$(echo "${blockchaininfo}" | jq -r '.verificationprogress') + btc_sync_percentage=$(echo ${btc_sync_progress} | awk '{printf( "%.2f%%", 100 * $1)}') + if [ "${btc_blocks_headers}" != "" ] && [ "${btc_blocks_headers}" == "${btc_blocks_verified}" ]; then + btc_sync_percentage="100.00" + fi + + # determine if synced (tolerate falling 1 block behind) + # and be sure that initial blockdownload is done + btc_synced=0 + if [ "${btc_sync_initialblockdownload}" == "0" ] && [ ${btc_blocks_behind} -lt 2 ]; then + btc_synced=1 + fi + + # print data + echo "btc_synced='${btc_synced}'" + echo "btc_blocks_headers='${btc_blocks_headers}'" + echo "btc_blocks_verified='${btc_blocks_verified}'" + echo "btc_blocks_behind='${btc_blocks_behind}'" + echo "btc_sync_progress='${btc_sync_progress}'" + echo "btc_sync_percentage='${btc_sync_percentage//[^0-9\..]/}'" + echo "btc_sync_initialblockdownload='${btc_sync_initialblockdownload}'" + exit 0 + +fi + +###################################################### +# MEMPOOL +###################################################### + +if [ "$2" = "mempool" ]; then + + # get data + mempoolinfo=$($bitcoincli_alias getmempoolinfo 2>/dev/null) + if [ "${mempoolinfo}" == "" ]; then + echo "error='no data'" + exit 1 + fi + + # parse data + btc_mempool_transactions=$(echo "${mempoolinfo}" | jq -r '.size') + + # print data + echo "btc_mempool_transactions=${btc_mempool_transactions}" + exit 0 + +fi + +################### +# PEER KICK START +################### + +if [ "$2" = "peer-kickstart" ]; then + + # check calling only for mainnet + if [ "$1" != "mainnet" ]; then + echo "error='only available for mainnet yet'" + exit 1 + fi + + # get raw node data from bitnodes.io (use Tor if available) + #if [ "${runBehindTor}" == "on" ]; then + # call over tor proxy (CAPTCHA BLOCKED) + #bitnodesRawData=$(curl --socks5-hostname 127.0.0.1:9050 -H "Accept: application/json; indent=4" https://bitnodes.io/api/v1/snapshots/latest/ 2>/dev/null) + #else + # call over clearnet + # bitnodesRawData=$(curl -H "Accept: application/json; indent=4" https://bitnodes.io/api/v1/snapshots/latest/ 2>/dev/null) + #fi + + bitnodesRawData=$(sudo -u admin cat /home/admin/fallback.nodes) + if [ ${#bitnodesRawData} -lt 100 ]; then + echo "error='no valid data from bitnodes.io'" + exit 1 + fi + + # determine which address to choose + addressFormat="$3" + # set default to auto + if [ "${addressFormat}" == "" ]; then + addressFormat="auto" + fi + # check valid value + if [ "${addressFormat}" != "ipv4" ] && [ "${addressFormat}" != "ipv6" ] && [ "${addressFormat}" != "tor" ] && [ "${addressFormat}" != "auto" ]; then + echo "error='invalid address type'" + exit 1 + fi + # if auto then determine whats running + if [ "${addressFormat}" == "auto" ]; then + source <() + if [ "$(cat /mnt/hdd/raspiblitz.conf | grep -c "^runBehindTor=on")" != "0" ]; then + addressFormat="tor" + else + source <(sudo ./config.scripts/internet.sh status global) + if [ "${ipv6}" == "off" ]; then + addressFormat="ipv4" + else + addressFormat="ipv6" + fi + fi + fi + echo "addressFormat='${addressFormat}'" + + # filter raw data for node addresses based on what kind of connection is running + if [ "${addressFormat}" == "tor" ]; then + # get Tor nodes (v2 or v3) + nodeList=$(echo "${bitnodesRawData}" | grep -o '[0-9a-z]\{16,56\}\.onion') + elif [ "${addressFormat}" == "ipv4" ]; then + # get IPv4 nodes + nodeList=$(echo "${bitnodesRawData}" | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\:[0-9]\{3,5\}') + elif [ "${addressFormat}" == "ipv6" ]; then + # get IPv6 nodes + nodeList=$(echo "${bitnodesRawData}" | grep -o '\[.\{5,45\}\]\:[0-9]\{3,5\}') + else + # invalid address + echo "error='invalid address format'" + exit 1 + fi + #echo "${nodeList}" + nodesAvailable=$(echo "${nodeList}" | wc -l) + echo "nodesAvailable=${nodesAvailable}" + if [ "${nodesAvailable}" == "0" ]; then + echo "error='no nodes available'" + exit 1 + fi + + # pick random node from list + randomLineNumber=$((1 + RANDOM % ${nodesAvailable})) + echo "randomNumber=${randomLineNumber}" + nodeAddress=$(echo "${nodeList}" | sed -n "${randomLineNumber}p") + if [ "${nodeAddress}" == "" ]; then + # if random pick fails pick first line + nodeAddress=$(echo "${nodeList}" | sed -n "1p") + fi + if [ "${nodeAddress}" == "" ]; then + echo "error='selecting node from list failed'" + exit 1 + fi + echo "newpeer='${nodeAddress}" + + # kick start node with + $bitcoincli_alias addnode "${nodeAddress}" "onetry" 1>/dev/null + echo "exitcode=$?" + + exit 0 +fi + +################### +# DISCONNECT ALL PEERS +# for testing peer kick-start +################### +if [ "$2" = "peer-disconnectall" ]; then + + # check calling only for mainnet + if [ "$1" != "mainnet" ]; then + echo "error='only available for mainnet yet'" + exit 1 + fi + + # get all peer id and disconnect them + $bitcoincli_alias getpeerinfo | grep '"addr": "' | while read line + do + peerID=$(echo $line | cut -d '"' -f4) + echo "# disconnecting peer with ID: ${peerID}" + $bitcoincli_alias disconnectnode ${peerID} + done + + echo "#### FINAL PEER INFO FROM BITCOIND" + $bitcoincli_alias getpeerinfo + exit 0 +fi + +echo "FAIL - Unknown Parameter $2" +exit 1 diff --git a/home.admin/config.scripts/bitcoin.update.sh b/home.admin/config.scripts/bitcoin.update.sh index feae8623..1a09d0c8 100755 --- a/home.admin/config.scripts/bitcoin.update.sh +++ b/home.admin/config.scripts/bitcoin.update.sh @@ -13,8 +13,6 @@ if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then exit 1 fi -source /home/admin/raspiblitz.info - # 1. parameter [info|tested|reckless] mode="$1" @@ -231,9 +229,10 @@ fi if [ "${mode}" = "tested" ]||[ "${mode}" = "reckless" ]||[ "${mode}" = "custom" ];then # install - echo "# Stopping bitcoind and lnd ..." - sudo systemctl stop lnd - sudo systemctl stop bitcoind + echo "# Stopping bitcoind ..." + sudo systemctl stop bitcoind 2>/dev/null + sudo systemctl stop tbitcoind 2>/dev/null + sudo systemctl stop sbitcoind 2>/dev/null echo echo "# Installing Bitcoin Core v${bitcoinVersion}" tar -xvf ${binaryName} @@ -245,29 +244,11 @@ if [ "${mode}" = "tested" ]||[ "${mode}" = "reckless" ]||[ "${mode}" = "custom" echo "# !!! BUILD FAILED --> Was not able to install bitcoind version(${bitcoinVersion})" exit 1 fi - echo "# flag update in raspiblitz config" - source /mnt/hdd/raspiblitz.conf - if [ ${#bitcoinInterimsUpdate} -eq 0 ]; then - echo "bitcoinInterimsUpdate='${bitcoinInterimsUpdateNew}'" >> /mnt/hdd/raspiblitz.conf - else - sudo sed -i "s/^bitcoinInterimsUpdate=.*/bitcoinInterimsUpdate='${bitcoinInterimsUpdateNew}'/g" /mnt/hdd/raspiblitz.conf - fi + + echo "# mark update in raspiblitz config" + /home/admin/config.scripts/blitz.conf.sh set bitcoinInterimsUpdate "${bitcoinInterimsUpdateNew}" echo "# OK Bitcoin Core ${bitcoinVersion} is installed" - if [ "${state}" == "ready" ]; then - echo - echo "# Starting ..." - sudo systemctl start bitcoind - sleep 10 - echo - sudo systemctl start lnd - echo "# Starting LND ..." - sleep 10 - echo - echo "# Press ENTER to proceed to unlock the LND wallet ..." - read key - sudo /home/admin/config.scripts/lnd.unlock.sh - fi exit 0 else diff --git a/home.admin/config.scripts/blitz.backupdevice.sh b/home.admin/config.scripts/blitz.backupdevice.sh index f5151b90..bfacc73a 100755 --- a/home.admin/config.scripts/blitz.backupdevice.sh +++ b/home.admin/config.scripts/blitz.backupdevice.sh @@ -169,11 +169,7 @@ THIS WILL DELETE ALL DATA ON THAT DEVICE! fi # change raspiblitz.conf - entryExists=$(cat /mnt/hdd/raspiblitz.conf | grep -c 'localBackupDeviceUUID=') - if [ ${entryExists} -eq 0 ]; then - echo "localBackupDeviceUUID='off'" >> /mnt/hdd/raspiblitz.conf - fi - sudo sed -i "s/^localBackupDeviceUUID=.*/localBackupDeviceUUID='${uuid}'/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set localBackupDeviceUUID "${uuid}" echo "activated=1" # mount device (so that no reboot is needed) @@ -188,7 +184,7 @@ THIS WILL DELETE ALL DATA ON THAT DEVICE! if [ ${userinteraction} -eq 1 ]; then if [ ${isMounted} -eq 0 ]; then - sudo sed -i "s/^localBackupDeviceUUID=.*/localBackupDeviceUUID=off/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set localBackupDeviceUUID "off" dialog --title ' Adding Backup Device ' --msgbox '\nFAIL - Not able to add device.' 7 40 else dialog --title ' Adding Backup Device ' --msgbox '\nOK - Device added for Backup.' 7 40 @@ -240,7 +236,7 @@ fi if [ "$1" = "off" ]; then echo "# BACKUP DEVICE REMOVE" - sudo sed -i "s/^localBackupDeviceUUID=.*/localBackupDeviceUUID=off/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set localBackupDeviceUUID "off" sudo umount /mnt/backup 2>/dev/null echo "# OK backup device is off" exit 0 diff --git a/home.admin/config.scripts/blitz.bootdrive.sh b/home.admin/config.scripts/blitz.bootdrive.sh index 21751028..6cad7c23 100644 --- a/home.admin/config.scripts/blitz.bootdrive.sh +++ b/home.admin/config.scripts/blitz.bootdrive.sh @@ -61,7 +61,7 @@ if [ "${action}" == "fsexpand" ]; then echo "# starting expand of file system of sd card" sudo sed -i "s/^fsexpanded=.*/fsexpanded=1/g" /home/admin/raspiblitz.info - if [ "${baseimage}" = "raspbian" ] || [ "${baseimage}" = "raspios_arm64" ]; then + if [ "${baseimage}" = "raspios_arm64" ]; then resizeRaspbian="/usr/bin/raspi-config" if [ -x ${resizeRaspbian} ]; then echo "# RUNNING EXPAND RASPBERRYPI: ${resizeRaspbian}" diff --git a/home.admin/config.scripts/blitz.cache.sh b/home.admin/config.scripts/blitz.cache.sh deleted file mode 100755 index e95471de..00000000 --- a/home.admin/config.scripts/blitz.cache.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -# command info -if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then - echo "RaspiBlitz Cache RAM disk" - echo "blitz.cache.sh [on|off]" - exit 1 -fi - -################### -# SWITCH ON -################### -if [ "$1" = "1" ] || [ "$1" = "on" ]; then - - echo "Turn ON: Cache" - - if ! grep -Eq '^tmpfs.*/var/cache/raspiblitz' /etc/fstab; then - - if grep -Eq '/var/cache/raspiblitz' /etc/fstab; then - # entry is in file but most likely just disabled -> re-enable it - sudo sed -i -E 's|^#(tmpfs.*/var/cache/raspiblitz.*)$|\1|g' /etc/fstab - else - # missing -> add - echo "" | sudo tee -a /etc/fstab >/dev/null - echo "tmpfs /var/cache/raspiblitz tmpfs nodev,nosuid,size=32M 0 0" | sudo tee -a /etc/fstab >/dev/null - fi - fi - - if ! findmnt -l /var/cache/raspiblitz >/dev/null; then - sudo mkdir -p /var/cache/raspiblitz - sudo mount /var/cache/raspiblitz - fi - -################### -# SWITCH OFF -################### -elif [ "$1" = "0" ] || [ "$1" = "off" ]; then - - echo "Turn OFF: Cache" - - if grep -Eq '/var/cache/raspiblitz' /etc/fstab; then - sudo sed -i -E 's|^(tmpfs.*/var/cache/raspiblitz.*)$|#\1|g' /etc/fstab - fi - - if findmnt -l /var/cache/raspiblitz >/dev/null; then - sudo umount /var/cache/raspiblitz - fi - -else - - echo "# FAIL: parameter not known - run with -h for help" -fi diff --git a/home.admin/config.scripts/blitz.conf.sh b/home.admin/config.scripts/blitz.conf.sh new file mode 100755 index 00000000..66bf707d --- /dev/null +++ b/home.admin/config.scripts/blitz.conf.sh @@ -0,0 +1,78 @@ +#!/usr/bin/env bash + +configFile="/mnt/hdd/raspiblitz.conf" + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then + echo "RaspiBlitz Config Edit - adds value to file & cache and creates entries if needed:" + echo "blitz.conf.sh set [key] [value]" + echo "blitz.conf.sh delete [key]" + echo "To use values use in shell scripts: source ${configFile}" + echo + exit 1 +fi + +if [ "$1" = "set" ]; then + + # get parameters + keystr=$2 + valuestr=$3 + overflow=$4 + + # check that key & value are given + if [ "${keystr}" == "" ] || [ "${valuestr}" == "" ]; then + echo "# blitz.conf.sh $@" + echo "# FAIL: missing parameter" + exit 1 + fi + + # check if input quotes are missing (there should be no 4th parameter) + if [ "${overflow}" != "" ]; then + echo "# blitz.conf.sh $@" + echo "# FAIL: possible missing quotes in value string" + exit 2 + fi + + # update config value in cache + /home/admin/_cache.sh set ${keystr} "${valuestr}" + + # check that config file exists + raspiblitzConfExists=$(ls ${configFile} 2>/dev/null | grep -c "${configFile}") + if [ ${raspiblitzConfExists} -eq 0 ]; then + echo "# blitz.conf.sh $@" + echo "# FAIL: missing config file: ${configFile}" + exit 3 + fi + + # check if key needs to be added (prepare new entry) + entryExists=$(grep -c "^${keystr}=" ${configFile}) + if [ ${entryExists} -eq 0 ]; then + echo "${keystr}=" | tee -a ${configFile} + fi + + # add valuestr quotes if not standard values + if [ "${valuestr}" != "on" ] && [ "${valuestr}" != "off" ] && [ "${valuestr}" != "1" ] && [ "${valuestr}" != "0" ]; then + valuestr="'${valuestr}'" + fi + + # set value (sed needs sudo to operate when user is not root) + sudo sed -i "s/^${keystr}=.*/${keystr}=${valuestr}/g" ${configFile} + + +elif [ "$1" = "delete" ]; then + + # get parameters + keystr=$2 + + # check that key & value are given + if [ "${keystr}" == "" ]; then + echo "# FAIL: missing parameter" + exit 1 + fi + + # delete value + sudo sed -i "/^${keystr}=/d" ${configFile} 2>/dev/null + +else + echo "# FAIL: parameter not known - run with -h for help" +fi \ No newline at end of file diff --git a/home.admin/config.scripts/blitz.datadrive.sh b/home.admin/config.scripts/blitz.datadrive.sh index d4ddf5b4..7ff01027 100755 --- a/home.admin/config.scripts/blitz.datadrive.sh +++ b/home.admin/config.scripts/blitz.datadrive.sh @@ -22,7 +22,7 @@ fi # check if started with sudo if [ "$EUID" -ne 0 ]; then - echo "error='missing sudo'" + echo "error='run as root'" exit 1 fi @@ -218,26 +218,32 @@ if [ "$1" = "status" ]; then ##################################### # Pre-Setup Investigation of DATA-PART + # make copy of raspiblitz.conf & # check for recoverable RaspiBlitz data (if config file exists) and raid - hddRaspiData=$(sudo ls -l /mnt/hdd${subVolumeDir} 2>/dev/null | grep -c raspiblitz.conf) - #isRaid=$(btrfs filesystem df /mnt/hdd 2>/dev/null | grep -c "Data, RAID1") + hddRaspiData=$(ls -l /mnt/hdd${subVolumeDir} 2>/dev/null | grep -c raspiblitz.conf) echo "hddRaspiData=${hddRaspiData}" hddRaspiVersion="" if [ ${hddRaspiData} -eq 1 ]; then + + # output version data from raspiblitz.conf source /mnt/hdd${subVolumeDir}/raspiblitz.conf - hddRaspiVersion="${raspiBlitzVersion}" - fi - echo "hddRaspiVersion='${hddRaspiVersion}'" + echo "hddRaspiVersion='${raspiBlitzVersion}'" - # check if there is a wifi configuration as backup - hddGotWifiConf=$(ls /mnt/hdd${subVolumeDir}/app-data/wpa_supplicant.conf 2>/dev/null | grep -c "wpa_supplicant.conf") - if [ ${hddGotWifiConf} -eq 1 ]; then - # make a copy to the mem cache drive (so that Wifi can be connected before setup & final HDD mount) - sudo cp /mnt/hdd${subVolumeDir}/app-data/wpa_supplicant.conf /var/cache/raspiblitz/wpa_supplicant.conf - echo "wifiBackupConfigCopy='/var/cache/raspiblitz/wpa_supplicant.conf'" - fi + # create hdd-inspect data dir on RAMDISK + mkdir /var/cache/raspiblitz/hdd-inspect + # make copy of raspiblitz.conf to RAMDISK + cp /mnt/hdd${subVolumeDir}/raspiblitz.conf /var/cache/raspiblitz/hdd-inspect/raspiblitz.conf + + # make copy of WIFI config to RAMDISK (if available) + cp /mnt/hdd${subVolumeDir}/app-data/wpa_supplicant.conf /var/cache/raspiblitz/hdd-inspect/wpa_supplicant.conf 2>/dev/null + + # make copy of SSH keys to RAMDISK (if available) + cp /mnt/hdd${subVolumeDir}/ssh /var/cache/raspiblitz/hdd-inspect/ssh 2>/dev/null + + fi + # comment this line out if case to study the contect of the data section sudo umount /mnt/hdd fi @@ -277,7 +283,11 @@ if [ "$1" = "status" ]; then # BRTS hdd_data_free1Kblocks=$(df -h -k /dev/${hdd}1 | grep "/dev/${hdd}1" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9') fi + hddDataFreeBytes=$((${hdd_data_free1Kblocks} * 1024)) + hddDataFreeGB=$((${hdd_data_free1Kblocks} / (1024 * 1024))) + echo "hddDataFreeBytes=${hddDataFreeBytes}" echo "hddDataFreeKB=${hdd_data_free1Kblocks}" + echo "hddDataFreeGB=${hddDataFreeGB}" # check if its another fullnode implementation data disk hddGotMigrationData="" @@ -372,7 +382,11 @@ if [ "$1" = "status" ]; then hddUsedInfo="${datadrive} & ${storageDrive}" fi echo "hddUsedInfo='${hddUsedInfo}'" + hddDataFreeBytes=$((${hdd_data_free1Kblocks} * 1024)) + hddDataFreeGB=$((${hdd_data_free1Kblocks} / (1024 * 1024))) + echo "hddDataFreeBytes=${hddDataFreeBytes}" echo "hddDataFreeKB=${hdd_data_free1Kblocks}" + echo "hddDataFreeGB=${hddDataFreeGB}" fi @@ -393,11 +407,12 @@ if [ "$1" = "status" ]; then hddAdapterUSAP=0 - # check if user wants to force UASP on + # check if force UASP flag is set on sd card if [ -f "/boot/uasp.force" ]; then hddAdapterUSAP=1 - echo "uaspForced=1" fi + + # or UASP is set by config file if [ $(cat /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "forceUasp=on") -eq 1 ]; then hddAdapterUSAP=1 fi @@ -411,6 +426,7 @@ if [ "$1" = "status" ]; then # SupTronics 2.5" SATA HDD Shield X825 v1.5 hddAdapterUSAP=1 fi + echo "hddAdapterUSAP=${hddAdapterUSAP}" fi diff --git a/home.admin/config.scripts/blitz.debug.sh b/home.admin/config.scripts/blitz.debug.sh index f177d31f..b5683554 100755 --- a/home.admin/config.scripts/blitz.debug.sh +++ b/home.admin/config.scripts/blitz.debug.sh @@ -7,6 +7,7 @@ source /home/admin/_version.info ## get basic info (its OK if not set yet) source /home/admin/raspiblitz.info 2>/dev/null +source <(/home/admin/_cache.sh get state setupPhase) source /mnt/hdd/raspiblitz.conf 2>/dev/null # for old nodes @@ -54,7 +55,6 @@ echo echo "*** LAST BLOCKCHAIN (MAINNET) ERROR LOGS ***" echo "sudo journalctl -u ${network}d -b --no-pager -n8" sudo journalctl -u ${network}d -b --no-pager -n8 -cat /home/admin/systemd.blockchain.log | grep "ERROR" | tail -n -2 echo echo "*** LAST BLOCKCHAIN (MAINNET) 20 INFO LOGS ***" echo "sudo tail -n 20 /mnt/hdd/${network}/debug.log" @@ -68,7 +68,6 @@ if [ "${lightning}" == "lnd" ] || [ "${lnd}" == "on" ] || [ "${lnd}" == "1" ]; t echo "*** LAST LND (MAINNET) ERROR LOGS ***" echo "sudo journalctl -u lnd -b --no-pager -n12" sudo journalctl -u lnd -b --no-pager -n12 - cat /home/admin/systemd.lightning.log | grep "ERROR" | tail -n -1 echo echo "*** LAST 30 LND (MAINNET) INFO LOGS ***" echo "sudo tail -n 30 /mnt/hdd/lnd/logs/${network}/mainnet/lnd.log" @@ -337,19 +336,22 @@ sudo /home/admin/config.scripts/internet.sh status | grep 'network_device\|local echo echo "*** HARDWARE TEST RESULTS ***" +source <(/home/admin/_cache.sh get system_count_undervoltage) showImproveInfo=0 -if [ ${#undervoltageReports} -gt 0 ]; then - echo "UndervoltageReports in Logs: ${undervoltageReports}" - if [ ${undervoltageReports} -gt 0 ]; then +if [ ${#system_count_undervoltage} -gt 0 ]; then + echo "UndervoltageReports in Logs: ${system_count_undervoltage}" + if [ ${system_count_undervoltage} -gt 0 ]; then showImproveInfo=1 fi fi echo -echo "*** SYSTEM STATUS (can take some seconds to gather) ***" -sudo /home/admin/config.scripts/blitz.statusscan.sh -echo +echo "*** SYSTEM CACHE STATUS ***" +/home/admin/_cache.sh "export" system_ +/home/admin/_cache.sh "export" ln_default | grep -v "ln_default_address" +/home/admin/_cache.sh "export" btc_default | grep -v "btc_default_address" +echo echo "*** OPTION: SHARE THIS DEBUG OUTPUT ***" echo "An easy way to share this debug output on GitHub or on a support chat" echo "use the following command and share the resulting link:" diff --git a/home.admin/config.scripts/blitz.display.sh b/home.admin/config.scripts/blitz.display.sh index d223b7c2..bfd8e4ce 100755 --- a/home.admin/config.scripts/blitz.display.sh +++ b/home.admin/config.scripts/blitz.display.sh @@ -3,19 +3,23 @@ # command info if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then echo "# make changes to the LCD screen" - echo "# blitz.display.sh rotate [on|off]" + echo echo "# blitz.display.sh image [path]" echo "# blitz.display.sh qr [datastring]" echo "# blitz.display.sh qr-console [datastring]" echo "# blitz.display.sh hide" - echo "# blitz.display.sh hdmi [on|off] ---> DEPRECATED use set-display" + echo + echo "# blitz.display.sh rotate [on|off]" echo "# blitz.display.sh test-lcd-connect" echo "# blitz.display.sh set-display [hdmi|lcd|headless]" exit 1 fi -# load config -source /home/admin/raspiblitz.info 2>/dev/null +# 1. Parameter: lcd command +command=$1 + +# its OK if its not exist yet +source /home/admin/raspiblitz.info source /mnt/hdd/raspiblitz.conf 2>/dev/null # Make sure needed packages are installed @@ -26,9 +30,6 @@ if [ $(sudo dpkg-query -l | grep "ii qrencode" | wc -l) = 0 ]; then sudo apt-get install qrencode -y > /dev/null fi -# 1. Parameter: lcd command -command=$1 - # check if LCD (/dev/fb1) or HDMI (/dev/fb0) # see https://github.com/rootzoll/raspiblitz/pull/1580 # but basically this just says if the driver for GPIO LCD is installed - not if connected @@ -44,18 +45,12 @@ if [ "${command}" == "rotate" ]; then # TURN ROTATE ON (the new default) if [ "$2" = "1" ] || [ "$2" = "on" ]; then - # add default 'lcdrotate' raspiblitz.conf if needed - if [ ${#lcdrotate} -eq 0 ]; then - echo "lcdrotate=0" >> /mnt/hdd/raspiblitz.conf - fi - # change rotation config echo "# Turn ON: LCD ROTATE" sudo sed -i "s/^dtoverlay=.*/dtoverlay=waveshare35a:rotate=90/g" /boot/config.txt sudo rm /etc/X11/xorg.conf.d/40-libinput.conf >/dev/null - # update raspiblitz conf file - sudo sed -i "s/^lcdrotate=.*/lcdrotate=1/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set lcdrotate 1 echo "# OK - a restart is needed: sudo shutdown -r now" # TURN ROTATE OFF @@ -79,8 +74,8 @@ EndSection EOF fi - # update raspiblitz conf file - sudo sed -i "s/^lcdrotate=.*/lcdrotate=0/g" /mnt/hdd/raspiblitz.conf + # update raspiblitz conf + /home/admin/config.scripts/blitz.conf.sh set lcdrotate 0 echo "OK - a restart is needed: sudo shutdown -r now" else @@ -133,14 +128,14 @@ if [ "${command}" == "qr" ]; then exit 1 fi - qrencode -l L -o /home/admin/qr.png "${datastring}" > /dev/null + qrencode -l L -o /var/cache/raspiblitz/qr.png "${datastring}" > /dev/null # see https://github.com/rootzoll/raspiblitz/pull/1580 if [ ${lcdExists} -eq 1 ] ; then # LCD - sudo fbi -a -T 1 -d /dev/fb1 --noverbose /home/admin/qr.png 2> /dev/null + sudo fbi -a -T 1 -d /dev/fb1 --noverbose /var/cache/raspiblitz/qr.png 2> /dev/null else # HDMI - sudo fbi -a -T 1 -d /dev/fb0 --noverbose /home/admin/qr.png 2> /dev/null + sudo fbi -a -T 1 -d /dev/fb0 --noverbose /var/cache/raspiblitz/qr.png 2> /dev/null fi exit 0 fi @@ -175,7 +170,7 @@ fi if [ "${command}" == "hide" ]; then sudo killall -3 fbi - shred -u /home/admin/qr.png 2> /dev/null + rm /var/cache/raspiblitz/qr.png 2> /dev/null exit 0 fi @@ -201,22 +196,6 @@ if [ "${command}" == "test-lcd-connect" ]; then exit 0 fi -############################### -# HDMI (deprecated - redirect) -############################### -if [ "${command}" == "hdmi" ]; then - secondParameter=$2 - if [ "${secondParameter}" == "on" ]; then - sudo /home/admin/config.scripts/blitz.display.sh set-display hdmi - elif [ "${secondParameter}" == "off" ]; then - sudo /home/admin/config.scripts/blitz.display.sh set-display lcd - else - echo "error='unknown second parameter'" - exit 1 - fi - exit 0 -fi - ####################################### # DISPLAY TYPED INSTALLS & UN-INSTALLS # HDMI is the default - every added @@ -360,36 +339,7 @@ function uninstall_lcd() { # not being used - can be deleted after mid 2021 function install_lcd_legacy() { - if [ "${baseimage}" = "raspbian" ] || [ "${baseimage}" = "dietpi" ]; then - echo "*** 32bit LCD DRIVER ***" - echo "--> Downloading LCD Driver from Github" - cd /home/admin/ - sudo -u admin git clone https://github.com/MrYacha/LCD-show.git - sudo -u admin chmod -R 755 LCD-show - sudo -u admin chown -R admin:admin LCD-show - cd LCD-show/ - # not signed - sudo -u admin git reset --hard 53dd0bf || exit 1 - # install xinput calibrator package - echo "--> install xinput calibrator package" - sudo apt install -y libxi6 - sudo dpkg -i xinput-calibrator_0.7.5-1_armhf.deb - - if [ "${baseimage}" = "dietpi" ]; then - echo "--> dietpi preparations" - sudo rm -rf /etc/X11/xorg.conf.d/40-libinput.conf - sudo mkdir /etc/X11/xorg.conf.d - sudo cp ./usr/tft35a-overlay.dtb /boot/overlays/ - sudo cp ./usr/tft35a-overlay.dtb /boot/overlays/tft35a.dtbo - sudo cp -rf ./usr/99-calibration.conf-35 /etc/X11/xorg.conf.d/99-calibration.conf - sudo cp -rf ./usr/99-fbturbo.conf /usr/share/X11/xorg.conf.d/ - sudo cp ./usr/cmdline.txt /DietPi/ - sudo cp ./usr/inittab /etc/ - sudo cp ./boot/config-35.txt /DietPi/config.txt - # make LCD screen rotation correct - sudo sed -i "s/dtoverlay=tft35a/dtoverlay=tft35a:rotate=270/" /DietPi/config.txt - fi - elif [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then + if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then echo "*** 64bit LCD DRIVER ***" echo "--> Downloading LCD Driver from Github" cd /home/admin/ @@ -433,13 +383,7 @@ function install_lcd_legacy() { # activate LCD and trigger reboot # dont do this on dietpi to allow for automatic build - if [ "${baseimage}" = "raspbian" ]; then - echo "Installing 32-bit LCD drivers ..." - sudo chmod +x -R /home/admin/LCD-show - cd /home/admin/LCD-show/ - sudo apt-mark hold raspberrypi-bootloader - sudo ./LCD35-show - elif [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then + if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then echo "Installing 64-bit LCD drivers ..." sudo chmod +x -R /home/admin/wavesharelcd-64bit-rpi cd /home/admin/wavesharelcd-64bit-rpi @@ -452,7 +396,7 @@ function install_lcd_legacy() { } function install_headless() { - if [ "${baseimage}" = "raspbian" ]||[ "${baseimage}" = "raspios_arm64" ]|| [ "${baseimage}" = "debian_rpi64" ]; then + if [ "${baseimage}" = "raspios_arm64" ]|| [ "${baseimage}" = "debian_rpi64" ]; then modificationExists=$(sudo cat /etc/systemd/system/getty@tty1.service.d/autologin.conf | grep -c "autologin pi") if [ "${modificationExists}" == "1" ]; then echo "# deactivating auto-login of pi user" @@ -476,7 +420,7 @@ function install_headless() { } function uninstall_headless() { - if [ "${baseimage}" = "raspbian" ]||[ "${baseimage}" = "raspios_arm64" ]|| [ "${baseimage}" = "debian_rpi64" ]; then + if [ "${baseimage}" = "raspios_arm64" ] || [ "${baseimage}" = "debian_rpi64" ]; then # activate auto-login sudo raspi-config nonint do_boot_behaviour B2 modificationExists=$(sudo cat /etc/systemd/system/getty@tty1.service.d/autologin.conf | grep -c "autologin pi") @@ -510,19 +454,6 @@ function uninstall_headless() { fi } -function prepareDisplayClassEntryRaspiblitzConf() { - # check if file exists / hdd is mounted - if [ -f "/mnt/hdd/raspiblitz.conf" ]; then - echo "file does exists" - entryExists=$(grep -c "displayClass=" /mnt/hdd/raspiblitz.conf) - if [ ${entryExists} -eq 0 ]; then - echo "displayClass=${displayClass}" >> /mnt/hdd/raspiblitz.conf - fi - else - echo "# /mnt/hdd/raspiblitz.conf does not exists (yet) - change is just part of raspiblitz.info" - fi -} - ################### # SET DISPLAY TYPE ################### @@ -532,6 +463,7 @@ if [ "${command}" == "set-display" ]; then paramDisplayClass=$2 paramDisplayType=$3 echo "# blitz.display.sh set-display ${paramDisplayClass} ${paramDisplayType}" + echo "baseimage(${baseimage})" # check if started with sudo if [ "$EUID" -ne 0 ]; then @@ -539,6 +471,12 @@ if [ "${command}" == "set-display" ]; then exit 1 fi + # check if display class parameter is given + if [ "${baseimage}" == "" ]; then + echo "err='missing baseimage info'" + exit 1 + fi + # check if display class parameter is given if [ "${paramDisplayClass}" == "" ]; then echo "err='missing parameter'" @@ -561,10 +499,9 @@ if [ "${command}" == "set-display" ]; then exit 1 fi - # mark new display class in configs - prepareDisplayClassEntryRaspiblitzConf + # mark new display class in config (if exist) + /home/admin/config.scripts/blitz.conf.sh set displayClass ${paramDisplayClass} sudo sed -i "s/^displayClass=.*/displayClass=${paramDisplayClass}/g" /home/admin/raspiblitz.info - sudo sed -i "s/^displayClass=.*/displayClass=${paramDisplayClass}/g" /mnt/hdd/raspiblitz.conf 2>/dev/null exit 0 fi diff --git a/home.admin/config.scripts/blitz.docker.sh b/home.admin/config.scripts/blitz.docker.sh index d667a744..c41548c1 100644 --- a/home.admin/config.scripts/blitz.docker.sh +++ b/home.admin/config.scripts/blitz.docker.sh @@ -13,11 +13,6 @@ fi source /mnt/hdd/raspiblitz.conf -# add default value to raspi config if needed -if ! grep -Eq "^docker=" /mnt/hdd/raspiblitz.conf; then - echo "docker=off" >> /mnt/hdd/raspiblitz.conf -fi - # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then @@ -48,7 +43,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then sudo pip3 install docker-compose # setting value in raspi blitz config - sudo sed -i "s/^docker=.*/docker=on/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set docker "on" echo "# docker install done" exit 0 fi @@ -56,7 +51,7 @@ fi # switch off if [ "$1" = "0" ] || [ "$1" = "off" ]; then # setting value in raspiblitz config - sudo sed -i "s/^docker=.*/docker=off/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set docker "off" echo "*** REMOVING docker & docker-compose ***" sudo pip3 uninstall -y docker-compose sudo apt-get purge -y docker-ce docker-ce-cli diff --git a/home.admin/config.scripts/blitz.error.sh b/home.admin/config.scripts/blitz.error.sh new file mode 100755 index 00000000..2de27876 --- /dev/null +++ b/home.admin/config.scripts/blitz.error.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env bash + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then + echo "RaspiBlitz Error Handling" + echo + echo "blitz.error.sh [source-script-name] [fixed-short-code] [?detail-message] [?additional-debugdata] [?logfile]" + echo + exit 1 +fi + +################### +# ERROR HANDLING +################### + +# get required parameters +script=$2 +shortcode=$3 + +# check reqired parameters +if [ "${script}" == "" ]; then + /home/admin/config.scripts/blitz.error.sh blitz.error.sh "error-missing-script" "missing any parameter" "$@" + exit 1 +fi +if [ "${shortcode}" == "" ]; then + /home/admin/config.scripts/blitz.error.sh blitz.error.sh "error-missing-code" "script ${script} missing error code" "$@" + exit 1 +fi + +# set error info in cache system state (for DISPLAY on lcd, report to webui, etc) +/home/admin/_cache.sh set state "error" +/home/admin/_cache.sh set message "${shortcode}" + +# prepare log error report +dateStr=$(date) +errorReport="ERROR in ${script} --> ${shortcode} on ${dateStr}" + +# get optional parameters & extend error report if given +detail=$4 +debugdata=$5 +if [ "${detail}" != "" ] || [ "${debugdata}" != "" ]; then + errorReport="${errorReport}\nDETAIL --> ${detail}\nDEBUG --> ${debugdata}" +fi + +# A) write error reports to /home/admin +timestampStr=$(date +%s) +filename="/home/admin/error-${script}-${timestampStr}.log" +echo "${errorReport}" > ${filename} +chown admin:admin ${filename} + +# B) write error to std outs +>&2 echo "${errorReport} --> ${filename}" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" +echo "${errorReport}" +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + +# C) write error report to given logfile (optional) +logfile=$6 +if [ "${logfile}" != "" ]; then + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >> ${logFile} + echo "${errorReport}" >> ${logFile} + echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >> ${logFile} +fi + +# on serial calls make sure that at least a second is between error reports +sleep 1 \ No newline at end of file diff --git a/home.admin/config.scripts/blitz.migration.sh b/home.admin/config.scripts/blitz.migration.sh index 25cfb050..272f830d 100755 --- a/home.admin/config.scripts/blitz.migration.sh +++ b/home.admin/config.scripts/blitz.migration.sh @@ -86,17 +86,18 @@ migrate_raspiblitz_conf () { # write default raspiblitz config source /home/admin/_version.info echo "# RASPIBLITZ CONFIG FILE" > /home/admin/raspiblitz.conf - echo "raspiBlitzVersion='${codeVersion}'" >> /home/admin/raspiblitz.conf - echo "network=bitcoin" >> /home/admin/raspiblitz.conf - echo "chain=main" >> /home/admin/raspiblitz.conf - echo "hostname=${nodename}" >> /home/admin/raspiblitz.conf - echo "displayClass=lcd" >> /home/admin/raspiblitz.conf - echo "lcdrotate=1" >> /home/admin/raspiblitz.conf - echo "runBehindTor=on" >> /home/admin/raspiblitz.conf sudo mv /home/admin/raspiblitz.conf /mnt/hdd/raspiblitz.conf sudo chown root:sudo /mnt/hdd/raspiblitz.conf sudo chmod 664 /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set raspiBlitzVersion "${codeVersion}" + /home/admin/config.scripts/blitz.conf.sh set network "bitcoin" + /home/admin/config.scripts/blitz.conf.sh set chain "main" + /home/admin/config.scripts/blitz.conf.sh set hostname "${nodename}" + /home/admin/config.scripts/blitz.conf.sh set displayClass "lcd" + /home/admin/config.scripts/blitz.conf.sh set lcdrotate "1" + /home/admin/config.scripts/blitz.conf.sh set runBehindTor "on" + # rename ext4 data drive sudo e2label /dev/sda1 BLOCKCHAIN } diff --git a/home.admin/config.scripts/blitz.notify.sh b/home.admin/config.scripts/blitz.notify.sh index 3269d3e2..04ad8954 100755 --- a/home.admin/config.scripts/blitz.notify.sh +++ b/home.admin/config.scripts/blitz.notify.sh @@ -12,65 +12,43 @@ fi # load config values source /home/admin/raspiblitz.info 2>/dev/null source /mnt/hdd/raspiblitz.conf 2>/dev/null -if [ ${#network} -eq 0 ]; then - echo "FAIL - was not able to load config data / network" - exit 1 -fi -# make sure main "notify" setting is present (add with default if not) -if ! grep -Eq "^notify=.*" /mnt/hdd/raspiblitz.conf; then - echo "notify=off" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null -fi - -# check all other settings and add if missing +# write default values if no custum values in raspiblitz config yet if ! grep -Eq "^notifyMethod=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMethod=mail" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMethod "mail" fi - -# Mail if ! grep -Eq "^notifyMailTo=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailTo=mail@example.com" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailTo "mail@example.com" fi - if ! grep -Eq "^notifyMailServer=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailServer=mail.example.com" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailServer "mail.example.com" fi - if ! grep -Eq "^notifyMailPort=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailPort=587" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailPort "587" fi - if ! grep -Eq "^notifyMailHostname=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailHostname=$(hostname)" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailHostname "${hostname}" fi - if ! grep -Eq "^notifyMailFromAddress=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailFromAddress=rb@example.com" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailFromAddress "rb@example.com" fi - if ! grep -Eq "^notifyMailFromName=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailFromName=\"RB User\"" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailFromName "RB User" fi - if ! grep -Eq "^notifyMailUser=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailUser=username" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailUser "username" fi - if ! grep -Eq "^notifyMailPass=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailPass=password" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailPass "password" fi - if ! grep -Eq "^notifyMailEncrypt=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailEncrypt=off" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailEncrypt "off" fi - if ! grep -Eq "^notifyMailToCert=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyMailToCert=/mnt/hdd/notify_mail_cert.pem" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyMailToCert "/mnt/hdd/notify_mail_cert.pem" fi - -# Ext if ! grep -Eq "^notifyExtCmd=.*" /mnt/hdd/raspiblitz.conf; then - echo "notifyExtCmd=/usr/bin/printf" | sudo tee -a /mnt/hdd/raspiblitz.conf >/dev/null + /home/admin/config.scripts/blitz.conf.sh set notifyExtCmd "/usr/bin/printf" fi # reload settings @@ -114,7 +92,7 @@ EOF # edit raspi blitz config echo "editing /mnt/hdd/raspiblitz.conf" - sudo sed -i "s/^notify=.*/notify=on/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set notify "on" exit 0 fi @@ -126,7 +104,7 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then echo "switching the NOTIFY OFF" # edit raspi blitz config echo "editing /mnt/hdd/raspiblitz.conf" - sudo sed -i "s/^notify=.*/notify=off/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set notify "off" exit 0 fi diff --git a/home.admin/config.scripts/blitz.preparerelease.sh b/home.admin/config.scripts/blitz.preparerelease.sh index 706cd78d..d451e517 100755 --- a/home.admin/config.scripts/blitz.preparerelease.sh +++ b/home.admin/config.scripts/blitz.preparerelease.sh @@ -3,15 +3,21 @@ # Just run this script once after a fresh sd card build # to prepare the image for release as a downloadable sd card image -# raspiblitz.info & logs -echo "cleaning raspiblitz info .." +# cleaning logs +echo "deleting raspiblitz & system logs .." +sudo rm /var/log/* 2>/dev/null +sudo rm /var/log/redis/* 2>/dev/null +sudo rm /var/log/private/* 2>/dev/null +sudo rm /var/log/nginx/* 2>/dev/null +sudo rm /home/admin/*.log 2>/dev/null +echo "OK" + +# clean raspiblitz.info toward the values set by sd card build script +echo "cleaning raspiblitz.info" source /home/admin/raspiblitz.info echo "baseimage=${baseimage}" > /home/admin/raspiblitz.info echo "cpu=${cpu}" >> /home/admin/raspiblitz.info echo "displayClass=${displayClass}" >> /home/admin/raspiblitz.info -echo "deleting raspiblitz logs .." -sudo rm /home/admin/*.log -echo "OK" # SSH Pubkeys (make unique for every sd card image install) echo "" diff --git a/home.admin/config.scripts/blitz.shutdown.sh b/home.admin/config.scripts/blitz.shutdown.sh index 253b7b9d..1cbe5b90 100755 --- a/home.admin/config.scripts/blitz.shutdown.sh +++ b/home.admin/config.scripts/blitz.shutdown.sh @@ -5,15 +5,7 @@ # 1) give UI the info that a reboot/shutdown is now happening # 2) shutdown/reboot in a safe way to prevent data corruption -# INFOFILE - state data from bootstrap -infoFile="/home/admin/raspiblitz.info" - -# get network info from config -source ${infoFile} 2>/dev/null -source /mnt/hdd/raspiblitz.conf 2>/dev/null -if [ ${#network} -eq 0 ]; then - network=bitcoin -fi +source <(/home/admin/_cache.sh get network) # display info echo "" @@ -21,13 +13,13 @@ echo "Green activity light stays dark and LCD turns white when shutdown complete if [ "$1" = "reboot" ]; then shutdownParams="-h -r now" echo "It will then reboot again automatically." - sed -i "s/^state=.*/state=reboot/g" ${infoFile} - sed -i "s/^message=.*/message='$2'/g" ${infoFile} + /home/admin/_cache.sh set state "reboot" + /home/admin/_cache.sh set message "$2" else shutdownParams="-h now" echo "Then wait 5 seconds and disconnect power." - sed -i "s/^state=.*/state=shutdown/g" ${infoFile} - sed -i "s/^message=.*/message=''/g" ${infoFile} + /home/admin/_cache.sh set state "shutdown" + /home/admin/_cache.sh set message "" fi # do shutdown/reboot diff --git a/home.admin/config.scripts/blitz.ssh.sh b/home.admin/config.scripts/blitz.ssh.sh index 87998213..b7ed0d8f 100755 --- a/home.admin/config.scripts/blitz.ssh.sh +++ b/home.admin/config.scripts/blitz.ssh.sh @@ -7,7 +7,8 @@ if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; echo "blitz.ssh.sh clear --> make sure old sshd host certs are cleared" echo "blitz.ssh.sh checkrepair --> check sshd & repair just in case" echo "blitz.ssh.sh backup --> copy ssh keys to backup (if exist)" - echo "blitz.ssh.sh restore --> restore ssh keys from backup (if exist)" + echo "blitz.ssh.sh sessions --> count open sessions" + echo "blitz.ssh.sh restore [?backup-root] --> restore ssh keys from backup (if exist)" exit 1 fi @@ -42,6 +43,16 @@ if [ "$1" = "clear" ]; then exit 0 fi +################### +# SESSIONS +################### +if [ "$1" = "sessions" ]; then + echo "# *** blitz.ssh.sh sessions" + sessionsCount=$(ss | grep -c ":ssh") + echo "ssh_session_count=${sessionsCount}" + exit 0 +fi + ################### # CHECK & REPAIR ################### @@ -117,6 +128,13 @@ fi ################### if [ "$1" = "restore" ]; then echo "# *** blitz.ssh.sh restore" + + # second parameter (optional) + ALTBACKUPBASEDIR=$2 + if [ "${ALTBACKUPBASEDIR}" != "" ]; then + DEFAULTBACKUPBASEDIR="${ALTBACKUPBASEDIR}" + fi + echo "# backup dir: ${DEFAULTBACKUPBASEDIR}/ssh" if [ -d "${DEFAULTBACKUPBASEDIR}/ssh" ]; then diff --git a/home.admin/config.scripts/blitz.statusscan.sh b/home.admin/config.scripts/blitz.statusscan.sh deleted file mode 100755 index 05289969..00000000 --- a/home.admin/config.scripts/blitz.statusscan.sh +++ /dev/null @@ -1,327 +0,0 @@ -#!/bin/bash - -source /home/admin/raspiblitz.info -source /mnt/hdd/raspiblitz.conf 2>/dev/null - -# LNTYPE is lnd | cl -if [ $# -gt 0 ];then - LNTYPE=$1 -else - LNTYPE=${lightning} -fi - -source <(/home/admin/config.scripts/network.aliases.sh getvars $LNTYPE ${chain}net) - -# command info -if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then - echo "# script to scan the state of the system after setup" - exit 1 -fi - -# measure time of scan -startTime=$(date +%s) - -# localIP -localip=$(hostname -I | awk '{print $1}') -echo "localIP='${localip}'" - -# temp - no measurement in a VM -tempC=0 -if [ -d "/sys/class/thermal/thermal_zone0/" ]; then - tempC=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc) - echo "tempCelsius='${tempC}'" -fi - -# uptime in seconds -uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime) -echo "uptime=${uptime}" - -# get UPS info (if configured) -/home/admin/config.scripts/blitz.ups.sh status - -# count restarts of bitcoind/litecoind -startcountBlockchain=$(cat /home/admin/systemd.blockchain.log 2>/dev/null | grep -c "STARTED") -echo "startcountBlockchain=${startcountBlockchain}" - -# is bitcoind running -bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running) -echo "bitcoinActive=${bitcoinRunning}" - -if [ ${bitcoinRunning} -eq 1 ]; then - - # get blockchain info - sudo touch /var/cache/raspiblitz/.bitcoind.out - sudo touch /var/cache/raspiblitz/.bitcoind.error - sudo chown root:sudo /var/cache/raspiblitz/.bitcoind.out - sudo chown root:sudo /var/cache/raspiblitz/.bitcoind.error - sudo chmod 660 /var/cache/raspiblitz/.bitcoind.out - sudo chmod 660 /var/cache/raspiblitz/.bitcoind.error - $bitcoincli_alias getblockchaininfo 1>/var/cache/raspiblitz/.bitcoind.out 2>/var/cache/raspiblitz/.bitcoind.error - # check if error on request - blockchaininfo=$(cat /var/cache/raspiblitz/.bitcoind.out 2>/dev/null) - bitcoinError=$(cat /var/cache/raspiblitz/.bitcoind.error 2>/dev/null) - #rm /var/cache/raspiblitz/.bitcoind.error 2>/dev/null - if [ ${#bitcoinError} -gt 0 ]; then - bitcoinErrorShort=$(echo ${bitcoinError/error*:/} | sed 's/[^a-zA-Z0-9 ]//g') - echo "bitcoinErrorShort='${bitcoinErrorShort}'" - bitcoinErrorFull=$(echo ${bitcoinError} | tr -d "'") - echo "bitcoinErrorFull='${bitcoinErrorFull}'" - else - - ################################### - # Get data from blockchain network - ################################### - - source <(sudo /home/admin/config.scripts/network.monitor.sh peer-status) - echo "blockchainPeers=${peers}" - - ############################## - # Get data from blockchaininfo - ############################## - - # get total number of blocks - total=$(echo ${blockchaininfo} | jq -r '.blocks') - echo "blockchainHeight=${total}" - - # is initial sync of blockchain - initialSync=$(echo ${blockchaininfo} | jq -r '.initialblockdownload' | grep -c 'true') - echo "initialSync=${initialSync}" - - # get blockchain sync progress - syncProgress="$(echo ${blockchaininfo} | jq -r '.verificationprogress')" - syncProgress=$(echo $syncProgress | awk '{printf( "%.2f%%", 100 * $1)}' | tr '%' ' ' | tr -s " ") - echo "syncProgress=${syncProgress}" - - fi -else - - # find out why Bitcoin not running - - pathAdd="" - if [ "${chain}" = "test" ]; then - pathAdd="/testnet3" - fi - - #### POSSIBLE/SOFT PROBLEMS - # place here in future analysis - - #### HARD PROBLEMS - - # LOW DISK SPACE - lowDiskSpace=$(sudo tail -n 100 /mnt/hdd/${network}${pathAdd}/debug.log 2>/dev/null | grep -c "Error: Disk space is low!") - if [ ${lowDiskSpace} -gt 0 ]; then - bitcoinErrorShort="HDD DISK SPACE LOW" - bitcoinErrorFull="HDD DISK SPACE LOW - check what data you can delete on HDD and restart" - fi - - #### GENERIC ERROR FIND - - # if still no error identified - search logs for generic error (after 4min uptime) - if [ ${#bitcoinErrorShort} -eq 0 ] && [ ${uptime} -gt 240 ]; then - bitcoinErrorFull=$(sudo tail -n 100 /mnt/hdd/${network}${pathAdd}/debug.log 2>/dev/null | grep -c "Error:" | tail -1 | tr -d "'") - if [ ${#bitcoinErrorFull} -gt 0 ]; then - bitcoinErrorShort="Error found in Logs" - fi - fi - - # output error if found - if [ ${#bitcoinErrorShort} -gt 0 ]; then - echo "bitcoinErrorShort='${bitcoinErrorShort}'" - echo "bitcoinErrorFull='${bitcoinErrorFull}'" - /home/admin/config.scripts/blitz.systemd.sh log blockchain "ERROR: ${bitcoinErrorShort}" - fi - -fi - -# count restarts of bitcoind/litecoind -startcountLightning=$(cat /home/admin/systemd.lightning.log 2>/dev/null | grep -c "STARTED") -echo "startcountLightning=${startcountLightning}" - -# is LND running -lndRunning=$(systemctl status ${netprefix}lnd.service 2>/dev/null | grep -c running) -echo "lndActive=${lndRunning}" - -if [ ${lndRunning} -eq 1 ] && [ "${LNTYPE}" == "lnd" ]; then - - # get LND info - lndRPCReady=1 - sudo touch /var/cache/raspiblitz/.lnd.error - sudo chown root:sudo /var/cache/raspiblitz/.lnd.error - sudo chmod 660 /var/cache/raspiblitz/.lnd.error - lndinfo=$($lncli_alias getinfo 2>/var/cache/raspiblitz/.lnd.error) - - # check if error on request - lndErrorFull=$(cat /var/cache/raspiblitz/.lnd.error 2>/dev/null) - lndErrorShort='' - #rm /var/cache/raspiblitz/.lnd.error 2>/dev/null - - if [ ${#lndErrorFull} -gt 0 ]; then - - # flag if error could be resoled by analysis - errorResolved=0 - - ### analyse LND logs since start - - # find a the line number in logs of start of LND - # just do this on error case to save on processing memory - lndStartLineNumber=$(sudo cat /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -in "LTND: Active chain:" | tail -1 | cut -d ":" -f1) - - # get logs of last LND start - lndLogsAfterStart=$(sudo tail --lines=+${lndStartLineNumber} /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null) - - # check RPC server ready (can take some time after wallet was unlocked) - lndRPCReady=$(echo "${lndLogsAfterStart}" | grep -c "RPCS: RPC server listening on") - echo "lndRPCReady=${lndRPCReady}" - - # check wallet if wallet was opened (after correct password) - lndWalletOpened=$(echo "${lndLogsAfterStart}" | grep -c "LNWL: Opened wallet") - echo "walletOpened=${lndWalletOpened}" - - # check wallet if wallet is ready (can take some time after wallet was opened) - lndWalletReady=$(echo "${lndLogsAfterStart}" | grep -c "LTND: LightningWallet opened") - echo "walletReady=${lndWalletReady}" - - ### check errors - - # scan error for walletLocked as common error - locked=$(echo ${lndErrorFull} | grep -c 'Wallet is encrypted') - if [ "${locked}" == "0" ]; then - locked=$(echo ${lndErrorFull} | grep -c 'wallet locked') - fi - if [ ${locked} -gt 0 ]; then - echo "walletLocked=1" - else - echo "walletLocked=0" - - rpcNotWorking=$(echo ${lndErrorFull} | grep -c 'connection refused') - if [ ${rpcNotWorking} -gt 0 ]; then - - # this can happen for a long time when LND is starting fresh sync - # on first startup - check if logs since start signaled RPC ready before - if [ ${lndRPCReady} -eq 0 ]; then - # nullify error - this is normal - lndErrorFull="" - errorResolved=1 - # output basic data because no error - echo "# LND RPC is still warming up - no scan progress: prepare scan" - echo "scanTimestamp=-2" - echo "syncedToChain=0" - else - echo "# LND RPC was started - some other problem going on" - lndErrorShort='LND RPC not responding' - lndErrorFull=$(echo "LND RPC is not responding. LND may have problems starting up. Check logs, config files and systemd service. Org-Error: ${lndErrorFull}" | tr -d "'") - fi - fi - - # if not known error and not resolved before - keep generic - if [ ${#lndErrorShort} -eq 0 ] && [ ${errorResolved} -eq 0 ]; then - lndErrorShort='Unknown Error - see logs' - lndErrorFull=$(echo ${lndErrorFull} | tr -d "'") - fi - - # write to results - if [ ${#lndErrorFull} -gt 0 ]; then - echo "lndErrorShort='${lndErrorShort}'" - echo "lndErrorFull='${lndErrorFull}'" - /home/admin/config.scripts/blitz.systemd.sh log lightning "ERROR: ${lndErrorFull}" - fi - - fi - - else - - # check if wallet is locked - locked=$(echo ${lndinfo} | grep -c unlock) - if [ ${locked} -gt 0 ]; then - echo "walletLocked=1" - else - echo "walletLocked=0" - fi - - # number of lnd peers - lndPeers=$(echo ${lndinfo} | jq -r '.num_peers') - echo "lndPeers=${lndPeers}" - - # synced to chain - syncedToChain=$(echo ${lndinfo} | jq -r '.synced_to_chain' | grep -c 'true') - echo "syncedToChain=${syncedToChain}" - - # lnd scan progress - scanTimestamp=$(echo ${lndinfo} | jq -r '.best_header_timestamp') - nowTimestamp=$(date +%s) - if [ ${#scanTimestamp} -gt 0 ] && [ ${scanTimestamp} -gt ${nowTimestamp} ]; then - scanTimestamp=${nowTimestamp} - fi - if [ ${#scanTimestamp} -gt 0 ]; then - echo "scanTimestamp=${scanTimestamp}" - scanDate=$(date -d @${scanTimestamp} 2>/dev/null) - echo "scanDate='${scanDate}'" - - # calculate LND scan progress by seconds since Genesis block - genesisTimestamp=1230940800 - - totalSeconds=$(echo "${nowTimestamp}-${genesisTimestamp}" | bc) - scannedSeconds=$(echo "${scanTimestamp}-${genesisTimestamp}" | bc) - scanProgress=$(echo "scale=2; $scannedSeconds*100/$totalSeconds" | bc) - echo "scanProgress=${scanProgress}" - else - echo "# was not able to parse 'best_header_timestamp' from: lncli getinfo" - echo "scanTimestamp=-1" - fi - - fi - - # output if lnd-RPC is ready - echo "lndRPCReady=${lndRPCReady}" - -fi - -# is CL running -clRunning=$(systemctl status ${netprefix}lightningd.service 2>/dev/null | grep -c running) -echo "clActive=${clRunning}" -echo "CLwalletLocked=0" - -if [ "${clRunning}" != "1" ] && [ "${LNTYPE}" == "cl" ]; then - # check if locked - if [ "$(sudo journalctl -n5 -u ${netprefix}lightningd | \ - grep -cE 'Could not read pass from stdin|pass the --encrypted-hsm|Wrong password')" -gt 0 ];then - echo "CLwalletLocked=1" - fi -fi - -if [ "${clRunning}" == "1" ] && [ "${LNTYPE}" == "cl" ]; then - clInfo=$($lightningcli_alias getinfo 2>&1) - clBlockHeight=$(echo "${clInfo}" | jq -r '.blockheight' | tr -cd '[[:digit:]]') - scanProgress=$(echo "scale=2; $clBlockHeight*100/$total" | bc) - echo "scanProgress=${scanProgress}" - clBlockHeightPlusOne=$(expr $clBlockHeight + 1) - if [ "${total}" == "${clBlockHeight}" ] || [ "${total}" == "${clBlockHeightPlusOne}" ]; then - echo "syncedToChain=1" - else - echo "syncedToChain=0" - fi -fi - -# touchscreen statistics -if [ "${touchscreen}" == "1" ]; then - echo "blitzTUIActive=1" - if [ ${#blitzTUIRestarts} -gt 0 ]; then - echo "blitzTUIRestarts=${blitzTUIRestarts}" - else - echo "blitzTUIRestarts=0" - fi -else - echo "blitzTUIActive=0" - echo "blitzTUIRestarts=0" -fi - -# check if runnig in vagrant -vagrant=$(df | grep -c "/vagrant") -echo "vagrant=${vagrant}" - -# check if online if problem with other stuff - -# info on scan run time -endTime=$(date +%s) -runTime=$(echo "${endTime}-${startTime}" | bc) -echo "scriptRuntime=${runTime}" diff --git a/home.admin/config.scripts/blitz.systemd.sh b/home.admin/config.scripts/blitz.systemd.sh index 89352613..a728204e 100755 --- a/home.admin/config.scripts/blitz.systemd.sh +++ b/home.admin/config.scripts/blitz.systemd.sh @@ -13,7 +13,5 @@ if [ "${1}" != "log" ]; then echo "# FAIL: unknown parameter" fi -# writing log file entry -logFile="/home/admin/systemd.${2}.log" -echo "$(date +%s) ${3}" >> ${logFile} -echo "# OK: log '${3}' written to ${logFile}" +# count for statistics in cache +/home/admin/_cache.sh increment system_count_start_${2} \ No newline at end of file diff --git a/home.admin/config.scripts/blitz.touchscreen.sh b/home.admin/config.scripts/blitz.touchscreen.sh index cd0ea5f2..c4aad159 100755 --- a/home.admin/config.scripts/blitz.touchscreen.sh +++ b/home.admin/config.scripts/blitz.touchscreen.sh @@ -1,7 +1,6 @@ #!/bin/bash # see issue: https://github.com/rootzoll/raspiblitz/issues/646 # and issue: https://github.com/rootzoll/raspiblitz/issues/809 -# to work it needs to be based on Raspbian Desktop base image # to check debug logs: sudo cat /home/pi/.cache/lxsession/LXDE-pi/run.log source /home/admin/raspiblitz.info @@ -136,11 +135,7 @@ EOF echo "LCD is rotated into default - no touchscreen rotate" fi - # mark touchscreen as switched ON in config - if [ ${#touchscreen} -eq 0 ]; then - echo "touchscreen=0" >> /mnt/hdd/raspiblitz.conf - fi - sudo sed -i 's/^touchscreen=.*/touchscreen=1/g' /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set touchscreen "1" echo "OK - a restart is needed: sudo shutdown -r now" exit 0 @@ -236,7 +231,7 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then sudo rm -f /etc/X11/xorg.conf.d/40-libinput.conf >/dev/null # mark touchscreen as switched OFF in config - sudo sed -i 's/^touchscreen=.*/touchscreen=0/g' /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set touchscreen "0" echo "OK - a restart is needed: sudo shutdown -r now" exit 0 diff --git a/home.admin/config.scripts/blitz.ups.sh b/home.admin/config.scripts/blitz.ups.sh index 12dc0c03..258ac12d 100755 --- a/home.admin/config.scripts/blitz.ups.sh +++ b/home.admin/config.scripts/blitz.ups.sh @@ -53,8 +53,9 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then if [ ${#ups} -eq 0 ]; then echo "ups=on" >> /mnt/hdd/raspiblitz.conf fi + # set ups config value (in case of update) - sudo sed -i "s/^ups=.*/ups='apcusb'/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set ups "apcusb" echo "OK - UPS is now connected" echo "Check status/connection with command: apcaccess" @@ -116,7 +117,7 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then sudo systemctl stop apcupsd sudo systemctl disable apcupsd sudo apt-get remove -y apcupsd - sudo sed -i "s/^ups=.*/ups=off/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set ups "off" else echo "FAIL: unknown UPSTYPE: ${ups}" exit 1 diff --git a/home.admin/config.scripts/blitz.web.sh b/home.admin/config.scripts/blitz.web.sh index fc42418d..af690b5f 100755 --- a/home.admin/config.scripts/blitz.web.sh +++ b/home.admin/config.scripts/blitz.web.sh @@ -57,6 +57,9 @@ EOF # ToDo(frennkie) verify this sudo sed -i -E '/^.*server_names_hash_bucket_size [0-9]*;$/a \\tserver_names_hash_bucket_size 128;' /etc/nginx/nginx.conf fi + if [ $(sudo cat /etc/nginx/nginx.conf | grep -c "# server_tokens off") -gt 0 ]; then + sudo sed -i "s/# server_tokens off;/server_tokens off;/g" /etc/nginx/nginx.conf + fi echo "# Checking dhparam.pem ..." if [ ! -f /etc/ssl/certs/dhparam.pem ]; then diff --git a/home.admin/config.scripts/bonus.angular_cli.sh b/home.admin/config.scripts/bonus.angular_cli.sh index 98d45e94..85f21cb5 100755 --- a/home.admin/config.scripts/bonus.angular_cli.sh +++ b/home.admin/config.scripts/bonus.angular_cli.sh @@ -9,11 +9,6 @@ fi source /mnt/hdd/raspiblitz.conf -# add default value to raspi config if needed -if ! grep -Eq "^angular_cli=" /mnt/hdd/raspiblitz.conf; then - echo "angular_cli=off" >> /mnt/hdd/raspiblitz.conf -fi - # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then # check if angular_cli was installed @@ -62,7 +57,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then fi fi # setting value in raspi blitz config - sudo sed -i "s/^angular_cli=.*/angular_cli=on/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set angular_cli "on" echo "Installed angular_cli $(node -v)" exit 0 fi @@ -70,7 +65,7 @@ fi # switch off if [ "$1" = "0" ] || [ "$1" = "off" ]; then # setting value in raspiblitz config - sudo sed -i "s/^angular_cli=.*/angular_cli=off/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set angular_cli "off" echo "*** REMOVING angular_cli ***" npm uninstall @angular/cli -g echo "OK angular_cli removed." diff --git a/home.admin/config.scripts/bonus.bos.sh b/home.admin/config.scripts/bonus.bos.sh index d2b89b11..a7ef4c5c 100755 --- a/home.admin/config.scripts/bonus.bos.sh +++ b/home.admin/config.scripts/bonus.bos.sh @@ -13,11 +13,6 @@ fi source /mnt/hdd/raspiblitz.conf -# add default value to raspi config if needed -if ! grep -Eq "^bos=" /mnt/hdd/raspiblitz.conf; then - echo "bos=off" >> /mnt/hdd/raspiblitz.conf -fi - # show info menu if [ "$1" = "menu" ]; then dialog --title " Info Balance of Satoshis " --msgbox " @@ -86,7 +81,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then sudo -u bos bash -c 'echo "source <(bos completion bash)" >> /home/bos/.bashrc' # setting value in raspi blitz config - sudo sed -i "s/^bos=.*/bos=on/g" /mnt/hdd/raspiblitz.conf + /home/admin/config.scripts/blitz.conf.sh set bos "on" echo "# Usage: https://github.com/alexbosworth/balanceofsatoshis/blob/master/README.md" echo "# To start type: 'sudo su bos' in the command line." @@ -101,8 +96,8 @@ fi if [ "$1" = "0" ] || [ "$1" = "off" ]; then # setting value in raspi blitz config - sudo sed -i "s/^bos=.*/bos=off/g" /mnt/hdd/raspiblitz.conf - + /home/admin/config.scripts/blitz.conf.sh set bos "off" + echo "*** REMOVING BALANCE OF SATOSHIS ***" sudo userdel -rf bos echo "# OK, bos is removed." diff --git a/home.admin/config.scripts/bonus.btc-rpc-explorer.sh b/home.admin/config.scripts/bonus.btc-rpc-explorer.sh index 9a4631b4..1b3611b7 100755 --- a/home.admin/config.scripts/bonus.btc-rpc-explorer.sh +++ b/home.admin/config.scripts/bonus.btc-rpc-explorer.sh @@ -80,11 +80,6 @@ Activate TOR to access the web block explorer from outside your local network. exit 0 fi -# add default value to raspi config if needed -if ! grep -Eq "^BTCRPCexplorer=" /mnt/hdd/raspiblitz.conf; then - echo "BTCRPCexplorer=off" >> /mnt/hdd/raspiblitz.conf -fi - # status if [ "$1" = "status" ]; then @@ -188,7 +183,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then # make sure that txindex of blockchain is switched on /home/admin/config.scripts/network.txindex.sh on - + # add btcrpcexplorer user sudo adduser --disabled-password --gecos "" btcrpcexplorer @@ -212,7 +207,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then PASSWORD_B=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcpassword | cut -c 13-) touch /home/admin/btc-rpc-explorer.env - sudo chmod 600 /home/admin/btc-rpc-explorer.env || exit 1 + sudo chmod 600 /home/admin/btc-rpc-explorer.env || exit 1 cat > /home/admin/btc-rpc-explorer.env <