raspiblitz/home.admin/config.scripts/bonus.btcpayserver.sh
/rootzoll 074c9d8549
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

585 lines
22 KiB
Bash
Executable file

#!/bin/bash
# Based on: https://gist.github.com/normandmickey/3f10fc077d15345fb469034e3697d0d0
# https://github.com/dgarage/NBXplorer/releases
NBXplorerVersion="v2.1.49"
# https://github.com/btcpayserver/btcpayserver/releases
BTCPayVersion="v1.0.7.2"
# command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "# config script to switch BTCPay Server on or off"
echo "# bonus.btcpayserver.sh [on|off|menu|write-tls-macaroon]"
echo "# installs BTCPayServer $BTCPayVersion with NBXplorer $NBXplorerVersion"
exit 1
fi
source /mnt/hdd/raspiblitz.conf
# get cpu architecture
source /home/admin/raspiblitz.info
if [ "$1" = "status" ]; then
if [ "${BTCPayServer}" = "on" ]; then
echo "switchedon=1"
isInstalled=$(sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service')
echo "installed=${isInstalled}"
localIP=$(hostname -I | awk '{print $1}')
echo "localIP='${localIP}'"
echo "httpsPort='23001'"
echo "publicIP='${publicIP}'"
# check for LetsEncryptDomain 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
sslFingerprintIP=$(openssl x509 -in /mnt/hdd/app-data/nginx/tls.cert -fingerprint -noout 2>/dev/null | cut -d"=" -f2)
echo "sslFingerprintIP='${sslFingerprintIP}'"
toraddress=$(sudo cat /mnt/hdd/tor/btcpay/hostname 2>/dev/null)
echo "toraddress='${toraddress}'"
sslFingerprintTOR=$(openssl x509 -in /mnt/hdd/app-data/nginx/tor_tls.cert -fingerprint -noout 2>/dev/null | cut -d"=" -f2)
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}'"
echo "ip2torID='${id}'"
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
fi
fi
# check for error
isDead=$(sudo systemctl status btcpayserver | grep -c 'inactive (dead)')
if [ ${isDead} -eq 1 ]; then
echo "error='Service Failed'"
fi
else
echo "switchedon=0"
echo "installed=0"
fi
exit 0
fi
# show info menu
if [ "$1" = "menu" ]; then
# get status info
echo "# collecting status info ... (please wait)"
source <(sudo /home/admin/config.scripts/bonus.btcpayserver.sh status)
if [ ${switchedon} -eq 0 ]; then
whiptail --title " BTCPay Server " --msgbox "BTCPay Server is not activated." 7 36
exit 0
fi
if [ ${installed} -eq 0 ]; then
whiptail --title " BTCPay Server " --msgbox "BTCPay Server needs to be re-installed.\nPress OK to start process." 8 45
/home/admin/config.scripts/bonus.btcpayserver.sh on
exit 0
fi
# 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}"
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}
SHA1 ${sslFingerprintIP}"
if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then
/home/admin/config.scripts/blitz.display.sh qr "${toraddress}"
text="${text}\n
TOR Browser Hidden Service address (see the QR onLCD):
${toraddress}"
fi
if [ ${#ip2torDomain} -gt 0 ]; then
text="${text}\n
IP2TOR+LetsEncrypt: https://${ip2torDomain}:${ip2torPort}
SHA1 ${sslFingerprintTOR}"
elif [ ${#ip2torIP} -gt 0 ]; then
text="${text}\n
IP2TOR: https://${ip2torIP}:${ip2torPort}
SHA1 ${sslFingerprintTOR}
go MAINMENU > SUBSCRIBE and add LetsEncrypt HTTPS Domain"
elif [ ${#publicDomain} -eq 0 ]; then
text="${text}\n
To enable easy reachability with normal browser from the outside
consider adding a IP2TOR Bridge: MAINMENU > SUBSCRIBE > IP2TOR"
fi
text="${text}\n
To get the 'Connection String' to activate Lightning Payments:
MAINMENU > CONNECT > BTCPay Server"
whiptail --title " BTCPay Server " --msgbox "${text}" 17 69
/home/admin/config.scripts/blitz.display.sh hide
echo "# please wait ..."
exit 0
fi
# add default values to raspi config if needed
if ! grep -Eq "^BTCPayServer=" /mnt/hdd/raspiblitz.conf; then
echo "BTCPayServer=off" >> /mnt/hdd/raspiblitz.conf
fi
if ! grep -Eq "^BTCPayDomain=" /mnt/hdd/raspiblitz.conf; then
echo "BTCPayDomain=off" >> /mnt/hdd/raspiblitz.conf
fi
# write-tls-macaroon
if [ "$1" = "write-tls-macaroon" ]; then
echo "# make sure btcpay is member of lndadmin"
sudo /usr/sbin/usermod --append --groups lndadmin btcpay
echo "# make sure symlink to central app-data directory exists"
if ! [[ -L "/home/btcpay/.lnd" ]]; then
sudo rm -rf "/home/btcpay/.lnd" # not a symlink.. delete it silently
sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/btcpay/.lnd" # and create symlink
fi
# copy admin macaroon
echo "# extra symlink to admin.macaroon for btcpay"
if ! [[ -L "/home/btcpay/admin.macaroon" ]]; then
sudo ln -s "/home/btcpay/.lnd/data/chain/${network}/${chain}net/admin.macaroon" "/home/btcpay/admin.macaroon"
fi
# set thumbprint
FINGERPRINT=$(openssl x509 -noout -fingerprint -sha256 -inform pem -in /home/btcpay/.lnd/tls.cert | cut -d"=" -f2)
doesNetworkEntryAlreadyExists=$(sudo cat /home/btcpay/.btcpayserver/Main/settings.config | grep -c '^network=')
if [ ${doesNetworkEntryAlreadyExists} -eq 0 ]; then
echo "# setting the LND TLS thumbprint for BTCPay"
echo "
### Global settings ###
network=mainnet
### Server settings ###
port=23000
bind=127.0.0.1
externalurl=https://$BTCPayDomain
### NBXplorer settings ###
BTC.explorer.url=http://127.0.0.1:24444/
BTC.lightning=type=lnd-rest;server=https://127.0.0.1:8080/;macaroonfilepath=/home/btcpay/admin.macaroon;certthumbprint=$FINGERPRINT
" | sudo -u btcpay tee -a /home/btcpay/.btcpayserver/Main/settings.config
else
echo "# setting new LND TLS thumbprint for BTCPay"
s="BTC.lightning=type=lnd-rest\;server=https\://127.0.0.1:8080/\;macaroonfilepath=/home/btcpay/admin.macaroon\;"
sudo -u btcpay sed -i "s|^${s}certthumbprint=.*|${s}certthumbprint=$FINGERPRINT|g" /home/btcpay/.btcpayserver/Main/settings.config
fi
if [ "${state}" == "ready" ]; then
sudo systemctl restart btcpayserver
fi
exit 0
fi
# switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "# INSTALL BTCPAYSERVER"
##################
# NGINX
##################
# setup nginx symlinks
if ! [ -f /etc/nginx/sites-available/btcpay_ssl.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/btcpay_ssl.conf /etc/nginx/sites-available/btcpay_ssl.conf
fi
if ! [ -f /etc/nginx/sites-available/btcpay_tor.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/btcpay_tor.conf /etc/nginx/sites-available/btcpay_tor.conf
fi
if ! [ -f /etc/nginx/sites-available/btcpay_tor_ssl.conf ]; then
sudo cp /home/admin/assets/nginx/sites-available/btcpay_tor_ssl.conf /etc/nginx/sites-available/btcpay_tor_ssl.conf
fi
sudo ln -sf /etc/nginx/sites-available/btcpay_ssl.conf /etc/nginx/sites-enabled/
sudo ln -sf /etc/nginx/sites-available/btcpay_tor.conf /etc/nginx/sites-enabled/
sudo ln -sf /etc/nginx/sites-available/btcpay_tor_ssl.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
# open the firewall
echo "# Updating the firewall"
sudo ufw allow 23000 comment 'allow BTCPay HTTP'
sudo ufw allow 23001 comment 'allow BTCPay HTTPS'
echo
# Hidden Service for BTCPay if Tor is active
if [ "${runBehindTor}" = "on" ]; then
# make sure to keep in sync with internet.tor.sh script
/home/admin/config.scripts/internet.hiddenservice.sh btcpay 80 23002 443 23003
fi
# check for $BTCPayDomain
source /mnt/hdd/raspiblitz.conf
# stop services
echo "# making sure services are not running"
sudo systemctl stop nbxplorer 2>/dev/null
sudo systemctl stop btcpayserver 2>/dev/null
isInstalled=$(sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service')
if [ ${isInstalled} -eq 0 ]; then
# create btcpay user
sudo adduser --disabled-password --gecos "" btcpay || exit 1
cd /home/btcpay || exit 1
# store BTCpay data on HDD
sudo mkdir /mnt/hdd/app-data/.btcpayserver 2>/dev/null
# move old btcpay data to app-data
sudo mv -f /mnt/hdd/.btcpayserver/* /mnt/hdd/app-data/.btcpayserver/ 2>/dev/null
sudo rm -rf /mnt/hdd/.btcpayserver 2>/dev/null
sudo chown -R btcpay:btcpay /mnt/hdd/app-data/.btcpayserver
sudo ln -s /mnt/hdd/app-data/.btcpayserver /home/btcpay/ 2>/dev/null
sudo chown -R btcpay:btcpay /home/btcpay/.btcpayserver
echo
echo "# Installing .NET"
echo
# download dotnet-sdk
# https://dotnet.microsoft.com/download/dotnet-core/3.1
# dependencies
sudo apt-get -y install libunwind8 gettext libssl1.0
if [ "${cpu}" = "arm" ]; then
binaryVersion="arm"
dotNetdirectLink="https://download.visualstudio.microsoft.com/download/pr/f2e1cb4a-0c70-49b6-871c-ebdea5ebf09d/acb1ea0c0dbaface9e19796083fe1a6b/dotnet-sdk-3.1.300-linux-arm.tar.gz"
dotNetChecksum="510de2931522633e5a35cfbaebac255704bb2a282e4980e7597c924531564b1a2f769cf67b3d1f196442ceca3d0d9a53e0a6dcb12adc9b0c6c1500742e7b1ee5"
elif [ "${cpu}" = "aarch64" ]; then
binaryVersion="arm64"
dotNetdirectLink="https://download.visualstudio.microsoft.com/download/pr/e5e70860-a6d4-48cf-b0d1-eeba32657d80/2da3c605aaa65c7e4ac2ad0507a2e429/dotnet-sdk-3.1.300-linux-arm64.tar.gz"
dotNetChecksum="b1d806dd719e61ae27297515d26e6ef12e615da131db4fd1c29b2acc4d6a68a6b0e4ce94ead4f8f737c203328d596422068c78495eba331a5759f595ed9ed149"
elif [ "${cpu}" = "x86_64" ]; then
binaryVersion="x64"
dotNetdirectLink="https://download.visualstudio.microsoft.com/download/pr/0c795076-b679-457e-8267-f9dd20a8ca28/02446ea777b6f5a5478cd3244d8ed65b/dotnet-sdk-3.1.300-linux-x64.tar.gz"
dotNetChecksum="1c3844ea5f8847d92372dae67529ebb08f09999cac0aa10ace571c63a9bfb615adbf8b9d5cebb2f960b0a81f6a5fba7d80edb69b195b77c2c7cca174cbc2fd0b"
fi
dotNetName="dotnet-sdk-3.1.300-linux-${binaryVersion}.tar.gz"
sudo rm /home/btcpay/${dotnetName} 2>/dev/null
sudo -u btcpay wget "${dotNetdirectLink}"
# check binary is was not manipulated (checksum test)
actualChecksum=$(sha512sum /home/btcpay/${dotNetName} | cut -d " " -f1)
if [ "${actualChecksum}" != "${dotNetChecksum}" ]; then
echo "# !!! FAIL !!! Downloaded ${dotNetName} not matching SHA512 checksum: ${dotNetChecksum}"
exit 1
fi
# download aspnetcore-runtime
if [ "${cpu}" = "arm" ]; then
AspNetdirectLink="https://download.visualstudio.microsoft.com/download/pr/06f9feeb-cd19-49e9-a5cd-a230e1d8c52f/a232fbb4a6e6a90bbe624225e180308a/aspnetcore-runtime-3.1.4-linux-arm.tar.gz"
AspNetChecksum="58fe16baf370cebda96b93735be9bc57cf9a846b56ecbdc3c745c83399ad5b59518251996b75ac959ee3a8eb438a92e2ea3d088af4f0631caed3c86006d4ed2d"
elif [ "${cpu}" = "aarch64" ]; then
AspNetdirectLink="https://download.visualstudio.microsoft.com/download/pr/0f94ccdf-a791-4978-a0e1-0309911f60a4/d734c7f79e6b180b7b91f3d7e78d24d8/aspnetcore-runtime-3.1.4-linux-arm64.tar.gz"
AspNetChecksum="db91ea66e796e3d27ee08d50cb0532d1fb74060d5a8f1c90d2f34cb66ad74d50d6a8d128457693c15216b3c94d6c1acb7bd342fe0a0fa770117e21211972abda"
elif [ "${cpu}" = "x86_64" ]; then
AspNetdirectLink="https://download.visualstudio.microsoft.com/download/pr/a1ddc998-933c-47af-b8c7-dc2503e44e91/42d8cd08b2055df52c9457c993911f2e/aspnetcore-runtime-3.1.4-linux-x64.tar.gz"
AspNetChecksum="a761fd3652a0bc838c33b2846724d21e82410a5744bd37cbfab96c60327c89ee89c177e480a519b0e0d62ee58ace37e2c2a4b12b517e5eb0af601ad9804e028f"
fi
aspNetCoreName="aspnetcore-runtime-3.1.4-linux-${binaryVersion}.tar.gz"
sudo rm /home/btcpay/${aspNetCoreName} 2>/dev/null
sudo -u btcpay wget "${AspNetdirectLink}"
# check binary is was not manipulated (checksum test)
actualAspNetChecksum=$(sha512sum /home/btcpay/${aspNetCoreName} | cut -d " " -f1)
if [ "${actualAspNetChecksum}" != "${AspNetChecksum=}" ]; then
echo "# !!! FAIL !!! Downloaded ${aspNetCoreName} not matching SHA512 checksum: ${AspNetChecksum=}"
exit 1
fi
sudo -u btcpay mkdir /home/btcpay/dotnet
sudo -u btcpay tar -xvf ${dotNetName} -C /home/btcpay/dotnet
sudo -u btcpay tar -xvf ${aspNetCoreName} -C /home/btcpay/dotnet
sudo rm -f *.tar.gz*
# opt out of telemetry
echo "DOTNET_CLI_TELEMETRY_OPTOUT=1" | sudo tee -a /etc/environment
# make .NET accessible and add to PATH
sudo ln -s /home/btcpay/dotnet /usr/share
export PATH=$PATH:/usr/share
if [ $(cat /etc/profile | grep -c "/usr/share") -eq 0 ]; then
sudo bash -c "echo 'PATH=\$PATH:/usr/share' >> /etc/profile"
fi
export DOTNET_ROOT=/home/btcpay/dotnet
export PATH=$PATH:/home/btcpay/dotnet
if [ $(cat /etc/profile | grep -c "DOTNET_ROOT") -eq 0 ]; then
sudo bash -c "echo 'DOTNET_ROOT=/home/btcpay/dotnet' >> /etc/profile"
sudo bash -c "echo 'PATH=\$PATH:/home/btcpay/dotnet' >> /etc/profile"
fi
sudo -u btcpay /home/btcpay/dotnet/dotnet --info
# NBXplorer
echo
echo "# Install NBXplorer"
echo
cd /home/btcpay || exit 1
echo "# Download the NBXplorer source code ..."
sudo -u btcpay git clone https://github.com/dgarage/NBXplorer.git 2>/dev/null
cd NBXplorer || exit 1
sudo -u btcpay git reset --hard $NBXplorerVersion
echo "# Build NBXplorer ..."
# from the build.sh with path
sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release NBXplorer/NBXplorer.csproj
# see the configuration options with:
# sudo -u btcpay /home/btcpay/dotnet/dotnet "/home/btcpay/NBXplorer/NBXplorer/bin/Release/netcoreapp3.1/NBXplorer.dll" -c /home/btcpay/.nbxplorer/Main/settings.config -h
# run manually to debug:
# sudo -u btcpay /home/btcpay/dotnet/dotnet "/home/btcpay/NBXplorer/NBXplorer/bin/Release/netcoreapp3.1/NBXplorer.dll" -c /home/btcpay/.nbxplorer/Main/settings.config --network=mainnet
echo"# create the nbxplorer.service"
echo "
[Unit]
Description=NBXplorer daemon
Requires=bitcoind.service
After=bitcoind.service
[Service]
ExecStart=/home/btcpay/dotnet/dotnet \
\"/home/btcpay/NBXplorer/NBXplorer/bin/Release/netcoreapp3.1/NBXplorer.dll\" \
-c /home/btcpay/.nbxplorer/Main/settings.config --network=${chain}net
User=btcpay
Group=btcpay
Type=simple
PIDFile=/run/nbxplorer/nbxplorer.pid
Restart=on-failure
# Hardening measures
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
[Install]
WantedBy=multi-user.target
" | sudo tee /etc/systemd/system/nbxplorer.service
sudo systemctl daemon-reload
# start to create settings.config
sudo systemctl enable nbxplorer
if [ "${state}" == "ready" ]; then
echo "# Starting nbxplorer"
sudo systemctl start nbxplorer
echo "# Checking for nbxplorer config"
while [ ! -f "/home/btcpay/.nbxplorer/Main/settings.config" ]
do
echo "# Waiting for nbxplorer to start - CTRL+C to abort"
sleep 10
hasFailed=$(sudo systemctl status nbxplorer | grep -c "Active: failed")
if [ ${hasFailed} -eq 1 ]; then
echo "# seems like starting nbxplorer service has failed - see: systemctl status nbxplorer"
echo "# maybe report here: https://github.com/rootzoll/raspiblitz/issues/214"
fi
done
else
echo "# Because the system is not 'ready' the service 'nbxplorer' will not be started at this point .. its enabled and will start on next reboot"
fi
echo
echo "# getting RPC credentials from the bitcoin.conf"
RPC_USER=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcuser | cut -c 9-)
PASSWORD_B=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep rpcpassword | cut -c 13-)
sudo -u btcpay mkdir -p /home/btcpay/.nbxplorer/Main
echo "\
btc.rpc.user=$RPC_USER
btc.rpc.password=$PASSWORD_B
" | sudo tee /home/btcpay/.nbxplorer/Main/settings.config
sudo chmod 600 /home/btcpay/.nbxplorer/Main/settings.config
sudo chown btcpay:btcpay /home/btcpay/.nbxplorer/Main/settings.config
if [ "${state}" == "ready" ]; then
sudo systemctl restart nbxplorer
fi
# BTCPayServer
echo
echo "# Install BTCPayServer"
echo
cd /home/btcpay || exit 1
echo "# Download the BTCPayServer source code ..."
sudo -u btcpay git clone https://github.com/btcpayserver/btcpayserver.git 2>/dev/null
cd btcpayserver
sudo -u btcpay git reset --hard $BTCPayVersion
echo "# Build BTCPayServer ..."
# from the build.sh with path
sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release /home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj
# see the configuration options with:
# sudo -u btcpay /home/btcpay/dotnet/dotnet run --no-launch-profile --no-build -c Release -p "/home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj" -- -h
# run manually to debug:
# sudo -u btcpay /home/btcpay/dotnet/dotnet run --no-launch-profile --no-build -c Release -p "/home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj" -- --sqlitefile=sqllite.db --network=mainnet
echo "# create the btcpayserver.service"
echo "
[Unit]
Description=BtcPayServer daemon
Requires=nbxplorer.service
After=nbxplorer.service
[Service]
ExecStart=/home/btcpay/dotnet/dotnet run --no-launch-profile --no-build \
-c Release \
-p \"/home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj\" -- \
--sqlitefile=sqllite.db --network=${chain}net
User=btcpay
Group=btcpay
Type=simple
PIDFile=/run/btcpayserver/btcpayserver.pid
Restart=on-failure
# Hardening measures
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
[Install]
WantedBy=multi-user.target
" | sudo tee /etc/systemd/system/btcpayserver.service
sudo systemctl enable btcpayserver
if [ "${state}" == "ready" ]; then
echo "# Starting btcpayserver"
sudo systemctl start btcpayserver
echo "# Checking for btcpayserver config"
while [ ! -f "/home/btcpay/.btcpayserver/Main/settings.config" ]; do
echo "# Waiting for btcpayserver to start - CTRL+C to abort"
sleep 10
hasFailed=$(sudo systemctl status btcpayserver | grep -c "Active: failed")
if [ ${hasFailed} -eq 1 ]; then
echo "# seems like starting btcpayserver service has failed - see: systemctl status btcpayserver"
echo "# maybe report here: https://github.com/rootzoll/raspiblitz/issues/214"
fi
done
else
echo "# Because the system is not 'ready' the service 'btcpayserver' will not be started at this point .. its enabled and will start on next reboot"
fi
sudo -u btcpay mkdir -p /home/btcpay/.btcpayserver/Main/
/home/admin/config.scripts/bonus.btcpayserver.sh write-tls-macaroon
else
echo "# BTCPay Server is already installed."
if [ "${state}" == "ready" ]; then
# start service
echo "# start service"
sudo systemctl start nbxplorer 2>/dev/null
sudo systemctl start btcpayserver 2>/dev/null
fi
fi
# setting value in raspi blitz config
sudo sed -i "s/^BTCPayServer=.*/BTCPayServer=on/g" /mnt/hdd/raspiblitz.conf
exit 0
fi
# switch off
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
# 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 BTCPay Server Data?" 8 30); then
deleteData=1
else
deleteData=0
fi
fi
echo "# deleteData(${deleteData})"
# setting value in raspi blitz config
sudo sed -i "s/^BTCPayServer=.*/BTCPayServer=off/g" /mnt/hdd/raspiblitz.conf
# Hidden Service if Tor is active
if [ "${runBehindTor}" = "on" ]; then
/home/admin/config.scripts/internet.hiddenservice.sh off btcpay
fi
isInstalled=$(sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service')
if [ ${isInstalled} -eq 1 ]; then
echo "# *** REMOVING BTCPAYSERVER, NBXPLORER and .NET ***"
# removing services
# btcpay
sudo systemctl stop btcpayserver
sudo systemctl disable btcpayserver
sudo rm /etc/systemd/system/btcpayserver.service
# nbxplorer
sudo systemctl stop nbxplorer
sudo systemctl disable nbxplorer
sudo rm /etc/systemd/system/nbxplorer.service
# clear dotnet cache
dotnet nuget locals all --clear
sudo rm -rf /tmp/NuGetScratch
# remove dotnet
sudo rm -rf /usr/share/dotnet
# clear app config (not user data)
sudo rm -f /home/btcpay/.nbxplorer/Main/settings.config
sudo rm -f /home/btcpay/.btcpayserver/Main/settings.config
# clear nginx config (from btcpaysetdomain)
sudo rm -f /etc/nginx/sites-enabled/btcpayserver
sudo rm -f /etc/nginx/sites-available/btcpayserver
# remove nginx symlinks
sudo rm -f /etc/nginx/sites-enabled/btcpay_ssl.conf
sudo rm -f /etc/nginx/sites-enabled/btcpay_tor.conf
sudo rm -f /etc/nginx/sites-enabled/btcpay_tor_ssl.conf
sudo rm -f /etc/nginx/sites-available/btcpay_ssl.conf
sudo rm -f /etc/nginx/sites-available/btcpay_tor.conf
sudo rm -f /etc/nginx/sites-available/btcpay_tor_ssl.conf
sudo nginx -t
sudo systemctl reload nginx
# nuke user
sudo userdel -rf btcpay 2>/dev/null
if [ ${deleteData} -eq 1 ]; then
echo "# deleting data"
sudo rm -R /mnt/hdd/app-data/.btcpayserver/
else
echo "# keeping data"
fi
echo "# OK BTCPayServer removed."
else
echo "# BTCPayServer is not installed."
fi
exit 0
fi
echo "# FAIL - Unknown Parameter $1"
exit 1