diff --git a/defaults.sh b/defaults.sh index 296d448..f6ddc3a 100755 --- a/defaults.sh +++ b/defaults.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -ex +set -e export DEPLOY_WWW_SERVER=false export DEPLOY_GHOST=false @@ -89,7 +89,7 @@ export UBUNTU_BASE_IMAGE_NAME="ss-ubuntu-${LXD_UBUNTU_BASE_VERSION//./-}" export DEPLOY_MGMT_REGISTRY=false export OTHER_SITES_LIST= export BTCPAY_ALT_NAMES= - +export BITCOIN_CHAIN=regtest export REMOTE_HOME="/home/ubuntu" export BTCPAY_SERVER_APPPATH="$REMOTE_HOME/btcpayserver-docker" @@ -98,4 +98,4 @@ export REMOTE_CERT_BASE_DIR="$REMOTE_HOME/.certs" # this space is for OS, docker images, etc. DOES NOT INCLUDE USER DATA. export ROOT_DISK_SIZE_GB=20 export REGISTRY_URL="https://index.docker.io/v1/" -export PRIMARY_DOMAIN= \ No newline at end of file +export PRIMARY_DOMAIN= diff --git a/deployment/btcpayserver/.gitignore b/deployment/btcpayserver/.gitignore new file mode 100644 index 0000000..26e8e7b --- /dev/null +++ b/deployment/btcpayserver/.gitignore @@ -0,0 +1 @@ +core-lightning \ No newline at end of file diff --git a/deployment/btcpayserver/backup_btcpay.sh b/deployment/btcpayserver/backup_btcpay.sh index 342a519..a4cf276 100755 --- a/deployment/btcpayserver/backup_btcpay.sh +++ b/deployment/btcpayserver/backup_btcpay.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -e +set -ex cd "$(dirname "$0")" # take the services down, create a backup archive, then pull it down. diff --git a/deployment/btcpayserver/go.sh b/deployment/btcpayserver/go.sh index f4a2051..e027189 100755 --- a/deployment/btcpayserver/go.sh +++ b/deployment/btcpayserver/go.sh @@ -5,6 +5,15 @@ cd "$(dirname "$0")" export DOCKER_HOST="ssh://ubuntu@$BTCPAY_FQDN" +docker pull btcpayserver/lightning:v22.11.1 +docker build -t clightning:latest ./core-lightning + +# run the btcpay setup script if it hasn't been done before. +if [ "$(ssh "$BTCPAY_FQDN" [[ ! -f "$REMOTE_HOME/btcpay.complete" ]]; echo $?)" -eq 0 ]; then + ./stub_btcpay_setup.sh + BACKUP_BTCPAY=false +fi + RUN_SERVICES=true # we will re-run the btcpayserver provisioning scripts if directed to do so. @@ -34,6 +43,7 @@ elif [ "$RECONFIGURE_BTCPAY_SERVER" == true ]; then ./stub_btcpay_setup.sh RUN_SERVICES=true + BACKUP_BTCPAY=false fi # if the script gets this far, then we grab a regular backup. @@ -48,4 +58,4 @@ if [ "$RUN_SERVICES" = true ] && [ "$STOP_SERVICES" = false ]; then ssh "$FQDN" "bash -c $BTCPAY_SERVER_APPPATH/btcpay-up.sh" fi -echo "FINISHED btcpayserver/go.sh" \ No newline at end of file +echo "FINISHED btcpayserver/go.sh" diff --git a/deployment/btcpayserver/stub_btcpay_setup.sh b/deployment/btcpayserver/stub_btcpay_setup.sh index 0adcefb..acf1105 100755 --- a/deployment/btcpayserver/stub_btcpay_setup.sh +++ b/deployment/btcpayserver/stub_btcpay_setup.sh @@ -3,12 +3,26 @@ set -e cd "$(dirname "$0")" +# 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" + # 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/farscapian/btcpayserver-docker" +#https://github.com/btcpayserver/btcpayserver-docker + cat > "$SITE_PATH/btcpay.sh" </dev/null 2>&1; then sleep 1 fi - if lxc network list --format csv | grep -q lxdbr1; then - lxc network delete lxdbr1 - sleep 1 - fi fi ssh -t "ubuntu@$FQDN" " @@ -172,6 +170,9 @@ if [ -z "$DATA_PLANE_MACVLAN_INTERFACE" ]; then DATA_PLANE_MACVLAN_INTERFACE="$(ssh -t ubuntu@"$FQDN" ip route | grep default | cut -d " " -f 5)" fi +export DATA_PLANE_MACVLAN_INTERFACE="$DATA_PLANE_MACVLAN_INTERFACE" + +echo "DATA_PLANE_MACVLAN_INTERFACE: $DATA_PLANE_MACVLAN_INTERFACE" # run lxd init on the remote server. cat < /home/ubuntu/.ss-githead" fi - -# deploy clams wallet. -LOCAL_CLAMS_PATH="$(pwd)/www/clams" -if [ "$DEPLOY_BTCPAY_SERVER" = true ]; then - if [ ! -d "$LOCAL_CLAMS_PATH" ]; then - git clone "$CLAMS_GIT_REPO" "$LOCAL_CLAMS_PATH" - else - cd "$LOCAL_CLAMS_PATH" - git pull - cd - - fi -fi - - diff --git a/deployment/deploy_vms.sh b/deployment/deploy_vms.sh index 2603b73..4bd6be1 100755 --- a/deployment/deploy_vms.sh +++ b/deployment/deploy_vms.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -ex +set -exu cd "$(dirname "$0")" @@ -34,8 +34,9 @@ if ! lxc list --format csv | grep -q "$LXD_VM_NAME"; then ./stub_lxc_profile.sh "$LXD_VM_NAME" lxc copy --profile="$LXD_VM_NAME" "$BASE_IMAGE_VM_NAME"/"ss-docker-$(date +%Y-%m)" "$LXD_VM_NAME" + # now let's create a new VM to work with. - #lxc init --profile="$LXD_VM_NAME" "$BASE_IMAGE_VM_NAME" "$LXD_VM_NAME" --vm + #@lxc init --profile="$LXD_VM_NAME" "$BASE_IMAGE_VM_NAME" "$LXD_VM_NAME" --vm # let's PIN the HW address for now so we don't exhaust IP # and so we can set DNS internally. @@ -52,11 +53,3 @@ ssh-keyscan -H -t ecdsa "$FQDN" >> "$SSH_HOME/known_hosts" # create a directory to store backup archives. This is on all new vms. ssh "$FQDN" mkdir -p "$REMOTE_HOME/backups" - -# if this execution is for btcpayserver, then we run the stub/btcpay setup script -# but only if it hasn't been executed before. -if [ "$VIRTUAL_MACHINE" = btcpayserver ]; then - if [ "$(ssh "$BTCPAY_FQDN" [[ ! -f "$REMOTE_HOME/btcpay.complete" ]]; echo $?)" -eq 0 ]; then - ./btcpayserver/stub_btcpay_setup.sh - fi -fi diff --git a/deployment/destroy.sh b/deployment/destroy.sh index 02ba408..b4704b6 100755 --- a/deployment/destroy.sh +++ b/deployment/destroy.sh @@ -1,9 +1,15 @@ #!/bin/bash -set -exu +set -ex cd "$(dirname "$0")" # this script takes down all resources in the cluster. This script is DESTRUCTIVE of data, so make sure it's backed up first. + +if lxc remote get-default | grep -q "local"; then + echo "ERROR: you are on the local lxc remote. Nothing to destroy" + exit 1 +fi + RESPONSE= read -r -p "Are you sure you want to continue? Responding 'y' here results in destruction of user data!": RESPONSE if [ "$RESPONSE" != "y" ]; then @@ -12,6 +18,8 @@ if [ "$RESPONSE" != "y" ]; then fi . ../defaults.sh + + . ./cluster_env.sh for VM in www btcpayserver; do diff --git a/deployment/reset.sh b/deployment/reset.sh index 79a01f3..199b978 100755 --- a/deployment/reset.sh +++ b/deployment/reset.sh @@ -6,54 +6,48 @@ cd "$(dirname "$0")" source ../defaults.sh -echo "Need to uncomment" -exit 1 -# ./destroy.sh +./destroy.sh -# # these only get initialzed upon creation, so we MUST delete here so they get recreated. -# if lxc profile list | grep -q "$BASE_IMAGE_VM_NAME"; then -# lxc profile delete "$BASE_IMAGE_VM_NAME" -# fi +# these only get initialzed upon creation, so we MUST delete here so they get recreated. +if lxc profile list | grep -q "$BASE_IMAGE_VM_NAME"; then + lxc profile delete "$BASE_IMAGE_VM_NAME" +fi -# if lxc image list | grep -q "$BASE_IMAGE_VM_NAME"; then -# lxc image rm "$BASE_IMAGE_VM_NAME" -# fi +if lxc image list | grep -q "$BASE_IMAGE_VM_NAME"; then + lxc image rm "$BASE_IMAGE_VM_NAME" +fi -# if lxc image list | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then -# lxc image rm "$UBUNTU_BASE_IMAGE_NAME" -# fi +if lxc image list | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then + lxc image rm "$UBUNTU_BASE_IMAGE_NAME" +fi -# CURRENT_PROJECT="$(lxc info | grep "project:" | awk '{print $2}')" -# if ! lxc info | grep -q "project: default"; then -# lxc project switch default -# lxc project delete "$CURRENT_PROJECT" -# fi +CURRENT_PROJECT="$(lxc info | grep "project:" | awk '{print $2}')" +if ! lxc info | grep -q "project: default"; then + lxc project switch default + lxc project delete "$CURRENT_PROJECT" +fi -# if lxc profile show default | grep -q "root:"; then -# lxc profile device remove default root -# fi +if lxc profile show default | grep -q "root:"; then + lxc profile device remove default root +fi -# if lxc profile show default| grep -q "eth0:"; then -# lxc profile device remove default eth0 -# fi +if lxc profile show default| grep -q "eth0:"; then + lxc profile device remove default eth0 +fi -# if lxc network list --format csv | grep -q lxdbr0; then -# lxc network delete lxdbr0 -# fi +if lxc network list --format csv | grep -q lxdbr0; then + lxc network delete lxdbr0 +fi -# if lxc network list --format csv | grep -q lxdbr1; then -# lxc network delete lxdbr1 -# fi +if lxc storage list --format csv | grep -q ss-base; then + lxc storage delete ss-base +fi -# if lxc storage list --format csv | grep -q ss-base; then -# lxc storage delete ss-base -# fi - -# CURRENT_REMOTE="$(lxc remote get-default)" -# if ! lxc remote get-default | grep -q "local"; then -# lxc remote switch local -# lxc remote remove "$CURRENT_REMOTE" -# fi +CURRENT_REMOTE="$(lxc remote get-default)" +if ! lxc remote get-default | grep -q "local"; then + lxc remote switch local + lxc remote remove "$CURRENT_REMOTE" +fi diff --git a/deployment/stub_lxc_profile.sh b/deployment/stub_lxc_profile.sh index 2be5849..2d554c8 100755 --- a/deployment/stub_lxc_profile.sh +++ b/deployment/stub_lxc_profile.sh @@ -107,14 +107,15 @@ if [ "$LXD_HOSTNAME" = "$BASE_IMAGE_VM_NAME" ]; then - path: /etc/docker/daemon.json content: | { - "registry-mirrors": ["${REGISTRY_URL}"], - "labels": [ "githead=${LATEST_GIT_COMMIT}" ] + "registry-mirrors": ["${REGISTRY_URL}"] } runcmd: - sudo apt-get install -y openssh-server EOF +#, +#"labels": [ "githead=${LATEST_GIT_COMMIT}" ] else # all other machines. @@ -195,7 +196,7 @@ cat >> "$YAML_PATH" < /dev/null 2>&1 +# let's ensure ~/.ssh/ssh_config is using the correct IP address for ss-mgmt. ssh ubuntu@"$IP_V4_ADDRESS" diff --git a/management/bashrc b/management/bashrc index afdeafb..6434430 100644 --- a/management/bashrc +++ b/management/bashrc @@ -85,7 +85,7 @@ if [ -x /usr/bin/dircolors ]; then fi # colored GCC warnings and errors -#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' +export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01' # some more ls aliases alias ll='ls -alF' diff --git a/temp/core-lightning/Dockerfile b/temp/core-lightning/Dockerfile new file mode 100644 index 0000000..6b5809d --- /dev/null +++ b/temp/core-lightning/Dockerfile @@ -0,0 +1,3 @@ +FROM btcpayserver/lightning:v22.11.1 + +EXPOSE 9736 \ No newline at end of file diff --git a/uninstall.sh b/uninstall.sh index b571fe6..9f75ebb 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -3,37 +3,52 @@ set -exu # this script undoes install.sh +if ! command -v lxc >/dev/null 2>&1; then + echo "This script requires 'lxc' to be installed. Please run 'install.sh'." + exit 1 +fi . ./defaults.sh if lxc list --format csv | grep -q ss-mgmt; then - if ! list list --format csv | grep ss-mgmt | grep -q "RUNNING"; then + if ! lxc list --format csv | grep ss-mgmt | grep -q "RUNNING"; then lxc stop ss-mgmt fi lxc config device remove ss-mgmt sscode - lxc delete ss-mgmt + lxc delete ss-mgmt -f fi -# if lxc image list | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then -# lxc image delete "$UBUNTU_BASE_IMAGE_NAME" -# fi +if lxc profile device list default | grep -q root; then + lxc profile device remove default root +fi -# if lxc storage list --format csv | grep -q sovereign-stack; then -# lxc profile device remove default root -# lxc storage delete sovereign-stack -# fi +if lxc profile device list default | grep -q enp5s0; then + lxc profile device remove default enp5s0 +fi -# if snap list | grep -q lxd; then -# sudo snap remove lxd -# sleep 2 -# fi +if lxc network list | grep -q lxdbr0; then + lxc network delete lxdbr0 +fi -# if zfs list | grep -q sovereign-stack; then -# sudo zfs destroy -r sovereign-stack -# fi +if lxc image list | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then + lxc image delete "$UBUNTU_BASE_IMAGE_NAME" +fi -# if zfs list | grep -q "sovereign-stack"; then -# sudo zfs destroy -r "rpool/lxd" -# fi +if lxc storage list --format csv | grep -q sovereign-stack; then + lxc storage delete sovereign-stack +fi + +if snap list | grep -q lxd; then + sudo snap remove lxd + sleep 2 +fi + +if zfs list | grep -q sovereign-stack; then + sudo zfs destroy -r sovereign-stack +fi + +if zfs list | grep -q "sovereign-stack"; then + sudo zfs destroy -r "rpool/lxd" +fi