use lncli_alias and bitcoincli_alias everywhere

This commit is contained in:
openoms
2021-05-23 19:00:52 +01:00
parent 5c5cccefc8
commit 4044295ace
11 changed files with 88 additions and 70 deletions

View File

@@ -18,19 +18,9 @@ if [ $# -gt 0 ];then
CHAIN=$1 CHAIN=$1
chain=${CHAIN::-3} chain=${CHAIN::-3}
fi fi
if [ ${chain} = test ];then source /home/admin/config.scripts/_functions.lightning.sh
L1rpcportmod=1 getLNvars lnd ${chain}net
L2rpcportmod=1 getLNaliases
elif [ ${chain} = sig ];then
L1rpcportmod=3
L2rpcportmod=3
elif [ ${chain} = main ];then
L1rpcportmod=""
L2rpcportmod=0
fi
shopt -s expand_aliases
alias lncli_alias="sudo -u bitcoin /usr/local/bin/lncli -n=${chain}net --rpcserver localhost:1${L2rpcportmod}009"
alias bitcoincli_alias="/usr/local/bin/${network}-cli -rpcport=${L1rpcportmod}8332"
## get HDD/SSD info ## get HDD/SSD info
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
@@ -80,7 +70,6 @@ if [ ${#chain} -eq 0 ]; then
fi fi
# set datadir # set datadir
bitcoin_dir="/home/bitcoin/.${network}"
lnd_dir="/home/bitcoin/.lnd" lnd_dir="/home/bitcoin/.lnd"
lnd_macaroon_dir="/home/bitcoin/.lnd/data/chain/${network}/${chain}net" lnd_macaroon_dir="/home/bitcoin/.lnd/data/chain/${network}/${chain}net"
@@ -110,12 +99,12 @@ btc_path=$(command -v bitcoin-cli)
blockInfo="-" blockInfo="-"
if [ -n "${btc_path}" ]; then if [ -n "${btc_path}" ]; then
btc_title=$network btc_title=$network
blockchaininfo="$(bitcoincli_alias -datadir=${bitcoin_dir} getblockchaininfo 2>/dev/null)" blockchaininfo="$($bitcoincli_alias getblockchaininfo 2>/dev/null)"
if [ ${#blockchaininfo} -gt 0 ]; then if [ ${#blockchaininfo} -gt 0 ]; then
btc_title="${btc_title} (${chain}net)" btc_title="${btc_title} (${chain}net)"
# get sync status # get sync status
block_chain="$(bitcoincli_alias -datadir=${bitcoin_dir} getblockcount 2>/dev/null)" block_chain="$($bitcoincli_alias getblockcount 2>/dev/null)"
block_verified="$(echo "${blockchaininfo}" | jq -r '.blocks')" block_verified="$(echo "${blockchaininfo}" | jq -r '.blocks')"
block_diff=$(expr ${block_chain} - ${block_verified}) block_diff=$(expr ${block_chain} - ${block_verified})
blockInfo="${block_verified}/${block_chain}" blockInfo="${block_verified}/${block_chain}"
@@ -142,13 +131,13 @@ if [ -n "${btc_path}" ]; then
fi fi
# get last known block # get last known block
last_block="$(bitcoincli_alias -datadir=${bitcoin_dir} getblockcount 2>/dev/null)" last_block="$($bitcoincli_alias getblockcount 2>/dev/null)"
if [ ! -z "${last_block}" ]; then if [ ! -z "${last_block}" ]; then
btc_line2="${btc_line2} ${color_gray}(block ${last_block})" btc_line2="${btc_line2} ${color_gray}(block ${last_block})"
fi fi
# get mem pool transactions # get mem pool transactions
mempool="$(bitcoincli_alias -datadir=${bitcoin_dir} getmempoolinfo 2>/dev/null | jq -r '.size')" mempool="$($bitcoincli_alias getmempoolinfo 2>/dev/null | jq -r '.size')"
else else
btc_line2="${color_red}NOT RUNNING\t\t" btc_line2="${color_red}NOT RUNNING\t\t"
@@ -156,7 +145,7 @@ if [ -n "${btc_path}" ]; then
fi fi
# get IP address & port # get IP address & port
networkInfo=$(bitcoincli_alias -datadir=${bitcoin_dir} getnetworkinfo 2>/dev/null) networkInfo=$($bitcoincli_alias getnetworkinfo 2>/dev/null)
local_ip="${localip}" # from internet.sh local_ip="${localip}" # from internet.sh
public_ip="${cleanip}" public_ip="${cleanip}"
public_port="$(echo ${networkInfo} | jq -r '.localaddresses [0] .port')" public_port="$(echo ${networkInfo} | jq -r '.localaddresses [0] .port')"
@@ -180,9 +169,9 @@ public_addr_pre="Public "
public_addr="??" public_addr="??"
torInfo="" torInfo=""
# Version # Version
networkVersion=$(bitcoincli_alias -datadir=${bitcoin_dir} -version 2>/dev/null | cut -d ' ' -f6) networkVersion=$($bitcoincli_alias -version 2>/dev/null | cut -d ' ' -f6)
# TOR or IP # TOR or IP
networkInfo=$(bitcoincli_alias -datadir=${bitcoin_dir} getnetworkinfo) networkInfo=$($bitcoincli_alias getnetworkinfo)
networkConnections=$(echo ${networkInfo} | jq -r '.connections') networkConnections=$(echo ${networkInfo} | jq -r '.connections')
networkConnectionsInfo="${color_green}${networkConnections} ${color_gray}connections" networkConnectionsInfo="${color_green}${networkConnections} ${color_gray}connections"
@@ -256,7 +245,7 @@ if [ "$wallet_unlocked" -gt 0 ] ; then
alias_color="${color_red}" alias_color="${color_red}"
ln_alias="Wallet Locked" ln_alias="Wallet Locked"
else else
ln_getInfo=$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>/dev/null) ln_getInfo=$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>/dev/null)
ln_external=$(echo "${ln_getInfo}" | grep "uris" -A 1 | tr -d '\n' | cut -d '"' -f4) ln_external=$(echo "${ln_getInfo}" | grep "uris" -A 1 | tr -d '\n' | cut -d '"' -f4)
ln_tor=$(echo "${ln_external}" | grep -c ".onion") ln_tor=$(echo "${ln_external}" | grep -c ".onion")
if [ ${ln_tor} -eq 1 ]; then if [ ${ln_tor} -eq 1 ]; then
@@ -280,23 +269,23 @@ else
ln_baseInfo="${color_amber} Waiting for Chain Sync" ln_baseInfo="${color_amber} Waiting for Chain Sync"
fi fi
else else
ln_walletbalance="$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.confirmed_balance')" 2>/dev/null ln_walletbalance="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.confirmed_balance')" 2>/dev/null
ln_walletbalance_wait="$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.unconfirmed_balance')" 2>/dev/null ln_walletbalance_wait="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.unconfirmed_balance')" 2>/dev/null
if [ "${ln_walletbalance_wait}" = "0" ]; then ln_walletbalance_wait=""; fi if [ "${ln_walletbalance_wait}" = "0" ]; then ln_walletbalance_wait=""; fi
if [ ${#ln_walletbalance_wait} -gt 0 ]; then ln_walletbalance_wait="(+${ln_walletbalance_wait})"; fi if [ ${#ln_walletbalance_wait} -gt 0 ]; then ln_walletbalance_wait="(+${ln_walletbalance_wait})"; fi
ln_channelbalance="$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.balance')" 2>/dev/null ln_channelbalance="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.balance')" 2>/dev/null
ln_channelbalance_pending="$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.pending_open_balance')" 2>/dev/null ln_channelbalance_pending="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.pending_open_balance')" 2>/dev/null
if [ "${ln_channelbalance_pending}" = "0" ]; then ln_channelbalance_pending=""; fi if [ "${ln_channelbalance_pending}" = "0" ]; then ln_channelbalance_pending=""; fi
if [ ${#ln_channelbalance_pending} -gt 0 ]; then ln_channelbalance_pending=" (+${ln_channelbalance_pending})"; fi if [ ${#ln_channelbalance_pending} -gt 0 ]; then ln_channelbalance_pending=" (+${ln_channelbalance_pending})"; fi
ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null
ln_channels_total="$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert listchannels | jq '.[] | length')" 2>/dev/null ln_channels_total="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert listchannels | jq '.[] | length')" 2>/dev/null
ln_baseInfo="${color_gray}wallet ${ln_walletbalance} sat ${ln_walletbalance_wait}" ln_baseInfo="${color_gray}wallet ${ln_walletbalance} sat ${ln_walletbalance_wait}"
ln_peers="$(echo "${ln_getInfo}" | jq -r '.num_peers')" 2>/dev/null ln_peers="$(echo "${ln_getInfo}" | jq -r '.num_peers')" 2>/dev/null
ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} sat${ln_channelbalance_pending}" ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} sat${ln_channelbalance_pending}"
ln_peersInfo="${color_green}${ln_peers} ${color_gray}peers" ln_peersInfo="${color_green}${ln_peers} ${color_gray}peers"
ln_dailyfees="$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport | jq -r '.day_fee_sum')" 2>/dev/null ln_dailyfees="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport | jq -r '.day_fee_sum')" 2>/dev/null
ln_weeklyfees="$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport | jq -r '.week_fee_sum')" 2>/dev/null ln_weeklyfees="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport | jq -r '.week_fee_sum')" 2>/dev/null
ln_monthlyfees="$(lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport | jq -r '.month_fee_sum')" 2>/dev/null ln_monthlyfees="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport | jq -r '.month_fee_sum')" 2>/dev/null
ln_feeReport="Fee Report (D-W-M): ${color_green}${ln_dailyfees}-${ln_weeklyfees}-${ln_monthlyfees} ${color_gray}sat" ln_feeReport="Fee Report (D-W-M): ${color_green}${ln_dailyfees}-${ln_weeklyfees}-${ln_monthlyfees} ${color_gray}sat"
fi fi
fi fi

View File

@@ -110,6 +110,9 @@ while :
configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf') configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf')
if [ ${configExists} -eq 1 ]; then if [ ${configExists} -eq 1 ]; then
source ${configFile} source ${configFile}
source /home/admin/config.scripts/_functions.lightning.sh
getLNvars lnd ${chain}net
getLNaliases
fi fi
# reboot info # reboot info
@@ -294,7 +297,7 @@ while :
fi fi
# if LND is syncing or scanning # if LND is syncing or scanning
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true) lndSynced=$($lncli_alias getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
if [ ${lndSynced} -eq 0 ]; then if [ ${lndSynced} -eq 0 ]; then
/home/admin/80scanLND.sh /home/admin/80scanLND.sh
sleep 20 sleep 20

View File

@@ -154,6 +154,9 @@ if [ "${state}" = "ready" ]; then
if [ ${configExists} -eq 1 ]; then if [ ${configExists} -eq 1 ]; then
echo "loading config data" echo "loading config data"
source ${configFile} source ${configFile}
source /home/admin/config.scripts/_functions.lightning.sh
getLNvars lnd ${chain}net
getLNaliases
else else
echo "setup still in progress - setupStep(${setupStep})" echo "setup still in progress - setupStep(${setupStep})"
fi fi
@@ -180,8 +183,8 @@ waitUntilChainNetworkIsReady()
echo "can take longer if device was off or first time" echo "can take longer if device was off or first time"
# check for error on network # check for error on network
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp bitcoincli_alias getblockchaininfo 1>/dev/null 2>error.tmp
clienterror=`cat error.tmp` clienterror=$(cat error.tmp)
rm error.tmp rm error.tmp
# check for missing blockchain data # check for missing blockchain data
@@ -279,7 +282,7 @@ How do you want to continue?
while : while :
do do
locked=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock) locked=$($lncli_alias getinfo 2>&1 | grep -c unlock)
if [ ${locked} -gt 0 ]; then if [ ${locked} -gt 0 ]; then
uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime) uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime)
if [ "${autoUnlock}" == "on" ] && [ ${uptime} -lt 300 ]; then if [ "${autoUnlock}" == "on" ] && [ ${uptime} -lt 300 ]; then
@@ -302,7 +305,7 @@ How do you want to continue?
fi fi
fi fi
fi fi
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true) lndSynced=$($lncli_alias getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
if [ ${lndSynced} -eq 0 ]; then if [ ${lndSynced} -eq 0 ]; then
/home/admin/80scanLND.sh /home/admin/80scanLND.sh
if [ $? -gt 0 ]; then if [ $? -gt 0 ]; then

View File

@@ -115,9 +115,9 @@ else
# check if the node is now in peer list # check if the node is now in peer list
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
isPeer=$(lightningcli_alias listpeers 2>/dev/null| grep "${pubkey}" -c) isPeer=$($lightningcli_alias listpeers 2>/dev/null| grep "${pubkey}" -c)
elif [ $LNTYPE = lnd ];then elif [ $LNTYPE = lnd ];then
isPeer=$(lncli_alias listpeers 2>/dev/null| grep "${pubkey}" -c) isPeer=$($lncli_alias listpeers 2>/dev/null| grep "${pubkey}" -c)
fi fi
if [ ${isPeer} -eq 0 ]; then if [ ${isPeer} -eq 0 ]; then

View File

@@ -17,15 +17,15 @@ getLNaliases
# PRECHECK) check if chain is in sync # PRECHECK) check if chain is in sync
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
BLOCKHEIGHT=$(bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1) BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1)
CLHEIGHT=$(lightningcli_alias getinfo | jq .blockheight) CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight)
if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then
chainOutSync=0 chainOutSync=0
else else
chainOutSync=1 chainOutSync=1
fi fi
elif [ $LNTYPE = lnd ];then elif [ $LNTYPE = lnd ];then
chainOutSync=$(lncli_alias getinfo | grep '"synced_to_chain": false' -c) chainOutSync=$($lncli_alias getinfo | grep '"synced_to_chain": false' -c)
fi fi
if [ ${chainOutSync} -eq 1 ]; then if [ ${chainOutSync} -eq 1 ]; then
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then

