project/btcpayserver/stub_btcpay_setup.sh

111 lines
3.2 KiB
Bash
Raw Normal View History

2023-03-06 19:30:56 +00:00
#!/bin/bash
set -e
cd "$(dirname "$0")"
2023-04-04 15:08:22 +00:00
2023-03-06 19:30:56 +00:00
# default is for regtest
CLIGHTNING_WEBSOCKET_PORT=9736
if [ "$BITCOIN_CHAIN" = testnet ]; then
CLIGHTNING_WEBSOCKET_PORT=9737
elif [ "$BITCOIN_CHAIN" = mainnet ]; then
CLIGHTNING_WEBSOCKET_PORT=9738
fi
export CLIGHTNING_WEBSOCKET_PORT="$CLIGHTNING_WEBSOCKET_PORT"
2023-04-04 15:08:22 +00:00
2023-03-06 19:30:56 +00:00
# export BTCPAY_FASTSYNC_ARCHIVE_FILENAME="utxo-snapshot-bitcoin-testnet-1445586.tar"
# BTCPAY_REMOTE_RESTORE_PATH="/var/lib/docker/volumes/generated_bitcoin_datadir/_data"
# This is the config for a basic proxy to the listening port 127.0.0.1:2368
# It also supports modern TLS, so SSL certs must be available.
#opt-add-nostr-relay;
export BTCPAYSERVER_GITREPO="https://github.com/btcpayserver/btcpayserver-docker"
cat > "$SITE_PATH/btcpay.sh" <<EOL
#!/bin/bash
set -e
cd "\$(dirname "\$0")"
# wait for cloud-init to complete yo
while [ ! -f /var/lib/cloud/instance/boot-finished ]; do
sleep 1
done
if [ ! -d "btcpayserver-docker" ]; then
echo "cloning btcpayserver-docker";
git clone -b master ${BTCPAYSERVER_GITREPO} btcpayserver-docker;
2023-08-11 13:48:20 +00:00
git config --global --add safe.directory /home/ubuntu/ss-data/btcpayserver-docker
2023-03-06 19:30:56 +00:00
else
cd ./btcpayserver-docker
git pull
git pull --all --tags
cd -
fi
cd btcpayserver-docker
export BTCPAY_HOST="${BTCPAY_USER_FQDN}"
export BTCPAY_ANNOUNCEABLE_HOST="${DOMAIN_NAME}"
export NBITCOIN_NETWORK="${BITCOIN_CHAIN}"
export LIGHTNING_ALIAS="${PRIMARY_DOMAIN}"
export BTCPAYGEN_LIGHTNING="clightning"
export BTCPAYGEN_CRYPTO1="btc"
export BTCPAYGEN_ADDITIONAL_FRAGMENTS="opt-save-storage-s;bitcoin-clightning.custom;"
export BTCPAYGEN_REVERSEPROXY="nginx"
export BTCPAY_ENABLE_SSH=false
2023-04-02 13:28:42 +00:00
export BTCPAY_BASE_DIRECTORY=${REMOTE_DATA_PATH}
2023-03-06 19:30:56 +00:00
export BTCPAYGEN_EXCLUDE_FRAGMENTS="nginx-https;"
export REVERSEPROXY_DEFAULT_HOST="$BTCPAY_USER_FQDN"
2023-04-02 13:24:59 +00:00
# if [ "\$NBITCOIN_NETWORK" != regtest ]; then
# cd ./contrib/FastSync
# ./load-utxo-set.sh
# cd -
# fi
2023-03-06 19:30:56 +00:00
# next we create fragments to customize various aspects of the system
# this block customizes clightning to ensure the correct endpoints are being advertised
# We want to advertise the correct ipv4 endpoint for remote hosts to get in touch.
2023-04-02 13:28:42 +00:00
cat > ${REMOTE_DATA_PATH}/btcpayserver-docker/docker-compose-generator/docker-fragments/bitcoin-clightning.custom.yml <<EOF
2023-03-06 19:30:56 +00:00
services:
clightning_bitcoin:
environment:
LIGHTNINGD_OPT: |
2023-08-11 13:48:20 +00:00
#announce-addr=${BTCPAY_USER_FQDN}
#announce-addr-dns=true
2023-03-06 19:30:56 +00:00
experimental-websocket-port=9736
2023-08-11 13:48:20 +00:00
experimental-peer-storage
experimental-offers
#experimental-dual-fund
#experimental-onion-messages
2023-03-06 19:30:56 +00:00
ports:
- "${CLIGHTNING_WEBSOCKET_PORT}:9736"
expose:
- "9736"
EOF
2023-08-11 13:48:20 +00:00
2023-03-06 19:30:56 +00:00
# run the setup script.
. ./btcpay-setup.sh -i
2023-04-02 13:28:42 +00:00
touch ${REMOTE_DATA_PATH}/btcpay.complete
2023-04-04 15:10:14 +00:00
chown ubuntu:ubuntu ${REMOTE_DATA_PATH}/btcpay.complete
2023-03-06 19:30:56 +00:00
EOL
# send the setup script to the remote machine.
2023-08-11 13:48:20 +00:00
scp "$SITE_PATH/btcpay.sh" "ubuntu@$BTCPAY_SERVER_FQDN:$REMOTE_DATA_PATH/btcpay_setup.sh"
ssh "$BTCPAY_SERVER_FQDN" "chmod 0744 $REMOTE_DATA_PATH/btcpay_setup.sh"
2023-03-06 19:30:56 +00:00
# script is executed under sudo
2023-08-11 13:48:20 +00:00
ssh "$BTCPAY_SERVER_FQDN" "sudo bash -c $REMOTE_DATA_PATH/btcpay_setup.sh"
2023-03-06 19:30:56 +00:00
# lets give time for the containers to spin up
sleep 10