diff --git a/home.admin/00mainMenu.sh b/home.admin/00mainMenu.sh index 3c5d92551..e6eff1f56 100755 --- a/home.admin/00mainMenu.sh +++ b/home.admin/00mainMenu.sh @@ -48,10 +48,13 @@ fi if [ "${BTCRPCexplorer}" == "on" ]; then OPTIONS+=(EXPLORE "BTC RPC Explorer") fi +if [ "${LNBits}" == "on" ]; then + OPTIONS+=(LNBITS "LNBits Server") +fi if [ "${lndmanage}" == "on" ]; then OPTIONS+=(LNDMANAGE "LND Manage Script") fi -if [ "${lndmanage}" == "on" ]; then +if [ "${loop}" == "on" ]; then OPTIONS+=(LOOP "Loop In/Out Service") fi @@ -157,6 +160,10 @@ case $CHOICE in /home/admin/config.scripts/bonus.electrs.sh menu ./00mainMenu.sh ;; + LNBITS) + /home/admin/config.scripts/bonus.lnbits.sh menu + ./00mainMenu.sh + ;; LNDMANAGE) /home/admin/config.scripts/bonus.lndmanage.sh menu ./00mainMenu.sh diff --git a/home.admin/00settingsMenuServices.sh b/home.admin/00settingsMenuServices.sh index 531b607cd..2b1ab1225 100644 --- a/home.admin/00settingsMenuServices.sh +++ b/home.admin/00settingsMenuServices.sh @@ -20,6 +20,7 @@ if [ ${#lcdrotate} -eq 0 ]; then lcdrotate=0; fi if [ ${#BTCPayServer} -eq 0 ]; then BTCPayServer="off"; fi if [ ${#ElectRS} -eq 0 ]; then ElectRS="off"; fi if [ ${#lndmanage} -eq 0 ]; then lndmanage="off"; fi +if [ ${#LNBits} -eq 0 ]; then LNBits="off"; fi echo "map chain to on/off" chainValue="off" @@ -71,6 +72,7 @@ r 'LCD Rotate' ${lcdrotateMenu} \ e 'Electrum Rust Server' ${ElectRS} \ p 'BTCPayServer' ${BTCPayServer} \ m 'lndmanage' ${lndmanage} \ +i 'LNBits' ${LNBits} \ 2>&1 >/dev/tty) else CHOICES=$(dialog --title ' Additional Services ' --checklist ' use spacebar to activate/de-activate ' 22 45 14 \ @@ -89,6 +91,7 @@ r 'LCD Rotate' ${lcdrotateMenu} \ e 'Electrum Rust Server' ${ElectRS} \ p 'BTCPayServer' ${BTCPayServer} \ m 'lndmanage' ${lndmanage} \ +i 'LNBits' ${LNBits} \ 2>&1 >/dev/tty) fi @@ -491,6 +494,21 @@ else echo "lndmanage setting unchanged." fi +# LNBits process choice +choice="off"; check=$(echo "${CHOICES}" | grep -c "i") +if [ ${check} -eq 1 ]; then choice="on"; fi +if [ "${LNBits}" != "${choice}" ]; then + echo "LNBits Setting changed .." + anychange=1 + sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh ${choice} + if [ "${choice}" = "on" ]; then + sudo systemctl start lnbits + sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh menu + fi +else + echo "lndmanage 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/XXdebugLogs.sh b/home.admin/XXdebugLogs.sh index 61e297ad8..d48198127 100644 --- a/home.admin/XXdebugLogs.sh +++ b/home.admin/XXdebugLogs.sh @@ -124,6 +124,16 @@ else echo "" fi +if [ "${LNBits}" = "on" ]; then + echo "*** LAST 20 LNBits LOGS ***" + echo "sudo journalctl -u lnbits -b --no-pager -n20" + sudo journalctl -u lnbits -b --no-pager -n20 + echo "" +else + echo "- LNBits is OFF by config" + echo "" +fi + echo "*** HARDWARE TEST RESULTS ***" showImproveInfo=0 if [ ${#undervoltageReports} -gt 0 ]; then diff --git a/home.admin/_bootstrap.provision.sh b/home.admin/_bootstrap.provision.sh index c29df65e1..0baa80048 100644 --- a/home.admin/_bootstrap.provision.sh +++ b/home.admin/_bootstrap.provision.sh @@ -350,6 +350,15 @@ else echo "Provisioning UPS - not active" >> ${logFile} fi +# LNBits +if [ "${LNBits}" = "on" ]; then + echo "Provisioning LNBits - run config script" >> ${logFile} + sudo sed -i "s/^message=.*/message='Setup LNBits '/g" ${infoFile} + sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh on >> ${logFile} 2>&1 +else + echo "Provisioning LNBits - keep default" >> ${logFile} +fi + # replay backup LND conf & tlscerts # https://github.com/rootzoll/raspiblitz/issues/324 echo "" >> ${logFile} diff --git a/home.admin/_bootstrap.sh b/home.admin/_bootstrap.sh index 6f43df257..cb3e98f69 100644 --- a/home.admin/_bootstrap.sh +++ b/home.admin/_bootstrap.sh @@ -431,6 +431,11 @@ if [ ${#network} -gt 0 ] && [ ${#chain} -gt 0 ]; then sudo sh -c "cat /mnt/hdd/lnd/data/chain/${network}/${chain}net/invoice.macaroon > /home/pi/.lnd/data/chain/${network}/${chain}net/invoice.macaroon" 2>> $logFile sudo chown pi:pi -R /home/pi/.lnd 2>> $logFile + if [ "${LNBits}" = "on" ]; then + echo "updating macaroons for LNBits fresh on start" >> $logFile + sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh write-macaroons >> $logFile + fi + else echo "skipping admin user LND data update" >> $logFile fi diff --git a/home.admin/config.scripts/bonus.lnbits.sh b/home.admin/config.scripts/bonus.lnbits.sh new file mode 100644 index 000000000..18c1e4315 --- /dev/null +++ b/home.admin/config.scripts/bonus.lnbits.sh @@ -0,0 +1,215 @@ +#!/bin/bash + +# https://github.com/arcbtc/lnbits + +# command info +if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then + echo "small config script to switch LNBits on or off" + echo "bonus.lnbits.sh [on|off|status|menu|write-macaroons]" + exit 1 +fi + +source /mnt/hdd/raspiblitz.conf + +# show info menu +if [ "$1" = "menu" ]; then + + # get status + echo "# collecting status info ... (please wait)" + source <(sudo /home/admin/config.scripts/bonus.lnbits.sh status) + + # get network info + localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') + toraddress=$(sudo cat /mnt/hdd/tor/lnbits/hostname 2>/dev/null) + + if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then + + # TOR + /home/admin/config.scripts/blitz.lcd.sh qr "${toraddress}" + whiptail --title " LNBits " --msgbox "Open the following URL in your local web browser: +http://${localip}:5000\n +Hidden Service address for TOR Browser (QR see LCD): +${toraddress} +" 11 67 + /home/admin/config.scripts/blitz.lcd.sh hide + else + + # IP + Domain + whiptail --title " LNBits " --msgbox "Open the following URL in your local web browser: +http://${localip}:5000\n +Activate TOR to access from outside your local network. +" 12 54 + fi + + echo "please wait ..." + exit 0 +fi + +# add default value to raspi config if needed +if ! grep -Eq "^LNBits=" /mnt/hdd/raspiblitz.conf; then + echo "LNBits=off" >> /mnt/hdd/raspiblitz.conf +fi + +# status +if [ "$1" = "status" ]; then + + if [ "${LNBits}" = "on" ]; then + echo "installed=1" + + # check for error + isDead=$(sudo systemctl status lnbits | grep -c 'inactive (dead)') + if [ ${isDead} -eq 1 ]; then + echo "error='Service Failed'" + exit 1 + fi + + else + echo "installed=0" + fi + exit 0 +fi + +# status +if [ "$1" = "write-macaroons" ]; then + + # make sure its run as user admin + adminUserId=$(id -u admin) + if [ "${EUID}" != "${adminUserId}" ]; then + echo "error='please run as admin user'" + exit 1 + fi + + # rewrite macaroons for lnbits environment + macaroonAdminHex=$(sudo xxd -ps -u -c 1000 /mnt/hdd/lnd/data/chain/${network}/${chain}net/admin.macaroon) + macaroonInvoiceHex=$(sudo xxd -ps -u -c 1000 /mnt/hdd/lnd/data/chain/${network}/${chain}net/invoice.macaroon) + macaroonReadHex=$(sudo xxd -ps -u -c 1000 /mnt/hdd/lnd/data/chain/${network}/${chain}net/readonly.macaroon) + sudo sed -i "s/^LND_API_ENDPOINT=.*/LND_API_ENDPOINT=https:\/\/127.0.0.1:8080/g" /home/admin/lnbits/.env + sudo sed -i "s/^LND_ADMIN_MACAROON=.*/LND_ADMIN_MACAROON=${macaroonAdminHex}/g" /home/admin/lnbits/.env + sudo sed -i "s/^LND_INVOICE_MACAROON=.*/LND_INVOICE_MACAROON=${macaroonInvoiceHex}/g" /home/admin/lnbits/.env + sudo sed -i "s/^LND_READ_MACAROON=.*/LND_READ_MACAROON=${macaroonReadHex}/g" /home/admin/lnbits/.env + echo "# OK - macaroons written to /home/admin/lnbits/.env" + exit 0 +fi + +# stop service +echo "making sure services are not running" +sudo systemctl stop lnbits 2>/dev/null + +# switch on +if [ "$1" = "1" ] || [ "$1" = "on" ]; then + echo "*** INSTALL LNBits ***" + + isInstalled=$(sudo ls /etc/systemd/system/lnbits.service 2>/dev/null | grep -c 'lnbits.service') + if [ ${isInstalled} -eq 0 ]; then + + # make sure needed debian packages are installed + echo "# installing needed packages" + sudo apt-get install -y pipenv 2>/dev/null + + # prepare .env file + echo "# get the github code" + sudo rm -r /home/admin/lnbits 2>/dev/null + cd /home/admin + sudo -u admin git clone https://github.com/arcbtc/lnbits.git + #sudo -u admin git reset --hard e3fd6b4ff1f19b750b852a0bb0814cd259db948c + + # write macarroons to .env file + echo "# preparing env file" + sudo rm /home/admin/lnbits/.env 2>/dev/null + sudo -u admin mv /home/admin/lnbits/.env.example /home/admin/lnbits/.env + sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh write-macaroons + + # set database path to HDD data so that its survives updates and migrations + sudo mkdir /mnt/hdd/app-data/LNBits 2>/dev/null + sudo chown admin:admin /mnt/hdd/app-data/LNBits + echo "LNBITS_DATA_FOLDER=/mnt/hdd/app-data/LNBits" >> /home/admin/lnbits/.env + + # make sure in settings file LND is set as funding source + cat > /home/admin/lnbits/lnbits/settings.py < /home/admin/lnbits.service <