View File

@@ -21,15 +21,15 @@ echo "*** Precheck ***"
# PRECHECK) check if chain is in sync # PRECHECK) check if chain is in sync
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
BLOCKHEIGHT=$(bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1) BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1)
CLHEIGHT=$(lightningcli_alias getinfo | jq .blockheight) CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight)
if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then
chainOutSync=0 chainOutSync=0
else else
chainOutSync=1 chainOutSync=1
fi fi
elif [ $LNTYPE = lnd ];then elif [ $LNTYPE = lnd ];then
chainOutSync=$(lncli_alias getinfo | grep '"synced_to_chain": false' -c) chainOutSync=$($lncli_alias getinfo | grep '"synced_to_chain": false' -c)
fi fi
if [ ${chainOutSync} -eq 1 ]; then if [ ${chainOutSync} -eq 1 ]; then
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
@@ -47,11 +47,11 @@ fi
# check available funding # check available funding
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
for i in $(lightningcli_alias listfunds | jq .outputs | grep value | awk '{print $2}' | cut -d, -f1);do for i in $($lightningcli_alias listfunds | jq .outputs | grep value | awk '{print $2}' | cut -d, -f1);do
confirmedBalance=$((confirmedBalance+i)) confirmedBalance=$((confirmedBalance+i))
done done
elif [ $LNTYPE = lnd ];then elif [ $LNTYPE = lnd ];then
confirmedBalance=$(lncli_alias walletbalance | grep '"confirmed_balance"' | cut -d '"' -f4) confirmedBalance=$($lncli_alias walletbalance | grep '"confirmed_balance"' | cut -d '"' -f4)
fi fi
if [ ${confirmedBalance} -eq 0 ]; then if [ ${confirmedBalance} -eq 0 ]; then
@@ -65,9 +65,9 @@ fi
# check number of connected peers # check number of connected peers
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
numConnectedPeers=$(lightningcli_alias listpeers | grep -c '"id":') numConnectedPeers=$($lightningcli_alias listpeers | grep -c '"id":')
elif [ $LNTYPE = lnd ];then elif [ $LNTYPE = lnd ];then
numConnectedPeers=$(lncli_alias listpeers | grep pub_key -c) numConnectedPeers=$($lncli_alias listpeers | grep pub_key -c)
fi fi
if [ ${numConnectedPeers} -eq 0 ]; then if [ ${numConnectedPeers} -eq 0 ]; then
@@ -163,7 +163,7 @@ fi
# build command # build command
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
# fundchannel id amount [feerate] [announce] [minconf] [utxos] [push_msat] [close_to] # fundchannel id amount [feerate] [announce] [minconf] [utxos] [push_msat] [close_to]
feerate=$(bitcoincli_alias estimatesmartfee $conf_target |grep feerate|awk '{print $2}'|cut -c 5-7|bc) feerate=$($bitcoincli_alias estimatesmartfee $conf_target |grep feerate|awk '{print $2}'|cut -c 5-7|bc)
command="lightningcli_alias fundchannel ${pubKey} ${amount} $feerate" command="lightningcli_alias fundchannel ${pubKey} ${amount} $feerate"
elif [ $LNTYPE = lnd ];then elif [ $LNTYPE = lnd ];then
command="lncli_alias openchannel --conf_target=${conf_target} ${pubKey} ${amount} 0" command="lncli_alias openchannel --conf_target=${conf_target} ${pubKey} ${amount} 0"

