Merge pull request #1140 from openoms/btcpay-patch

BTCPay: copy admin macaroon and update TLS thumbprint when changed, update to latest master.
This commit is contained in:
Christian Rotzoll
2020-04-28 19:07:09 +02:00
committed by GitHub
2 changed files with 52 additions and 34 deletions

View File

@@ -5,7 +5,7 @@
# command info # command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "config script to switch BTCPay Server on or off" echo "config script to switch BTCPay Server on or off"
echo "bonus.btcpayserver.sh [on|off|menu] [ip|tor]" echo "bonus.btcpayserver.sh [on|off|menu|write-tls-macaroon] [ip|tor]"
exit 1 exit 1
fi fi
@@ -49,10 +49,41 @@ if ! grep -Eq "^BTCPayDomain=" /mnt/hdd/raspiblitz.conf; then
echo "BTCPayDomain=off" >> /mnt/hdd/raspiblitz.conf echo "BTCPayDomain=off" >> /mnt/hdd/raspiblitz.conf
fi fi
# stop services # write-tls-macaroon
echo "making sure services are not running" if [ "$1" = "write-tls-macaroon" ]; then
sudo systemctl stop nbxplorer 2>/dev/null # copy admin macaroon
sudo systemctl stop btcpayserver 2>/dev/null echo "copyin admin.macaroon for btcpay"
sudo cp /mnt/hdd/lnd/data/chain/bitcoin/mainnet/admin.macaroon /home/btcpay/admin.macaroon
sudo chown btcpay:btcpay /home/btcpay/admin.macaroon
sudo chmod 600 /home/btcpay/admin.macaroon
# set thumbprint
FINGERPRINT=$(openssl x509 -noout -fingerprint -sha256 -inform pem -in /home/admin/.lnd/tls.cert | cut -c 20-)
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"
sudo -u btcpay sed -i \
"s/^BTC.lightning=type=lnd-rest\;server=https\:\/\/127.0.0.1:8080\/\;macaroonfilepath=\/home\/btcpay\/admin.macaroon\;certthumbprint=.*\
/BTC.lightning=type=lnd-rest\;server=https\:\/\/127.0.0.1:8080\/\;macaroonfilepath=\/home\/btcpay\/admin.macaroon\;certthumbprint=$FINGERPRINT/g" \
/home/btcpay/.btcpayserver/Main/settings.config
fi
sudo systemctl restart btcpayserver
exit 0
fi
# switch on # switch on
if [ "$1" = "1" ] || [ "$1" = "on" ]; then if [ "$1" = "1" ] || [ "$1" = "on" ]; then
@@ -78,6 +109,11 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
# check for $BTCPayDomain # check for $BTCPayDomain
source /mnt/hdd/raspiblitz.conf 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') isInstalled=$(sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service')
if [ ${isInstalled} -eq 0 ]; then if [ ${isInstalled} -eq 0 ]; then
# create btcpay user # create btcpay user
@@ -236,7 +272,9 @@ EOF
sudo -u btcpay git clone https://github.com/btcpayserver/btcpayserver.git 2>/dev/null sudo -u btcpay git clone https://github.com/btcpayserver/btcpayserver.git 2>/dev/null
cd btcpayserver cd btcpayserver
# check https://github.com/btcpayserver/btcpayserver/releases # check https://github.com/btcpayserver/btcpayserver/releases
sudo -u btcpay git reset --hard v1.0.4.1 #sudo -u btcpay git reset --hard v1.0.4.1
# https://github.com/btcpayserver/btcpayserver/commits/master
sudo -u btcpay git checkout 3a2970a495316d42c9cce0be1ddb185fcdc15352
# from the build.sh with path # from the build.sh with path
sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release /home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release /home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj
@@ -275,30 +313,8 @@ WantedBy=multi-user.target
fi fi
done done
# set thumbprint /home/admin/config.scripts/bonus.btcpayserver.sh write-tls-macaroon
FINGERPRINT=$(openssl x509 -noout -fingerprint -sha256 -inform pem -in /home/admin/.lnd/tls.cert | cut -c 20-)
sudo cp /mnt/hdd/lnd/data/chain/bitcoin/mainnet/admin.macaroon /home/btcpay/admin.macaroon
sudo chown btcpay:btcpay /home/btcpay/admin.macaroon
sudo chmod 600 /home/btcpay/admin.macaroon
doesNetworkEntryAlreadyExists=$(sudo cat /home/btcpay/.btcpayserver/Main/settings.config | grep -c '^network=')
if [ ${doesNetworkEntryAlreadyExists} -eq 0 ]; then
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
fi
sudo systemctl restart btcpayserver
else else
echo "BTCPay Server is already installed." echo "BTCPay Server is already installed."
# start service # start service
@@ -331,12 +347,9 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then
sudo systemctl disable nbxplorer sudo systemctl disable nbxplorer
sudo rm /etc/systemd/system/nbxplorer.service sudo rm /etc/systemd/system/nbxplorer.service
# clear dotnet cache # clear dotnet cache
sudo -u btcpay dotnet nuget locals all --clear dotnet nuget locals all --clear
sudo rm -rf /tmp/NuGetScratch sudo rm -rf /tmp/NuGetScratch
# remove dotnet # remove dotnet
sudo rm -f /home/btcpay/dotnet-sdk*
sudo rm -f /home/btcpay/aspnetcore*
sudo rm -rf /home/btcpay/dotnet
sudo rm -rf /usr/share/dotnet sudo rm -rf /usr/share/dotnet
# clear app config (not user data) # clear app config (not user data)
sudo rm -f /home/btcpay/.nbxplorer/Main/settings.config sudo rm -f /home/btcpay/.nbxplorer/Main/settings.config
@@ -344,6 +357,8 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then
# clear nginx config # clear nginx config
sudo rm -f /etc/nginx/sites-enabled/btcpayserver sudo rm -f /etc/nginx/sites-enabled/btcpayserver
sudo rm -f /etc/nginx/sites-available/btcpayserver sudo rm -f /etc/nginx/sites-available/btcpayserver
# nuke user
sudo userdel -rf btcpay 2>/dev/null
echo "OK BTCPayServer removed." echo "OK BTCPayServer removed."
else else
echo "BTCPayServer is not installed." echo "BTCPayServer is not installed."

View File

@@ -158,6 +158,9 @@ elif [ "${exportType}" = "reset" ]; then
echo "- copy new macaroons to admin user" echo "- copy new macaroons to admin user"
sudo cp /home/bitcoin/.lnd/data/chain/${network}/${chain}net/*.macaroon /home/admin/.lnd/data/chain/${network}/${chain}net/ sudo cp /home/bitcoin/.lnd/data/chain/${network}/${chain}net/*.macaroon /home/admin/.lnd/data/chain/${network}/${chain}net/
sudo chown admin:admin -R /home/admin/.lnd/data/chain/${network}/${chain}net/*.macaroon sudo chown admin:admin -R /home/admin/.lnd/data/chain/${network}/${chain}net/*.macaroon
# BTCPayServer
if [ "${BTCPayServer}" == "on" ]; then
/home/admin/config.scripts/bonus.btcpayserver.sh write-tls-macaroon
# LNBits # LNBits
if [ "${LNBits}" = "on" ]; then if [ "${LNBits}" = "on" ]; then
sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh write-macaroons sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh write-macaroons