From 8bc31b6698a4b4a2d11988e4a13bded24298b485 Mon Sep 17 00:00:00 2001 From: openoms Date: Wed, 23 Jun 2021 08:30:52 +0100 Subject: [PATCH] apply bitcoin and lncli aliases in all scripts --- home.admin/00settingsMenuBasics.sh | 7 +++++-- home.admin/10setupBlitz.sh | 11 ++++++++--- home.admin/70initLND.sh | 8 ++++---- home.admin/99lndMenu.sh | 4 +++- home.admin/AAunlockLND.sh | 5 ++++- home.admin/BBconnectPeer.sh | 2 +- home.admin/_background.sh | 6 ++++-- home.admin/config.scripts/network.aliases.sh | 3 +-- 8 files changed, 30 insertions(+), 16 deletions(-) diff --git a/home.admin/00settingsMenuBasics.sh b/home.admin/00settingsMenuBasics.sh index 03e38bfca..b5699d4c5 100755 --- a/home.admin/00settingsMenuBasics.sh +++ b/home.admin/00settingsMenuBasics.sh @@ -158,8 +158,11 @@ if [ "${chain}" != "${choice}" ]; then echo "B) Answer 'n' because you don't have a 'cipher seed mnemonic' (24 words) yet" echo "C) For 'passphrase' to encrypt your 'cipher seed' use PASSWORD D (optional)" echo "****************************************************************************" - sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net create 2>error.out - error=`sudo cat error.out` + source <(/home/admin/config.scripts/network.aliases.sh getvars lnd ${choice}net) + shopt -s expand_aliases + alias lncli_alias="$lncli_alias" + lncli_alias create 2>error.out + error=$(sudo cat error.out) if [ ${#error} -eq 0 ]; then sleep 2 # WIN diff --git a/home.admin/10setupBlitz.sh b/home.admin/10setupBlitz.sh index d6da8ef87..bd41b9f7f 100755 --- a/home.admin/10setupBlitz.sh +++ b/home.admin/10setupBlitz.sh @@ -50,6 +50,11 @@ fi lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running) if [ ${lndRunning} -eq 1 ]; then + source <(/home/admin/config.scripts/network.aliases.sh getvars lnd) + shopt -s expand_aliases + alias bitcoincli_alias="$bitcoincli_alias" + alias lncli_alias="$lncli_alias" + echo "LND is running ..." sleep 1 @@ -60,7 +65,7 @@ if [ ${lndRunning} -eq 1 ]; then if [ ${walletExists} -eq 1 ];then echo "lnd wallet exists ... checking if locked" sleep 2 - walletLocked=$(sudo -u bitcoin /usr/local/bin/lncli getinfo 2>&1 | grep -c unlock) + walletLocked=$($lncli_alias getinfo 2>&1 | grep -c unlock) fi if [ ${walletLocked} -gt 0 ]; then # LND wallet is locked @@ -70,7 +75,7 @@ if [ ${lndRunning} -eq 1 ]; then fi # check if blockchain still syncing (during sync sometimes CLI returns with error at this point) - chainInfo=$(sudo -u bitcoin ${network}-cli getblockchaininfo 2>/dev/null | grep 'initialblockdownload') + chainInfo=$($bitcoincli_alias getblockchaininfo 2>/dev/null | grep 'initialblockdownload') chainSyncing=1 if [ ${#chainInfo} -gt 0 ];then echo "check chaininfo" @@ -86,7 +91,7 @@ if [ ${lndRunning} -eq 1 ]; then fi # check if lnd is scanning blockchain - lndInfo=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} getinfo 2>/dev/null | grep "synced_to_chain") + lndInfo=$($lncli_alias --chain=${network} getinfo 2>/dev/null | grep "synced_to_chain") lndSyncing=1 if [ ${#lndInfo} -gt 0 ];then lndSyncing=$(echo "${chainInfo}" | grep "false" -c) diff --git a/home.admin/70initLND.sh b/home.admin/70initLND.sh index a43247440..305efd36e 100755 --- a/home.admin/70initLND.sh +++ b/home.admin/70initLND.sh @@ -22,11 +22,11 @@ if [ ${#chain} -eq 0 ]; then fi # CHECK ######### - +source <(/home/admin/config.scripts/network.aliases.sh getvars) echo "*** Check ${network} Running ***" -bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running) +bitcoinRunning=$(systemctl status ${netprefix}${network}d.service 2>/dev/null | grep -c running) if [ ${bitcoinRunning} -eq 0 ]; then - bitcoinRunning=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo | grep -c verificationprogress) + bitcoinRunning=$($bitcoincli_alias getblockchaininfo | grep -c verificationprogress) fi if [ ${bitcoinRunning} -eq 0 ]; then whiptail --title "70initLND - WARNING" --yes-button "Retry" --no-button "EXIT+Logs" --yesno "Service ${network}d is not running." 8 50 @@ -46,7 +46,7 @@ loopCount=0 while [ ${chainIsReady} -eq 0 ] do loopCount=$(($loopCount +1)) - result=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>error.out) + result=$($bitcoincli_alias getblockchaininfo 2>error.out) error=$(cat error.out) rm error.out if [ ${#error} -gt 0 ]; then diff --git a/home.admin/99lndMenu.sh b/home.admin/99lndMenu.sh index c8acf4c44..7a3a76519 100644 --- a/home.admin/99lndMenu.sh +++ b/home.admin/99lndMenu.sh @@ -8,6 +8,8 @@ source /mnt/hdd/raspiblitz.conf # get the local network IP to be displayed on the LCD source <(/home/admin/config.scripts/internet.sh status local) +source <(/home/admin/config.scripts/network.aliases.sh getvars lnd $1) + # BASIC MENU INFO HEIGHT=13 WIDTH=64 @@ -33,7 +35,7 @@ fi OPTIONS+=(NAME "Change Name/Alias of Node") -openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net listchannels 2>/dev/null | jq '.[] | length') +openChannels=$($lncli_alias listchannels 2>/dev/null | jq '.[] | length') if [ ${#openChannels} -gt 0 ] && [ ${openChannels} -gt 0 ]; then OPTIONS+=(CLOSEALL "Close all open Channels") HEIGHT=$((HEIGHT+1)) diff --git a/home.admin/AAunlockLND.sh b/home.admin/AAunlockLND.sh index 86c63616f..c9c166ae7 100755 --- a/home.admin/AAunlockLND.sh +++ b/home.admin/AAunlockLND.sh @@ -18,9 +18,12 @@ echo "************************************************************************** echo "HELP: Enter your PASSWORD C" echo "You may wait some seconds until you get asked for password." echo "****************************************************************************" +source <(/home/admin/config.scripts/network.aliases.sh getvars lnd) +shopt -s expand_aliases +alias lncli_alias="$lncli_alias" while : do - sudo -u bitcoin /usr/local/bin/lncli --chain=${network} unlock + lncli_alias --chain=${network} unlock sleep 4 locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock) if [ ${locked} -eq 0 ]; then diff --git a/home.admin/BBconnectPeer.sh b/home.admin/BBconnectPeer.sh index 5a3530dcf..43450078f 100755 --- a/home.admin/BBconnectPeer.sh +++ b/home.admin/BBconnectPeer.sh @@ -53,7 +53,7 @@ fi # info output clear echo "******************************" -echo "Connect to A Lightning Node" +echo "Connect to a Lightning Node" echo "******************************" echo echo "COMMAND LINE: " diff --git a/home.admin/_background.sh b/home.admin/_background.sh index 6fcfaed6d..a2d39859a 100755 --- a/home.admin/_background.sh +++ b/home.admin/_background.sh @@ -400,7 +400,8 @@ do if [ "${autoUnlock}" = "on" ]; then # check if lnd is locked - locked=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock) + source <(/home/admin/config.scripts/network.aliases.sh getvars lnd) + locked=$($lncli_alias getinfo 2>&1 | grep -c unlock) if [ ${locked} -gt 0 ]; then echo "STARTING AUTO-UNLOCK ..." @@ -441,7 +442,8 @@ do # 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 - finishedIBD=$(sudo -u bitcoin ${network}-cli getblockchaininfo | grep "initialblockdownload" | grep -c "false") + 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, check TOR and restart ${network}d" diff --git a/home.admin/config.scripts/network.aliases.sh b/home.admin/config.scripts/network.aliases.sh index a855805ce..400c121fc 100644 --- a/home.admin/config.scripts/network.aliases.sh +++ b/home.admin/config.scripts/network.aliases.sh @@ -1,7 +1,7 @@ #!/bin/bash # Usage: -# source <(/home/admin/config.scripts/network.aliases.sh +# source <(/home/admin/config.scripts/network.aliases.sh getvars ) # shopt -s expand_aliases # alias bitcoincli_alias="$bitcoincli_alias" # alias lncli_alias="$lncli_alias" @@ -55,7 +55,6 @@ if [ $1 = getvars ];then echo "portprefix=''" fi - #TODO ALL # instead of all # sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net echo "lncli_alias=\"sudo -u bitcoin /usr/local/bin/lncli -n=${chain}net --rpcserver localhost:1${L2rpcportmod}009\""