View File

@@ -21,8 +21,8 @@ getLNaliases
# check if chain is in sync # check if chain is in sync
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
lncommand="lightning-cli" lncommand="lightning-cli"
BLOCKHEIGHT=$(bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1) BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1)
CLHEIGHT=$(lightningcli_alias getinfo | jq .blockheight) CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight)
if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then
cmdChainInSync=1 cmdChainInSync=1
else else
@@ -48,9 +48,9 @@ done
# check number of connected peers # check number of connected peers
echo "check for open channels" echo "check for open channels"
if [ $LNTYPE = cln ];then if [ $LNTYPE = cln ];then
openChannels=$(lightningcli_alias listpeers | grep -c '"CHANNELD_NORMAL:Funding transaction locked. Channel announced."') openChannels=$($lightningcli_alias listpeers | grep -c '"CHANNELD_NORMAL:Funding transaction locked. Channel announced."')
elif [ $LNTYPE = lnd ];then elif [ $LNTYPE = lnd ];then
openChannels=$(lncli_alias listchannels 2>/dev/null | grep chan_id -c) openChannels=$($lncli_alias listchannels 2>/dev/null | grep chan_id -c)
fi fi
if [ ${openChannels} -eq 0 ]; then if [ ${openChannels} -eq 0 ]; then
echo echo

