Refactor Repair & Recovery Options #2901 (#2910)

This commit is contained in:
/rootzoll 2022-01-25 12:07:11 +01:00 committed by GitHub
parent fa21b1ac43
commit ec7f983ed2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 1287 additions and 681 deletions

View File

@ -37,6 +37,7 @@
- [Recover from a cl-rescue file](#recover-from-a-cl-rescue-file)
- [Recover from a seed](#recover-from-a-seed)
- [Rescan the chain after restoring a used c-lightning wallet](#rescan-the-chain-after-restoring-a-used-c-lightning-wallet)
- [Guesstoremote to recover funds from force-closed channels](#guesstoremote-to-recover-funds-from-force-closed-channels)
- [Update](#update)
- [Update to a new C-lightning release](#update-to-a-new-c-lightning-release)
- [Experimental update to the latest master](#experimental-update-to-the-latest-master)
@ -626,20 +627,21 @@ Will need to pay through a peer which supports the onion messages which means yo
* use the `REPAIR-CL` - `SEEDRESTORE` option in the menu for instructions to paste the seedwords to restore
#### Rescan the chain after restoring a used c-lightning wallet
* https://lightning.readthedocs.io/FAQ.html#rescanning-the-block-chain-for-lost-utxos
* Stop `lightningd`:
```
* can use the `menu` -> `REPAIR` -> `REPAIR-CL` -> `RESCAN` option
* or follow the manual process:
<https://lightning.readthedocs.io/FAQ.html#rescanning-the-block-chain-for-lost-utxos>
```
# stop `lightningd`:
sudo systemctl stop lightningd
```
An ungraceful method:
```
# the ungraceful method:
sudo killall ligthningd
* Rescan from the block 700000
```
# Rescan from the block 700000
sudo -u bitcoin lightningd --rescan -700000 --log-level debug
```
* Rescan the last 1000 blocks:
```
# Rescan the last 1000 blocks:
sudo -u bitcoin lightningd --rescan 1000 --log-level debug
```
* can monitor in a new window using the shortcut:
@ -647,6 +649,61 @@ Will need to pay through a peer which supports the onion messages which means yo
cllog
```
#### Guesstoremote to recover funds from force-closed channels
* <https://lightning.readthedocs.io/lightning-hsmtool.8.html>
```
$ man lightning-hsmtool
guesstoremote p2wpkh node_id max_channel_dbid hsm_secret [password]
Brute-force the private key to our funds from a remote unilateral close of a channel, in a case where we have lost all database data except for our hsm_secret. The peer must be the one to close the channel (and the funds will remain unrecoverable until the channel is closed). max_channel_dbid is your own guess on what the channel_dbid was, or at least the maximum possible value, and is usually no greater than the number of channels that the node has ever had. Specify password if the hsm_secret is encrypted.
```
* Usage on the RaspiBlitz (example for mainnet):
```
sudo -u bitcoin lightning-hsmtool guesstoremote p2wpkh-ADDRESS-bc1... PEER_NODE_ID 5000 /home/bitcoin/.lightning/bitcoin/hsm_secret
```
* The `p2wpkh-ADDRESS-bc1...` must a be a non-timelocked output. Shows with `OP_PUSHBYTES_20` in block explorers.
* The `max_channel_dbid` = 5000 is usually plenty, can set any higher number
* If the `hsm_secret` is encrypted give the password on the end
* Output if unsuccessful (the private key is not known):
```
Could not find any basepoint matching the provided witness programm.
Are you sure that the channel used `option_static_remotekey` ?
*** stack smashing detected ***: terminated
Aborted
```
* Output if successful:
```
bech32 : bc1q......................................
pubkey hash : 0123456789abcdef0123456789abcdef01234567
pubkey : 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef01
privkey : 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
```
* To import the private key of the address in Electrum Wallet will need to convert to base58
```
git clone https://github.com/matja/bitcoin-tool
cd bitcoin-tool
make test
./bitcoin-tool \
--network bitcoin \
--input-type private-key \
--input-format hex \
--input PASTE_THE_privkey_HERE \
--output-type private-key-wif \
--output-format base58check \
--public-key-compression compressed
```
* Example output:
```
KwFvTne98E1t3mTNAr8pKx67eUzFJWdSNPqPSfxMEtrueW7PcQzL
```
* To import to teh Electrum Wallet use the `p2wpkh:` prefix:
<https://bitcoinelectrum.com/importing-your-private-keys-into-electrum/>
```
p2wpkh:KxacygL6usxP8T9cFSM2SRW5QsEg66bUQUEn997UWwCZANEe7NLT
```
## Update
### Update to a new C-lightning release
* See the tagged releases by the C-lightning team: [github.com/ElementsProject/lightning/releases](https://github.com/ElementsProject/lightning/releases)

View File

@ -187,6 +187,10 @@ if [ "${lightning}" != "" ]; then
ln_sync="${value}"
source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_locked)
ln_locked="${value}"
source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_recovery_mode)
ln_recovery_mode="${value}"
source <(/home/admin/_cache.sh meta ln_${lightning}_${chain}net_recovery_done)
ln_recovery_done="${value}"
# lightning is still starting
if [ "${ln_ready}" != "1" ]; then
@ -200,6 +204,12 @@ if [ "${lightning}" != "" ]; then
ln_baseInfo="${color_amber}Wallet Locked"
ln_peersInfo=""
# lightning is still syncing
elif [ "${ln_recovery_mode}" == "1" ] && [ "${ln_recovery_done}" == "0" ]; then
ln_baseInfo="${color_amber}Rescanning transactions"
ln_peersInfo=""
# lightning is still syncing
elif [ "${ln_sync}" != "1" ]; then
@ -284,7 +294,7 @@ elif [ "${lightning}" == "lnd" ]; then
fi
LNinfo=" + Lightning Network"
if [ "${lightning}" == "" ]; then
if [ "${lightning}" == "" ] || [ "${lightning}" == "none" ]; then
LNinfo=""
fi

View File

@ -108,6 +108,7 @@ while :
lightning \
ln_default_locked \
btc_default_synced \
btc_default_online \
btc_default_sync_initialblockdownload \
btc_default_blocks_behind \
)
@ -118,7 +119,15 @@ while :
continue
fi
if [ "${btc_default_synced}" != "1" ]; then
# when lightning is active - show sync until ln_default_sync_initial_done
if [ "${lightning}" != "" ] && [ "${lightning}" != "none" ] && [ "${ln_default_sync_initial_done}" == "0" ]; then
/home/admin/setup.scripts/eventBlockchainSync.sh lcd
sleep 3
continue
fi
# when btc not online or not synced - show sync screen
if [ "${btc_default_synced}" != "1" ] || [ "${btc_default_online}" != "1" ]; then
/home/admin/setup.scripts/eventBlockchainSync.sh lcd
sleep 3
continue

View File

@ -99,6 +99,7 @@ do
btc_default_synced \
ln_default_sync_chain \
ln_default_locked \
ln_default_sync_initial_done \
message \
network \
chain \
@ -185,13 +186,73 @@ do
# MAKE SURE BLOCKCHAIN/LN IS SYNC
#####################################
if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ]; then
if [ "${btc_default_synced}" != "1" ] || [ "${ln_default_sync_chain}" != "1" ]; then
if [ "${btc_default_synced}" != "1" ] || [ "${ln_default_sync_chain}" == "0" ] || [ "${ln_default_sync_initial_done}" == "0" ]; then
/home/admin/setup.scripts/eventBlockchainSync.sh ssh
sleep 3
continue
fi
fi
#####################################
# SCB ACTIVATION
#####################################
# when setup is done & state is ready .. check for SCB activation
if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ]; then
# check if there is a channel.backup to activate
gotSCB=$(ls /home/admin/channel.backup 2>/dev/null | grep -c 'channel.backup')
if [ "${gotSCB}" == "1" ]; then
clear
echo
echo "*** channel.backup Recovery ***"
echo "Running ... (please wait)"
lncli --chain=${network} 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
# output error message
echo ""
echo "!!! FAIL !!! SOMETHING WENT WRONG:"
echo "${error}"
# check if its possible to give background info on the error
notMachtingSeed=$(echo $error | grep -c 'unable to unpack chan backup')
if [ ${notMachtingSeed} -gt 0 ]; then
echo "--> ERROR BACKGROUND:"
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."
echo
fi
# basic info on error
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo "To try upload of channel.backup again:"
echo "MAINMENU > REPAIR > REPAIR-LND > RETRYSCB"
echo
echo "Press ENTER to continue for now ..."
rm /home/admin/channel.backup
read key
else
rm /home/admin/channel.backup
dialog --title " OK Static-Channel-Backup IMPORT " --msgbox "
LND accepted the channel.backup file you uploaded.
It can now take up to an hour until you can see,
if LND was able to recover funds from your channels.
If you dont see any pending on-chain incoming funds
within the next hour or you still missing funds, you
can always retry the upload again under:
MAINMENU > REPAIR > REPAIR-LND > RETRYSCB
" 14 58
fi
fi
fi
#####################################
# MAIN MENU or BLOCKCHAIN SYNC
#####################################

View File

@ -9,6 +9,27 @@ source <(/home/admin/config.scripts/network.aliases.sh getvars cl $1)
sudo mkdir /var/cache/raspiblitz/temp 2>/dev/null
function clRescan() {
trap 'rm -f "$_temp"' EXIT
_temp=$(mktemp -p /dev/shm/)
dialog --backtitle "Choose the new gap limit" \
--title "Enter the rescan depth or blockheight (-)" \
--inputbox "
Enter the number of blocks to rescan from the current tip
or use a negative number for the absolute blockheight to scan from.
If left empty will start to rescan from the block 700000 (-700000).
" 12 71 2> "$_temp"
BLOCK=$(cat "$_temp")
if [ ${#BLOCK} -eq 0 ]; then
BLOCK="-700000"
fi
sudo /home/admin/config.scripts/cl.backup.sh "${CHAIN}" recoverymode on "${BLOCK}"
sudo systemctl restart ${netprefix}lightningd
}
# BASIC MENU INFO
WIDTH=64
BACKTITLE="RaspiBlitz"
@ -31,6 +52,7 @@ fi
OPTIONS+=(RESET "Reset the wallet and create new")
OPTIONS+=(FILERESTORE "Restore from a rescue file")
OPTIONS+=(SEEDRESTORE "Restore from a seed (onchain funds only)")
OPTIONS+=(RESCAN "Rescan for onchain funds from a given block")
CHOICE_HEIGHT=$(("${#OPTIONS[@]}/2+1"))
HEIGHT=$((CHOICE_HEIGHT+6))
@ -102,6 +124,8 @@ case $CHOICE in
/home/admin/config.scripts/blitz.conf.sh set ${netprefix}clAutoUnlock "off"
# new
/home/admin/config.scripts/cl.hsmtool.sh new $CHAIN
# create config
/home/admin/config.scripts/cl.install.sh on $CHAIN
# set the lightningd service file on each active network
if [ "${cl}" == "on" ] || [ "${cl}" == "1" ]; then
/home/admin/config.scripts/cl.install-service.sh mainnet
@ -171,8 +195,13 @@ case $CHOICE in
/home/admin/config.scripts/cl.hsmtool.sh autounlock-off
/home/admin/config.scripts/cl.hsmtool.sh decrypt
/home/admin/config.scripts/cl.install.sh on $CHAIN
clRescan
;;
RESCAN)
clRescan
;;
esac
exit 0

View File

@ -89,9 +89,9 @@ syncAndCheckLND() # from _provision.setup.sh
sudo /home/admin/config.scripts/blitz.datadrive.sh link
# check if now a config exists
configLinkedCorrectly=$(ls /home/bitcoin/.lnd/lnd.conf | grep -c "lnd.conf")
configLinkedCorrectly=$(ls /home/bitcoin/.lnd/${netprefix}lnd.conf | grep -c "${netprefix}lnd.conf")
if [ "${configLinkedCorrectly}" != "1" ]; then
echo "lnd-link-broken" "link /home/bitcoin/.lnd/lnd.conf broken" ""
echo "lnd-link-broken" "link /home/bitcoin/.lnd/${netprefix}lnd.conf broken" ""
exit 7
fi
@ -103,7 +103,7 @@ syncAndCheckLND() # from _provision.setup.sh
sudo systemctl stop ${netprefix}lnd 2>/dev/null
sudo systemctl disable ${netprefix}lnd 2>/dev/null
# copy lnd service
# copy lnd service - note the same service is created with 'lnd.install.sh on mainnet'
sudo cp /home/admin/assets/lnd.service /etc/systemd/system/lnd.service
# start lnd up
@ -137,12 +137,14 @@ syncAndCheckLND() # from _provision.setup.sh
# now sync macaroons & TLS to other users
sudo /home/admin/config.scripts/lnd.credentials.sh sync
# make a final lnd check
source <(/home/admin/config.scripts/lnd.check.sh basic-setup)
if [ "${err}" != "" ]; then
echo "lnd-check-error" "lnd.check.sh basic-setup with error" "/home/admin/config.scripts/lnd.check.sh basic-setup --> ${err}"
exit 15
fi
# make a final lnd check
source <(/home/admin/config.scripts/lnd.check.sh basic-setup "${chain}net")
if [ "${err}" != "" ]; then
echo
echo "lnd-check-error" "lnd.check.sh basic-setup ${chain}net with error" "/home/admin/config.scripts/lnd.check.sh basic-setup ${chain}net --> ${err}"
echo
# exit 15
fi
}
function restoreFromSeed()
@ -172,21 +174,7 @@ or having a complete LND rescue-backup from your old node.
getpasswordC
clear
echo
echo "The next step will overwrite the old LND wallets on all chains"
echo "Press ENTER to continue or CTRL+C to abort"
read key
echo "Stopping ${netprefix}lnd ..."
sudo systemctl stop ${netprefix}lnd
if [ "${tlnd}" == "on" ];then
sudo systemctl stop tlnd
fi
if [ "${slnd}" == "on" ];then
sudo systemctl stop slnd
fi
echo "Reset wallet"
sudo rm -r /mnt/hdd/lnd
removeLNDwallet
# creates fresh lnd.conf without an alias
/home/admin/config.scripts/lnd.install.sh on $CHAIN
@ -213,64 +201,102 @@ function restoreSCB()
{
# import SCB and get results
_temp="/var/cache/raspiblitz/.temp.tmp"
/home/admin/config.scripts/lnd.backup.sh scb-import-gui setup $_temp
# 'production' to use passwordA
/home/admin/config.scripts/lnd.backup.sh scb-import-gui production $_temp
source $_temp 2>/dev/null
sudo rm $_temp 2>/dev/null
# if user canceled the upload
if [ "${staticchannelbackup}" == "" ]; then
# signal cancel to the calling script by exit code (5 = exit on scb)
if ! ls -la /home/admin/channel.backup; then
echo "# signal cancel to the calling script by exit code (5 = exit on scb)"
exit 5
fi
echo
echo "The next step will attempt to trigger all online peers to force close the channels with this node."
echo "Restoring the channel.backup can be repeated again until all the channels are force closed."
echo "Contacting the peers and asking them to force close achieves the same."
echo "The next step will attempt to trigger all online peers to force close the channels."
echo "Restoring the channel.backup can be repeated until all the channels are force closed."
echo
echo "Make sure to enter the Raspiblitz menu to trigger the next step."
echo "If menu does not open automatically - use command: raspiblitz"
echo "Press ENTER to continue or CTRL+C to abort"
read key
# WALLET --> SEED + SCB
if [ "${staticchannelbackup}" != "" ]; then
### --> DEACTIVATED BECAUSE when a file is placed at /home/admin/channel.backup
### it will now automatically trigger a Static-Channel-Backup procedure after lnd recoverymode is done
#
# # WALLET --> SEED + SCB
# if ls -la /home/admin/channel.backup; then
#
# # LND was restarted so need to unlock
# echo "WALLET --> UNLOCK WALLET - SCAN 0"
# /home/admin/_cache.sh set message "LND Wallet Unlock - scan 0"
# source <(/home/admin/config.scripts/lnd.initwallet.py unlock "${chain}net" "${passwordC}" 0)
# if [ "${err}" != "" ]; then
# echo "lnd-wallet-unlock" "lnd.initwallet.py unlock returned error" "/home/admin/config.scripts/lnd.initwallet.py unlock ${chain}net ... --> ${err} + ${errMore}"
# if [ "${errMore}" = "wallet already unlocked, WalletUnlocker service is no longer available" ]; then
# echo "The wallet is already unlocked, continue."
# else
# exit 11
# fi
# fi
#
# echo "WALLET --> SEED + SCB "
# /home/admin/_cache.sh set message "LND Wallet (SEED & SCB)"
# macaroonPath="/home/admin/.lnd/data/chain/${network}/${chain}net/admin.macaroon"
# source <(/home/admin/config.scripts/lnd.initwallet.py scb ${chain}net "/home/admin/channel.backup" "${macaroonPath}")
# if [ "${err}" != "" ]; then
# echo "lnd-wallet-seed+scb" "lnd.initwallet.py scb returned error" "/home/admin/config.scripts/lnd.initwallet.py scb ${chain}net ... --> ${err} + ${errMore}"
# while [ $(echo "${errMore}" | grep -c "RPC server is in the process of starting up") -gt 0 ]; do
# echo "# ${errMore}"
# echo "# waiting 10 seconds (${counter})"
# counter=$((counter+1))
# if [ ${counter} -eq 60 ]; then
# echo "# Giving up after 10 minutes"
# echo
# echo "lnd-wallet-seed+scb" "lnd.initwallet.py scb returned error" "/home/admin/config.scripts/lnd.initwallet.py scb ${chain}net ... --> ${err} + ${errMore}"
# echo
# echo "The SCB recovery is not possible now - use the RETRYSCB option the REPAIR-LND menu after LND is synced."
# echo "Can repeat the SCB recovery until all peers have force closed the channels to this node."
# echo
# echo "# ${netprefix}lnd error logs:"
# sudo journalctl -u ${netprefix}lnd
# echo
# echo "# ${netprefix}lnd logs:"
# sudo tail /home/bitcoin/.lnd/logs/bitcoin/${CHAIN}/lnd.log
# exit 12
# fi
# sleep 10
# source <(/home/admin/config.scripts/lnd.initwallet.py scb ${chain}net "/home/admin/channel.backup" "${macaroonPath}")
# done
#
# fi
# fi
#
# syncAndCheckLND
# LND was restarted so need to unlock
echo "WALLET --> UNLOCK WALLET - SCAN 0"
/home/admin/_cache.sh set message "LND Wallet Unlock - scan 0"
source <(/home/admin/config.scripts/lnd.initwallet.py unlock "${chain}net" "${passwordC}" 0)
if [ "${err}" != "" ]; then
echo "lnd-wallet-unlock" "lnd.initwallet.py unlock returned error" "/home/admin/config.scripts/lnd.initwallet.py unlock ${chain}net ... --> ${err} + ${errMore}"
if [ "${errMore}" = "wallet already unlocked, WalletUnlocker service is no longer available" ]; then
echo "The wallet is already unlocked, continue."
else
exit 11
fi
fi
}
echo "WALLET --> SEED + SCB "
/home/admin/_cache.sh set message "LND Wallet (SEED & SCB)"
macaroonPath="/home/admin/.lnd/data/chain/${network}/${chain}net/admin.macaroon"
source <(/home/admin/config.scripts/lnd.initwallet.py scb ${chain}net "/home/admin/channel.backup" "${macaroonPath}")
if [ "${err}" != "" ]; then
echo "lnd-wallet-seed+scb" "lnd.initwallet.py scb returned error" "/home/admin/config.scripts/lnd.initwallet.py scb ${chain}net ... --> ${err} + ${errMore}"
if [ "${errMore}" = "server is still in the process of starting" ]; then
echo "The SCB recovery is not possible now - use the RETRYSCB option the REPAIR-LND menu after LND is synced."
echo "Can repeat the SCB recovery until all peers have force closed the channels to this node."
else
exit 12
fi
fi
fi
syncAndCheckLND
# LND was restarted so need to unlock
echo "WALLET --> UNLOCK WALLET - SCAN 5000"
/home/admin/_cache.sh set message "LND Wallet Unlock - scan 5000"
source <(/home/admin/config.scripts/lnd.initwallet.py unlock ${chain}net "${passwordC}" 5000)
if [ "${err}" != "" ]; then
echo "lnd-wallet-unlock" "lnd.initwallet.py unlock returned error" "/home/admin/config.scripts/lnd.initwallet.py unlock ${chain}net ... --> ${err} + ${errMore}"
exit 50
fi
function removeLNDwallet
{
clear
echo
echo "The next step WILL REMOVE the old LND wallet on ${CHAIN}"
echo "Press ENTER to continue or CTRL+C to abort"
read key
echo "# Stopping lnd on ${CHAIN} ..."
sudo systemctl stop ${netprefix}lnd
sudo systemctl disable ${netprefix}lnd
echo "Reset wallet on ${CHAIN}"
sudo rm -f /home/bitcoin/.lnd/${netprefix}lnd.conf
sudo rm -f /home/bitcoin/.lnd/${netprefix}v3_onion_private_key
sudo rm -f /mnt/hdd/lnd/data/chain/${network}/${CHAIN}/wallet.db
sudo rm -f /home/bitcoin/.lnd/data/graph/${CHAIN}/channel.db
sudo rm -f /home/bitcoin/.lnd/data/graph/${CHAIN}/sphinxreplay.db
sudo rm -rf /mnt/hdd/lnd/data/chain/${network}/${CHAIN}
sudo rm -rf /home/bitcoin/.lnd/logs/${network}/${CHAIN}
sudo rm -rf /home/bitcoin/.lnd/data/graph/${CHAIN}
sudo rm -rf home/bitcoin/.lnd/data/watchtower/${CHAIN}
}
# BASIC MENU INFO
@ -279,8 +305,10 @@ BACKTITLE="RaspiBlitz"
TITLE="LND repair options for $CHAIN"
MENU=""
OPTIONS=()
OPTIONS+=(COMPACT "Compact the LND channel.db")
if [ "${chain}" = "main" ]; then
OPTIONS+=(COMPACT "Compact the LND channel.db")
OPTIONS+=(GETSCB "Download channel.backup (StaticChannelBackup)")
fi
OPTIONS+=(BACKUP-LND "Backup your LND data (Rescue-File)")
OPTIONS+=(RESET-LND "Delete LND & start new node/wallet")
OPTIONS+=(LNDRESCUE "Restore from a rescue file")
@ -311,6 +339,9 @@ case $CHOICE in
echo "Press ENTER to return to main menu."
read key
;;
GETSCB)
/home/admin/config.scripts/lnd.backup.sh scb-export-gui
;;
BACKUP-LND)
/home/admin/config.scripts/lnd.compact.sh interactive
sudo /home/admin/config.scripts/lnd.backup.sh ${netprefix}lnd-export-gui
@ -342,26 +373,12 @@ case $CHOICE in
# sudo /home/admin/config.scripts/lnd.setname.sh ${chain}net "${result}"
# /home/admin/config.scripts/blitz.conf.sh set hostname "${result}"
echo "stopping ${netprefix}lnd ..."
sudo systemctl stop ${netprefix}lnd
if [ "${tlnd}" == "on" ];then
sudo systemctl stop tlnd
fi
if [ "${slnd}" == "on" ];then
sudo systemctl stop slnd
fi
echo "Delete wallet"
sudo rm -r /mnt/hdd/lnd
removeLNDwallet
# create wallet
/home/admin/config.scripts/lnd.install.sh on ${chain}net initwallet
# display and delete the seed for ${chain}net
sudo /home/admin/config.scripts/lnd.install.sh display-seed ${chain}net delete
if [ "${tlnd}" == "on" ];then
/home/admin/config.scripts/lnd.install.sh on testnet initwallet
fi
if [ "${slnd}" == "on" ];then
/home/admin/config.scripts/lnd.install.sh on signet initwallet
fi
syncAndCheckLND
@ -374,18 +391,24 @@ case $CHOICE in
LNDRESCUE)
askLNDbackupCopy
echo "The next step will overwrite the old LND wallets on all chains"
#removeAllLNDwallets
clear
echo
echo "The next step WILL REMOVE the old LND wallets on ALL CHAINS"
echo "Press ENTER to continue or CTRL+C to abort"
read key
echo "Stopping ${netprefix}lnd ..."
sudo systemctl stop ${netprefix}lnd
echo "# Stopping lnd on mainnet ..."
sudo systemctl stop lnd
# don' t want to set CL as default if running parallel
#/home/admin/config.scripts/lnd.install.sh off mainnet
if [ "${tlnd}" == "on" ];then
sudo systemctl stop tlnd
/home/admin/config.scripts/lnd.install.sh off testnet
fi
if [ "${slnd}" == "on" ];then
sudo systemctl stop slnd
/home/admin/config.scripts/lnd.install.sh off signet
fi
echo "Delete wallet"
echo "Reset wallet"
sudo rm -r /mnt/hdd/lnd
## from dialogLightningWallet.sh
@ -408,12 +431,20 @@ case $CHOICE in
exit 0
;;
SEED+SCB)
restoreFromSeed
ONLYSEED)
restoreSCB
restoreFromSeed
echo "Set lnd recovery mode & restart ..."
sudo /home/admin/config.scripts/lnd.backup.sh "${chain}net" recoverymode on
sudo systemctl restart ${netprefix}lnd
sleep 3
echo "# Unlock wallet ..."
/home/admin/config.scripts/lnd.unlock.sh "${CHAIN}"
echo
echo "System will now go thru rescan for on-chain funds"
echo "Press ENTER to return to main menu."
read key
# go back to main menu (and show)
@ -421,63 +452,60 @@ case $CHOICE in
exit 0
;;
SEED+SCB)
restoreFromSeed
restoreSCB
echo "Set lnd recovery mode & restart ..."
sudo /home/admin/config.scripts/lnd.backup.sh "${chain}net" recoverymode on
sudo systemctl restart ${netprefix}lnd
sleep 3
echo "# Unlock wallet ..."
/home/admin/config.scripts/lnd.unlock.sh "${CHAIN}"
echo
echo "System will now go thru rescan for on-chain funds and when done"
echo "the Static-Channel-Backup will trigger to recover off-chain funds."
echo "Press ENTER to return to main menu."
read key
# go back to main menu (and show)
/home/admin/00raspiblitz.sh
exit 0
;;
RETRYSCB)
restoreSCB
echo
echo "Press ENTER to return to main menu."
read key
# go back to main menu (and show)
/home/admin/00raspiblitz.sh
exit 0
;;
ONLYSEED)
restoreFromSeed
echo "WALLET --> UNLOCK WALLET - SCAN 5000"
/home/admin/_cache.sh set message "LND Wallet Unlock - scan 5000"
source <(/home/admin/config.scripts/lnd.initwallet.py unlock "${chain}net" "${passwordC}" 5000)
if [ "${err}" != "" ]; then
echo "lnd-wallet-unlock" "lnd.initwallet.py unlock returned error" "/home/admin/config.scripts/lnd.initwallet.py unlock ${chain}net ... --> ${err} + ${errMore}"
exit 50
fi
echo "Press ENTER to return to main menu."
read key
# go back to main menu (and show)
/home/admin/00raspiblitz.sh
exit 0
;;
RESCAN)
clear
echo "Restart lnd to lock the wallet ..."
echo "If this takes very long LND might be already rescanning."
echo "Can use 'sudo pkill lnd' to shut down ungracefully."
sudo systemctl restart lnd
# from blitz.conf.sh
configFile="/home/admin/raspiblitz.info"
keystr="fundRecovery"
valuestr="1"
# check if key needs to be added (prepare new entry)
entryExists=$(grep -c "^${keystr}=" ${configFile})
if [ ${entryExists} -eq 0 ]; then
echo "${keystr}=" | tee -a ${configFile}
source <(sudo /home/admin/config.scripts/lnd.backup.sh "${CHAIN}" recoverymode status)
if [ "${recoverymode}" == "0" ]; then
echo "Putting lnd back in recoverymode."
sudo /home/admin/config.scripts/lnd.backup.sh "${CHAIN}" recoverymode on
echo "Restarting lnd ..."
sudo systemctl restart ${netprefix}lnd
sleep 3
else
echo "lnd already in recoverymode."
fi
# add valuestr quotes if not standard values
if [ "${valuestr}" != "on" ] && [ "${valuestr}" != "off" ] && [ "${valuestr}" != "1" ] && [ "${valuestr}" != "0" ]; then
valuestr="'${valuestr}'"
fi
# set value (sed needs sudo to operate when user is not root)
sudo sed -i "s/^${keystr}=.*/${keystr}=${valuestr}/g" ${configFile}
/home/admin/config.scripts/lnd.unlock.sh unlock
# switch rescan off for the next unlock
valuestr="0"
sudo sed -i "s/^${keystr}=.*/${keystr}=${valuestr}/g" ${configFile}
echo "# Unlock wallet ..."
/home/admin/config.scripts/lnd.unlock.sh "${CHAIN}"
echo
echo "To show the scanning progress in the background will follow the lnd.log with:"

View File

@ -27,9 +27,9 @@ elif [ $LNTYPE = lnd ];then
fi
if [ ${chainOutSync} -eq 1 ]; then
if [ $LNTYPE = cl ];then
echo "# FAIL PRECHECK - lncli getinfo shows 'synced_to_chain': false - wait until chain is sync "
echo "# FAIL PRECHECK - '$lightningcli_alias getinfo' blockheight is different from 'bitcoind getblockchaininfo' - wait until chain is sync "
else
echo "# FAIL PRECHECK - 'lightning-cli getinfo' blockheight is different from 'bitcoind getblockchaininfo' - wait until chain is sync "
echo "# FAIL PRECHECK - '$lncli_alias getinfo' shows 'synced_to_chain': false - wait until chain is sync "
fi
echo
echo "# PRESS ENTER to return to menu"

View File

@ -18,8 +18,6 @@ fi
source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2)
source <(/home/admin/config.scripts/network.aliases.sh getvars $LNTYPE ${chain}net)
# check if chain is in sync
if [ $LNTYPE = cl ];then
lncommand="${netprefix}lightning-cli"

View File

@ -70,6 +70,9 @@ WEEK=604800
MONTH=2592000
YEAR=31536000
# make sure root is in group bitcoin and allowed to read macaroons
usermod -G bitcoin root
####################################################################
# INIT
####################################################################
@ -285,29 +288,9 @@ do
# data that may be based on setup phase or configuration
####################################################################
# by default will only scan the btc & lightning instances that are set to default
# but can scan/monitor all that are switched on when `system_scan_all=on` in config
# read/update config values
source /mnt/hdd/raspiblitz.conf
# check if a one time `system_scan_all_once=1` is set on cache
# will trigger a scan_all for one loop
source <(/home/admin/_cache.sh get system_scan_all_once)
if [ "${system_scan_all_once}" == "1" ]; then
echo "system_scan_all_once found --> TRIGGER system_scan_all for one loop"
/home/admin/_cache.sh set system_scan_all_once "0"
system_scan_all="on"
fi
# check if a temporary `system_scan_all_temp=1` is set on cache
# will trigger a scan_all until its gone or `0`
source <(/home/admin/_cache.sh get system_scan_all_temp)
if [ "${system_scan_all_temp}" == "1" ]; then
echo "system_scan_all_temp found --> TRIGGER system_scan_all"
system_scan_all="on"
fi
###################
# HARDDRIVE
@ -354,12 +337,14 @@ do
continue
fi
# only scan non defaults when set by parameter from config
if [ "${system_scan_all}" != "on" ]; then
if [ "${isDefaultChain}" != "1" ]; then
#echo "skip btc ${CHAIN}net scan - because its not default"
continue
fi
# set intervals for non default & non-default (in seconds)
CYCLE_QUICK=30
CYCLE_MID=60
CYCLE_LONG=90
if [ "${isDefaultChain}" != "1" ]; then
CYCLE_QUICK=150
CYCLE_MID=300
CYCLE_LONG=600
fi
# update basic status values always
@ -381,7 +366,7 @@ do
btc_default_error_full \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt 30 ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_QUICK} ]; then
echo "updating: /home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net status"
source <(/home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net status)
/home/admin/_cache.sh set btc_${CHAIN}net_activated "1"
@ -429,7 +414,7 @@ do
btc_default_sync_initialblockdownload \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_MID} ]; then
error=""
echo "updating: /home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net info"
source <(/home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net info)
@ -450,6 +435,7 @@ do
/home/admin/_cache.sh set btc_default_sync_percentage "${btc_sync_percentage}"
/home/admin/_cache.sh set btc_default_sync_initialblockdownload "${btc_sync_initialblockdownload}"
fi
else
echo "!! ERROR --> ${error}"
fi
@ -468,7 +454,7 @@ do
btc_default_port \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_MID} ]; then
error=""
echo "updating: /home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net network"
source <(/home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net network)
@ -495,7 +481,7 @@ do
btc_default_mempool_transactions \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE5} ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_LONG} ]; then
error=""
echo "updating: /home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net mempool"
source <(/home/admin/config.scripts/bitcoin.monitor.sh ${CHAIN}net mempool)
@ -538,12 +524,14 @@ do
isDefaultChain=$(echo "${CHAIN}" | grep -c "${chain}")
isDefaultLightning=$(echo "${lightning}" | grep -c "lnd")
# only scan non defaults when set by parameter from config
if [ "${system_scan_all}" != "on" ]; then
if [ "${isDefaultChain}" != "1" ] || [ ${isDefaultLightning} != "1" ]; then
#echo "skip lnd ${CHAIN}net scan - because its not default"
continue
fi
# set intervals for non default & non-default (in seconds)
CYCLE_QUICK=30
CYCLE_MID=60
CYCLE_LONG=90
if [ "${isDefaultChain}" != "1" ] || [ "${isDefaultLightning}" != "1" ]; then
CYCLE_QUICK=300
CYCLE_MID=600
CYCLE_LONG=900
fi
# update basic status values always
@ -567,7 +555,7 @@ do
ln_default_error_full \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt 30 ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_QUICK} ]; then
echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net status"
source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net status)
/home/admin/_cache.sh set ln_lnd_${CHAIN}net_activated "1"
@ -596,7 +584,7 @@ do
# check if config needs update
source <(/home/admin/_cache.sh valid ln_lnd_${CHAIN}net_alias)
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE5} ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_LONG} ]; then
error=""
echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net config"
source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net config)
@ -621,6 +609,8 @@ do
ln_lnd_${CHAIN}net_channels_inactive \
ln_lnd_${CHAIN}net_channels_total \
ln_lnd_${CHAIN}net_peers \
ln_lnd_${CHAIN}net_recovery_mode \
ln_lnd_${CHAIN}net_recovery_done \
)
if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ] && [ "${stillvalid}" == "1" ]; then
source <(/home/admin/_cache.sh valid \
@ -633,9 +623,11 @@ do
ln_default_channels_inactive \
ln_default_channels_total \
ln_default_peers \
ln_default_recovery_mode \
ln_default_recovery_done \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_MID} ]; then
error=""
echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net info"
source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net info)
@ -650,6 +642,8 @@ do
/home/admin/_cache.sh set ln_lnd_${CHAIN}net_channels_inactive "${ln_lnd_channels_inactive}"
/home/admin/_cache.sh set ln_lnd_${CHAIN}net_channels_total "${ln_lnd_channels_total}"
/home/admin/_cache.sh set ln_lnd_${CHAIN}net_peers "${ln_lnd_peers}"
/home/admin/_cache.sh set ln_lnd_${CHAIN}net_recovery_mode "${ln_lnd_recovery_mode}"
/home/admin/_cache.sh set ln_lnd_${CHAIN}net_recovery_done "${ln_lnd_recovery_done}"
if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then
/home/admin/_cache.sh set ln_default_address "${ln_lnd_address}"
/home/admin/_cache.sh set ln_default_tor "${ln_lnd_tor}"
@ -660,6 +654,8 @@ do
/home/admin/_cache.sh set ln_default_channels_inactive "${ln_lnd_channels_inactive}"
/home/admin/_cache.sh set ln_default_channels_total "${ln_lnd_channels_total}"
/home/admin/_cache.sh set ln_default_peers "${ln_lnd_peers}"
/home/admin/_cache.sh set ln_default_recovery_mode "${ln_lnd_recovery_mode}"
/home/admin/_cache.sh set ln_default_recovery_done "${ln_lnd_recovery_done}"
fi
else
echo "!! ERROR --> ${error}"
@ -681,7 +677,7 @@ do
ln_default_wallet_channels_pending \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt 22 ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_QUICK} ]; then
error=""
echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net wallet"
source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net wallet)
@ -713,7 +709,7 @@ do
ln_default_fees_total \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE5} ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_LONG} ]; then
error=""
echo "updating: /home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net fees"
source <(/home/admin/config.scripts/lnd.monitor.sh ${CHAIN}net fees)
@ -758,12 +754,14 @@ do
isDefaultChain=$(echo "${CHAIN}" | grep -c "${chain}")
isDefaultLightning=$(echo "${lightning}" | grep -c "cl")
# only scan non defaults when set by parameter from config
if [ "${system_scan_all}" != "on" ]; then
if [ "${isDefaultChain}" != "1" ] || [ ${isDefaultLightning} != "1" ]; then
#echo "skip cl ${CHAIN}net scan - because its not default"
continue
fi
# set intervals for non default & non-default (in seconds)
CYCLE_QUICK=30
CYCLE_MID=60
CYCLE_LONG=90
if [ "${isDefaultChain}" != "1" ] || [ "${isDefaultLightning}" != "1" ]; then
CYCLE_QUICK=300
CYCLE_MID=600
CYCLE_LONG=900
fi
# TODO: c-lightning is seen as "always unlocked" for now - needs to be implemented later #2691
@ -787,7 +785,7 @@ do
ln_default_error_full \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt 30 ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_QUICK} ]; then
echo "updating: /home/admin/config.scripts/cl.monitor.sh ${CHAIN}net status"
source <(/home/admin/config.scripts/cl.monitor.sh ${CHAIN}net status)
/home/admin/_cache.sh set ln_cl_${CHAIN}net_activated "1"
@ -841,7 +839,7 @@ do
ln_default_fees_total \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_MID} ]; then
error=""
echo "updating: /home/admin/config.scripts/cl.monitor.sh ${CHAIN}net info"
source <(/home/admin/config.scripts/cl.monitor.sh ${CHAIN}net info)
@ -857,6 +855,8 @@ do
/home/admin/_cache.sh set ln_cl_${CHAIN}net_channels_inactive "${ln_cl_channels_inactive}"
/home/admin/_cache.sh set ln_cl_${CHAIN}net_channels_total "${ln_cl_channels_total}"
/home/admin/_cache.sh set ln_cl_${CHAIN}net_fees_total "${ln_cl_fees_total}"
/home/admin/_cache.sh set ln_cl_${CHAIN}net_recovery_mode "${ln_cl_recovery_mode}"
/home/admin/_cache.sh set ln_cl_${CHAIN}net_recovery_done "${ln_cl_recovery_done}"
if [ "${isDefaultLightning}" == "1" ] && [ "${isDefaultChain}" == "1" ]; then
/home/admin/_cache.sh set ln_default_alias "${ln_cl_alias}"
@ -870,6 +870,8 @@ do
/home/admin/_cache.sh set ln_default_channels_inactive "${ln_cl_channels_inactive}"
/home/admin/_cache.sh set ln_default_channels_total "${ln_cl_channels_total}"
/home/admin/_cache.sh set ln_default_fees_total "${ln_cl_fees_total}"
/home/admin/_cache.sh set ln_default_recovery_mode "${ln_cl_recovery_mode}"
/home/admin/_cache.sh set ln_default_recovery_done "${ln_cl_recovery_done}"
fi
else
echo "!! ERROR --> ${error}"
@ -891,7 +893,7 @@ do
ln_default_wallet_channels_pending \
)
fi
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${MINUTE} ]; then
if [ "${stillvalid}" == "0" ] || [ ${age} -gt ${CYCLE_MID} ]; then
error=""
echo "updating: /home/admin/config.scripts/cl.monitor.sh ${CHAIN}net wallet"
source <(/home/admin/config.scripts/cl.monitor.sh ${CHAIN}net wallet)
@ -913,6 +915,98 @@ do
fi
done
##################################
# DEFAULT & SUMMARIZED SYNC STATUS
btc_default_sync_initial_done=0
btc_all_sync_initial_done=1
ln_default_sync_initial_done=0
ln_all_sync_initial_done=1
blitz_sync_initial_done=0
networks=( "main" "test" "sig" )
sedondLayers=( "lnd" "cl" )
# if default is mainnet, then consider mainnet=on
if [ "${chain}" == "main" ]; then
mainnet="on"
fi
# loop over all chains
for CHAIN in "${networks[@]}"
do
# skip if this network is not switched on
btc_service_name="${CHAIN}net"
if [ "${!btc_service_name}" != "on" ]; then
echo "skipping because ${btc_service_name}=${!btc_service_name}"
continue
fi
# get values from cache
source <(/home/admin/_cache.sh meta btc_${CHAIN}net_sync_initial_done)
flagBtcDone="${value}"
# check if default
if [ "${CHAIN}" == "${chain}" ]; then
btc_default_sync_initial_done="${flagBtcDone}"
fi
# check for all btc sync
if [ "${flagBtcDone}" != "1" ]; then
btc_all_sync_initial_done=0
fi
# sub loop over all layer 2 on that chain
for LN in "${sedondLayers[@]}"
do
# skip if this variant is not switched on
ln_service_name="${LN}"
if [ "${CHAIN}" == "test" ]; then
ln_service_name="t${LN}"
fi
if [ "${CHAIN}" == "sig" ]; then
ln_service_name="s${LN}"
fi
if [ "${!ln_service_name}" != "on" ]; then
echo "skipping because ${ln_service_name}=${!ln_service_name}"
continue
fi
# get values from cache
source <(/home/admin/_cache.sh meta ln_${LN}_${CHAIN}net_sync_initial_done)
flagLNSyncDone="${value}"
# check if default
if [ "${CHAIN}" == "${chain}" ] && [ "${LN}" == "${lightning}" ]; then
ln_default_sync_initial_done="${flagLNSyncDone}"
fi
# check for all ln sync
if [ "${flagLNSyncDone}" != "1" ]; then
ln_all_sync_initial_done=0
fi
done
done
# finalize & writing results to cache
if [ "${lightning}" == "" ] || [ "${lightning}" == "none" ]; then
ln_all_sync_initial_done=""
ln_default_sync_initial_done=""
blitz_sync_initial_done="${btc_all_sync_initial_done}"
else
# only if all btc & ln sync done - the complete blitz has done syncing
if [ "${btc_all_sync_initial_done}" == "1" ] && [ "${ln_all_sync_initial_done}" == "1" ]; then
blitz_sync_initial_done="1"
fi
fi
/home/admin/_cache.sh set blitz_sync_initial_done "${blitz_sync_initial_done}"
/home/admin/_cache.sh set btc_default_sync_initial_done "${btc_default_sync_initial_done}"
/home/admin/_cache.sh set btc_all_sync_initial_done "${btc_all_sync_initial_done}"
/home/admin/_cache.sh set ln_default_sync_initial_done "${ln_default_sync_initial_done}"
/home/admin/_cache.sh set ln_all_sync_initial_done "${ln_all_sync_initial_done}"
#################
# DONE

View File

@ -43,7 +43,7 @@ do
source ${infoFile} 2>/dev/null
source ${configFile} 2>/dev/null
source <(/home/admin/_cache.sh get state setupPhase)
####################################################
# SKIP BACKGROUND TASK LOOP ON CERTAIN SYSTEM STATES
# https://github.com/rootzoll/raspiblitz/issues/160
@ -223,6 +223,148 @@ do
fi
fi
####################################################
# MONITOR Initial Syncing of Bitcoin & Lightning
# - turn off recovery mode
####################################################
recheckIBD=$((($counter % 10)+1))
if [ ${recheckIBD} -eq 1 ]; then
# loop thru mainet, testnet & signet
networks=( "main" "test" "sig" )
for CHAIN in "${networks[@]}"
do
# gat values from cache
source <(/home/admin/_cache.sh meta btc_${CHAIN}net_sync_initial_started)
flagBtcStarted="${value}"
source <(/home/admin/_cache.sh meta btc_${CHAIN}net_sync_initialblockdownload)
flagBtcActive="${value}"
source <(/home/admin/_cache.sh meta btc_${CHAIN}net_synced)
flagBtcSynced="${value}"
source <(/home/admin/_cache.sh meta btc_${CHAIN}net_online)
flagBtcOnline="${value}"
source <(/home/admin/_cache.sh meta btc_${CHAIN}net_sync_initial_done)
flagBtcDone="${value}"
#echo "CHAIN(${CHAIN}) flagBtcStarted(${flagBtcStarted}) flagBtcActive(${flagBtcActive}) flagBtcSynced(${flagBtcSynced}) flagBtcOnline(${flagBtcOnline}) flagBtcDone(${flagBtcDone})"
# first check if flags need to be reset (manually delete of blockchain)
if [ "${flagBtcDone}" == "1" ] && [ "${flagBtcActive}" == "1" ]; then
flagBtcDone=0
/home/admin/config.scripts/blitz.conf.sh set btc_${CHAIN}net_sync_initial_done ${flagBtcDone} /home/admin/raspiblitz.info
echo "EVENT --> btc_${CHAIN}net_sync_initial_done changed to ${flagBtcDone}"
fi
# when started flag not set yet - but is now active --> set flag
if [ "${flagBtcStarted}" != "1" ] && [ "${flagBtcActive}" == "1" ]; then
flagBtcStarted=1
/home/admin/_cache.sh set btc_${CHAIN}net_sync_initial_started ${flagBtcStarted}
echo "EVENT --> btc_${CHAIN}net_sync_initial_started changed to ${flagBtcStarted}"
fi
# when started done is set - but not not active anymore --> end of IDB event detected
if [ "${flagBtcDone}" == "0" ] && [ "${flagBtcOnline}" == "1" ] && [ "${flagBtcSynced}" == "1" ]; then
flagBtcDone=1
/home/admin/config.scripts/blitz.conf.sh set btc_${CHAIN}net_sync_initial_done ${flagBtcDone} /home/admin/raspiblitz.info
echo "EVENT --> btc_${CHAIN}net_sync_initial_done changed to ${flagBtcDone}"
fi
# loop thru all second layers
sedondLayers=( "lnd" "cl" )
for LN in "${sedondLayers[@]}"
do
source <(/home/admin/_cache.sh meta ln_${LN}_${CHAIN}net_sync_chain)
flagLnSyncChain="${value}"
source <(/home/admin/_cache.sh meta ln_${LN}_${CHAIN}net_online)
flagLnOnline="${value}"
source <(/home/admin/_cache.sh meta ln_${LN}_${CHAIN}net_recovery_mode)
flagLNRecoveryMode="${value}"
source <(/home/admin/_cache.sh meta ln_${LN}_${CHAIN}net_recovery_done)
flagLNRecoveryDone="${value}"
source <(/home/admin/_cache.sh meta ln_${LN}_${CHAIN}net_sync_initial_done)
flagLNSyncDone="${value}"
#echo "LN(${LN}) flagLnSyncChain(${flagLnSyncChain}) flagLnOnline(${flagLnOnline}) flagLNRecoveryMode(${flagLNRecoveryMode}) flagLNRecoveryDone(${flagLNRecoveryDone}) flagLNSyncDone(${flagLNSyncDone})"
# first check if flags need to be reset (manually a rescan was triggered)
if [ "${flagLNSyncDone}" == "1" ] && [ "${flagLNRecoveryMode}" == "1" ]; then
flagLNSyncDone=0
/home/admin/config.scripts/blitz.conf.sh set ln_${LN}_${CHAIN}net_sync_initial_done ${flagLNSyncDone} /home/admin/raspiblitz.info
echo "EVENT --> ln_${LN}_${CHAIN}net_sync_initial_done to ${flagLNSyncDone}"
fi
# when flag initial sync not done yet - but all chains are in sync with network
if [ "${flagLNSyncDone}" == "0" ] && [ "${flagBtcDone}" == "1" ] && [ "${flagLnOnline}" == "1" ] && [ "${flagLnSyncChain}" == "1" ]; then
# then only finished if no LNRecoveryMode or LNRecoveryDone
if [ "${flagLNRecoveryMode}" == "0" ] || [ "${flagLNRecoveryDone}" == "1" ]; then
# write event
flagLNSyncDone=1
/home/admin/config.scripts/blitz.conf.sh set ln_${LN}_${CHAIN}net_sync_initial_done ${flagLNSyncDone} /home/admin/raspiblitz.info
echo "EVENT --> ln_${LN}_${CHAIN}net_sync_initial_done to ${flagLNSyncDone}"
# LND if recovery mode was on - deactivate now
if [ "${LN}" == "lnd" ] && [ "${flagLNRecoveryMode}" == "1" ]; then
/home/admin/_cache.sh set ln_lnd_mainnet_recovery_mode 0
/home/admin/config.scripts/lnd.backup.sh mainnet recoverymode off
fi
fi
fi
done
done
fi
####################################################
# CHECK FOR End of Intial Blockhain & Lightning Sync
# bitcoin mainnet only / special on dbcache size
####################################################
# check every 60secs
recheckIBD=$((($counter % 60)+1))
if [ ${recheckIBD} -eq 1 ]; then
# check if flag exists (gets created on setup)
# this flag signals that an initial blockchain sync/chatchup was happening
flagExists=$(ls /mnt/hdd/bitcoin/blocks/selfsync.flag 2>/dev/null | grep -c "selfsync.flag")
if [ ${flagExists} -eq 1 ]; then
source <(/home/admin/_cache.sh get btc_default_sync_initialblockdownload)
if [ "${btc_default_sync_initialblockdownload}" == "0" ]; then
echo "CHECK FOR END OF IBD --> reduce RAM for next reboot"
# remove flag
rm /mnt/hdd/bitcoin/blocks/selfsync.flag
# set dbcache back to normal (to give room for other apps after reboot in the future)
kbSizeRAM=$(cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g')
# RP4 4GB
if [ ${kbSizeRAM} -gt 3500000 ]; then
echo "Detected RAM >=4GB --> normalizing bitcoin.conf"
sed -i "s/^dbcache=.*/dbcache=512/g" /mnt/hdd/bitcoin/bitcoin.conf
# RP4 2GB
elif [ ${kbSizeRAM} -gt 1500000 ]; then
echo "Detected RAM >=2GB --> normalizing bitcoin.conf"
sed -i "s/^dbcache=.*/dbcache=256/g" /mnt/hdd/bitcoin/bitcoin.conf
#RP3/4 1GB
else
echo "Detected RAM <=1GB --> normalizing bitcoin.conf"
sed -i "s/^dbcache=.*/dbcache=128/g" /mnt/hdd/bitcoin/bitcoin.conf
fi
# relax sanning on sync progress (after 30 more secs)
/home/admin/_cache.sh focus btc_default_sync_progress 10 30
fi
fi
fi
###############################
# BlitzTUI Monitoring
###############################
@ -410,43 +552,6 @@ do
fi
fi
####################################################
# CHECK FOR END OF IBD (self validation)
####################################################
# check every 60secs
recheckIBD=$((($counter % 60)+1))
if [ ${recheckIBD} -eq 1 ]; then
# check if flag exists (got created on 50syncHDD.sh)
flagExists=$(ls /mnt/hdd/${network}/blocks/selfsync.flag 2>/dev/null | grep -c "selfsync.flag")
if [ ${flagExists} -eq 1 ]; then
source <(/home/admin/config.scripts/network.aliases.sh getvars)
finishedIBD=$($bitcoincli_alias getblockchaininfo | grep "initialblockdownload" | grep -c "false")
if [ ${finishedIBD} -eq 1 ]; then
echo "CHECK FOR END OF IBD --> reduce RAM for next reboot"
# remove flag
rm /mnt/hdd/${network}/blocks/selfsync.flag
# set dbcache back to normal (to give room for other apps after reboot in the future)
kbSizeRAM=$(cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g')
if [ ${kbSizeRAM} -gt 1500000 ]; then
echo "Detected RAM >1GB --> optimizing ${network}.conf"
sed -i "s/^dbcache=.*/dbcache=512/g" /mnt/hdd/${network}/${network}.conf
else
echo "Detected RAM 1GB --> optimizing ${network}.conf"
sed -i "s/^dbcache=.*/dbcache=128/g" /mnt/hdd/${network}/${network}.conf
fi
# relax sanning on sync progress (after 30 more secs)
/home/admin/_cache.sh focus btc_default_sync_progress 10 30
fi
fi
fi
###############################
# Prepare next loop
###############################

View File

@ -48,10 +48,22 @@ sudo /home/admin/config.scripts/blitz.ssh.sh checkrepair >> ${logFile}
echo "## INIT raspiblitz.info" >> $logFile
# set default values for raspiblitz.info (that are not set by build_sdcard.sh)
setupPhase='boot'
setupStep=0
fsexpanded=0
fundRecovery=0
btc_mainnet_sync_initial_done=0
btc_testnet_sync_initial_done=0
btc_signet_sync_initial_done=0
ln_lnd_mainnet_sync_initial_done=0
ln_lnd_testnet_sync_initial_done=0
ln_lnd_signet_sync_initial_done=0
ln_cl_mainnet_sync_initial_done=0
ln_cl_testnet_sync_initial_done=0
ln_cl_signet_sync_initial_done=0
# load already persisted valued (overwriting defaults if exist)
source ${infoFile} 2>/dev/null
@ -63,9 +75,18 @@ echo "displayClass=${displayClass}" >> $infoFile
echo "displayType=${displayType}" >> $infoFile
echo "setupPhase=${setupPhase}" >> $infoFile
echo "setupStep=${setupStep}" >> $infoFile
echo "fundRecovery=${fundRecovery}" >> $infoFile
echo "fsexpanded=${fsexpanded}" >> $infoFile
echo "state=starting" >> $infoFile
echo "btc_mainnet_sync_initial_done=${btc_mainnet_sync_initial_done}" >> $infoFile
echo "btc_testnet_sync_initial_done=${btc_testnet_sync_initial_done}" >> $infoFile
echo "btc_signet_sync_initial_done=${btc_signet_sync_initial_done}" >> $infoFile
echo "ln_lnd_mainnet_sync_initial_done=${ln_lnd_mainnet_sync_initial_done}" >> $infoFile
echo "ln_lnd_testnet_sync_initial_done=${ln_lnd_testnet_sync_initial_done}" >> $infoFile
echo "ln_lnd_signet_sync_initial_done=${ln_lnd_signet_sync_initial_done}" >> $infoFile
echo "ln_cl_mainnet_sync_initial_done=${ln_cl_mainnet_sync_initial_done}" >> $infoFile
echo "ln_cl_testnet_sync_initial_done=${ln_cl_testnet_sync_initial_done}" >> $infoFile
echo "ln_cl_signet_sync_initial_done=${ln_cl_signet_sync_initial_done}" >> $infoFile
sudo chmod 664 ${infoFile}
# write content of raspiblitz.info to logs
@ -541,10 +562,16 @@ if [ ${isMounted} -eq 0 ]; then
echo "# lsblk -o NAME,FSTYPE,LABEL " >> ${logFile}
lsblk -o NAME,FSTYPE,LABEL >> ${logFile}
# if migrationFile was uploaded - now import it
# load fresh setup data
echo "# Sourcing ${setupFile} " >> ${logFile}
source ${setupFile}
# if migrationFile was uploaded (value from raspiblitz.setup) - now import
echo "# migrationFile(${migrationFile})" >> ${logFile}
if [ "${migrationFile}" != "" ]; then
echo "##### IMPORT MIGRATIONFILE: ${migrationFile}" >> ${logFile}
# unpack
sed -i "s/^message=.*/message='Unpacking Migration Data'/g" ${infoFile}
source <(/home/admin/config.scripts/blitz.migration.sh import "${migrationFile}")
@ -555,6 +582,13 @@ if [ ${isMounted} -eq 0 ]; then
exit 1
fi
# make sure a raspiblitz.conf exists after migration
confExists=$(ls /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "raspiblitz.conf")
if [ "${confExists}" != "1" ]; then
/home/admin/config.scripts/blitz.error.sh _bootstrap.sh "migration-failed" "missing-config" "After runnign migration process - no raspiblitz.conf abvailable." ${logFile}
exit 1
fi
# signal recovery provision phase
setupPhase="recovery"
/home/admin/_cache.sh set setupPhase "${setupPhase}"

View File

@ -189,7 +189,6 @@ function status() {
echo
echo "Keep X pressed to EXIT loop ... (please wait)"
echo
/home/admin/_cache.sh set system_scan_all_temp "1"
sleep 4
while :
do
@ -203,7 +202,6 @@ function status() {
# check if user wants to abort session
if [ "${keyPressed}" = "x" ]; then
echo
/home/admin/_cache.sh set system_scan_all_temp "0"
echo "Returning to menu ....."
sleep 4
break

View File

@ -29,7 +29,7 @@ echo "###################################" >> ${logFile}
/home/admin/_cache.sh set message "Provision Migration"
if [ "${hddGotMigrationData}" == "" ]; then
/home/admin/config.scripts/blitz.error.sh _provision.migration.sh "missing-hostnamemigrationdata" "missing hddGotMigrationData" "" ${logFile}
/home/admin/config.scripts/blitz.error.sh _provision.migration.sh "missing-migrationdata" "missing hddGotMigrationData" "" ${logFile}
exit 2
fi
@ -45,7 +45,14 @@ if [ "${err}" != "" ]; then
exit 3
fi
# make sure for the rest of the seup info is set correctly
# make sure a raspiblitz.conf exists after migration
confExists=$(ls /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "raspiblitz.conf")
if [ "${confExists}" != "1" ]; then
/home/admin/config.scripts/blitz.error.sh _provision.migration.sh "missing-config" "no /mnt/hdd/raspiblitz.conf" "After runningn migration process - no raspiblitz.conf abvailable." ${logFile}
exit 6
fi
# make sure for the rest of the setup info is set correctly
/home/admin/config.scripts/blitz.conf.sh set network "bitcoin"
/home/admin/config.scripts/blitz.conf.sh set chain "main"

View File

@ -32,6 +32,13 @@ echo "###################################" >> ${logFile}
echo "# _provision.setup.sh" >> ${logFile}
echo "###################################" >> ${logFile}
# make sure a raspiblitz.conf exists
confExists=$(ls /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "raspiblitz.conf")
if [ "${confExists}" != "1" ]; then
/home/admin/config.scripts/blitz.error.sh _provision.setup.sh "missing-config" "No raspiblitz.conf abvailable." ${logFile}
exit 6
fi
###################################
# Preserve SSH keys
# just copy dont link anymore
@ -81,7 +88,7 @@ echo "# setting PASSWORD B" >> ${logFile}
/home/admin/config.scripts/blitz.setpassword.sh b "${passwordB}" >> ${logFile}
# optimize RAM for blockchain validation (bitcoin only)
if [ "${network}" == "bitcoin" ] && [ "${hddBlocksBitcoin}" == "0" ]; then
if [ "${network}" == "bitcoin" ]; then
echo "*** Optimizing RAM for Sync ***" >> ${logFile}
kbSizeRAM=$(cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g')
echo "kbSizeRAM(${kbSizeRAM})" >> ${logFile}
@ -259,8 +266,10 @@ if [ "${lightning}" == "lnd" ]; then
exit 12
fi
echo "Rescanning addresses takes a long time" >> ${logFile}
echo "use the RESCAN option in the REPAIR-LND menu after LND is synced or 'lncli unlock ---recovery_window 5000'" >> ${logFile}
# set lnd into recovery mode (gets activated after setup reboot)
/home/admin/config.scripts/lnd.backup.sh mainnet recoverymode on >> ${logFile}
echo "Rescanning will activate after setup-reboot ..." >> ${logFile}
# WALLET --> NEW
else
@ -312,40 +321,6 @@ if [ "${lightning}" == "lnd" ]; then
exit 15
fi
# restore SCB
if [ "${staticchannelbackup}" != "" ]; then
# LND was restarted so need to unlock
echo "WALLET --> UNLOCK WALLET - SCAN 0" >> ${logFile}
/home/admin/_cache.sh set message "LND Wallet Unlock - scan 0"
source <(/home/admin/config.scripts/lnd.initwallet.py unlock "${chain}net" "${passwordC}" 0)
if [ "${err}" != "" ]; then
echo "lnd-wallet-unlock" "lnd.initwallet.py unlock returned error" "/home/admin/config.scripts/lnd.initwallet.py unlock ${chain}net ... --> ${err} + ${errMore}"
if [ "${errMore}" = "wallet already unlocked, WalletUnlocker service is no longer available" ]; then
echo "The wallet is already unlocked, continue."
else
exit 11
fi
fi
echo "WALLET --> SCB" >> ${logFile}
/home/admin/_cache.sh set message "LND Wallet (SEED & SCB)"
macaroonPath="/home/admin/.lnd/data/chain/${network}/${chain}net/admin.macaroon"
source <(/home/admin/config.scripts/lnd.initwallet.py scb "${chain}net" "/home/admin/channel.backup" "${macaroonPath}")
if [ "${err}" != "" ]; then
echo "lnd-wallet-seed+scb" "lnd.initwallet.py scb returned error" "/home/admin/config.scripts/lnd.initwallet.py scb mainnet ... --> ${err} + ${errMore}" ${logFile}
if [ "${errMore}" = "server is still in the process of starting" ]; then
echo "The SCB recovery is not possible now - use the RETRYSCB option the REPAIR-LND menu after LND is synced." >> ${logFile}
echo "Can repeat the SCB recovery until all peers have force closed the channels to this node." >> ${logFile}
else
exit 12
fi
fi
fi
echo "Rescanning addresses takes a long time" >> ${logFile}
echo "use the RESCAN option in the REPAIR-LND menu after LND is synced or 'lncli unlock ---recovery_window 5000'" >> ${logFile}
# stop lnd for the rest of the provision process
echo "stopping lnd for the rest provision again (will start on next boot)" >> ${logFile}
systemctl stop lnd >> ${logFile}

View File

@ -5,9 +5,8 @@ configFile="/mnt/hdd/raspiblitz.conf"
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then
echo "RaspiBlitz Config Edit - adds value to file & cache and creates entries if needed:"
echo "blitz.conf.sh set [key] [value]"
echo "blitz.conf.sh delete [key]"
echo "To use values use in shell scripts: source ${configFile}"
echo "blitz.conf.sh set [key] [value] [?conffile]"
echo "blitz.conf.sh delete [key] [?conffile]"
echo
exit 1
fi
@ -17,7 +16,7 @@ if [ "$1" = "set" ]; then
# get parameters
keystr=$2
valuestr=$3
overflow=$4
configfileAlternative=$4
# check that key & value are given
if [ "${keystr}" == "" ] || [ "${valuestr}" == "" ]; then
@ -26,11 +25,9 @@ if [ "$1" = "set" ]; then
exit 1
fi
# check if input quotes are missing (there should be no 4th parameter)
if [ "${overflow}" != "" ]; then
echo "# blitz.conf.sh $@"
echo "# FAIL: possible missing quotes in value string"
exit 2
# optional another configfile
if [ "${configfileAlternative}" != "" ]; then
configFile="${configfileAlternative}"
fi
# update config value in cache
@ -47,7 +44,7 @@ if [ "$1" = "set" ]; then
# check if key needs to be added (prepare new entry)
entryExists=$(grep -c "^${keystr}=" ${configFile})
if [ ${entryExists} -eq 0 ]; then
echo "${keystr}=" | sudo tee -a ${configFile}
echo "${keystr}=" | sudo tee -a ${configFile} 1>/dev/null
fi
# add valuestr quotes if not standard values
@ -63,6 +60,7 @@ elif [ "$1" = "delete" ]; then
# get parameters
keystr=$2
configfileAlternative=$3
# check that key & value are given
if [ "${keystr}" == "" ]; then
@ -70,6 +68,11 @@ elif [ "$1" = "delete" ]; then
exit 1
fi
# optional another configfile
if [ "${configfileAlternative}" != "" ]; then
configFile="${configfileAlternative}"
fi
# delete value
sudo sed -i "/^${keystr}=/d" ${configFile} 2>/dev/null

View File

@ -30,7 +30,7 @@ fi
btrfsInstalled=$(btrfs --version 2>/dev/null | grep -c "btrfs-progs")
if [ ${btrfsInstalled} -eq 0 ]; then
>&2 echo "# Installing BTRFS ..."
sudo apt-get install -y btrfs-tools 1>/dev/null
apt-get install -y btrfs-tools 1>/dev/null
fi
btrfsInstalled=$(btrfs --version 2>/dev/null | grep -c "btrfs-progs")
if [ ${btrfsInstalled} -eq 0 ]; then
@ -46,9 +46,10 @@ fi
# is global so that also other parts of this script can use this
# basics
isMounted=$(sudo df | grep -c /mnt/hdd)
isBTRFS=$(sudo btrfs filesystem show 2>/dev/null| grep -c 'BLITZSTORAGE')
isMounted=$(df | grep -c /mnt/hdd)
isBTRFS=$(btrfs filesystem show 2>/dev/null| grep -c 'BLITZSTORAGE')
isRaid=$(btrfs filesystem df /mnt/hdd 2>/dev/null | grep -c "Data, RAID1")
isZFS=$(zfs list 2>/dev/null | grep -c "/mnt/hdd")
isSSD="0"
# determine if swap is external on or not
@ -82,12 +83,12 @@ if [ "$1" = "status" ]; then
# will then be used to offer formatting and permanent mounting
hdd=""
sizeDataPartition=0
OSPartition=$(sudo df /usr 2>/dev/null | grep dev | cut -d " " -f 1 | sed "s#/dev/##g")
OSPartition=$(df /usr 2>/dev/null | grep dev | cut -d " " -f 1 | sed "s#/dev/##g")
# detect boot partition on UEFI systems
bootPartition=$(sudo df /boot/efi 2>/dev/null | grep dev | cut -d " " -f 1 | sed "s#/dev/##g")
bootPartition=$(df /boot/efi 2>/dev/null | grep dev | cut -d " " -f 1 | sed "s#/dev/##g")
if [ ${#bootPartition} -eq 0 ]; then
# for non UEFI
bootPartition=$(sudo df /boot 2>/dev/null | grep dev | cut -d " " -f 1 | sed "s#/dev/##g")
bootPartition=$(df /boot 2>/dev/null | grep dev | cut -d " " -f 1 | sed "s#/dev/##g")
fi
lsblk -o NAME,SIZE -b | grep -P "[s|vn][dv][a-z][0-9]?" > .lsblk.tmp
while read line; do
@ -108,7 +109,7 @@ if [ "$1" = "status" ]; then
# count partitions
testpartitioncount=0
if [ ${#testdevice} -gt 0 ]; then
testpartitioncount=$(sudo fdisk -l | grep /dev/$testdevice | wc -l)
testpartitioncount=$(fdisk -l | grep /dev/$testdevice | wc -l)
# do not count line with disk info
testpartitioncount=$((testpartitioncount-1))
fi
@ -147,7 +148,7 @@ if [ "$1" = "status" ]; then
# make sure to use the biggest
if [ ${testsize} -gt ${sizeDataPartition} ]; then
# Partition to be created is smaller than disk so this is not correct (but close)
sizeDataPartition=$(sudo fdisk -l /dev/$testdevice | grep GiB | cut -d " " -f 5)
sizeDataPartition=$(fdisk -l /dev/$testdevice | grep GiB | cut -d " " -f 5)
hddDataPartition="${testdevice}1"
hdd="${testdevice}"
fi
@ -162,7 +163,7 @@ if [ "$1" = "status" ]; then
fi
# try to detect if its an SSD
isSSD=$(sudo cat /sys/block/${hdd}/queue/rotational 2>/dev/null | grep -c 0)
isSSD=$(cat /sys/block/${hdd}/queue/rotational 2>/dev/null | grep -c 0)
echo "isSSD=${isSSD}"
# display results from hdd & partition detection
@ -170,7 +171,7 @@ if [ "$1" = "status" ]; then
hddBytes=0
hddGigaBytes=0
if [ "${hdd}" != "" ]; then
hddBytes=$(sudo fdisk -l /dev/$hdd | grep GiB | cut -d " " -f 5)
hddBytes=$(fdisk -l /dev/$hdd | grep GiB | cut -d " " -f 5)
hddGigaBytes=$(echo "scale=0; ${hddBytes}/1024/1024/1024" | bc -l)
fi
echo "hddBytes=${hddBytes}"
@ -200,14 +201,14 @@ if [ "$1" = "status" ]; then
# temp mount data drive
mountError=""
sudo mkdir -p /mnt/hdd
mkdir -p /mnt/hdd
if [ "${hddFormat}" = "ext4" ]; then
hddDataPartitionExt4=$hddDataPartition
mountError=$(sudo mount /dev/${hddDataPartitionExt4} /mnt/hdd 2>&1)
mountError=$(mount /dev/${hddDataPartitionExt4} /mnt/hdd 2>&1)
isTempMounted=$(df | grep /mnt/hdd | grep -c ${hddDataPartitionExt4})
fi
if [ "${hddFormat}" = "btrfs" ]; then
mountError=$(sudo mount -o degraded /dev/${hdd}1 /mnt/hdd 2>&1)
mountError=$(mount -o degraded /dev/${hdd}1 /mnt/hdd 2>&1)
isTempMounted=$(df | grep /mnt/hdd | grep -c ${hdd})
fi
@ -257,18 +258,18 @@ if [ "$1" = "status" ]; then
fi
# comment this line out if case to study the contect of the data section
sudo umount /mnt/hdd
umount /mnt/hdd
fi
# temp storage data drive
sudo mkdir -p /mnt/storage
mkdir -p /mnt/storage
if [ "${hddFormat}" = "btrfs" ]; then
# in btrfs setup the second partition is storage partition
sudo mount /dev/${hdd}2 /mnt/storage 2>/dev/null
mount /dev/${hdd}2 /mnt/storage 2>/dev/null
isTempMounted=$(df | grep /mnt/storage | grep -c ${hdd})
else
# in ext4 setup the partition is also the storage partition
sudo mount /dev/${hddDataPartitionExt4} /mnt/storage 2>/dev/null
mount /dev/${hddDataPartitionExt4} /mnt/storage 2>/dev/null
isTempMounted=$(df | grep /mnt/storage | grep -c ${hddDataPartitionExt4})
fi
if [ ${isTempMounted} -eq 0 ]; then
@ -279,7 +280,7 @@ if [ "$1" = "status" ]; then
# Pre-Setup Invetigation of STORAGE-PART
# check for blockchain data on storage
hddBlocksBitcoin=$(sudo ls /mnt/storage${subVolumeDir}/bitcoin/blocks/blk00000.dat 2>/dev/null | grep -c '.dat')
hddBlocksBitcoin=$(ls /mnt/storage${subVolumeDir}/bitcoin/blocks/blk00000.dat 2>/dev/null | grep -c '.dat')
echo "hddBlocksBitcoin=${hddBlocksBitcoin}"
if [ "${blockchainType}" = "bitcoin" ] && [ ${hddBlocksBitcoin} -eq 1 ]; then
echo "hddGotBlockchain=1"
@ -311,9 +312,9 @@ if [ "$1" = "status" ]; then
hddGotMigrationDataExtra=""
if [ "${hddFormat}" = "ext4" ]; then
# check for other node implementations
isUmbrelHDD=$(sudo ls /mnt/storage/umbrel/info.json 2>/dev/null | grep -c '.json')
isCitadelHDD=$(sudo ls /mnt/storage/citadel/info.json 2>/dev/null | grep -c '.json')
isMyNodeHDD=$(sudo ls /mnt/storage/mynode/bitcoin/bitcoin.conf 2>/dev/null | grep -c '.conf')
isUmbrelHDD=$(ls /mnt/storage/umbrel/info.json 2>/dev/null | grep -c '.json')
isCitadelHDD=$(ls /mnt/storage/citadel/info.json 2>/dev/null | grep -c '.json')
isMyNodeHDD=$(ls /mnt/storage/mynode/bitcoin/bitcoin.conf 2>/dev/null | grep -c '.conf')
if [ ${isUmbrelHDD} -gt 0 ]; then
hddGotMigrationData="umbrel"
lndVersion=$(grep "lightninglabs/lnd" /mnt/storage/umbrel/docker-compose.yml 2>/dev/null | sed 's/.*lnd://' | sed 's/@.*//')
@ -331,7 +332,7 @@ if [ "$1" = "status" ]; then
echo "hddGotMigrationData='${hddGotMigrationData}'"
# comment this line out if case to study the contect of the storage section
sudo umount /mnt/storage
umount /mnt/storage
fi
else
# if not ext4 or btrfs - there is no usable data
@ -345,9 +346,16 @@ if [ "$1" = "status" ]; then
# STATUS INFO WHEN MOUNTED
# output data drive
if [ ${isBTRFS} -eq 1 ]; then
if [ "${isBTRFS}" -gt 0 ]; then
# on btrfs date the storage partition as the data partition
hddDataPartition=$(df | grep "/mnt/storage$" | cut -d " " -f 1 | cut -d "/" -f 3)
elif [ "${isZFS}" -gt 0 ]; then
# a ZFS pool has no leading /
hddDataPartition=$(df | grep "/mnt/hdd$" | cut -d " " -f 1 | cut -d "/" -f 2)
if [ ${#hddDataPartition} -eq 0 ];then
# just a pool, no filesystem
hddDataPartition=$(df | grep "/mnt/hdd$" | cut -d " " -f 1 | cut -d "/" -f 1)
fi
else
# on ext4 its the whole /mnt/hdd
hddDataPartition=$(df | grep "/mnt/hdd$" | cut -d " " -f 1 | cut -d "/" -f 3)
@ -357,7 +365,7 @@ if [ "$1" = "status" ]; then
if [ "${hddFormat}" = "ext4" ]; then
hddDataPartitionExt4=$hddDataPartition
fi
hddRaspiData=$(sudo ls -l /mnt/hdd | grep -c raspiblitz.conf)
hddRaspiData=$(ls -l /mnt/hdd | grep -c raspiblitz.conf)
echo "hddRaspiData=${hddRaspiData}"
hddRaspiVersion=""
if [ ${hddRaspiData} -eq 1 ]; then
@ -366,7 +374,7 @@ if [ "$1" = "status" ]; then
fi
echo "hddRaspiVersion='${hddRaspiVersion}'"
isSSD=$(sudo cat /sys/block/${hdd}/queue/rotational 2>/dev/null | grep -c 0)
isSSD=$(cat /sys/block/${hdd}/queue/rotational 2>/dev/null | grep -c 0)
echo "isSSD=${isSSD}"
echo "datadisk='${hdd}'"
@ -375,7 +383,7 @@ if [ "$1" = "status" ]; then
echo "hddPartitionCandidate='${hddDataPartition}'"
# check if blockchain data is available
hddBlocksBitcoin=$(sudo ls /mnt/hdd/bitcoin/blocks/blk00000.dat 2>/dev/null | grep -c '.dat')
hddBlocksBitcoin=$(ls /mnt/hdd/bitcoin/blocks/blk00000.dat 2>/dev/null | grep -c '.dat')
echo "hddBlocksBitcoin=${hddBlocksBitcoin}"
if [ "${blockchainType}" = "bitcoin" ] && [ ${hddBlocksBitcoin} -eq 1 ]; then
echo "hddGotBlockchain=1"
@ -384,19 +392,18 @@ if [ "$1" = "status" ]; then
fi
# check size in bytes and GBs
sizeDataPartition=$(lsblk -o NAME,SIZE -b | grep "${hddDataPartition}" | awk '$1=$1' | cut -d " " -f 2)
if [ "${isZFS}" -gt 0 ]; then
sizeDataPartition=$(zpool list -pH | awk '{print $2}')
hddGigaBytes=$(echo "scale=0; ${sizeDataPartition}/1024/1024/1024" | bc -l)
else
sizeDataPartition=$(lsblk -o NAME,SIZE -b | grep "${hddDataPartition}" | awk '$1=$1' | cut -d " " -f 2)
hddGigaBytes=$(echo "scale=0; ${sizeDataPartition}/1024/1024/1024" | bc -l)
fi
echo "hddBytes=${sizeDataPartition}"
hddGigaBytes=$(echo "scale=0; ${sizeDataPartition}/1024/1024/1024" | bc -l)
echo "hddGigaBytes=${hddGigaBytes}"
# used space - at the moment just string info to display
if [ ${isBTRFS} -eq 0 ]; then
# EXT4 calculations
hdd_used_space=$(df -h | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 3 2>/dev/null)
hdd_used_ratio=$(df -h | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 5 | tr -dc '0-9' 2>/dev/null)
hdd_data_free1Kblocks=$(df -h -k /dev/${hddDataPartitionExt4} | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9')
hddUsedInfo="${hdd_used_space} (${hdd_used_ratio}%)"
else
if [ "${isBTRFS}" -gt 0 ]; then
# BTRFS calculations
# TODO: this is the final/correct way - make better later
# https://askubuntu.com/questions/170044/btrfs-and-missing-free-space
@ -404,6 +411,18 @@ if [ "$1" = "status" ]; then
storageDrive=$(df -h | grep "/dev/${hdd}2" | sed -e's/ */ /g' | cut -d" " -f 5)
hdd_data_free1Kblocks=$(df -h -k /dev/${hdd}1 | grep "/dev/${hdd}1" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9')
hddUsedInfo="${datadrive} & ${storageDrive}"
elif [ "${isZFS}" -gt 0 ]; then
# ZFS calculations
hdd_used_space=$(zpool list -H | awk '{print $3}')
hdd_used_ratio=$((100 * ${hdd_used_space::-1} / hddGigaBytes))
hdd_data_free1Kblocks=$(($(zpool list -pH | awk '{print $4}') / 1024))
hddUsedInfo="${hdd_used_space} (${hdd_used_ratio}%)"
else
# EXT4 calculations
hdd_used_space=$(df -h | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 3 2>/dev/null)
hdd_used_ratio=$(df -h | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 5 | tr -dc '0-9' 2>/dev/null)
hdd_data_free1Kblocks=$(df -h -k /dev/${hddDataPartitionExt4} | grep "/dev/${hddDataPartitionExt4}" | sed -e's/ */ /g' | cut -d" " -f 4 | tr -dc '0-9')
hddUsedInfo="${hdd_used_space} (${hdd_used_ratio}%)"
fi
echo "hddUsedInfo='${hddUsedInfo}'"
hddDataFreeBytes=$((${hdd_data_free1Kblocks} * 1024))
@ -463,7 +482,7 @@ if [ "$1" = "status" ]; then
# show devices used for raid
raidHddDev=$(lsblk -o NAME,MOUNTPOINT | grep "/mnt/hdd" | awk '$1=$1' | cut -d " " -f 1 | sed 's/[^0-9a-z]*//g')
raidUsbDev=$(sudo btrfs filesystem show /mnt/hdd | grep -F -v "${raidHddDev}" | grep "/dev/" | cut -d "/" --f 3)
raidUsbDev=$(btrfs filesystem show /mnt/hdd | grep -F -v "${raidHddDev}" | grep "/dev/" | cut -d "/" --f 3)
echo "raidHddDev='${raidHddDev}'"
echo "raidUsbDev='${raidUsbDev}'"
@ -543,12 +562,12 @@ if [ "$1" = "format" ]; then
fi
# get basic info on data drive
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
source <(/home/admin/config.scripts/blitz.datadrive.sh status)
if [ ${isSwapExternal} -eq 1 ] && [ "${hdd}" == "${datadisk}" ]; then
>&2 echo "# Switching off external SWAP of system drive"
sudo dphys-swapfile swapoff 1>/dev/null
sudo dphys-swapfile uninstall 1>/dev/null
dphys-swapfile swapoff 1>/dev/null
dphys-swapfile uninstall 1>/dev/null
fi
>&2 echo "# Unmounting all partitions of this device"
@ -556,19 +575,19 @@ if [ "$1" = "format" ]; then
lsblk -o UUID,NAME | grep "${hdd}" | cut -d " " -f 1 | grep "-" | while read -r uuid ; do
if [ ${#uuid} -gt 0 ]; then
>&2 echo "# Cleaning /etc/fstab from ${uuid}"
sudo sed -i "/UUID=${uuid}/d" /etc/fstab
sed -i "/UUID=${uuid}/d" /etc/fstab
sync
else
>&2 echo "# skipping empty result"
fi
done
sudo mount -a
mount -a
if [ "${hdd}" == "${datadisk}" ]; then
>&2 echo "# Make sure system drives are unmounted .."
sudo umount /mnt/hdd 2>/dev/null
sudo umount /mnt/temp 2>/dev/null
sudo umount /mnt/storage 2>/dev/null
umount /mnt/hdd 2>/dev/null
umount /mnt/temp 2>/dev/null
umount /mnt/storage 2>/dev/null
unmounted1=$(df | grep -c "/mnt/hdd")
if [ ${unmounted1} -gt 0 ]; then
>&2 echo "# ERROR: failed to unmount /mnt/hdd"
@ -606,14 +625,14 @@ if [ "$1" = "format" ]; then
if [ $wipePartitions -eq 1 ]; then
# wipe all partitions and write fresh GPT
>&2 echo "# Wiping all partitions (sfdisk/wipefs)"
sudo sfdisk --delete /dev/${hdd}
sfdisk --delete /dev/${hdd}
sleep 4
sudo wipefs -a /dev/${hdd}
wipefs -a /dev/${hdd}
sleep 4
partitions=$(lsblk | grep -c "${hdd}")
if [ ${partitions} -gt 0 ]; then
>&2 echo "# WARNING: partitions are still not clean - try Quick & Dirty"
sudo dd if=/dev/zero of=/dev/${hdd} bs=512 count=1
dd if=/dev/zero of=/dev/${hdd} bs=512 count=1
fi
partitions=$(lsblk | grep -c "${hdd}")
if [ ${partitions} -gt 0 ]; then
@ -621,7 +640,7 @@ if [ "$1" = "format" ]; then
echo "error='partition cleaning failed'"
exit 1
fi
sudo parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2
parted -s /dev/${hdd} mklabel gpt 1>/dev/null 1>&2
sleep 2
sync
fi
@ -631,12 +650,12 @@ if [ "$1" = "format" ]; then
if [ "$2" = "ext4" ]; then
# prepare temp mount point
sudo mkdir -p /tmp/ext4 1>/dev/null
mkdir -p /tmp/ext4 1>/dev/null
if [ $ext4IsPartition -eq 0 ]; then
# write new EXT4 partition
>&2 echo "# Creating the one big partition"
sudo parted -s /dev/${hdd} mkpart primary ext4 1024KiB 100% 1>&2
parted -s /dev/${hdd} mkpart primary ext4 1024KiB 100% 1>&2
sleep 6
sync
# loop until the partition gets available
@ -659,7 +678,7 @@ if [ "$1" = "format" ]; then
fi
# make sure /mnt/hdd is unmounted before formatting
sudo umount -f /tmp/ext4 2>/dev/null
umount -f /tmp/ext4 2>/dev/null
unmounted=$(df | grep -c "/tmp/ext4")
if [ ${unmounted} -gt 0 ]; then
>&2 echo "# ERROR: failed to unmount /tmp/ext4"
@ -669,9 +688,9 @@ if [ "$1" = "format" ]; then
>&2 echo "# Formatting"
if [ $ext4IsPartition -eq 0 ]; then
sudo mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null
mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd}1 1>/dev/null
else
sudo mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd} 1>/dev/null
mkfs.ext4 -F -L BLOCKCHAIN /dev/${hdd} 1>/dev/null
fi
loopdone=0
loopcount=0
@ -692,9 +711,9 @@ if [ "$1" = "format" ]; then
# setting fsk check interval to 1
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467567572
if [ $ext4IsPartition -eq 0 ]; then
sudo tune2fs -c 1 /dev/${hdd}1
tune2fs -c 1 /dev/${hdd}1
else
sudo tune2fs -c 1 /dev/${hdd}
tune2fs -c 1 /dev/${hdd}
fi
>&2 echo "# OK EXT 4 format done"
@ -705,10 +724,10 @@ if [ "$1" = "format" ]; then
if [ "$2" = "btrfs" ]; then
# prepare temp mount point
sudo mkdir -p /tmp/btrfs 1>/dev/null
mkdir -p /tmp/btrfs 1>/dev/null
>&2 echo "# Creating BLITZDATA (${hdd})"
sudo parted -s -- /dev/${hdd} mkpart primary btrfs 1024KiB 30GiB 1>/dev/null
parted -s -- /dev/${hdd} mkpart primary btrfs 1024KiB 30GiB 1>/dev/null
sync
sleep 6
win=$(lsblk -o NAME | grep -c ${hdd}1)
@ -716,7 +735,7 @@ if [ "$1" = "format" ]; then
echo "error='partition failed'"
exit 1
fi
sudo mkfs.btrfs -f -L BLITZDATA /dev/${hdd}1 1>/dev/null
mkfs.btrfs -f -L BLITZDATA /dev/${hdd}1 1>/dev/null
# check result
loopdone=0
loopcount=0
@ -725,7 +744,7 @@ if [ "$1" = "format" ]; then
>&2 echo "# waiting until formatted drives gets available"
sleep 2
sync
sudo parted -l
parted -l
loopdone=$(lsblk -o NAME,LABEL | grep -c BLITZDATA)
loopcount=$(($loopcount +1))
if [ ${loopcount} -gt 60 ]; then
@ -738,18 +757,18 @@ if [ "$1" = "format" ]; then
>&2 echo "# OK BLITZDATA exists now"
>&2 echo "# Creating SubVolume for Snapshots"
sudo mount /dev/${hdd}1 /tmp/btrfs 1>/dev/null
mount /dev/${hdd}1 /tmp/btrfs 1>/dev/null
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
echo "error='mount ${hdd}1 failed'"
exit 1
fi
cd /tmp/btrfs
sudo btrfs subvolume create WORKINGDIR
subVolDATA=$(sudo btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
cd && sudo umount /tmp/btrfs
btrfs subvolume create WORKINGDIR
subVolDATA=$(btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
cd && umount /tmp/btrfs
>&2 echo "# Creating BLITZSTORAGE"
sudo parted -s -- /dev/${hdd} mkpart primary btrfs 30GiB -34GiB 1>/dev/null
parted -s -- /dev/${hdd} mkpart primary btrfs 30GiB -34GiB 1>/dev/null
sync
sleep 6
win=$(lsblk -o NAME | grep -c ${hdd}2)
@ -757,7 +776,7 @@ if [ "$1" = "format" ]; then
echo "error='partition failed'"
exit 1
fi
sudo mkfs.btrfs -f -L BLITZSTORAGE /dev/${hdd}2 1>/dev/null
mkfs.btrfs -f -L BLITZSTORAGE /dev/${hdd}2 1>/dev/null
# check result
loopdone=0
loopcount=0
@ -766,7 +785,7 @@ if [ "$1" = "format" ]; then
>&2 echo "# waiting until formatted drives gets available"
sleep 2
sync
sudo parted -l
parted -l
loopdone=$(lsblk -o NAME,LABEL | grep -c BLITZSTORAGE)
loopcount=$(($loopcount +1))
if [ ${loopcount} -gt 60 ]; then
@ -778,17 +797,17 @@ if [ "$1" = "format" ]; then
>&2 echo "# OK BLITZSTORAGE exists now"
>&2 echo "# Creating SubVolume for Snapshots"
sudo mount /dev/${hdd}2 /tmp/btrfs 1>/dev/null
mount /dev/${hdd}2 /tmp/btrfs 1>/dev/null
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
echo "error='mount ${hdd}2 failed'"
exit 1
fi
cd /tmp/btrfs
sudo btrfs subvolume create WORKINGDIR
cd && sudo umount /tmp/btrfs
btrfs subvolume create WORKINGDIR
cd && umount /tmp/btrfs
>&2 echo "# Creating the FAT32 partition"
sudo parted -s -- /dev/${hdd} mkpart primary fat32 -34GiB 100% 1>/dev/null
parted -s -- /dev/${hdd} mkpart primary fat32 -34GiB 100% 1>/dev/null
sync && sleep 3
win=$(lsblk -o NAME | grep -c ${hdd}3)
if [ ${win} -eq 0 ]; then
@ -797,7 +816,7 @@ if [ "$1" = "format" ]; then
fi
>&2 echo "# Creating Volume BLITZTEMP (format)"
sudo mkfs -t vfat -n BLITZTEMP /dev/${hdd}3 1>/dev/null
mkfs -t vfat -n BLITZTEMP /dev/${hdd}3 1>/dev/null
# check result
loopdone=0
loopcount=0
@ -806,7 +825,7 @@ if [ "$1" = "format" ]; then
>&2 echo "# waiting until formatted drives gets available"
sleep 2
sync
sudo parted -l
parted -l
loopdone=$(lsblk -o NAME,LABEL | grep -c BLITZTEMP)
loopcount=$(($loopcount +1))
if [ ${loopcount} -gt 60 ]; then
@ -856,9 +875,9 @@ if [ "$1" = "fstab" ]; then
# unmount
if [ ${isMounted} -eq 1 ]; then
echo "# unmounting all drives"
sudo umount /mnt/hdd > /dev/null 2>&1
sudo umount /mnt/storage > /dev/null 2>&1
sudo umount /mnt/temp > /dev/null 2>&1
umount /mnt/hdd > /dev/null 2>&1
umount /mnt/storage > /dev/null 2>&1
umount /mnt/temp > /dev/null 2>&1
fi
if [ "${hddFormat}" = "ext4" ]; then
@ -884,15 +903,15 @@ if [ "$1" = "fstab" ]; then
# write new /etc/fstab & mount
echo "# mount /mnt/hdd"
sudo mkdir -p /mnt/hdd 1>/dev/null
mkdir -p /mnt/hdd 1>/dev/null
updated=$(cat /etc/fstab | grep -c "/mnt/hdd")
if [ $updated -eq 0 ]; then
echo "# updating /etc/fstab"
sudo sed "/raspiblitz/ i UUID=${uuid1} /mnt/hdd ext4 noexec,defaults 0 2" -i /etc/fstab 1>/dev/null
sed "/raspiblitz/ i UUID=${uuid1} /mnt/hdd ext4 noexec,defaults 0 2" -i /etc/fstab 1>/dev/null
fi
sync
sudo mount -a 1>/dev/null
mount -a 1>/dev/null
# loop mounts are available
mountactive1=0
@ -921,15 +940,15 @@ if [ "$1" = "fstab" ]; then
# get info on: Data Drive
uuidDATA=$(lsblk -o UUID,NAME,LABEL | grep "${hdd}" | grep "BLITZDATA" | cut -d " " -f 1 | grep "-")
sudo mkdir -p /tmp/btrfs
sudo mount /dev/${hdd}1 /tmp/btrfs 1>/dev/null
mkdir -p /tmp/btrfs
mount /dev/${hdd}1 /tmp/btrfs 1>/dev/null
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
echo "error='mount ${hdd}1 failed'"
exit 1
fi
cd /tmp/btrfs
subVolDATA=$(sudo btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
cd && sudo umount /tmp/btrfs
subVolDATA=$(btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
cd && umount /tmp/btrfs
echo "uuidDATA='${uuidDATA}'"
echo "subVolDATA='${subVolDATA}'"
if [ ${#uuidDATA} -eq 0 ] || [ ${#subVolDATA} -eq 0 ]; then
@ -939,14 +958,14 @@ if [ "$1" = "fstab" ]; then
# get info on: Storage Drive
uuidSTORAGE=$(lsblk -o UUID,NAME,LABEL | grep "${hdd}" | grep "BLITZSTORAGE" | cut -d " " -f 1 | grep "-")
sudo mount /dev/${hdd}2 /tmp/btrfs 1>/dev/null
mount /dev/${hdd}2 /tmp/btrfs 1>/dev/null
if [ $(df | grep -c "/tmp/btrfs") -eq 0 ]; then
echo "error='mount ${hdd}2 failed'"
exit 1
fi
cd /tmp/btrfs
subVolSTORAGE=$(sudo btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
cd && sudo umount /tmp/btrfs
subVolSTORAGE=$(btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
cd && umount /tmp/btrfs
echo "uuidSTORAGE='${uuidSTORAGE}'"
echo "subVolSTORAGE='${subVolSTORAGE}'"
if [ ${#uuidSTORAGE} -eq 0 ] || [ ${#subVolSTORAGE} -eq 0 ]; then
@ -965,7 +984,7 @@ if [ "$1" = "fstab" ]; then
# remove old entries from fstab
lsblk -o UUID,NAME | grep "${hdd}" | cut -d " " -f 1 | grep "-" | while read -r uuid ; do
>&2 echo "# Cleaning /etc/fstab from ${uuid}"
sudo sed -i "/UUID=${uuid}/d" /etc/fstab
sed -i "/UUID=${uuid}/d" /etc/fstab
sync
done
@ -974,16 +993,16 @@ if [ "$1" = "fstab" ]; then
bitcoinGID=$(id -g bitcoin)
# modifying /etc/fstab & mount
sudo mkdir -p /mnt/hdd 1>/dev/null
mkdir -p /mnt/hdd 1>/dev/null
fstabAdd1="UUID=${uuidDATA} /mnt/hdd btrfs noexec,defaults,subvolid=${subVolDATA} 0 2"
sudo sed "3 a ${fstabAdd1}" -i /etc/fstab 1>/dev/null
sudo mkdir -p /mnt/storage 1>/dev/null
sed "3 a ${fstabAdd1}" -i /etc/fstab 1>/dev/null
mkdir -p /mnt/storage 1>/dev/null
fstabAdd2="UUID=${uuidSTORAGE} /mnt/storage btrfs noexec,defaults,subvolid=${subVolSTORAGE} 0 2"
sudo sed "4 a ${fstabAdd2}" -i /etc/fstab 1>/dev/null
sudo mkdir -p /mnt/temp 1>/dev/null
sed "4 a ${fstabAdd2}" -i /etc/fstab 1>/dev/null
mkdir -p /mnt/temp 1>/dev/null
fstabAdd3="UUID=${uuidTEMP} /mnt/temp vfat noexec,defaults,uid=${bitcoinUID},gid=${bitcoinGID} 0 2"
sudo sed "5 a ${fstabAdd3}" -i /etc/fstab 1>/dev/null
sync && sudo mount -a 1>/dev/null
sed "5 a ${fstabAdd3}" -i /etc/fstab 1>/dev/null
sync && mount -a 1>/dev/null
# test mount
mountactive1=0
@ -1098,7 +1117,7 @@ if [ "$1" = "raid" ] && [ "$2" = "on" ]; then
# remove all partitions from device
for v_partition in $(parted -s /dev/${usbdev} print|awk '/^ / {print $1}')
do
sudo parted -s /dev/${usbdev} rm ${v_partition}
parted -s /dev/${usbdev} rm ${v_partition}
done
# check if usb device is at least 30GB big
@ -1111,8 +1130,8 @@ if [ "$1" = "raid" ] && [ "$2" = "on" ]; then
# add usb device as raid for data
>&2 echo "# adding ${usbdev} as BTRFS raid1 for /mnt/hdd"
sudo btrfs device add -f /dev/${usbdev} /mnt/hdd 1>/dev/null
sudo btrfs filesystem balance start -dconvert=raid1 -mconvert=raid1 /mnt/hdd 1>/dev/null
btrfs device add -f /dev/${usbdev} /mnt/hdd 1>/dev/null
btrfs filesystem balance start -dconvert=raid1 -mconvert=raid1 /mnt/hdd 1>/dev/null
>&2 echo "# OK - ${usbdev} is now part of a RAID1 for your RaspiBlitz data"
exit 0
@ -1123,7 +1142,7 @@ fi
if [ "$1" = "raid" ] && [ "$2" = "off" ]; then
# checking if BTRFS mode
isBTRFS=$(sudo btrfs filesystem show 2>/dev/null| grep -c 'BLITZSTORAGE')
isBTRFS=$(btrfs filesystem show 2>/dev/null| grep -c 'BLITZSTORAGE')
if [ ${isBTRFS} -eq 0 ]; then
echo "error='raid only BTRFS'"
exit 1
@ -1136,8 +1155,8 @@ if [ "$1" = "raid" ] && [ "$2" = "off" ]; then
fi
>&2 echo "# removing USB DEV from RAID"
sudo btrfs balance start -mconvert=dup -dconvert=single /mnt/hdd 1>/dev/null
sudo btrfs device remove ${deviceToBeRemoved} /mnt/hdd 1>/dev/null
btrfs balance start -mconvert=dup -dconvert=single /mnt/hdd 1>/dev/null
btrfs device remove ${deviceToBeRemoved} /mnt/hdd 1>/dev/null
isRaid=$(btrfs filesystem df /mnt/hdd 2>/dev/null | grep -c "Data, RAID1")
if [ ${isRaid} -eq 0 ]; then
@ -1195,18 +1214,18 @@ if [ "$1" = "snapshot" ]; then
>&2 echo "# Preparing Snapshot ..."
# make sure backup folder exists
sudo mkdir -p ${subvolume}/snapshots
mkdir -p ${subvolume}/snapshots
# delete old backup if existing
oldBackupExists=$(sudo ls ${subvolume}/snapshots | grep -c backup)
oldBackupExists=$(ls ${subvolume}/snapshots | grep -c backup)
if [ ${oldBackupExists} -gt 0 ]; then
>&2 echo "# Deleting old snapshot"
sudo btrfs subvolume delete ${subvolume}/snapshots/backup 1>/dev/null
btrfs subvolume delete ${subvolume}/snapshots/backup 1>/dev/null
fi
>&2 echo "# Creating Snapshot ..."
sudo btrfs subvolume snapshot ${subvolume} ${subvolume}/snapshots/backup 1>/dev/null
if [ $(sudo btrfs subvolume list ${subvolume} | grep -c snapshots/backup) -eq 0 ]; then
btrfs subvolume snapshot ${subvolume} ${subvolume}/snapshots/backup 1>/dev/null
if [ $(btrfs subvolume list ${subvolume} | grep -c snapshots/backup) -eq 0 ]; then
echo "error='not created'"
exit 1
else
@ -1217,25 +1236,25 @@ if [ "$1" = "snapshot" ]; then
elif [ "$3" = "rollback" ]; then
# check if an old snapshot exists
oldBackupExists=$(sudo ls ${subvolume}/snapshots | grep -c backup)
oldBackupExists=$(ls ${subvolume}/snapshots | grep -c backup)
if [ ${oldBackupExists} -eq 0 ]; then
echo "error='no old snapshot found'"
exit 1
fi
>&2 echo "# Resetting state to old Snapshot ..."
sudo umount ${subvolume}
sudo mkdir -p /tmp/btrfs 1>/dev/null
sudo mount ${partition} /tmp/btrfs
sudo mv /tmp/btrfs/WORKINGDIR/snapshots/backup /tmp/btrfs/backup
sudo btrfs subvolume delete /tmp/btrfs/WORKINGDIR
sudo mv /tmp/btrfs/backup /tmp/btrfs/WORKINGDIR
subVolID=$(sudo btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
sudo sed -i "/${subvolumeESC}/d" /etc/fstab
umount ${subvolume}
mkdir -p /tmp/btrfs 1>/dev/null
mount ${partition} /tmp/btrfs
mv /tmp/btrfs/WORKINGDIR/snapshots/backup /tmp/btrfs/backup
btrfs subvolume delete /tmp/btrfs/WORKINGDIR
mv /tmp/btrfs/backup /tmp/btrfs/WORKINGDIR
subVolID=$(btrfs subvolume show /tmp/btrfs/WORKINGDIR | grep "Subvolume ID:" | awk '$1=$1' | cut -d " " -f 3)
sed -i "/${subvolumeESC}/d" /etc/fstab
fstabAdd="UUID=${uuid} ${subvolume} btrfs noexec,defaults,subvolid=${subVolID} 0 2"
sudo sed "4 a ${fstabAdd}" -i /etc/fstab 1>/dev/null
sudo umount /tmp/btrfs
sudo mount -a
sed "4 a ${fstabAdd}" -i /etc/fstab 1>/dev/null
umount /tmp/btrfs
mount -a
sync
if [ $(df | grep -c "${subvolume}") -eq 0 ]; then
>&2 echo "# check drive setting ... rollback seemed to "
@ -1310,8 +1329,8 @@ if [ "$1" = "tempmount" ]; then
# do EXT4 temp mount
echo "# temp mount /dev/${hddDataPartitionExt4} --> /mnt/hdd"
sudo mkdir -p /mnt/hdd 1>/dev/null
sudo mount /dev/${hddDataPartitionExt4} /mnt/hdd
mkdir -p /mnt/hdd 1>/dev/null
mount /dev/${hddDataPartitionExt4} /mnt/hdd
# check result
isMounted=$(df | grep -c "/mnt/hdd")
@ -1330,12 +1349,12 @@ if [ "$1" = "tempmount" ]; then
bitcoinGID=$(id -g bitcoin)
# do BTRFS temp mount
sudo mkdir -p /mnt/hdd 1>/dev/null
sudo mkdir -p /mnt/storage 1>/dev/null
sudo mkdir -p /mnt/temp 1>/dev/null
sudo mount -t btrfs -o degraded -o subvol=WORKINGDIR /dev/${hddBTRFS}1 /mnt/hdd
sudo mount -t btrfs -o subvol=WORKINGDIR /dev/${hddBTRFS}2 /mnt/storage
sudo mount -o umask=0000,uid=${bitcoinUID},gid=${bitcoinGID} /dev/${hddBTRFS}3 /mnt/temp
mkdir -p /mnt/hdd 1>/dev/null
mkdir -p /mnt/storage 1>/dev/null
mkdir -p /mnt/temp 1>/dev/null
mount -t btrfs -o degraded -o subvol=WORKINGDIR /dev/${hddBTRFS}1 /mnt/hdd
mount -t btrfs -o subvol=WORKINGDIR /dev/${hddBTRFS}2 /mnt/storage
mount -o umask=0000,uid=${bitcoinUID},gid=${bitcoinGID} /dev/${hddBTRFS}3 /mnt/temp
# check result
isMountedA=$(df | grep -c "/mnt/hdd")
@ -1362,9 +1381,9 @@ if [ "$1" = "tempmount" ]; then
fi
if [ "$1" = "unmount" ]; then
sudo umount /mnt/hdd 2>/dev/null
sudo umount /mnt/storage 2>/dev/null
sudo umount /mnt/temp 2>/dev/null
umount /mnt/hdd 2>/dev/null
umount /mnt/storage 2>/dev/null
umount /mnt/temp 2>/dev/null
echo "# OK done unmount"
exit 1
fi
@ -1381,93 +1400,93 @@ if [ "$1" = "link" ]; then
fi
# cleanups
if [ $(sudo ls -la /home/bitcoin/ | grep -c "bitcoin ->") -eq 0 ]; then
if [ $(ls -la /home/bitcoin/ | grep -c "bitcoin ->") -eq 0 ]; then
>&2 echo "# - /home/bitcoin/.bitcoin -> is not a link, cleaning"
sudo rm -r /home/bitcoin/.bitcoin 2>/dev/null
rm -r /home/bitcoin/.bitcoin 2>/dev/null
else
sudo rm /home/bitcoin/.bitcoin 2>/dev/null
rm /home/bitcoin/.bitcoin 2>/dev/null
fi
# make sure common base directory exits
sudo mkdir -p /mnt/hdd/lnd
sudo mkdir -p /mnt/hdd/app-data
mkdir -p /mnt/hdd/lnd
mkdir -p /mnt/hdd/app-data
if [ ${isBTRFS} -eq 1 ]; then
>&2 echo "# Creating BTRFS setup links"
>&2 echo "# - linking blockchains into /mnt/hdd"
if [ $(ls -F /mnt/hdd/bitcoin | grep -c '/mnt/hdd/bitcoin@') -eq 0 ]; then
sudo mkdir -p /mnt/storage/bitcoin
sudo cp -R /mnt/hdd/bitcoin/* /mnt/storage/bitcoin 2>/dev/null
sudo chown -R bitcoin:bitcoin /mnt/storage/bitcoin
sudo rm -r /mnt/hdd/bitcoin
sudo ln -s /mnt/storage/bitcoin /mnt/hdd/bitcoin
sudo rm /mnt/storage/bitcoin/bitcoin 2>/dev/null
mkdir -p /mnt/storage/bitcoin
cp -R /mnt/hdd/bitcoin/* /mnt/storage/bitcoin 2>/dev/null
chown -R bitcoin:bitcoin /mnt/storage/bitcoin
rm -r /mnt/hdd/bitcoin
ln -s /mnt/storage/bitcoin /mnt/hdd/bitcoin
rm /mnt/storage/bitcoin/bitcoin 2>/dev/null
fi
>&2 echo "# linking lnd for user bitcoin"
sudo rm /home/bitcoin/.lnd 2>/dev/null
sudo ln -s /mnt/hdd/lnd /home/bitcoin/.lnd
rm /home/bitcoin/.lnd 2>/dev/null
ln -s /mnt/hdd/lnd /home/bitcoin/.lnd
>&2 echo "# - linking blockchain for user bitcoin"
sudo ln -s /mnt/storage/bitcoin /home/bitcoin/.bitcoin
ln -s /mnt/storage/bitcoin /home/bitcoin/.bitcoin
>&2 echo "# - linking storage into /mnt/hdd"
sudo mkdir -p /mnt/storage/app-storage
sudo chown -R bitcoin:bitcoin /mnt/storage/app-storage
sudo rm /mnt/hdd/app-storage 2>/dev/null
sudo ln -s /mnt/storage/app-storage /mnt/hdd/app-storage
mkdir -p /mnt/storage/app-storage
chown -R bitcoin:bitcoin /mnt/storage/app-storage
rm /mnt/hdd/app-storage 2>/dev/null
ln -s /mnt/storage/app-storage /mnt/hdd/app-storage
>&2 echo "# - linking temp into /mnt/hdd"
sudo rm /mnt/hdd/temp 2>/dev/null
sudo ln -s /mnt/temp /mnt/hdd/temp
sudo chown -R bitcoin:bitcoin /mnt/temp
rm /mnt/hdd/temp 2>/dev/null
ln -s /mnt/temp /mnt/hdd/temp
chown -R bitcoin:bitcoin /mnt/temp
>&2 echo "# - creating snapshots folder"
sudo mkdir -p /mnt/hdd/snapshots
sudo mkdir -p /mnt/storage/snapshots
mkdir -p /mnt/hdd/snapshots
mkdir -p /mnt/storage/snapshots
else
>&2 echo "# Creating EXT4 setup links"
>&2 echo "# opening blockchain into /mnt/hdd"
sudo mkdir -p /mnt/hdd/bitcoin
mkdir -p /mnt/hdd/bitcoin
>&2 echo "# linking blockchain for user bitcoin"
sudo rm /home/bitcoin/.bitcoin 2>/dev/null
sudo ln -s /mnt/hdd/bitcoin /home/bitcoin/.bitcoin
rm /home/bitcoin/.bitcoin 2>/dev/null
ln -s /mnt/hdd/bitcoin /home/bitcoin/.bitcoin
>&2 echo "# linking lnd for user bitcoin"
sudo rm /home/bitcoin/.lnd 2>/dev/null
sudo ln -s /mnt/hdd/lnd /home/bitcoin/.lnd
rm /home/bitcoin/.lnd 2>/dev/null
ln -s /mnt/hdd/lnd /home/bitcoin/.lnd
>&2 echo "# creating default storage & temp folders"
sudo mkdir -p /mnt/hdd/app-storage
sudo mkdir -p /mnt/hdd/temp
mkdir -p /mnt/hdd/app-storage
mkdir -p /mnt/hdd/temp
fi
# fix ownership of linked files
sudo chown -R bitcoin:bitcoin /mnt/hdd/bitcoin
sudo chown -R bitcoin:bitcoin /mnt/hdd/lnd
sudo chown -R bitcoin:bitcoin /home/bitcoin/.lnd
sudo chown -R bitcoin:bitcoin /home/bitcoin/.bitcoin
sudo chown -R bitcoin:bitcoin /mnt/hdd/app-storage
sudo chown -R bitcoin:bitcoin /mnt/hdd/app-data
sudo chown -R bitcoin:bitcoin /mnt/hdd/temp 2>/dev/null
sudo chmod -R 777 /mnt/temp 2>/dev/null
sudo chmod -R 777 /mnt/hdd/temp 2>/dev/null
chown -R bitcoin:bitcoin /mnt/hdd/bitcoin
chown -R bitcoin:bitcoin /mnt/hdd/lnd
chown -R bitcoin:bitcoin /home/bitcoin/.lnd
chown -R bitcoin:bitcoin /home/bitcoin/.bitcoin
chown bitcoin:bitcoin /mnt/hdd/app-storage
chown bitcoin:bitcoin /mnt/hdd/app-data
chown -R bitcoin:bitcoin /mnt/hdd/temp 2>/dev/null
chmod -R 777 /mnt/temp 2>/dev/null
chmod -R 777 /mnt/hdd/temp 2>/dev/null
# write info files about what directories are for
echo "The /mnt/hdd/temp directory is for short time data and will get cleaned up on very start. Dont work with data here thats bigger then 25GB - because on BTRFS hdd layout this is a own partition with limited space. Also on BTRFS hdd layout the temp partition is an FAT format - so it can be easily mounted on Windows and OSx laptops by just connecting it to such laptops. Use this for easy export data. To import data make sure to work with the data before bootstrap is deleting the directory on startup." > ./README.txt
sudo mv ./README.txt /mnt/hdd/temp/README.txt 2>/dev/null
mv ./README.txt /mnt/hdd/temp/README.txt 2>/dev/null
echo "The /mnt/hdd/app-data directory should be used by additional/optional apps and services installed to the RaspiBlitz for their data that should survive an import/export/backup. Data that can be reproduced (indexes, etc.) should be stored in app-storage." > ./README.txt
sudo mv ./README.txt /mnt/hdd/app-data/README.txt 2>/dev/null
mv ./README.txt /mnt/hdd/app-data/README.txt 2>/dev/null
echo "The /mnt/hdd/app-storage directory should be used by additional/optional apps and services installed to the RaspiBlitz for their non-critical and reproducible data (indexes, public blockchain, etc.) that does not need to survive an an import/export/backup. Data is critical should be in app-data." > ./README.txt
sudo mv ./README.txt /mnt/hdd/app-storage/README.txt 2>/dev/null
mv ./README.txt /mnt/hdd/app-storage/README.txt 2>/dev/null
>&2 echo "# OK - all symbolic links are built"
exit 0
@ -1495,33 +1514,33 @@ if [ "$1" = "swap" ]; then
fi
>&2 echo "# Switch off/uninstall old SWAP"
sudo dphys-swapfile swapoff 1>/dev/null
sudo dphys-swapfile uninstall 1>/dev/null
dphys-swapfile swapoff 1>/dev/null
dphys-swapfile uninstall 1>/dev/null
if [ ${isBTRFS} -eq 1 ]; then
>&2 echo "# Rewrite external SWAP config for BTRFS setup"
sudo sed -i "s/^#CONF_SWAPFILE=/CONF_SWAPFILE=/g" /etc/dphys-swapfile
sudo sed -i "s/^CONF_SWAPFILE=.*/CONF_SWAPFILE=\/mnt\/temp\/swapfile/g" /etc/dphys-swapfile
sed -i "s/^#CONF_SWAPFILE=/CONF_SWAPFILE=/g" /etc/dphys-swapfile
sed -i "s/^CONF_SWAPFILE=.*/CONF_SWAPFILE=\/mnt\/temp\/swapfile/g" /etc/dphys-swapfile
else
>&2 echo "# Rewrite external SWAP config for EXT4 setup"
sudo sed -i "s/^#CONF_SWAPFILE=/CONF_SWAPFILE=/g" /etc/dphys-swapfile
sudo sed -i "s/^CONF_SWAPFILE=.*/CONF_SWAPFILE=\/mnt\/hdd\/swapfile/g" /etc/dphys-swapfile
sed -i "s/^#CONF_SWAPFILE=/CONF_SWAPFILE=/g" /etc/dphys-swapfile
sed -i "s/^CONF_SWAPFILE=.*/CONF_SWAPFILE=\/mnt\/hdd\/swapfile/g" /etc/dphys-swapfile
fi
sudo sed -i "s/^CONF_SWAPSIZE=/#CONF_SWAPSIZE=/g" /etc/dphys-swapfile
sudo sed -i "s/^#CONF_MAXSWAP=.*/CONF_MAXSWAP=4096/g" /etc/dphys-swapfile
sed -i "s/^CONF_SWAPSIZE=/#CONF_SWAPSIZE=/g" /etc/dphys-swapfile
sed -i "s/^#CONF_MAXSWAP=.*/CONF_MAXSWAP=4096/g" /etc/dphys-swapfile
>&2 echo "# Creating SWAP file .."
sudo dd if=/dev/zero of=$externalSwapPath count=4096 bs=1MiB 1>/dev/null
sudo chmod 0600 $externalSwapPath 1>/dev/null
dd if=/dev/zero of=$externalSwapPath count=4096 bs=1MiB 1>/dev/null
chmod 0600 $externalSwapPath 1>/dev/null
>&2 echo "# Activating new SWAP"
sudo mkswap $externalSwapPath
sudo dphys-swapfile setup
sudo dphys-swapfile swapon
mkswap $externalSwapPath
dphys-swapfile setup
dphys-swapfile swapon
>&2 echo "# OK - Swap is now ON external"
exit 0
@ -1534,19 +1553,19 @@ if [ "$1" = "swap" ]; then
fi
>&2 echo "# Switch off/uninstall old SWAP"
sudo dphys-swapfile swapoff 1>/dev/null
sudo dphys-swapfile uninstall 1>/dev/null
dphys-swapfile swapoff 1>/dev/null
dphys-swapfile uninstall 1>/dev/null
>&2 echo "# Rewrite SWAP config"
sudo sed -i "12s/.*/CONF_SWAPFILE=\/var\/swap/" /etc/dphys-swapfile
sudo sed -i "16s/.*/#CONF_SWAPSIZE=/" /etc/dphys-swapfile
sudo dd if=/dev/zero of=/var/swap count=256 bs=1MiB 1>/dev/null
sudo chmod 0600 /var/swap
sed -i "12s/.*/CONF_SWAPFILE=\/var\/swap/" /etc/dphys-swapfile
sed -i "16s/.*/#CONF_SWAPSIZE=/" /etc/dphys-swapfile
dd if=/dev/zero of=/var/swap count=256 bs=1MiB 1>/dev/null
chmod 0600 /var/swap
>&2 echo "# Create and switch on new SWAP"
sudo mkswap /var/swap 1>/dev/null
sudo dphys-swapfile setup 1>/dev/null
sudo dphys-swapfile swapon 1>/dev/null
mkswap /var/swap 1>/dev/null
dphys-swapfile setup 1>/dev/null
dphys-swapfile swapon 1>/dev/null
>&2 echo "# OK - Swap is now OFF external"
exit 0
@ -1577,7 +1596,7 @@ if [ "$1" = "clean" ]; then
fi
>&2 echo "# Making sure 'secure-delete' is installed ..."
sudo apt-get install -y secure-delete 1>/dev/null
apt-get install -y secure-delete 1>/dev/null
>&2 echo
>&2 echo "# IMPORTANT: No 100% guarantee that sensitive data is completely deleted!"
@ -1594,8 +1613,8 @@ if [ "$1" = "clean" ]; then
>&2 echo "# Deleting personal Data .."
# make sure swap is off
sudo dphys-swapfile swapoff 1>/dev/null
sudo dphys-swapfile uninstall 1>/dev/null
dphys-swapfile swapoff 1>/dev/null
dphys-swapfile uninstall 1>/dev/null
sync
# for all other data shred files selectively
@ -1635,18 +1654,18 @@ if [ "$1" = "clean" ]; then
if [ -d "/mnt/hdd/$entry" ]; then
if [ ${whenDeleteSchredd} -eq 1 ]; then
>&2 echo "# shredding DIR : ${entry}"
sudo srm -lr /mnt/hdd/$entry
srm -lr /mnt/hdd/$entry
else
>&2 echo "# deleting DIR : ${entry}"
sudo rm -r /mnt/hdd/$entry
rm -r /mnt/hdd/$entry
fi
else
if [ ${whenDeleteSchredd} -eq 1 ]; then
>&2 echo "# shredding FILE : ${entry}"
sudo srm -l /mnt/hdd/$entry
srm -l /mnt/hdd/$entry
else
>&2 echo "# deleting FILE : ${entry}"
sudo rm /mnt/hdd/$entry
rm /mnt/hdd/$entry
fi
fi
@ -1664,7 +1683,7 @@ if [ "$1" = "clean" ]; then
echo "Cleaning Blockchain: ${chain}"
# take extra care if wallet.db exists
sudo srm -v /mnt/hdd/${chain}/wallet.db 2>/dev/null
srm -v /mnt/hdd/${chain}/wallet.db 2>/dev/null
# the rest just delete (keep blocks and chainstate and testnet3)
for entry in $(ls -A1 /mnt/hdd/${chain} 2>/dev/null)
@ -1679,10 +1698,10 @@ if [ "$1" = "clean" ]; then
if [ ${delete} -eq 1 ]; then
if [ -d "/mnt/hdd/${chain}/$entry" ]; then
>&2 echo "# Deleting DIR : /mnt/hdd/${chain}/${entry}"
sudo rm -r /mnt/hdd/${chain}/$entry
rm -r /mnt/hdd/${chain}/$entry
else
>&2 echo "# deleting FILE : /mnt/hdd/${chain}/${entry}"
sudo rm /mnt/hdd/${chain}/$entry
rm /mnt/hdd/${chain}/$entry
fi
else
>&2 echo "# keeping: ${entry}"
@ -1702,10 +1721,10 @@ if [ "$1" = "clean" ]; then
if [ ${delete} -eq 1 ]; then
if [ -d "/mnt/hdd/bitcoin/testnet3/$entry" ]; then
>&2 echo "# Deleting DIR : /mnt/hdd/bitcoin/testnet3/${entry}"
sudo rm -r /mnt/hdd/bitcoin/testnet3/$entry
rm -r /mnt/hdd/bitcoin/testnet3/$entry
else
>&2 echo "# deleting FILE : /mnt/hdd/bitcoin/testnet3/${entry}"
sudo rm /mnt/hdd/bitcoin/testnet3/$entry
rm /mnt/hdd/bitcoin/testnet3/$entry
fi
else
>&2 echo "# keeping: ${entry}"
@ -1737,8 +1756,8 @@ if [ "$1" = "clean" ]; then
fi
# deleting the blocks and chainstate
sudo rm -R ${basePath}/bitcoin/blocks 1>/dev/null 2>/dev/null
sudo rm -R ${basePath}/bitcoin/chainstate 1>/dev/null 2>/dev/null
rm -R ${basePath}/bitcoin/blocks 1>/dev/null 2>/dev/null
rm -R ${basePath}/bitcoin/chainstate 1>/dev/null 2>/dev/null
>&2 echo "# OK cleaning done."
exit 1
@ -1761,10 +1780,10 @@ if [ "$1" = "clean" ]; then
if [ -d "${tempPath}/$entry" ]; then
>&2 echo "# shredding DIR : ${entry}"
sudo rm -r ${tempPath}/$entry
rm -r ${tempPath}/$entry
else
>&2 echo "# shredding FILE : ${entry}"
sudo rm ${tempPath}/$entry
rm ${tempPath}/$entry
fi
else
@ -1794,18 +1813,18 @@ if [ "$1" = "uasp-fix" ]; then
# check if UASP is already deactivated (on RaspiOS)
# https://www.pragmaticlinux.com/2021/03/fix-for-getting-your-ssd-working-via-usb-3-on-your-raspberry-pi/
cmdlineExists=$(sudo ls /boot/cmdline.txt 2>/dev/null | grep -c "cmdline.txt")
cmdlineExists=$(ls /boot/cmdline.txt 2>/dev/null | grep -c "cmdline.txt")
if [ ${cmdlineExists} -eq 1 ] && [ ${#hddAdapterUSB} -gt 0 ] && [ ${hddAdapterUSAP} -eq 0 ]; then
echo "# Checking for UASP deactivation ..."
usbQuirkActive=$(sudo cat /boot/cmdline.txt | grep -c "usb-storage.quirks=")
usbQuirkDone=$(sudo cat /boot/cmdline.txt | grep -c "usb-storage.quirks=${hddAdapterUSB}:u")
usbQuirkActive=$(cat /boot/cmdline.txt | grep -c "usb-storage.quirks=")
usbQuirkDone=$(cat /boot/cmdline.txt | grep -c "usb-storage.quirks=${hddAdapterUSB}:u")
if [ ${usbQuirkActive} -gt 0 ] && [ ${usbQuirkDone} -eq 0 ]; then
# remove old usb-storage.quirks
sudo sed -i "s/usb-storage.quirks=[^ ]* //g" /boot/cmdline.txt
sed -i "s/usb-storage.quirks=[^ ]* //g" /boot/cmdline.txt
fi
if [ ${usbQuirkDone} -eq 0 ]; then
# add new usb-storage.quirks
sudo sed -i "s/^/usb-storage.quirks=${hddAdapterUSB}:u /" /boot/cmdline.txt
sed -i "s/^/usb-storage.quirks=${hddAdapterUSB}:u /" /boot/cmdline.txt
# go into reboot to activate new setting
echo "# DONE deactivating UASP for ${hddAdapterUSB} ... reboot needed"
echo "neededReboot=1"

View File

@ -14,8 +14,8 @@ fi
###################
# get required parameters
script=$2
shortcode=$3
script=$1
shortcode=$2
# check reqired parameters
if [ "${script}" == "" ]; then

View File

@ -462,7 +462,7 @@ if [ "$1" = "import" ]; then
# copy bitcoin data backups back to original places (if part of backup)
if [ -d "/mnt/hdd/backup_bitcoin" ]; then
echo "# Copying back bitcoin backup data .."
sudo mkdir /mnt/hdd/bitcoin
sudo mkdir /mnt/hdd/bitcoin 2>/dev/null
sudo cp /mnt/hdd/backup_bitcoin/bitcoin.conf /mnt/hdd/bitcoin/bitcoin.conf
sudo cp /mnt/hdd/backup_bitcoin/wallet.dat /mnt/hdd/bitcoin/wallet.dat 2>/dev/null
sudo chown bitcoin:bitcoin -R /mnt/hdd/bitcoin

View File

@ -76,13 +76,16 @@ if [ "${action}" == "check-upload" ]; then
if [ "${type}" == "scb" ]; then
# general filename check
typeCount=$(sudo ls ${defaultUploadPath}/*.backup 2>/dev/null | grep -c '.backup')
sudo mv ${defaultUploadPath}/channel-all.bak ${defaultUploadPath}/channel.backup 2>/dev/null
typeCount=$(sudo ls ${defaultUploadPath}/channel.backup 2>/dev/null | grep -c '.backup')
if [ "${typeCount}" != "1" ]; then
sudo rm ${defaultUploadPath}/* 2>/dev/null
echo "error='invalid'"
echo "errorDetail='not *.backup'"
exit 1
fi
filename="${defaultUploadPath}/channel.backup"
byteSize=$(ls -l ${filename} | awk '{print $5}')
fi
# LND-RESCUE check if file looks valid

View File

@ -13,12 +13,101 @@ if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "---------------------------------------------------"
echo "SEED WORDS"
echo "---------------------------------------------------"
echo "cl.backup.sh seed-export-gui [lndseeddata]"
echo "cl.backup.sh seed-export-gui [clseeddata]"
echo "cl.backup.sh seed-import-gui [resultfile]"
echo "---------------------------------------------------"
echo "RECOVERY"
echo "---------------------------------------------------"
echo "cl.backup.sh [mainnet|signet|testnet] recoverymode [on|off|status] <-rescanbockheight|rescandepth>"
echo
exit 1
fi
# 1st PARAMETER [mainnet|signet|testnet]
if [ "$1" == "mainnet" ] || [ "$1" == "testnet" ] || [ "$1" == "signet" ]; then
# prepare all chain dependent variables
source <(/home/admin/config.scripts/network.aliases.sh getvars cl $1)
mode="$2"
################################
# RECOVERY
################################
# c-lightning is considered in "recoverymode" when it is scanning the chain
# and getinfo -H shows: 'warning_lightningd_sync=Still loading latest blocks from bitcoind.'
# and 'blockheight=lower-than-in-bitcoind'
if [ ${mode} = "recoverymode" ]; then
# check if started with sudo
if [ "$EUID" -ne 0 ]; then
echo "error='run as root'"
exit 1
fi
# status
recoverymodeStatus=$(grep -c "^rescan=" < "${CLCONF}")
if [ "$3" == "status" ]; then
if [ ${recoverymodeStatus} -gt 0 ]; then
echo "recoverymode=1"
else
echo "recoverymode=0"
fi
exit 0
fi
# on
if [ "$3" == "on" ]; then
if [ ${recoverymodeStatus} -gt 0 ]; then
echo "# recoverymode already on"
exit 0
fi
# clean
sed -i 's/^rescan=.*//g' "${CLCONF}"
sed -i 's/^log-level=.*//g' "${CLCONF}"
# activate rescan in cl config
if [ $# -gt 3 ]; then
scanFrom="$4"
else
# scan from block 700000 by default
scanFrom="-700000"
fi
echo "# activating recovery mode ..."
echo "rescan=${scanFrom}" | tee -a "${CLCONF}"
echo "# setting log-level=debug ..."
echo "log-level=debug" | tee -a "${CLCONF}"
echo "# OK - restart/reboot needed for: ${netprefix}lightningd.service"
exit 0
fi
# off
if [ "$3" == "off" ]; then
if [ ${recoverymodeStatus} -eq 0 ]; then
echo "# recoverymode already off"
exit 0
fi
# remove --reset-wallet-transactions parameter in systemd service
echo "# deactivating recovery mode ..."
sed -i 's/^rescan=.*//g' "${CLCONF}"
sed -i 's/^log-level=.*//g' "${CLCONF}"
echo "# setting log-level=info (default) ..."
echo "log-level=info" | tee -a "${CLCONF}"
echo "# OK - restart/reboot needed for: ${netprefix}lightningd.service"
exit 0
fi
# parameter fallback
echo "error='unknown parameter'"
exit 1
fi
fi
# 1st PARAMETER action
mode="$1"
@ -261,9 +350,9 @@ if [ ${mode} = "cl-import-gui" ]; then
echo "Write the word 'override' and press ENTER to CONTINUE:"
read securityInput
if [ "${securityInput}" != "override" ] && [ "${securityInput}" != "'override'" ]; then
echo
echo "CANCELED import of uploaded rescue file"
exit 1
echo
echo "CANCELED import of uploaded rescue file"
exit 1
fi
echo
@ -328,7 +417,7 @@ if [ ${mode} = "seed-export-gui" ]; then
# use text snippet for testing:
#
# 2nd PARAMETER: lnd seed data
# 2nd PARAMETER: cl seed data
seedwords6x4=$2
if [ "${seedwords6x4}" == "" ]; then
echo "error='missing parameter'"
@ -344,7 +433,7 @@ if [ ${mode} = "seed-export-gui" ]; then
ack=1
fi
done
exit 0
fi
# Results will be stored on memory cache:

View File

@ -14,13 +14,13 @@ if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]||\
echo
echo "Usage:"
echo "Create new wallet:"
echo "cl.hsmtool.sh [new] [mainnet|testnet|signet] [?seedPassword]"
echo "cl.hsmtool.sh [new-force] [mainnet|testnet|signet] [?seedPassword]"
echo "There will be no seedPassword(passphrase) used by default"
echo "cl.hsmtool.sh [new] [mainnet|testnet|signet] [?seedpassword]"
echo "cl.hsmtool.sh [new-force] [mainnet|testnet|signet] [?seedpassword]"
echo "There will be no seedpassword(passphrase) used by default"
echo "new-force will backup the old wallet and will work without interaction"
echo
echo "cl.hsmtool.sh [seed] [mainnet|testnet|signet] [\"space-separated-seed-words\"] [?seedPassword]"
echo "cl.hsmtool.sh [seed-force] [mainnet|testnet|signet] [\"space-separated-seed-words\"] [?seedPassword]"
echo "cl.hsmtool.sh [seed] [mainnet|testnet|signet] [\"space-separated-seed-words\"] [?seedpassword]"
echo "cl.hsmtool.sh [seed-force] [mainnet|testnet|signet] [\"space-separated-seed-words\"] [?seedpassword]"
echo "The new hsm_secret will be not encrypted if no NewPassword is given"
echo "seed-force will delete any old wallet and will work without dialog"
echo
@ -38,7 +38,7 @@ source <(/home/admin/config.scripts/network.aliases.sh getvars cl $2)
hsmSecretPath="/home/bitcoin/.lightning/${CLNETWORK}/hsm_secret"
# password file is on the disk if encrypted and auto-unlock is enabled
passwordFile=/dev/shm/.${netprefix}cl.pw
passwordFile="/dev/shm/.${netprefix}cl.pw"
if grep -Eq "${netprefix}clEncryptedHSM=on" /mnt/hdd/raspiblitz.conf;then
if grep -Eq "${netprefix}clAutoUnlock=on" /mnt/hdd/raspiblitz.conf;then
passwordFile=/home/bitcoin/.${netprefix}cl.pw
@ -159,7 +159,8 @@ function decryptHSMsecret() {
if [ "$1" = "new" ] || [ "$1" = "new-force" ] || [ "$1" = "seed" ] || [ "$1" = "seed-force" ]; then
# make sure /home/bitcoin/.lightning/bitcoin exists (when lightningd was not run yet)
if ! sudo ls /home/bitcoin/.lightning/bitcoin; then
if ! sudo ls /home/bitcoin/.lightning/bitcoin 1>/dev/null; then
echo "# Create /home/bitcoin/.lightning/bitcoin/"
sudo -u bitcoin mkdir -p /home/bitcoin/.lightning/bitcoin/
fi
@ -205,7 +206,7 @@ if [ "$1" = "new" ] || [ "$1" = "new-force" ] || [ "$1" = "seed" ] || [ "$1" = "
fi
if [ "$1" = "new" ]; then
seedPassword="$3"
seedpassword="$3"
# get 24 words
source <(python /home/admin/config.scripts/blitz.mnemonic.py generate)
#TODO seedwords to cl.backup.sh seed-export-gui
@ -244,7 +245,7 @@ seedwords6x4='${seedwords6x4}'
(echo "0"; echo "${seedwords}"; echo) | sudo -u bitcoin lightning-hsmtool \
"generatehsm" $hsmSecretPath 1>&2
else
# pass to 'hsmtool generatehsm hsm_secret' - confirm seedPassword
# pass to 'hsmtool generatehsm hsm_secret' - confirm seedpassword
(echo "0"; echo "${seedwords}"; echo "$seedpassword"; echo "$seedpassword")\
| sudo -u bitcoin lightning-hsmtool "generatehsm" $hsmSecretPath 1>&2
fi

View File

@ -124,8 +124,10 @@ if [ "$2" = "info" ]; then
# sudo /usr/local/bin/lightning-cli --lightning-dir=/home/bitcoin/.lightning --conf=/home/bitcoin/.lightning/config getinfo
# get data
ln_getInfo=$($lightningcli_alias getinfo 2>/dev/null)
command="sudo -u bitcoin $lightningcli_alias getinfo"
ln_getInfo=$(${command} 2>/dev/null)
if [ "${ln_getInfo}" == "" ]; then
echo "command='${command}'"
echo "error='no data'"
exit 1
fi
@ -166,7 +168,18 @@ if [ "$2" = "info" ]; then
cl_sync_chain=1
fi
fi
# recovery info
source <(/home/admin/config.scripts/cl.backup.sh $1 recoverymode status)
cl_recovery_mode="${recoverymode}"
cl_recovery_done="0"
if [ "${cl_recovery_mode}" == "1" ]; then
scanning=$(echo "${ln_getInfo}" | grep "warning_lightningd_sync" | grep "Still loading latest blocks from bitcoind." -c)
if [ "${cl_recovery_mode}" == "1" ] && [ "${scanning}" == "0" ] && [ "${cl_sync_chain}" == "1" ]; then
cl_recovery_done="1"
fi
fi
# print data
echo "ln_cl_alias='${cl_alias}'"
echo "ln_cl_address='${cl_address}'"
@ -179,6 +192,8 @@ if [ "$2" = "info" ]; then
echo "ln_cl_channels_inactive='${cl_channels_inactive}'"
echo "ln_cl_channels_total='${cl_channels_total}'"
echo "ln_cl_fees_total='${cl_fees_collected_msat//[^0-9.]/}'"
echo "ln_cl_recovery_mode='${cl_recovery_mode}'"
echo "ln_cl_recovery_done='${cl_recovery_done}'"
exit 0
fi
@ -193,8 +208,11 @@ if [ "$2" = "wallet" ]; then
# /usr/local/bin/lightning-cli --lightning-dir=/home/bitcoin/.lightning --conf=/home/bitcoin/.lightning/config listfunds
# get data
cl_listfunds=$($lightningcli_alias listfunds 2>/dev/null)
sudo -u bitcoin
command="sudo -u bitcoin $lightningcli_alias listfunds"
cl_listfunds=$(${command} 2>/dev/null)
if [ "${cl_listfunds}" == "" ]; then
echo "command='${command}'"
echo "error='no data'"
exit 1
fi

View File

@ -21,10 +21,110 @@ if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# ---------------------------------------------------"
echo "# lnd.backup.sh seed-export-gui [lndseeddata]"
echo "# lnd.backup.sh seed-import-gui [resultfile]"
echo "# ---------------------------------------------------"
echo "# RECOVERY"
echo "# ---------------------------------------------------"
echo "# lnd.backup.sh [mainnet|signet|testnet] recoverymode [on|off|status]"
exit 1
fi
# 1st PRAMETER action
# 1st PARAMETER [mainnet|signet|testnet]
if [ "$1" == "mainnet" ] || [ "$1" == "testnet" ] || [ "$1" == "signet" ]; then
# prepare all chain dependent variables
lndChain="$1"
mode="$2"
netprefix=""
if [ "${lndChain}" == "testnet" ]; then
netprefix="t"
fi
if [ "${lndChain}" == "signet" ]; then
netprefix="s"
fi
################################
# RECOVERY
################################
# LND is considered in "recoverymode" when it gets started with --reset-wallet-transactions parameter
# so it will forgets all the old on-chain transactions. This will trigger wallet unlock with
# recovery window to rescan for transactions and background process will monitor when finished
if [ ${mode} = "recoverymode" ]; then
# check if started with sudo
if [ "$EUID" -ne 0 ]; then
echo "error='run as root'"
exit 1
fi
# status
recoverymodeStatus=$(cat /mnt/hdd/lnd/${netprefix}lnd.conf | grep -c "^reset-wallet-transactions=true")
if [ "$3" == "status" ]; then
if [ ${recoverymodeStatus} -gt 0 ]; then
echo "recoverymode=1"
else
echo "recoverymode=0"
fi
exit 0
fi
# on
if [ "$3" == "on" ]; then
if [ ${recoverymodeStatus} -gt 0 ]; then
echo "# recoverymode already on"
exit 0
fi
# make sure config entry exits
entryExists=$(cat /mnt/hdd/lnd/${netprefix}lnd.conf | grep -c "^reset-wallet-transactions=")
if [ $entryExists -eq 0 ]; then
# find section
sectionLine=$(cat /mnt/hdd/lnd/${netprefix}lnd.conf | grep -n "^\[Application Options\]" | cut -d ":" -f1)
insertLine=$(expr $sectionLine + 1)
sed -i "${insertLine}ireset-wallet-transactions=false" /mnt/hdd/lnd/${netprefix}lnd.conf
fi
# activate reset-wallet-transactions in lnd.conf
echo "# activating recovery mode ..."
sed -i 's/^reset-wallet-transactions=.*/reset-wallet-transactions=true/g' /mnt/hdd/lnd/${netprefix}lnd.conf
echo "# OK - restart/reboot needed for: ${netprefix}lnd.service"
# set system status
/home/admin/config.scripts/blitz.conf.sh set ln_lnd_${lndChain}_sync_initial_done 0 /home/admin/raspiblitz.info
source <(/home/admin/_cache.sh get chain lightning)
if [ "${lndChain}" == "${chain}net" ] && [ "${lightning}" == "lnd" ]; then
/home/admin/_cache.sh set ln_default_sync_initial_done 0
fi
exit 0
fi
# off
if [ "$3" == "off" ]; then
if [ ${recoverymodeStatus} -eq 0 ]; then
echo "# recoverymode already off"
exit 0
fi
# remove --reset-wallet-transactions parameter in systemd service
echo "# deactivating recovery mode ..."
sed -i 's/^reset-wallet-transactions=.*/reset-wallet-transactions=false/g' /mnt/hdd/lnd/${netprefix}lnd.conf
echo "# OK - restart/reboot needed for: ${netprefix}lnd.service"
exit 0
fi
# parameter fallback
echo "error='unknown parameter'"
exit 1
fi
fi
# 1st PARAMETER all other: action
mode="$1"
################################
@ -392,7 +492,7 @@ if [ ${mode} = "scb-import-gui" ]; then
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 ./*.backup ${defaultUploadUser}@${localip}:${defaultUploadPath}/"
echo "scp ./channel.backup ${defaultUploadUser}@${localip}:${defaultUploadPath}/"
echo ""
echo "Use ${passwordInfo} to authenticate file transfer."
echo "PRESS ENTER when upload is done."
@ -435,19 +535,13 @@ if [ ${mode} = "scb-import-gui" ]; then
# in setup scenario the final import is happening during provison
if [ "${scenario}" == "setup" ]; then
# just add staticchannelbackup filename to give file
echo "# result in: ${RESULTFILE} (remember to make clean delete once processed)"
echo "staticchannelbackup='${filename}'" >> $RESULTFILE
exit 0
fi
# run import process
echo "OK importing channel.backup file ..."
source <(sudo /home/admin/config.scripts/lnd.backup.sh scb-import "${filename}")
# give final info
echo "DONE - placed SCB file at /home/admin/channel.backup"
echo "Reboot and login to trigger import."
echo "# DONE - placed SCB file at /home/admin/channel.backup"
exit 0
fi

View File

@ -3,13 +3,18 @@
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "-help" ]; then
echo "# script to check LND states"
echo "# lnd.check.sh basic-setup"
echo "# lnd.check.sh basic-setup [mainnet|testnet|signet]"
echo "# lnd.check.sh prestart [mainnet|testnet|signet]"
exit 1
fi
# load raspiblitz conf
source /mnt/hdd/raspiblitz.conf
source <(/home/admin/config.scripts/network.aliases.sh getvars lnd $2)
# config file
echo "# checking lnd config for ${targetchain}"
echo "# lndConfFile(${lndConfFile})"
######################################################################
# PRESTART
@ -56,33 +61,6 @@ if [ "$1" == "prestart" ]; then
/home/admin/config.scripts/blitz.systemd.sh log lightning STARTED
fi
# prefixes for parallel services
if [ "${targetchain}" = "mainnet" ];then
netprefix=""
portprefix=""
rpcportmod=0
zmqprefix=28
elif [ "${targetchain}" = "testnet" ];then
netprefix="t"
portprefix=1
rpcportmod=1
zmqprefix=21
elif [ "${targetchain}" = "signet" ];then
netprefix="s"
portprefix=3
rpcportmod=3
zmqprefix=23
else
echo "err='unvalid chain parameter on lnd.check.sh'"
exit 1
fi
# config file
echo "# checking lnd config for ${targetchain}"
lndConfFile="/mnt/hdd/lnd/${netprefix}lnd.conf"
echo "# lndConfFile(${lndConfFile})"
##### BITCOIN OPTIONS SECTION #####
# [bitcoin]
@ -185,7 +163,7 @@ if [ "$1" == "prestart" ]; then
insertLine=$(expr $sectionLine + 1)
# make sure API ports are set to standard
setting ${lndConfFile} ${insertLine} "rpclisten" "0\.0\.0\.0\:1${rpcportmod}009"
setting ${lndConfFile} ${insertLine} "rpclisten" "0\.0\.0\.0\:1${L2rpcportmod}009"
setting ${lndConfFile} ${insertLine} "restlisten" "0\.0\.0\.0\:${portprefix}8080"
# enforce LND port is set correctly (if set in raspiblitz.conf)
@ -293,30 +271,30 @@ elif [ "$1" == "basic-setup" ]; then
fi
# check lnd.conf exists
lndConfExists=$(sudo ls /mnt/hdd/lnd/lnd.conf 2>/dev/null | grep -c 'lnd.conf')
lndConfExists=$(sudo ls ${lndConfFile} 2>/dev/null | grep -c "${netprefix}lnd.conf")
if [ ${lndConfExists} -gt 0 ]; then
echo "config=1"
else
echo "config=0"
echo "err='lnd.conf is missing in /mnt/hdd/lnd'"
echo "err='${netprefix}lnd.conf is missing in ${lndConfFile}'"
fi
# check lnd.conf exits (on SD card for admin)
lndConfExists=$(sudo ls /home/admin/.lnd/lnd.conf 2>/dev/null | grep -c 'lnd.conf')
lndConfExists=$(sudo ls /home/admin/.lnd/${netprefix}lnd.conf 2>/dev/null | grep -c 'lnd.conf')
if [ ${lndConfExists} -gt 0 ]; then
echo "configCopy=1"
# check if the same
orgChecksum=$(sudo shasum -a 256 /mnt/hdd/lnd/lnd.conf 2>/dev/null | cut -d " " -f1)
cpyChecksum=$(sudo shasum -a 256 /home/admin/.lnd/lnd.conf 2>/dev/null | cut -d " " -f1)
orgChecksum=$(sudo shasum -a 256 ${lndConfFile} 2>/dev/null | cut -d " " -f1)
cpyChecksum=$(sudo shasum -a 256 /home/admin/.lnd/${netprefix}lnd.conf 2>/dev/null | cut -d " " -f1)
if [ "${orgChecksum}" == "${cpyChecksum}" ]; then
echo "configMismatch=0"
else
echo "configMismatch=1"
echo "err='lnd.conf for user admin is old'"
echo "err='${netprefix}lnd.conf for user admin is old'"
fi
else
echo "configCopy=0"
echo "configMismatch=0"
echo "err='lnd.conf is missing for user admin'"
echo "err='$(netprefix)lnd.conf is missing for user admin'"
fi
# get network from config (BLOCKCHAIN)
@ -325,7 +303,7 @@ elif [ "$1" == "basic-setup" ]; then
# check if network is same the raspiblitz config
if [ "${network}" != "${lndNetwork}" ]; then
echo "err='lnd.conf: blockchain network in lnd.conf (${lndNetwork}) is different from raspiblitz.conf (${network})'"
echo "err='$(netprefix)lnd.conf: blockchain network in $(netprefix)lnd.conf (${lndNetwork}) is different from raspiblitz.conf (${network})'"
fi
# # get chain from config (TESTNET / MAINNET)

View File

@ -10,6 +10,10 @@ fi
echo "###########################################"
echo "# lnd.compact.sh"
if ! sudo ls /mnt/hdd/lnd/data/graph/mainnet/channel.db; then
echo "# /mnt/hdd/lnd/data/graph/mainnet/channel.db does not exist - exiting"
exit 1
fi
# check if HDD/SSD has enough space to run compaction (at least again the size as the channel.db at the moment)
channelDBsizeKB=$(sudo ls -l --block-size=K /mnt/hdd/lnd/data/graph/mainnet/channel.db | cut -d " " -f5 | tr -dc '0-9')
@ -45,6 +49,8 @@ echo
echo "# Stop LND"
sudo systemctl stop lnd
sudo touch /home/admin/lnd.db.bolt.auto-compact.log
sudo chmod 777 /home/admin/lnd.db.bolt.auto-compact.log
echo "# Run LND with --db.bolt.auto-compact"
sudo -u bitcoin /usr/local/bin/lnd --configfile=/home/bitcoin/.lnd/lnd.conf --db.bolt.auto-compact > /home/admin/lnd.db.bolt.auto-compact.log &

View File

@ -9,6 +9,8 @@ fi
# load data from config
source /mnt/hdd/raspiblitz.conf
# shellcheck disable=SC2154 # gets the ${chain} from the raspiblitz.conf
source <(/home/admin/config.scripts/network.aliases.sh getvars lnd "${chain}net")
###########################
# FUNCTIONS
@ -34,7 +36,7 @@ do
local n=${1:-bitcoin} # the network (e.g. bitcoin) defaults to bitcoin
local c=${2:-main} # the chain (e.g. main, test, sim, reg) defaults to main (for mainnet)
if [ ! -f /mnt/hdd/app-data/lnd/data/chain/"${n}"/"${c}"net/"${macaroon}" ]; then
missing=$(($missing + 1))
missing=$((missing + 1))
echo "# ${macaroon} is missing ($missing)"
else
echo "# ${macaroon} is present"
@ -77,6 +79,7 @@ if [ "$1" = "reset" ]; then
echo "## Resetting Macaroons"
echo "# all your macaroons get deleted and recreated"
cd || exit
# shellcheck disable=SC2154 # gets the ${network} from the raspiblitz.conf
sudo find /mnt/hdd/app-data/lnd/data/chain/"${network}"/"${chain}"net/ -iname '*.macaroon' -delete
sudo find /home/bitcoin/.lnd/data/chain/"${network}"/"${chain}"net/ -iname '*.macaroon' -delete
if [ "${keepOldMacaroons}" != "1" ]; then
@ -93,11 +96,12 @@ if [ "$1" = "reset" ]; then
# unlock wallet after restart
echo "# restarting LND ... wait 10 secs"
sudo systemctl start lnd
# shellcheck disable=SC2154
sudo systemctl start "${netprefix}lnd"
sleep 10
# unlock wallet after restart
sudo /home/admin/config.scripts/lnd.unlock.sh
sudo /home/admin/config.scripts/lnd.unlock.sh "${CHAIN}"
sleep 10
if [ ${resetMacaroons} -eq 1 ]; then
@ -147,11 +151,11 @@ elif [ "$1" = "sync" ]; then
fi
echo "# make sure LND conf is readable and symlinked"
sudo chmod 644 "/mnt/hdd/lnd/lnd.conf"
sudo chown bitcoin:bitcoin "/mnt/hdd/lnd/lnd.conf"
if ! [[ -L "/mnt/hdd/app-data/lnd/lnd.conf" ]]; then
sudo rm -rf "/mnt/hdd/app-data/lnd/lnd.conf" # not a symlink.. delete it silently
sudo ln -s "/mnt/hdd/lnd/lnd.conf" "/mnt/hdd/app-data/lnd/lnd.conf" # and create symlink
sudo chmod 644 "/mnt/hdd/lnd/${netprefix}lnd.conf"
sudo chown bitcoin:bitcoin "/mnt/hdd/lnd/${netprefix}lnd.conf"
if ! [[ -L "/mnt/hdd/app-data/lnd/${netprefix}lnd.conf" ]]; then
sudo rm -rf "/mnt/hdd/app-data/lnd/${netprefix}lnd.conf" # not a symlink.. delete it silently
sudo ln -s "/mnt/hdd/lnd/${netprefix}lnd.conf" "/mnt/hdd/app-data/lnd/${netprefix}lnd.conf" # and create symlink
fi
echo "# make sure TLS certificate is readable and symlinked"
@ -166,9 +170,9 @@ elif [ "$1" = "sync" ]; then
# Check Macaroons and fix missing
###########################
elif [ "$1" = "check" ]; then
check_macaroons ${network} ${chain}
check_macaroons "${network}" "${chain}"
if [ $missing -gt 0 ]; then
/home/admin/config.scrips/lnd.creds.sh reset keepold
/home/admin/config.scrips/lnd.credentials.sh reset keepold
fi
###########################

View File

@ -89,12 +89,14 @@ def new(stub, wallet_password="", seed_entropy=None):
print("err='InitWallet'")
sys.exit(1)
# init wallet with recovery_window=0 (to not trigger rescan)
# but make sure to put lnd into recovery mode with lnd.backup.sh
# script after that
def seed(stub, wallet_password="", seed_words="", seed_password=""):
request = lnrpc.InitWalletRequest(
wallet_password=wallet_password.encode(),
cipher_seed_mnemonic=[x.encode() for x in seed_words],
recovery_window=5000,
recovery_window=0,
aezeed_passphrase=seed_password.encode()
)

View File

@ -233,8 +233,8 @@ source /mnt/hdd/raspiblitz.conf
function removeParallelService() {
if [ -f "/etc/systemd/system/${netprefix}lnd.service" ];then
sudo -u bitcoin /usr/local/bin/lncli\
--rpcserver localhost:1${rpcportmod}009 stop
echo "# Stopping ${netprefix}lnd ..."
#sudo -u bitcoin /usr/local/bin/lncli --rpcserver localhost:1${rpcportmod}009 stop
sudo systemctl stop ${netprefix}lnd
sudo systemctl disable ${netprefix}lnd
sudo rm /etc/systemd/system/${netprefix}lnd.service 2>/dev/null
@ -446,9 +446,11 @@ alias ${netprefix}lndconf=\"sudo nano /home/bitcoin/.lnd/${netprefix}lnd.conf\"\
/home/admin/config.scripts/blitz.conf.sh set ${netprefix}lnd "on"
# if this is the first lightning mainnet turned on - make default
if [ "${CHAIN}" == "mainnet" ] && [ "${lightning}" == "" ]; then
echo "# LND is now default lighthning implementation"
/home/admin/config.scripts/blitz.conf.sh set lightning "lnd"
if [ "${CHAIN}" == "mainnet" ]; then
if [ "${lightning}" == "" ] || [ "${lightning}" == "none" ]; then
echo "# LND is now default lighthning implementation"
/home/admin/config.scripts/blitz.conf.sh set lightning "lnd"
fi
fi
exit 0

View File

@ -26,10 +26,10 @@ if [ "$1" == "mainnet" ]; then
lndcli_alias="/usr/local/bin/lncli -n=mainnet --rpcserver=localhost:10009 --macaroonpath=${lndHomeDir}/data/chain/bitcoin/mainnet/readonly.macaroon --tlscertpath=${lndHomeDir}/tls.cert"
netprefix=""
elif [ "$1" == "testnet" ]; then
lndcli_alias="/usr/local/bin/lncli -n=mainnet --rpcserver=localhost:11009 --macaroonpath=${lndHomeDir}/data/chain/bitcoin/testnet/readonly.macaroon --tlscertpath=${lndHomeDir}/tls.cert"
lndcli_alias="/usr/local/bin/lncli -n=testnet --rpcserver=localhost:11009 --macaroonpath=${lndHomeDir}/data/chain/bitcoin/testnet/readonly.macaroon --tlscertpath=${lndHomeDir}/tls.cert"
netprefix="t"
elif [ "$1" == "signet" ]; then
lndcli_alias="/usr/local/bin/lncli -n=mainnet --rpcserver=localhost:13009 --macaroonpath=${lndHomeDir}/data/chain/bitcoin/signet/readonly.macaroon --tlscertpath=${lndHomeDir}/tls.cert"
lndcli_alias="/usr/local/bin/lncli -n=signet --rpcserver=localhost:13009 --macaroonpath=${lndHomeDir}/data/chain/bitcoin/signet/readonly.macaroon --tlscertpath=${lndHomeDir}/tls.cert"
netprefix="s"
else
echo "error='not supported net'"
@ -141,6 +141,7 @@ if [ "$2" = "info" ]; then
# get data
ln_getInfo=$($lndcli_alias getinfo 2>/dev/null)
if [ "${ln_getInfo}" == "" ]; then
echo "command='$lndcli_alias getinfo'"
echo "error='no data'"
exit 1
fi
@ -156,7 +157,7 @@ if [ "$2" = "info" ]; then
lnd_channels_total=$(( lnd_channels_pending + lnd_channels_active + lnd_channels_inactive ))
lnd_peers=$(echo "${ln_getInfo}" | jq -r '.num_peers')
# calaculate the sync/scan progress
# calculate the sync/scan progress
lnd_sync_progress=""
scanTimestamp=$(echo "${ln_getInfo}" | jq -r '.best_header_timestamp')
nowTimestamp=$(date +%s)
@ -175,6 +176,19 @@ if [ "$2" = "info" ]; then
fi
fi
# recovery info
source <(/home/admin/config.scripts/lnd.backup.sh $1 recoverymode status)
lnd_recovery_mode="${recoverymode}"
lnd_recovery_done="0"
if [ "${lnd_recovery_mode}" == "1" ]; then
ln_getrecoveryinfo=$($lndcli_alias getrecoveryinfo 2>/dev/null)
activated=$(echo "${ln_getrecoveryinfo}" | grep "recovery_mode" | grep "true" -c)
finished=$(echo "${ln_getrecoveryinfo}" | grep "recovery_finished" | grep "true" -c)
if [ "${activated}" == "1" ] && [ "${finished}" == "1" ]; then
lnd_recovery_done="1"
fi
fi
# print data
echo "ln_lnd_address='${lnd_address}'"
echo "ln_lnd_tor='${lnd_tor}'"
@ -186,6 +200,8 @@ if [ "$2" = "info" ]; then
echo "ln_lnd_channels_inactive='${lnd_channels_inactive}'"
echo "ln_lnd_channels_total='${lnd_channels_total}'"
echo "ln_lnd_peers='${lnd_peers}'"
echo "ln_lnd_recovery_mode='${lnd_recovery_mode}'"
echo "ln_lnd_recovery_done='${lnd_recovery_done}'"
exit 0
fi

View File

@ -43,9 +43,6 @@ if [ ${#newName} -eq 0 ]; then
fi
fi
# lnd conf file
lndConfFile="/mnt/hdd/lnd/${netprefix}lnd.conf"
# check if lnd config file exists
configExists=$(ls ${lndConfFile} | grep -c '.conf')
if [ ${configExists} -eq 0 ]; then

View File

@ -21,9 +21,20 @@ passwordC="$2"
# chain-unlock --> unlock with re-arranged parameters
CHAIN="${chain}net"
if [ "${action}" == "chain-unlock" ]; then
action="unlock"
passwordC=""
CHAIN=$2
if [ "${CHAIN}" == "mainnet" ]; then
chain="main"
elif [ "${CHAIN}" == "testnet" ]; then
chain="test"
passwordC=""
elif [ "${CHAIN}" == "signet" ]; then
chain="sig"
passwordC=""
else
echo "# unkown chain parameter: ${CHAIN}"
sleep 1
exit 1
fi
fi
# dont if state is on reboot or shutdown
@ -38,7 +49,7 @@ source <(/home/admin/config.scripts/network.aliases.sh getvars lnd ${chain}net)
# check if wallet is already unlocked
# echo "# checking LND wallet ... (can take some time)"
lndError=$(sudo -u bitcoin lncli --chain=${network} --network=${chain}net getinfo 2>&1)
lndError=$(${lncli_alias} getinfo 2>&1)
walletLocked=$(echo "${lndError}" | grep -c "Wallet is encrypted")
if [ "${walletLocked}" == "0" ]; then
# test for new error message
@ -55,22 +66,10 @@ fi
# if already unlocked all is done
if [ ${walletLocked} -eq 0 ] && [ ${macaroonsMissing} -eq 0 ]; then
# echo "# OK LND wallet was already unlocked"
echo "# OK LND wallet was already unlocked"
exit 0
fi
# check if LND is below 0.10 (has no STDIN password option)
fallback=0
source <(/home/admin/config.scripts/lnd.update.sh info)
if [ ${lndInstalledVersionMajor} -eq 0 ] && [ ${lndInstalledVersionMain} -lt 10 ]; then
if [ ${#passwordC} -gt 0 ]; then
echo "error='lnd version too old'"
exit 1
else
fallback=1
fi
fi
# if no password check if stored for auto-unlock
if [ ${#passwordC} -eq 0 ]; then
autoUnlockExists=$(sudo ls /root/lnd.autounlock.pwd 2>/dev/null | grep -c "lnd.autounlock.pwd")
@ -82,13 +81,14 @@ fi
# if still no password get from user
manualEntry=0
if [ ${#passwordC} -eq 0 ] && [ ${fallback} -eq 0 ]; then
if [ ${#passwordC} -eq 0 ]; then
echo "# manual input"
manualEntry=1
passwordC=$(whiptail --passwordbox "\nEnter Password C to unlock wallet:\n" 9 52 "" --title " LND Wallet " --backtitle "RaspiBlitz" 3>&1 1>&2 2>&3)
fi
loopCount=0
fallback=0
while [ ${fallback} -eq 0 ]
do
@ -96,7 +96,16 @@ while [ ${fallback} -eq 0 ]
loopCount=$(($loopCount +1))
echo "# calling: lncli unlock"
result=$(echo "$passwordC" | $lncli_alias unlock --recovery_window=1000 --stdin 2>&1)
# check if lnd is in recovery mode
source <(sudo /home/admin/config.scripts/lnd.backup.sh mainnet recoverymode status)
recoveryOption=""
if [ "${recoverymode}" == "1" ]; then
recoveryOption="--recovery_window=5000 "
echo "# running unlock with ${recoveryOption}"
fi
result=$(echo "$passwordC" | $lncli_alias unlock ${recoveryOption}--stdin 2>&1)
wasUnlocked=$(echo "${result}" | grep -c 'successfully unlocked')
wrongPassword=$(echo "${result}" | grep -c 'invalid passphrase')
if [ ${wasUnlocked} -gt 0 ]; then
@ -162,7 +171,7 @@ do
echo "############################"
echo "Calling: ${netprefix}lncli unlock"
echo "Please re-enter Password C:"
$lncli_alias unlock --recovery_window=1000
$lncli_alias unlock --recovery_window=5000
# test unlock
walletLocked=$($lncli_alias getinfo 2>&1 | grep -c unlock)

View File

@ -40,7 +40,7 @@ if [ "$1" = getvars ];then
chain=main
fi
# CHAIN is: signet | testnet | mainnet
if [ $# -gt 2 ]&&[ "$3" != net ];then
if [ $# -gt 2 ]&&[ "$3" != net ]&&[ "$3" != "" ];then
CHAIN=$3
chain=${CHAIN::-3}
else
@ -49,29 +49,34 @@ if [ "$1" = getvars ];then
echo "CHAIN=${chain}net"
echo "chain=${chain}"
# netprefix is: "" | t | s
# portprefix is: "" | 1 | 3
# L2rpcportmod is: 0 | 1 | 3
# netprefix is: "" | t | s
# portprefix is: "" | 1 | 3
# L2rpcportmod is: 0 | 1 | 3
# zmqprefix is: 28 | 21 | 23
if [ "${chain}" == "main" ];then
netprefix=""
L1rpcportmod=""
L2rpcportmod=0
portprefix=""
zmqprefix=28
elif [ "${chain}" == "test" ];then
netprefix="t"
L1rpcportmod=1
L2rpcportmod=1
portprefix=1
zmqprefix=21
elif [ "${chain}" == "sig" ];then
netprefix="s"
L1rpcportmod=3
L2rpcportmod=3
portprefix=3
zmqprefix=23
fi
echo "netprefix=${netprefix}"
echo "portprefix=${portprefix}"
echo "L2rpcportmod=${L2rpcportmod}"
echo "zmqprefix=${zmqprefix}"
if [ "${LNTYPE}" == "cl" ];then
# CLNETWORK is: bitcoin / signet / testnet
if [ "${chain}" == "main" ];then
@ -96,8 +101,10 @@ if [ "$1" = getvars ];then
# typeprefix is: "" | c
if [ "${LNTYPE}" == "lnd" ];then
typeprefix=''
lndConfFile="/mnt/hdd/lnd/${netprefix}lnd.conf"
fi
echo "typeprefix=${typeprefix}"
echo "lndConfFile=${lndConfFile}"
# instead of all
# sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net

View File

@ -35,10 +35,7 @@ fi
# BLOCKCHAIN INFO & OPTIONS
# get fresh data
source <(/home/admin/_cache.sh get \n
btc_default_sync_percentage \n
network \n
)
source <(/home/admin/_cache.sh get btc_default_sync_percentage network)
syncProgressFull=$(echo "${btc_default_sync_percentage}" | cut -d "." -f1)
if [ "${syncProgressFull}" != "" ] && [ "${network}" == "bitcoin" ] && [ ${syncProgressFull} -lt 75 ]; then
@ -54,54 +51,6 @@ if [ "${syncProgressFull}" != "" ] && [ "${network}" == "bitcoin" ] && [ ${syncP
fi
############# SCB activation
# check if there is a channel.backup to activate
gotSCB=$(ls /home/admin/channel.backup 2>/dev/null | grep -c 'channel.backup')
if [ "${gotSCB}" == "1" ]; then
echo "*** channel.backup Recovery ***"
lncli --chain=${network} 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
# output error message
echo ""
echo "!!! FAIL !!! SOMETHING WENT WRONG:"
echo "${error}"
# check if its possible to give background info on the error
notMachtingSeed=$(echo $error | grep -c 'unable to unpack chan backup')
if [ ${notMachtingSeed} -gt 0 ]; then
echo "# FAIL Static-Channel-Backup: seed not machting file" >> /home/admin/raspiblitz.log
echo "--> ERROR BACKGROUND:"
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."
echo
fi
# basic info on error
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo
echo "You can try after full setup to restore channel.backup file again with:"
echo "lncli --chain=${network} restorechanbackup --multi_file=/home/admin/channel.backup"
echo
echo "Press ENTER to continue for now ..."
read key
else
mv /home/admin/channel.backup /home/admin/channel.backup.done
dialog --title " OK channel.backup IMPORT " --msgbox "
LND accepted the channel.backup file you uploaded.
It will now take around a hour until you can see,
if LND was able to recover funds from your channels.
" 9 56
fi
fi
############################################
# SETUP DONE CONFIRMATION (Konfetti Moment)

View File

@ -167,7 +167,8 @@ if [ ${uploadSCB} -eq 1 ]; then
/home/admin/config.scripts/lnd.backup.sh scb-import-gui setup $_temp
source $_temp 2>/dev/null
sudo rm $_temp 2>/dev/null
sleep 2
x
# if user canceled the upload
if [ "${staticchannelbackup}" == "" ]; then
# signal cancel to the calling script by exit code (5 = exit on scb)

View File

@ -46,6 +46,7 @@ source <(/home/admin/_cache.sh get \
lightning \
ln_default_ready \
ln_default_sync_progress \
ln_default_recovery_mode \
system_count_start_lightning \
)
@ -61,6 +62,8 @@ if [ "${lightning}" != "" ] && [ "${ln_default_sync_progress}" == "" ]; then
else
scanProgress="waiting"
fi
elif [ "${ln_default_sync_progress}" == "100.00" ] && [ "${ln_default_recovery_mode}" == "1" ]; then
scanProgress="recoverscan"
elif [ ${#ln_default_sync_progress} -lt 6 ]; then
scanProgress=" ${ln_default_sync_progress} %"
else