Browse Source

Merge branch 'v1.2' into v.1.2-doc-update

master
Christian Rotzoll 6 years ago
committed by GitHub
parent
commit
60dba93a77
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      README.md
  2. 3
      WORKSHOP.md
  3. 20
      build_sdcard.sh
  4. 30
      home.admin/00infoBlitz.sh
  5. 18
      home.admin/00infoLCD.sh
  6. 467
      home.admin/00mainMenu.sh
  7. 390
      home.admin/00raspiblitz.sh
  8. 17
      home.admin/00settingsMenuServices.sh
  9. 1
      home.admin/20recoverDialog.sh
  10. 15
      home.admin/30initHDD.sh
  11. 2
      home.admin/50downloadHDD.sh
  12. 45
      home.admin/50torrentHDD.sh
  13. 313
      home.admin/70initLND.sh
  14. 101
      home.admin/80scanLND.old.sh
  15. 184
      home.admin/80scanLND.sh
  16. 4
      home.admin/90finishSetup.sh
  17. 6
      home.admin/95finalSetup.sh
  18. 133
      home.admin/99checkUpdate.sh
  19. 103
      home.admin/BBcashoutWallet.sh
  20. 2
      home.admin/XXsyncScripts.sh
  21. 149
      home.admin/_background.sh
  22. 9
      home.admin/_bootstrap.sh
  23. 2
      home.admin/_commands.sh
  24. 118
      home.admin/config.scripts/blitz.statusscan.sh
  25. 99
      home.admin/config.scripts/dropbox.upload.sh
  26. 43
      home.admin/config.scripts/internet.sshpubkey.sh
  27. 97
      home.admin/config.scripts/lnd.initwallet.py
  28. 33
      home.admin/config.scripts/lnd.rescue.sh

4
README.md

@ -1,7 +1,7 @@
# RaspiBlitz
*Build your own Lightning Node on a RaspberryPi with a nice Display.*
`Version 1.1 with lnd 0.6-beta-RC3 and bitcoin 0.17.1 or litecoin 0.16.3.`
`Version 1.2 with lnd 0.6-beta and bitcoin 0.17.1 or litecoin 0.16.3.`
![RaspiBlitz](pictures/raspiblitz.jpg)
@ -587,5 +587,3 @@ Also get inspired for a deep-dive with the original "[RaspiBolt](https://github.
Join me on twitter [@rootzoll](https://twitter.com/rootzoll), visit us at a upcomming [#lightninghackday](https://twitter.com/hashtag/LightningHackday?src=hash) or check by on of our bitcoin meetups in Berlin ... every 1st Thursday evening a month at the room77 bar - feel free to buy me a beer with lightning there :)
* [How can I get further help/support?](#support)
IRC channel on Freenode `irc://irc.freenode.net/raspiblitz` (unmoderated)

3
WORKSHOP.md

@ -108,6 +108,9 @@ Check how much time is left to go thru the next steps of connecting to peers, fu
Its also nice to add casual social open-end segment to the end of the workshop. So people can already go into personal conversations, music and beverages while some last nodes sync up, confirmations come in and people sending their first satoshis on some lightning chess or from node to node.
Here are some videos that show what else is possible with the RaspiBlitz:
- [Lightning Network LND API - Buying Stickers using Commandline](https://youtu.be/tocJFPU8sAc) 24min
# Organisation Tasks
*Which of the follwoing organisation tasks are relevant for you depends on which starting scenario you choose (see above). Here is the complete possible list with details:*

20
build_sdcard.sh

@ -1,9 +1,9 @@
#!/bin/bash
#########################################################################
# Build your SD card image based on:
# RASPBIAN STRETCH WITH DESKTOP (2018-11-13)
# RASPBIAN STRETCH WITH DESKTOP (2019-04-09)
# https://www.raspberrypi.org/downloads/raspbian/
# SHA256: a121652937ccde1c2583fe77d1caec407f2cd248327df2901e4716649ac9bc97
# SHA256: 7e10a446f8e57210d0e9ad02f0c833aabb86e58187b4dc02431aff5a3f1ccb83
#
# or download the image for your ARM based SBC on https://DietPi.com
##########################################################################
@ -462,16 +462,16 @@ echo "*** LND ***"
## based on https://github.com/Stadicus/guides/blob/master/raspibolt/raspibolt_40_lnd.md#lightning-lnd
## see LND releases: https://github.com/lightningnetwork/lnd/releases
lndVersion="0.6-beta-rc4"
lndVersion="0.6-beta"
if [ ${isARM} -eq 1 ] ; then
lndOSversion="armv7"
lndSHA256="3ed4b5e54afb6bf083a9693058dbf7d490e15837da5e5dc49ba06bfb942a1312"
lndSHA256="effea372c207293fd42b0cc27800da3a70c22f8c9a0e7b5eb8dbe56b5b98e1a3"
fi
if [ ${isAARCH64} -eq 1 ] ; then
lndOSversion="arm64"
lndSHA256="43c86a8fd50dc54d942bc85883202396da063780c249769f7b97b2159e8d5630"
fi
lndSHA256="2f31b13a4da6217ed7e27a44e1705103d7ed846aa2f599b7e5de0e6033a66c19"
fi
# olaoluwa
PGPpkeys="https://keybase.io/roasbeef/pgp_keys.asc"
@ -538,10 +538,7 @@ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1
echo "to switch between python2/3: sudo update-alternatives --config python"
sudo apt-get -f -y install virtualenv
sudo -u admin virtualenv lnd
sudo -u admin source lnd/bin/activate
sudo -u admin pip install grpcio grpcio-tools googleapis-common-protos
sudo -u admin bash -c "cd; virtualenv python-env-lnd; source /home/admin/python-env-lnd/bin/activate; pip install grpcio grpcio-tools googleapis-common-protos"
echo ""
# Go is needed for ZAP connect later
@ -619,6 +616,7 @@ sudo apt-get -y install exfat-fuse
# for blockchain torrent download
sudo apt-get -y install transmission-cli
sudo apt-get -y install rtorrent
sudo apt-get -y install cpulimit
# for background downloading
sudo apt-get -y install screen
@ -652,7 +650,7 @@ sudo bash -c "echo 'PATH=\$PATH:\$GOPATH/bin' >> /home/admin/.profile"
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' >> /home/admin/.bashrc"
sudo bash -c "echo './00mainMenu.sh' >> /home/admin/.bashrc"
sudo bash -c "echo './00raspiblitz.sh' >> /home/admin/.bashrc"
if [ "${baseImage}" = "raspbian" ] || [ "${baseImage}" = "armbian" ] || [ "${baseImage}" = "ubuntu" ]; then
# bash autostart for pi

30
home.admin/00infoBlitz.sh

@ -58,7 +58,7 @@ tempF=$(((cpu/1000) * (9/5) + 32))
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 100 ]; then
if [ ${ram_avail} -lt 50 ]; then
color_ram="${color_red}\e[7m"
else
color_ram=${color_green}
@ -271,18 +271,22 @@ else
fi
# STATUS SINALING: Backup Torrent Seeding
torrentBaseStatus="•"
torrentUpdateStatus="•"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseComplete}" == "1" ]; then
torrentBaseStatus="↑"
elif [ "${baseSeeding}" == "1" ]; then
torrentBaseStatus="↓"
fi
if [ "${updateComplete}" == "1" ]; then
torrentUpdateStatus="↑"
elif [ "${updateSeeding}" == "1" ]; then
torrentUpdateStatus="↓"
torrentBaseStatus=""
torrentUpdateStatus=""
if [ "${backupTorrentSeeding}" == "on" ]; then
torrentBaseStatus="•"
torrentUpdateStatus="•"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseComplete}" == "1" ]; then
torrentBaseStatus="↑"
elif [ "${baseSeeding}" == "1" ]; then
torrentBaseStatus="↓"
fi
if [ "${updateComplete}" == "1" ]; then
torrentUpdateStatus="↑"
elif [ "${updateSeeding}" == "1" ]; then
torrentUpdateStatus="↓"
fi
fi
sleep 5

18
home.admin/00infoLCD.sh

@ -197,24 +197,6 @@ while :
continue
fi
# check if bitcoin is ready
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp
clienterror=`cat error.tmp`
rm error.tmp
if [ ${#clienterror} -gt 0 ]; then
boxwidth=40
l1="Waiting for ${network}d to get ready.\n"
l2="---> ${clienterror/error*:/}\n"
l3="Can take longer if device was off."
uptimeSeconds="$(cat /proc/uptime | grep -o '^[0-9]\+')"
if [ ${uptimeSeconds} -gt 600 ]; then
l3="!!Please login for more details!!"
fi
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip}) - Welcome Back" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
continue
fi
# check if locked
locked=$(sudo -u bitcoin lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock)
if [ "${locked}" -gt 0 ]; then

467
home.admin/00mainMenu.sh

