raspiblitz/home.admin/config.scripts/bonus.lnbits.sh

443 lines
15 KiB
Bash
Raw Normal View History

2020-02-10 12:33:03 +01:00
#!/bin/bash
2020-05-02 19:56:30 +02:00
# https://github.com/lnbits/lnbits
2020-02-10 12:33:03 +01:00
# 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 [?GITHUBUSER] [?BRANCH]"
echo "bonus.lnbits.sh [off|status|menu|write-macaroons]"
echo "# DEVELOPMENT: TO SYNC WITH YOUR FORKED GITHUB-REPO"
echo "bonus.lnbits.sh github repo [GITHUBUSER] [?BRANCH]"
echo "bonus.lnbits.sh github sync"
exit 1
2020-02-10 12:33:03 +01:00
fi
2020-04-28 18:01:50 +02:00
source /mnt/hdd/raspiblitz.conf
2020-02-10 12:33:03 +01:00
# show info menu
if [ "$1" = "menu" ]; then
2020-07-14 21:04:14 +02:00
# get LNbits status info
2020-02-10 12:33:03 +01:00
echo "# collecting status info ... (please wait)"
source <(sudo /home/admin/config.scripts/bonus.lnbits.sh status)
# display possible problems with IP2TOR setup
if [ ${#ip2torWarn} -gt 0 ]; then
whiptail --title " Warning " \
--yes-button "Back" \
--no-button "Continue Anyway" \
--yesno "Your IP2TOR+LetsEncrypt may have problems:\n${ip2torWarn}\n\nCheck if locally responding: https://${localIP}:${httpsPort}\n\nCheck if service is reachable over Tor:\n${toraddress}" 14 72
if [ "$?" != "1" ]; then
exit 0
fi
fi
text="Local Webrowser: https://${localIP}:${httpsPort}"
2020-07-14 21:04:14 +02:00
if [ ${#publicDomain} -gt 0 ]; then
text="${text}
Public Domain: https://${publicDomain}:${httpsPort}
port forwarding on router needs to be active & may change port"
fi
text="${text}\n
You need to accept self-signed HTTPS cert with SHA1 Fingerprint:
${sslFingerprintIP}"
2020-02-10 12:33:03 +01:00
2020-07-14 21:04:14 +02:00
if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then
2021-04-08 00:02:57 +02:00
/home/admin/config.scripts/blitz.display.sh qr "${toraddress}"
2020-07-14 21:04:14 +02:00
text="${text}\n
2020-07-14 21:17:05 +02:00
TOR Browser Hidden Service address (QR see LCD):
2020-07-14 21:04:14 +02:00
${toraddress}"
fi
if [ ${#ip2torDomain} -gt 0 ]; then
2020-07-14 23:06:09 +02:00
text="${text}\n
2020-07-14 21:04:14 +02:00
IP2TOR+LetsEncrypt: https://${ip2torDomain}:${ip2torPort}
2020-07-14 23:06:09 +02:00
SHA1 ${sslFingerprintTOR}"
2020-07-14 21:04:14 +02:00
elif [ ${#ip2torIP} -gt 0 ]; then
2020-07-14 22:56:20 +02:00
text="${text}\n
2020-07-14 21:04:14 +02:00
IP2TOR: https://${ip2torIP}:${ip2torPort}
2020-07-14 21:11:59 +02:00
SHA1 ${sslFingerprintTOR}
2020-07-14 21:04:14 +02:00
go MAINMENU > SUBSCRIBE and add LetsEncrypt HTTPS Domain"
elif [ ${#publicDomain} -eq 0 ]; then
2020-07-14 21:10:19 +02:00
text="${text}\n
2020-08-12 09:44:49 +02:00
To enable easy reachability with normal browser from the outside
2020-07-14 21:17:05 +02:00
consider adding a IP2TOR Bridge (MAINMENU > SUBSCRIBE)."
2020-02-10 12:33:03 +01:00
fi
whiptail --title " LNbits " --msgbox "${text}" 16 69
2020-07-14 21:04:14 +02:00
2021-04-08 00:02:57 +02:00
/home/admin/config.scripts/blitz.display.sh hide
2020-02-10 12:33:03 +01:00
echo "please wait ..."
exit 0
fi
# add default value to raspi config if needed
2020-04-23 23:21:32 +02:00
if ! grep -Eq "^LNBits=" /mnt/hdd/raspiblitz.conf; then
echo "LNBits=off" >> /mnt/hdd/raspiblitz.conf
2020-02-10 12:33:03 +01:00
fi
# status
if [ "$1" = "status" ]; then
2020-04-23 23:08:14 +02:00
if [ "${LNBits}" = "on" ]; then
2020-02-10 12:33:03 +01:00
echo "installed=1"
merging pre-1.7.1 (#2462) * fix copychain returns * typo in sync loop * stop services on inconsistent state * calling correct provisioning * apply bitcoin and lncli aliases in all scripts * network.aliases: add CLNETWORK * make cln default plugin dir: cln-plugins-enabled similar to the nginx model make 2 directories for plugins: cln-plugins-enabled - symlinked to ~/.lightning/plugins plugins from here are loaded automatically on cln start cln-plugins-available: plugins are downloaded here to be run until the next cln restart (or stopped with runonce) note the disk is mounted with noexec so plugins can't run from there discuss in: https://github.com/rootzoll/raspiblitz/issues/2295 * move shutdown script * change all place where shutdown script is used * change notify & release * moved shutdown script * moved shutdown scripts * add more debug info * moving github script * remove chain in sync * no longer needed chain in sync * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * avoid scrolling in menus * use new selfsignedcert if no lnd tls.cert present * sparko: add info and connect menu with own cert https://github.com/rootzoll/raspiblitz/issues/2295 * cln.rest: add connect option for Zeus https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add the backup plugin + options Usage options: cln-plugin.backup.sh [on] [testnet|mainnet|signet] cln-plugin.backup.sh [restore] [testnet|mainnet|signet] [force] cln-plugin.backup.sh [backup-compact] [testnet|mainnet|signet] https://github.com/lightningd/plugins/tree/master/backup Discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add cln-plugin.standard.python.sh Install and show the output of the chosen plugin for C-lightning Usage: cln-plugin.standard-python.sh on [plugin-name] [testnet|mainnet|signet] [runonce] tested plugins: summary | helpme | feeadjuster find more at: https://github.com/lightningd/plugins discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * shellcheck: change all `egrep` to `grep -E` https://github.com/koalaman/shellcheck/wiki/SC2196 * do not resolve aliases, use as variables * lnd: fix lnd.conf for parallel networks discussed in: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: add LND option for parallel networks * deprecate Testnet in SETTINGS keysend and autopilot only for mainnet due to: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: autopilot and autounlock for testnet * fix comments * add the SYSTEM menu for parallel chains * RTL update to v0.11.0 make chain specific directory for the config: /home/rtl/${netprefix}RTL/ use ${netprefix}lnd.conf in config override Environmen tvaribales for cln in the systemd service: /etc/systemd/system/${netprefix}${typeprefix}RTL.service discussed in: https://github.com/rootzoll/raspiblitz/issues/2384 * lnd.setname.sh for testnet * display ${CHAIN} in the SYSTEM menu options * keep _aliases file when live patches are applied * all lncli_aliases to be used as variables * default to KIllMode=control-group in services https://www.man7.org/linux/man-pages/man5/systemd.kill.5.html discussed in: https://github.com/rootzoll/raspiblitz/issues/1901 * add cln.hsmtool.sh for hsm_secret handling encrypt | decrypt | autounlock the hsm_secret for C-lightning usage: cln.hsmtool.sh [unlock] [testnet|mainnet|signet] cln.hsmtool.sh [encrypt|decrypt] [testnet|mainnet|signet] cln.hsmtool.sh [autounlock-on|autounlock-off] [testnet|mainnet|signet] discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * add cln.install-service.sh to set up cln with systemd script to set up or update the CLN systemd service checks for hsm_secret encryption, autounlock and the sparko plugin usage: /home/admin/config.scripts/cln.install-service.sh $CHAIN discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * use symlink to cln-plugins-enabled for all plugins * keep lnd autopilot and autounlock mainnet only mainnet only settings: lnd autopilot lnd keysend circuibreaker lnd autounlock StaticChannelBackup to DropBox and USB * cln FUNDING fix parsing address * cln.hsmtool: add change-password and lock options * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * #1126 preparing new setup with new c-lightning (#2396) * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * lnd.unlock: fix typo * netwok.monitor.sh debug * cln-plugin.summary: fix paths * rtl: fix permission of config on copy * CASHOUT: use aliases for lnd * rtl: install correctly for paralell chains * use CHAIN in CLN and LND menu * cln: add CASHOUT option * CLOSEALL and CASHOUT: Improve labels and comments Explaining CASHOUT in the label as discussed in: https://github.com/rootzoll/raspiblitz/issues/2358 * cln.install: fix tor config * cln: installthe latest master until the next release * _commands: source _aliases only if exists * network aliases: fall back to 'main' for 'chain' * new setup: keep testnet3 blocks and chainstate * new setup: improve capitalization in menu * improve help and comments * cln: install Sparko if configured, but not present * cln: add new wallet and import seed options * fix peernum * make sure that aliases get created on lnd setup * no error if aliases not yet exist * debug state * fix network alias when not set * fix syntax error * add debug error info * mute unlocking echos * add debug wait * add debug wait * make sure info is uptodate * make alias info as defaults * rename option * update sync info for no lightning * add action string * update sync info * move name dialog * wait for sync progress info * wait for syncprogress info * fix syntax * get fresh data * make sure to disable lnd * add c-lightning to debug * add setup logs to debug output * fix syntax error * add new-force wallet * try fix call hsmtool * hsm output tool * fix output * add seed-force * refactor blitz.mnemonic.py * test seed * debug info * dump object * try check * correct putput * fix syntax * check lnd for valid seed * fix gui * add Suez install script discussed in: https://github.com/rootzoll/raspiblitz/issues/2366 * cln rescue file export * get correct version * add cln export gui * cln.backup.sh cln-import * correct bytesize * generate cln wallet with passwordc * fix syntax * fix syntax * mute not needed error msg * PEERING: correct message on success * cln.install-service: fix sparko check * add Suez to menu for CLN and LND needs to be installed with the bitcoin user to be able to interact with CLN related: https://github.com/rootzoll/raspiblitz/issues/2366 * debug _provison.setup.sh stop bitcoind and restart with new config to avoid rpc password error disable and enable service instead of daemon-reload CLN: don't use passwordC as seedPassword * add cln.setname.sh make lnd.setname.sh work with parallel wallets * improve comments * SYSTEM: add CLNLOG and CLNCONF options * SYSTEM menu fixes * cln: add more aliases cln, clnlog, clnconf * cln: activate the backup plugin on every install * SERVICES menu: fix chantools/CLN switch * cln: load plugins from ${netprefix}cln-plugins-enabled changed the config paths to $lightning-dir/config or /networkname/config plugins are downloaded to the SDcard: /home/bitcoin/cln-plugins-available/ symlinked and loaded automatically from: /home/bitcoin/${netprefix}cln-plugins-enabled Related: #2295 * sparko: don't show logs after install * #2425 Adding experimental Blitz WebUI & API (#2426) * no password C & D when cln * add debug echos * set defaults before * #2228 wider grep to detect nvms (#2427) * cln.hsmtool: init backup with the new wallet * cln.install: fix access to raspiblitz.conf * cln-plugin.backup: fix path to backup-cli * cln: hide unhelpful warnings during setup * remove old jinja template rendering * fix lnd unlock detection * cln: look for files in .lightning dir with sudo * cln: correct lightning name in FInalDialog + typo * cln: make sure .lightning/bitcoin dir exists * FinalDialog: make the 24 words fit * cln.install.sh: create cln config if not present * Simplify localIP detection and improve compatibility (#2432) * show tail info on provision * only show lnd options when activated * fix syntax * only show main lightning impl options for RC1 * cln: always start the lightnind.service * cln: clear before showing summary * start cln on the end of provisioning * exit 0 on cln menu * press key after single actions * remove key press on cln actions * change to none * detect cln running * fix syntax * fix lightniing info * add TODO for CLN * add clnblockheight * zty with user bitcoin * check synced to chain for cln * fix increment * try scanprogress * use cln sync detection and progress * replace LNTYPE * next line * fix spaces * fix spaces * Update README.md (#2456) Fix 404 * Fix FAQ links (#2441) * Fix invalid URL ( (#2440) * support channels (#2382) * use #2370 height optimization * adjust exit codes in menu scripts * adjust password menu exit codes * adapt shutdown for cln * settings adapt to running lightning impl * fix syntax * debug info * add debug * better height * add default values * add config entry if not there yet * change default value * Added exit info for cln * make sure to load config file if available * add sparko to menu * add default for sparko * replace default sparko entry * show sparko installed or not * add more description to sparko option * RTL for clightnign in service menu * main menu item rtl * add RTL description * debug in RTL install * install sparko on recovery * update menu with cln * rework menu options Co-authored-by: openoms <oms@tuta.io> Co-authored-by: openoms <43343391+openoms@users.noreply.github.com> Co-authored-by: rek79 <rek79@users.noreply.github.com> Co-authored-by: Bitpaint <67663265+bitpaint@users.noreply.github.com> Co-authored-by: João Thallis <joaothallis@icloud.com> Co-authored-by: Peter Flock <78184669+peterflock@users.noreply.github.com> Co-authored-by: nyxnor <nyxnor@protonmail.com>
2021-08-04 00:18:30 +02:00
localIP=$(hostname -I | awk '{print $1}')
2020-07-14 20:29:33 +02:00
echo "localIP='${localIP}'"
echo "httpPort='5000'"
2020-07-14 20:29:33 +02:00
echo "httpsPort='5001'"
echo "publicIP='${publicIP}'"
# check for LetsEnryptDomain for DynDns
error=""
source <(sudo /home/admin/config.scripts/blitz.subscriptions.ip2tor.py ip-by-tor $publicIP)
if [ ${#error} -eq 0 ]; then
echo "publicDomain='${domain}'"
fi
2020-07-14 20:35:37 +02:00
sslFingerprintIP=$(openssl x509 -in /mnt/hdd/app-data/nginx/tls.cert -fingerprint -noout 2>/dev/null | cut -d"=" -f2)
2020-07-14 20:29:33 +02:00
echo "sslFingerprintIP='${sslFingerprintIP}'"
toraddress=$(sudo cat /mnt/hdd/tor/lnbits/hostname 2>/dev/null)
echo "toraddress='${toraddress}'"
2020-07-14 20:35:37 +02:00
sslFingerprintTOR=$(openssl x509 -in /mnt/hdd/app-data/nginx/tor_tls.cert -fingerprint -noout 2>/dev/null | cut -d"=" -f2)
2020-07-14 20:29:33 +02:00
echo "sslFingerprintTOR='${sslFingerprintTOR}'"
# check for IP2TOR
error=""
source <(sudo /home/admin/config.scripts/blitz.subscriptions.ip2tor.py ip-by-tor $toraddress)
if [ ${#error} -eq 0 ]; then
echo "ip2torType='${ip2tor-v1}'"
2020-07-14 20:36:04 +02:00
echo "ip2torID='${id}'"
2020-07-14 20:29:33 +02:00
echo "ip2torIP='${ip}'"
echo "ip2torPort='${port}'"
# check for LetsEnryptDomain on IP2TOR
error=""
source <(sudo /home/admin/config.scripts/blitz.subscriptions.letsencrypt.py domain-by-ip $ip)
if [ ${#error} -eq 0 ]; then
echo "ip2torDomain='${domain}'"
domainWarning=$(sudo /home/admin/config.scripts/blitz.subscriptions.letsencrypt.py subscription-detail ${domain} ${port} | jq -r ".warning")
if [ ${#domainWarning} -gt 0 ]; then
echo "ip2torWarn='${domainWarning}'"
fi
2020-07-14 20:29:33 +02:00
fi
fi
2020-02-10 12:33:03 +01:00
# 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
2020-02-10 12:33:03 +01:00
# make sure its run as user admin
adminUserId=$(id -u admin)
2020-02-10 12:47:33 +01:00
if [ "${EUID}" != "${adminUserId}" ]; then
2020-02-10 12:33:03 +01:00
echo "error='please run as admin user'"
exit 1
fi
2020-05-01 11:15:32 +02:00
echo "make sure symlink to central app-data directory exists"
if ! [[ -L "/home/lnbits/.lnd" ]]; then
sudo rm -rf "/home/lnbits/.lnd" # not a symlink.. delete it silently
sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/lnbits/.lnd" # and create symlink
fi
# set tls.cert path (use | as separator to avoid escaping file path slashes)
sudo -u lnbits sed -i "s|^LND_REST_CERT=.*|LND_REST_CERT=/home/lnbits/.lnd/tls.cert|g" /home/lnbits/lnbits/.env
2020-05-01 11:15:32 +02:00
# set macaroon path info in .env - USING HEX IMPORT
sudo chmod 600 /home/lnbits/lnbits/.env
2020-05-04 15:32:18 +02:00
macaroonAdminHex=$(sudo xxd -ps -u -c 1000 /home/lnbits/.lnd/data/chain/${network}/${chain}net/admin.macaroon)
macaroonInvoiceHex=$(sudo xxd -ps -u -c 1000 /home/lnbits/.lnd/data/chain/${network}/${chain}net/invoice.macaroon)
macaroonReadHex=$(sudo xxd -ps -u -c 1000 /home/lnbits/.lnd/data/chain/${network}/${chain}net/readonly.macaroon)
sudo sed -i "s/^LND_REST_ADMIN_MACAROON=.*/LND_REST_ADMIN_MACAROON=${macaroonAdminHex}/g" /home/lnbits/lnbits/.env
sudo sed -i "s/^LND_REST_INVOICE_MACAROON=.*/LND_REST_INVOICE_MACAROON=${macaroonInvoiceHex}/g" /home/lnbits/lnbits/.env
sudo sed -i "s/^LND_REST_READ_MACAROON=.*/LND_REST_READ_MACAROON=${macaroonReadHex}/g" /home/lnbits/lnbits/.env
#echo "make sure lnbits is member of lndreadonly, lndinvoice, lndadmin"
#sudo /usr/sbin/usermod --append --groups lndinvoice lnbits
#sudo /usr/sbin/usermod --append --groups lndreadonly lnbits
#sudo /usr/sbin/usermod --append --groups lndadmin lnbits
2020-05-04 15:32:18 +02:00
# set macaroon path info in .env - USING PATH
#sudo sed -i "s|^LND_REST_ADMIN_MACAROON=.*|LND_REST_ADMIN_MACAROON=/home/lnbits/.lnd/data/chain/${network}/${chain}net/admin.macaroon|g" /home/lnbits/lnbits/.env
#sudo sed -i "s|^LND_REST_INVOICE_MACAROON=.*|LND_REST_INVOICE_MACAROON=/home/lnbits/.lnd/data/chain/${network}/${chain}net/invoice.macaroon|g" /home/lnbits/lnbits/.env
#sudo sed -i "s|^LND_REST_READ_MACAROON=.*|LND_REST_READ_MACAROON=/home/lnbits/.lnd/data/chain/${network}/${chain}net/read.macaroon|g" /home/lnbits/lnbits/.env
echo "# OK - macaroons written to /home/lnbits/lnbits/.env"
2020-02-10 12:33:03 +01:00
exit 0
fi
if [ "$1" = "repo" ]; then
# get github parameters
githubUser="$2"
if [ ${#githubUser} -eq 0 ]; then
echo "echo='missing parameter'"
exit 1
fi
githubBranch="$3"
if [ ${#githubBranch} -eq 0 ]; then
githubBranch="master"
fi
# check if repo exists
githubRepo="https://github.com/${githubUser}/lnbits"
httpcode=$(curl -s -o /dev/null -w "%{http_code}" ${githubRepo})
if [ "${httpcode}" != "200" ]; then
echo "# tested github repo: ${githubRepo}"
echo "error='repo for user does not exist'"
exit 1
fi
# change origin repo of lnbits code
echo "# changing LNbits github repo(${githubUser}) branch(${githubBranch})"
cd /home/lnbits/lnbits
sudo git remote remove origin
sudo git remote add origin ${githubRepo}
sudo git fetch
sudo git checkout ${githubBranch}
sudo git branch --set-upstream-to=origin/${githubBranch} ${githubBranch}
fi
if [ "$1" = "sync" ] || [ "$1" = "repo" ]; then
echo "# pull all changes from github repo"
# output basic info
cd /home/lnbits/lnbits
sudo git remote -v
sudo git branch -v
# pull latest code
sudo git pull
# restart lnbits service
sudo systemctl restart lnbits
echo "# server is restarting ... maybe takes some seconds until available"
exit 0
fi
2020-02-10 12:33:03 +01:00
# 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 ***"
2020-02-10 12:33:03 +01:00
isInstalled=$(sudo ls /etc/systemd/system/lnbits.service 2>/dev/null | grep -c 'lnbits.service')
if [ ${isInstalled} -eq 0 ]; then
2020-04-28 09:27:03 +01:00
echo "*** Add the 'lnbits' user ***"
sudo adduser --disabled-password --gecos "" lnbits
2020-02-10 12:33:03 +01:00
# make sure needed debian packages are installed
echo "# installing needed packages"
# get optional github parameter
githubUser="lnbits"
if [ "$2" != "" ]; then
githubUser="$2"
fi
githubBranch="tags/raspiblitz"
#githubBranch="f6bcff01f4b62ca26177f22bd2d479b01d371406"
if [ "$3" != "" ]; then
githubBranch="$3"
fi
2020-02-10 12:33:03 +01:00
# install from GitHub
echo "# get the github code user(${githubUser}) branch(${githubBranch})"
2020-04-28 09:27:03 +01:00
sudo rm -r /home/lnbits/lnbits 2>/dev/null
cd /home/lnbits
sudo -u lnbits git clone https://github.com/${githubUser}/lnbits.git
2020-04-28 09:27:03 +01:00
cd /home/lnbits/lnbits
sudo -u lnbits git checkout ${githubBranch}
# prepare .env file
2020-02-10 12:33:03 +01:00
echo "# preparing env file"
2020-04-28 09:27:03 +01:00
sudo rm /home/lnbits/lnbits/.env 2>/dev/null
sudo -u lnbits touch /home/lnbits/lnbits/.env
sudo bash -c "echo 'QUART_APP=lnbits.app:create_app()' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LNBITS_FORCE_HTTPS=0' >> /home/lnbits/lnbits/.env"
2020-05-02 19:56:30 +02:00
sudo bash -c "echo 'LNBITS_BACKEND_WALLET_CLASS=LndRestWallet' >> /home/lnbits/lnbits/.env"
2020-05-02 19:54:57 +01:00
sudo bash -c "echo 'LND_REST_ENDPOINT=https://127.0.0.1:8080' >> /home/lnbits/lnbits/.env"
2020-05-02 19:56:30 +02:00
sudo bash -c "echo 'LND_REST_CERT=' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LND_REST_ADMIN_MACAROON=' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LND_REST_INVOICE_MACAROON=' >> /home/lnbits/lnbits/.env"
sudo bash -c "echo 'LND_REST_READ_MACAROON=' >> /home/lnbits/lnbits/.env"
2020-04-28 09:27:03 +01:00
/home/admin/config.scripts/bonus.lnbits.sh write-macaroons
2020-02-10 21:07:24 +01:00
# set database path to HDD data so that its survives updates and migrations
2020-04-23 08:07:49 +02:00
sudo mkdir /mnt/hdd/app-data/LNBits 2>/dev/null
2020-04-28 09:27:03 +01:00
sudo chown lnbits:lnbits -R /mnt/hdd/app-data/LNBits
sudo bash -c "echo 'LNBITS_DATA_FOLDER=/mnt/hdd/app-data/LNBits' >> /home/lnbits/lnbits/.env"
2020-02-10 12:33:03 +01:00
2020-02-10 14:29:28 +01:00
# to the install
2020-04-24 06:52:33 +02:00
echo "# installing application dependencies"
2020-04-28 09:27:03 +01:00
cd /home/lnbits/lnbits
# do install like this
sudo -u lnbits python3 -m venv venv
#sudo -u lnbits /home/lnbits/lnbits/venv/bin/pip install hypercorn
sudo -u lnbits ./venv/bin/pip install -r requirements.txt
# process assets
echo "# processing assets"
sudo -u lnbits ./venv/bin/quart assets
2020-07-22 21:20:34 +02:00
# update databases (if needed)
2020-04-24 06:52:33 +02:00
echo "# updating databases"
sudo -u lnbits ./venv/bin/quart migrate
2020-02-10 12:33:03 +01:00
# open firewall
2020-02-10 13:15:18 +01:00
echo
2020-02-10 12:33:03 +01:00
echo "*** Updating Firewall ***"
sudo ufw allow 5000 comment 'lnbits HTTP'
sudo ufw allow 5001 comment 'lnbits HTTPS'
2020-02-10 12:33:03 +01:00
echo ""
# install service
2020-02-10 14:29:28 +01:00
echo "*** Install systemd ***"
2020-05-23 22:17:00 +01:00
cat <<EOF | sudo tee /etc/systemd/system/lnbits.service >/dev/null
2020-02-10 18:16:55 +01:00
# systemd unit for lnbits
2020-02-10 12:33:03 +01:00
[Unit]
Description=lnbits
Wants=lnd.service
After=lnd.service
[Service]
2020-04-28 09:27:03 +01:00
WorkingDirectory=/home/lnbits/lnbits
ExecStart=/bin/sh -c 'cd /home/lnbits/lnbits && ./venv/bin/hypercorn -k trio --bind 0.0.0.0:5000 "lnbits.app:create_app()"'
2020-04-28 09:27:03 +01:00
User=lnbits
2020-02-10 12:33:03 +01:00
Restart=always
TimeoutSec=120
RestartSec=30
StandardOutput=null
StandardError=journal
2020-02-10 18:40:53 +01:00
merging pre-1.7.1 (#2462) * fix copychain returns * typo in sync loop * stop services on inconsistent state * calling correct provisioning * apply bitcoin and lncli aliases in all scripts * network.aliases: add CLNETWORK * make cln default plugin dir: cln-plugins-enabled similar to the nginx model make 2 directories for plugins: cln-plugins-enabled - symlinked to ~/.lightning/plugins plugins from here are loaded automatically on cln start cln-plugins-available: plugins are downloaded here to be run until the next cln restart (or stopped with runonce) note the disk is mounted with noexec so plugins can't run from there discuss in: https://github.com/rootzoll/raspiblitz/issues/2295 * move shutdown script * change all place where shutdown script is used * change notify & release * moved shutdown script * moved shutdown scripts * add more debug info * moving github script * remove chain in sync * no longer needed chain in sync * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * avoid scrolling in menus * use new selfsignedcert if no lnd tls.cert present * sparko: add info and connect menu with own cert https://github.com/rootzoll/raspiblitz/issues/2295 * cln.rest: add connect option for Zeus https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add the backup plugin + options Usage options: cln-plugin.backup.sh [on] [testnet|mainnet|signet] cln-plugin.backup.sh [restore] [testnet|mainnet|signet] [force] cln-plugin.backup.sh [backup-compact] [testnet|mainnet|signet] https://github.com/lightningd/plugins/tree/master/backup Discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * cln: add cln-plugin.standard.python.sh Install and show the output of the chosen plugin for C-lightning Usage: cln-plugin.standard-python.sh on [plugin-name] [testnet|mainnet|signet] [runonce] tested plugins: summary | helpme | feeadjuster find more at: https://github.com/lightningd/plugins discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * shellcheck: change all `egrep` to `grep -E` https://github.com/koalaman/shellcheck/wiki/SC2196 * do not resolve aliases, use as variables * lnd: fix lnd.conf for parallel networks discussed in: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: add LND option for parallel networks * deprecate Testnet in SETTINGS keysend and autopilot only for mainnet due to: https://github.com/rootzoll/raspiblitz/issues/2290 * lnd: autopilot and autounlock for testnet * fix comments * add the SYSTEM menu for parallel chains * RTL update to v0.11.0 make chain specific directory for the config: /home/rtl/${netprefix}RTL/ use ${netprefix}lnd.conf in config override Environmen tvaribales for cln in the systemd service: /etc/systemd/system/${netprefix}${typeprefix}RTL.service discussed in: https://github.com/rootzoll/raspiblitz/issues/2384 * lnd.setname.sh for testnet * display ${CHAIN} in the SYSTEM menu options * keep _aliases file when live patches are applied * all lncli_aliases to be used as variables * default to KIllMode=control-group in services https://www.man7.org/linux/man-pages/man5/systemd.kill.5.html discussed in: https://github.com/rootzoll/raspiblitz/issues/1901 * add cln.hsmtool.sh for hsm_secret handling encrypt | decrypt | autounlock the hsm_secret for C-lightning usage: cln.hsmtool.sh [unlock] [testnet|mainnet|signet] cln.hsmtool.sh [encrypt|decrypt] [testnet|mainnet|signet] cln.hsmtool.sh [autounlock-on|autounlock-off] [testnet|mainnet|signet] discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * add cln.install-service.sh to set up cln with systemd script to set up or update the CLN systemd service checks for hsm_secret encryption, autounlock and the sparko plugin usage: /home/admin/config.scripts/cln.install-service.sh $CHAIN discussed in: https://github.com/rootzoll/raspiblitz/issues/2295 * use symlink to cln-plugins-enabled for all plugins * keep lnd autopilot and autounlock mainnet only mainnet only settings: lnd autopilot lnd keysend circuibreaker lnd autounlock StaticChannelBackup to DropBox and USB * cln FUNDING fix parsing address * cln.hsmtool: add change-password and lock options * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * #1126 preparing new setup with new c-lightning (#2396) * move debug script * patch patch command * make sure setup file is sourced * remove debug output * make sure lnd is put behind tor * change indent * get fresh sync progress * always set password A * cached peer info * fix printing cache * fix check for existing files * handle bitcoind not running * result with newline * test line break * test new line * test new line * two vars on output * #2388 improve online check (less pinging) * used cached peer status * move chache * cach file permissions * allow sudo call * fix cache * remove double scan info * add conf info to sync screen * reorder info * add space * add space * order info * internet suppress error messages * order info * fix offering Blockchain copy * fix hostname * final ready state info * lnd unlock after provision * remove debug exit * harmonize ready state * add status to lnd unlock * update lnd unlock script * edit the unlock * remove debug echo * add debug * add debug * fix if statement * debug output * switch position of source setupdata * lnd.unlock: fix typo * netwok.monitor.sh debug * cln-plugin.summary: fix paths * rtl: fix permission of config on copy * CASHOUT: use aliases for lnd * rtl: install correctly for paralell chains * use CHAIN in CLN and LND menu * cln: add CASHOUT option * CLOSEALL and CASHOUT: Improve labels and comments Explaining CASHOUT in the label as discussed in: https://github.com/rootzoll/raspiblitz/issues/2358 * cln.install: fix tor config * cln: installthe latest master until the next release * _commands: source _aliases only if exists * network aliases: fall back to 'main' for 'chain' * new setup: keep testnet3 blocks and chainstate * new setup: improve capitalization in menu * improve help and comments * cln: install Sparko if configured, but not present * cln: add new wallet and import seed options * fix peernum * make sure that aliases get created on lnd setup * no error if aliases not yet exist * debug state * fix network alias when not set * fix syntax error * add debug error info * mute unlocking echos * add debug wait * add debug wait * make sure info is uptodate * make alias info as defaults * rename option * update sync info for no lightning * add action string * update sync info * move name dialog * wait for sync progress info * wait for syncprogress info * fix syntax * get fresh data * make sure to disable lnd * add c-lightning to debug * add setup logs to debug output * fix syntax error * add new-force wallet * try fix call hsmtool * hsm output tool * fix output * add seed-force * refactor blitz.mnemonic.py * test seed * debug info * dump object * try check * correct putput * fix syntax * check lnd for valid seed * fix gui * add Suez install script discussed in: https://github.com/rootzoll/raspiblitz/issues/2366 * cln rescue file export * get correct version * add cln export gui * cln.backup.sh cln-import * correct bytesize * generate cln wallet with passwordc * fix syntax * fix syntax * mute not needed error msg * PEERING: correct message on success * cln.install-service: fix sparko check * add Suez to menu for CLN and LND needs to be installed with the bitcoin user to be able to interact with CLN related: https://github.com/rootzoll/raspiblitz/issues/2366 * debug _provison.setup.sh stop bitcoind and restart with new config to avoid rpc password error disable and enable service instead of daemon-reload CLN: don't use passwordC as seedPassword * add cln.setname.sh make lnd.setname.sh work with parallel wallets * improve comments * SYSTEM: add CLNLOG and CLNCONF options * SYSTEM menu fixes * cln: add more aliases cln, clnlog, clnconf * cln: activate the backup plugin on every install * SERVICES menu: fix chantools/CLN switch * cln: load plugins from ${netprefix}cln-plugins-enabled changed the config paths to $lightning-dir/config or /networkname/config plugins are downloaded to the SDcard: /home/bitcoin/cln-plugins-available/ symlinked and loaded automatically from: /home/bitcoin/${netprefix}cln-plugins-enabled Related: #2295 * sparko: don't show logs after install * #2425 Adding experimental Blitz WebUI & API (#2426) * no password C & D when cln * add debug echos * set defaults before * #2228 wider grep to detect nvms (#2427) * cln.hsmtool: init backup with the new wallet * cln.install: fix access to raspiblitz.conf * cln-plugin.backup: fix path to backup-cli * cln: hide unhelpful warnings during setup * remove old jinja template rendering * fix lnd unlock detection * cln: look for files in .lightning dir with sudo * cln: correct lightning name in FInalDialog + typo * cln: make sure .lightning/bitcoin dir exists * FinalDialog: make the 24 words fit * cln.install.sh: create cln config if not present * Simplify localIP detection and improve compatibility (#2432) * show tail info on provision * only show lnd options when activated * fix syntax * only show main lightning impl options for RC1 * cln: always start the lightnind.service * cln: clear before showing summary * start cln on the end of provisioning * exit 0 on cln menu * press key after single actions * remove key press on cln actions * change to none * detect cln running * fix syntax * fix lightniing info * add TODO for CLN * add clnblockheight * zty with user bitcoin * check synced to chain for cln * fix increment * try scanprogress * use cln sync detection and progress * replace LNTYPE * next line * fix spaces * fix spaces * Update README.md (#2456) Fix 404 * Fix FAQ links (#2441) * Fix invalid URL ( (#2440) * support channels (#2382) * use #2370 height optimization * adjust exit codes in menu scripts * adjust password menu exit codes * adapt shutdown for cln * settings adapt to running lightning impl * fix syntax * debug info * add debug * better height * add default values * add config entry if not there yet * change default value * Added exit info for cln * make sure to load config file if available * add sparko to menu * add default for sparko * replace default sparko entry * show sparko installed or not * add more description to sparko option * RTL for clightnign in service menu * main menu item rtl * add RTL description * debug in RTL install * install sparko on recovery * update menu with cln * rework menu options Co-authored-by: openoms <oms@tuta.io> Co-authored-by: openoms <43343391+openoms@users.noreply.github.com> Co-authored-by: rek79 <rek79@users.noreply.github.com> Co-authored-by: Bitpaint <67663265+bitpaint@users.noreply.github.com> Co-authored-by: João Thallis <joaothallis@icloud.com> Co-authored-by: Peter Flock <78184669+peterflock@users.noreply.github.com> Co-authored-by: nyxnor <nyxnor@protonmail.com>
2021-08-04 00:18:30 +02:00
# Hardening measures
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
2020-02-10 18:40:53 +01:00
[Install]
WantedBy=multi-user.target
2020-02-10 12:33:03 +01:00
EOF
sudo systemctl enable lnbits
2020-07-19 17:56:00 +02:00
source /home/admin/raspiblitz.info
if [ "${state}" == "ready" ]; then
2020-07-19 17:56:39 +02:00
echo "# OK - lnbits service is enabled, system is on ready so starting lnbits service"
2020-07-19 17:56:00 +02:00
sudo systemctl start lnbits
else
echo "# OK - lnbits service is enabled, but needs reboot or manual starting: sudo systemctl start lnbits"
fi
2020-02-10 12:33:03 +01:00
else
echo "LNbits already installed."
2020-02-10 12:33:03 +01:00
fi
2020-05-23 22:34:03 +01:00
# setup nginx symlinks
if ! [ -f /etc/nginx/sites-available/lnbits_ssl.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/lnbits_ssl.conf /etc/nginx/sites-available/lnbits_ssl.conf
fi
if ! [ -f /etc/nginx/sites-available/lnbits_tor.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/lnbits_tor.conf /etc/nginx/sites-available/lnbits_tor.conf
fi
if ! [ -f /etc/nginx/sites-available/lnbits_tor_ssl.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/lnbits_tor_ssl.conf /etc/nginx/sites-available/lnbits_tor_ssl.conf
fi
sudo ln -sf /etc/nginx/sites-available/lnbits_ssl.conf /etc/nginx/sites-enabled/
sudo ln -sf /etc/nginx/sites-available/lnbits_tor.conf /etc/nginx/sites-enabled/
sudo ln -sf /etc/nginx/sites-available/lnbits_tor_ssl.conf /etc/nginx/sites-enabled/
2020-05-23 22:34:03 +01:00
sudo nginx -t
sudo systemctl reload nginx
2020-02-10 12:33:03 +01:00
# setting value in raspi blitz config
2020-04-23 23:08:14 +02:00
sudo sed -i "s/^LNBits=.*/LNBits=on/g" /mnt/hdd/raspiblitz.conf
2020-02-10 14:29:28 +01:00
# Hidden Service if Tor is active
2020-02-10 12:33:03 +01:00
source /mnt/hdd/raspiblitz.conf
if [ "${runBehindTor}" = "on" ]; then
2020-07-18 15:26:56 +02:00
# make sure to keep in sync with internet.tor.sh script
2020-05-24 17:55:48 +01:00
/home/admin/config.scripts/internet.hiddenservice.sh lnbits 80 5002 443 5003
2020-02-10 12:33:03 +01:00
fi
exit 0
fi
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
2020-07-24 02:00:47 +02:00
# check for second parameter: should data be deleted?
deleteData=0
if [ "$2" = "--delete-data" ]; then
deleteData=1
elif [ "$2" = "--keep-data" ]; then
deleteData=0
else
if (whiptail --title " DELETE DATA? " --yesno "Do you want to delete\nthe LNbits Server Data?" 8 30); then
2020-07-24 02:00:47 +02:00
deleteData=1
else
deleteData=0
fi
fi
echo "# deleteData(${deleteData})"
2020-02-10 12:33:03 +01:00
# setting value in raspi blitz config
2020-04-23 23:08:14 +02:00
sudo sed -i "s/^LNBits=.*/LNBits=off/g" /mnt/hdd/raspiblitz.conf
2020-02-10 12:33:03 +01:00
2020-05-23 22:34:03 +01:00
# remove nginx symlinks
sudo rm -f /etc/nginx/sites-enabled/lnbits_ssl.conf
sudo rm -f /etc/nginx/sites-enabled/lnbits_tor.conf
sudo rm -f /etc/nginx/sites-enabled/lnbits_tor_ssl.conf
2020-06-26 22:57:12 +02:00
sudo rm -f /etc/nginx/sites-available/lnbits_ssl.conf
sudo rm -f /etc/nginx/sites-available/lnbits_tor.conf
sudo rm -f /etc/nginx/sites-available/lnbits_tor_ssl.conf
2020-05-23 22:34:03 +01:00
sudo nginx -t
sudo systemctl reload nginx
# Hidden Service if Tor is active
if [ "${runBehindTor}" = "on" ]; then
/home/admin/config.scripts/internet.hiddenservice.sh off lnbits
fi
2020-02-10 12:33:03 +01:00
isInstalled=$(sudo ls /etc/systemd/system/lnbits.service 2>/dev/null | grep -c 'lnbits.service')
2020-04-23 23:08:14 +02:00
if [ ${isInstalled} -eq 1 ] || [ "${LNBits}" == "on" ]; then
echo "*** REMOVING LNbits ***"
2020-02-10 12:33:03 +01:00
sudo systemctl stop lnbits
sudo systemctl disable lnbits
sudo rm /etc/systemd/system/lnbits.service
2020-04-28 09:27:03 +01:00
sudo userdel -rf lnbits
2020-07-24 02:00:47 +02:00
if [ ${deleteData} -eq 1 ]; then
echo "# deleting data"
sudo rm -R /mnt/hdd/app-data/LNBits
else
echo "# keeping data"
fi
echo "OK LNbits removed."
else
echo "LNbits is not installed."
2020-02-10 12:33:03 +01:00
fi
exit 0
fi
echo "FAIL - Unknown Parameter $1"
exit 1