2019-12-04 08:13:21 +00:00
#!/bin/bash
2020-05-01 11:34:52 +02:00
# Based on: https://gist.github.com/normandmickey/3f10fc077d15345fb469034e3697d0d0
2019-12-04 08:13:21 +00:00
2020-11-11 16:40:48 +00:00
# https://github.com/dgarage/NBXplorer/releases
2021-03-16 22:49:13 +00:00
NBXplorerVersion = "v2.1.49"
2020-11-11 16:40:48 +00:00
# https://github.com/btcpayserver/btcpayserver/releases
2021-04-08 23:50:45 +02:00
BTCPayVersion = "v1.0.7.2"
2020-11-11 16:40:48 +00:00
2019-12-04 08:13:21 +00:00
# command info
if [ $# -eq 0 ] || [ " $1 " = "-h" ] || [ " $1 " = "-help" ] ; then
2020-11-11 16:40:48 +00:00
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 "
2019-12-05 16:45:27 +00:00
exit 1
2019-12-04 08:13:21 +00:00
fi
source /mnt/hdd/raspiblitz.conf
2020-06-04 14:33:19 +01:00
# get cpu architecture
source /home/admin/raspiblitz.info
2019-12-04 08:13:21 +00:00
2020-07-14 23:46:06 +02:00
if [ " $1 " = "status" ] ; then
2020-07-18 13:40:41 +02:00
2020-07-14 23:46:06 +02:00
if [ " ${ BTCPayServer } " = "on" ] ; then
2020-07-18 13:40:41 +02:00
echo "switchedon=1"
isInstalled = $( sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service' )
echo " installed= ${ isInstalled } "
2020-07-14 23:46:06 +02:00
2021-06-25 23:48:33 +01:00
localIP = $( ip addr | grep 'state UP' -A2 | grep -E -v 'docker0|veth' | grep 'eth0\|wlan0\|enp0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/' )
2020-07-14 23:46:06 +02:00
echo " localIP=' ${ localIP } ' "
echo "httpsPort='23001'"
echo " publicIP=' ${ publicIP } ' "
2020-01-27 02:00:38 +01:00
2021-03-16 22:49:13 +00:00
# check for LetsEncryptDomain for DynDns
2020-07-14 23:46:06 +02:00
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-01-27 02:00:38 +01:00
2020-07-14 23:46:06 +02:00
sslFingerprintIP = $( openssl x509 -in /mnt/hdd/app-data/nginx/tls.cert -fingerprint -noout 2>/dev/null | cut -d"=" -f2)
echo " sslFingerprintIP=' ${ sslFingerprintIP } ' "
2020-01-27 02:00:38 +01:00
2020-07-14 23:46:06 +02:00
toraddress = $( sudo cat /mnt/hdd/tor/btcpay/hostname 2>/dev/null)
echo " toraddress=' ${ toraddress } ' "
2020-01-27 02:00:38 +01:00
2020-07-14 23:46:06 +02:00
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 } ' "
2020-09-14 15:29:50 +02:00
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 23:46:06 +02:00
fi
2020-06-25 18:57:05 +02:00
fi
2020-07-14 23:46:06 +02:00
# check for error
isDead = $( sudo systemctl status btcpayserver | grep -c 'inactive (dead)' )
if [ ${ isDead } -eq 1 ] ; then
echo "error='Service Failed'"
2020-06-25 19:58:22 +02:00
fi
2020-07-14 23:46:06 +02:00
else
2020-07-18 13:40:41 +02:00
echo "switchedon=0"
2020-07-14 23:46:06 +02:00
echo "installed=0"
fi
exit 0
fi
# show info menu
if [ " $1 " = "menu" ] ; then
2020-11-11 16:40:48 +00:00
# get status info
2020-07-14 23:46:06 +02:00
echo "# collecting status info ... (please wait)"
source <( sudo /home/admin/config.scripts/bonus.btcpayserver.sh status)
2020-07-18 13:40:41 +02:00
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
2020-11-23 21:27:39 +01:00
# display possible problems with IP2TOR setup
2020-09-14 15:29:50 +02:00
if [ ${# ip2torWarn } -gt 0 ] ; then
2020-11-23 21:27:39 +01:00
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
2020-09-14 15:29:50 +02:00
fi
2020-07-14 23:46:06 +02:00
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
2021-04-08 00:02:57 +02:00
/home/admin/config.scripts/blitz.display.sh qr " ${ toraddress } "
2020-07-14 23:46:06 +02:00
text = " ${ text } \n
2020-11-11 16:40:48 +00:00
TOR Browser Hidden Service address ( see the QR onLCD) :
2020-07-14 23:46:06 +02:00
${ 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
2020-08-12 09:44:49 +02:00
To enable easy reachability with normal browser from the outside
2020-09-17 16:53:44 +02:00
consider adding a IP2TOR Bridge: MAINMENU > SUBSCRIBE > IP2TOR"
2020-01-27 02:00:38 +01:00
fi
2020-09-17 16:53:44 +02:00
text = " ${ text } \n
To get the 'Connection String' to activate Lightning Payments:
2021-04-18 18:04:59 +02:00
MAINMENU > CONNECT > BTCPay Server"
2020-09-17 16:53:44 +02:00
whiptail --title " BTCPay Server " --msgbox " ${ text } " 17 69
2020-07-14 23:46:06 +02:00
2021-04-08 00:02:57 +02:00
/home/admin/config.scripts/blitz.display.sh hide
2020-11-11 16:40:48 +00:00
echo "# please wait ..."
2020-01-27 02:00:38 +01:00
exit 0
fi
2020-01-28 16:30:08 +01:00
# add default values to raspi config if needed
2020-01-11 09:38:17 +00:00
if ! grep -Eq "^BTCPayServer=" /mnt/hdd/raspiblitz.conf; then
2019-12-04 08:13:21 +00:00
echo "BTCPayServer=off" >> /mnt/hdd/raspiblitz.conf
fi
2020-01-28 16:30:08 +01:00
if ! grep -Eq "^BTCPayDomain=" /mnt/hdd/raspiblitz.conf; then
echo "BTCPayDomain=off" >> /mnt/hdd/raspiblitz.conf
fi
2020-01-11 09:38:17 +00:00
2020-04-28 14:14:17 +01:00
# write-tls-macaroon
2020-04-28 14:40:09 +01:00
if [ " $1 " = "write-tls-macaroon" ] ; then
2020-05-01 11:34:52 +02:00
2020-11-11 16:40:48 +00:00
echo "# make sure btcpay is member of lndadmin"
2020-05-01 11:39:29 +02:00
sudo /usr/sbin/usermod --append --groups lndadmin btcpay
2020-11-11 16:40:48 +00:00
echo "# make sure symlink to central app-data directory exists"
2020-05-01 11:34:52 +02:00
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
2020-04-28 14:14:17 +01:00
# copy admin macaroon
2020-11-11 16:40:48 +00:00
echo "# extra symlink to admin.macaroon for btcpay"
2020-05-01 11:34:52 +02:00
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
2020-04-28 14:14:17 +01:00
# set thumbprint
2020-05-01 11:34:52 +02:00
FINGERPRINT = $( openssl x509 -noout -fingerprint -sha256 -inform pem -in /home/btcpay/.lnd/tls.cert | cut -d"=" -f2)
2020-04-28 14:14:17 +01:00
doesNetworkEntryAlreadyExists = $( sudo cat /home/btcpay/.btcpayserver/Main/settings.config | grep -c '^network=' )
if [ ${ doesNetworkEntryAlreadyExists } -eq 0 ] ; then
2020-11-11 16:40:48 +00:00
echo "# setting the LND TLS thumbprint for BTCPay"
2020-04-28 14:14:17 +01:00
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
2020-11-11 16:40:48 +00:00
echo "# setting new LND TLS thumbprint for BTCPay"
2020-05-01 11:34:52 +02:00
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
2020-04-28 14:14:17 +01:00
fi
2020-07-18 22:49:26 +02:00
if [ " ${ state } " = = "ready" ] ; then
sudo systemctl restart btcpayserver
fi
2020-04-28 14:14:17 +01:00
exit 0
fi
2019-12-04 08:13:21 +00:00
# switch on
if [ " $1 " = "1" ] || [ " $1 " = "on" ] ; then
2021-03-16 22:49:13 +00:00
echo "# INSTALL BTCPAYSERVER"
2019-12-05 13:37:33 +00:00
2020-06-11 18:15:42 +01:00
##################
# 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
2021-03-16 22:49:13 +00:00
echo "# Updating the firewall"
2020-06-11 18:15:42 +01:00
sudo ufw allow 23000 comment 'allow BTCPay HTTP'
sudo ufw allow 23001 comment 'allow BTCPay HTTPS'
2020-11-11 16:40:48 +00:00
echo
2020-06-11 18:15:42 +01:00
# Hidden Service for BTCPay if Tor is active
if [ " ${ runBehindTor } " = "on" ] ; then
2020-07-18 15:26:56 +02:00
# make sure to keep in sync with internet.tor.sh script
2020-06-11 18:15:42 +01:00
/home/admin/config.scripts/internet.hiddenservice.sh btcpay 80 23002 443 23003
2020-01-28 17:54:28 +01:00
fi
2020-01-28 16:30:08 +01:00
2020-01-13 15:00:22 +00:00
# check for $BTCPayDomain
source /mnt/hdd/raspiblitz.conf
2019-12-05 13:37:33 +00:00
2020-04-28 14:14:17 +01:00
# stop services
2020-11-11 16:40:48 +00:00
echo "# making sure services are not running"
2020-04-28 14:14:17 +01:00
sudo systemctl stop nbxplorer 2>/dev/null
sudo systemctl stop btcpayserver 2>/dev/null
2019-12-04 08:13:21 +00:00
isInstalled = $( sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service' )
if [ ${ isInstalled } -eq 0 ] ; then
2019-12-24 09:55:53 +01:00
# create btcpay user
2021-03-17 20:23:29 +00:00
sudo adduser --disabled-password --gecos "" btcpay || exit 1
2021-03-16 22:49:13 +00:00
cd /home/btcpay || exit 1
2019-12-23 19:03:00 +01:00
2019-12-24 09:55:53 +01:00
# store BTCpay data on HDD
2020-01-13 15:00:22 +00:00
sudo mkdir /mnt/hdd/app-data/.btcpayserver 2>/dev/null
2019-12-24 09:55:53 +01:00
# move old btcpay data to app-data
2020-01-13 15:00:22 +00:00
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
2020-01-20 22:38:36 +00:00
sudo ln -s /mnt/hdd/app-data/.btcpayserver /home/btcpay/ 2>/dev/null
2020-01-13 15:00:22 +00:00
sudo chown -R btcpay:btcpay /home/btcpay/.btcpayserver
2019-12-24 09:55:53 +01:00
2020-11-11 16:40:48 +00:00
echo
echo "# Installing .NET"
echo
2019-12-04 08:13:21 +00:00
# download dotnet-sdk
2020-01-21 04:21:35 +00:00
# https://dotnet.microsoft.com/download/dotnet-core/3.1
2020-06-04 14:33:19 +01:00
# dependencies
2019-12-04 08:13:21 +00:00
sudo apt-get -y install libunwind8 gettext libssl1.0
2020-06-04 14:33:19 +01:00
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 "
2020-01-27 04:33:41 +01:00
sudo rm /home/btcpay/${ dotnetName } 2>/dev/null
2020-06-04 14:33:19 +01:00
sudo -u btcpay wget " ${ dotNetdirectLink } "
2020-01-27 04:33:41 +01:00
# check binary is was not manipulated (checksum test)
2020-06-04 14:33:19 +01:00
actualChecksum = $( sha512sum /home/btcpay/${ dotNetName } | cut -d " " -f1)
if [ " ${ actualChecksum } " != " ${ dotNetChecksum } " ] ; then
2020-11-11 16:40:48 +00:00
echo " # !!! FAIL !!! Downloaded ${ dotNetName } not matching SHA512 checksum: ${ dotNetChecksum } "
2019-12-04 08:13:21 +00:00
exit 1
fi
2020-05-01 11:34:52 +02:00
2019-12-04 08:13:21 +00:00
# download aspnetcore-runtime
2020-06-04 14:33:19 +01:00
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 } "
2020-01-27 04:33:41 +01:00
# check binary is was not manipulated (checksum test)
2020-06-04 14:33:19 +01:00
actualAspNetChecksum = $( sha512sum /home/btcpay/${ aspNetCoreName } | cut -d " " -f1)
if [ " ${ actualAspNetChecksum } " != " ${ AspNetChecksum = } " ] ; then
2020-11-11 16:40:48 +00:00
echo " # !!! FAIL !!! Downloaded ${ aspNetCoreName } not matching SHA512 checksum: ${ AspNetChecksum = } "
2019-12-04 08:13:21 +00:00
exit 1
fi
2020-05-01 11:34:52 +02:00
2019-12-04 08:13:21 +00:00
sudo -u btcpay mkdir /home/btcpay/dotnet
2020-06-04 14:33:19 +01:00
sudo -u btcpay tar -xvf ${ dotNetName } -C /home/btcpay/dotnet
sudo -u btcpay tar -xvf ${ aspNetCoreName } -C /home/btcpay/dotnet
2020-01-13 15:00:22 +00:00
sudo rm -f *.tar.gz*
2020-05-01 11:34:52 +02:00
2019-12-04 08:13:21 +00:00
# opt out of telemetry
echo "DOTNET_CLI_TELEMETRY_OPTOUT=1" | sudo tee -a /etc/environment
2020-05-01 11:34:52 +02:00
2020-01-21 04:21:35 +00:00
# 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
2019-12-04 08:13:21 +00:00
sudo -u btcpay /home/btcpay/dotnet/dotnet --info
2020-05-01 11:34:52 +02:00
2020-01-21 04:21:35 +00:00
# NBXplorer
2020-11-11 16:40:48 +00:00
echo
echo "# Install NBXplorer"
echo
2021-03-17 20:23:29 +00:00
cd /home/btcpay || exit 1
echo "# Download the NBXplorer source code ..."
2020-01-21 04:21:35 +00:00
sudo -u btcpay git clone https://github.com/dgarage/NBXplorer.git 2>/dev/null
2021-04-10 17:27:05 +01:00
cd NBXplorer || exit 1
2020-11-11 16:40:48 +00:00
sudo -u btcpay git reset --hard $NBXplorerVersion
2021-03-17 20:23:29 +00:00
echo "# Build NBXplorer ..."
2020-01-21 04:21:35 +00:00
# from the build.sh with path
sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release NBXplorer/NBXplorer.csproj
2021-03-17 20:23:29 +00:00
# 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"
2019-12-04 08:13:21 +00:00
echo "
[ Unit]
Description = NBXplorer daemon
Requires = bitcoind.service
After = bitcoind.service
[ Service]
2021-03-17 20:23:29 +00:00
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
2019-12-04 08:13:21 +00:00
User = btcpay
Group = btcpay
2020-01-15 11:23:32 +01:00
Type = simple
2019-12-04 08:13:21 +00:00
PIDFile = /run/nbxplorer/nbxplorer.pid
Restart = on-failure
2021-06-02 09:18:29 +01:00
# Hardening measures
2019-12-04 08:13:21 +00:00
PrivateTmp = true
ProtectSystem = full
NoNewPrivileges = true
PrivateDevices = true
[ Install]
WantedBy = multi-user.target
2020-01-13 15:00:22 +00:00
" | sudo tee /etc/systemd/system/nbxplorer.service
2020-05-01 11:34:52 +02:00
2019-12-04 08:13:21 +00:00
sudo systemctl daemon-reload
2020-01-21 04:21:35 +00:00
# start to create settings.config
2019-12-04 08:13:21 +00:00
sudo systemctl enable nbxplorer
2020-07-24 00:42:56 +02:00
if [ " ${ state } " = = "ready" ] ; then
2020-11-11 16:40:48 +00:00
echo "# Starting nbxplorer"
2020-07-24 00:42:56 +02:00
sudo systemctl start nbxplorer
2020-11-11 16:40:48 +00:00
echo "# Checking for nbxplorer config"
2020-07-24 00:42:56 +02:00
while [ ! -f "/home/btcpay/.nbxplorer/Main/settings.config" ]
do
2020-11-11 16:40:48 +00:00
echo "# Waiting for nbxplorer to start - CTRL+C to abort"
2020-07-24 00:42:56 +02:00
sleep 10
hasFailed = $( sudo systemctl status nbxplorer | grep -c "Active: failed" )
if [ ${ hasFailed } -eq 1 ] ; then
2020-11-11 16:40:48 +00:00
echo "# seems like starting nbxplorer service has failed - see: systemctl status nbxplorer"
echo "# maybe report here: https://github.com/rootzoll/raspiblitz/issues/214"
2020-07-24 00:42:56 +02:00
fi
done
else
2020-11-11 16:40:48 +00:00
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"
2020-07-24 00:42:56 +02:00
fi
2020-05-01 11:34:52 +02:00
2020-11-11 16:40:48 +00:00
echo
echo "# getting RPC credentials from the bitcoin.conf"
2019-12-04 08:13:21 +00:00
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-)
2020-07-18 22:58:13 +02:00
sudo -u btcpay mkdir -p /home/btcpay/.nbxplorer/Main
2021-03-16 22:49:13 +00:00
echo " \
btc.rpc.user= $RPC_USER
2019-12-04 08:13:21 +00:00
btc.rpc.password= $PASSWORD_B
2021-03-16 22:49:13 +00:00
" | sudo tee /home/btcpay/.nbxplorer/Main/settings.config
sudo chmod 600 /home/btcpay/.nbxplorer/Main/settings.config
2019-12-04 08:13:21 +00:00
sudo chown btcpay:btcpay /home/btcpay/.nbxplorer/Main/settings.config
2020-07-18 22:43:14 +02:00
if [ " ${ state } " = = "ready" ] ; then
2020-07-24 00:42:56 +02:00
sudo systemctl restart nbxplorer
fi
2020-05-01 11:34:52 +02:00
2020-01-21 04:21:35 +00:00
# BTCPayServer
2020-11-11 16:40:48 +00:00
echo
echo "# Install BTCPayServer"
2021-03-16 22:49:13 +00:00
echo
2021-03-17 20:23:29 +00:00
cd /home/btcpay || exit 1
echo "# Download the BTCPayServer source code ..."
2020-01-21 04:21:35 +00:00
sudo -u btcpay git clone https://github.com/btcpayserver/btcpayserver.git 2>/dev/null
2019-12-04 08:13:21 +00:00
cd btcpayserver
2020-11-11 16:40:48 +00:00
sudo -u btcpay git reset --hard $BTCPayVersion
2021-03-17 20:23:29 +00:00
echo "# Build BTCPayServer ..."
2020-01-21 04:21:35 +00:00
# from the build.sh with path
2020-05-01 11:34:52 +02:00
sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release /home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj
2021-03-17 20:23:29 +00:00
# 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"
2019-12-04 08:13:21 +00:00
echo "
[ Unit]
Description = BtcPayServer daemon
2021-03-17 20:23:29 +00:00
Requires = nbxplorer.service
2019-12-04 08:13:21 +00:00
After = nbxplorer.service
[ Service]
2021-03-17 20:23:29 +00:00
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
2019-12-04 08:13:21 +00:00
User = btcpay
Group = btcpay
Type = simple
PIDFile = /run/btcpayserver/btcpayserver.pid
Restart = on-failure
2021-06-02 09:18:29 +01:00
# Hardening measures
PrivateTmp = true
ProtectSystem = full
NoNewPrivileges = true
PrivateDevices = true
2019-12-04 08:13:21 +00:00
[ Install]
WantedBy = multi-user.target
2020-01-13 15:00:22 +00:00
" | sudo tee /etc/systemd/system/btcpayserver.service
2021-03-16 22:49:13 +00:00
sudo systemctl enable btcpayserver
2020-05-01 11:34:52 +02:00
2021-03-16 22:49:13 +00:00
if [ " ${ state } " = = "ready" ] ; then
2020-11-11 16:40:48 +00:00
echo "# Starting btcpayserver"
2020-07-18 22:43:14 +02:00
sudo systemctl start btcpayserver
2020-11-11 16:40:48 +00:00
echo "# Checking for btcpayserver config"
2021-03-16 22:49:13 +00:00
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
2020-07-24 00:42:56 +02:00
done
2020-07-18 22:43:14 +02:00
else
2020-11-11 16:40:48 +00:00
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"
2020-07-18 22:43:14 +02:00
fi
2020-07-18 23:49:12 +02:00
sudo -u btcpay mkdir -p /home/btcpay/.btcpayserver/Main/
2020-04-28 14:14:17 +01:00
/home/admin/config.scripts/bonus.btcpayserver.sh write-tls-macaroon
2019-12-04 08:13:21 +00:00
2020-05-01 11:34:52 +02:00
else
2020-11-11 16:40:48 +00:00
echo "# BTCPay Server is already installed."
2020-07-18 22:43:14 +02:00
if [ " ${ state } " = = "ready" ] ; then
# start service
2020-11-11 16:40:48 +00:00
echo "# start service"
2020-07-18 22:43:14 +02:00
sudo systemctl start nbxplorer 2>/dev/null
sudo systemctl start btcpayserver 2>/dev/null
fi
2020-05-01 11:34:52 +02:00
fi
2019-12-05 15:31:07 +00:00
# setting value in raspi blitz config
sudo sed -i "s/^BTCPayServer=.*/BTCPayServer=on/g" /mnt/hdd/raspiblitz.conf
2019-12-04 08:13:21 +00:00
exit 0
fi
# switch off
if [ " $1 " = "0" ] || [ " $1 " = "off" ] ; then
2020-07-23 23:54:25 +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
2020-10-14 23:25:39 +02:00
if ( whiptail --title " DELETE DATA? " --yesno "Do you want to delete\nthe BTCPay Server Data?" 8 30) ; then
2020-07-23 23:54:25 +02:00
deleteData = 1
else
deleteData = 0
fi
fi
2020-07-23 23:58:34 +02:00
echo " # deleteData( ${ deleteData } ) "
2020-07-23 23:54:25 +02:00
2019-12-04 08:13:21 +00:00
# setting value in raspi blitz config
sudo sed -i "s/^BTCPayServer=.*/BTCPayServer=off/g" /mnt/hdd/raspiblitz.conf
2020-07-12 20:05:41 +02:00
# Hidden Service if Tor is active
if [ " ${ runBehindTor } " = "on" ] ; then
/home/admin/config.scripts/internet.hiddenservice.sh off btcpay
fi
2019-12-04 08:13:21 +00:00
isInstalled = $( sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service' )
if [ ${ isInstalled } -eq 1 ] ; then
2020-07-23 23:54:25 +02:00
echo "# *** REMOVING BTCPAYSERVER, NBXPLORER and .NET ***"
2020-01-27 08:29:25 +00:00
# removing services
# btcpay
2019-12-04 08:13:21 +00:00
sudo systemctl stop btcpayserver
sudo systemctl disable btcpayserver
sudo rm /etc/systemd/system/btcpayserver.service
2020-01-27 08:29:25 +00:00
# nbxplorer
sudo systemctl stop nbxplorer
sudo systemctl disable nbxplorer
sudo rm /etc/systemd/system/nbxplorer.service
# clear dotnet cache
2020-04-28 14:40:09 +01:00
dotnet nuget locals all --clear
2020-01-21 04:21:35 +00:00
sudo rm -rf /tmp/NuGetScratch
2020-01-27 08:29:25 +00:00
# remove dotnet
2020-01-21 04:21:35 +00:00
sudo rm -rf /usr/share/dotnet
2020-01-27 08:29:25 +00:00
# clear app config (not user data)
2019-12-04 08:13:21 +00:00
sudo rm -f /home/btcpay/.nbxplorer/Main/settings.config
sudo rm -f /home/btcpay/.btcpayserver/Main/settings.config
2020-06-11 18:15:42 +01:00
# clear nginx config (from btcpaysetdomain)
2020-01-27 08:29:25 +00:00
sudo rm -f /etc/nginx/sites-enabled/btcpayserver
2020-01-27 04:12:03 +01:00
sudo rm -f /etc/nginx/sites-available/btcpayserver
2020-06-11 18:15:42 +01:00
# 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
2020-06-26 20:43:16 +02:00
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
2020-06-11 18:15:42 +01:00
sudo nginx -t
sudo systemctl reload nginx
2020-04-28 14:40:09 +01:00
# nuke user
sudo userdel -rf btcpay 2>/dev/null
2020-07-23 23:54:25 +02:00
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."
2020-05-01 11:34:52 +02:00
else
2020-07-23 23:54:25 +02:00
echo "# BTCPayServer is not installed."
2019-12-04 08:13:21 +00:00
fi
exit 0
fi
2020-11-11 16:40:48 +00:00
echo " # FAIL - Unknown Parameter $1 "
2019-12-23 19:03:00 +01:00
exit 1