2021-12-25 18:43:01 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-10-29 15:34:17 +00:00
|
|
|
set -eu
|
2021-12-25 18:43:01 +00:00
|
|
|
cd "$(dirname "$0")"
|
|
|
|
|
2022-04-22 20:10:24 +00:00
|
|
|
check_dependencies () {
|
|
|
|
for cmd in "$@"; do
|
|
|
|
if ! command -v "$cmd" >/dev/null 2>&1; then
|
2022-05-28 03:07:17 +00:00
|
|
|
echo "This script requires \"${cmd}\" to be installed. Please run 'install.sh'."
|
2022-04-22 20:10:24 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Check system's dependencies
|
2022-10-31 02:24:25 +00:00
|
|
|
check_dependencies wait-for-it dig rsync sshfs lxc
|
2022-04-22 20:10:24 +00:00
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
# let's check to ensure the management machine is on the Baseline ubuntu 21.04
|
2022-08-15 13:41:00 +00:00
|
|
|
if ! lsb_release -d | grep -q "Ubuntu 22.04"; then
|
2022-06-22 17:42:51 +00:00
|
|
|
echo "ERROR: Your machine is not running the Ubuntu 22.04 LTS baseline OS on your management machine."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-12-25 18:43:01 +00:00
|
|
|
DOMAIN_NAME=
|
2022-10-30 16:59:24 +00:00
|
|
|
RUN_CERT_RENEWAL=true
|
2022-10-27 20:07:00 +00:00
|
|
|
SKIP_WWW=false
|
2022-08-24 14:11:50 +00:00
|
|
|
RESTORE_WWW=false
|
2022-10-24 01:04:50 +00:00
|
|
|
BACKUP_CERTS=true
|
2022-10-27 20:07:00 +00:00
|
|
|
BACKUP_APPS=true
|
|
|
|
BACKUP_BTCPAY=true
|
2022-10-08 16:44:46 +00:00
|
|
|
RESTORE_BTCPAY=false
|
2022-10-27 01:41:14 +00:00
|
|
|
BTCPAY_RESTORE_ARCHIVE_PATH=
|
2022-10-27 20:07:00 +00:00
|
|
|
BTCPAY_LOCAL_BACKUP_PATH=
|
2022-08-24 14:11:50 +00:00
|
|
|
MIGRATE_WWW=false
|
|
|
|
MIGRATE_BTCPAY=false
|
2022-10-26 23:33:43 +00:00
|
|
|
SKIP_BTCPAY=false
|
2021-12-25 18:43:01 +00:00
|
|
|
UPDATE_BTCPAY=false
|
|
|
|
RECONFIGURE_BTCPAY_SERVER=false
|
2022-07-27 16:38:33 +00:00
|
|
|
CLUSTER_NAME="$(lxc remote get-default)"
|
2022-10-22 00:04:03 +00:00
|
|
|
STOP_SERVICES=false
|
2022-04-22 19:51:02 +00:00
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
# grab any modifications from the command line.
|
2021-12-25 18:43:01 +00:00
|
|
|
for i in "$@"; do
|
|
|
|
case $i in
|
2022-07-27 16:38:33 +00:00
|
|
|
--restore-www)
|
2022-08-24 14:11:50 +00:00
|
|
|
RESTORE_WWW=true
|
2022-10-08 16:44:46 +00:00
|
|
|
BACKUP_APPS=false
|
2022-05-24 18:19:26 +00:00
|
|
|
RUN_CERT_RENEWAL=false
|
2021-12-25 18:43:01 +00:00
|
|
|
shift
|
|
|
|
;;
|
2022-07-27 16:38:33 +00:00
|
|
|
--restore-btcpay)
|
|
|
|
RESTORE_BTCPAY=true
|
2022-08-24 14:11:50 +00:00
|
|
|
BACKUP_BTCPAY=false
|
2022-10-08 16:44:46 +00:00
|
|
|
RUN_CERT_RENEWAL=false
|
2022-07-27 16:38:33 +00:00
|
|
|
shift
|
|
|
|
;;
|
2022-09-28 17:59:01 +00:00
|
|
|
--backup-certs)
|
|
|
|
BACKUP_CERTS=true
|
|
|
|
shift
|
|
|
|
;;
|
2022-10-22 00:04:03 +00:00
|
|
|
--stop)
|
|
|
|
STOP_SERVICES=true
|
|
|
|
shift
|
|
|
|
;;
|
2022-05-28 03:07:17 +00:00
|
|
|
--domain=*)
|
|
|
|
DOMAIN_NAME="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2022-01-14 21:25:45 +00:00
|
|
|
--update-btcpay)
|
2021-12-25 18:43:01 +00:00
|
|
|
UPDATE_BTCPAY=true
|
|
|
|
shift
|
|
|
|
;;
|
2022-07-27 16:38:33 +00:00
|
|
|
--skip-www)
|
2022-10-26 23:33:43 +00:00
|
|
|
SKIP_WWW=true
|
2022-07-27 16:38:33 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--skip-btcpay)
|
2022-10-26 23:33:43 +00:00
|
|
|
SKIP_BTCPAY=true
|
2022-07-27 16:38:33 +00:00
|
|
|
shift
|
|
|
|
;;
|
2022-09-28 17:59:01 +00:00
|
|
|
--backup-ghost)
|
2022-10-08 16:44:46 +00:00
|
|
|
BACKUP_APPS=true
|
2021-12-25 18:43:01 +00:00
|
|
|
shift
|
|
|
|
;;
|
2022-09-28 17:59:01 +00:00
|
|
|
--backup-btcpay)
|
|
|
|
BACKUP_BTCPAY=true
|
2022-08-24 14:11:50 +00:00
|
|
|
shift
|
|
|
|
;;
|
2022-10-27 01:41:14 +00:00
|
|
|
--restore-archive=*)
|
|
|
|
BTCPAY_RESTORE_ARCHIVE_PATH="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2022-08-24 14:11:50 +00:00
|
|
|
--migrate-www)
|
|
|
|
MIGRATE_WWW=true
|
|
|
|
RUN_CERT_RENEWAL=false
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--migrate-btcpay)
|
|
|
|
MIGRATE_BTCPAY=true
|
2022-10-27 20:07:00 +00:00
|
|
|
BACKUP_BTCPAY=true
|
2022-07-27 16:38:33 +00:00
|
|
|
RUN_CERT_RENEWAL=false
|
2021-12-25 18:43:01 +00:00
|
|
|
shift
|
|
|
|
;;
|
2022-09-28 17:59:01 +00:00
|
|
|
--renew-certs)
|
|
|
|
RUN_CERT_RENEWAL=true
|
2021-12-25 18:43:01 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--reconfigure-btcpay)
|
|
|
|
RECONFIGURE_BTCPAY_SERVER=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
2022-08-15 13:42:15 +00:00
|
|
|
echo "Unexpected option: $1"
|
|
|
|
exit 1
|
2021-12-25 18:43:01 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2022-10-26 23:33:43 +00:00
|
|
|
|
2022-10-27 20:07:00 +00:00
|
|
|
# do some CLI checking.
|
|
|
|
if [ "$RESTORE_BTCPAY" = true ] && [ ! -f "$BTCPAY_RESTORE_ARCHIVE_PATH" ]; then
|
|
|
|
echo "ERROR: The restoration archive is not specified. Ensure --restore-archive= is set on the command line."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
# set up our default paths.
|
2022-06-22 17:42:51 +00:00
|
|
|
source ./defaults.sh
|
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
export CACHES_DIR="$HOME/ss-cache"
|
2022-05-28 03:07:17 +00:00
|
|
|
export DOMAIN_NAME="$DOMAIN_NAME"
|
2022-05-24 18:19:26 +00:00
|
|
|
export REGISTRY_DOCKER_IMAGE="registry:2"
|
2022-10-27 01:41:14 +00:00
|
|
|
export BTCPAY_RESTORE_ARCHIVE_PATH="$BTCPAY_RESTORE_ARCHIVE_PATH"
|
2022-08-24 14:11:50 +00:00
|
|
|
export RESTORE_WWW="$RESTORE_WWW"
|
2022-10-22 00:04:03 +00:00
|
|
|
export STOP_SERVICES="$STOP_SERVICES"
|
2022-09-28 17:59:01 +00:00
|
|
|
export BACKUP_CERTS="$BACKUP_CERTS"
|
2022-10-08 16:44:46 +00:00
|
|
|
export BACKUP_APPS="$BACKUP_APPS"
|
2022-08-24 14:11:50 +00:00
|
|
|
export RESTORE_BTCPAY="$RESTORE_BTCPAY"
|
2022-10-26 23:33:43 +00:00
|
|
|
export BACKUP_BTCPAY="$BACKUP_BTCPAY"
|
2022-08-24 14:11:50 +00:00
|
|
|
export MIGRATE_WWW="$MIGRATE_WWW"
|
|
|
|
export MIGRATE_BTCPAY="$MIGRATE_BTCPAY"
|
2022-09-09 18:00:07 +00:00
|
|
|
export RUN_CERT_RENEWAL="$RUN_CERT_RENEWAL"
|
2022-07-27 16:38:33 +00:00
|
|
|
export CLUSTER_NAME="$CLUSTER_NAME"
|
|
|
|
export CLUSTER_PATH="$CLUSTERS_DIR/$CLUSTER_NAME"
|
2022-05-20 15:05:38 +00:00
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
# ensure our cluster path is created.
|
2022-07-27 16:38:33 +00:00
|
|
|
mkdir -p "$CLUSTER_PATH"
|
2022-05-24 18:19:26 +00:00
|
|
|
|
2022-05-28 03:07:17 +00:00
|
|
|
# if an authorized_keys file does not exist, we'll stub one out with the current user.
|
|
|
|
# add additional id_rsa.pub entries manually for more administrative logins.
|
2022-07-27 16:38:33 +00:00
|
|
|
if [ ! -f "$CLUSTER_PATH/authorized_keys" ]; then
|
|
|
|
cat "$SSH_HOME/id_rsa.pub" >> "$CLUSTER_PATH/authorized_keys"
|
|
|
|
echo "INFO: Sovereign Stack just stubbed out '$CLUSTER_PATH/authorized_keys'. Go update it."
|
2022-09-09 18:00:07 +00:00
|
|
|
echo " Add ssh pubkeys for your various management machines, if any."
|
2022-10-19 17:15:38 +00:00
|
|
|
echo " By default we added your main ssh pubkey: '$SSH_HOME/id_rsa.pub'."
|
2022-05-28 03:07:17 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-12-25 18:43:01 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
CLUSTER_DEFINITION="$CLUSTER_PATH/cluster_definition"
|
|
|
|
export CLUSTER_DEFINITION="$CLUSTER_DEFINITION"
|
|
|
|
|
|
|
|
#########################################
|
|
|
|
if [ ! -f "$CLUSTER_DEFINITION" ]; then
|
|
|
|
echo "ERROR: The cluster defintion could not be found. You may need to re-run 'ss-cluster create'."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
source "$CLUSTER_DEFINITION"
|
2022-05-24 18:19:26 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
###########################3
|
|
|
|
# # This section is done to the management machine. We deploy a registry pull through cache on port 5000
|
|
|
|
# if ! docker volume list | grep -q registry_data; then
|
|
|
|
# docker volume create registry_data
|
|
|
|
# fi
|
2022-05-24 18:19:26 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# if the registry URL isn't defined, then we just use the upstream dockerhub.
|
|
|
|
# recommended to run a registry cache on your management machine though.
|
|
|
|
if [ -n "$REGISTRY_URL" ]; then
|
2022-05-24 18:19:26 +00:00
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
cat > "$CLUSTER_PATH/registry.yml" <<EOL
|
2022-05-24 18:19:26 +00:00
|
|
|
version: 0.1
|
|
|
|
http:
|
|
|
|
addr: 0.0.0.0:5000
|
|
|
|
host: ${REGISTRY_URL}
|
|
|
|
|
|
|
|
proxy:
|
|
|
|
remoteurl: ${REGISTRY_URL}
|
|
|
|
username: ${REGISTRY_USERNAME}
|
|
|
|
password: ${REGISTRY_PASSWORD}
|
|
|
|
EOL
|
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# enable docker swarm mode so we can support docker stacks.
|
|
|
|
if docker info | grep -q "Swarm: inactive"; then
|
|
|
|
docker swarm init
|
|
|
|
fi
|
2022-05-28 03:07:17 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
mkdir -p "${CACHES_DIR}/registry_images"
|
2021-12-25 18:43:01 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# run a docker registry pull through cache on the management machine.
|
|
|
|
if [ "$DEPLOY_MGMT_REGISTRY" = true ]; then
|
|
|
|
if ! docker stack list | grep -q registry; then
|
|
|
|
docker stack deploy -c management/registry_mirror.yml registry
|
2022-04-22 19:20:53 +00:00
|
|
|
fi
|
|
|
|
fi
|
2022-05-24 18:19:26 +00:00
|
|
|
fi
|
2022-04-22 19:20:53 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
# this is our password generation mechanism. Relying on GPG for secure password generation
|
2022-05-24 18:19:26 +00:00
|
|
|
function new_pass {
|
2022-07-27 16:38:33 +00:00
|
|
|
gpg --gen-random --armor 1 25
|
2022-05-28 03:07:17 +00:00
|
|
|
}
|
2022-05-24 18:19:26 +00:00
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
|
2022-08-24 14:11:50 +00:00
|
|
|
function instantiate_vms {
|
2021-12-25 18:43:01 +00:00
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
export BTC_CHAIN="$BTC_CHAIN"
|
|
|
|
export UPDATE_BTCPAY="$UPDATE_BTCPAY"
|
|
|
|
export RECONFIGURE_BTCPAY_SERVER="$RECONFIGURE_BTCPAY_SERVER"
|
|
|
|
|
|
|
|
# iterate over all our server endpoints and provision them if needed.
|
|
|
|
# www
|
|
|
|
VPS_HOSTNAME=
|
2022-08-03 14:53:11 +00:00
|
|
|
|
|
|
|
for VIRTUAL_MACHINE in www btcpayserver; do
|
2022-05-24 18:19:26 +00:00
|
|
|
FQDN=
|
2022-05-28 03:07:17 +00:00
|
|
|
|
2022-08-24 14:11:50 +00:00
|
|
|
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME"
|
2021-12-25 18:43:01 +00:00
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
source "$SITE_PATH/site_definition"
|
2022-09-09 18:00:07 +00:00
|
|
|
source ./domain_env.sh
|
2022-06-22 17:42:51 +00:00
|
|
|
|
2022-08-24 14:11:50 +00:00
|
|
|
# VALIDATE THE INPUT from the ENVFILE
|
|
|
|
if [ -z "$DOMAIN_NAME" ]; then
|
|
|
|
echo "ERROR: DOMAIN_NAME not specified. Use the --domain-name= option."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-10-19 17:15:38 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# first let's get the DISK_TO_USE and DATA_PLANE_MACVLAN_INTERFACE from the ss-config
|
|
|
|
# which is set up during LXD cluster creation ss-cluster.
|
|
|
|
LXD_SS_CONFIG_LINE=
|
|
|
|
if lxc network list --format csv | grep lxdbrSS | grep ss-config; then
|
|
|
|
LXD_SS_CONFIG_LINE="$(lxc network list --format csv | grep lxdbrSS | grep ss-config)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$LXD_SS_CONFIG_LINE" ]; then
|
|
|
|
echo "ERROR: the MACVLAN interface has not been specified. You may need to run ss-cluster again."
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-10-19 17:15:38 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
CONFIG_ITEMS="$(echo "$LXD_SS_CONFIG_LINE" | awk -F'"' '{print $2}')"
|
|
|
|
DATA_PLANE_MACVLAN_INTERFACE="$(echo "$CONFIG_ITEMS" | cut -d ',' -f2)"
|
|
|
|
DISK_TO_USE="$(echo "$CONFIG_ITEMS" | cut -d ',' -f3)"
|
2022-08-24 14:11:50 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
export DATA_PLANE_MACVLAN_INTERFACE="$DATA_PLANE_MACVLAN_INTERFACE"
|
|
|
|
export DISK_TO_USE="$DISK_TO_USE"
|
|
|
|
|
|
|
|
./deployment/create_lxc_base.sh
|
2022-08-24 14:11:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
export MAC_ADDRESS_TO_PROVISION=
|
|
|
|
export VPS_HOSTNAME="$VPS_HOSTNAME"
|
|
|
|
export FQDN="$VPS_HOSTNAME.$DOMAIN_NAME"
|
2022-09-09 18:00:07 +00:00
|
|
|
|
2022-08-24 14:11:50 +00:00
|
|
|
# ensure the admin has set the MAC address for the base image.
|
|
|
|
if [ -z "$SOVEREIGN_STACK_MAC_ADDRESS" ]; then
|
|
|
|
echo "ERROR: SOVEREIGN_STACK_MAC_ADDRESS is undefined. Check your project definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
DDNS_HOST=
|
2022-08-24 14:11:50 +00:00
|
|
|
MIGRATE_VPS=false
|
2022-07-27 16:38:33 +00:00
|
|
|
if [ "$VIRTUAL_MACHINE" = www ]; then
|
2022-10-26 23:33:43 +00:00
|
|
|
if [ "$SKIP_WWW" = true ]; then
|
2022-10-27 01:41:14 +00:00
|
|
|
echo "INFO: Skipping WWW due to command line argument."
|
2022-07-27 16:38:33 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
VPS_HOSTNAME="$WWW_HOSTNAME"
|
2022-09-09 18:00:07 +00:00
|
|
|
MAC_ADDRESS_TO_PROVISION="$WWW_SERVER_MAC_ADDRESS"
|
2022-06-22 17:42:51 +00:00
|
|
|
DDNS_HOST="$WWW_HOSTNAME"
|
|
|
|
ROOT_DISK_SIZE_GB="$((ROOT_DISK_SIZE_GB + NEXTCLOUD_SPACE_GB))"
|
2022-08-24 14:11:50 +00:00
|
|
|
if [ "$MIGRATE_WWW" = true ]; then
|
|
|
|
MIGRATE_VPS=true
|
|
|
|
fi
|
2022-10-26 23:33:43 +00:00
|
|
|
elif [ "$VIRTUAL_MACHINE" = btcpayserver ] || [ "$SKIP_BTCPAY" = true ]; then
|
2022-06-22 17:42:51 +00:00
|
|
|
DDNS_HOST="$BTCPAY_HOSTNAME"
|
|
|
|
VPS_HOSTNAME="$BTCPAY_HOSTNAME"
|
2022-09-09 18:00:07 +00:00
|
|
|
MAC_ADDRESS_TO_PROVISION="$BTCPAYSERVER_MAC_ADDRESS"
|
2022-06-22 17:42:51 +00:00
|
|
|
if [ "$BTC_CHAIN" = mainnet ]; then
|
|
|
|
ROOT_DISK_SIZE_GB=150
|
|
|
|
elif [ "$BTC_CHAIN" = testnet ]; then
|
|
|
|
ROOT_DISK_SIZE_GB=70
|
|
|
|
fi
|
2022-08-24 14:11:50 +00:00
|
|
|
|
|
|
|
if [ "$MIGRATE_BTCPAY" = true ]; then
|
|
|
|
MIGRATE_VPS=true
|
|
|
|
fi
|
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
elif [ "$VIRTUAL_MACHINE" = "sovereign-stack" ]; then
|
|
|
|
DDNS_HOST="sovereign-stack-base"
|
2022-06-22 17:42:51 +00:00
|
|
|
ROOT_DISK_SIZE_GB=8
|
|
|
|
else
|
2022-07-27 16:38:33 +00:00
|
|
|
echo "ERROR: VIRTUAL_MACHINE not within allowable bounds."
|
2022-06-22 17:42:51 +00:00
|
|
|
exit
|
2022-05-24 18:19:26 +00:00
|
|
|
fi
|
2021-12-25 18:43:01 +00:00
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
export DDNS_HOST="$DDNS_HOST"
|
|
|
|
export FQDN="$DDNS_HOST.$DOMAIN_NAME"
|
|
|
|
export LXD_VM_NAME="${FQDN//./-}"
|
2022-09-09 18:00:07 +00:00
|
|
|
export VIRTUAL_MACHINE="$VIRTUAL_MACHINE"
|
|
|
|
export REMOTE_CERT_DIR="$REMOTE_CERT_BASE_DIR/$FQDN"
|
|
|
|
export MAC_ADDRESS_TO_PROVISION="$MAC_ADDRESS_TO_PROVISION"
|
2022-10-27 20:07:00 +00:00
|
|
|
export BTCPAY_LOCAL_BACKUP_PATH="$SITE_PATH/backups/btcpayserver/$BACKUP_TIMESTAMP"
|
|
|
|
export BTCPAY_LOCAL_BACKUP_ARCHIVE_PATH="$BTCPAY_LOCAL_BACKUP_PATH/$UNIX_BACKUP_TIMESTAMP.tar.gz"
|
2022-05-28 03:07:17 +00:00
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
MACHINE_EXISTS=false
|
2022-10-31 02:24:25 +00:00
|
|
|
if lxc list --format csv | grep -q "$FQDN"; then
|
2022-05-24 18:19:26 +00:00
|
|
|
MACHINE_EXISTS=true
|
2021-12-25 18:43:01 +00:00
|
|
|
fi
|
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
if [ "$MACHINE_EXISTS" = true ]; then
|
|
|
|
# we delete the machine if the user has directed us to
|
2022-10-27 01:41:14 +00:00
|
|
|
# but before we do, we get a backup of applcation data of the running instance/vm
|
|
|
|
# that backup becomes the basis for restoring to the newer version of the host host (Type-1 VM)
|
2022-08-03 14:57:19 +00:00
|
|
|
if [ "$MIGRATE_VPS" = true ]; then
|
2022-07-29 22:33:24 +00:00
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
# get a backup of the machine. This is what we restore to the new VPS.
|
2022-09-09 18:00:07 +00:00
|
|
|
echo "INFO: Machine exists. Since we're going to delete it, let's grab a backup. "
|
|
|
|
echo " We don't need to restore services since we're deleting it."
|
2022-08-24 14:11:50 +00:00
|
|
|
./deployment/deploy_vms.sh
|
2022-05-24 18:19:26 +00:00
|
|
|
|
|
|
|
# delete the remote VPS.
|
2022-10-31 02:24:25 +00:00
|
|
|
lxc delete --force "$LXD_VM_NAME"
|
2022-05-24 18:19:26 +00:00
|
|
|
|
|
|
|
# Then we run the script again to re-instantiate a new VPS, restoring all user data
|
|
|
|
# if restore directory doesn't exist, then we end up with a new site.
|
|
|
|
echo "INFO: Recreating the remote VPS then restoring user data."
|
2022-08-24 14:11:50 +00:00
|
|
|
sleep 2
|
|
|
|
|
|
|
|
./deployment/deploy_vms.sh
|
2022-05-24 18:19:26 +00:00
|
|
|
else
|
2022-08-24 14:11:50 +00:00
|
|
|
./deployment/deploy_vms.sh
|
2022-05-24 18:19:26 +00:00
|
|
|
fi
|
|
|
|
else
|
2022-08-03 14:57:19 +00:00
|
|
|
if [ "$MIGRATE_VPS" = true ]; then
|
2022-10-27 20:07:00 +00:00
|
|
|
echo "INFO: User has indicated a migration, but it doesn't exist. Try removing some command line arguments."
|
|
|
|
exit 1
|
2022-05-24 18:19:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# The machine does not exist. Let's bring it into existence, restoring from latest backup.
|
2022-10-27 20:07:00 +00:00
|
|
|
echo "Machine does not exist. Creating."
|
2022-08-24 14:11:50 +00:00
|
|
|
./deployment/deploy_vms.sh
|
2022-05-24 18:19:26 +00:00
|
|
|
fi
|
2022-08-24 14:11:50 +00:00
|
|
|
|
2022-09-09 18:00:07 +00:00
|
|
|
# if the local docker client isn't logged in, do so;
|
|
|
|
# this helps prevent docker pull errors since they throttle.
|
|
|
|
if [ ! -f "$HOME/.docker/config.json" ]; then
|
|
|
|
echo "$REGISTRY_PASSWORD" | docker login --username "$REGISTRY_USERNAME" --password-stdin
|
|
|
|
fi
|
2022-08-24 14:11:50 +00:00
|
|
|
|
2022-09-09 18:00:07 +00:00
|
|
|
# this tells our local docker client to target the remote endpoint via SSH
|
|
|
|
export DOCKER_HOST="ssh://ubuntu@$PRIMARY_WWW_FQDN"
|
2022-08-24 14:11:50 +00:00
|
|
|
|
2022-09-09 18:00:07 +00:00
|
|
|
# enable docker swarm mode so we can support docker stacks.
|
|
|
|
if docker info | grep -q "Swarm: inactive"; then
|
|
|
|
docker swarm init --advertise-addr enp6s0
|
|
|
|
fi
|
2022-08-24 14:11:50 +00:00
|
|
|
|
2022-09-09 18:00:07 +00:00
|
|
|
done
|
2022-08-24 14:11:50 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-09 18:00:07 +00:00
|
|
|
|
2022-08-24 14:11:50 +00:00
|
|
|
function stub_site_definition {
|
|
|
|
mkdir -p "$SITE_PATH" "$PROJECT_PATH/sites"
|
|
|
|
|
|
|
|
# create a symlink from the CLUSTERPATH/sites/DOMAIN_NAME to the ss-sites/domain name
|
|
|
|
if [ ! -d "$PROJECT_PATH/sites/$DOMAIN_NAME" ]; then
|
|
|
|
ln -s "$SITE_PATH" "$PROJECT_PATH/sites/$DOMAIN_NAME"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -f "$SITE_PATH/site_definition" ]; then
|
2022-05-28 03:07:17 +00:00
|
|
|
# check to see if the enf file exists. exist if not.
|
|
|
|
SITE_DEFINITION_PATH="$SITE_PATH/site_definition"
|
|
|
|
if [ ! -f "$SITE_DEFINITION_PATH" ]; then
|
|
|
|
|
|
|
|
# stub out a site_definition with new passwords.
|
|
|
|
cat >"$SITE_DEFINITION_PATH" <<EOL
|
|
|
|
#!/bin/bash
|
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
export DOMAIN_NAME="${DOMAIN_NAME}"
|
2022-09-28 17:59:01 +00:00
|
|
|
export SITE_LANGUAGE_CODES="en"
|
2022-05-28 03:07:17 +00:00
|
|
|
export DUPLICITY_BACKUP_PASSPHRASE="$(new_pass)"
|
2022-09-09 18:00:07 +00:00
|
|
|
#export BTCPAY_HOSTNAME_IN_CERT="store"
|
2022-05-28 03:07:17 +00:00
|
|
|
export DEPLOY_GHOST=true
|
2022-10-22 00:04:03 +00:00
|
|
|
export DEPLOY_NEXTCLOUD=false
|
2022-10-19 17:15:38 +00:00
|
|
|
export DEPLOY_NOSTR_RELAY=true
|
2022-10-22 00:04:03 +00:00
|
|
|
export NOSTR_ACCOUNT_PUBKEY="NOSTR_IDENTITY_PUBKEY_GOES_HERE"
|
2022-05-28 03:07:17 +00:00
|
|
|
export DEPLOY_GITEA=false
|
2022-10-08 16:44:46 +00:00
|
|
|
#export DEPLOY_ONION_SITE=false
|
2022-05-28 03:07:17 +00:00
|
|
|
export GHOST_MYSQL_PASSWORD="$(new_pass)"
|
|
|
|
export GHOST_MYSQL_ROOT_PASSWORD="$(new_pass)"
|
|
|
|
export NEXTCLOUD_MYSQL_PASSWORD="$(new_pass)"
|
|
|
|
export NEXTCLOUD_MYSQL_ROOT_PASSWORD="$(new_pass)"
|
|
|
|
export GITEA_MYSQL_PASSWORD="$(new_pass)"
|
|
|
|
export GITEA_MYSQL_ROOT_PASSWORD="$(new_pass)"
|
|
|
|
|
2022-08-24 14:09:09 +00:00
|
|
|
EOL
|
|
|
|
|
|
|
|
chmod 0744 "$SITE_DEFINITION_PATH"
|
|
|
|
echo "INFO: we stubbed a new site_defintion for you at '$SITE_DEFINITION_PATH'. Go update it yo!"
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function stub_project_definition {
|
|
|
|
|
|
|
|
# check to see if the enf file exists. exist if not.
|
|
|
|
PROJECT_DEFINITION_PATH="$PROJECT_PATH/project_definition"
|
|
|
|
if [ ! -f "$PROJECT_DEFINITION_PATH" ]; then
|
|
|
|
|
|
|
|
# stub out a site_definition with new passwords.
|
|
|
|
cat >"$PROJECT_DEFINITION_PATH" <<EOL
|
|
|
|
#!/bin/bash
|
|
|
|
|
2022-09-09 18:00:07 +00:00
|
|
|
# see https://www.sovereign-stack.org/project-definition for more info.
|
2022-08-24 14:09:09 +00:00
|
|
|
|
|
|
|
export WWW_SERVER_MAC_ADDRESS="CHANGE_ME_REQUIRED"
|
2022-08-15 13:41:53 +00:00
|
|
|
export BTCPAYSERVER_MAC_ADDRESS="CHANGE_ME_REQUIRED"
|
2022-10-30 16:59:24 +00:00
|
|
|
export BTC_CHAIN="regtest|testnet|mainnet"
|
|
|
|
export PRIMARY_DOMAIN="domain0.tld"
|
|
|
|
export OTHER_SITES_LIST="domain1.tld,domain2.tld,domain3.tld"
|
|
|
|
|
2022-05-28 03:07:17 +00:00
|
|
|
EOL
|
|
|
|
|
2022-08-24 14:09:09 +00:00
|
|
|
chmod 0744 "$PROJECT_DEFINITION_PATH"
|
|
|
|
echo "INFO: we stubbed a new project_defition for you at '$PROJECT_DEFINITION_PATH'. Go update it yo!"
|
2022-09-09 18:00:07 +00:00
|
|
|
echo "INFO: Learn more at https://www.sovereign-stack.org/project-definitions/"
|
2022-10-19 17:15:38 +00:00
|
|
|
|
2022-08-24 14:09:09 +00:00
|
|
|
exit 1
|
2022-05-28 03:07:17 +00:00
|
|
|
fi
|
|
|
|
|
2022-08-24 14:09:09 +00:00
|
|
|
# source project defition.
|
|
|
|
source "$PROJECT_DEFINITION_PATH"
|
2022-05-28 03:07:17 +00:00
|
|
|
}
|
|
|
|
|
2022-08-24 14:09:09 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
CURRENT_PROJECT="$(lxc info | grep "project:" | awk '{print $2}')"
|
|
|
|
PROJECT_PATH="$PROJECTS_DIR/$PROJECT_NAME"
|
|
|
|
mkdir -p "$PROJECT_PATH" "$CLUSTER_PATH/projects"
|
|
|
|
export PROJECT_PATH="$PROJECT_PATH"
|
2022-08-24 14:09:09 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# create a symlink from ./clusterpath/projects/project
|
|
|
|
if [ ! -d "$CLUSTER_PATH/projects/$PROJECT_NAME" ]; then
|
|
|
|
ln -s "$PROJECT_PATH" "$CLUSTER_PATH/projects/$PROJECT_NAME"
|
|
|
|
fi
|
2022-08-24 14:09:09 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# check if we need to provision a new lxc project.
|
|
|
|
if [ "$PROJECT_NAME" != "$CURRENT_PROJECT" ]; then
|
|
|
|
if ! lxc project list | grep -q "$PROJECT_NAME"; then
|
|
|
|
echo "INFO: The lxd project specified in the cluster_definition did not exist. We'll create one!"
|
|
|
|
lxc project create "$PROJECT_NAME"
|
2022-08-24 14:09:09 +00:00
|
|
|
fi
|
2022-09-09 18:00:07 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
echo "INFO: switch to lxd project '$PROJECT_NAME'."
|
|
|
|
lxc project switch "$PROJECT_NAME"
|
2022-09-09 18:00:07 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
fi
|
2022-10-30 16:59:24 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# stub out the project definition if needed.
|
|
|
|
stub_project_definition
|
2022-08-24 14:09:09 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# the DOMAIN_LIST is a complete list of all our domains. We often iterate over this list.
|
|
|
|
export DOMAIN_LIST="${PRIMARY_DOMAIN},${OTHER_SITES_LIST}"
|
|
|
|
export DOMAIN_COUNT=$(("$(echo $DOMAIN_LIST | tr -cd , | wc -c)"+1))
|
2022-08-24 14:09:09 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# let's provision our primary domain first.
|
|
|
|
export DOMAIN_NAME="$PRIMARY_DOMAIN"
|
2022-05-28 03:07:17 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# we deploy the WWW and btcpay server under the PRIMARY_DOMAIN.
|
|
|
|
export DEPLOY_WWW_SERVER=true
|
|
|
|
export DEPLOY_BTCPAY_SERVER=true
|
2022-10-27 01:41:14 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME"
|
|
|
|
export PRIMARY_WWW_FQDN="$WWW_HOSTNAME.$DOMAIN_NAME"
|
|
|
|
|
|
|
|
stub_site_definition
|
2022-09-09 18:00:07 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# bring the vms up under the primary domain name.
|
|
|
|
instantiate_vms
|
|
|
|
|
|
|
|
# let's stub out the rest of our site definitions, if any.
|
|
|
|
for DOMAIN_NAME in ${OTHER_SITES_LIST//,/ }; do
|
|
|
|
export DOMAIN_NAME="$DOMAIN_NAME"
|
|
|
|
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME"
|
|
|
|
|
|
|
|
# stub out the site_defition if it's doesn't exist.
|
2022-05-28 03:07:17 +00:00
|
|
|
stub_site_definition
|
2022-10-31 02:24:25 +00:00
|
|
|
done
|
2022-05-24 18:19:26 +00:00
|
|
|
|
2022-10-31 02:24:25 +00:00
|
|
|
# now let's run the www and btcpay-specific provisioning scripts.
|
|
|
|
if [ "$SKIP_WWW" = false ]; then
|
|
|
|
bash -c "./deployment/www/go.sh"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$SKIP_BTCPAY" = false ]; then
|
|
|
|
bash -c "./deployment/btcpayserver/go.sh"
|
|
|
|
fi
|