@ -7,121 +7,14 @@ configFile="/mnt/hdd/raspiblitz.conf"
# INFOFILE - state data from bootstrap
infoFile="/home/admin/raspiblitz.info"
# check if HDD is connected
hddExists=$(lsblk | grep -c sda1)
if [ ${hddExists} -eq 0 ]; then
# check if there is maybe a HDD but woth no partitions
noPartition=$(lsblk | grep -c sda)
if [ ${noPartition} -eq 1 ]; then
echo "***********************************************************"
echo "WARNING: HDD HAS NO PARTITIONS"
echo "***********************************************************"
echo "Press ENTER to create a Partition - or CTRL+C to abort"
read key
echo "Creating Partition ..."
sudo parted -s /dev/sda unit s mkpart primary `sudo parted /dev/sda unit s print free | grep 'Free Space' | tail -n 1`
echo "DONE."
sleep 3
else
echo "***********************************************************"
echo "WARNING: NO HDD FOUND -> Shutdown, connect HDD and restart."
echo "***********************************************************"
exit
fi
fi
# check data from _bootstrap.sh that was running on device setup
bootstrapInfoExists=$(ls $infoFile | grep -c '.info')
if [ ${bootstrapInfoExists} -eq 0 ]; then
echo "***********************************************************"
echo "WARNING: NO raspiblitz.info FOUND -> bootstrap not running?"
echo "***********************************************************"
exit
fi
# load the data from the info file (will get produced on every startup)
# MAIN MENU AFTER SETUP
source ${infoFile}
source ${configFile}
if [ "${state}" = "recovering" ]; then
echo "***********************************************************"
echo "WARNING: bootstrap still updating - close SSH, login later"
echo "To monitor progress --> tail -n1000 -f raspiblitz.log"
echo "***********************************************************"
exit
fi
# signal that after bootstrap recover user dialog is needed
if [ "${state}" = "recovered" ]; then
echo "System recovered - needs final user settings"
./20recoverDialog.sh
exit 1
fi
# signal that a reindex was triggered
if [ "${state}" = "reindex" ]; then
echo "Re-Index in progress ... start monitoring:"
/home/admin/config.scripts/network.reindex.sh
exit 1
fi
# singal that torrent is in re-download
if [ "${state}" = "retorrent" ]; then
echo "Re-Index in progress ... start monitoring:"
/home/admin/50torrentHDD.sh
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info
/home/admin/00mainMenu.sh
exit
fi
# if pre-sync is running - stop it - before continue
if [ "${state}" = "presync" ]; then
# stopping the pre-sync
echo ""
# analyse if blockchain was detected broken by pre-sync
blockchainBroken=$(sudo tail /mnt/hdd/bitcoin/debug.log | grep -c "Please restart with -reindex or -reindex-chainstate to recover.")
if [ ${blockchainBroken} -eq 1 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Detected corrupted blockchain on pre-sync !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Deleting blockchain data ..."
echo "(needs to get downloaded fresh during setup)"
sudo rm -f -r /mnt/hdd/bitcoin
else
echo "********************************************"
echo "Stopping pre-sync ... pls wait (up to 1min)"
echo "********************************************"
sudo -u root bitcoin-cli -conf=/home/admin/assets/bitcoin.conf stop
echo "bitcoind called to stop .."
sleep 50
fi
# unmount the temporary mount
echo "Unmount HDD .."
sudo umount -l /mnt/hdd
sleep 3
# update info file
state=waitsetup
sudo sed -i "s/^state=.*/state=waitsetup/g" $infoFile
sudo sed -i "s/^message=.*/message='Pre-Sync Stopped'/g" $infoFile
fi
# if state=ready -> setup is done or started
if [ "${state}" = "ready" ]; then
configExists=$(ls ${configFile} | grep -c '.conf')
if [ ${configExists} -eq 1 ]; then
echo "loading config data"
source ${configFile}
else
echo "setup still in progress - setupStep(${setupStep})"
fi
fi
# get the local network IP to be displayed on the lCD
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
## default menu settings
# to fit the main menu without scrolling:
# HEIGHT=23
# CHOICE_HEIGHT=20
# BASIC MENU INFO
HEIGHT=13
WIDTH=64
CHOICE_HEIGHT=6
@ -129,262 +22,56 @@ BACKTITLE="RaspiBlitz"
TITLE=""
MENU="Choose one of the following options:"
OPTIONS=()
# check if RTL web interface is installed
runningRTL=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
# get the local network IP to be displayed on the lCD
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
# function to use later
waitUntilChainNetworkIsReady()
{
echo "checking ${network}d - please wait .."
echo "can take longer if device was off or first time"
while :
do
# check for error on network
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp
clienterror=`cat error.tmp`
rm error.tmp
# check for missing blockchain data
minSize=250000000000
if [ "${network}" = "litecoin" ]; then
minSize=20000000000
fi
blockchainsize=$(sudo du -shbc /mnt/hdd/${network} | head -n1 | awk '{print $1;}')
if [ ${#blockchainsize} -gt 0 ]; then
if [ ${blockchainsize} -lt ${minSize} ]; then
echo "blockchainsize(${blockchainsize})"
echo "Missing Blockchain Data (<${minSize}) ..."
clienterror="missing blockchain"
sleep 3
fi
fi
if [ ${#clienterror} -gt 0 ]; then
# analyse LOGS for possible reindex
reindex=$(sudo cat /mnt/hdd/${network}/debug.log | grep -c 'Please restart with -reindex or -reindex-chainstate to recover')
if [ ${reindex} -gt 0 ] || [ "${clienterror}" = "missing blockchain" ]; then
echo "!! DETECTED NEED FOR RE-INDEX in debug.log ... starting repair options."
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info
sleep 3
dialog --backtitle "RaspiBlitz - Repair Script" --msgbox "Your blockchain data needs to be repaired.
This can be due to power problems or a failing HDD.
Please check the FAQ on RaspiBlitz Github
'My blockchain data is corrupted - what can I do?'
https://github.com/rootzoll/raspiblitz/blob/master/FAQ.md
The RaspiBlitz will now try to help you on with the repair.
To run a BACKUP of funds & channels first is recommended.
" 13 65
clear
# Basic Options
OPTIONS=(TORRENT "Redownload Prepared Torrent (DEFAULT)" \
COPY "Copy from another Computer (SKILLED)" \
REINDEX "Resync thru ${network}d (TAKES VERY VERY LONG)" \
BACKUP "Run Backup LND data first (optional)"
)
CHOICE=$(dialog --backtitle "RaspiBlitz - Repair Script" --clear --title "Repair Blockchain Data" --menu "Choose a repair/recovery option:" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty)
clear
if [ "${CHOICE}" = "TORRENT" ]; then
echo "Starting TORRENT ..."
sudo sed -i "s/^state=.*/state=retorrent/g" /home/admin/raspiblitz.info
/home/admin/50torrentHDD.sh
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info
/home/admin/00mainMenu.sh
exit
elif [ "${CHOICE}" = "COPY" ]; then
echo "Starting COPY ..."
sudo sed -i "s/^state=.*/state=recopy/g" /home/admin/raspiblitz.info
/home/admin/50copyHDD.sh
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info
/home/admin/00mainMenu.sh
exit
elif [ "${CHOICE}" = "REINDEX" ]; then
echo "Starting REINDEX ..."
sudo /home/admin/config.scripts/network.reindex.sh
exit
elif [ "${CHOICE}" = "BACKUP" ]; then
sudo /home/admin/config.scripts/lnd.rescue.sh backup
echo "PRESS ENTER to return to menu."
read key
/home/admin/00mainMenu.sh
exit
else
echo "CANCEL"
exit
fi
else
echo "${network} error: ${clienterror}"
fi
# normal info
boxwidth=40
l1="Waiting for ${network}d to get ready.\n"
l2="---> ${clienterror/error*:/}\n"
l3="Can take longer if device was off."
uptimeSeconds="$(cat /proc/uptime | grep -o '^[0-9]\+')"
# after 2 min show complete long string (full detail)
if [ ${uptimeSeconds} -gt 120 ]; then
boxwidth=80
l2="${clienterror}\n"
l3="CTRL+C => terminal"
fi
dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
else
locked=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock)
if [ ${locked} -gt 0 ]; then
./AAunlockLND.sh
echo "please wait ... update to next screen can be slow"
fi
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
if [ ${lndSynced} -eq 0 ]; then
./80scanLND.sh
else
# everything is ready - return from loop
return
fi
fi
sleep 5
done
}
if [ ${#setupStep} -eq 0 ]; then
echo "WARN: no setup step found in raspiblitz.info"
setupStep=0
plus=""
if [ "${runBehindTor}" = "on" ]; then
plus=" / TOR"
fi
if [ ${setupStep} -eq 0 ]; then
# check data from boostrap
# TODO: when olddata --> CLEAN OR MANUAL-UPDATE-INFO
if [ "${state}" = "olddata" ]; then
# old data setup
BACKTITLE="RaspiBlitz - Manual Update"
TITLE="⚡ Found old RaspiBlitz Data on HDD ⚡"
MENU="\n ATTENTION: OLD DATA COULD CONTAIN FUNDS\n"
OPTIONS+=(MANUAL "read how to recover your old funds" \
DELETE "erase old data, keep blockchain, reboot" )
HEIGHT=11
else
# show hardware test
/home/admin/05hardwareTest.sh
# start setup
BACKTITLE="RaspiBlitz - Setup"
TITLE="⚡ Welcome to your RaspiBlitz ⚡"
MENU="\nChoose how you want to setup your RaspiBlitz: \n "
OPTIONS+=(BITCOIN "Setup BITCOIN and Lightning (DEFAULT)" \
LITECOIN "Setup LITECOIN and Lightning (EXPERIMENTAL)" )
HEIGHT=11
fi
elif [ ${setupStep} -lt 100 ]; then
# see function above
if [ ${setupStep} -gt 59 ]; then
waitUntilChainNetworkIsReady
fi
# continue setup
BACKTITLE="${hostname} / ${network} / ${chain}"
TITLE="⚡ Welcome to your RaspiBlitz ⚡"
MENU="\nThe setup process is not finished yet: \n "
OPTIONS+=(CONTINUE "Continue Setup of your RaspiBlitz")
HEIGHT=10
else
# see function above
waitUntilChainNetworkIsReady
# MAIN MENU AFTER SETUP
plus=""
if [ "${runBehindTor}" = "on" ]; then
plus=" / TOR"
fi
if [ ${#dynDomain} -gt 0 ]; then
plus="${plus} / ${dynDomain}"
fi
BACKTITLE="${localip} / ${hostname} / ${network} / ${chain}${plus}"
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep -c unlock)
if [ ${locked} -gt 0 ]; then
if [ "${rtlWebinterface}" = "on" ]; then
# WEBINTERFACE INFO LOCK SCREEN
TITLE="SSH UNLOCK"
MENU="IMPORTANT: Please unlock thru the RTL Webinterface.\nWebinterface --> http://${localip}:3000\nThen TRY AGAIN to get to main menu."
OPTIONS+=(R "TRY AGAIN - check again if unlocked" \
U "FALLBACK -> Unlock with 'lncli unlock'")
else
# NORMAL LOCK SCREEN
MENU="!!! YOUR WALLET IS LOCKED !!!"
OPTIONS+=(U "Unlock your Lightning Wallet with 'lncli unlock'")
fi
else
if [ ${runningRTL} -eq 1 ]; then
TITLE="Webinterface: http://${localip}:3000"
fi
# Basic Options
OPTIONS+=(INFO "RaspiBlitz Status Screen" \
FUNDING "Fund your on-chain Wallet" \
CONNECT "Connect to a Peer" \
CHANNEL "Open a Channel with Peer" \
SEND "Pay an Invoice/PaymentRequest" \
RECEIVE "Create Invoice/PaymentRequest" \
SERVICES "Activate/Deactivate Services" \
MOBILE "Connect Mobile Wallet" \
EXPORT "Macaroons and TLS.cert" \
NAME "Change Name/Alias of Node" \
PASSWORD "Change Passwords" \
CASHOUT "Remove Funds from on-chain Wallet")
# dont offer lnbalance/lnchannels on testnet
if [ "${chain}" = "main" ]; then
OPTIONS+=(lnbalance "Detailed Wallet Balances" \
lnchannels "Lightning Channel List")
fi
# Depending Options
openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net listchannels 2>/dev/null | jq '.[] | length')
if [ ${openChannels} -gt 0 ]; then
OPTIONS+=(CLOSEALL "Close all open Channels")
fi
if [ "${runBehindTor}" = "on" ]; then
OPTIONS+=(NYX "Monitor TOR")
fi
if [ ${#dynDomain} -gt 0 ]; then
plus="${plus} / ${dynDomain}"
fi
BACKTITLE="${localip} / ${hostname} / ${network} / ${chain}${plus}"
# final Options
OPTIONS+=(HARDWARE "Run Hardwaretest")
OPTIONS+=(SOFTWARE "Run Softwaretest")
OPTIONS+=(OFF "PowerOff RaspiBlitz")
OPTIONS+=(X "Console / Terminal")
if [ "${rtlWebinterface}" == "on" ]; then
TITLE="Webinterface: http://${localip}:3000"
fi
fi
# Basic Options
OPTIONS+=(INFO "RaspiBlitz Status Screen" \
FUNDING "Fund your on-chain Wallet" \
CONNECT "Connect to a Peer" \
CHANNEL "Open a Channel with Peer" \
SEND "Pay an Invoice/PaymentRequest" \
RECEIVE "Create Invoice/PaymentRequest" \
SERVICES "Activate/Deactivate Services" \
MOBILE "Connect Mobile Wallet" \
EXPORT "Macaroons and TLS.cert" \
NAME "Change Name/Alias of Node" \
PASSWORD "Change Passwords" \
CASHOUT "Remove Funds from on-chain Wallet"
)
# dont offer lnbalance/lnchannels on testnet
if [ "${chain}" = "main" ]; then
OPTIONS+=(lnbalance "Detailed Wallet Balances" \
lnchannels "Lightning Channel List")
fi
# Depending Options
openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net listchannels 2>/dev/null | jq '.[] | length')
if [ ${#openChannels} -gt 0 ] && [ ${openChannels} -gt 0 ]; then
OPTIONS+=(CLOSEALL "Close all open Channels")
fi
if [ "${runBehindTor}" == "on" ]; then
OPTIONS+=(NYX "Monitor TOR")
fi
# final Options
OPTIONS+=(HARDWARE "Run Hardwaretest")
OPTIONS+=(SOFTWARE "Run Softwaretest (DebugReport)")
OPTIONS+=(UPDATE "Check/Prepare RaspiBlitz Update")
OPTIONS+=(OFF "PowerOff RaspiBlitz")
OPTIONS+=(X "Console / Terminal")
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
@ -393,27 +80,11 @@ CHOICE=$(dialog --clear \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
#clear
case $CHOICE in
CLOSE)
exit 1;
;;
BITCOIN)
sed -i "s/^network=.*/network=bitcoin/g" ${infoFile}
sed -i "s/^chain=.*/chain=main/g" ${infoFile}
./10setupBlitz.sh
exit 1;
;;
LITECOIN)
sed -i "s/^network=.*/network=litecoin/g" ${infoFile}
sed -i "s/^chain=.*/chain=main/g" ${infoFile}
./10setupBlitz.sh
exit 1;
;;
CONTINUE)
./10setupBlitz.sh
exit 1;
;;
INFO)
./00infoBlitz.sh
echo "Screen is not updating ... press ENTER to continue."
@ -448,8 +119,6 @@ case $CHOICE in
;;
CASHOUT)
./BBcashoutWallet.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
CHANNEL)
@ -492,18 +161,6 @@ case $CHOICE in
read key
./00mainMenu.sh
;;
TOR)
sudo ./96addTorService.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
RTL)
sudo ./98installRTL.sh
echo "Press ENTER to return to main menu."
read key
./00mainMenu.sh
;;
EXPORT)
sudo /home/admin/config.scripts/lnd.export.sh
echo "Press ENTER to return to main menu."
@ -564,30 +221,14 @@ case $CHOICE in
sudo shutdown now
exit 0
;;
MANUAL)
echo "************************************************************************************"
echo "PLEASE go to RaspiBlitz FAQ:"
echo "https://github.com/rootzoll/raspiblitz"
echo "And check: How can I recover my coins from a failing RaspiBlitz?"
echo "************************************************************************************"
exit 0
;;
DELETE)
sudo ./XXcleanHDD.sh
sudo shutdown -r now
exit 0
;;
X)
lncli -h
echo "OK you now on the command line."
echo "You can return to the main menu with the command:"
echo "raspiblitz"
;;
R)
UPDATE)
/home/admin/99checkUpdate.sh
./00mainMenu.sh
;;
U) # unlock
./AAunlockLND.sh
./00mainMenu.sh
;;
exit 0
;;
esac

