From b519150536d362c633c0c8585ef60c82465e4792 Mon Sep 17 00:00:00 2001 From: openoms Date: Wed, 25 Aug 2021 11:07:26 +0100 Subject: [PATCH 1/2] change all LNdefault vars to lightning --- home.admin/00parallelChainsMenu.sh | 12 +- home.admin/99clnMenu.sh | 6 +- home.admin/99lndMenu.sh | 6 +- home.admin/config.scripts/cln-plugin.spark.sh | 203 ++++++++++++++++++ home.admin/config.scripts/network.aliases.sh | 4 +- 5 files changed, 217 insertions(+), 14 deletions(-) create mode 100644 home.admin/config.scripts/cln-plugin.spark.sh diff --git a/home.admin/00parallelChainsMenu.sh b/home.admin/00parallelChainsMenu.sh index 97b345a8e..ea6e04275 100644 --- a/home.admin/00parallelChainsMenu.sh +++ b/home.admin/00parallelChainsMenu.sh @@ -8,8 +8,8 @@ source /home/admin/raspiblitz.info 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 +if ! grep -Eq "^lightning=" /mnt/hdd/raspiblitz.conf; then + echo "lightning=lnd" >> /mnt/hdd/raspiblitz.conf fi source /mnt/hdd/raspiblitz.conf @@ -25,12 +25,12 @@ else fi # LNTYPE is lnd | cln -if [ $# -gt 1 ]&&[ $2 != $LNdefault ];then +if [ $# -gt 1 ]&&[ $2 != $lightning ];then nonDefaultLNtype=1 LNTYPE=$2 else nonDefaultLNtype=0 - LNTYPE=$LNdefault + LNTYPE=$lightning fi # get the local network IP to be displayed on the LCD @@ -163,8 +163,8 @@ case $CHOICE in ;; 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" + sudo sed -i "s/^lightning=.*/lightning=$LNTYPE/g" /mnt/hdd/raspiblitz.conf + echo "# OK - Set lightning=$LNTYPE in /mnt/hdd/raspiblitz.conf" echo echo "Press ENTER to return to main menu." ;; diff --git a/home.admin/99clnMenu.sh b/home.admin/99clnMenu.sh index b347552cc..92d01ca50 100644 --- a/home.admin/99clnMenu.sh +++ b/home.admin/99clnMenu.sh @@ -34,7 +34,7 @@ if [ ${#openChannels} -gt 0 ] && [ ${openChannels} -gt 0 ]; then OPTIONS+=(CLOSEALL "Close all open Channels on $CHAIN") fi -if [ ${#LNdefault} -gt 0 ]&&[ $LNdefault = lnd ];then +if [ ${#lightning} -gt 0 ]&&[ $lightning = lnd ];then OPTIONS+=(SWITCHLN "Use C-lightning as default") fi @@ -104,8 +104,8 @@ case $CHOICE in 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" + sudo sed -i "s/^lightning=.*/lightning=cln/g" /mnt/hdd/raspiblitz.conf + echo "# OK - lightning=cln is set in /mnt/hdd/raspiblitz.conf" echo echo "Press ENTER to return to main menu." read key diff --git a/home.admin/99lndMenu.sh b/home.admin/99lndMenu.sh index e202a434b..07550de02 100644 --- a/home.admin/99lndMenu.sh +++ b/home.admin/99lndMenu.sh @@ -38,7 +38,7 @@ if [ ${#openChannels} -gt 0 ] && [ ${openChannels} -gt 0 ]; then fi OPTIONS+=(CASHOUT "Withdraw all funds from LND on $CHAIN") -if [ ${#LNdefault} -gt 0 ]&&[ $LNdefault = cln ];then +if [ ${#lightning} -gt 0 ]&&[ $lightning = cln ];then OPTIONS+=(SWITCHLN "Use LND as default") fi @@ -132,8 +132,8 @@ case $CHOICE in 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" + sudo sed -i "s/^lightning=.*/lightning=lnd/g" /mnt/hdd/raspiblitz.conf + echo "# OK - lightning=lnd is set in /mnt/hdd/raspiblitz.conf" echo echo "Press ENTER to return to main menu." read key diff --git a/home.admin/config.scripts/cln-plugin.spark.sh b/home.admin/config.scripts/cln-plugin.spark.sh new file mode 100644 index 000000000..5c0c26ec6 --- /dev/null +++ b/home.admin/config.scripts/cln-plugin.spark.sh @@ -0,0 +1,203 @@ +#!/bin/bash + +#https://github.com/shesek/spark-wallet/releases +sparkVERSION="v0.3.0rc" + +# command info +if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ];then + echo + echo "Install, remove, connect or get info about the Spark Wallet plugin for C-lightning" + echo "version: $SPARKVERSION" + echo "Usage:" + echo "cln-plugin.spark-wallet.sh [on|off|menu|connect] [testnet|mainnet|signet]" + echo + exit 1 +fi + +# source <(/home/admin/config.scripts/network.aliases.sh getvars cln ) +source <(/home/admin/config.scripts/network.aliases.sh getvars cln $2) + +# show info menu +if [ "$1" = "menu" ]; then + + # get network info + localip=$(ip addr | grep 'state UP' -A2 | grep -E -v 'docker0|veth' | grep 'eth0\|wlan0\|enp0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + toraddress=$(sudo cat /mnt/hdd/tor/${netprefix}spark/hostname) + toraddresstext="Hidden Service address for the Tor Browser (QRcode on LCD):\n$toraddress" + if [ ${#toraddress} -eq 0 ];then + toraddresstext="Activate Tor to access the web interface from outside of the local network." + else + /home/admin/config.scripts/blitz.display.sh qr "${toraddress}" + fi + fingerprint=$(openssl x509 -in /home/bitcoin/.lightning/spark-tls/cert.pem -fingerprint -noout | cut -d"=" -f2) + + whiptail --title "\ +spark - $CHAIN" --msgbox "Open in your local web browser: +https://${localip}:${portprefix}9000\n +username: blitz +password: 'your Password B'\n +Accept the self-signed SSL certificate with the fingerprint: +${fingerprint}\n +${toraddresstext} +" 17 67 + + /home/admin/config.scripts/blitz.display.sh hide + + echo "# please wait ..." + exit 0 +fi + +# add default value to raspi config if needed +configEntry="${netprefix}spark" +configEntryExists=$(sudo cat /mnt/hdd/raspiblitz.conf | grep -c "${configEntry}") +if [ "${configEntryExists}" == "0" ]; then + echo "# adding default config entry for '${configEntry}'" + sudo /bin/sh -c "echo '${configEntry}=off' >> /mnt/hdd/raspiblitz.conf" +else + echo "# default config entry for '${configEntry}' exists" +fi + +if [ $1 = connect ];then + localip=$(ip addr | grep 'state UP' -A2 | grep -E -v 'docker0|veth' | grep 'eth0\|wlan0\|enp0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + toraddress=$(sudo cat /mnt/hdd/tor/${netprefix}spark/hostname) + accesskey=$(sudo cat ${CLNCONF} | grep "^spark-keys=" | cut -d= -f2 | cut -d';' -f1) + url="https://${localip}:${portprefix}9000/" + string="${url}?access-key=${accesskey}" + + /home/admin/config.scripts/blitz.display.sh qr "$string" + clear + echo "connection string (shown as a QRcode on the top and on the LCD):" + echo "$string" + qrencode -t ANSIUTF8 "${string}" + echo + echo "Tor address (shown as a QRcode below):" + echo "${toraddress}" + qrencode -t ANSIUTF8 "${toraddress}" + echo + echo "# Press enter to hide the QRcode from the LCD" + read key + /home/admin/config.scripts/blitz.display.sh hide +fi + +if [ $1 = on ];then + + # check and install NodeJS + /home/admin/config.scripts/bonus.nodejs.sh on + + # create spark user + sudo adduser --disabled-password --gecos "" spark + + # set up npm-global + sudo -u spark mkdir /home/spark/.npm-global + sudo -u spark npm config set prefix '/home/spark/.npm-global' + sudo bash -c "echo 'PATH=$PATH:/home/spark/.npm-global/bin' >> /home/spark/.bashrc" + + echo "# Create data folder on the disk" + # move old data if present + sudo mv /home/spark/.spark /mnt/hdd/app-data/ 2>/dev/null + echo "# make sure the data directory exists" + sudo mkdir -p /mnt/hdd/app-data/.spark + echo "# symlink" + sudo rm -rf /home/spark/.spark # not a symlink.. delete it silently + sudo ln -s /mnt/hdd/app-data/.spark/ /home/spark/.spark + sudo chown spark:spark -R /mnt/hdd/app-data/.spark + + + + npm install -g spark-wallet + + if [ ! -f /home/bitcoin/cln-plugins-available/spark ];then + sudo -u bitcoin mkdir /home/bitcoin/cln-plugins-available + # download binary + sudo -u bitcoin wget https://github.com/fiatjaf/spark/releases/download/${sparkVERSION}/spark_${DISTRO}\ + -O /home/bitcoin/cln-plugins-available/spark || exit 1 + # make executable + sudo chmod +x /home/bitcoin/cln-plugins-available/spark + fi + + if [ ! -L /home/bitcoin/${netprefix}cln-plugins-enabled/spark ];then + sudo ln -s /home/bitcoin/cln-plugins-available/spark \ + /home/bitcoin/${netprefix}cln-plugins-enabled + fi + + if [ ! -f /home/bitcoin/.lightning/spark-tls/key.pem ];then + # create a self signed cert https://github.com/fiatjaf/spark#how-to-use + /home/admin/config.scripts/internet.selfsignedcert.sh + # spark looks for specific filenames + sudo -u bitcoin mkdir /home/bitcoin/.lightning/spark-tls + sudo ln -sf /mnt/hdd/app-data/selfsignedcert/selfsigned.key \ + /home/bitcoin/.lightning/spark-tls/key.pem + sudo ln -sf /mnt/hdd/app-data/selfsignedcert/selfsigned.cert \ + /home/bitcoin/.lightning/spark-tls/cert.pem + fi + + ########## + # Config # + ########## + if ! grep -Eq "^spark" ${CLNCONF};then + echo "# Editing ${CLNCONF}" + echo "# See: https://github.com/fiatjaf/spark#how-to-use" + PASSWORD_B=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcpassword | cut -c 13-) + # Spark wallet only allows alphanumeric characters + masterkeythatcandoeverything=$(< /dev/urandom tr -dc a-zA-Z0-9 | head -c20) + secretaccesskeythatcanreadstuff=$(< /dev/urandom tr -dc a-zA-Z0-9 | head -c20) + verysecretkeythatcanpayinvoices=$(< /dev/urandom tr -dc a-zA-Z0-9 | head -c20) + keythatcanlistentoallevents=$(< /dev/urandom tr -dc a-zA-Z0-9 | head -c20) + echo " +spark-host=0.0.0.0 +spark-port=${portprefix}9000 +spark-tls-path=/home/bitcoin/.lightning/spark-tls +spark-login=blitz:$PASSWORD_B +spark-keys=${masterkeythatcandoeverything}; ${secretaccesskeythatcanreadstuff}: getinfo, listchannels, listnodes; ${verysecretkeythatcanpayinvoices}: pay; ${keythatcanlistentoallevents}: stream +" | sudo tee -a ${CLNCONF} + else + echo "# spark is already configured in ${CLNCONF}" + fi + + echo "# Allowing port ${portprefix}9000 through the firewall" + sudo ufw allow "${portprefix}9000" comment "${netprefix}spark" + + # hidden service to https://xx.onion + /home/admin/config.scripts/internet.hiddenservice.sh ${netprefix}spark 443 ${portprefix}9000 + + # setting value in raspi blitz config + sudo sed -i "s/^${netprefix}spark=.*/${netprefix}spark=on/g" /mnt/hdd/raspiblitz.conf + + source /home/admin/raspiblitz.info + if [ "${state}" == "ready" ]; then + echo "# Restart the ${netprefix}lightningd.service to activate spark" + sudo systemctl restart ${netprefix}lightningd + fi + + echo "# spark was installed" + echo "# Monitor with:" + echo "sudo journalctl | grep spark | tail -n5" + echo "sudo tail -n 100 -f /home/bitcoin/.lightning/${CLNETWORK}/cl.log | grep spark" + +fi + +if [ $1 = off ];then + # delete symlink + sudo rm -rf /home/bitcoin/${netprefix}cln-plugins-enabled/spark + + echo "# Editing ${CLNCONF}" + sudo sed -i "/^spark/d" ${CLNCONF} + + echo "# Restart the ${netprefix}lightningd.service to deactivate spark" + sudo systemctl restart ${netprefix}lightningd + + echo "# Deny port ${portprefix}9000 through the firewall" + sudo ufw deny "${portprefix}9000" + + /home/admin/config.scripts/internet.hiddenservice.sh off ${netprefix}spark + + # purge + if [ "$(echo "$@" | grep -c purge)" -gt 0 ];then + echo "# Delete plugin" + sudo rm -rf /home/bitcoin/cln-plugins-available/spark + fi + # setting value in raspi blitz config + sudo sed -i "s/^${netprefix}spark=.*/${netprefix}spark=off/g" /mnt/hdd/raspiblitz.conf + echo "# spark was uninstalled" + +fi diff --git a/home.admin/config.scripts/network.aliases.sh b/home.admin/config.scripts/network.aliases.sh index 21a970ed7..3f9cec1c9 100644 --- a/home.admin/config.scripts/network.aliases.sh +++ b/home.admin/config.scripts/network.aliases.sh @@ -27,8 +27,8 @@ if [ $1 = getvars ];then if [ $# -gt 1 ];then LNTYPE=$2 else - if [ ${#LNdefault} -gt 0 ];then - LNTYPE=${LNdefault} + if [ ${#lightning} -gt 0 ];then + LNTYPE=${lightning} else LNTYPE=lnd fi From b5e10b76c94a1dddc646b133a2e622c65a3fc870 Mon Sep 17 00:00:00 2001 From: openoms Date: Wed, 25 Aug 2021 11:11:25 +0100 Subject: [PATCH 2/2] Tor: fix capitalization in SETTINGS --- home.admin/00settingsMenuBasics.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/home.admin/00settingsMenuBasics.sh b/home.admin/00settingsMenuBasics.sh index a6c3a6191..c4311f543 100755 --- a/home.admin/00settingsMenuBasics.sh +++ b/home.admin/00settingsMenuBasics.sh @@ -75,7 +75,7 @@ echo "run dialog ..." # BASIC MENU INFO OPTIONS=() -OPTIONS+=(t 'Run behind TOR' ${runBehindTor}) +OPTIONS+=(t 'Run behind Tor' ${runBehindTor}) if [ "${displayClass}" == "lcd" ]; then OPTIONS+=(s 'Touchscreen' ${touchscreenMenu}) @@ -277,20 +277,20 @@ else echo "LND AUTONAT Setting unchanged." fi -# TOR process choice +# Tor process choice choice="off"; check=$(echo "${CHOICES}" | grep -c "t") if [ ${check} -eq 1 ]; then choice="on"; fi if [ "${runBehindTor}" != "${choice}" ]; then - echo "TOR Setting changed .." + echo "Tor Setting changed .." - # special actions if TOR is turned on + # special actions if Tor is turned on if [ "${choice}" = "on" ]; then # inform user about privacy risk whiptail --title " PRIVACY NOTICE " --msgbox " -RaspiBlitz will now install/activate TOR & after reboot run behind it. +RaspiBlitz will now install/activate Tor & after reboot run behind it. -Please keep in mind that thru your LND node id & your previous IP history with your internet provider your lightning node could still be linked to your personal id even when running behind TOR. To unlink you from that IP history its recommended that after the switch/reboot to TOR you also use the REPAIR > RESET-LND option to create a fresh LND wallet. That might involve closing all channels & move your funds out of RaspiBlitz before that RESET-LND. +Please keep in mind that thru your LND node id & your previous IP history with your internet provider your lightning node could still be linked to your personal id even when running behind Tor. To unlink you from that IP history its recommended that after the switch/reboot to Tor you also use the REPAIR > RESET-LND option to create a fresh LND wallet. That might involve closing all channels & move your funds out of RaspiBlitz before that RESET-LND. " 16 76 # make sure AutoNAT & UPnP is off @@ -298,13 +298,13 @@ Please keep in mind that thru your LND node id & your previous IP history with y /home/admin/config.scripts/network.upnp.sh off fi - # change TOR + # change Tor anychange=1 sudo /home/admin/config.scripts/internet.tor.sh ${choice} needsReboot=1 else - echo "TOR Setting unchanged." + echo "Tor Setting unchanged." fi # LND Auto-Unlock