View File

@@ -32,8 +32,12 @@ function getLNvars {
# getLNaliases <vars set by getLNvars> # getLNaliases <vars set by getLNvars>
function getLNaliases { function getLNaliases {
#TODO ALL
# instead of all
# sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net
lncli_alias="sudo -u bitcoin /usr/local/bin/lncli -n=${chain}net --rpcserver localhost:1${L2rpcportmod}009" lncli_alias="sudo -u bitcoin /usr/local/bin/lncli -n=${chain}net --rpcserver localhost:1${L2rpcportmod}009"
bitcoincli_alias="/usr/local/bin/${network}-cli -rpcport=${L1rpcportmod}8332" # sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network}
bitcoincli_alias="/usr/local/bin/${network}-cli -datadir=/home/bitcoin/.${network} -rpcport=${L1rpcportmod}8332"
lightningcli_alias="sudo -u bitcoin /usr/local/bin/lightning-cli --conf=/home/bitcoin/.lightning/${netprefix}config" lightningcli_alias="sudo -u bitcoin /usr/local/bin/lightning-cli --conf=/home/bitcoin/.lightning/${netprefix}config"
shopt -s expand_aliases shopt -s expand_aliases
alias lncli_alias="$lncli_alias" alias lncli_alias="$lncli_alias"

View File

@@ -3,6 +3,17 @@
source /home/admin/raspiblitz.info source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf source /mnt/hdd/raspiblitz.conf
# LNTYPE is lnd | cln
if [ $# -gt 0 ];then
LNTYPE=$1
else
LNTYPE=lnd
fi
source /home/admin/config.scripts/_functions.lightning.sh
getLNvars $LNTYPE ${chain}net
getLNaliases
# command info # command info
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# script to scan the state of the system after setup" echo "# script to scan the state of the system after setup"
@@ -45,7 +56,7 @@ echo "bitcoinActive=${bitcoinRunning}"
if [ ${bitcoinRunning} -eq 1 ]; then if [ ${bitcoinRunning} -eq 1 ]; then
# get blockchain info # get blockchain info
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/mnt/hdd/temp/.bitcoind.out 2>/mnt/hdd/temp/.bitcoind.error bitcoincli_alias getblockchaininfo 1>/mnt/hdd/temp/.bitcoind.out 2>/mnt/hdd/temp/.bitcoind.error
# check if error on request # check if error on request
blockchaininfo=$(cat /mnt/hdd/temp/.bitcoind.out 2>/dev/null) blockchaininfo=$(cat /mnt/hdd/temp/.bitcoind.out 2>/dev/null)
bitcoinError=$(cat /mnt/hdd/temp/.bitcoind.error 2>/dev/null) bitcoinError=$(cat /mnt/hdd/temp/.bitcoind.error 2>/dev/null)
@@ -120,14 +131,14 @@ startcountLightning=$(cat /home/admin/systemd.lightning.log 2>/dev/null | grep -
echo "startcountLightning=${startcountLightning}" echo "startcountLightning=${startcountLightning}"
# is LND running # is LND running
lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running) lndRunning=$(systemctl status ${netprefix}lnd.service 2>/dev/null | grep -c running)
echo "lndActive=${lndRunning}" echo "lndActive=${lndRunning}"
if [ ${lndRunning} -eq 1 ]; then if [ ${lndRunning} -eq 1 ]; then
# get LND info # get LND info
lndRPCReady=1 lndRPCReady=1
lndinfo=$(sudo -u bitcoin lncli --chain=${network} --network=${chain}net getinfo 2>/mnt/hdd/temp/.lnd.error) lndinfo=$($lncli_alias getinfo 2>/mnt/hdd/temp/.lnd.error)
# check if error on request # check if error on request
lndErrorFull=$(cat /mnt/hdd/temp/.lnd.error 2>/dev/null) lndErrorFull=$(cat /mnt/hdd/temp/.lnd.error 2>/dev/null)

View File

@@ -10,13 +10,17 @@ fi
source /home/admin/raspiblitz.info source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf source /mnt/hdd/raspiblitz.conf
source /home/admin/config.scripts/_functions.lightning.sh
getLNvars lnd ${chain}net
getLNaliases
# 1. parameter # 1. parameter
passwordC="$1" passwordC="$1"
# check if wallet is already unlocked # check if wallet is already unlocked
echo "# checking LND wallet ... (can take some time)" echo "# checking LND wallet ... (can take some time)"
walletLocked=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock) walletLocked=$($lncli_alias getinfo 2>&1 | grep -c unlock)
macaroonsMissing=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c "unable to read macaroon") macaroonsMissing=$($lncli_alias getinfo 2>&1 | grep -c "unable to read macaroon")
if [ ${walletLocked} -eq 0 ] && [ ${macaroonsMissing} -eq 0 ]; then if [ ${walletLocked} -eq 0 ] && [ ${macaroonsMissing} -eq 0 ]; then
echo "# OK LND wallet was already unlocked" echo "# OK LND wallet was already unlocked"
exit 0 exit 0
@@ -91,7 +95,7 @@ while [ ${fallback} -eq 0 ]
# UNKNOWN RESULT # UNKNOWN RESULT
# check if wallet was unlocked anyway # check if wallet was unlocked anyway
walletLocked=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock) walletLocked=$($lncli_alias getinfo 2>&1 | grep -c unlock)
if [ "${walletUnlocked}" = "0" ]; then if [ "${walletUnlocked}" = "0" ]; then
echo "# OK LND wallet unlocked" echo "# OK LND wallet unlocked"
exit 0 exit 0
@@ -120,12 +124,12 @@ do
# do CLI unlock # do CLI unlock
echo echo
echo "############################" echo "############################"
echo "Calling: lncli unlock" echo "Calling: ${netprefix}lncli unlock"
echo "Please re-enter Password C:" echo "Please re-enter Password C:"
lncli --chain=${network} --network=${chain}net unlock --recovery_window=1000 lncli_alias unlock --recovery_window=1000
# test unlock # test unlock
walletLocked=$(sudo -u bitcoin /usr/local/bin/lncli getinfo 2>&1 | grep -c unlock) walletLocked=$($lncli_alias getinfo 2>&1 | grep -c unlock)
if [ ${walletLocked} -eq 0 ]; then if [ ${walletLocked} -eq 0 ]; then
echo "# --> OK LND wallet unlocked" echo "# --> OK LND wallet unlocked"
else else

View File

@@ -2,7 +2,7 @@
# command info # command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "monitor and troubleshot the bitcoin network" echo "monitor and troubleshoot the bitcoin network"
echo "network.monitor.sh peer-status" echo "network.monitor.sh peer-status"
echo "network.monitor.sh peer-kickstart [ipv4|ipv6|tor|auto]" echo "network.monitor.sh peer-kickstart [ipv4|ipv6|tor|auto]"
echo "network.monitor.sh peer-disconnectall" echo "network.monitor.sh peer-disconnectall"
@@ -12,6 +12,10 @@ fi
source /mnt/hdd/raspiblitz.conf source /mnt/hdd/raspiblitz.conf
source /home/admin/raspiblitz.info source /home/admin/raspiblitz.info
source /home/admin/config.scripts/_functions.lightning.sh
getLNvars lnd ${chain}net
getLNaliases
################### ###################
# STATUS # STATUS
################### ###################
@@ -19,7 +23,7 @@ if [ "$1" = "peer-status" ]; then
echo "#network.monitor.sh peer-status" echo "#network.monitor.sh peer-status"
# number of peers connected # number of peers connected
peerNum=$(${network}-cli getnetworkinfo | grep "connections\"" | tr -cd '[[:digit:]]') peerNum=$($bitcoincli_alias getnetworkinfo | grep "connections\"" | tr -cd '[[:digit:]]')
echo "peers=${peerNum}" echo "peers=${peerNum}"
exit 0 exit 0
@@ -111,7 +115,7 @@ if [ "$1" = "peer-kickstart" ]; then
echo "newpeer='${nodeAddress}" echo "newpeer='${nodeAddress}"
# kick start node with # kick start node with
sudo -u admin ${network}-cli addnode "${nodeAddress}" "onetry" 1>/dev/null bitcoincli_alias addnode "${nodeAddress}" "onetry" 1>/dev/null
echo "exitcode=$?" echo "exitcode=$?"
exit 0 exit 0
@@ -131,15 +135,15 @@ if [ "$1" = "peer-disconnectall" ]; then
fi fi
# get all peer id and disconnect them # get all peer id and disconnect them
sudo -u admin ${network}-cli getpeerinfo | grep '"addr": "' | while read line bitcoincli_alias getpeerinfo | grep '"addr": "' | while read line
do do
peerID=$(echo $line | cut -d '"' -f4) peerID=$(echo $line | cut -d '"' -f4)
echo "# disconnecting peer with ID: ${peerID}" echo "# disconnecting peer with ID: ${peerID}"
sudo -u admin ${network}-cli disconnectnode ${peerID} bitcoincli_alias disconnectnode ${peerID}
done done
echo "#### FINAL PEER INFO FORM BITCOIND" echo "#### FINAL PEER INFO FROM BITCOIND"
sudo -u admin ${network}-cli getpeerinfo bitcoincli_alias getpeerinfo
exit 0 exit 0
fi fi