390
home.admin/00raspiblitz.sh

@ -0,0 +1,390 @@
#!/bin/bash
echo "Starting the main menu ..."
# CONFIGFILE - configuration of RaspiBlitz
configFile="/mnt/hdd/raspiblitz.conf"
# INFOFILE - state data from bootstrap
infoFile="/home/admin/raspiblitz.info"
# check if HDD is connected
hddExists=$(lsblk | grep -c sda1)
if [ ${hddExists} -eq 0 ]; then
# check if there is maybe a HDD but woth no partitions
noPartition=$(lsblk | grep -c sda)
if [ ${noPartition} -eq 1 ]; then
echo "***********************************************************"
echo "WARNING: HDD HAS NO PARTITIONS"
echo "***********************************************************"
echo "Press ENTER to create a Partition - or CTRL+C to abort"
read key
echo "Creating Partition ..."
sudo parted -s /dev/sda unit s mkpart primary `sudo parted /dev/sda unit s print free | grep 'Free Space' | tail -n 1`
echo "DONE."
sleep 3
else
echo "***********************************************************"
echo "WARNING: NO HDD FOUND -> Shutdown, connect HDD and restart."
echo "***********************************************************"
exit
fi
fi
# check data from _bootstrap.sh that was running on device setup
bootstrapInfoExists=$(ls $infoFile | grep -c '.info')
if [ ${bootstrapInfoExists} -eq 0 ]; then
echo "***********************************************************"
echo "WARNING: NO raspiblitz.info FOUND -> bootstrap not running?"
echo "***********************************************************"
exit
fi
# load the data from the info file (will get produced on every startup)
source ${infoFile}
if [ "${state}" = "recovering" ]; then
echo "***********************************************************"
echo "WARNING: bootstrap still updating - close SSH, login later"
echo "To monitor progress --> tail -n1000 -f raspiblitz.log"
echo "***********************************************************"
exit
fi
# signal that after bootstrap recover user dialog is needed
if [ "${state}" = "recovered" ]; then
echo "System recovered - needs final user settings"
/home/admin/20recoverDialog.sh
exit 1
fi
# signal that a reindex was triggered
if [ "${state}" = "reindex" ]; then
echo "Re-Index in progress ... start monitoring:"
/home/admin/config.scripts/network.reindex.sh
exit 1
fi
# singal that torrent is in re-download
if [ "${state}" = "retorrent" ]; then
echo "Re-Index in progress ... start monitoring:"
/home/admin/50torrentHDD.sh
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info
/home/admin/00raspiblitz.sh
exit
fi
# if pre-sync is running - stop it - before continue
if [ "${state}" = "presync" ]; then
# stopping the pre-sync
echo ""
# analyse if blockchain was detected broken by pre-sync
blockchainBroken=$(sudo tail /mnt/hdd/bitcoin/debug.log | grep -c "Please restart with -reindex or -reindex-chainstate to recover.")
if [ ${blockchainBroken} -eq 1 ]; then
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Detected corrupted blockchain on pre-sync !"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "Deleting blockchain data ..."
echo "(needs to get downloaded fresh during setup)"
sudo rm -f -r /mnt/hdd/bitcoin
else
echo "********************************************"
echo "Stopping pre-sync ... pls wait (up to 1min)"
echo "********************************************"
sudo -u root bitcoin-cli -conf=/home/admin/assets/bitcoin.conf stop
echo "bitcoind called to stop .."
sleep 50
fi
# unmount the temporary mount
echo "Unmount HDD .."
sudo umount -l /mnt/hdd
sleep 3
# update info file
state=waitsetup
sudo sed -i "s/^state=.*/state=waitsetup/g" $infoFile
sudo sed -i "s/^message=.*/message='Pre-Sync Stopped'/g" $infoFile
fi
# if state=ready -> setup is done or started
if [ "${state}" = "ready" ]; then
configExists=$(ls ${configFile} | grep -c '.conf')
if [ ${configExists} -eq 1 ]; then
echo "loading config data"
source ${configFile}
else
echo "setup still in progress - setupStep(${setupStep})"
fi
fi
## default menu settings
# to fit the main menu without scrolling:
HEIGHT=13
WIDTH=64
CHOICE_HEIGHT=6
BACKTITLE="RaspiBlitz"
TITLE=""
MENU="Choose one of the following options:"
OPTIONS=()
# check if RTL web interface is installed
runningRTL=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
# function to use later
waitUntilChainNetworkIsReady()
{
echo "checking ${network}d - please wait .."
echo "can take longer if device was off or first time"
while :
do
# check for error on network
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp
clienterror=`cat error.tmp`
rm error.tmp
# check for missing blockchain data
minSize=250000000000
if [ "${network}" = "litecoin" ]; then
minSize=20000000000
fi
blockchainsize=$(sudo du -shbc /mnt/hdd/${network} | head -n1 | awk '{print $1;}')
if [ ${#blockchainsize} -gt 0 ]; then
if [ ${blockchainsize} -lt ${minSize} ]; then
echo "blockchainsize(${blockchainsize})"
echo "Missing Blockchain Data (<${minSize}) ..."
clienterror="missing blockchain"
sleep 3
fi
fi
if [ ${#clienterror} -gt 0 ]; then
# analyse LOGS for possible reindex
reindex=$(sudo cat /mnt/hdd/${network}/debug.log | grep -c 'Please restart with -reindex or -reindex-chainstate to recover')
if [ ${reindex} -gt 0 ] || [ "${clienterror}" = "missing blockchain" ]; then
echo "!! DETECTED NEED FOR RE-INDEX in debug.log ... starting repair options."
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info
sleep 3
dialog --backtitle "RaspiBlitz - Repair Script" --msgbox "Your blockchain data needs to be repaired.
This can be due to power problems or a failing HDD.
Please check the FAQ on RaspiBlitz Github
'My blockchain data is corrupted - what can I do?'
https://github.com/rootzoll/raspiblitz/blob/master/FAQ.md
The RaspiBlitz will now try to help you on with the repair.
To run a BACKUP of funds & channels first is recommended.
" 13 65
clear
# Basic Options
OPTIONS=(TORRENT "Redownload Prepared Torrent (DEFAULT)" \
COPY "Copy from another Computer (SKILLED)" \
REINDEX "Resync thru ${network}d (TAKES VERY VERY LONG)" \
BACKUP "Run Backup LND data first (optional)"
)
CHOICE=$(dialog --backtitle "RaspiBlitz - Repair Script" --clear --title "Repair Blockchain Data" --menu "Choose a repair/recovery option:" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty)
clear
if [ "${CHOICE}" = "TORRENT" ]; then
echo "Starting TORRENT ..."
sudo sed -i "s/^state=.*/state=retorrent/g" /home/admin/raspiblitz.info
/home/admin/50torrentHDD.sh
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info
/home/admin/00raspiblitz.sh
exit
elif [ "${CHOICE}" = "COPY" ]; then
echo "Starting COPY ..."
sudo sed -i "s/^state=.*/state=recopy/g" /home/admin/raspiblitz.info
/home/admin/50copyHDD.sh
sudo sed -i "s/^state=.*/state=repair/g" /home/admin/raspiblitz.info
/home/admin/00raspiblitz.sh
exit
elif [ "${CHOICE}" = "REINDEX" ]; then
echo "Starting REINDEX ..."
sudo /home/admin/config.scripts/network.reindex.sh
exit
elif [ "${CHOICE}" = "BACKUP" ]; then
sudo /home/admin/config.scripts/lnd.rescue.sh backup
echo "PRESS ENTER to return to menu."
read key
/home/admin/00raspiblitz.sh
exit
else
echo "CANCEL"
exit
fi
fi
# let 80scanLND script to the info to use
/home/admin/80scanLND.sh
if [ $? -gt 0 ]; then
echo "${network} error: ${clienterror}"
exit 0
fi
else
locked=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock)
if [ ${locked} -gt 0 ]; then
uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime)
if [ "${autoUnlock}" == "on" ] && [ ${uptime} -lt 300 ]; then
# give autounlock 5 min after startup to react
sleep 1
else
/home/admin/AAunlockLND.sh
echo "please wait ... update to next screen can be slow"
fi
fi
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
if [ ${lndSynced} -eq 0 ]; then
/home/admin/80scanLND.sh
if [ $? -gt 0 ]; then
exit 0
fi
else
# everything is ready - return from loop
return
fi
fi
sleep 5
done
}
if [ ${#setupStep} -eq 0 ]; then
echo "WARN: no setup step found in raspiblitz.info"
setupStep=0
fi
if [ ${setupStep} -eq 0 ]; then
# check data from boostrap
# TODO: when olddata --> CLEAN OR MANUAL-UPDATE-INFO
if [ "${state}" = "olddata" ]; then
# old data setup
BACKTITLE="RaspiBlitz - Manual Update"
TITLE="⚡ Found old RaspiBlitz Data on HDD ⚡"
MENU="\n ATTENTION: OLD DATA COULD CONTAIN FUNDS\n"
OPTIONS+=(MANUAL "read how to recover your old funds" \
DELETE "erase old data, keep blockchain, reboot" )
HEIGHT=11
else
# show hardware test
/home/admin/05hardwareTest.sh
# start setup
BACKTITLE="RaspiBlitz - Setup"
TITLE="⚡ Welcome to your RaspiBlitz ⚡"
MENU="\nChoose how you want to setup your RaspiBlitz: \n "
OPTIONS+=(BITCOIN "Setup BITCOIN and Lightning (DEFAULT)" \
LITECOIN "Setup LITECOIN and Lightning (EXPERIMENTAL)" )
HEIGHT=11
fi
elif [ ${setupStep} -lt 100 ]; then
# see function above
if [ ${setupStep} -gt 59 ]; then
waitUntilChainNetworkIsReady
fi
# continue setup
BACKTITLE="${hostname} / ${network} / ${chain}"
TITLE="⚡ Welcome to your RaspiBlitz ⚡"
MENU="\nThe setup process is not finished yet: \n "
OPTIONS+=(CONTINUE "Continue Setup of your RaspiBlitz")
HEIGHT=10
else
# when all is setup - forward to main menu
waitUntilChainNetworkIsReady
/home/admin/00mainMenu.sh
exit 0
fi
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case $CHOICE in
CLOSE)
exit 1;
;;
BITCOIN)
sed -i "s/^network=.*/network=bitcoin/g" ${infoFile}
sed -i "s/^chain=.*/chain=main/g" ${infoFile}
/home/admin/10setupBlitz.sh
exit 1;
;;
LITECOIN)
sed -i "s/^network=.*/network=litecoin/g" ${infoFile}
sed -i "s/^chain=.*/chain=main/g" ${infoFile}
/home/admin/10setupBlitz.sh
exit 1;
;;
CONTINUE)
/home/admin/10setupBlitz.sh
exit 1;
;;
OFF)
echo ""
echo "LCD turns white when shutdown complete."
echo "Then wait 5 seconds and disconnect power."
echo "-----------------------------------------------"
echo "stop lnd - please wait .."
sudo systemctl stop lnd
echo "stop ${network}d (1) - please wait .."
sudo -u bitcoin ${network}-cli stop
sleep 10
echo "stop ${network}d (2) - please wait .."
sudo systemctl stop ${network}d
sleep 3
sync
echo "starting shutdown ..."
sudo shutdown now
exit 0
;;
MANUAL)
echo "************************************************************************************"
echo "PLEASE go to RaspiBlitz FAQ:"
echo "https://github.com/rootzoll/raspiblitz"
echo "And check: How can I recover my coins from a failing RaspiBlitz?"
echo "************************************************************************************"
exit 0
;;
DELETE)
sudo /home/admin/XXcleanHDD.sh
sudo shutdown -r now
exit 0
;;
X)
lncli -h
echo "OK you now on the command line."
echo "You can return to the main menu with the command:"
echo "raspiblitz"
;;
R)
/home/admin/00raspiblitz.sh
;;
U) # unlock
/home/admin/AAunlockLND.sh
/home/admin/00raspiblitz.sh
;;
esac

17
home.admin/00settingsMenuServices.sh

