diff --git a/README.md b/README.md index e71f3559b..897886271 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,7 @@ In the end your RaspiBlitz should look like this: ## Downloading the Software + |Method|Install the image|Build the sd card| |------|-----------------|-----------------| |Philosophy|Trust|Sovereignty| diff --git a/home.admin/00infoBlitz.sh b/home.admin/00infoBlitz.sh index b8cc29f4f..1807ac148 100755 --- a/home.admin/00infoBlitz.sh +++ b/home.admin/00infoBlitz.sh @@ -1,5 +1,7 @@ #!/bin/bash +# 00infoBlitz.sh + # load code software version source /home/admin/_version.info @@ -14,6 +16,12 @@ color_gray='\033[0;37m' source /home/admin/raspiblitz.info 2>/dev/null source /mnt/hdd/raspiblitz.conf 2>/dev/null +source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) +shopt -s expand_aliases +alias bitcoincli_alias="$bitcoincli_alias" +alias lncli_alias="$lncli_alias" +alias lightningcli_alias="$lightningcli_alias" + ## get HDD/SSD info source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status) hdd="${hddUsedInfo}" @@ -45,7 +53,7 @@ if [ ${#network} -eq 0 ]; then if [ ${litecoinActive} -eq 1 ]; then network="litecoin" else - network=`sudo cat /home/admin/.network 2>/dev/null` + network=$(sudo cat /home/admin/.network 2>/dev/null) fi if [ ${#network} -eq 0 ]; then network="bitcoin" @@ -62,7 +70,6 @@ if [ ${#chain} -eq 0 ]; then fi # set datadir -bitcoin_dir="/home/bitcoin/.${network}" lnd_dir="/home/bitcoin/.lnd" lnd_macaroon_dir="/home/bitcoin/.lnd/data/chain/${network}/${chain}net" @@ -74,9 +81,13 @@ cpu=0 if [ -d "/sys/class/thermal/thermal_zone0/" ]; then cpu=$(cat /sys/class/thermal/thermal_zone0/temp) fi -tempC=$((cpu/1000)) -tempF=$(((tempC * 18 + 325) / 10)) - +if [ $cpu = 0 ];then + tempC="" + tempF="" +else + tempC=$((cpu/1000)) + tempF=$(((tempC * 18 + 325) / 10)) +fi # get memory ram_avail=$(free -m | grep Mem | awk '{ print $7 }') ram=$(printf "%sM / %sM" "${ram_avail}" "$(free -m | grep Mem | awk '{ print $2 }')") @@ -90,14 +101,14 @@ fi # Bitcoin blockchain btc_path=$(command -v ${network}-cli) blockInfo="-" -if [ -n ${btc_path} ]; then +if [ -n "${btc_path}" ]; then btc_title=$network - blockchaininfo="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo 2>/dev/null)" + blockchaininfo="$($bitcoincli_alias getblockchaininfo 2>/dev/null)" if [ ${#blockchaininfo} -gt 0 ]; then btc_title="${btc_title} (${chain}net)" # get sync status - block_chain="$(${network}-cli -datadir=${bitcoin_dir} getblockcount 2>/dev/null)" + block_chain="$($bitcoincli_alias getblockcount 2>/dev/null)" block_verified="$(echo "${blockchaininfo}" | jq -r '.blocks')" block_diff=$(expr ${block_chain} - ${block_verified}) blockInfo="${block_verified}/${block_chain}" @@ -124,13 +135,13 @@ if [ -n ${btc_path} ]; then fi # get last known block - last_block="$(${network}-cli -datadir=${bitcoin_dir} getblockcount 2>/dev/null)" + last_block="$($bitcoincli_alias getblockcount 2>/dev/null)" if [ ! -z "${last_block}" ]; then btc_line2="${btc_line2} ${color_gray}(block ${last_block})" fi # get mem pool transactions - mempool="$(${network}-cli -datadir=${bitcoin_dir} getmempoolinfo 2>/dev/null | jq -r '.size')" + mempool="$($bitcoincli_alias getmempoolinfo 2>/dev/null | jq -r '.size')" else btc_line2="${color_red}NOT RUNNING\t\t" @@ -138,7 +149,7 @@ if [ -n ${btc_path} ]; then fi # get IP address & port -networkInfo=$(${network}-cli -datadir=${bitcoin_dir} getnetworkinfo 2>/dev/null) +networkInfo=$($bitcoincli_alias getnetworkinfo 2>/dev/null) local_ip="${localip}" # from internet.sh public_ip="${cleanip}" public_port="$(echo ${networkInfo} | jq -r '.localaddresses [0] .port')" @@ -152,9 +163,14 @@ fi # check if RTL web interface is installed webinterfaceInfo="" -runningRTL=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service') +runningRTL=$(systemctl status ${netprefix}${typeprefix}RTL.service 2>/dev/null | grep -c active) if [ ${runningRTL} -eq 1 ]; then - webinterfaceInfo="Web admin --> ${color_green}http://${local_ip}:3000" + if [ ${LNTYPE} = "cln" ]; then + RTLHTTP=${portprefix}7000 + elif [ ${LNTYPE} = "lnd" ];then + RTLHTTP=${portprefix}3000 + fi + webinterfaceInfo="Web admin --> ${color_green}http://${local_ip}:${RTLHTTP}" fi # CHAIN NETWORK @@ -162,9 +178,9 @@ public_addr_pre="Public " public_addr="??" torInfo="" # Version -networkVersion=$(${network}-cli -datadir=${bitcoin_dir} -version 2>/dev/null | cut -d ' ' -f6) +networkVersion=$($bitcoincli_alias -version 2>/dev/null | cut -d ' ' -f6) # TOR or IP -networkInfo=$(${network}-cli -datadir=${bitcoin_dir} getnetworkinfo) +networkInfo=$($bitcoincli_alias getnetworkinfo) networkConnections=$(echo ${networkInfo} | jq -r '.connections') networkConnectionsInfo="${color_green}${networkConnections} ${color_gray}connections" @@ -222,69 +238,167 @@ else fi # LIGHTNING NETWORK - -ln_baseInfo="-" -ln_channelInfo="\n" -ln_external="\n" -ln_alias="${hostname}" -ln_publicColor="" -ln_port=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep "^listen=*" | cut -f2 -d':') -if [ ${#ln_port} -eq 0 ]; then - ln_port="9735" -fi - -wallet_unlocked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2> /dev/null | grep -c unlock) -if [ "$wallet_unlocked" -gt 0 ] ; then - alias_color="${color_red}" - ln_alias="Wallet Locked" -else - ln_getInfo=$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>/dev/null) - ln_external=$(echo "${ln_getInfo}" | grep "uris" -A 1 | tr -d '\n' | cut -d '"' -f4) - ln_tor=$(echo "${ln_external}" | grep -c ".onion") - if [ ${ln_tor} -eq 1 ]; then - ln_publicColor="${color_green}" - else - public_check=$(nc -z -w6 ${public_ip} ${ln_port} 2>/dev/null; echo $?) - if [ $public_check = "0" ] || [ "${ipv6}" == "on" ]; then - # only set yellow/normal because netcat can only say that the port is open - not that it points to this device for sure - ln_publicColor="${color_amber}" - else - ln_publicColor="${color_red}" - fi +if [ ${LNTYPE} = "cln" ]; then + ln_baseInfo="-" + ln_channelInfo="\n" + ln_external="\n" + ln_alias="$(sudo cat /home/bitcoin/.lightning/${netprefix}config | grep "^alias=*" | cut -f2 -d=)" + if [ ${#ln_alias} -eq 0 ];then + ln_alias=$(lightningcli_alias getinfo | grep '"alias":' | cut -d '"' -f4) fi - alias_color="${color_grey}" - ln_sync=$(echo "${ln_getInfo}" | grep "synced_to_chain" | grep "true" -c) - ln_version=$(echo "${ln_getInfo}" | jq -r '.version' | cut -d' ' -f1) - if [ ${ln_sync} -eq 0 ]; then - if [ ${#ln_getInfo} -eq 0 ]; then - ln_baseInfo="${color_red} Not Started | Not Ready Yet" - else - ln_baseInfo="${color_amber} Waiting for Chain Sync" - fi + if [ ${#ln_alias} -eq 0 ];then + ln_alias=${hostname} + fi + ln_publicColor="" + ln_port=$(sudo cat /home/bitcoin/.lightning/${netprefix}config | grep "^bind-addr=*" | cut -f2 -d':') + if [ ${#ln_port} -eq 0 ]; then + ln_port=$(lightningcli_alias getinfo | grep '"port":' | cut -d: -f2 | tail -1 | bc) + fi + wallet_unlocked=0 #TODO + if [ "$wallet_unlocked" -gt 0 ] ; then + alias_color="${color_red}" + ln_alias="Wallet Locked" + else + ln_getInfo=$($lightningcli_alias getinfo 2>/dev/null) + pubkey=$(echo "${ln_getInfo}" | grep '"id":' | cut -d '"' -f4) + address=$(echo "${ln_getInfo}" | grep '.onion' | cut -d '"' -f4) + if [ ${#address} -eq 0 ];then + address=$(echo "${ln_getInfo}" | grep '"ipv4"' -A 1 | tail -1 | cut -d '"' -f4) + fi + ln_external="${pubkey}@${address}" + ln_tor=$(echo "${ln_external}" | grep -c ".onion") + if [ ${ln_tor} -eq 1 ]; then + ln_publicColor="${color_green}" else - ln_walletbalance="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.confirmed_balance')" 2>/dev/null - ln_walletbalance_wait="$(sudo -u bitcoin /usr/local/bin/lncli --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} -gt 0 ]; then ln_walletbalance_wait="(+${ln_walletbalance_wait})"; fi - ln_channelbalance="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.balance')" 2>/dev/null - ln_channelbalance_pending="$(sudo -u bitcoin /usr/local/bin/lncli --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} -gt 0 ]; then ln_channelbalance_pending=" (+${ln_channelbalance_pending})"; fi - ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null - ln_channels_total="$(sudo -u bitcoin /usr/local/bin/lncli --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_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_peersInfo="${color_green}${ln_peers} ${color_gray}peers" - ln_dailyfees="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport | jq -r '.day_fee_sum')" 2>/dev/null - ln_weeklyfees="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert feereport | jq -r '.week_fee_sum')" 2>/dev/null - ln_monthlyfees="$(sudo -u bitcoin /usr/local/bin/lncli --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" + public_check=$(nc -z -w6 ${public_ip} ${ln_port} 2>/dev/null; echo $?) + if [ $public_check = "0" ] || [ "${ipv6}" == "on" ]; then + # only set yellow/normal because netcat can only say that the port is open - not that it points to this device for sure + ln_publicColor="${color_amber}" + else + ln_publicColor="${color_red}" + fi fi + alias_color="${color_grey}" + BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1) + CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight) + if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then + ln_sync=1 + else + ln_sync=0 + fi + ln_version=$(lightningcli_alias -V) + if [ ${ln_sync} -eq 0 ]; then + if [ ${#ln_getInfo} -eq 0 ]; then + ln_baseInfo="${color_red} Not Started | Not Ready Yet" + else + ln_baseInfo="${color_amber} Waiting for Chain Sync" + fi + else + ln_walletbalance=0 + for i in $($lightningcli_alias \ + listfunds|jq .outputs[]|jq 'select(.status=="confirmed")'|grep value|awk '{print $2}'|cut -d, -f1);do + ln_walletbalance=$((ln_walletbalance+i)) + done + for i in $($lightningcli_alias \ + listfunds|jq .outputs[]|jq 'select(.status=="unconfirmed")'|grep value|awk '{print $2}'|cut -d, -f1);do + ln_walletbalance_wait=$((ln_walletbalance_wait+i)) + done + if [ "${ln_walletbalance_wait}" = "0" ]; then ln_walletbalance_wait=""; fi + if [ ${#ln_walletbalance_wait} -gt 0 ]; then ln_walletbalance_wait="(+${ln_walletbalance_wait})"; fi + ln_channelbalance=0 + for i in $($lightningcli_alias \ + listfunds|jq .channels[]|jq 'select(.state=="CHANNELD_NORMAL")'|grep channel_sat|awk '{print $2}'|cut -d, -f1);do + ln_channelbalance=$((ln_channelbalance+i)) + done + if [ ${#ln_channelbalance} -eq 0 ];then + ln_channelbalance=0 + fi + for i in $($lightningcli_alias \ + listfunds|jq .channels[]|grep channel_sat|awk '{print $2}'|cut -d, -f1);do + ln_channelbalance_all=$((ln_channelbalance_all+i)) + done + ln_channelbalance_pending=$((ln_channelbalance_all-ln_channelbalance)) + if [ "${ln_channelbalance_pending}" = "0" ]; then ln_channelbalance_pending=""; fi + if [ ${#ln_channelbalance_pending} -gt 0 ]; then ln_channelbalance_pending=" (+${ln_channelbalance_pending})"; fi + ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null + ln_channels_total="$(echo "${ln_getInfo}" | jq -r '.num_peers')" 2>/dev/null + ln_baseInfo="${color_gray}wallet ${ln_walletbalance} ${netprefix}sat ${ln_walletbalance_wait}" + ln_peers="$(echo "${ln_getInfo}" | jq -r '.num_peers')" 2>/dev/null + ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} ${netprefix}sat${ln_channelbalance_pending}" + ln_peersInfo="${color_green}${ln_peers} ${color_gray}peers" + #ln_dailyfees="$($lncli_alias feereport | jq -r '.day_fee_sum')" 2>/dev/null + #ln_weeklyfees="$($lncli_alias feereport | jq -r '.week_fee_sum')" 2>/dev/null + #ln_monthlyfees="$($lncli_alias feereport | jq -r '.month_fee_sum')" 2>/dev/null + #ln_feeReport="Fee Report (D-W-M): ${color_green}${ln_dailyfees}-${ln_weeklyfees}-${ln_monthlyfees} ${color_gray}sat" + ln_feeReport="$(lightningcli_alias -H summary | grep fees_collected)" + fi + fi + +elif [ ${LNTYPE} = "lnd" ];then + ln_baseInfo="-" + ln_channelInfo="\n" + ln_external="\n" + ln_alias="$(sudo cat /mnt/hdd/lnd/${netprefix}lnd.conf | grep "^alias=*" | cut -f2 -d=)" + if [ ${#ln_alias} -eq 0 ];then + ln_alias=${hostname} + fi + ln_publicColor="" + ln_port=$(sudo cat /mnt/hdd/lnd/${netprefix}lnd.conf | grep "^listen=*" | cut -f2 -d':') + if [ ${#ln_port} -eq 0 ]; then + ln_port="9735" + fi + wallet_unlocked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2> /dev/null | grep -c unlock) + if [ "$wallet_unlocked" -gt 0 ] ; then + alias_color="${color_red}" + ln_alias="Wallet Locked" + else + ln_getInfo=$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>/dev/null) + ln_external=$(echo "${ln_getInfo}" | grep "uris" -A 1 | tr -d '\n' | cut -d '"' -f4) + ln_tor=$(echo "${ln_external}" | grep -c ".onion") + if [ ${ln_tor} -eq 1 ]; then + ln_publicColor="${color_green}" + else + public_check=$(nc -z -w6 ${public_ip} ${ln_port} 2>/dev/null; echo $?) + if [ $public_check = "0" ] || [ "${ipv6}" == "on" ]; then + # only set yellow/normal because netcat can only say that the port is open - not that it points to this device for sure + ln_publicColor="${color_amber}" + else + ln_publicColor="${color_red}" + fi + fi + alias_color="${color_grey}" + ln_sync=$(echo "${ln_getInfo}" | grep "synced_to_chain" | grep "true" -c) + ln_version=$(echo "${ln_getInfo}" | jq -r '.version' | cut -d' ' -f1) + if [ ${ln_sync} -eq 0 ]; then + if [ ${#ln_getInfo} -eq 0 ]; then + ln_baseInfo="${color_red} Not Started | Not Ready Yet" + else + ln_baseInfo="${color_amber} Waiting for Chain Sync" + fi + else + 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 + if [ "${ln_walletbalance_wait}" = "0" ]; then 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_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} -gt 0 ]; then ln_channelbalance_pending=" (+${ln_channelbalance_pending})"; fi + ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null + ln_channels_total="$($lncli_alias --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert listchannels | jq '.[] | length')" 2>/dev/null + ln_baseInfo="${color_gray}wallet ${ln_walletbalance} ${netprefix}sat ${ln_walletbalance_wait}" + ln_peers="$(echo "${ln_getInfo}" | jq -r '.num_peers')" 2>/dev/null + ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} ${netprefix}sat${ln_channelbalance_pending}" + ln_peersInfo="${color_green}${ln_peers} ${color_gray}peers" + 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_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" + fi + fi fi # show JoinMarket stats in place of the LND URI only if the Yield Generator is running - source /home/joinmarket/joinin.conf 2>/dev/null if [ "${joinmarket}" = "on" ] && [ $(sudo -u joinmarket pgrep -f "python yg-privacyenhanced.py $YGwallet --wallet-password-stdin" 2>/dev/null | wc -l) -gt 2 ]; then JMstats=$(mktemp 2>/dev/null) @@ -305,6 +419,17 @@ ${color_yellow} ${color_yellow}${ln_publicColor}${ln_external}${color_gray}" fi +if [ $LNTYPE = "cln" ];then + LNline="C-LIGHTNING ${color_green}${ln_version} ${ln_baseInfo}" +elif [ $LNTYPE = "lnd" ];then + LNline="LND ${color_green}${ln_version} ${ln_baseInfo}" +fi + +if [ $cpu = 0 ];then + templine="on $(uname -m) VM%s%s" +else + templine="temp %s°C %s°F" +fi sleep 5 ## get uptime and current date & time @@ -320,14 +445,14 @@ ${color_yellow} ${color_amber}%s ${color_green} ${ln_alias} ${upsI ${color_yellow} ${color_gray}${network^} Fullnode + Lightning Network ${torInfo} ${color_yellow} ,/ ${color_yellow}%s ${color_yellow} ,'/ ${color_gray}%s -${color_yellow} ,' / ${color_gray}%s, temp %s°C %s°F +${color_yellow} ,' / ${color_gray}%s, ${templine} ${color_yellow} ,' /_____, ${color_gray}Free Mem ${color_ram}${ram} ${color_gray} HDDuse ${color_hdd}%s${color_gray} ${color_yellow} .'____ ,' ${color_gray}SSH admin@${color_green}${local_ip}${color_gray} d${network_rx} u${network_tx} ${color_yellow} / ,' ${color_gray}${webinterfaceInfo} ${color_yellow} / ,' ${color_gray}${network} ${color_green}${networkVersion} ${color_gray}${chain}net ${networkConnectionsInfo} ${color_yellow} /,' ${color_gray}Blocks ${blockInfo} ${color_gray}Sync ${sync_color}${sync} %s ${color_yellow} /' ${color_gray} -${color_yellow} ${color_gray}LND ${color_green}${ln_version} ${ln_baseInfo} +${color_yellow} ${color_gray}${LNline} ${color_yellow} ${color_gray}${ln_channelInfo} ${ln_peersInfo} ${color_yellow} ${color_gray}${ln_feeReport} $lastLine diff --git a/home.admin/00infoLCD.sh b/home.admin/00infoLCD.sh index f36643533..3bfafede8 100755 --- a/home.admin/00infoLCD.sh +++ b/home.admin/00infoLCD.sh @@ -86,6 +86,15 @@ while : # get config info if already available (with state value) source ${infoFile} + configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf') + if [ ${configExists} -eq 1 ]; then + source ${configFile} + source <(/home/admin/config.scripts/network.aliases.sh getvars) + shopt -s expand_aliases + alias bitcoincli_alias="$bitcoincli_alias" + alias lncli_alias="$lncli_alias" + alias lightningcli_alias="$lightningcli_alias" + fi if [ "${setupPhase}" != "done" ]; then @@ -98,7 +107,7 @@ while : # TODO: ALSO SEPERATE GUI/ACTION FOR THE SCANNING / WALLET UNLOCK / ERROR DETECTION # 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 /home/admin/80scanLND.sh sleep 20 diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index 15c991dee..0d41ed551 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -40,6 +40,14 @@ confirmation() # get the local network IP to be displayed on the LCD source <(/home/admin/config.scripts/internet.sh status local) +if [ ${chain} = test ];then + netprefix="t" +elif [ ${chain} = sig ];then + netprefix="s" +elif [ ${chain} = main ];then + netprefix="" +fi + # BASIC MENU INFO HEIGHT=19 WIDTH=64 @@ -163,9 +171,28 @@ if [ "${circuitbreaker}" == "on" ]; then CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) fi +if [ "${testnet}" == "on" ]&&[ ${chain} != test ];then + OPTIONS+=(TESTNET "Testnet Service Options") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +if [ ${chain} != main ];then + OPTIONS+=(MAINNET "Mainnet Service Options") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + # Basic Options OPTIONS+=(INFO "RaspiBlitz Status Screen") -OPTIONS+=(LIGHTNING "LND Wallet Options") +OPTIONS+=(LND "LND Wallet Options") + +if [ "$cln" == "on" ]||[ $chain = test ]&&[ "$tcln" == "on" ]; then + OPTIONS+=(CLN "C-lightning Wallet Options") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + OPTIONS+=(SETTINGS "Node Settings & Options") OPTIONS+=(SERVICES "Additional Apps & Services") OPTIONS+=(SYSTEM "Monitoring & Configuration") @@ -226,8 +253,11 @@ case $CHOICE in exit 0 fi ;; - LIGHTNING) - /home/admin/99lightningMenu.sh + LND) + /home/admin/99lndMenu.sh + ;; + CLN) + /home/admin/99clnMenu.sh ${chain}net ;; CONNECT) /home/admin/99connectMenu.sh @@ -298,6 +328,12 @@ case $CHOICE in ;; CIRCUIT) sudo /home/admin/config.scripts/bonus.circuitbreaker.sh menu + ;; + TESTNET) + /home/admin/00parallelChainsMenu.sh testnet + ;; + MAINNET) + /home/admin/00parallelChainsMenu.sh mainnet ;; SUBSCRIBE) /home/admin/config.scripts/blitz.subscriptions.py diff --git a/home.admin/00parallelChainsMenu.sh b/home.admin/00parallelChainsMenu.sh new file mode 100644 index 000000000..9a1bbdbe2 --- /dev/null +++ b/home.admin/00parallelChainsMenu.sh @@ -0,0 +1,191 @@ +#!/bin/bash + +# Usage: +# 00parallelChainsMenu.sh + +source /home/admin/raspiblitz.info +# add default value to raspi config if needed +if ! grep -Eq "^testnet=" /mnt/hdd/raspiblitz.conf; then + echo "testnet=off" >> /mnt/hdd/raspiblitz.conf +fi +if ! grep -Eq "^LNdefault=" /mnt/hdd/raspiblitz.conf; then + echo "LNdefault=lnd" >> /mnt/hdd/raspiblitz.conf +fi +source /mnt/hdd/raspiblitz.conf + +# CHAIN is signet | testnet | mainnet +if [ $# -gt 0 ] && [ $1 != ${chain}net ];then + nonDefaultChain=1 + CHAIN=$1 +else + nonDefaultChain=0 + CHAIN=${chain}net +fi + +# LNTYPE is lnd | cln +if [ $# -gt 1 ]&&[ $2 != $LNdefault ];then + nonDefaultLNtype=1 + LNTYPE=$2 +else + nonDefaultLNtype=0 + LNTYPE=$LNdefault +fi + +# get the local network IP to be displayed on the LCD +source <(/home/admin/config.scripts/internet.sh status local) + +# BASIC MENU INFO +HEIGHT=10 +WIDTH=64 +CHOICE_HEIGHT=3 +BACKTITLE="${CHAIN} options" +TITLE="" +MENU="Choose one of the following options:" +OPTIONS=() +plus="" + +if [ "${runBehindTor}" = "on" ]; then + plus=" / TOR" +fi +if [ ${#dynDomain} -gt 0 ]; then + plus="${plus} / ${dynDomain}" +fi +BACKTITLE="${localip} / ${hostname} / ${network} / ${chain}${plus}" + +# Put Activated Apps on top +if [ $chain = test ]&&[ "$trtlWebinterface" = "on" ]||\ + [ $chain = sig ]&& [ "$srtlWebinterface" = "on" ]||\ + [ $chain = main ]&&[ "$rtlWebinterface" = "on" ]; then + OPTIONS+=(RTL "RTL Web Node Manager for LND ${CHAIN}") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +if [ $chain = test ]&&[ "$tlnd" = "on" ]||\ + [ $chain = sig ]&& [ "$slnd" = "on" ]||\ + [ $chain = main ]&&[ "$lnd" = "on" ]; then + #TODO OPTIONS+=(LND "LND options for ${CHAIN}") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +if [ "$chain" = "test" ]&&[ "$tcrtlWebinterface" = "on" ]||\ + [ "$chain" = "sig" ]&& [ "$scrtlWebinterface" = "on" ]||\ + [ "$chain" = "main" ]&&[ "$crtlWebinterface" = "on" ]; then + OPTIONS+=(cRTL "RTL Web Node Manager for C-lightning ${CHAIN}") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +if [ "$chain" = "test" ]&&[ "$tcln" = "on" ]||\ + [ "$chain" = "sig" ]&& [ "$scln" = "on" ]||\ + [ "$chain" = "main" ]&&[ "$cln" = "on" ]; then + OPTIONS+=(CLN "C-lightning options for ${CHAIN}") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +OPTIONS+=(INFO "RaspiBlitz Status Screen for ${CHAIN}") + +if [ "$testnet" == "on" ]; then +OPTIONS+=(SERVICES "Additional Apps & Services on ${CHAIN}") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi +#TODO OPTIONS+=(SYSTEM "Monitoring & Configuration") +#TODO OPTIONS+=(CONNECT "Connect Apps & Show Credentials") + +if [ $nonDefaultLNtype = 1 ];then + OPTIONS+=(SWITCHLN "Make ${LNTYPE} the default lightning wallet") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +if [ $nonDefaultChain = 1 ];then + OPTIONS+=(MKDEFAULT "Make ${CHAIN} the default chain") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +CHOICE=$(dialog --clear \ + --backtitle "$BACKTITLE" \ + --title "$TITLE" \ + --ok-label "Select" \ + --cancel-label "Back" \ + --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT \ + "${OPTIONS[@]}" \ + 2>&1 >/dev/tty) + +case $CHOICE in + INFO) + # #TODO + # echo "Gathering Information (please wait) ..." + # walletLocked=$(lncli getinfo 2>&1 | grep -c "Wallet is encrypted") + # if [ ${walletLocked} -eq 0 ]; then + # while : + # do + # # show the same info as on LCD screen + # /home/admin/00infoBlitz.sh + # # wait 6 seconds for user exiting loop + # echo "" + # echo -en "Screen is updating in a loop .... press 'x' now to get back to menu." + # read -n 1 -t 6 keyPressed + # echo -en "\rGathering information to update info ... please wait. \n" + # # check if user wants to abort session + # if [ "${keyPressed}" = "x" ]; then + # echo "" + # echo "Returning to menu ....." + # sleep 4 + # break + # fi + # done + # else + # /home/admin/00raspiblitz.sh + # exit 0 + # fi + /home/admin/00infoBlitz.sh $CHAIN + ;; + RTL) + /home/admin/config.scripts/bonus.rtl.sh menu lnd $CHAIN + ;; + cRTL) + /home/admin/config.scripts/bonus.rtl.sh menu cln $CHAIN + ;; + LND) + /home/admin/99lndMenu.sh $CHAIN + ;; + CLN) + /home/admin/99clnMenu.sh $CHAIN + ;; + SERVICES) + if [ $CHAIN = testnet ];then + /home/admin/00parallelTestnetServices.sh + elif [ $CHAIN = mainnet ];then + /home/admin/00parallelMainnetServices.sh $CHAIN + fi + ;; + SYSTEM) + /home/admin/99systemMenu.sh $CHAIN + ;; + CONNECT) + /home/admin/99connectMenu.sh $CHAIN + ;; + SWITCHLN) + # setting value in raspi blitz config + sudo sed -i "s/^LNdefault=.*/LNdefault=$LNTYPE/g" /mnt/hdd/raspiblitz.conf + echo "# OK - Set LNdefault=$LNTYPE in /mnt/hdd/raspiblitz.conf" + echo + echo "Press ENTER to return to main menu." + ;; + MKDEFAULT) + # setting value in raspi blitz config + newchain=${CHAIN::-3} + sudo sed -i "s/^chain=.*/chain=${newchain}/g" /mnt/hdd/raspiblitz.conf + echo "# OK - Set chain=${newchain} in /mnt/hdd/raspiblitz.conf" + sudo /home/admin/config.scripts/lnd.credentials.sh sync + echo + echo "Press ENTER to return to main menu." + read key + ;; +esac \ No newline at end of file diff --git a/home.admin/00parallelMainnetServices.sh b/home.admin/00parallelMainnetServices.sh new file mode 100644 index 000000000..31eca3b25 --- /dev/null +++ b/home.admin/00parallelMainnetServices.sh @@ -0,0 +1,179 @@ +#!/bin/bash + +# get raspiblitz config +echo "get raspiblitz config" +source /home/admin/raspiblitz.info +source /mnt/hdd/raspiblitz.conf + +CHAIN=mainnet + +# for testnet +echo "services default values" +if [ ${#rtlWebinterface} -eq 0 ]; then rtlWebinterface="off"; fi +if [ ${#lnd} -eq 0 ]; then lnd="off"; fi +if [ ${#cln} -eq 0 ]; then cln="off"; fi +if [ ${#crtlWebinterface} -eq 0 ]; then crtlWebinterface="off"; fi +if [ ${#sparko} -eq 0 ]; then sparko="off"; fi + +# show select dialog +echo "run dialog ..." + +OPTIONS=() +OPTIONS+=(l "LND on $CHAIN" ${lnd}) +OPTIONS+=(r "RTL for LND $CHAIN" ${rtlWebinterface}) +OPTIONS+=(c "C-lightning on $CHAIN" ${cln}) +OPTIONS+=(t "RTL for CLN on $CHAIN" ${crtlWebinterface}) +OPTIONS+=(s "Sparko for CLN on $CHAIN" ${sparko}) + +CHOICES=$(dialog --title ' Additional Services ' \ + --checklist ' use spacebar to activate/de-activate ' \ + 11 45 4 "${OPTIONS[@]}" 2>&1 >/dev/tty) + +dialogcancel=$? +echo "done dialog" +clear + +# check if user canceled dialog +echo "dialogcancel(${dialogcancel})" +if [ ${dialogcancel} -eq 1 ]; then + echo "user canceled" + exit 1 +elif [ ${dialogcancel} -eq 255 ]; then + echo "ESC pressed" + exit 1 +fi + +needsReboot=0 +anychange=0 + +# lnd process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "l") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${lnd}" != "${choice}" ]; then + echo "# LND on $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/lnd.chain.sh ${choice} $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + echo "# Successfully installed LND on $CHAIN" + else + l1="# !!! FAIL on LND on $CHAIN install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/lnd.chain.sh on $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# LND on $CHAIN Setting unchanged." +fi + +# cln process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "c") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${cln}" != "${choice}" ]; then + echo "# CLN on $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/cln.install.sh ${choice} $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + echo "# Successfully installed CLN on $CHAIN" + else + l1="# !!! FAIL on CLN on $CHAIN install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/cln.install.sh on $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# CLN on $CHAIN Setting unchanged." +fi + +# RTL process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "r") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${rtlWebinterface}" != "${choice}" ]; then + echo "# RTL for LND $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/bonus.rtl.sh ${choice} lnd $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + sudo systemctl start RTL + echo "# waiting 10 secs .." + sleep 10 + /home/admin/config.scripts/bonus.rtl.sh menu lnd $CHAIN + else + l1="# !!! FAIL on RTL for LND $CHAIN install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/bonus.rtl.sh on lnd $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# RTL for LND $CHAIN Setting unchanged." +fi + +# cRTL process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "t") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${crtlWebinterface}" != "${choice}" ]; then + echo "RTL for CLN $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/bonus.rtl.sh ${choice} cln $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + sudo systemctl start cRTL + echo "waiting 10 secs .." + sleep 10 + /home/admin/config.scripts/bonus.rtl.sh menu lnd $CHAIN + else + l1="!!! FAIL on RTL for CLN $CHAIN install !!!" + l2="Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/bonus.rtl.sh on cln $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "RTL for CLN $CHAIN Setting unchanged." +fi + +# sparko process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "s") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${sparko}" != "${choice}" ]; then + echo "# Sparko on $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/cln.sparko.sh ${choice} $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + /home/admin/config.scripts/cln.sparko.sh menu $CHAIN + else + l1="# !!! FAIL on Sparko on $CHAIN install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/cln.sparko.sh on $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# Sparko on $CHAIN Setting unchanged." +fi + +if [ ${anychange} -eq 0 ]; then + dialog --msgbox "NOTHING CHANGED!\nUse Spacebar to check/uncheck services." 8 58 + exit 0 +fi + +if [ ${needsReboot} -eq 1 ]; then + sleep 2 + dialog --pause "OK. System will reboot to activate changes." 8 58 8 + clear + echo "rebooting .. (please wait)" + # stop bitcoind + sudo -u bitcoin ${network}-cli stop + sleep 4 + sudo /home/admin/XXshutdown.sh reboot +fi \ No newline at end of file diff --git a/home.admin/00parallelTestnetServices.sh b/home.admin/00parallelTestnetServices.sh new file mode 100644 index 000000000..39dc35f3f --- /dev/null +++ b/home.admin/00parallelTestnetServices.sh @@ -0,0 +1,181 @@ +#!/bin/bash + +# get raspiblitz config +echo "get raspiblitz config" +source /home/admin/raspiblitz.info +source /mnt/hdd/raspiblitz.conf + +CHAIN=testnet + +# for testnet +echo "services default values" +if [ ${#trtlWebinterface} -eq 0 ]; then trtlWebinterface="off"; fi +if [ ${#tlnd} -eq 0 ]; then tlnd="off"; fi +if [ ${#tcrtlWebinterface} -eq 0 ]; then tcrtlWebinterface="off"; fi +if [ ${#tcln} -eq 0 ]; then tcln="off"; fi +if [ ${#tsparko} -eq 0 ]; then tsparko="off"; fi + +# show select dialog +echo "run dialog ..." + +OPTIONS=() +OPTIONS+=(l "LND on $CHAIN" ${tlnd}) +OPTIONS+=(r "RTL for LND $CHAIN" ${trtlWebinterface}) +OPTIONS+=(c "C-lightning on $CHAIN" ${tcln}) +OPTIONS+=(t "RTL for CLN on $CHAIN" ${tcrtlWebinterface}) +OPTIONS+=(s "Sparko for CLN on $CHAIN" ${tsparko}) + +CHOICES=$(dialog --title ' Additional Services ' \ + --checklist ' use spacebar to activate/de-activate ' \ + 11 45 4 "${OPTIONS[@]}" 2>&1 >/dev/tty) + +dialogcancel=$? +echo "done dialog" +clear + +# check if user canceled dialog +echo "dialogcancel(${dialogcancel})" +if [ ${dialogcancel} -eq 1 ]; then + echo "user canceled" + exit 1 +elif [ ${dialogcancel} -eq 255 ]; then + echo "ESC pressed" + exit 1 +fi + +needsReboot=0 +anychange=0 + +# tlnd process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "l") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${tlnd}" != "${choice}" ]; then + echo "# LND on $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/lnd.chain.sh ${choice} $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + echo "# Successfully installed LND on $CHAIN" + else + l1="# !!! FAIL on LND on $CHAIN install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/lnd.chain.sh on $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# LND on $CHAIN Setting unchanged." +fi + +# tcln process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "c") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${tcln}" != "${choice}" ]; then + echo "# CLN on $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/cln.install.sh ${choice} $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + echo "# Successfully installed CLN on $CHAIN" + else + l1="# !!! FAIL on CLN on $CHAIN install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/cln.install.sh on $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# CLN on $CHAIN Setting unchanged." +fi + +# tRTL process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "r") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${trtlWebinterface}" != "${choice}" ]; then + echo "# RTL for LND $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/bonus.rtl.sh ${choice} lnd $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + sudo systemctl start tRTL + echo "# waiting 10 secs .." + sleep 10 + /home/admin/config.scripts/bonus.rtl.sh menu lnd $CHAIN + else + l1="# !!! FAIL on RTL for LND $CHAIN install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/bonus.rtl.sh on lnd $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# RTL for LND $CHAIN Setting unchanged." +fi + +# ctRTL process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "t") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${tcrtlWebinterface}" != "${choice}" ]; then + echo "RTL for CLN $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/bonus.rtl.sh ${choice} cln $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + sudo systemctl start tcRTL + echo "waiting 10 secs .." + sleep 10 + /home/admin/config.scripts/bonus.rtl.sh menu lnd $CHAIN + else + l1="!!! FAIL on RTL for CLN $CHAIN install !!!" + l2="Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/bonus.rtl.sh on cln $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "RTL for CLN $CHAIN Setting unchanged." +fi + +# tsparko process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "s") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${tsparko}" != "${choice}" ]; then + echo "# Sparko on $CHAIN Setting changed .." + anychange=1 + /home/admin/config.scripts/cln.sparko.sh ${choice} $CHAIN + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + /home/admin/config.scripts/cln.sparko.sh menu $CHAIN + else + l1="# !!! FAIL on Sparko on $CHAIN install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/cln.sparko.sh on $CHAIN" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# Sparko on $CHAIN Setting unchanged." +fi + + + +if [ ${anychange} -eq 0 ]; then + dialog --msgbox "NOTHING CHANGED!\nUse Spacebar to check/uncheck services." 8 58 + exit 0 +fi + +if [ ${needsReboot} -eq 1 ]; then + sleep 2 + dialog --pause "OK. System will reboot to activate changes." 8 58 8 + clear + echo "rebooting .. (please wait)" + # stop bitcoind + sudo -u bitcoin ${network}-cli stop + sleep 4 + sudo /home/admin/XXshutdown.sh reboot +fi \ No newline at end of file diff --git a/home.admin/00raspiblitz.sh b/home.admin/00raspiblitz.sh index 35894d924..ade86205b 100755 --- a/home.admin/00raspiblitz.sh +++ b/home.admin/00raspiblitz.sh @@ -313,6 +313,11 @@ if [ "${state}" = "ready" ]; then if [ ${configExists} -eq 1 ]; then echo "loading config data" source ${configFile} + source <(/home/admin/config.scripts/network.aliases.sh getvars lnd ${chain}net) + shopt -s expand_aliases + alias bitcoincli_alias="$bitcoincli_alias" + alias lncli_alias="$lncli_alias" + alias lightningcli_alias="$lightningcli_alias" else echo "setup still in progress - setupStep(${setupStep})" fi @@ -339,8 +344,8 @@ waitUntilChainNetworkIsReady() echo "can take longer if device was off or first time" # check for error on network - sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp - clienterror=`cat error.tmp` + bitcoincli_alias getblockchaininfo 1>/dev/null 2>error.tmp + clienterror=$(cat error.tmp) rm error.tmp # check for missing blockchain data @@ -438,7 +443,7 @@ How do you want to continue? while : 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 uptime=$(awk '{printf("%d\n",$1 + 0.5)}' /proc/uptime) if [ "${autoUnlock}" == "on" ] && [ ${uptime} -lt 300 ]; then @@ -461,7 +466,7 @@ How do you want to continue? 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 /home/admin/80scanLND.sh if [ $? -gt 0 ]; then diff --git a/home.admin/00settingsMenuBasics.sh b/home.admin/00settingsMenuBasics.sh index 9715dce11..03e38bfca 100755 --- a/home.admin/00settingsMenuBasics.sh +++ b/home.admin/00settingsMenuBasics.sh @@ -85,7 +85,7 @@ if [ "${displayClass}" == "lcd" ]; then fi OPTIONS+=(a 'Channel Autopilot' ${autoPilot}) OPTIONS+=(k 'Accept Keysend' ${keysend}) -OPTIONS+=(n 'Testnet' ${chainValue}) +# OPTIONS+=(n 'Testnet' ${chainValue}) #TODO remove related code OPTIONS+=(c 'Circuitbreaker (LND firewall)' ${circuitbreaker}) OPTIONS+=(u 'LND Auto-Unlock' ${autoUnlock}) OPTIONS+=(d 'StaticChannelBackup on DropBox' ${DropboxBackup}) diff --git a/home.admin/00settingsMenuServices.sh b/home.admin/00settingsMenuServices.sh index 33229a891..7e94031bc 100755 --- a/home.admin/00settingsMenuServices.sh +++ b/home.admin/00settingsMenuServices.sh @@ -23,6 +23,8 @@ if [ ${#sphinxrelay} -eq 0 ]; then sphinxrelay="off"; fi if [ ${#lit} -eq 0 ]; then lit="off"; fi if [ ${#whitepaper} -eq 0 ]; then whitepaper="off"; fi if [ ${#chantools} -eq 0 ]; then chantools="off"; fi +if [ ${#testnet} -eq 0 ]; then testnet="off"; fi +if [ ${#cln} -eq 0 ]; then cln="off"; fi # show select dialog echo "run dialog ..." @@ -43,10 +45,12 @@ OPTIONS+=(x 'Sphinx-Relay' ${sphinxrelay}) OPTIONS+=(y 'PyBLOCK' ${pyblock}) OPTIONS+=(c 'ChannelTools (Fund Rescue)' ${chantools}) OPTIONS+=(w 'Download Bitcoin Whitepaper' ${whitepaper}) +OPTIONS+=(n 'Parallel Testnet services' ${testnet}) +OPTIONS+=(c 'C-lightning' ${cln}) CHOICES=$(dialog --title ' Additional Services ' \ --checklist ' use spacebar to activate/de-activate ' \ - 22 45 15 "${OPTIONS[@]}" 2>&1 >/dev/tty) + 24 45 17 "${OPTIONS[@]}" 2>&1 >/dev/tty) dialogcancel=$? echo "done dialog" @@ -432,6 +436,56 @@ else echo "Whitepaper setting unchanged." fi +# testnet process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "n") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${testnet}" != "${choice}" ]; then + echo "# Testnet Setting changed .." + anychange=1 + /home/admin/config.scripts/bitcoin.chains.sh ${choice} testnet + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + echo "# Successfully installed Testnet" + echo + echo "# Press ENTER to continue ..." + read key + else + l1="# !!! FAIL on Testnet install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/bitcoin.chains.sh on testnet" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# Testnet Setting unchanged." +fi + +# cln process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "c") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${cln}" != "${choice}" ]; then + echo "# C-lightning Setting changed .." + anychange=1 + /home/admin/config.scripts/cln.install.sh ${choice} + errorOnInstall=$? + if [ "${choice}" = "on" ]; then + if [ ${errorOnInstall} -eq 0 ]; then + echo "# Successfully installed C-lightning" + echo + echo "# Press ENTER to continue ..." + read key + else + l1="# !!! FAIL on C-lightning install !!!" + l2="# Try manual install on terminal after reboot with:" + l3="/home/admin/config.scripts/cln.install.sh on" + dialog --title 'FAIL' --msgbox "${l1}\n${l2}\n${l3}" 7 65 + fi + fi +else + echo "# C-lightning Setting unchanged." +fi + if [ ${anychange} -eq 0 ]; then dialog --msgbox "NOTHING CHANGED!\nUse Spacebar to check/uncheck services." 8 58 exit 0 diff --git a/home.admin/99clnMenu.sh b/home.admin/99clnMenu.sh new file mode 100644 index 000000000..ff9aff7cc --- /dev/null +++ b/home.admin/99clnMenu.sh @@ -0,0 +1,137 @@ +#!/bin/bash + +# get raspiblitz config +echo "# get raspiblitz config" +source /home/admin/raspiblitz.info +source /mnt/hdd/raspiblitz.conf + +if [ $# -gt 0 ];then + NETWORK=$1 +else + NETWORK=${chain}net +fi + +# get the local network IP to be displayed on the LCD +source <(/home/admin/config.scripts/internet.sh status local) + +# BASIC MENU INFO +HEIGHT=13 +WIDTH=64 +CHOICE_HEIGHT=7 +BACKTITLE="RaspiBlitz" +TITLE="C-Lightning Options" +MENU="" +OPTIONS=() + +OPTIONS+=(FUNDING "Fund your C-Lightning Wallet") +OPTIONS+=(PEERING "Connect to a Peer") +OPTIONS+=(CHANNEL "Open a Channel with Peer") +OPTIONS+=(SEND "Pay an Invoice/PaymentRequest") +OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest") + +if [ "${chain}" = "main" ]; then +#TODO OPTIONS+=(lnbalance "Detailed Wallet Balances") +#TODO OPTIONS+=(lnchannels "Lightning Channel List") +#TODO OPTIONS+=(lnfwdreport "Lightning Forwarding Events Report") + HEIGHT=$((HEIGHT+3)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+3)) +fi + +#TODO 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') +if [ ${#openChannels} -gt 0 ] && [ ${openChannels} -gt 0 ]; then +#TODO OPTIONS+=(CLOSEALL "Close all open Channels") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi +if [ ${#LNdefault} -gt 0 ]&&[ $LNdefault = lnd ];then + OPTIONS+=(SWITCHLN "Use C-lightning as default") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +#TODO OPTIONS+=(CASHOUT "Remove Funds from LND") + +CHOICE=$(dialog --clear \ + --backtitle "$BACKTITLE" \ + --title "$TITLE" \ + --ok-label "Select" \ + --cancel-label "Main menu" \ + --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT \ + "${OPTIONS[@]}" \ + 2>&1 >/dev/tty) + +case $CHOICE in + lnbalance) + clear + echo "*** YOUR SATOSHI BALANCES ***" + /home/admin/config.scripts/lnd.balance.sh ${network} + echo "Press ENTER to return to main menu." + read key + ;; + lnchannels) + clear + echo "*** YOUR LIGHTNING CHANNELS ***" + echo "" + echo "Capacity -> total sats in the channel (their side + your side)" + echo "Commit-Fee -> the fee that's charged if either side of the channel closes" + echo "Balance-Local -> sats on your side of the channel (outbound liquidity)" + echo "Balance-Remote -> sats on their side of the channel (inbound liquidity)" + echo "Fee-Base -> fixed fee (in millisatoshis) per forwarding on channel" + echo "Fee-PerMil -> amount based fee (millisatoshis per 1 satoshi) on forwarding" + /home/admin/config.scripts/lnd.channels.sh ${network} + echo "Press ENTER to return to main menu." + read key + ;; + lnfwdreport) + /home/admin/config.scripts/lnd.fwdreport.sh -menu + echo "Press ENTER to return to main menu." + read key + ;; + PEERING) + /home/admin/BBconnectPeer.sh cln $NETWORK + ;; + FUNDING) + /home/admin/BBfundWallet.sh cln $NETWORK + ;; + CASHOUT) + /home/admin/BBcashoutWallet.sh + ;; + CHANNEL) + /home/admin/BBopenChannel.sh cln $NETWORK + ;; + SEND) + /home/admin/BBpayInvoice.sh cln $NETWORK + ;; + RECEIVE) + /home/admin/BBcreateInvoice.sh cln $NETWORK + ;; + NAME) + sudo /home/admin/config.scripts/lnd.setname.sh + noreboot=$? + if [ "${noreboot}" = "0" ]; then + sudo -u bitcoin ${network}-cli stop + echo "Press ENTER to Reboot." + read key + sudo /home/admin/XXshutdown.sh reboot + exit 0 + fi + ;; + CLOSEALL) + /home/admin/BBcloseAllChannels.sh + echo "Press ENTER to return to main menu." + read key + ;; + SWITCHLN) + clear + echo + # setting value in raspi blitz config + sudo sed -i "s/^LNdefault=.*/LNdefault=cln/g" /mnt/hdd/raspiblitz.conf + echo "# OK - LNdefault=cln is set in /mnt/hdd/raspiblitz.conf" + echo + echo "Press ENTER to return to main menu." + read key + ;; +esac diff --git a/home.admin/99connectMenu.sh b/home.admin/99connectMenu.sh index 1c619af6a..1d40d696a 100644 --- a/home.admin/99connectMenu.sh +++ b/home.admin/99connectMenu.sh @@ -171,7 +171,7 @@ HiddenServicePort 8333 127.0.0.1:8333" | sudo tee -a /etc/tor/torrc localIP=$(ip addr | grep 'state UP' -A2 | grep -E -v 'docker0|veth' |\ grep 'eth0\|wlan0\|enp0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/') allowIPrange=$(grep -c "rpcallowip=$localIPrange" < /mnt/hdd/${network}/${network}.conf) - bindIP=$(grep -c "rpcbind=$localIP" < /mnt/hdd/${network}/${network}.conf) + bindIP=$(grep -c "${chain}.rpcbind=$localIP" < /mnt/hdd/${network}/${network}.conf) rpcTorService=$(grep -c "HiddenServicePort ${BITCOINRPCPORT} 127.0.0.1:${BITCOINRPCPORT}" < /etc/tor/torrc) TorRPCaddress=$(sudo cat /mnt/hdd/tor/bitcoin${BITCOINRPCPORT}/hostname) @@ -239,7 +239,7 @@ HiddenServicePort 8333 127.0.0.1:8333" | sudo tee -a /etc/tor/torrc restartCore=1 fi if [ $bindIP -eq 0 ]; then - echo "rpcbind=$localIP" | sudo tee -a /mnt/hdd/${network}/${network}.conf + echo "${chain}.rpcbind=$localIP" | sudo tee -a /mnt/hdd/${network}/${network}.conf restartCore=1 fi if [ $restartCore = 1 ];then @@ -286,7 +286,7 @@ HiddenServicePort 8333 127.0.0.1:8333" | sudo tee -a /etc/tor/torrc restartCore=1 fi if [ $bindIP -gt 0 ]; then - sudo sed -i "/^rpcbind=$localIP/d" /mnt/hdd/${network}/${network}.conf + sudo sed -i "/^${chain}.rpcbind=$localIP/d" /mnt/hdd/${network}/${network}.conf restartCore=1 fi if [ $restartCore = 1 ];then diff --git a/home.admin/99lightningMenu.sh b/home.admin/99lightningMenu.sh deleted file mode 100644 index 63ea9d920..000000000 --- a/home.admin/99lightningMenu.sh +++ /dev/null @@ -1,116 +0,0 @@ -#!/bin/bash - -# get raspiblitz config -echo "get raspiblitz config" -source /home/admin/raspiblitz.info -source /mnt/hdd/raspiblitz.conf - -# get the local network IP to be displayed on the LCD -source <(/home/admin/config.scripts/internet.sh status local) - -# BASIC MENU INFO -HEIGHT=13 -WIDTH=64 -CHOICE_HEIGHT=7 -BACKTITLE="RaspiBlitz" -TITLE="Lightning Options" -MENU="" -OPTIONS=() - -OPTIONS+=(FUNDING "Fund your LND Wallet") -OPTIONS+=(PEERING "Connect to a Peer") -OPTIONS+=(CHANNEL "Open a Channel with Peer") -OPTIONS+=(SEND "Pay an Invoice/PaymentRequest") -OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest") - -if [ "${chain}" = "main" ]; then - OPTIONS+=(lnbalance "Detailed Wallet Balances") - OPTIONS+=(lnchannels "Lightning Channel List") - OPTIONS+=(lnfwdreport "Lightning Forwarding Events Report") - HEIGHT=$((HEIGHT+3)) - CHOICE_HEIGHT=$((CHOICE_HEIGHT+3)) -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') -if [ ${#openChannels} -gt 0 ] && [ ${openChannels} -gt 0 ]; then - OPTIONS+=(CLOSEALL "Close all open Channels") - HEIGHT=$((HEIGHT+1)) - CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) -fi - -OPTIONS+=(CASHOUT "Remove Funds from LND") - -CHOICE=$(dialog --clear \ - --backtitle "$BACKTITLE" \ - --title "$TITLE" \ - --ok-label "Select" \ - --cancel-label "Main menu" \ - --menu "$MENU" \ - $HEIGHT $WIDTH $CHOICE_HEIGHT \ - "${OPTIONS[@]}" \ - 2>&1 >/dev/tty) - -case $CHOICE in - lnbalance) - clear - echo "*** YOUR SATOSHI BALANCES ***" - /home/admin/config.scripts/lnd.balance.sh ${network} - echo "Press ENTER to return to main menu." - read key - ;; - lnchannels) - clear - echo "*** YOUR LIGHTNING CHANNELS ***" - echo "" - echo "Capacity -> total sats in the channel (their side + your side)" - echo "Commit-Fee -> the fee that's charged if either side of the channel closes" - echo "Balance-Local -> sats on your side of the channel (outbound liquidity)" - echo "Balance-Remote -> sats on their side of the channel (inbound liquidity)" - echo "Fee-Base -> fixed fee (in millisatoshis) per forwarding on channel" - echo "Fee-PerMil -> amount based fee (millisatoshis per 1 satoshi) on forwarding" - /home/admin/config.scripts/lnd.channels.sh ${network} - echo "Press ENTER to return to main menu." - read key - ;; - lnfwdreport) - /home/admin/config.scripts/lnd.fwdreport.sh -menu - echo "Press ENTER to return to main menu." - read key - ;; - PEERING) - /home/admin/BBconnectPeer.sh - ;; - FUNDING) - /home/admin/BBfundWallet.sh - ;; - CASHOUT) - /home/admin/BBcashoutWallet.sh - ;; - CHANNEL) - /home/admin/BBopenChannel.sh - ;; - SEND) - /home/admin/BBpayInvoice.sh - ;; - RECEIVE) - /home/admin/BBcreateInvoice.sh - ;; - NAME) - sudo /home/admin/config.scripts/lnd.setname.sh - noreboot=$? - if [ "${noreboot}" = "0" ]; then - sudo -u bitcoin ${network}-cli stop - echo "Press ENTER to Reboot." - read key - sudo /home/admin/XXshutdown.sh reboot - exit 0 - fi - ;; - CLOSEALL) - /home/admin/BBcloseAllChannels.sh - echo "Press ENTER to return to main menu." - read key - ;; -esac diff --git a/home.admin/99lndMenu.sh b/home.admin/99lndMenu.sh new file mode 100644 index 000000000..c8acf4c44 --- /dev/null +++ b/home.admin/99lndMenu.sh @@ -0,0 +1,131 @@ +#!/bin/bash + +# get raspiblitz config +echo "get raspiblitz config" +source /home/admin/raspiblitz.info +source /mnt/hdd/raspiblitz.conf + +# get the local network IP to be displayed on the LCD +source <(/home/admin/config.scripts/internet.sh status local) + +# BASIC MENU INFO +HEIGHT=13 +WIDTH=64 +CHOICE_HEIGHT=7 +BACKTITLE="RaspiBlitz" +TITLE="Lightning Options" +MENU="" +OPTIONS=() + +OPTIONS+=(FUNDING "Fund your LND Wallet") +OPTIONS+=(PEERING "Connect to a Peer") +OPTIONS+=(CHANNEL "Open a Channel with Peer") +OPTIONS+=(SEND "Pay an Invoice/PaymentRequest") +OPTIONS+=(RECEIVE "Create Invoice/PaymentRequest") + +if [ "${chain}" = "main" ]; then + OPTIONS+=(lnbalance "Detailed Wallet Balances") + OPTIONS+=(lnchannels "Lightning Channel List") + OPTIONS+=(lnfwdreport "Lightning Forwarding Events Report") + HEIGHT=$((HEIGHT+3)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+3)) +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') +if [ ${#openChannels} -gt 0 ] && [ ${openChannels} -gt 0 ]; then + OPTIONS+=(CLOSEALL "Close all open Channels") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +OPTIONS+=(CASHOUT "Remove Funds from LND") +if [ ${#LNdefault} -gt 0 ]&&[ $LNdefault = cln ];then + OPTIONS+=(SWITCHLN "Use LND as default") + HEIGHT=$((HEIGHT+1)) + CHOICE_HEIGHT=$((CHOICE_HEIGHT+1)) +fi + +CHOICE=$(dialog --clear \ + --backtitle "$BACKTITLE" \ + --title "$TITLE" \ + --ok-label "Select" \ + --cancel-label "Main menu" \ + --menu "$MENU" \ + $HEIGHT $WIDTH $CHOICE_HEIGHT \ + "${OPTIONS[@]}" \ + 2>&1 >/dev/tty) + +case $CHOICE in + lnbalance) + clear + echo "*** YOUR SATOSHI BALANCES ***" + /home/admin/config.scripts/lnd.balance.sh ${network} + echo "Press ENTER to return to main menu." + read key + ;; + lnchannels) + clear + echo "*** YOUR LIGHTNING CHANNELS ***" + echo "" + echo "Capacity -> total sats in the channel (their side + your side)" + echo "Commit-Fee -> the fee that's charged if either side of the channel closes" + echo "Balance-Local -> sats on your side of the channel (outbound liquidity)" + echo "Balance-Remote -> sats on their side of the channel (inbound liquidity)" + echo "Fee-Base -> fixed fee (in millisatoshis) per forwarding on channel" + echo "Fee-PerMil -> amount based fee (millisatoshis per 1 satoshi) on forwarding" + /home/admin/config.scripts/lnd.channels.sh ${network} + echo "Press ENTER to return to main menu." + read key + ;; + lnfwdreport) + /home/admin/config.scripts/lnd.fwdreport.sh -menu + echo "Press ENTER to return to main menu." + read key + ;; + PEERING) + /home/admin/BBconnectPeer.sh + ;; + FUNDING) + /home/admin/BBfundWallet.sh + ;; + CASHOUT) + /home/admin/BBcashoutWallet.sh + ;; + CHANNEL) + /home/admin/BBopenChannel.sh + ;; + SEND) + /home/admin/BBpayInvoice.sh + ;; + RECEIVE) + /home/admin/BBcreateInvoice.sh + ;; + NAME) + sudo /home/admin/config.scripts/lnd.setname.sh + noreboot=$? + if [ "${noreboot}" = "0" ]; then + sudo -u bitcoin ${network}-cli stop + echo "Press ENTER to Reboot." + read key + sudo /home/admin/XXshutdown.sh reboot + exit 0 + fi + ;; + CLOSEALL) + /home/admin/BBcloseAllChannels.sh + echo "Press ENTER to return to main menu." + read key + ;; + SWITCHLN) + clear + echo + # setting value in raspi blitz config + sudo sed -i "s/^LNdefault=.*/LNdefault=lnd/g" /mnt/hdd/raspiblitz.conf + echo "# OK - LNdefault=lnd is set in /mnt/hdd/raspiblitz.conf" + echo + echo "Press ENTER to return to main menu." + read key + ;; +esac diff --git a/home.admin/BBconnectPeer.sh b/home.admin/BBconnectPeer.sh index 96ece91e9..1c8cad05d 100755 --- a/home.admin/BBconnectPeer.sh +++ b/home.admin/BBconnectPeer.sh @@ -12,7 +12,13 @@ if [ ${#chain} -eq 0 ]; then chain=$(${network}-cli getblockchaininfo | jq -r '.chain') fi -# set ntwork map info +source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) +shopt -s expand_aliases +alias bitcoincli_alias="$bitcoincli_alias" +alias lncli_alias="$lncli_alias" +alias lightningcli_alias="$lightningcli_alias" + +# set network map info networkMap="https://lnmainnet.gaben.win" if [ "$network" = "litecoin" ]; then networkMap="https://lnexplorer.hcwong.me" @@ -22,9 +28,14 @@ if [ "$chain" = "test" ]; then fi # let user enter a @host + l1="Enter the node pubkey address with host information:" l2="example -----> 024ddf33[...]1f5f9f3@91.65.1.38:9735" -l3="node directory -> 1ml.com" +if [ "$chain" = "main" ]; then + l3="node directory -> https://1ml.com" +elif [ "$chain" = "test" ]; then + l3="node directory -> https://1ml.com/testnet" +fi dialog --title "Open a Connection to a Peer" \ --backtitle "Lightning ( ${network} | ${chain} )" \ --inputbox "$l1\n$l2\n$l3" 10 60 2>$_temp @@ -38,18 +49,26 @@ if [ ${#_input} -eq 0 ]; then exit 1 fi +pubkey=$(echo $_input|cut -d@ -f1) +address=$(echo ${_input}|cut -d@ -f2|cut -d: -f1) +port=$(echo ${_input}|cut -d: -f2) # build command -command="lncli --chain=${network} --network=${chain}net connect ${_input}" +if [ $LNTYPE = cln ];then + # connect id [host port] + command="$lightningcli_alias connect $pubkey $address $port" +elif [ $LNTYPE = lnd ];then + command="$lncli_alias connect ${pubkey}@${address}:${port}" +fi # info output clear echo "******************************" echo "Connect to A Lightning Node" echo "******************************" -echo "" +echo echo "COMMAND LINE: " echo $command -echo "" +echo echo "RESULT (might have to wait for timeout):" win=1 @@ -82,13 +101,13 @@ if [ ${#result} -eq 0 ]; then info="No return value. Error not known." # try to get error output - result=`cat ${_error}` + result=$(cat "${_error}") echo "$result" # basic cli error cliError=$(echo "${result}" | grep "[lncli]" -c ) if [ ${cliError} -gt 0 ]; then - info="Its possible that LND daemon is not running, not configured correct or not connected to the lncli." + info="It's possible that the lightning daemon is not running, not configured correct or not connected to the cli." fi else @@ -97,8 +116,11 @@ else echo "$result" # check if the node is now in peer list - pubkey=$(echo $_input | cut -d '@' -f1) - isPeer=$(lncli --chain=${network} --network=${chain}net listpeers 2>/dev/null| grep "${pubkey}" -c) + if [ $LNTYPE = cln ];then + isPeer=$($lightningcli_alias listpeers 2>/dev/null| grep "${pubkey}" -c) + elif [ $LNTYPE = lnd ];then + isPeer=$($lncli_alias listpeers 2>/dev/null| grep "${pubkey}" -c) + fi if [ ${isPeer} -eq 0 ]; then # basic error message @@ -114,14 +136,14 @@ else fi # output info -echo "" +echo if [ ${win} -eq 1 ]; then echo "******************************" echo "WIN" echo "******************************" echo "${info}" - echo "" - echo "Whats next? --> Open a channel with that node." + echo + echo "What's next? --> Open a channel with that node." else echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "FAIL" @@ -129,6 +151,6 @@ else echo "${info}" fi -echo "" +echo echo "Press ENTER to return to main menu." read key \ No newline at end of file diff --git a/home.admin/BBcreateInvoice.sh b/home.admin/BBcreateInvoice.sh index a291bf1a7..99fe93e16 100755 --- a/home.admin/BBcreateInvoice.sh +++ b/home.admin/BBcreateInvoice.sh @@ -14,16 +14,22 @@ if [ ${#chain} -eq 0 ]; then chain=$(${network}-cli getblockchaininfo | jq -r '.chain') fi +source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) +shopt -s expand_aliases +alias bitcoincli_alias="$bitcoincli_alias" +alias lncli_alias="$lncli_alias" +alias lightningcli_alias="$lightningcli_alias" + # Check if ready (chain in sync and channels open) -./XXchainInSync.sh $network $chain +./XXchainInSync.sh $network $chain $LNTYPE if [ $? != 0 ]; then exit 1 fi # let user enter the invoice -l1="Enter the AMOUNT IN SATOSHI of the invoice:" +l1="Enter the AMOUNT IN SATOSHIS to invoice:" l2="1 ${network} = 100 000 000 SAT" -dialog --title "Pay thru Lightning Network" \ +dialog --title "Request payment through Lightning" \ --inputbox "$l1\n$l2" 9 50 2>$_temp amount=$(cat $_temp | xargs | tr -dc '0-9') shred -u $_temp @@ -38,23 +44,30 @@ fi # TODO let user enter a description # build command -command="lncli --chain=${network} --network=${chain}net addinvoice ${amount}" +if [ $LNTYPE = cln ];then + label=$(date +%s) # seconds since 1970-01-01 00:00:00 UTC + # invoice msatoshi label description [expiry] [fallbacks] [preimage] [exposeprivatechannels] [cltv] + command="$lightningcli_alias invoice ${amount}sat $label ''" + # TODO warn about insufficient liquidity +elif [ $LNTYPE = lnd ];then + command="$lncli_alias addinvoice ${amount}" +fi # info output clear echo "******************************" echo "Create Invoice / Payment Request" echo "******************************" -echo "" +echo echo "COMMAND LINE: " echo $command -echo "" +echo echo "RESULT:" sleep 2 # execute command result=$($command 2>$_error) -error=`cat ${_error} 2>/dev/null` +error=$(cat ${_error} 2>/dev/null) #echo "result(${result})" #echo "error(${error})" @@ -65,9 +78,12 @@ if [ ${#error} -gt 0 ]; then echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" echo "${error}" else - - rhash=$(echo "$result" | grep r_hash | cut -d '"' -f4) - payReq=$(echo "$result" | grep payment_request | cut -d '"' -f4) + if [ $LNTYPE = cln ];then + payReq=$(echo "$result" | grep bolt11 | cut -d '"' -f4) + elif [ $LNTYPE = lnd ];then + rhash=$(echo "$result" | grep r_hash | cut -d '"' -f4) + payReq=$(echo "$result" | grep payment_request | cut -d '"' -f4) + fi /home/admin/config.scripts/blitz.display.sh qr "${payReq}" if [ $(sudo dpkg-query -l | grep "ii qrencode" | wc -l) = 0 ]; then @@ -86,19 +102,27 @@ else echo "${payReq}" echo echo "Monitoring the Incoming Payment with:" - echo "lncli --chain=${network} --network=${chain}net lookupinvoice ${rhash}" + if [ $LNTYPE = cln ];then + echo "$lightningcli_alias waitinvoice $label" + elif [ $LNTYPE = lnd ];then + echo "$lncli_alias lookupinvoice ${rhash}" + fi echo "Press x and hold to skip to menu." while : do - - result=$(lncli --chain=${network} --network=${chain}net lookupinvoice ${rhash}) - wasPayed=$(echo $result | grep -c '"settled": true') + if [ $LNTYPE = cln ];then + result=$($lightningcli_alias waitinvoice $label) + wasPayed=$(echo $result | grep -c 'paid') + elif [ $LNTYPE = lnd ];then + result=$($lncli_alias lookupinvoice ${rhash}) + wasPayed=$(echo $result | grep -c '"settled": true') + fi if [ ${wasPayed} -gt 0 ]; then echo echo $result echo - echo "Returning to menu - OK Invoice payed." + echo "OK the Invoice was paid - returning to menu." /home/admin/config.scripts/blitz.display.sh hide /home/admin/config.scripts/blitz.display.sh image /home/admin/raspiblitz/pictures/ok.png sleep 2 diff --git a/home.admin/BBfundWallet.sh b/home.admin/BBfundWallet.sh index 3425089a2..cd89162ab 100755 --- a/home.admin/BBfundWallet.sh +++ b/home.admin/BBfundWallet.sh @@ -11,28 +11,55 @@ if [ ${#chain} -eq 0 ]; then chain=$(${network}-cli getblockchaininfo | jq -r '.chain') fi +source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) +shopt -s expand_aliases +alias bitcoincli_alias="$bitcoincli_alias" +alias lncli_alias="$lncli_alias" +alias lightningcli_alias="$lightningcli_alias" + # PRECHECK) check if chain is in sync -chainOutSync=$(lncli --chain=${network} --network=${chain}net getinfo | grep '"synced_to_chain": false' -c) +if [ $LNTYPE = cln ];then + BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1) + CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight) + if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then + chainOutSync=0 + else + chainOutSync=1 + fi +elif [ $LNTYPE = lnd ];then + chainOutSync=$($lncli_alias getinfo | grep '"synced_to_chain": false' -c) +fi if [ ${chainOutSync} -eq 1 ]; then - echo "FAIL PRECHECK - lncli getinfo shows 'synced_to_chain': false - wait until chain is sync " - echo "" - echo "PRESS ENTER to return to menu" + if [ $LNTYPE = cln ];then + echo "# FAIL PRECHECK - lncli getinfo shows 'synced_to_chain': false - wait until chain is sync " + else + echo "# FAIL PRECHECK - 'lightning-cli getinfo' blockheight is different from 'bitcoind getblockchaininfo' - wait until chain is sync " + fi + echo + echo "# PRESS ENTER to return to menu" read key exit 1 +else + echo "# OK - the chain is synced" fi # execute command -echo "calling lncli ... please wait" -command="lncli --chain=${network} --network=${chain}net newaddress p2wkh" +if [ $LNTYPE = cln ];then + command="$lightningcli_alias newaddr bech32" +elif [ $LNTYPE = lnd ];then + command="$lncli_alias newaddress p2wkh" +fi +echo "# Calling:" echo "${command}" +echo result=$($command) echo "$result" # on no result if [ ${#result} -eq 0 ]; then - echo "Empty result - sorry something went wrong - thats unusual." - echo "" - echo "PRESS ENTER to return to menu" + echo "# Empty result - sorry something went wrong - that is unusual." + echo + echo "# Press ENTER to return to menu" read key exit 1 fi @@ -58,7 +85,7 @@ echo "generating QR code ... please wait" /home/admin/config.scripts/blitz.display.sh qr "$network:${address}" # dialog with instructions while QR code is shown on LCD -whiptail --backtitle "Fund your on chain wallet" \ +whiptail --backtitle "Fund your onchain wallet" \ --title "Send ${coininfo}" \ --yes-button "DONE" \ --no-button "Console QRcode" \ @@ -73,6 +100,11 @@ fi /home/admin/config.scripts/blitz.display.sh hide # follow up info -whiptail --backtitle "Fund your on chain wallet" \ +if [ $LNTYPE = cln ];then + string="Wait for confirmations." +elif [ $LNTYPE = lnd ];then + string="Wait for confirmations. \n\nYou can use info on LCD to check if funds have arrived. \n\nIf you want your lighting node to open channels automatically, activate the 'Autopilot' under 'Activate/Deactivate Services'" +fi +whiptail --backtitle "Fund your onchain wallet" \ --title "What's next?" \ - --msgbox "Wait for confirmations. \n\nYou can use info on LCD to check if funds have arrived. \n\nIf you want your lighting node to open channels automatically, activate the 'Autopilot' under 'Activate/Deactivate Services'" 0 0 \ No newline at end of file + --msgbox "$string" 0 0 \ No newline at end of file diff --git a/home.admin/BBopenChannel.sh b/home.admin/BBopenChannel.sh index 43ef1e100..53d2634dd 100755 --- a/home.admin/BBopenChannel.sh +++ b/home.admin/BBopenChannel.sh @@ -12,38 +12,72 @@ if [ ${#chain} -eq 0 ]; then chain=$(${network}-cli getblockchaininfo | jq -r '.chain') fi +source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) +shopt -s expand_aliases +alias bitcoincli_alias="$bitcoincli_alias" +alias lncli_alias="$lncli_alias" +alias lightningcli_alias="$lightningcli_alias" + echo "" echo "*** Precheck ***" -# check if chain is in sync -chainInSync=$(lncli --chain=${network} --network=${chain}net getinfo | grep '"synced_to_chain": true' -c) -if [ ${chainInSync} -eq 0 ]; then - echo "FAIL - 'lncli getinfo' shows 'synced_to_chain': false" - echo "Wait until chain is sync with LND and try again." - echo "" - echo "Press ENTER to return to main menu." +# PRECHECK) check if chain is in sync +if [ $LNTYPE = cln ];then + BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1) + CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight) + if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then + chainOutSync=0 + else + chainOutSync=1 + fi +elif [ $LNTYPE = lnd ];then + chainOutSync=$($lncli_alias getinfo | grep '"synced_to_chain": false' -c) +fi +if [ ${chainOutSync} -eq 1 ]; then + if [ $LNTYPE = cln ];then + echo "# FAIL PRECHECK - lncli getinfo shows 'synced_to_chain': false - wait until chain is sync " + else + echo "# FAIL PRECHECK - 'lightning-cli getinfo' blockheight is different from 'bitcoind getblockchaininfo' - wait until chain is sync " + fi + echo + echo "# PRESS ENTER to return to menu" read key exit 1 +else + echo "# OK - the chain is synced" fi # check available funding -confirmedBalance=$(lncli --chain=${network} --network=${chain}net walletbalance | grep '"confirmed_balance"' | cut -d '"' -f4) +if [ $LNTYPE = cln ];then + for i in $($lightningcli_alias \ + listfunds|jq .outputs[]|jq 'select(.status=="confirmed")'|grep value|awk '{print $2}'|cut -d, -f1);do + confirmedBalance=$((confirmedBalance+i)) + done +elif [ $LNTYPE = lnd ];then + confirmedBalance=$($lncli_alias walletbalance | grep '"confirmed_balance"' | cut -d '"' -f4) +fi + if [ ${confirmedBalance} -eq 0 ]; then echo "FAIL - You have 0 SATOSHI in your confirmed LND On-Chain Wallet." echo "Please fund your on-chain wallet first and wait until confirmed." - echo "" + echo echo "Press ENTER to return to main menu." read key exit 1 fi # check number of connected peers -numConnectedPeers=$(lncli --chain=${network} --network=${chain}net listpeers | grep pub_key -c) +if [ $LNTYPE = cln ];then + numConnectedPeers=$($lightningcli_alias listpeers | grep -c '"id":') +elif [ $LNTYPE = lnd ];then + numConnectedPeers=$($lncli_alias listpeers | grep pub_key -c) +fi + if [ ${numConnectedPeers} -eq 0 ]; then - echo "FAIL - no peers connected on lightning network" + echo "FAIL - no peers connected on the lightning network" echo "You can only open channels to peer nodes to connected to first." echo "Use CONNECT peer option in main menu first." - echo "" + echo echo "Press ENTER to return to main menu." read key exit 1 @@ -51,12 +85,21 @@ fi # let user pick a peer to open a channels with OPTIONS=() -while IFS= read -r grepLine -do - pubKey=$(echo ${grepLine} | cut -d '"' -f4) - #echo "grepLine(${pubKey})" - OPTIONS+=(${pubKey} "") -done < <(lncli --chain=${network} --network=${chain}net listpeers | grep pub_key) +if [ $LNTYPE = cln ];then + while IFS= read -r grepLine + do + pubKey=$(echo ${grepLine} | cut -d '"' -f4) + # echo "grepLine(${pubKey})" + OPTIONS+=(${pubKey} "") + done < <(lightningcli_alias listpeers | grep '"id":') +elif [ $LNTYPE = lnd ];then + while IFS= read -r grepLine + do + pubKey=$(echo ${grepLine} | cut -d '"' -f4) + # echo "grepLine(${pubKey})" + OPTIONS+=(${pubKey} "") + done < <(lncli_alias listpeers | grep pub_key) +fi TITLE="Open (Payment) Channel" MENU="\nChoose a peer you connected to, to open the channel with: \n " pubKey=$(dialog --clear \ @@ -68,11 +111,11 @@ pubKey=$(dialog --clear \ clear if [ ${#pubKey} -eq 0 ]; then - clear - echo - echo "no channel selected - returning to menu ..." - sleep 4 - exit 1 + clear + echo + echo "no channel selected - returning to menu ..." + sleep 4 + exit 1 fi # find out what is the minimum amount @@ -82,15 +125,17 @@ minSat=20000 if [ "${network}" = "bitcoin" ]; then minSat=50000 fi -_error="./.error.out" -lncli --chain=${network} openchannel --network=${chain}net ${CHOICE} 1 0 2>$_error -error=`cat ${_error}` -if [ $(echo "${error}" | grep "channel is too small" -c) -eq 1 ]; then - minSat=$(echo "${error}" | tr -dc '0-9') +if [ $LNTYPE = lnd ];then + _error="./.error.out" + lncli_alias openchannel ${pubkey} 1 0 2>$_error + error=$(cat ${_error}) + if [ $(echo "${error}" | grep "channel is too small" -c) -eq 1 ]; then + minSat=$(echo "${error}" | tr -dc '0-9') + fi fi # let user enter an amount -l1="Amount in SATOSHI to fund this channel:" +l1="Amount in satoshis to fund this channel:" l2="min required : ${minSat}" l3="max available : ${confirmedBalance}" dialog --title "Funding of Channel" \ @@ -119,22 +164,27 @@ if [ ${#conf_target} -eq 0 ]; then fi # build command -command="lncli --chain=${network} --network=${chain}net openchannel --conf_target=${conf_target} ${pubKey} ${amount} 0" - +if [ $LNTYPE = cln ];then + # 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) + command="lightningcli_alias fundchannel ${pubKey} ${amount} $feerate" +elif [ $LNTYPE = lnd ];then + command="lncli_alias openchannel --conf_target=${conf_target} ${pubKey} ${amount} 0" +fi # info output clear echo "******************************" echo "Open Channel" echo "******************************" -echo "" +echo echo "COMMAND LINE: " echo $command -echo "" +echo echo "RESULT:" # execute command -result=$($command 2>$_error) -error=`cat ${_error}` +result=$(eval $command 2>$_error) +error=$(cat ${_error}) #echo "result(${result})" #echo "error(${error})" @@ -149,20 +199,33 @@ else echo "WIN" echo "******************************" echo "${result}" - echo "" - echo "Whats next? --> You need to wait 3 confirmations, for the channel to be ready." - fundingTX=$(echo "${result}" | grep 'funding_txid' | cut -d '"' -f4) + echo + echo "What's next? --> You need to wait 3 confirmations for the channel to be ready." + if [ $LNTYPE = cln ];then + fundingTX=$(echo "${result}" | grep 'txid' | cut -d '"' -f4) + elif [ $LNTYPE = lnd ];then + fundingTX=$(echo "${result}" | grep 'funding_txid' | cut -d '"' -f4) + fi + echo if [ "${network}" = "bitcoin" ]; then if [ "${chain}" = "main" ]; then - echo "https://live.blockcypher.com/btc/tx/${fundingTX}" - else - echo "https://live.blockcypher.com/btc-testnet/tx/${fundingTX}" + #echo "https://live.blockcypher.com/btc/tx/${fundingTX}" + echo "https://mempool.space/tx/${fundingTX}" + elif [ "${chain}" = "test" ]||[ "${chain}" = "sig" ]; then + echo "https://mempool.space/${chain}net/tx/${fundingTX}" + fi + echo + echo "In the Tor Browser:" + if [ "${chain}" = "main" ]; then + echo "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/tx/${fundingTX}" + elif [ "${chain}" = "test" ]||[ "${chain}" = "sig" ]; then + echo "http://mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad.onion/${chain}net/tx/${fundingTX}" fi fi if [ "${network}" = "litecoin" ]; then echo "https://live.blockcypher.com/ltc/tx/${fundingTX}/" fi fi -echo "" +echo echo "Press ENTER to return to main menu." read key \ No newline at end of file diff --git a/home.admin/BBpayInvoice.sh b/home.admin/BBpayInvoice.sh index aafcc8418..06880c965 100755 --- a/home.admin/BBpayInvoice.sh +++ b/home.admin/BBpayInvoice.sh @@ -14,8 +14,14 @@ if [ ${#chain} -eq 0 ]; then chain=$(${network}-cli getblockchaininfo | jq -r '.chain') fi +source <(/home/admin/config.scripts/network.aliases.sh getvars $1 $2) +shopt -s expand_aliases +alias bitcoincli_alias="$bitcoincli_alias" +alias lncli_alias="$lncli_alias" +alias lightningcli_alias="$lightningcli_alias" + # Check if ready (chain in sync and channels open) -./XXchainInSync.sh $network $chain +./XXchainInSync.sh $network $chain $LNTYPE if [ $? != 0 ]; then exit 1 fi @@ -36,7 +42,7 @@ if [ "${network}" = "bitcoin" ]; then if [ "${chain}" = "main" ]; then testSite="https://satoshis.place" else - testSite="https://testnet.satoshis.place" + testSite="https://starblocks.acinq.co/" fi elif [ "${network}" = "litecoin" ]; then testSite="https://millionlitecoinhomepage.net" @@ -46,7 +52,7 @@ fi l1="Copy the LightningInvoice/PaymentRequest into here:" l2="Its a long string starting with '${paymentRequestStart}'" l3="To try it out go to: ${testSite}" -dialog --title "Pay thru Lightning Network" \ +dialog --title "Pay through the Lightning Network" \ --inputbox "$l1\n$l2\n$l3" 10 70 2>$_temp invoice=$(cat $_temp | xargs) shred -u $_temp @@ -61,7 +67,12 @@ fi # TODO: maybe try/show the decoded info first by using https://api.lightning.community/#decodepayreq # build command -command="lncli --chain=${network} --network=${chain}net sendpayment --force --pay_req=${invoice}" +if [ $LNTYPE = cln ];then + # pay bolt11 [msatoshi] [label] [riskfactor] [maxfeepercent] [retry_for] [maxdelay] [exemptfee] + command="$lightningcli_alias pay ${invoice}" +elif [ $LNTYPE = lnd ];then + command="$lncli_alias sendpayment --force --pay_req=${invoice}" +fi # info output clear @@ -70,20 +81,24 @@ echo "Pay Invoice / Payment Request" echo "This script is as an example how to use the lncli interface." echo "Its not optimized for performance or error handling." echo "************************************************************" -echo "" +echo echo "COMMAND LINE: " echo $command -echo "" +echo echo "RESULT (may wait in case of timeout):" # execute command result=$($command 2>$_error) -error=`cat ${_error}` +error=$(cat ${_error}) #echo "result(${result})" #echo "error(${error})" -resultIsError=$(echo "${result}" | grep -c "payment_error") +if [ $LNTYPE = cln ];then + resultIsError=$(echo "${result}" | grep -c '"code":') +elif [ $LNTYPE = lnd ];then + resultIsError=$(echo "${result}" | grep -c "payment_error") +fi if [ ${resultIsError} -gt 0 ]; then error="${result}" fi @@ -99,8 +114,8 @@ else echo "******************************" echo "WIN" echo "******************************" - echo "It worked :) - check out the service you were paying." + echo "It worked :) - check the service you were paying." fi -echo "" +echo echo "Press ENTER to return to main menu." read key diff --git a/home.admin/XXchainInSync.sh b/home.admin/XXchainInSync.sh index 9e102072e..210b5e553 100755 --- a/home.admin/XXchainInSync.sh +++ b/home.admin/XXchainInSync.sh @@ -7,14 +7,39 @@ network=$1 chain=$2 +# LNTYPE is lnd | cln +if [ $# -gt 2 ];then + LNTYPE=$3 +else + LNTYPE=lnd +fi + +source <(/home/admin/config.scripts/network.aliases.sh getvars $LNTYPE ${chain}net) +shopt -s expand_aliases +alias bitcoincli_alias="$bitcoincli_alias" +alias lncli_alias="$lncli_alias" +alias lightningcli_alias="$lightningcli_alias" + # check if chain is in sync -cmdChainInSync="lncli --chain=${network} --network=${chain}net getinfo | grep '"synced_to_chain": true' -c" +if [ $LNTYPE = cln ];then + lncommand="lightning-cli" + BLOCKHEIGHT=$($bitcoincli_alias getblockchaininfo|grep blocks|awk '{print $2}'|cut -d, -f1) + CLHEIGHT=$($lightningcli_alias getinfo | jq .blockheight) + if [ $BLOCKHEIGHT -eq $CLHEIGHT ];then + cmdChainInSync=1 + else + cmdChainInSync=0 + fi +elif [ $LNTYPE = lnd ];then + lncommand="lncli" + cmdChainInSync="lncli_alias getinfo | grep '"synced_to_chain": true' -c" +fi chainInSync=${cmdChainInSync} while [ "${chainInSync}" == "0" ]; do dialog --title "Fail: not in sync" \ --ok-label "Try now" \ --cancel-label "Give up" \ - --pause "\n\n'lncli getinfo' shows 'synced_to_chain': false\n\nTry again in a few seconds." 15 60 5 + --pause "\n\n'$lncommand getinfo' shows 'synced_to_chain': false\n\nTry again in a few seconds." 15 60 5 if [ $? -gt 0 ]; then exit 1 @@ -24,13 +49,17 @@ done # check number of connected peers echo "check for open channels" -openChannels=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net listchannels 2>/dev/null | grep chan_id -c) +if [ $LNTYPE = cln ];then + openChannels=$($lightningcli_alias listpeers | grep -c "CHANNELD_NORMAL") +elif [ $LNTYPE = lnd ];then + openChannels=$($lncli_alias listchannels 2>/dev/null | grep chan_id -c) +fi if [ ${openChannels} -eq 0 ]; then - echo "" + echo echo "!!!!!!!!!!!!!!!!!!!" echo "FAIL - You have NO ESTABLISHED CHANNELS .. open a channel first." echo "!!!!!!!!!!!!!!!!!!!" - echo "" + echo exit 1 fi diff --git a/home.admin/_commands.sh b/home.admin/_commands.sh index cb1ccf744..b71442c54 100755 --- a/home.admin/_commands.sh +++ b/home.admin/_commands.sh @@ -1,5 +1,8 @@ #!/bin/bash +# source aliases from /home/admin/_aliases.sh +source /home/admin/_aliases.sh + # SHORTCUT COMMANDS you can call as user 'admin' from terminal # command: raspiblitz @@ -123,7 +126,24 @@ function torthistx() { # start the status screen in the terminal function status() { echo "Gathering data - please wait a moment..." - sudo -u pi /home/admin/00infoLCD.sh --pause 0 + while : + do + # show the same info as on LCD screen + # 00infoBlitz.sh + /home/admin/00infoBlitz.sh $1 $2 + # wait 6 seconds for user exiting loop + #echo + #echo -en "Screen is updating in a loop .... press 'x' now to get back to menu." + read -n 1 -t 6 keyPressed + #echo -en "\rGathering information to update info ... please wait. \n" + # check if user wants to abort session + if [ "${keyPressed}" = "x" ]; then + echo + echo "Returning to menu ....." + sleep 4 + break + fi + done } # command: lnbalance diff --git a/home.admin/assets/raspiblitz-v1.6-2020-08-04.img.gz.torrent b/home.admin/assets/raspiblitz-v1.6-2020-08-04.img.gz.torrent deleted file mode 100755 index 96264baf7..000000000 Binary files a/home.admin/assets/raspiblitz-v1.6-2020-08-04.img.gz.torrent and /dev/null differ diff --git a/home.admin/assets/raspiblitz-v1.6.1-2020-10-20.img.gz.torrent b/home.admin/assets/raspiblitz-v1.6.1-2020-10-20.img.gz.torrent deleted file mode 100644 index 19288d03e..000000000 Binary files a/home.admin/assets/raspiblitz-v1.6.1-2020-10-20.img.gz.torrent and /dev/null differ diff --git a/home.admin/assets/raspiblitz-v1.7.0-2021-04-25.img.gz.torrent b/home.admin/assets/raspiblitz-v1.7.0-2021-04-25.img.gz.torrent new file mode 100755 index 000000000..c60518f8d Binary files /dev/null and b/home.admin/assets/raspiblitz-v1.7.0-2021-04-25.img.gz.torrent differ diff --git a/home.admin/config.scripts/bitcoin.chains.sh b/home.admin/config.scripts/bitcoin.chains.sh new file mode 100644 index 000000000..f5456b2ee --- /dev/null +++ b/home.admin/config.scripts/bitcoin.chains.sh @@ -0,0 +1,216 @@ +#!/bin/bash + +# command info +if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ];then + echo + echo "Install or remove parallel chains for Bitcoin Core" + echo "network.bitcoinchains.sh [on|off] [signet|testnet|mainnet]" + echo + exit 1 +fi + +# CHAIN is signet | testnet | mainnet +CHAIN=$2 +if [ ${CHAIN} = signet ]||[ ${CHAIN} = testnet ]||[ ${CHAIN} = mainnet ];then + echo "# Installing Bitcoin Core instance on ${CHAIN}" +else + echo "# ${CHAIN} is not supported" + exit 1 +fi + +# prefix for parallel services +if [ ${CHAIN} = testnet ];then + prefix="t" + bitcoinprefix=test + zmqprefix=21 # zmqpubrawblock=21332 zmqpubrawtx=21333 + rpcprefix=1 # rpcport=18332 +elif [ ${CHAIN} = signet ];then + prefix="s" + bitcoinprefix=signet + zmqprefix=23 + rpcprefix=3 +elif [ ${CHAIN} = mainnet ];then + prefix="" + bitcoinprefix=main + zmqprefix=28 + rpcprefix="" +fi + +function removeParallelService() { + if [ -f "/etc/systemd/system/${prefix}bitcoind.service" ];then + if [ ${CHAIN} != mainnet ];then + /usr/local/bin/bitcoin-cli -${CHAIN} stop + else + /usr/local/bin/bitcoin-cli stop + fi + sudo systemctl stop ${prefix}bitcoind + sudo systemctl disable ${prefix}bitcoind + echo "# Bitcoin Core on ${CHAIN} service is stopped and disabled" + echo + fi +} + +function installParallelService() { + # bitcoin.conf + if [ ! -f /home/bitcoin/.bitcoin/bitcoin.conf ];then + # add minimal config + randomRPCpass=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8) + echo " +# bitcoind configuration for ${CHAIN} + +# Connection settings +rpcuser=raspiblitz +rpcpassword=$randomRPCpass +${bitcoinprefix}.zmqpubrawblock=tcp://127.0.0.1:${zmqprefix}332 +${bitcoinprefix}.zmqpubrawtx=tcp://127.0.0.1:${zmqprefix}333 + +onlynet=onion +proxy=127.0.0.1:9050 + +datadir=/mnt/hdd/bitcoin +" | sudo -u bitcoin tee /home/bitcoin/.bitcoin/bitcoin.conf + else + echo "# /home/bitcoin/.bitcoin/bitcoin.conf is present" + fi + + # make sure rpcbind is correctly configured + sudo sed -i s/^rpcbind=/main.rpcbind=/g /mnt/hdd/${network}/${network}.conf + + # correct rpcport entry + sudo sed -i s/^rpcport=/main.rpcport=/g /mnt/hdd/${network}/${network}.conf + if [ $(grep -c "${bitcoinprefix}.rpcport" < /mnt/hdd/${network}/${network}.conf) -eq 0 ];then + echo "\ +${bitcoinprefix}.rpcport=${rpcprefix}8332"|\ + sudo tee -a /mnt/hdd/${network}/${network}.conf + fi + + # correct zmq entry + sudo sed -i s/^zmqpubraw/main.zmqpubraw/g /mnt/hdd/${network}/${network}.conf + if [ $(grep -c "${bitcoinprefix}.zmqpubrawblock" < /mnt/hdd/${network}/${network}.conf) -eq 0 ];then + echo "\ +${bitcoinprefix}.zmqpubrawblock=tcp://127.0.0.1:${zmqprefix}332 +${bitcoinprefix}.zmqpubrawtx=tcp://127.0.0.1:${zmqprefix}333"|\ + sudo tee -a /mnt/hdd/${network}/${network}.conf + fi + + # addnode + if [ ${bitcoinprefix} = signet ];then + if [ $(grep -c "${bitcoinprefix}.addnode" < /mnt/hdd/${network}/${network}.conf) -eq 0 ];then + echo "\ +signet.addnode=g7fyzp4rgxlrcg73jmrwrzhjnfpsuavjvopurvfq7nrl5x2tif3gx6qd.onion:38333 +signet.addnode=s7fcvn5rblem7tiquhhr7acjdhu7wsawcph7ck44uxyd6sismumemcyd.onion:38333 +signet.addnode=6megrst422lxzsqvshkqkg6z2zhunywhyrhy3ltezaeyfspfyjdzr3qd.onion:38333 +signet.addnode=jahtu4veqnvjldtbyxjiibdrltqiiighauai7hmvknwxhptsb4xat4qd.onion:38333 +signet.addnode=4j6owtnrkgfty2ehbyuwz72k32fyos7co7jnnktxwg7rfrgnqk3obkid.onion:38333 +signet.addnode=f4kwoin7kk5a5kqpni7yqe25z66ckqu6bv37sqeluon24yne5rodzkqd.onion:38333 +signet.addnode=u2d5lofh73k275q3zm76r5bob5pjbff35goubg5hwr2xpgj365ei7cyd.onion:38333 +signet.addnode=nsgyo7begau4yecc46ljfecaykyzszcseapxmtu6adrfagfrrzrlngyd.onion:38333"|\ + sudo tee -a /mnt/hdd/${network}/${network}.conf + fi + fi + + removeParallelService + if [ ${CHAIN} = mainnet ];then + sudo cp /home/admin/assets/${network}d.service /etc/systemd/system/${network}d.service + else + # /etc/systemd/system/${prefix}bitcoind.service + echo " +[Unit] +Description=Bitcoin daemon on ${CHAIN} + +[Service] +User=bitcoin +Group=bitcoin +Type=forking +PIDFile=/mnt/hdd/bitcoin/${prefix}bitcoind.pid +ExecStart=/usr/local/bin/bitcoind -${CHAIN} -daemon\ + -pid=/mnt/hdd/bitcoin/${prefix}bitcoind.pid +KillMode=process +Restart=always +TimeoutSec=120 +RestartSec=30 +StandardOutput=null +StandardError=journal + +# Hardening measures +PrivateTmp=true +ProtectSystem=full +NoNewPrivileges=true +PrivateDevices=true + +[Install] +WantedBy=multi-user.target +" | sudo tee /etc/systemd/system/${prefix}bitcoind.service + fi + sudo systemctl daemon-reload + sudo systemctl enable ${prefix}bitcoind + echo "# OK - the bitcoin daemon on ${CHAIN} service is now enabled" + + # add aliases + if [ ${CHAIN} != mainnet ];then + if [ $(alias | grep -c ${prefix}bitcoin) -eq 0 ];then + bash -c "echo 'alias ${prefix}bitcoin-cli=\"/usr/local/bin/bitcoin-cli\ + -rpcport=${rpcprefix}8332\"' \ + >> /home/admin/_aliases.sh" + bash -c "echo 'alias ${prefix}bitcoind=\"/usr/local/bin/bitcoind\ + -${CHAIN}\"' \ + >> /home/admin/_aliases.sh" + fi + fi + + source /home/admin/raspiblitz.info + if [ "${state}" == "ready" ]; then + echo "# OK - the ${prefix}bitcoind.service is enabled, system is ready so starting service" + sudo systemctl start ${prefix}bitcoind + else + echo "# OK - the ${prefix}bitcoindservice is enabled, to start manually use:" + echo "sudo systemctl start ${prefix}bitcoind" + fi + + isInstalled=$(systemctl status ${prefix}bitcoind | grep -c active) + if [ $isInstalled -gt 0 ];then + echo "# Installed $(bitcoind --version | grep version) ${prefix}bitcoind.service" + echo + echo "# Monitor the ${prefix}bitcoind with:" + if [ ${CHAIN} = signet ]; then + echo "sudo tail -f /mnt/hdd/bitcoin/signet/debug.log" + elif [ ${CHAIN} = testnet ]; then + echo "sudo tail -f /mnt/hdd/bitcoin/testnet3/debug.log" + elif [ ${CHAIN} = mainnet ]; then + echo "sudo tail -f /mnt/hdd/bitcoin/debug.log" + fi + echo + else + echo "# Installation failed" + echo "# See:" + echo "# sudo journalctl -fu ${prefix}bitcoind" + exit 1 + fi +} + +source /mnt/hdd/raspiblitz.conf + +# add default value to raspi config if needed +if ! grep -Eq "^${CHAIN}=" /mnt/hdd/raspiblitz.conf; then + echo "${CHAIN}=off" >> /mnt/hdd/raspiblitz.conf +fi + +# switch on +if [ "$1" = "1" ] || [ "$1" = "on" ]; then + installParallelService + # setting value in raspi blitz config + sudo sed -i "s/^${CHAIN}=.*/${CHAIN}=on/g" /mnt/hdd/raspiblitz.conf + exit 0 +fi + +# switch off +if [ "$1" = "0" ] || [ "$1" = "off" ]; then + removeParallelService + # setting value in raspi blitz config + sudo sed -i "s/^${CHAIN}=.*/${CHAIN}=off/g" /mnt/hdd/raspiblitz.conf + exit 0 +fi + +echo "# FAIL - Unknown Parameter $1" +echo "# may need reboot to run" +exit 1 \ No newline at end of file diff --git a/home.admin/config.scripts/blitz.statusscan.sh b/home.admin/config.scripts/blitz.statusscan.sh index 4e3bc8c5f..8c295d6f5 100755 --- a/home.admin/config.scripts/blitz.statusscan.sh +++ b/home.admin/config.scripts/blitz.statusscan.sh @@ -3,6 +3,19 @@ source /home/admin/raspiblitz.info source /mnt/hdd/raspiblitz.conf 2>/dev/null +# LNTYPE is lnd | cln +if [ $# -gt 0 ];then + LNTYPE=$1 +else + LNTYPE=lnd +fi + +source <(/home/admin/config.scripts/network.aliases.sh getvars $LNTYPE ${chain}net) +shopt -s expand_aliases +alias bitcoincli_alias="$bitcoincli_alias" +alias lncli_alias="$lncli_alias" +alias lightningcli_alias="$lightningcli_alias" + # command info if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then echo "# script to scan the state of the system after setup" @@ -45,7 +58,7 @@ echo "bitcoinActive=${bitcoinRunning}" if [ ${bitcoinRunning} -eq 1 ]; then # get blockchain info - sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/mnt/hdd/temp/.bitcoind.out 2>/mnt/hdd/temp/.bitcoind.error + bitcoincli_alias getblockchaininfo 1>/mnt/hdd/temp/.bitcoind.out 2>/mnt/hdd/temp/.bitcoind.error # check if error on request blockchaininfo=$(cat /mnt/hdd/temp/.bitcoind.out 2>/dev/null) bitcoinError=$(cat /mnt/hdd/temp/.bitcoind.error 2>/dev/null) @@ -127,15 +140,15 @@ startcountLightning=$(cat /home/admin/systemd.lightning.log 2>/dev/null | grep - echo "startcountLightning=${startcountLightning}" # 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}" if [ ${lndRunning} -eq 1 ]; then # get LND info 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 lndErrorFull=$(cat /mnt/hdd/temp/.lnd.error 2>/dev/null) lndErrorShort='' diff --git a/home.admin/config.scripts/bonus.rtl.sh b/home.admin/config.scripts/bonus.rtl.sh index 77f5de2fb..6f0ab3db6 100755 --- a/home.admin/config.scripts/bonus.rtl.sh +++ b/home.admin/config.scripts/bonus.rtl.sh @@ -1,23 +1,75 @@ #!/bin/bash RTLVERSION="v0.10.1" -# command info -if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then - echo "# config script to switch the RideTheLightning WebGUI on, off or update" - echo "# bonus.rtl.sh [on|off|update|menu|config]" - echo "# installs the version $RTLVERSION by default" - exit 1 -fi - # check and load raspiblitz config # to know which network is running source /home/admin/raspiblitz.info source /mnt/hdd/raspiblitz.conf + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "# config script to switch the RideTheLightning WebGUI on, off or update" + echo + echo "# bonus.rtl.sh [on|off|menu] " + echo "# sets up lnd on ${chain}net by default" + echo "# able to run intances for lnd and cln parallel" + echo "# lnd mainnet and testnet can run parallel" + echo "# cln can only have one network active at a time" + echo + echo "# bonus.rtl.sh [update|config]" + echo "# installs the version $RTLVERSION by default" + exit 1 +fi + +echo "# Running: 'bonus.rtl.sh $*'" + if [ ${#network} -eq 0 ]; then echo "FAIL - missing /mnt/hdd/raspiblitz.conf" exit 1 fi +# LNTYPE is lnd | cln +if [ $# -gt 1 ];then + LNTYPE=$2 +else + LNTYPE=lnd +fi +if [ ${LNTYPE} != lnd ]&&[ ${LNTYPE} != cln ];then + echo "# ${LNTYPE} is not a supported LNTYPE" + exit 1 +fi + +# CHAIN is signet | testnet | mainnet +if [ $# -gt 2 ];then + CHAIN=$3 +else + CHAIN=${chain}net +fi +if [ ${CHAIN} != testnet ]&&[ ${CHAIN} != mainnet ]&&[ ${CHAIN} != signet ];then + echo "# ${CHAIN} is not a supported CHAIN" + exit 1 +fi + +# prefix for parallel services +if [ ${CHAIN} = testnet ];then + netprefix="t" + portprefix=1 +elif [ ${CHAIN} = signet ];then + netprefix="s" + portprefix=3 +elif [ ${CHAIN} = mainnet ];then + netprefix="" + portprefix="" +fi + +if [ ${LNTYPE} = cln ]; then + RTLHTTP=${portprefix}7000 + typeprefix=c +elif [ ${LNTYPE} = lnd ];then + RTLHTTP=${portprefix}3000 + typeprefix="" +fi + # show info menu if [ "$1" = "menu" ]; then @@ -29,9 +81,9 @@ if [ "$1" = "menu" ]; then if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then # Info with TOR /home/admin/config.scripts/blitz.display.sh qr "${toraddress}" - whiptail --title " Ride The Lightning (RTL) " --msgbox "Open in your local web browser: -http://${localip}:3000\n -https://${localip}:3001 with Fingerprint: + whiptail --title "Ride The Lightning (RTL - $LNTYPE - $CHAIN)" --msgbox "Open in your local web browser: +http://${localip}:${RTLHTTP}\n +https://${localip}:$((RTLHTTP+1)) with Fingerprint: ${fingerprint}\n Use your Password B to login.\n Hidden Service address for TOR Browser (QRcode on LCD):\n${toraddress} @@ -39,9 +91,9 @@ Hidden Service address for TOR Browser (QRcode on LCD):\n${toraddress} /home/admin/config.scripts/blitz.display.sh hide else # Info without TOR - whiptail --title " Ride The Lightning (RTL) " --msgbox "Open in your local web browser & accept self-signed cert: -http://${localip}:3000\n -https://${localip}:3001 with Fingerprint: + whiptail --title "Ride The Lightning (RTL - $LNTYPE - $CHAIN)" --msgbox "Open in your local web browser & accept self-signed cert: +http://${localip}:${RTLHTTP}\n +https://${localip}:$((RTLHTTP+1)) with Fingerprint: ${fingerprint}\n Use your Password B to login.\n Activate TOR to access the web interface from outside your local network. @@ -52,36 +104,41 @@ Activate TOR to access the web interface from outside your local network. fi # add default value to raspi config if needed -if ! grep -Eq "^rtlWebinterface=" /mnt/hdd/raspiblitz.conf; then - echo "rtlWebinterface=off" >> /mnt/hdd/raspiblitz.conf +if ! grep -Eq "^${netprefix}${typeprefix}rtlWebinterface=" /mnt/hdd/raspiblitz.conf; then + echo "${netprefix}${typeprefix}rtlWebinterface=off" >> /mnt/hdd/raspiblitz.conf fi # stop services echo "# making sure services are not running" -sudo systemctl stop RTL 2>/dev/null +sudo systemctl stop ${netprefix}${typeprefix}RTL 2>/dev/null function configRTL() { - SWAPSERVERPORT=8443 - if [ "$(grep -Ec "(loop=|lit=)" < /mnt/hdd/raspiblitz.conf)" -gt 0 ];then - if [ $lit = on ];then - echo "# Add the rtl user to the lit group" - sudo /usr/sbin/usermod --append --groups lit rtl - echo "# Symlink the lit-loop.macaroon" - sudo rm -rf "/home/rtl/.loop" # delete symlink - sudo ln -s "/home/lit/.loop/" "/home/rtl/.loop" # create symlink - SWAPSERVERPORT=8443 - elif [ $loop = on ];then - echo "# Add the rtl user to the loop group" - sudo /usr/sbin/usermod --append --groups loop rtl - echo "# Symlink the loop.macaroon" - sudo rm -rf "/home/rtl/.loop" # delete symlink - sudo ln -s "/home/loop/.loop/" "/home/rtl/.loop" # create symlink - SWAPSERVERPORT=8081 + + if [ $LNTYPE = lnd ];then + echo "# Make sure rtl is member of lndadmin" + sudo /usr/sbin/usermod --append --groups lndadmin rtl + SWAPSERVERPORT=8443 + if [ "$(grep -Ec "(loop=|lit=)" < /mnt/hdd/raspiblitz.conf)" -gt 0 ];then + if [ $lit = on ];then + echo "# Add the rtl user to the lit group" + sudo /usr/sbin/usermod --append --groups lit rtl + echo "# Symlink the lit-loop.macaroon" + sudo rm -rf "/home/rtl/.loop" # delete symlink + sudo ln -s "/home/lit/.loop/" "/home/rtl/.loop" # create symlink + SWAPSERVERPORT=8443 + elif [ $loop = on ];then + echo "# Add the rtl user to the loop group" + sudo /usr/sbin/usermod --append --groups loop rtl + echo "# Symlink the loop.macaroon" + sudo rm -rf "/home/rtl/.loop" # delete symlink + sudo ln -s "/home/loop/.loop/" "/home/rtl/.loop" # create symlink + SWAPSERVERPORT=8081 + fi + echo "# Make the loop macaroon group readable" + sudo chmod 640 /home/rtl/.loop/mainnet/macaroons.db + else + echo "# No Loop or LiT is installed" fi - echo "# Make the loop macaroon group readable" - sudo chmod 640 /home/rtl/.loop/mainnet/macaroons.db - else - echo "# No Loop or LiT is installed" fi # prepare RTL-Config.json file @@ -96,6 +153,7 @@ function configRTL() { //Read data var data = require('/home/rtl/RTL/sample-RTL-Config.json'); //Manipulate data +data.port = '$RTLHTTP' data.nodes[0].lnNode = '$hostname' data.nodes[0].Authentication.macaroonPath = '/home/rtl/.lnd/data/chain/${network}/${chain}net/' data.nodes[0].Authentication.configPath = '/home/rtl/.lnd/lnd.conf'; @@ -115,87 +173,76 @@ EOF # switch on if [ "$1" = "1" ] || [ "$1" = "on" ]; then - echo "# INSTALL RTL" + echo "# Installing the RTL for ${LNTYPE} ${CHAIN}" - isInstalled=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service') + isInstalled=$(sudo ls /etc/systemd/system/${netprefix}${typeprefix}RTL.service 2>/dev/null | grep -c "${netprefix}${typeprefix}RTL.service") if ! [ ${isInstalled} -eq 0 ]; then - echo "# RTL already installed." + echo "# OK, the ${netprefix}${typeprefix}RTL.service is already installed." else # check and install NodeJS /home/admin/config.scripts/bonus.nodejs.sh on # create rtl user - sudo adduser --disabled-password --gecos "" rtl || exit 1 - - echo "# Make sure rtl is member of lndadmin" - sudo /usr/sbin/usermod --append --groups lndadmin rtl - - echo "# Make sure symlink to central app-data directory exists" - if ! [[ -L "/home/rtl/.lnd" ]]; then - sudo rm -rf "/home/rtl/.lnd" # not a symlink.. delete it silently - sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/rtl/.lnd" # and create symlink + if [ $(compgen -u | grep -c rtl) -eq 0 ];then + sudo adduser --disabled-password --gecos "" rtl || exit 1 fi - # download source code and set to tag release - echo "# Get the RTL Source Code" - rm -rf /home/admin/RTL 2>/dev/null - sudo -u rtl rm -rf /home/rtl/RTL 2>/dev/null - sudo -u rtl git clone https://github.com/ShahanaFarooqui/RTL.git /home/rtl/RTL - cd /home/rtl/RTL - # check https://github.com/Ride-The-Lightning/RTL/releases/ - sudo -u rtl git reset --hard $RTLVERSION - # from https://github.com/Ride-The-Lightning/RTL/commits/master - # git checkout 917feebfa4fb583360c140e817c266649307ef72 - if [ -d "/home/rtl/RTL" ]; then - echo "# OK - RTL code copy looks good" + if [ -f /home/rtl/RTL/rtl.js ];then + echo "# OK - the RTL code is already present" else - echo "# FAIL - code copy did not run correctly" - echo "# ABORT - RTL install" - exit 1 - fi - echo "" - - # install - echo "# Run: npm install" - export NG_CLI_ANALYTICS=false - sudo -u rtl npm install --only=prod - if ! [ $? -eq 0 ]; then - echo "# FAIL - npm install did not run correctly, aborting" + + echo "# Make sure symlink to central app-data directory exists" + if ! [[ -L "/home/rtl/.lnd" ]]; then + sudo rm -rf "/home/rtl/.lnd" # not a symlink.. delete it silently + sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/rtl/.lnd" # and create symlink + fi + + # download source code and set to tag release + echo "# Get the RTL Source Code" + rm -rf /home/admin/RTL 2>/dev/null + sudo -u rtl rm -rf /home/rtl/RTL 2>/dev/null + sudo -u rtl git clone https://github.com/ShahanaFarooqui/RTL.git /home/rtl/RTL + cd /home/rtl/RTL + # check https://github.com/Ride-The-Lightning/RTL/releases/ + sudo -u rtl git reset --hard $RTLVERSION + # from https://github.com/Ride-The-Lightning/RTL/commits/master + # git checkout 917feebfa4fb583360c140e817c266649307ef72 + if [ -d "/home/rtl/RTL" ]; then + echo "# OK - RTL code copy looks good" + else + echo "# FAIL - code copy did not run correctly" + echo "# ABORT - RTL install" exit 1 - else - echo "# OK - RTL install looks good" - echo + fi + echo + + # install + echo "# Run: npm install" + export NG_CLI_ANALYTICS=false + sudo -u rtl npm install --only=prod + if ! [ $? -eq 0 ]; then + echo "# FAIL - npm install did not run correctly, aborting" + exit 1 + else + echo "# OK - RTL install looks good" + echo + fi fi - # setup nginx symlinks - if ! [ -f /etc/nginx/sites-available/rtl_ssl.conf ]; then - sudo cp /home/admin/assets/nginx/sites-available/rtl_ssl.conf /etc/nginx/sites-available/rtl_ssl.conf - fi - if ! [ -f /etc/nginx/sites-available/rtl_tor.conf ]; then - sudo cp /home/admin/assets/nginx/sites-available/rtl_tor.conf /etc/nginx/sites-available/rtl_tor.conf - fi - if ! [ -f /etc/nginx/sites-available/rtl_tor_ssl.conf ]; then - sudo cp /home/admin/assets/nginx/sites-available/rtl_tor_ssl.conf /etc/nginx/sites-available/rtl_tor_ssl.conf - fi - sudo ln -sf /etc/nginx/sites-available/rtl_ssl.conf /etc/nginx/sites-enabled/ - sudo ln -sf /etc/nginx/sites-available/rtl_tor.conf /etc/nginx/sites-enabled/ - sudo ln -sf /etc/nginx/sites-available/rtl_tor_ssl.conf /etc/nginx/sites-enabled/ - sudo nginx -t - sudo systemctl reload nginx - echo "# Updating Firewall" - sudo ufw allow 3000 comment 'RTL HTTP' - sudo ufw allow 3001 comment 'RTL HTTPS' + sudo ufw allow ${RTLHTTP} comment "${netprefix}${typeprefix}RTL HTTP" + sudo ufw allow $((RTLHTTP+1)) comment "${netprefix}${typeprefix}RTL HTTPS" echo + if [ $LNTYPE = lnd ];then echo "# Install service" echo "# Install RTL systemd for ${network} on ${chain}" - cat > /home/admin/RTL.service < /home/admin/${netprefix}${typeprefix}RTL.service <