BTCpay and NBXplorer update, use postgres for new installs (#3641)

* use postgres for new btcpay installs
keep sqlite if the database is present
clean and format the script with shellcheck
* reinstall the service on update and check postgres
* run userdel -rf btcpay when off
* btcpay update to v1.7.5
* add systemctl daemon-reload when changing service
* exit on failed builds
* Restart=always
* nbxplorer update to v2.3.58
* prevent the git error 'detected dubious ownership in repository'
This commit is contained in:
openoms 2023-02-04 12:37:59 +00:00 committed by GitHub
parent 61823316dc
commit 57434aa107
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 175 additions and 138 deletions

View file

@ -20,7 +20,7 @@
- Update: RTL v0.13.0 with update option [details](https://github.com/Ride-The-Lightning/RTL/releases/tag/v0.12.3) - Update: RTL v0.13.0 with update option [details](https://github.com/Ride-The-Lightning/RTL/releases/tag/v0.12.3)
- Update: Thunderhub v0.13.16 with balance sharing disabled [details](https://github.com/apotdevin/thunderhub/releases/tag/v0.13.16) - Update: Thunderhub v0.13.16 with balance sharing disabled [details](https://github.com/apotdevin/thunderhub/releases/tag/v0.13.16)
- Update: LNbits 0.9.6 [details](https://github.com/lnbits/lnbits-legend/releases/tag/0.9.6) - Update: LNbits 0.9.6 [details](https://github.com/lnbits/lnbits-legend/releases/tag/0.9.6)
- Update: BTCPayServer 1.7.2 [details](https://github.com/btcpayserver/btcpayserver/releases/tag/v1.7.2) - Update: BTCPayServer 1.7.5 (using postgres for new installs) [details](https://github.com/btcpayserver/btcpayserver/releases/tag/v1.7.5)
- Update: ItchySats 0.7.0 [details](https://github.com/itchysats/itchysats/releases/tag/0.7.0) - Update: ItchySats 0.7.0 [details](https://github.com/itchysats/itchysats/releases/tag/0.7.0)
- Update: Channel Tools (chantools) v0.10.5 [details](https://github.com/guggero/chantools/releases/tag/v0.10.5) - Update: Channel Tools (chantools) v0.10.5 [details](https://github.com/guggero/chantools/releases/tag/v0.10.5)
- Update: JoinMarket v0.9.8 [details](https://github.com/JoinMarket-Org/joinmarket-clientserver/releases/tag/v0.9.8) - Update: JoinMarket v0.9.8 [details](https://github.com/JoinMarket-Org/joinmarket-clientserver/releases/tag/v0.9.8)

View file

@ -3,9 +3,9 @@
# Based on: https://gist.github.com/normandmickey/3f10fc077d15345fb469034e3697d0d0 # Based on: https://gist.github.com/normandmickey/3f10fc077d15345fb469034e3697d0d0
# https://github.com/dgarage/NBXplorer/tags # https://github.com/dgarage/NBXplorer/tags
NBXplorerVersion="v2.3.49" NBXplorerVersion="v2.3.58"
# https://github.com/btcpayserver/btcpayserver/releases # https://github.com/btcpayserver/btcpayserver/releases
BTCPayVersion="v1.7.2" BTCPayVersion="v1.7.5"
# command info # command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
@ -25,27 +25,19 @@ source /mnt/hdd/raspiblitz.conf
source /home/admin/raspiblitz.info source /home/admin/raspiblitz.info
source <(/home/admin/_cache.sh get state) source <(/home/admin/_cache.sh get state)
function postgresConfig() { function NBXplorerConfig() {
# check the postgres database
echo "# Generate the database" if sudo -u postgres psql -c '\l' | grep nbxplorermainnet; then
sudo -u postgres psql -c "create database nbxplorermainnet;" echo "# nbxplorermainnet database already exists"
sudo -u postgres psql -c "create user nbxplorer with encrypted password 'raspiblitz';" else
# change to ${newPassword} or use Passfile= echo "# Generate the database for nbxplorer"
# sudo -u postgres psql -c "alter user btcpay with encrypted password '${newPassword}';" sudo -u postgres psql -c "create database nbxplorermainnet;"
# sudo -u btcpay sed -i "s/Password=*/Password='${newPassword}';/g" /home/btcpay/.nbxplorer/Main/settings.config sudo -u postgres psql -c "create user nbxplorer with encrypted password 'raspiblitz';"
# sudo -u btcpay sed -i "s/Password=*/Password='${newPassword}';/g" /home/btcpay/.btcpayserver/Main/settings.config sudo -u postgres psql -c "grant all privileges on database nbxplorermainnet to nbxplorer;"
sudo -u postgres psql -c "grant all privileges on database nbxplorermainnet to nbxplorer;" fi
echo "# List databases with: sudo -u postgres psql -c '\l'" echo "# List databases with: sudo -u postgres psql -c '\l'"
sudo -u postgres psql -c '\l' sudo -u postgres psql -c '\l'
## clean postgresql:
# sudo su - postgres -c "/usr/lib/postgresql/${PGVERSION}/bin/pg_ctl stop --wait --pgdata=/var/lib/postgresql/${PGVERSION}/main"
# sudo pg_dropcluster ${PGVERSION} main
# sudo apt remove postgresql -y --purge
# sudo apt remove postgresql-${PGVERSION} -y --purge
}
function NBXplorerConfig() {
# https://docs.btcpayserver.org/Deployment/ManualDeploymentExtended/#4-create-a-configuration-file # https://docs.btcpayserver.org/Deployment/ManualDeploymentExtended/#4-create-a-configuration-file
echo echo
echo "# Getting RPC credentials from the bitcoin.conf" echo "# Getting RPC credentials from the bitcoin.conf"
@ -66,7 +58,24 @@ nomigrateevts=1
function BtcPayConfig() { function BtcPayConfig() {
# set thumbprint # set thumbprint
FINGERPRINT=$(openssl x509 -noout -fingerprint -sha256 -inform pem -in /home/btcpay/.lnd/tls.cert | cut -d"=" -f2) FINGERPRINT=$(openssl x509 -noout -fingerprint -sha256 -inform pem -in /home/btcpay/.lnd/tls.cert | cut -d"=" -f2)
echo "# setting the LND TLS thumbprint for BTCPay" if sudo ls /mnt/hdd/app-data/.btcpayserver/Main/sqllite.db 1>/dev/null 2>&1; then
echo "# sqlite database exists"
databaseOption="# keep using sqlite as /mnt/hdd/app-data/.btcpayserver/Main/sqllite.db exists (configured in the btcpayserver.service)"
else
echo "# sqlite database does not exist, using postgresql"
databaseOption="postgres=User ID=btcpay;Host=localhost;Port=5432;Application Name=btcpay;MaxPoolSize=20;Database=btcpaymainnet;Password='raspiblitz';"
if sudo -u postgres psql -c '\l' | grep btcpaymainnet; then
echo "# btcpaymainnet database already exists"
else
echo "# Generate the database for btcpay"
sudo -u postgres psql -c "create database btcpaymainnet;"
sudo -u postgres psql -c "create user btcpay with encrypted password 'raspiblitz';"
sudo -u postgres psql -c "grant all privileges on database btcpaymainnet to btcpay;"
fi
echo "# List databases with: sudo -u postgres psql -c '\l'"
sudo -u postgres psql -c '\l'
fi
echo "# Regenerate the btcpayserver settings (includes the LND TLS thumbprint)"
# https://docs.btcpayserver.org/Deployment/ManualDeploymentExtended/#3-create-a-configuration-file # https://docs.btcpayserver.org/Deployment/ManualDeploymentExtended/#3-create-a-configuration-file
echo " echo "
### Global settings ### ### Global settings ###
@ -82,24 +91,60 @@ 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 BTC.lightning=type=lnd-rest;server=https://127.0.0.1:8080/;macaroonfilepath=/home/btcpay/admin.macaroon;certthumbprint=$FINGERPRINT
### Database ### ### Database ###
# keep sqlite for now as configured in the btcpayserver.service ${databaseOption}
# postgres=User ID=btcpay;Password=urpassword;Application Name=btcpayserver;Host=localhost;Port=5432;Database=btcpay;
explorer.postgres=User ID=nbxplorer;Host=localhost;Port=5432;Application Name=nbxplorer;MaxPoolSize=20;Database=nbxplorermainnet;Password='raspiblitz'; explorer.postgres=User ID=nbxplorer;Host=localhost;Port=5432;Application Name=nbxplorer;MaxPoolSize=20;Database=nbxplorermainnet;Password='raspiblitz';
" | sudo -u btcpay tee /home/btcpay/.btcpayserver/Main/settings.config " | sudo -u btcpay tee /home/btcpay/.btcpayserver/Main/settings.config
#doesNetworkEntryAlreadyExists=$(sudo cat /home/btcpay/.btcpayserver/Main/settings.config | grep -c '^network=') }
#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\;" function BtcPayService() {
#sudo -u btcpay sed -i "s|^${s}certthumbprint=.*|${s}certthumbprint=$FINGERPRINT|g" /home/btcpay/.btcpayserver/Main/settings.config if sudo ls /mnt/hdd/app-data/.btcpayserver/Main/sqllite.db 1>/dev/null 2>&1; then
echo "# sqlite database exists"
databaseOption=" -- --sqlitefile=sqllite.db"
else
echo "# sqlite database does not exist, using postgresql"
databaseOption=""
fi
# see the configuration options with:
# sudo -u btcpay /home/btcpay/dotnet/dotnet run --no-launch-profile --no-build -c Release --project "/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 --project "/home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj" -- --sqlitefile=sqllite.db
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 --project \"/home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj\" ${databaseOption}
User=btcpay
Group=btcpay
Type=simple
PIDFile=/run/btcpayserver/btcpayserver.pid
Restart=always
RestartSec=10
# Hardening measures
PrivateTmp=true
ProtectSystem=full
NoNewPrivileges=true
PrivateDevices=true
[Install]
WantedBy=multi-user.target
" | sudo tee /etc/systemd/system/btcpayserver.service
sudo systemctl daemon-reload
} }
if [ "$1" = "status" ]; then if [ "$1" = "status" ]; then
echo "version='${BTCPayVersion}'" echo "version='${BTCPayVersion}'"
isInstalled=$(compgen -u | grep -c btcpay) isInstalled=$(compgen -u | grep -c btcpay)
echo "prepared=${isInstalled}" echo "prepared=${isInstalled}"
isActive=$(sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service') isActive=$(sudo ls /etc/systemd/system/btcpayserver.service 2>/dev/null | grep -c 'btcpayserver.service')
echo "installed=${isActive}" echo "installed=${isActive}"
if [ "${BTCPayServer}" = "on" ]; then if [ "${BTCPayServer}" = "on" ]; then
echo "switchedon=1" echo "switchedon=1"
@ -168,31 +213,31 @@ if [ "$1" = "menu" ]; then
source <(sudo /home/admin/config.scripts/bonus.btcpayserver.sh status) source <(sudo /home/admin/config.scripts/bonus.btcpayserver.sh status)
if [ ${switchedon} -eq 0 ]; then if [ ${switchedon} -eq 0 ]; then
whiptail --title " BTCPay Server " --msgbox "BTCPay Server is not activated." 7 36 whiptail --title " BTCPay Server " --msgbox "BTCPay Server is not activated." 7 36
exit 0 exit 0
fi fi
if [ ${installed} -eq 0 ]; then if [ ${installed} -eq 0 ]; then
whiptail --title " BTCPay Server " --msgbox "BTCPay Server needs to be re-installed.\nPress OK to start process." 8 45 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 /home/admin/config.scripts/bonus.btcpayserver.sh on
exit 0 exit 0
fi fi
# display possible problems with IP2TOR setup # display possible problems with IP2TOR setup
if [ ${#ip2torWarn} -gt 0 ]; then if [ ${#ip2torWarn} -gt 0 ]; then
whiptail --title " Warning " \ whiptail --title " Warning " \
--yes-button "Back" \ --yes-button "Back" \
--no-button "Continue Anyway" \ --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 --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 if [ "$?" != "1" ]; then
exit 0 exit 0
fi fi
fi fi
text="Local Web Browser: https://${localIP}:${httpsPort}" text="Local Web Browser: https://${localIP}:${httpsPort}"
if [ ${#publicDomain} -gt 0 ]; then if [ ${#publicDomain} -gt 0 ]; then
text="${text} text="${text}
Public Domain: https://${publicDomain}:${httpsPort} Public Domain: https://${publicDomain}:${httpsPort}
port forwarding on router needs to be active & may change port" port forwarding on router needs to be active & may change port"
fi fi
@ -222,7 +267,7 @@ To enable easy reachability with normal browser from the outside
consider adding a IP2TOR Bridge: MAINMENU > SUBSCRIBE > IP2TOR" consider adding a IP2TOR Bridge: MAINMENU > SUBSCRIBE > IP2TOR"
fi fi
text="${text}\n text="${text}\n
To get the 'Connection String' to activate Lightning Payments: To get the 'Connection String' to activate Lightning Payments:
MAINMENU > CONNECT > BTCPay Server" MAINMENU > CONNECT > BTCPay Server"
@ -241,8 +286,8 @@ if [ "$1" = "write-tls-macaroon" ]; then
echo "# make sure symlink to central app-data directory exists" echo "# make sure symlink to central app-data directory exists"
if ! [[ -L "/home/btcpay/.lnd" ]]; then if ! [[ -L "/home/btcpay/.lnd" ]]; then
sudo rm -rf "/home/btcpay/.lnd" # not a symlink.. delete it silently 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 sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/btcpay/.lnd" # and create symlink
fi fi
# copy admin macaroon # copy admin macaroon
@ -264,7 +309,7 @@ if [ "$1" = "cln-lightning-rpc-access" ]; then
if [ "${cl}" = "on" ]; then if [ "${cl}" = "on" ]; then
source <(/home/admin/config.scripts/network.aliases.sh getvars cl mainnet) source <(/home/admin/config.scripts/network.aliases.sh getvars cl mainnet)
if [ $(grep -c "^rpc-file-mode=0660" < ${CLCONF}) -eq 0 ]; then if [ $(grep -c "^rpc-file-mode=0660" <${CLCONF}) -eq 0 ]; then
echo "rpc-file-mode=0660" | tee -a ${CLCONF} echo "rpc-file-mode=0660" | tee -a ${CLCONF}
if [ "${state}" == "ready" ]; then if [ "${state}" == "ready" ]; then
sudo systemctl restart lightningd sudo systemctl restart lightningd
@ -341,9 +386,9 @@ if [ "$1" = "install" ]; then
echo "DOTNET_CLI_TELEMETRY_OPTOUT=1" | sudo tee -a /etc/environment echo "DOTNET_CLI_TELEMETRY_OPTOUT=1" | sudo tee -a /etc/environment
# NBXplorer # NBXplorer
echo "# Install NBXplorer" echo "# Install NBXplorer $NBXplorerVersion"
cd /home/btcpay || exit 1 cd /home/btcpay || exit 1
echo "# Download the NBXplorer source code ..." echo "# Download the NBXplorer source code $NBXplorerVersion"
sudo -u btcpay git clone https://github.com/dgarage/NBXplorer.git 2>/dev/null sudo -u btcpay git clone https://github.com/dgarage/NBXplorer.git 2>/dev/null
cd NBXplorer || exit 1 cd NBXplorer || exit 1
sudo -u btcpay git reset --hard $NBXplorerVersion sudo -u btcpay git reset --hard $NBXplorerVersion
@ -352,14 +397,17 @@ if [ "$1" = "install" ]; then
PGPpubkeyLink="https://keybase.io/nicolasdorier/pgp_keys.asc" PGPpubkeyLink="https://keybase.io/nicolasdorier/pgp_keys.asc"
PGPpubkeyFingerprint="AB4CFA9895ACA0DBE27F6B346618763EF09186FE" PGPpubkeyFingerprint="AB4CFA9895ACA0DBE27F6B346618763EF09186FE"
sudo -u btcpay /home/admin/config.scripts/blitz.git-verify.sh "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1 sudo -u btcpay /home/admin/config.scripts/blitz.git-verify.sh "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1
echo "# Build NBXplorer ..." echo "# Build NBXplorer $NBXplorerVersion"
# from the build.sh with path # from the build.sh with path
sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release NBXplorer/NBXplorer.csproj sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release NBXplorer/NBXplorer.csproj || (
echo "# Build failed"
exit 1
)
# BTCPayServer # BTCPayServer
echo "# Install BTCPayServer" echo "# Install BTCPayServer"
cd /home/btcpay || exit 1 cd /home/btcpay || exit 1
echo "# Download the BTCPayServer source code ..." echo "# Download the BTCPayServer source code $BTCPayVersion"
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 || exit 1 cd btcpayserver || exit 1
sudo -u btcpay git reset --hard $BTCPayVersion sudo -u btcpay git reset --hard $BTCPayVersion
@ -372,9 +420,13 @@ if [ "$1" = "install" ]; then
#PGPpubkeyFingerprint="8E5530D9D1C93097" #PGPpubkeyFingerprint="8E5530D9D1C93097"
sudo -u btcpay /home/admin/config.scripts/blitz.git-verify.sh "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1 sudo -u btcpay /home/admin/config.scripts/blitz.git-verify.sh "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1
echo "# Build BTCPayServer ..." echo "# Build BTCPayServer $BTCPayVersion"
# 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 || (
echo "# Build failed"
exit 1
)
exit 0 exit 0
fi fi
@ -430,13 +482,13 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
# setup nginx symlinks # setup nginx symlinks
if ! [ -f /etc/nginx/sites-available/btcpay_ssl.conf ]; then 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 sudo cp /home/admin/assets/nginx/sites-available/btcpay_ssl.conf /etc/nginx/sites-available/btcpay_ssl.conf
fi fi
if ! [ -f /etc/nginx/sites-available/btcpay_tor.conf ]; then 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 sudo cp /home/admin/assets/nginx/sites-available/btcpay_tor.conf /etc/nginx/sites-available/btcpay_tor.conf
fi fi
if ! [ -f /etc/nginx/sites-available/btcpay_tor_ssl.conf ]; then 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 sudo cp /home/admin/assets/nginx/sites-available/btcpay_tor_ssl.conf /etc/nginx/sites-available/btcpay_tor_ssl.conf
fi fi
sudo ln -sf /etc/nginx/sites-available/btcpay_ssl.conf /etc/nginx/sites-enabled/ 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.conf /etc/nginx/sites-enabled/
@ -522,26 +574,23 @@ WantedBy=multi-user.target
echo "# Starting nbxplorer" echo "# Starting nbxplorer"
sudo systemctl start nbxplorer sudo systemctl start nbxplorer
echo "# Checking for nbxplorer config" echo "# Checking for nbxplorer config"
while [ ! -f "/home/btcpay/.nbxplorer/Main/settings.config" ] while [ ! -f "/home/btcpay/.nbxplorer/Main/settings.config" ]; do
do echo "# Waiting for nbxplorer to start - CTRL+C to abort"
echo "# Waiting for nbxplorer to start - CTRL+C to abort" sleep 10
sleep 10 hasFailed=$(sudo systemctl status nbxplorer | grep -c "Active: failed")
hasFailed=$(sudo systemctl status nbxplorer | grep -c "Active: failed") if [ ${hasFailed} -eq 1 ]; then
if [ ${hasFailed} -eq 1 ]; then echo "# seems like starting nbxplorer service has failed - see: systemctl status nbxplorer"
echo "# seems like starting nbxplorer service has failed - see: systemctl status nbxplorer" echo "# maybe report here: https://github.com/rootzoll/raspiblitz/issues/214"
echo "# maybe report here: https://github.com/rootzoll/raspiblitz/issues/214" fi
fi
done done
else 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" 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 fi
postgresConfig
NBXplorerConfig NBXplorerConfig
# whitelist localhost in bitcoind # whitelist localhost in bitcoind
if ! sudo grep -Eq "^whitelist=127.0.0.1" /mnt/hdd/bitcoin/bitcoin.conf;then if ! sudo grep -Eq "^whitelist=127.0.0.1" /mnt/hdd/bitcoin/bitcoin.conf; then
echo "whitelist=127.0.0.1" | sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf echo "whitelist=127.0.0.1" | sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf
bitcoindRestart=yes bitcoindRestart=yes
fi fi
@ -554,38 +603,11 @@ WantedBy=multi-user.target
sudo systemctl restart nbxplorer sudo systemctl restart nbxplorer
fi fi
# see the configuration options with: BtcPayConfig
# 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 --project "/home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj" -- --sqlitefile=sqllite.db
echo "# create the btcpayserver.service"
echo "
[Unit]
Description=BtcPayServer daemon
Requires=nbxplorer.service
After=nbxplorer.service
[Service] BtcPayService
ExecStart=/home/btcpay/dotnet/dotnet run --no-launch-profile --no-build \
-c Release --project \"/home/btcpay/btcpayserver/BTCPayServer/BTCPayServer.csproj\" \
-- --sqlitefile=sqllite.db
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 sudo systemctl enable btcpayserver
if [ "${state}" == "ready" ]; then if [ "${state}" == "ready" ]; then
echo "# Starting btcpayserver" echo "# Starting btcpayserver"
sudo systemctl start btcpayserver sudo systemctl start btcpayserver
@ -593,14 +615,14 @@ WantedBy=multi-user.target
while [ ! -f "/home/btcpay/.btcpayserver/Main/settings.config" ]; do while [ ! -f "/home/btcpay/.btcpayserver/Main/settings.config" ]; do
echo "# Waiting for btcpayserver to start - CTRL+C to abort .." echo "# Waiting for btcpayserver to start - CTRL+C to abort .."
sleep 30 sleep 30
hasFailed=$(sudo systemctl status btcpayserver | grep -c "Active: failed") hasFailed=$(sudo systemctl status btcpayserver | grep -c "Active: failed")
if [ ${hasFailed} -eq 1 ]; then if [ ${hasFailed} -eq 1 ]; then
echo "# seems like starting btcpayserver service has failed - see: systemctl status btcpayserver" echo "# seems like starting btcpayserver service has failed - see: systemctl status btcpayserver"
echo "# maybe report here: https://github.com/rootzoll/raspiblitz/issues/214" echo "# maybe report here: https://github.com/rootzoll/raspiblitz/issues/214"
fi fi
done done
else 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" echo "# Because the system is not 'ready' the service 'btcpayserver' will not be started at this point .. it is enabled and will start on next reboot"
fi fi
sudo -u btcpay mkdir -p /home/btcpay/.btcpayserver/Main/ sudo -u btcpay mkdir -p /home/btcpay/.btcpayserver/Main/
@ -634,7 +656,7 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then
else else
if (whiptail --title " DELETE DATA? " --yesno "Do you want to delete\nthe BTCPay Server Data?" 8 30); then if (whiptail --title " DELETE DATA? " --yesno "Do you want to delete\nthe BTCPay Server Data?" 8 30); then
deleteData=1 deleteData=1
else else
deleteData=0 deleteData=0
fi fi
fi fi
@ -684,7 +706,10 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then
else else
echo "# keeping data" echo "# keeping data"
fi fi
echo "# OK BTCPayServer deactivaed." echo "# OK BTCPayServer deactivated."
echo "# delete the btcpay user home directory"
sudo userdel -rf btcpay 2>/dev/null
# needed for API/WebUI as signal that install ran thru # needed for API/WebUI as signal that install ran thru
echo "result='OK'" echo "result='OK'"
@ -693,6 +718,11 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then
fi fi
if [ "$1" = "update" ]; then if [ "$1" = "update" ]; then
# prevent the git error 'detected dubious ownership in repository'
git config --global --add safe.directory /home/btcpay/NBXplorer
git config --global --add safe.directory /home/btcpay/btcpayserver
echo "# Update NBXplorer" echo "# Update NBXplorer"
cd /home/btcpay || exit 1 cd /home/btcpay || exit 1
cd NBXplorer || exit 1 cd NBXplorer || exit 1
@ -712,7 +742,7 @@ if [ "$1" = "update" ]; then
TAG=$(git tag | sort -V | tail -1) TAG=$(git tag | sort -V | tail -1)
echo "# Up-to-date on version $TAG" echo "# Up-to-date on version $TAG"
else else
echo "# Pulling latest changes..." echo "# Pulling the latest changes..."
sudo -u btcpay git pull -p sudo -u btcpay git pull -p
TAG=$(git tag | sort -V | tail -1) TAG=$(git tag | sort -V | tail -1)
echo "# Reset to the latest release tag: $TAG" echo "# Reset to the latest release tag: $TAG"
@ -720,22 +750,24 @@ if [ "$1" = "update" ]; then
PGPsigner="nicolasdorier" PGPsigner="nicolasdorier"
PGPpubkeyLink="https://keybase.io/nicolasdorier/pgp_keys.asc" PGPpubkeyLink="https://keybase.io/nicolasdorier/pgp_keys.asc"
PGPpubkeyFingerprint="AB4CFA9895ACA0DBE27F6B346618763EF09186FE" PGPpubkeyFingerprint="AB4CFA9895ACA0DBE27F6B346618763EF09186FE"
sudo -u btcpay /home/admin/config.scripts/blitz.git-verify.sh \ sudo -u btcpay /home/admin/config.scripts/blitz.git-verify.sh \
"${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1 "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1
echo "# Build NBXplorer ..."
echo "# Build NBXplorer $TAG"
# from the build.sh with path # from the build.sh with path
sudo systemctl stop nbxplorer sudo systemctl stop nbxplorer
sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release NBXplorer/NBXplorer.csproj sudo -u btcpay /home/btcpay/dotnet/dotnet build -c Release NBXplorer/NBXplorer.csproj || (
echo "# Build failed"
exit 1
)
# whitelist localhost in bitcoind # whitelist localhost in bitcoind
if ! sudo grep -Eq "^whitelist=127.0.0.1" /mnt/hdd/bitcoin/bitcoin.conf;then if ! sudo grep -Eq "^whitelist=127.0.0.1" /mnt/hdd/bitcoin/bitcoin.conf; then
echo "whitelist=127.0.0.1" | sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf echo "whitelist=127.0.0.1" | sudo tee -a /mnt/hdd/bitcoin/bitcoin.conf
echo "# Restarting bitcoind" echo "# Restarting bitcoind"
sudo systemctl restart bitcoind sudo systemctl restart bitcoind
fi fi
# POSTGRES
postgresConfig
NBXplorerConfig NBXplorerConfig
sudo systemctl start nbxplorer sudo systemctl start nbxplorer
@ -747,6 +779,9 @@ if [ "$1" = "update" ]; then
BtcPayConfig BtcPayConfig
# always update the btcpayserver.service
BtcPayService
echo "# Update BTCPayServer" echo "# Update BTCPayServer"
cd /home/btcpay || exit 1 cd /home/btcpay || exit 1
cd btcpayserver || exit 1 cd btcpayserver || exit 1
@ -775,10 +810,13 @@ if [ "$1" = "update" ]; then
# https://github.com/rootzoll/raspiblitz/issues/3025 # https://github.com/rootzoll/raspiblitz/issues/3025
# sudo -u btcpay /home/admin/config.scripts/blitz.git-verify.sh \ # sudo -u btcpay /home/admin/config.scripts/blitz.git-verify.sh \
# "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1 # "${PGPsigner}" "${PGPpubkeyLink}" "${PGPpubkeyFingerprint}" || exit 1
echo "# Build BTCPayServer ..." echo "# Build BTCPayServer $TAG"
# from the build.sh with path # from the build.sh with path
sudo systemctl stop btcpayserver sudo systemctl stop btcpayserver
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 || (
echo "# Build failed"
exit 1
)
sudo systemctl start btcpayserver sudo systemctl start btcpayserver
echo "# Updated BTCPayServer to $TAG" echo "# Updated BTCPayServer to $TAG"
fi fi

View file

@ -2,12 +2,12 @@
# command info # command info
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "config script to install PostgreSQL" echo "config script to install PostgreSQL"
echo "bonus.postgresql.sh [on|off]" echo "bonus.postgresql.sh [on|off]"
echo "bonus.postgresql.sh [backup] [database]" echo "bonus.postgresql.sh [backup] [database]"
echo "bonus.postgresql.sh [restore] [database] [user] [password]" echo "bonus.postgresql.sh [restore] [database] [user] [password]"
echo "bonus.postgresql.sh [info]" echo "bonus.postgresql.sh [info]"
exit 1 exit 1
fi fi
command=$1 command=$1
@ -36,22 +36,22 @@ if [ "$command" = "1" ] || [ "$command" = "on" ]; then
fi fi
fix_postgres=0 fix_postgres=0
if [ -L $postgres_datadir ] ; then if [ -L $postgres_datadir ]; then
if [ -e $postgres_datadir ] ; then if [ -e $postgres_datadir ]; then
echo "# Good link in $postgres_datadir" echo "# Good link in $postgres_datadir"
else else
echo "# Broken link in $postgres_datadir" echo "# Broken link in $postgres_datadir"
fix_postgres=1 fix_postgres=1
fi fi
elif [ -e $postgres_datadir ] ; then elif [ -e $postgres_datadir ]; then
echo "# Not a link in $postgres_datadir" echo "# Not a link in $postgres_datadir"
fix_postgres=1 fix_postgres=1
else else
echo "# Missing Link in $postgres_datadir" echo "# Missing Link in $postgres_datadir"
fix_postgres=1 fix_postgres=1
fi fi
if [ fix_postgres = 1 ] || [ ! -d /mnt/hdd/app-data/postgresql ]; then if [ ${fix_postgres} = 1 ] || [ ! -d /mnt/hdd/app-data/postgresql ]; then
echo "# Move the PostgreSQL data to /mnt/hdd/app-data/postgresql" echo "# Move the PostgreSQL data to /mnt/hdd/app-data/postgresql"
sudo systemctl stop postgresql 2>/dev/null sudo systemctl stop postgresql 2>/dev/null
sudo rsync -av $postgres_datadir /mnt/hdd/app-data sudo rsync -av $postgres_datadir /mnt/hdd/app-data
@ -67,9 +67,8 @@ if [ "$command" = "1" ] || [ "$command" = "on" ]; then
# wait for the postgres server to start # wait for the postgres server to start
count=0 count=0
count_max=30 count_max=30
while ! nc -zv 127.0.0.1 5432 2>/dev/null; while ! nc -zv 127.0.0.1 5432 2>/dev/null; do
do count=$((count + 1))
count=`expr $count + 1`
echo "sleep $count/$count_max" echo "sleep $count/$count_max"
sleep 1 sleep 1
if [ $count = $count_max ]; then if [ $count = $count_max ]; then
@ -103,16 +102,16 @@ fi
# backup # backup
backup_target="/mnt/hdd/app-data/backup/$db_name" backup_target="/mnt/hdd/app-data/backup/$db_name"
backup_file="${db_name}_`date +%d`-`date +%m`-`date +%Y`_`date +%H`-`date +%M`_dump" backup_file="${db_name}_$(date +%d)-$(date +%m)-$(date +%Y)_$(date +%H)-$(date +%M)_dump"
if [ ! -d $backup_target ]; then if [ ! -d $backup_target ]; then
sudo mkdir -p $backup_target 1>&2 sudo mkdir -p $backup_target 1>&2
fi fi
# https://www.postgresql.org/docs/current/backup-dump.html # https://www.postgresql.org/docs/current/backup-dump.html
if [ "$command" = "backup" ] && [ "$db_name" != "" ]; then if [ "$command" = "backup" ] && [ "$db_name" != "" ]; then
echo "*** BACKUP POSTGRESQL $db_name ***" echo "*** BACKUP POSTGRESQL $db_name ***"
sudo -u postgres pg_dump $db_name > $backup_target/${backup_file}.sql || exit 1 sudo -u postgres pg_dump $db_name >$backup_target/${backup_file}.sql || exit 1
# Delete old backups (keep last 3 backups) # Delete old backups (keep last 3 backups)
sudo chown -R admin:admin $backup_target sudo chown -R admin:admin $backup_target
ls -tp $backup_target/*.sql | grep -v '/$' | tail -n +4 | tr '\n' '\0' | xargs -0 rm -- 2>/dev/null ls -tp $backup_target/*.sql | grep -v '/$' | tail -n +4 | tr '\n' '\0' | xargs -0 rm -- 2>/dev/null
@ -154,7 +153,7 @@ if [ "$command" = "restore" ] && [ "$db_name" != "" ] && [ "$db_user" != "" ] &&
echo "# Import SQL Dump" echo "# Import SQL Dump"
sudo mkdir -p $backup_target/logs 1>&2 sudo mkdir -p $backup_target/logs 1>&2
sudo chown -R postgres:postgres $backup_file sudo chown -R postgres:postgres $backup_file
sudo -u postgres psql $db_name < ${backup_file} > $backup_target/logs/sql_import.log || exit 1 sudo -u postgres psql $db_name <${backup_file} >$backup_target/logs/sql_import.log || exit 1
echo "$backup_target/sql_import.log written" echo "$backup_target/sql_import.log written"
echo "OK - database $db_name restored from ${backup_file}" echo "OK - database $db_name restored from ${backup_file}"
exit 0 exit 0