@ -222,9 +222,16 @@ if [ "${backupTorrentSeeding}" != "${choice}" ]; then
echo "BACKUP TORRENT SEEDING Setting changed .."
anychange=1
if [ "${choice}" = "on" ]; then
/home/admin/50torrentHDD.sh backup-torrent-hosting
dialog --backtitle "RaspiBlitz Settings" --title " OK " --msgbox "
whiptail --title "Experimental Feature" --yes-button "Activate" --no-button "Dont Activate" --yesno "The Backup Torrent Seeding is still a very early
experimental feature and could compromise your
Lightning Node stability.
Are you sure that you want to activate it?
" 11 54
if [ $? -eq 0 ]; then
/home/admin/50torrentHDD.sh backup-torrent-hosting
dialog --backtitle "RaspiBlitz Settings" --title " OK " --msgbox "
BACKUP TORRENT SEEDING IS NOW ACTIVE
-------------------------------------
If possible forward ports 49200-49250
@ -234,6 +241,12 @@ During initial torrent download your
RaspiBlitz can be slow.
" 13 42
else
echo
echo "Skipping Backup Torrent Seeding ..."
echo
sleep 3
fi
else
echo "Stopping Torrents and Cleaning Up ..."

1
home.admin/20recoverDialog.sh

@ -46,6 +46,7 @@ ACTUAL/OLD Password C to re-activate the
Auto-Unlock feature. Enter a empty password
to deactivate the Auto-Unlock feature.
" 10 52
echo "Activating Auto-Unlock (please wait) .."
sudo /home/admin/config.scripts/lnd.autounlock.sh on
dialog --backtitle "RaspiBlitz" --msgbox "FINAL REBOOT IS NEEDED." 6 52

15
home.admin/30initHDD.sh

@ -70,6 +70,21 @@ if [ ${existsHDD} -eq 1 ]; then
echo "FAIL - HDD is mounted"
echo "If you really want to reinit the HDD, then unmount the HDD first and try again"
else
echo ""
dialog --title "Format HDD" --yes-button "Yes" --no-button "Cancel" --yesno "RaspiBlitz detected a Hard Disk Drive (HDD).
It will get formatted to EXT4 to be usefull.
This will DELETE ALL FORMER DATA on the HDD.
Is it OK to delete HDD for fresh RaspiBlitz?
" 10 48
if [ $? -eq 1 ]; then
dialog --title "Replace HDD" --msgbox "OK. RaspiBlitz will shutdown now.
Please disconnect Power then.
Backup HDD data or connect another one.
Then Power up again." 8 39
sudo shutdown now
exit 1
fi
echo ""
echo "*** Formatting the HDD ***"
echo "WARNING ALL DATA ON HDD WILL GET DELETED - CAN TAKE SOME TIME"

2
home.admin/50downloadHDD.sh

@ -143,7 +143,7 @@ if [ ${finalSize} -lt ${targetSize} ]; then
case $response in
1) sudo rm -rf /mnt/hdd/download ;;
esac
./00mainMenu.sh
./00raspiblitz.sh
exit 1;
else

45
home.admin/50torrentHDD.sh

@ -11,6 +11,9 @@
# status
# to get info backround torrent hosting
# stop
# just stopping the download - not switching off
## get basic info
source /home/admin/raspiblitz.info
@ -40,7 +43,7 @@ targetDir="/mnt/hdd/torrent"
sessionDir="/home/admin/.rtorrent.session"
# BACKUP TORRENT SEEDING
if [ "$1" == "cleanup" ]; then
if [ "$1" == "stop" ] || [ "$1" == "cleanup" ]; then
echo "Stopping Torrents ..."
sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
@ -50,6 +53,20 @@ if [ "$1" == "cleanup" ]; then
if [ ${#sessionPID} -gt 0 ]; then
sudo pkill -P ${sessionPID}
fi
fi
if [ "$1" == "stop" ] || [ "$1" == "cleanup" ]; then
echo "Stopping Torrents ..."
sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
sudo pkill -P ${sessionPID}
fi
sessionPID=$(screen -ls | grep "update" | cut -d "." -f1 | xargs)
if [ ${#sessionPID} -gt 0 ]; then
sudo pkill -P ${sessionPID}
fi
if [ "$1" == "stop" ]; then
exit 0
fi
echo "Deleting all possible old (version) torrent data ..."
sudo rm -r /home/admin/.rtorrent.session 2>/dev/null
sudo rm -r /mnt/hdd/torrent 2>/dev/null
@ -153,6 +170,7 @@ sleep 2
# just let torrent start and run in the background
if [ "$1" == "backup-torrent-hosting" ]; then
# changing config - so it can be startup again after a reboot by bootstrap
source /mnt/hdd/raspiblitz.conf
if [ ${#backupTorrentSeeding} -eq 0 ]; then
@ -160,6 +178,27 @@ if [ "$1" == "backup-torrent-hosting" ]; then
else
sudo sed -i "s/^backupTorrentSeeding=.*/backupTorrentSeeding=on/g" /mnt/hdd/raspiblitz.conf
fi
# set the torrents processes to cpulimit 25%
sleep 6
echo ""
rtorrentPIDs=$(ps axf | grep "rtorrent" | awk '{$1=$1;print}' | cut -d' ' -f1)
while read -r pid ; do
ps ${pid} | grep "rtorrent"
echo "---> reducing this rTorrent process to 25% CPU"
sudo cpulimit -p ${pid} -l 25 &
echo ""
done < <(echo "${rtorrentPIDs}")
sleep 6
# set the torrents processes to cpulimit 20%
#sessionPID=$(screen -ls | grep "blockchain" | cut -d "." -f1 | xargs)
#echo "Putting rTorrent blockchain 'BASE' (PID=${sessionPID}) to background ... (please wait)"
#sudo cpulimit -p ${sessionPID} -l 25 &
#sessionPID=$(screen -ls | grep "update" | cut -d "." -f1 | xargs)
#echo "Putting rTorrent blockchain 'UPDATE' (PID=${sessionPID}) to background ... (please wait)"
#sudo cpulimit -p ${sessionPID} -l 25 &
echo "Done BACKUP TORRENT HOSTING"
exit
fi
@ -322,7 +361,7 @@ if [ ${torrentError} -gt 0 ]; then
case $response in
1) sudo rm -rf ${targetDir}; sudo rm -rf ${sessionDir} ;;
esac
./00mainMenu.sh
./00raspiblitz.sh
exit 1;
fi
@ -345,8 +384,8 @@ date +%s
echo "can take 10-60 minutes... please wait"
sudo mkdir /mnt/hdd/${network} 2>/dev/null
sudo mv ${targetPath1}/* /mnt/hdd/${network}/
sudo rm -r ${sessionDir}/blockchain
sudo cp --verbose -r ${targetPath2}/* /mnt/hdd/${network}/
sudo rm -r ${targetDir}
echo "OK"
date +%s

313
home.admin/70initLND.sh

@ -143,11 +143,15 @@ if [ ${walletExists} -eq 0 ]; then
# UI: Ask if user wants NEW wallet or RECOVER a wallet
OPTIONS=(NEW "Setup a brand new Lightning Node (DEFAULT)" \
OLD "I had a old Node I want to recover/restore")
CHOICE=$(dialog --backtitle "RaspiBlitz - LND Setup" --clear --title "LND Data & Wallet" --menu "How to setup your node?:" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty)
CHOICE=$(dialog --backtitle "RaspiBlitz" --clear --title "LND Setup" --menu "LND Data & Wallet" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty)
echo "choice($CHOICE)"
if [ "${CHOICE}" == "NEW" ]; then
############################
# NEW WALLET
############################
# let user enter password c
sudo shred /home/admin/.pass.tmp 2>/dev/null
sudo ./config.scripts/blitz.setpassword.sh x "Set your Password C for the LND Wallet Unlock" /home/admin/.pass.tmp
@ -161,26 +165,36 @@ if [ ${walletExists} -eq 0 ]; then
fi
# generate wallet with seed and set passwordC
source lnd/bin/activate
sudo python /home/admin/config.scripts/lnd.initwallet.py new ${passwordC} > /home/admin/.seed.tmp
echo "Generating new Wallet ...."
source /home/admin/python-env-lnd/bin/activate
python /home/admin/config.scripts/lnd.initwallet.py new ${passwordC} > /home/admin/.seed.tmp
source /home/admin/.seed.tmp
sudo shred /home/admin/.pass.tmp 2>/dev/null
# in case of error - retry
if [ ${#err} -eq 0 ]; then
if [ ${#err} -gt 0 ]; then
whiptail --title "lnd.initwallet.py - ERROR" --msgbox "${err}" 8 50
/home/admin/70initLND.sh
exit 1
else
if [ ${#seedwords} -eq 0 ]; then
echo "FAIL!! -> MISSING seedwords data - but also no err data ?!?"
echo "CHECK output data above - PRESS ENTER to restart 70initLND.sh"
read key
/home/admin/70initLND.sh
exit 1
fi
fi
# TODO: create numbered string in rows
# 5 rows with 6 words each - each word needs to be filled up with spaces to be 12chars long -> (1:test )
if [ ${#seedwords6x4} -eq 0 ]; then
seedwords6x4="${seedwords}"
fi
ack=0
while [ ${ack} -eq 0 ]
do
whiptail --title "IMPORTANT - PLEASE WRITE DOWN" --msgbox "LND Wallet got created. Store these numbered words in a safe location:" 8 76
whiptail --title "Please Confirm" --yes-button "Show Again" --no-button "CONTINUE" --yesno " Are you sure that you wrote down the word list?\n${seedwords}" 8 55
whiptail --title "IMPORTANT SEED WORDS - PLEASE WRITE DOWN" --msgbox "LND Wallet got created. Store these numbered words in a safe location:\n\n${seedwords6x4}" 12 76
whiptail --title "Please Confirm" --yes-button "Show Again" --no-button "CONTINUE" --yesno " Are you sure that you wrote down the word list?" 8 55
if [ $? -eq 1 ]; then
ack=1
fi
@ -190,25 +204,238 @@ if [ ${walletExists} -eq 0 ]; then
else
# TODO: IMPLEMENT
# - Recover with Seed Word List
# --> (ask if seed word list was password D protected)
# - Recover with Seed Word List & Channel Backup Snapshot File
# --> (ask if seed word list was password D protected)
# - Restore LND backup made with Rescue-Script (tar.gz-file)
# --> run retsore script
# FALLBACK TO lncli create FOR NOW
dialog --title "OK" --msgbox "\nI will start 'lncli create' for you ..." 7 44
sudo -u bitcoin /usr/local/bin/lncli --chain=${network} create
############################
# RECOVER OLD WALLET
############################
OPTIONS=(LNDRESCUE "LND tar.gz-Backupfile (BEST)" \
SEED+SCB "Seed & channel.backup file (OK)" \
ONLYSEED "Only Seed Word List (FALLBACK)")
CHOICE=$(dialog --backtitle "RaspiBlitz" --clear --title "RECOVER LND DATA & WALLET" --menu "Data you have to recover from?" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty)
# LND RESCUE
if [ "${CHOICE}" == "LNDRESCUE" ]; then
sudo /home/admin/config.scripts/lnd.rescue.sh restore
echo ""
echo "PRESS ENTER to continue."
read key
/home/admin/70initLND.sh
exit 1
fi
# WRNING ON ONLY SEED
if [ "${CHOICE}" == "ONLYSEED" ]; then
whiptail --title "IMPORTANT INFO" --yes-button "Continue" --no-button "Go Back" --yesno "
Using JUST SEED WORDS will only recover your on-chain funds.
To also try to recover the open channel funds you need the
channel.backup file (since RaspiBlitz v1.2 / LND 0.6-beta)
or having a complete LND rescue-backup from your old node.
" 11 65
if [ $? -eq 1 ]; then
/home/admin/70initLND.sh
exit 1
fi
fi
##### DEACTIVATED UNTIL config.scripts/lnd.initwallet.py WORKS
# # let user enter password c
# sudo shred /home/admin/.pass.tmp 2>/dev/null
# sudo ./config.scripts/blitz.setpassword.sh x "Set your Password C for the LND Wallet Unlock" /home/admin/.pass.tmp
# passwordC=`sudo cat /home/admin/.pass.tmp`
# sudo shred /home/admin/.pass.tmp 2>/dev/null
#
# # get seed word list
# if [ "${CHOICE}" == "SEED+SCB" ] || [ "${CHOICE}" == "ONLYSEED" ]; then
#
# # dialog to enter
# dialog --backtitle "RaspiBlitz - LND Recover" --inputbox "Please enter/paste the SEED WORD LIST:\n(just the words, seperated by commas, in correct order as numbered)" 9 78 2>/home/admin/.seed.tmp
# wordstring=$( cat /home/admin/.seed.tmp | sed 's/[^a-zA-Z0-9,]//g' )
# shred /home/admin/.seed.tmp
# echo "processing ... ${wordstring}"
#
# # check correct number of words
# IFS=',' read -r -a seedArray <<< "$wordstring"
# if [ ${#seedArray[@]} -eq 24 ]; then
# echo "OK - 24 words"
# else
# whiptail --title " WARNING " --msgbox "
#The word list has ${#seedArray[@]} words. But it must be 24.
#Please check your list and try again.
#
#Best is to write words in external editor
#and then copy and paste them into dialog.
#
#The Word list should look like this:
#wordone,wordtweo,wordthree, ...
#
#" 16 52
# /home/admin/70initLND.sh
# exit 1
# fi
#
# # ask if seed was protected by password D
# passwordD=""
# dialog --title "SEED PASSWORD" --yes-button "No extra Password" --no-button "Yes" --yesno "
#Are your seed words protected by an extra password?
#
#During wallet creation LND offers to set an extra password
#to protect the seed words. Most users did not set this.
# " 11 65
# if [ $? -eq 1 ]; then
# sudo shred /home/admin/.pass.tmp 2>/dev/null
# sudo ./config.scripts/blitz.setpassword.sh x "Enter extra Password D" /home/admin/.pass.tmp
# passwordD=`sudo cat /home/admin/.pass.tmp`
# sudo shred /home/admin/.pass.tmp 2>/dev/null
# fi
#
# fi
#
# if [ "${CHOICE}" == "ONLYSEED" ]; then
#
# # trigger wallet recovery
# source <(python /home/admin/config.scripts/lnd.initwallet.py seed ${passwordC} ${wordstring} ${passwordD})
#
# # on success the python script should return the seed words again
# if [ ${#seedwords} -gt 1 ]; then
# dialog --title " SUCCESS " --msgbox "
#Looks good :) LND was able to recover the wallet.
# " 7 53
# else
# if [ ${#err} -eq 0 ]; then
# echo
# echo "FAIL!! Unkown Error - check output above for any hints and report to development."
# echo "PRESS ENTER to try again."
# read key
# /home/admin/70initLND.sh
# exit 1
# else
# whiptail --title " FAIL " --msgbox "
#Something went wrong - see info below:
#${err}
#${errMore}
# " 13 72
# /home/admin/70initLND.sh
# exit 1
# fi
# fi
# fi
if [ "${CHOICE}" == "SEED+SCB" ]; then
# get the channel.backup file
gotFile=-1
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
while [ ${gotFile} -lt 1 ]
do
# show info
clear
sleep 1
echo "**********************************"
echo "* UPLOAD THE channel.backup FILE *"
echo "**********************************"
echo
if [ ${gotFile} -eq -1 ]; then
echo "If you have the channel.backup file on your laptop or on"
echo "another server you can now upload it to the RaspiBlitz."
elif [ ${gotFile} -eq 0 ]; then
echo "NO channel.backup FOUND IN /home/admin"
echo "Please try upload again."
fi
echo
echo "To make upload open a new terminal and change,"
echo "into the directory where your lnd-rescue file is and"
echo "COPY, PASTE AND EXECUTE THE FOLLOWING COMMAND:"
echo "scp ./channel.backup admin@${localip}:/home/admin/"
echo ""
echo "Use password A to authenticate file transfere."
echo "PRESS ENTER when upload is done. Enter x & ENTER to cancel."
# wait user interaction
echo "Please upload file. Press ENTER to try again or (x & ENTER) to cancel."
read key
if [ "${key}" == "x" ]; then
/home/admin/70initLND.sh
exit 1
fi
# test upload
gotFile=$(ls /home/admin/channel.backup | grep -c 'channel.backup')
done
clear
echo "OK - channel.backup file found."
fi
##### FALLBACK UNTIL config.scripts/lnd.initwallet.py WORKS
echo "****************************************************************************"
echo "Helping Instructions --> for recovering a LND Wallet"
echo "****************************************************************************"
echo "A) For 'Wallet Password' use your old PASSWORD C"
echo "B) For 'cipher seed mnemonic' answere 'y' and then enter your seed words"
echo "C) On 'cipher seed passphrase' ONLY enter PASSWORD D if u used it on create"
echo "D) On 'address look-ahead' only enter more than 2500 had lots of channels"
echo "****************************************************************************"
echo ""
sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net create 2>/home/admin/.error.tmp
error=`cat /home/admin/.error.tmp`
rm /home/admin/.error.tmp 2>/dev/null
if [ ${#error} -gt 0 ]; then
echo ""
echo "!!! FAIL !!! SOMETHING WENT WRONG:"
echo "${error}"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
echo "Press ENTER to retry ..."
read key
echo "Starting RETRY ..."
/home/admin/70initLND.sh
exit 1
fi
/home/admin/70initLND.sh
exit 1
fi
##### DEACTIVATED UNTIL config.scripts/lnd.initwallet.py WORKS
# # trigger wallet recovery
# source <(python /home/admin/config.scripts/lnd.initwallet.py seed ${passwordC} ${wordstring} /home/admin/channel.backup ${passwordD})
#
# # WIN/FAIL User feedback
# # on success the python script should return the seed words again
# if [ ${#seedwords} -gt 1 ]; then
# dialog --title " SUCCESS " --msgbox "
#Looks good :) LND was able to recover the wallet.
# " 7 53
# else
# if [ ${#err} -eq 0 ]; then
# echo
# echo "FAIL!! Unkown Error - check output above for any hints and report to development."
# echo "PRESS ENTER to try again."
# read key
# /home/admin/70initLND.sh
# exit 1
# else
# whiptail --title " FAIL " --msgbox "
#Something went wrong - see info below:
#${err}
#${errMore}
# " 13 72
# /home/admin/70initLND.sh
# exit 1
# fi
# fi
fi # END OLD WALLET
else
echo "OK - LND wallet already exists."
fi
dialog --pause " Waiting for LND - please wait .." 8 58 60
###### Copy LND macaroons to admin
############################
# Copy LND macaroons to admin
############################
echo ""
echo "*** Copy LND Macaroons to user admin ***"
macaroonExists=$(sudo -u bitcoin ls -la /home/bitcoin/.lnd/data/chain/${network}/${chain}net/admin.macaroon 2>/dev/null | grep -c admin.macaroon)
@ -253,11 +480,49 @@ if [ ${locked} -gt 0 ]; then
else
echo "OK - Wallet is already unlocked"
fi
echo ""
###### USE CHANNEL.BACKUP FILE IF AVAILABLE
echo "*** channel.backup Recovery ***"
gotSCB=$(ls /home/admin/channel.backup | grep -c 'channel.backup')
if [ ${gotSCB} -eq 1 ]; then
lncli restorechanbackup --multi_file=/home/admin/channel.backup 2>/home/admin/.error.tmp
error=`cat /home/admin/.error.tmp`
rm /home/admin/.error.tmp 2>/dev/null
if [ ${#error} -gt 0 ]; then
echo ""
echo "!!! FAIL !!! SOMETHING WENT WRONG:"
notMachtingSeed=$(echo $error | grep -c 'unable to unpack chan backup')
if [ ${notMachtingSeed} -gt 0 ]; then
echo "--> unable to unpack chan backup"
echo "The WORD SEED is not matching the channel.backup file."
echo "Either there was an error in the word seed list or"
echo "or the channel.backup file is from another RaspiBlitz."
else
echo "${error}"
fi
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo ""
echo "You can try after full setup to restore channel.backup file again with:"
echo "lncli restorechanbackup --multi_file=/home/admin/channel.backup"
echo "Press ENTER to continue for now ..."
read key
exit 1
fi
else
echo "NO /home/admin/channel.backup file - skipping SCB"
fi
echo "PRESS ENTER"
read key
# set SetupState (scan is done - so its 80%)
sudo sed -i "s/^setupStep=.*/setupStep=80/g" /home/admin/raspiblitz.info
###### finishSetup
sudo ./90finishSetup.sh
sudo ./95finalSetup.sh
sudo ./95finalSetup.sh

101
home.admin/80scanLND.old.sh

@ -0,0 +1,101 @@
#!/bin/bash
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
### USER PI AUTOSTART (LCD Display)
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
# parse the actual scanned height progress from LND logs
item=0
blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo)
chain="$(echo "${blockchaininfo}" | jq -r '.chain')"
## TRY to get the actual progress height of scanning
# 1) First try the "Rescanned through block" - it seems to happen if it restarts
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Rescanned through block" | tail -n1 | cut -d ']' -f2 | cut -d '(' -f2 | tr -dc '0-9')
action="Rescanning"
# 2) Second try the "Caught up to height" - thats the usual on first scan start
if [ ${#item} -eq 0 ]; then
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Caught up to height" | tail -n1 | cut -d ']' -f2 | tr -dc '0-9')
action="Catching-Up"
fi
# 3) Third try the "LNWL: Filtering block" - thats the usual on later starts
if [ ${#item} -eq 0 ]; then
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "LNWL: Filtering block" | tail -n1 | cut -d ' ' -f7 | tr -dc '0-9')
action="Filtering"
fi
# if no progress info
online=1
if [ ${#item} -eq 0 ]; then
item="?"
# check if offline
online=$(ping 1.0.0.1 -c 1 -W 2 | grep -c '1 received')
if [ ${online} -eq 0 ]; then
# re-test with other server
online=$(ping 8.8.8.8 -c 1 -W 2 | grep -c '1 received')
fi
if [ ${online} -eq 0 ]; then
# re-test with other server
online=$(ping 208.67.222.222 -c 1 -W 2 | grep -c '1 received')
fi
fi
# get total number of blocks
total=$(echo "${blockchaininfo}" | jq -r '.blocks')
# put scanstate
scanstate="${item}/${total}"
# get blockchain sync progress
progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')"
#progress=$(echo "${progress}*100" | bc)
progress=$(echo $progress | awk '{printf( "%.2f%%", 100 * $1)}')
# check if blockchain is still syncing
heigh=6
width=44
isInitialChainSync=$(echo "${blockchaininfo}" | grep 'initialblockdownload' | grep "true" -c)
isWaitingBlockchain=$( sudo -u bitcoin tail -n 2 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Waiting for chain backend to finish sync" -c )
if [ ${isWaitingBlockchain} -gt 0 ]; then
isInitialChainSync=1
fi
if [ ${online} -eq 0 ]; then
heigh=7
width=44
infoStr=$(echo " Waiting INTERNET CONNECTION\n RaspiBlitz cannot ping 1.0.0.1\n Local IP is ${localip}\n Please check cables and router.")
elif [ ${isInitialChainSync} -gt 0 ]; then
heigh=7
infoStr=" Waiting for final Blockchain Sync\n Progress: ${progress} \n Please wait - this can take some time.\n ssh admin@${localip}\n Password A"
if [ "$USER" = "admin" ]; then
heigh=6
width=53
infoStr=$(echo " Waiting for final Blockchain Sync\n Progress: ${progress} %\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.")
fi
else
heigh=7
# check if wallet has any UTXO
# reason see: https://github.com/lightningnetwork/lnd/issues/2326
txlines=$(sudo -u bitcoin lncli listchaintxns 2>/dev/null | wc -l)
# has just 4 lines if empty
if [ ${txlines} -eq 4 ]; then
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n re-rescan every start until funding\n ssh admin@${localip}\n Password A")
else
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n Please wait - this can take some time\n ssh admin@${localip}\n Password A")
if [ "$USER" = "admin" ]; then
heigh=6
width=53
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.")
fi
fi
fi
# display progress to user
sleep 3
temp=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc)
dialog --title " ${network} / ${chain} " --backtitle "RaspiBlitz (${hostname}) CPU: ${temp}°C" --infobox "${infoStr}" ${heigh} ${width}

184
home.admin/80scanLND.sh

@ -1,101 +1,123 @@
#!/bin/bash
source /home/admin/_version.info
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
### USER PI AUTOSTART (LCD Display)
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
source <(sudo /home/admin/config.scripts/blitz.statusscan.sh)
# parse the actual scanned height progress from LND logs
item=0
blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo)
chain="$(echo "${blockchaininfo}" | jq -r '.chain')"
adminStr="ssh admin@${localIP} ->Password A"
if [ "$USER" == "admin" ]; then
adminStr="Use CTRL+c to EXIT to Terminal"
fi
## TRY to get the actual progress height of scanning
if [ ${bitcoinActive} -eq 0 ] || [ ${#bitcoinErrorFull} -gt 0 ]; then
# 1) First try the "Rescanned through block" - it seems to happen if it restarts
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Rescanned through block" | tail -n1 | cut -d ']' -f2 | cut -d '(' -f2 | tr -dc '0-9')
action="Rescanning"
####################
# On Bitcoin Error
####################
# 2) Second try the "Caught up to height" - thats the usual on first scan start
if [ ${#item} -eq 0 ]; then
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Caught up to height" | tail -n1 | cut -d ']' -f2 | tr -dc '0-9')
action="Catching-Up"
fi
height=5
width=43
title="Blockchain Info"
if [ ${uptime} -gt 300 ]; then
infoStr=" The ${network}d service is not running.\n Login for more details:"
if [ "$USER" == "admin" ]; then
echo ""
echo "*****************************************"
echo "* The ${network}d service is not running."
echo "*****************************************"
echo "If you just started some config/setup, this might be OK."
echo
if [ ${#bitcoinErrorFull} -gt 0 ]; then
echo "More Error Detail:"
echo ${bitcoinErrorFull}
echo
fi
echo "-> To start ${network}d run: sudo systemctl start ${network}d"
echo "-> To force Main Menu run: /home/admin/00mainMenu.sh"
echo "-> Use following command to debug: /home/admin/XXdebugLogs.sh"
echo ""
exit 1
fi
else
height=6
if [ ${#bitcoinErrorShort} -eq 0 ]; then
bitcoinErrorShort="Initial Startup - Please Wait"
fi
infoStr=" The ${network}d service is starting:\n ${bitcoinErrorShort}\n Login for more details:"
if [ "$USER" == "admin" ]; then
infoStr=" The ${network}d service is starting:\n ${bitcoinErrorShort}\n Please wait up to 5min ..."
fi
fi
# 3) Third try the "LNWL: Filtering block" - thats the usual on later starts
if [ ${#item} -eq 0 ]; then
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "LNWL: Filtering block" | tail -n1 | cut -d ' ' -f7 | tr -dc '0-9')
action="Filtering"
fi
elif [ ${lndActive} -eq 0 ] || [ ${#lndErrorFull} -gt 0 ]; then
# if no progress info
online=1
if [ ${#item} -eq 0 ]; then
item="?"
####################
# On LND Error
####################
# check if offline
online=$(ping 1.0.0.1 -c 1 -W 2 | grep -c '1 received')
if [ ${online} -eq 0 ]; then
# re-test with other server
online=$(ping 8.8.8.8 -c 1 -W 2 | grep -c '1 received')
fi
if [ ${online} -eq 0 ]; then
# re-test with other server
online=$(ping 208.67.222.222 -c 1 -W 2 | grep -c '1 received')
height=5
width=43
title="Lightning Info"
if [ ${uptime} -gt 300 ]; then
infoStr=" The LND service is not running.\n Login for more details:"
if [ "$USER" == "admin" ]; then
echo ""
echo "*********************************"
echo "* The LND service is not running."
echo "*********************************"
echo "If you just started some config/setup, this might be OK."
echo
if [ ${#lndErrorFull} -gt 0 ]; then
echo "More Error Detail:"
echo ${lndErrorFull}
echo
fi
echo "-> To start LND run: sudo systemctl start lnd"
echo "-> To force Main Menu run: /home/admin/00mainMenu.sh"
echo "-> Use following command to debug: /home/admin/XXdebugLogs.sh"
echo ""
exit 1
fi
else
infoStr=" The LND service is starting.\n Login for more details:"
if [ "$USER" == "admin" ]; then
infoStr=" The LND service is starting.\n Please wait up to 5min ..."
fi
fi
fi
else
# get total number of blocks
total=$(echo "${blockchaininfo}" | jq -r '.blocks')
# put scanstate
scanstate="${item}/${total}"
# get blockchain sync progress
progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')"
#progress=$(echo "${progress}*100" | bc)
progress=$(echo $progress | awk '{printf( "%.2f%%", 100 * $1)}')
# check if blockchain is still syncing
heigh=6
width=44
isInitialChainSync=$(echo "${blockchaininfo}" | grep 'initialblockdownload' | grep "true" -c)
isWaitingBlockchain=$( sudo -u bitcoin tail -n 2 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Waiting for chain backend to finish sync" -c )
if [ ${isWaitingBlockchain} -gt 0 ]; then
isInitialChainSync=1
fi
if [ ${online} -eq 0 ]; then
heigh=7
width=44
infoStr=$(echo " Waiting INTERNET CONNECTION\n RaspiBlitz cannot ping 1.0.0.1\n Local IP is ${localip}\n Please check cables and router.")
elif [ ${isInitialChainSync} -gt 0 ]; then
heigh=7
infoStr=" Waiting for final Blockchain Sync\n Progress: ${progress} %\n Please wait - this can take some time.\n ssh admin@${localip}\n Password A"
if [ "$USER" = "admin" ]; then
heigh=6
width=53
infoStr=$(echo " Waiting for final Blockchain Sync\n Progress: ${progress} %\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.")
####################
# Sync Progress
####################
# basic dialog info
height=6
width=43
title="Node is Syncing (${scriptRuntime})"
# formatting progress values
if [ ${#syncProgress} -eq 0 ]; then
syncProgress="waiting"
elif [ ${#syncProgress} -lt 6 ]; then
syncProgress=" ${syncProgress} %"
else
syncProgress="${syncProgress} %"
fi
else
heigh=7
# check if wallet has any UTXO
# reason see: https://github.com/lightningnetwork/lnd/issues/2326
txlines=$(sudo -u bitcoin lncli listchaintxns 2>/dev/null | wc -l)
# has just 4 lines if empty
if [ ${txlines} -eq 4 ]; then
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n re-rescan every start until funding\n ssh admin@${localip}\n Password A")
if [ ${#scanProgress} -eq 0 ]; then
scanProgress="waiting"
elif [ ${#scanProgress} -lt 6 ]; then
scanProgress=" ${scanProgress} %"
else
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n Please wait - this can take some time\n ssh admin@${localip}\n Password A")
if [ "$USER" = "admin" ]; then
heigh=6
width=53
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.")
fi
scanProgress="${scanProgress} %"
fi
# setting info string
infoStr=" Blockchain Progress : ${syncProgress}\n Lightning Progress : ${scanProgress}\n Please wait - this can take some time"
fi
# display progress to user
sleep 3
temp=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc)
dialog --title " ${network} / ${chain} " --backtitle "RaspiBlitz (${hostname}) CPU: ${temp}°C" --infobox "${infoStr}" ${heigh} ${width}
# display info to user
dialog --title " ${title} " --backtitle "RaspiBlitz ${codeVersion} ${hostname} / ${network} / ${chain} / ${tempCelsius}°C" --infobox "${infoStr}\n ${adminStr}" ${height} ${width}

4
home.admin/90finishSetup.sh

@ -1,8 +1,8 @@
#!/bin/bash
echo ""
# add bonus scripts
/home/admin/91addBonus.sh
# add bonus scripts (auto install deactivated to reduce third party repos)
# /home/admin/91addBonus.sh
###### SWAP & FS
echo ""

6
home.admin/95finalSetup.sh

@ -1,12 +1,12 @@
#!/bin/bash
echo ""
# set raspiblitz config file
configFile="/mnt/hdd/raspiblitz.conf"
# load setup config
source /home/admin/raspiblitz.info
# in case the config already exists
source /mnt/hdd/raspiblitz.conf 2>/dev/null
# load version
source /home/admin/_version.info

133
home.admin/99checkUpdate.sh

@ -0,0 +1,133 @@
#!/bin/bash
# load raspiblitz config data
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
source /home/admin/_version.info
clear
# get latest release verison from GitHub
sudo curl -s -X GET https://raw.githubusercontent.com/rootzoll/raspiblitz/master/home.admin/_version.info > /home/admin/.version.tmp
gitHubVersionMain=$(cut -d"=" -f2 /home/admin/.version.tmp | cut -d'"' -f2 | cut -d"." -f1 | egrep "^[0-9]")
gitHubVersionSub=$(cut -d"=" -f2 /home/admin/.version.tmp | cut -d'"' -f2 | cut -d"." -f2 | egrep "^[0-9]")
sudo shred /home/admin/.version.tmp
sudo rm /home/admin/.version.tmp 2>/dev/null
# check valid version info
if [ ${#gitHubVersionMain} -eq 0 ] || [ ${#gitHubVersionSub} -eq 0 ]; then
echo "FAIL: Was not able to get latest release Version from GitHub."
echo "PRESS ENTER to continue."
read key
exit 1
fi
# get local version
localVersionMain=$(cut -d"=" -f2 /home/admin/_version.info | cut -d'"' -f2 | cut -d"." -f1 | egrep "^[0-9]")
localVersionSub=$(cut -d"=" -f2 /home/admin/_version.info | cut -d'"' -f2 | cut -d"." -f2 | egrep "^[0-9]")
echo "github version: ${gitHubVersionMain}.${gitHubVersionSub}"
echo "local version: ${localVersionMain}.${localVersionSub}"
# compare versions
newerVersionAvailable=0
if [ ${gitHubVersionMain} -gt ${localVersionMain} ]; then
echo "Main version is higher ..."
newerVersionAvailable=1
else
if [ ${gitHubVersionMain} -lt ${localVersionMain} ]; then
echo "Strange that GutHub main version is lower then local - you maybe using a early release."
elif [ ${gitHubVersionSub} -gt ${localVersionSub} ]; then
echo "Sub version is higher ..."
newerVersionAvailable=1
fi
fi
# give feedback on version number
if [ ${newerVersionAvailable} -eq 0 ]; then
dialog --title " Update Check " --yes-button "OK" --no-button "Update Anyway" --yesno "
OK. You are running the newest version of RaspiBlitz.
" 7 57
if [ $? -eq 0 ]; then
exit 1
fi
clear
else
whiptail --title "Update Check" --yes-button "Yes" --no-button "Not Now" --yesno "
There is a new Version of RaspiBlitz available.
You are running: ${localVersionMain}.${localVersionSub}
New Version: ${gitHubVersionMain}.${gitHubVersionSub}
Do you want more Information on how to update?
" 12 52
if [ $? -eq 1 ]; then
exit 1
fi
fi
whiptail --title "Update Instructions" --yes-button "Not Now" --no-button "Start Update" --yesno "To update your RaspiBlitz to a new version:
- Download the new SD card image to your laptop:
https://github.com/rootzoll/raspiblitz
- Flash that SD card image to a new SD card
- Choose 'Start Update' below.
No need to close channels or download blockchain again.
Do you want to start the Update now?
" 16 62
if [ $? -eq 0 ]; then
exit 1
fi
whiptail --title "LND Data Backup" --yes-button "Download Backup" --no-button "Skip" --yesno "
Before we start the RaspiBlitz Update process,
its recommended to make a backup of all your LND Data
and download that file to your laptop.
Do you want to download LND Data Backup now?
" 12 58
if [ $? -eq 0 ]; then
clear
echo "*************************************"
echo "* PREPARING LND BACKUP DOWNLOAD"
echo "*************************************"
echo "please wait .."
sleep 2
/home/admin/config.scripts/lnd.rescue.sh backup
echo
echo "PRESS ENTER to continue once your done downloading."
read key
else
clear
echo "*************************************"
echo "* JUST MAKING BACKUP TO OLD SD CARD"
echo "*************************************"
echo "please wait .."
sleep 2
/home/admin/config.scripts/lnd.rescue.sh backup no-download
fi
whiptail --title "READY TO UPDATE?" --yes-button "START UPDATE" --no-button "Cancel" --yesno "If you start the update: The RaspiBlitz will power down.
Once the LCD is white and no LEDs are blicking anymore:
- Remove the Power from RaspiBlitz
- Exchange the old with the new SD card
- Connect Power back to the RaspiBlitz
- Follow the instructions on the LCD
Do you have the SD card with the new version image ready
and do you WANT TO START UPDATE NOW?
" 16 62
if [ $? -eq 1 ]; then
dialog --title " Update Canceled " --msgbox "
OK. RaspiBlitz will NOT update now.
" 7 39
sudo systemctl start lnd
exit 1
fi
clear
sudo shutdown now

103
home.admin/BBcashoutWallet.sh

@ -22,33 +22,32 @@ if [ ${#openChannels} -eq 0 ]; then
echo "Still starting up, is locked or is not running?"
echo "Try later, try reboot or check ./XXdebugLogs.sh"
echo "************************************************"
echo "Press ENTER to return to main menu."
read key
exit 1
fi
if [ ${openChannels} -gt 0 ]; then
dialog --title 'Info' --msgbox 'You still have funds in open Lightning Channels.\nUse CLOSEALL first if you want to cashout all funds.\nNOTICE: Just confirmed on-chain funds can be moved.' 7 58
echo "please wait ..."
whiptail --title 'Info' --yes-button='Cashout Anyway' --no-button='Go Back' --yesno 'You still have funds in open Lightning Channels.\nUse CLOSEALL first if you want to cashout all funds.\nNOTICE: Just confirmed on-chain funds can be moved' 10 56
if [ $? -eq 1 ]; then
exit 1
fi
echo "..."
fi
# check if money is waiting to get confirmed
unconfirmed=$(lncli --chain=${network} --network=${chain}net walletbalance | grep '"unconfirmed_balance"' | cut -d '"' -f4)
if [ ${unconfirmed} -gt 0 ]; then
dialog --title 'Info' --msgbox "Still waiting confirmation for ${unconfirmed} sat.\nNOTICE: Just confirmed on-chain funds can be moved." 6 58
echo "please wait ..."
fi
# get available amount in on-chain wallet
maxAmount=$(lncli --chain=${network} --network=${chain}net walletbalance | grep '"confirmed_balance"' | cut -d '"' -f4)
if [ ${maxAmount} -eq 0 ]; then
dialog --title 'Info' --msgbox "You have 0 moveable funds available.\nNOTICE: Just confirmed on-chain funds can be moved." 6 58
exit 1
whiptail --title 'Info' --yes-button='Cashout Anyway' --no-button='Go Back' --yesno "Still waiting confirmation for (some of) your funds.\nNOTICE: Just confirmed on-chain funds can be moved." 8 58
if [ $? -eq 1 ]; then
exit 1
fi
echo "..."
fi
# let user enter the address
l1="Enter on-chain address to send confirmed funds to:"
l2="You will send: ${maxAmount} sat"
l3="Maximal fee: 20000 sat (wil be subtracted)"
dialog --title "Where to send funds?" \
--inputbox "$l1\n$l2\n$l3" 9 75 2>$_temp
dialog --title "Where to send funds?" --inputbox "\n$l1\n" 9 75 2>$_temp
if test $? -eq 0
then
echo "ok pressed"
@ -60,63 +59,33 @@ address=$(cat $_temp | xargs)
shred $_temp
if [ ${#address} -eq 0 ]; then
echo "FAIL - not a valid address (${address})"
echo "Press ENTER to return to main menu."
read key
exit 1
fi
# TODO: check address is valid for network and chain
clear
echo "******************************"
echo "Send on-chain Funds"
echo "Sweep all possible Funds"
echo "******************************"
tryAgain=1
count=1
while [ ${tryAgain} -eq 1 ]
do
sleep 1
fee=$(($count * 1000))
amount=$(($maxAmount - $fee))
echo ""
echo "TRY #${count} ---> with max fee ${fee} sat:"
# execute command
command="lncli --chain=${network} --network=${chain}net sendcoins --addr ${address} --amt ${amount} --conf_target 3"
echo "$command"
result=$($command 2>$_error)
error=`cat ${_error}`
#error="sim error: insufficient funds available to construct transaction"
#result=""
if [ ${#result} -eq 0 ]; then
# fail - retry on 'insufficient funds available to construct transaction'
echo "FAIL: $error"
tryAgain=$(echo "${error}" | grep -c 'insufficient funds available to construct transaction')
if [ ${tryAgain} -eq 0 ]; then
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FINAL FAIL --> Was not able to send transaction (see error above)"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
fi
else
# success
echo "$result"
echo ""
echo "********************************************************************"
echo "OK --> send ${amount} sat to address + ${fee} sat fees max"
echo "********************************************************************"
tryAgain=0
fi
# abort aftzer 20 tries
count=$(($count + 1))
if [ ${count} -gt 20 ]; then
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FINAL FAIL --> Was not able to send transaction with max 20000 sat"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
tryAgain=0
fi
done
exit 1
# execute command
command="lncli --chain=${network} --network=${chain}net sendcoins --sweepall --addr=${address} --conf_target=6"
echo "$command"
result=$($command 2>$_error)
error=`cat ${_error}`
echo ""
if [ ${#error} -gt 0 ]; then
echo "FAIL: $error"
echo ""
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "FAIL --> Was not able to send transaction (see error above)"
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
else
echo "Result: $result"
echo ""
echo "********************************************************************"
fi
echo ""
echo "Press ENTER to return to main menu."
read key

2
home.admin/XXsyncScripts.sh

@ -61,7 +61,7 @@ else
echo "******************************************"
fi
echo "COPYING from GIT-Directory to /home/admin/ .."
sudo -u admin cp --verbose -r -f /home/admin/raspiblitz/home.admin/*.* /home/admin
sudo -u admin cp -r -f /home/admin/raspiblitz/home.admin/*.* /home/admin
sudo -u admin chmod +x /home/admin/*.sh
sudo -u admin chmod +x /home/admin/*.py
sudo -u admin chmod +x /home/admin/config.scripts/*.sh

149
home.admin/_background.sh

@ -22,6 +22,10 @@ fi
echo "_background.sh STARTED"
# monitor lost LND sync
syncedSince=0
lastSyncState=0
counter=0
while [ 1 ]
do
@ -146,6 +150,151 @@ do
fi
###############################
# SCB Monitoring
###############################
# check every 1min
recheckSCB=$(($counter % 60))
if [ ${recheckSCB} -eq 1 ]; then
echo "SCB Monitoring ..."
source ${configFile}
# check if channel.backup exists
scbExists=$(sudo ls /mnt/hdd/lnd/data/chain/${network}/${chain}net/channel.backup 2>/dev/null | grep -c 'channel.backup')
if [ ${scbExists} -eq 1 ]; then
echo "Found Channel Backup File .. check if changed .."
md5checksumORG=$(sudo md5sum /mnt/hdd/lnd/data/chain/${network}/${chain}net/channel.backup 2>/dev/null | head -n1 | cut -d " " -f1)
md5checksumCPY=$(sudo md5sum /home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup 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/.lnd/data/chain/${network}/${chain}net/ 2>/dev/null
sudo cp /mnt/hdd/lnd/data/chain/${network}/${chain}net/channel.backup /home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup
echo "OK channel.backup copied to '/home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup'"
# check if a SCP backup target is set
# paramter in raspiblitz.conf:
# scpBackupTarget='[USER]@[SERVER]:[DIRPATH-WITHOUT-ENDING-/]'
# On target server add the public key of your RaspiBlitz to the authorized_keys for the user
# https://www.linode.com/docs/security/authentication/use-public-key-authentication-with-ssh/
if [ ${#scpBackupTarget} -gt 0 ]; then
echo "--> Offsite-Backup SCP Server"
# 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 whithout ignoriing known host, script might not run thru and that way: no offsite channel backup
sudo scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null /home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup ${scpBackupTarget}/channel.backup
result=$?
if [ ${result} -eq 0 ]; then
echo "OK - SCP Backup exited with 0"
else
echo "FAIL - SCP Backup exited with ${result}"
fi
fi
# check if a DropBox backup target is set
# paramter 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} /home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup)
if [ ${#err} -gt 0 ]; then
echo "FAIL - ${err}"
echo "${errMore}"
else
echo "OK - ${upload}"
fi
fi
else
echo "Channel Backup File not changed."
fi
else
echo "No Channel Backup File .."
fi
fi
###############################
# LND MONITOR LOST SYNC
###############################
# check every 5min
recheckSync=$(($counter % 300))
if [ ${recheckSync} -eq 1 ]; then
source ${configFile}
echo "LND MONITOR LOST SYNC ..."
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
echo "lndSynced(${lndSynced})"
echo "syncedSince(${syncedSince})"
echo "lastSyncState(${lastSyncState})"
if [ ${lndSynced} -eq ${lastSyncState} ]; then
echo "no sync change"
if [ ${lndSynced} -eq 1 ]; then
echo "all is good - LND still in sync now for:"
actualSecondsTimestamp=$(date +%s)
secondsInSync=$(echo "${actualSecondsTimestamp}-"${syncedSince} | bc)
#echo "${secondsInSync} seconds"
# when >10min in sync
if [ ${secondsInSync} -gt 3600 ]; then
echo "LND in sync for longer then 1 hour"
if [ "${backupTorrentSeeding}" == "on" ]; then
echo "Backup Torrent Seeding is ON - check if already running"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseSeeding}" == "0" ] || [ "${updateSeeding}" == "0" ]; then
echo "---> STARTING Backup Torrent Seeding"
sudo -u admin /home/admin/50torrentHDD.sh backup-torrent-hosting
fi
fi
fi
else
echo "still not in sync"
if [ ${syncedSince} -gt 0 ]; then
echo "was in sync at least once since rinning but lost now for:"
actualSecondsTimestamp=$(date +%s)
secondsOutOfSync=$(echo "${actualSecondsTimestamp}-"${syncedSince} | bc)
echo "${secondsOutOfSync} seconds"
# when >1h out of sync
#if [ ${secondsOutOfSync} -gt 3600 ]; then
# echo "!!!! LND fell out of sync for longer then 1 hour !!!"
# TODO: When auto-unlock is ON --> consider implementing restart (this sometimes help)
#fi
fi
fi
else
echo "sync change detected"
if [ ${lastSyncState} -eq 1 ] && [ ${lndSynced} -eq 0 ]; then
echo "--> LND SYNC LOST"
if [ "${backupTorrentSeeding}" == "on" ]; then
#echo "Backup Torrent Seeding is ON - check if still running"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseSeeding}" == "1" ] || [ "${updateSeeding}" == "1" ]; then
echo "---> STOPPING Backup Torrent Seeding"
sudo -u admin /home/admin/50torrentHDD.sh stop
fi
fi
else
if [ ${syncedSince} -eq 0 ]; then
echo "--> LND SYNC GAINED"
else
echo "--> LND SYNC RECOVERED"
fi
syncedSince=$(date +%s)
fi
fi
lastSyncState=${lndSynced}
fi
###############################
# LND AUTO-UNLOCK
###############################

9
home.admin/_bootstrap.sh

@ -435,14 +435,5 @@ sed -i "s/^state=.*/state=stresstest/g" ${infoFile}
sed -i "s/^message=.*/message='Testing Hardware 60s'/g" ${infoFile}
sudo /home/admin/config.scripts/blitz.stresstest.sh /home/admin/stresstest.report
################################
# BACKUP TORRENT SEEDING
################################
if [ "${backupTorrentSeeding}" == "on" ]; then
echo "Starting BACKUP TORRENT HOSTING in background (after 6 hours) ..." >> $logFile
( sleep 6h ; sudo -u admin /home/admin/50torrentHDD.sh backup-torrent-hosting ) &
fi
echo "DONE BOOTSTRAP" >> $logFile
exit 0

2
home.admin/_commands.sh

@ -6,5 +6,5 @@
# calls the the raspiblitz mainmenu
function raspiblitz() {
cd /home/admin
./00mainMenu.sh
./00raspiblitz.sh
}

118
home.admin/config.scripts/blitz.statusscan.sh

@ -0,0 +1,118 @@
#!/bin/bash
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
# 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)
# macke sure temp folder on HDD is available and fro all usable
sudo mkdir /mnt/hdd/temp 2>/dev/null
sudo chmod 777 -R /mnt/hdd/temp 2>/dev/null
# localIP
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
echo "localIP='${localip}'"
# temp
tempC=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc)
echo "tempCelsius='${tempC}'"
# uptime in seconds
uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime)
echo "uptime=${uptime}"
# 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 -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/mnt/hdd/temp/.bitcoind.out 2>/mnt/hdd/temp/.bitcoind.error
# check if error on request
blockchaininfo=$(cat /mnt/hdd/temp/.bitcoind.out 2>/dev/null)
bitcoinError=$(cat /mnt/hdd/temp/.bitcoind.error 2>/dev/null)
#rm /mnt/hdd/temp/.bitcoind.error 2>/dev/null
if [ ${#bitcoinError} -gt 0 ]; then
echo "bitcoinErrorFull='${bitcoinError}'"
bitcoinErrorShort=$(echo ${bitcoinError/error*:/} | sed 's/[^a-zA-Z0-9 ]//g')
echo "bitcoinErrorShort='${bitcoinErrorShort}'"
else
##############################
# 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
fi
# is LND running
lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running)
# TODO: check how long running ... try to find out if problem on starting
echo "lndActive=${lndRunning}"
if [ ${lndRunning} -eq 1 ]; then
# get LND info
lndinfo=$(sudo -u bitcoin lncli getinfo 2>/mnt/hdd/temp/.lnd.error)
# check if error on request
lndErrorFull=$(cat /mnt/hdd/temp/.lnd.error 2>/dev/null)
#rm /mnt/hdd/temp/.lnd.error 2>/dev/null
if [ ${#lndError} -gt 0 ]; then
echo "lndErrorFull='${lndErrorFull}'"
echo "lndErrorShort=''"
else
# 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')
echo "scanTimestamp=${scanTimestamp}"
if [ ${#scanTimestamp} -gt 0 ]; then
scanDate=$(date -d @${scanTimestamp})
echo "scanDate='${scanDate}'"
# calculate LND scan progress by seconds since Genesisblock
genesisTimestamp=1230940800
nowTimestamp=$(date +%s)
totalSeconds=$(echo "${nowTimestamp}-${genesisTimestamp}" | bc)
scannedSeconds=$(echo "${scanTimestamp}-${genesisTimestamp}" | bc)
scanProgress=$(echo "scale=2; $scannedSeconds*100/$totalSeconds" | bc)
echo "scanProgress=${scanProgress}"
fi
fi
fi
# check if online if problem with other stuff
# info on scan run time
endTime=$(date +%s)
runTime=$(echo "${endTime}-${startTime}" | bc)
echo "scriptRuntime=${runTime}"

99
home.admin/config.scripts/dropbox.upload.sh

@ -0,0 +1,99 @@
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# script to upload a file to DropBox (without third party libs)"
echo "# dropbox.upload.sh upload [AUTHTOKEN] [FILEPATH]"
echo "# dropbox.upload.sh check [AUTHTOKEN]"
echo "# for Dropbox Setup with Authtoken, see:"
echo "# https://gist.github.com/vindard/e0cd3d41bb403a823f3b5002488e3f90"
echo "err='just informational output'"
exit 1
fi
# get first parameter
MODE="$1"
if [ "${MODE}" == "check" ]; then
# get needed second parameter
DROPBOX_APITOKEN="$2"
if [ ${#DROPBOX_APITOKEN} -eq 0 ]; then
echo "err='missing Parameter AUTHTOKEN'"
exit 1
fi
# run API check
curl -s -X POST https://api.dropboxapi.com/2/users/get_current_account \
--header "Authorization: Bearer "$DROPBOX_APITOKEN | grep rror
if [[ ! $? -eq 0 ]] ; then
echo "# Dropbox API Token worked"
echo "check=1"
else
echo "# Invalid Dropbox API Token!"
echo "check=0"
fi
elif [ "${MODE}" == "upload" ]; then
# get needed second parameter
DROPBOX_APITOKEN="$2"
if [ ${#DROPBOX_APITOKEN} -eq 0 ]; then
echo "err='missing Parameter AUTHTOKEN'"
exit 1
fi
# get needed third parameter
SOURCEFILE="$3"
if [ ${#SOURCEFILE} -eq 0 ]; then
echo "err='missing Parameter SOURCEFILE'"
exit 1
fi
source /mnt/hdd/raspiblitz.conf
if [ ${#hostname} -eq 0 ]; then
hostname="raspiblitz"
fi
DEVICE=$(echo "${hostname}" | awk '{print tolower($0)}' | sed -e 's/ /-/g')
BACKUPFOLDER=lndbackup-$DEVICE
FILENAME=$(basename "${SOURCEFILE}")
sudo curl -s -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer "${DROPBOX_APITOKEN}"" \
--header "Dropbox-API-Arg: {\"path\": \"/"$BACKUPFOLDER"/"$FILENAME"\",\"mode\": \"overwrite\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @$SOURCEFILE > /home/admin/.dropbox.tmp
safeResponse=$(sed 's/[^a-zA-Z0-9 ]//g' /home/admin/.dropbox.tmp)
sudo shred /home/admin/.dropbox.tmp
sudo rm /home/admin/.dropbox.tmp 2>/dev/null
success=$(echo "${safeResponse}" | grep -c 'servermodified')
sizeZero=$(echo "${safeResponse}" | grep -c 'size 0')
if [ ${sizeZero} -gt 0 ]; then
echo "# Upload happened but is size zero"
echo "upload=0"
echo "err='size zero'"
echo "errMore='${safeResponse}'"
elif [ ${success} -gt 0 ] ; then
echo "# Successfully uploaded!"
echo "upload=1"
else
echo "# Unknown Error"
echo "upload=0"
echo "err='unknown'"
echo "errMore='${safeResponse}'"
fi
else
echo "err='unkown mode'"
exit 1
fi

43
home.admin/config.scripts/internet.sshpubkey.sh

@ -0,0 +1,43 @@
#!/bin/bash
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# config script to init/show/transfer ssh pub keys."
echo "# To init and return pubkey as data:"
echo "# internet.sshpubkey.sh get"
echo "# To init and transfer ssh-pub to a authorizedkey of remote server:"
echo "# internet.sshpubkey.sh transfer [REMOTEUSER]@[REMOTESERVER]"
echo "err='just informational output'"
exit 1
fi
# 1. parameter MODE
MODE="$1"
# root as default user
# its used for all ssh tunnel/back action
# make sure the ssh keys for that user are initialized
sshKeysExist=$(sudo ls /root/.ssh/id_rsa.pub | grep -c 'id_rsa.pub')
if [ ${sshKeysExist} -eq 0 ]; then
echo "# generation SSH keys for user root"
sudo mkdir /root/.ssh 2>/dev/null
sudo sh -c 'yes y | sudo ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""'
fi
if [ "${MODE}" == "get" ]; then
# get ssh pub key and print
sshPubKey=$(sudo cat /root/.ssh/id_rsa.pub)
echo "user='root'"
echo "sshPubKey='${sshPubKey}'"
elif [ "${MODE}" == "transfer" ]; then
sudo ssh-copy-id $2
else
echo "err='paremeter not known - run with -help'"
fi

97
home.admin/config.scripts/lnd.initwallet.py

@ -37,9 +37,28 @@ if mode=="new":
elif mode=="seed":
print("err='TODO: implement creating from seed'")
if len(sys.argv)>2:
walletpassword=sys.argv[2]
if len(walletpassword)<8:
print("err='wallet password is too short'")
sys.exit(1)
else:
print("err='not correct amount of parameter'")
sys.exit(1)
if len(sys.argv)>3:
seedwordString=sys.argv[3]
seedwords=seedwordString.split(",")
if len(seedwords)<24:
print("err='not 24 seed words seperated by just commas'")
sys.exit(1)
else:
print("err='not correct amount of parameter'")
sys.exit(1)
if len(sys.argv)>4:
seedpassword=sys.argv[4]
elif mode=="scb":
print("err='TODO: implement creating from seed/scb'")
@ -57,50 +76,84 @@ channel = grpc.secure_channel('localhost:10009', ssl_creds)
stub = lnrpc.WalletUnlockerStub(channel)
if mode=="new":
#request = ln.GenSeedRequest(
# aezeed_passphrase=<bytes>
#)
request = ln.GenSeedRequest()
try:
response = stub.GenSeed(request)
seedwords = response.cipher_seed_mnemonic
seedwordsString=','.join(seedwords)
seedwordsString=', '.join(seedwords)
print("seedwords='"+seedwordsString+"'")
except grpc.RpcError as err:
# - wallet might already exist
print("err='grpc.RpcError'")
print >> sys.stderr, err
# add a 6x4 formatted version to the output
seedwords6x4=""
for i in range(0,len(seedwords)):
if i % 6 == 0 and i != 0:
seedwords6x4=seedwords6x4+"\n"
singleWord=str(i+1)+":"+seedwords[i]
while len(singleWord)<12:
singleWord=singleWord+" "
seedwords6x4=seedwords6x4+singleWord
print("seedwords6x4='"+seedwords6x4+"'")
except grpc.RpcError as rpc_error_call:
code = rpc_error_call.code()
print >> sys.stderr, code
details = rpc_error_call.details()
print("err='RPCError GenSeedRequest'")
print("errMore='"+details+"'")
sys.exit(1)
except Exception as err:
print("err='GenSeedRequest'")
print >> sys.stderr, err
except:
e = sys.exc_info()[0]
print >> sys.stderr, e
print("err='GenSeedRequest'")
sys.exit(1)
# TODO: do first https://api.lightning.community/#genseed
#if len(seedpassword)>0:
# request = ln.InitWalletRequest(wallet_password=base64.b64encode(walletpassword.decode(),aezeed_passphrase=base64.b64encode(seedpassword).decode())
#else:
request = ln.InitWalletRequest(
wallet_password=walletpassword,
cipher_seed_mnemonic=seedwords
)
try:
response = stub.InitWallet(request)
except grpc.RpcError as rpc_error_call:
code = rpc_error_call.code()
print >> sys.stderr, code
details = rpc_error_call.details()
print("err='RPCError InitWallet'")
print("errMore='"+details+"'")
sys.exit(1)
except:
e = sys.exc_info()[0]
print >> sys.stderr, e
print("err='Failed: RPC InitWallet'")
print("err='InitWallet'")
sys.exit(1)
elif mode=="seed":
print("err='TODO: implement creating from seed'")
print("err='TODO: debug creating from seed")
sys.exit(1)
request = ln.InitWalletRequest(
wallet_password=walletpassword,
cipher_seed_mnemonic=seedwords,
recovery_window=1000,
aezeed_passphrase=seedpassword
)
try:
response = stub.InitWallet(request)
except grpc.RpcError as rpc_error_call:
code = rpc_error_call.code()
print >> sys.stderr, code
details = rpc_error_call.details()
print("err='RPCError InitWallet'")
print("errMore='"+details+"'")
sys.exit(1)
except:
e = sys.exc_info()[0]
print >> sys.stderr, e
print("err='InitWallet'")
sys.exit(1)
elif mode=="scb":
print("err='TODO: implement creating from seed/scb'")
sys.exit(1)
sys.exit(1)

33
home.admin/config.scripts/lnd.rescue.sh

@ -3,7 +3,7 @@
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "small rescue script to to backup or restore"
echo "lnd.rescue.sh [backup|restore]"
echo "lnd.rescue.sh [backup|restore] [?no-download]"
exit 1
fi
@ -29,10 +29,19 @@ if [ ${mode} = "backup" ]; then
sudo tar -zcvf /home/admin/lnd-rescue.tar.gz /mnt/hdd/lnd
sudo chown admin:admin /home/admin/lnd-rescue.tar.gz
# delete old backups
rm /home/admin/lnd-rescue-*.tar.gz
# name with md5 checksum
md5checksum=$(md5sum /home/admin/lnd-rescue.tar.gz | head -n1 | cut -d " " -f1)
mv /home/admin/lnd-rescue.tar.gz /home/admin/lnd-rescue-${md5checksum}.tar.gz
# stop here in case of 'no-download' option
if [ "${2}" == "no-download" ]; then
echo "No download of LND data requested."
exit 0
fi
# offer SCP for download
echo
echo "****************************"
@ -58,6 +67,9 @@ elif [ ${mode} = "restore" ]; then
echo "*** LND.RESCUE --> RESTORE"
echo ""
# delete old backups
rm /home/admin/lnd-rescue-*.tar.gz
filename=""
while [ ${#filename} -eq 0 ]
do
@ -66,9 +78,10 @@ elif [ ${mode} = "restore" ]; then
echo "**************************"
echo "* UPLOAD THE BACKUP FILE *"
echo "**************************"
echo
echo "If you have a lnd-rescue backup file on your laptop you can now"
echo "upload it and restore the your old LND state."
echo "upload it and restore the your latest LND state."
echo
echo "CAUTION: Dont restore old LND states - risk of loosing funds!"
echo
echo "To make upload open a new terminal on your laptop,"
echo "change into the directory where your lnd-rescue file is and"
@ -76,14 +89,15 @@ elif [ ${mode} = "restore" ]; then
echo "scp -r ./lnd-rescue-*.tar.gz admin@${localip}:/home/admin/"
echo ""
echo "Use password A to authenticate file transfere."
echo
echo "PRESS ENTER when upload is done. Use CTRL-C to abort."
echo "PRESS ENTER when upload is done. Enter x & ENTER to cancel."
fi
if [ ${countZips} -gt 1 ]; then
echo "!! WARNING !!"
echo "There are multiple lnd-rescue files in directory /home/admin."
echo "Make sure there is only one file to work with and start again."
echo "Make sure you upload only one tar.gz-file and start again."
echo
echo "PRESS ENTER to continue."
read key
exit 1
fi
if [ ${countZips} -eq 1 ]; then
@ -111,9 +125,12 @@ elif [ ${mode} = "restore" ]; then
echo
echo "WARNING: This will delete/overwrite the LND state/funds of this RaspiBlitz."
echo
echo "PRESS ENTER to start restore. Use CTRL-C to abort."
echo "PRESS ENTER to start restore. Enter x & ENTER to cancel."
fi
read key
if [ "${key}" == "x" ]; then
exit 1
fi
done
# stop LND
@ -143,7 +160,7 @@ elif [ ${mode} = "restore" ]; then
echo
echo "DONE - please check if LND starts up correctly with restored state and funds."
echo "Keep in mind that some channels got forced closed by channel partners in the meanwhile."
echo "Keep in mind that some channels maybe forced closed in the meanwhile."
echo
else

Loading…
Cancel
Save