2021-12-25 18:43:01 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
set -eux
|
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-07-27 16:38:33 +00:00
|
|
|
check_dependencies wait-for-it dig rsync sshfs lxc docker-machine
|
|
|
|
|
2022-04-22 20:10:24 +00:00
|
|
|
# TODO remove dependency on Docker-machine. That's what we use to provision VM on 3rd party vendors. Looking for LXD endpoint.
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
# let's check to ensure the management machine is on the Baseline ubuntu 21.04
|
|
|
|
if ! lsb_release -d | grep -q "Ubuntu 22.04 LTS"; then
|
|
|
|
echo "ERROR: Your machine is not running the Ubuntu 22.04 LTS baseline OS on your management machine."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-04-22 19:51:02 +00:00
|
|
|
MIGRATE_VPS=false
|
2021-12-25 18:43:01 +00:00
|
|
|
DOMAIN_NAME=
|
2022-07-27 16:38:33 +00:00
|
|
|
RESTORE_ARCHIVE=
|
2022-05-24 18:19:26 +00:00
|
|
|
VPS_HOSTING_TARGET=lxd
|
2021-12-25 18:43:01 +00:00
|
|
|
RUN_CERT_RENEWAL=true
|
|
|
|
USER_NO_BACKUP=false
|
|
|
|
USER_RUN_RESTORE=false
|
2022-07-27 16:38:33 +00:00
|
|
|
RESTORE_BTCPAY=false
|
|
|
|
USER_SKIP_WWW=false
|
|
|
|
USER_SKIP_BTCPAY=false
|
2021-12-25 18:43:01 +00:00
|
|
|
UPDATE_BTCPAY=false
|
|
|
|
RECONFIGURE_BTCPAY_SERVER=false
|
2022-04-22 19:51:02 +00:00
|
|
|
DEPLOY_BTCPAY_SERVER=false
|
2022-07-27 16:38:33 +00:00
|
|
|
CLUSTER_NAME="$(lxc remote get-default)"
|
2022-07-29 22:33:24 +00:00
|
|
|
RUN_BACKUP=true
|
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-05-24 18:11:58 +00:00
|
|
|
--aws)
|
|
|
|
VPS_HOSTING_TARGET=aws
|
2021-12-25 18:43:01 +00:00
|
|
|
shift
|
|
|
|
;;
|
2022-07-27 16:38:33 +00:00
|
|
|
--restore-www)
|
2021-12-25 18:43:01 +00:00
|
|
|
USER_RUN_RESTORE=true
|
2022-05-24 18:19:26 +00:00
|
|
|
RUN_CERT_RENEWAL=false
|
|
|
|
USER_NO_BACKUP=true
|
2021-12-25 18:43:01 +00:00
|
|
|
shift
|
|
|
|
;;
|
2022-07-27 16:38:33 +00:00
|
|
|
--restore-btcpay)
|
|
|
|
RESTORE_BTCPAY=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--archive=*)
|
|
|
|
RESTORE_ARCHIVE="${i#*=}"
|
|
|
|
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)
|
|
|
|
USER_SKIP_WWW=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--skip-btcpay)
|
|
|
|
USER_SKIP_BTCPAY=true
|
|
|
|
shift
|
|
|
|
;;
|
2021-12-25 18:43:01 +00:00
|
|
|
--no-backup)
|
|
|
|
USER_NO_BACKUP=true
|
|
|
|
shift
|
|
|
|
;;
|
2022-07-27 16:38:33 +00:00
|
|
|
--migrate-btcpay)
|
2022-04-22 19:51:02 +00:00
|
|
|
MIGRATE_VPS=true
|
2022-07-27 16:38:33 +00:00
|
|
|
RUN_CERT_RENEWAL=false
|
2021-12-25 18:43:01 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--no-cert-renew)
|
|
|
|
RUN_CERT_RENEWAL=false
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--reconfigure-btcpay)
|
|
|
|
RECONFIGURE_BTCPAY_SERVER=true
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# unknown option
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
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"
|
|
|
|
export SSH_HOME="$HOME/.ssh"
|
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-07-27 16:38:33 +00:00
|
|
|
export RESTORE_ARCHIVE="$RESTORE_ARCHIVE"
|
2022-05-28 03:07:17 +00:00
|
|
|
|
2022-07-29 22:33:24 +00:00
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
if [ "$VPS_HOSTING_TARGET" = aws ]; then
|
2022-07-27 16:38:33 +00:00
|
|
|
|
|
|
|
if [ -z "$DOMAIN_NAME" ]; then
|
|
|
|
echo "ERROR: Please specify a domain name with --domain= when using --aws."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
CLUSTER_NAME="docker-machine"
|
2022-05-28 03:07:17 +00:00
|
|
|
fi
|
|
|
|
|
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-05-28 03:07:17 +00:00
|
|
|
echo " Add ssh pubkeys for your various management machines, if any. We've stubbed it out"
|
|
|
|
echo " with your ssh pubkey at '$HOME/.ssh/id_rsa.pub'."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$VPS_HOSTING_TARGET" = lxd ]; then
|
2022-07-27 16:38:33 +00:00
|
|
|
CLUSTER_DEFINITION="$CLUSTER_PATH/cluster_definition"
|
2022-06-22 17:42:51 +00:00
|
|
|
export CLUSTER_DEFINITION="$CLUSTER_DEFINITION"
|
2021-12-25 18:43:01 +00:00
|
|
|
|
2022-05-28 03:07:17 +00:00
|
|
|
#########################################
|
2022-06-22 17:42:51 +00:00
|
|
|
if [ ! -f "$CLUSTER_DEFINITION" ]; then
|
|
|
|
echo "ERROR: The cluster defintion could not be found. You may need to re-run 'ss-cluster create'."
|
2022-05-28 03:07:17 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
source "$CLUSTER_DEFINITION"
|
2022-05-24 18:19:26 +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
|
|
|
|
|
|
|
|
# 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.
|
2022-05-28 03:07:17 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
# enable docker swarm mode so we can support docker stacks.
|
|
|
|
if ! docker info | grep -q "Swarm: active"; then
|
|
|
|
docker swarm init
|
2021-12-25 18:43:01 +00:00
|
|
|
fi
|
2022-05-28 03:07:17 +00:00
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
mkdir -p "${CACHES_DIR}/registry_images"
|
2021-12-25 18:43:01 +00:00
|
|
|
|
2022-07-27 16:38:33 +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
|
|
|
|
fi
|
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-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
|
|
|
if [ "$VPS_HOSTING_TARGET" = lxd ]; then
|
|
|
|
# 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="$(lxc network list --format csv | grep ss-config)"
|
|
|
|
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)"
|
|
|
|
|
|
|
|
export DATA_PLANE_MACVLAN_INTERFACE="$DATA_PLANE_MACVLAN_INTERFACE"
|
|
|
|
export DISK_TO_USE="$DISK_TO_USE"
|
|
|
|
|
|
|
|
./deployment/create_lxc_base.sh
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2022-05-28 03:07:17 +00:00
|
|
|
function run_domain {
|
2021-12-25 18:43:01 +00:00
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
export VPS_HOSTING_TARGET="$VPS_HOSTING_TARGET"
|
|
|
|
export RUN_CERT_RENEWAL="$RUN_CERT_RENEWAL"
|
|
|
|
export BTC_CHAIN="$BTC_CHAIN"
|
|
|
|
export UPDATE_BTCPAY="$UPDATE_BTCPAY"
|
|
|
|
export MIGRATE_VPS="$MIGRATE_VPS"
|
|
|
|
export RECONFIGURE_BTCPAY_SERVER="$RECONFIGURE_BTCPAY_SERVER"
|
|
|
|
|
|
|
|
# iterate over all our server endpoints and provision them if needed.
|
|
|
|
# www
|
|
|
|
VPS_HOSTNAME=
|
2022-07-27 16:38:33 +00:00
|
|
|
# OPTINOAL umbrel
|
|
|
|
for VIRTUAL_MACHINE in www btcpayserver umbrel; do
|
2022-05-24 18:19:26 +00:00
|
|
|
FQDN=
|
2022-05-28 03:07:17 +00:00
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
# shellcheck disable=SC1091
|
|
|
|
source ./shared.sh
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
if [ ! -f "$SITE_PATH/site_definition" ]; then
|
|
|
|
echo "ERROR: Something went wrong. Your site_definition is missing."
|
|
|
|
exit 1
|
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
|
|
|
source "$SITE_PATH/site_definition"
|
|
|
|
|
|
|
|
# create the local packup path if it's not there!
|
|
|
|
BACKUP_PATH_CREATED=false
|
|
|
|
|
|
|
|
export BACKUP_PATH_CREATED="$BACKUP_PATH_CREATED"
|
|
|
|
export MAC_ADDRESS_TO_PROVISION=
|
|
|
|
export VPS_HOSTNAME="$VPS_HOSTNAME"
|
|
|
|
export FQDN="$VPS_HOSTNAME.$DOMAIN_NAME"
|
2022-07-27 16:38:33 +00:00
|
|
|
export VIRTUAL_MACHINE="$VIRTUAL_MACHINE"
|
2022-06-22 17:42:51 +00:00
|
|
|
BACKUP_TIMESTAMP="$(date +"%Y-%m")"
|
|
|
|
UNIX_BACKUP_TIMESTAMP="$(date +%s)"
|
2022-07-27 16:38:33 +00:00
|
|
|
export REMOTE_BACKUP_PATH="$REMOTE_HOME/backups/$VIRTUAL_MACHINE/$BACKUP_TIMESTAMP"
|
|
|
|
LOCAL_BACKUP_PATH="$SITE_PATH/backups/$VIRTUAL_MACHINE/$BACKUP_TIMESTAMP"
|
2022-06-22 17:42:51 +00:00
|
|
|
export LOCAL_BACKUP_PATH="$LOCAL_BACKUP_PATH"
|
|
|
|
|
|
|
|
export BACKUP_TIMESTAMP="$BACKUP_TIMESTAMP"
|
|
|
|
export UNIX_BACKUP_TIMESTAMP="$UNIX_BACKUP_TIMESTAMP"
|
|
|
|
|
|
|
|
export REMOTE_CERT_DIR="$REMOTE_CERT_BASE_DIR/$FQDN"
|
|
|
|
|
|
|
|
if [ ! -d "$LOCAL_BACKUP_PATH" ]; then
|
|
|
|
mkdir -p "$LOCAL_BACKUP_PATH"
|
|
|
|
BACKUP_PATH_CREATED=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
DDNS_HOST=
|
2022-07-27 16:38:33 +00:00
|
|
|
if [ "$VIRTUAL_MACHINE" = www ]; then
|
|
|
|
if [ "$DEPLOY_WWW_SERVER" = false ] || [ "$USER_SKIP_WWW" = true ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
VPS_HOSTNAME="$WWW_HOSTNAME"
|
|
|
|
MAC_ADDRESS_TO_PROVISION="$WWW_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-07-27 16:38:33 +00:00
|
|
|
elif [ "$VIRTUAL_MACHINE" = btcpayserver ] || [ "$USER_SKIP_BTCPAY" = true ]; then
|
|
|
|
if [ "$DEPLOY_BTCPAY_SERVER" = false ]; then
|
2022-05-24 18:19:26 +00:00
|
|
|
continue
|
2021-12-25 18:43:01 +00:00
|
|
|
fi
|
2022-07-27 16:38:33 +00:00
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
DDNS_HOST="$BTCPAY_HOSTNAME"
|
|
|
|
VPS_HOSTNAME="$BTCPAY_HOSTNAME"
|
|
|
|
MAC_ADDRESS_TO_PROVISION="$BTCPAY_MAC_ADDRESS"
|
|
|
|
if [ "$BTC_CHAIN" = mainnet ]; then
|
|
|
|
ROOT_DISK_SIZE_GB=150
|
|
|
|
elif [ "$BTC_CHAIN" = testnet ]; then
|
|
|
|
ROOT_DISK_SIZE_GB=70
|
|
|
|
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
|
2022-07-27 16:38:33 +00:00
|
|
|
MAC_ADDRESS_TO_PROVISION="$SOVEREIGN_STACK_MAC_ADDRESS"
|
2022-06-22 17:42:51 +00:00
|
|
|
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//./-}"
|
|
|
|
export REMOTE_BACKUP_PATH="$REMOTE_BACKUP_PATH"
|
|
|
|
|
|
|
|
# This next section of if statements is our sanity checking area.
|
|
|
|
if [ "$VPS_HOSTING_TARGET" = aws ]; then
|
|
|
|
# we require DDNS on AWS to set the public DNS to the right host.
|
|
|
|
if [ -z "$DDNS_PASSWORD" ]; then
|
|
|
|
echo "ERROR: Ensure DDNS_PASSWORD is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-05-28 03:07:17 +00:00
|
|
|
fi
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
if [ "$DEPLOY_GHOST" = true ]; then
|
|
|
|
if [ -z "$GHOST_MYSQL_PASSWORD" ]; then
|
|
|
|
echo "ERROR: Ensure GHOST_MYSQL_PASSWORD is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$GHOST_MYSQL_ROOT_PASSWORD" ]; then
|
|
|
|
echo "ERROR: Ensure GHOST_MYSQL_ROOT_PASSWORD is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DEPLOY_GITEA" = true ]; then
|
|
|
|
if [ -z "$GITEA_MYSQL_PASSWORD" ]; then
|
|
|
|
echo "ERROR: Ensure GITEA_MYSQL_PASSWORD is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ -z "$GITEA_MYSQL_ROOT_PASSWORD" ]; then
|
|
|
|
echo "ERROR: Ensure GITEA_MYSQL_ROOT_PASSWORD is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DEPLOY_NEXTCLOUD" = true ]; then
|
|
|
|
if [ -z "$NEXTCLOUD_MYSQL_ROOT_PASSWORD" ]; then
|
|
|
|
echo "ERROR: Ensure NEXTCLOUD_MYSQL_ROOT_PASSWORD is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$NEXTCLOUD_MYSQL_PASSWORD" ]; then
|
|
|
|
echo "ERROR: Ensure NEXTCLOUD_MYSQL_PASSWORD is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DEPLOY_NOSTR" = true ]; then
|
|
|
|
if [ -z "$NOSTR_ACCOUNT_PUBKEY" ]; then
|
|
|
|
echo "ERROR: Ensure NOSTR_ACCOUNT_PUBKEY is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$NOSTR_ACCOUNT_PUBKEY" ]; then
|
|
|
|
echo "ERROR: Ensure NOSTR_ACCOUNT_PUBKEY is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$DUPLICITY_BACKUP_PASSPHRASE" ]; then
|
|
|
|
echo "ERROR: Ensure DUPLICITY_BACKUP_PASSPHRASE is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$DOMAIN_NAME" ]; then
|
|
|
|
echo "ERROR: Ensure DOMAIN_NAME is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$DEPLOY_BTCPPAY_SERVER" ]; then
|
|
|
|
echo "ERROR: Ensure DEPLOY_BTCPPAY_SERVER is configured in your site_definition."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$NOSTR_ACCOUNT_PUBKEY" ]; then
|
|
|
|
echo "ERROR: You MUST specify a Nostr public key. This is how you get all your social features."
|
|
|
|
echo "INFO: Go to your site_definition file and set the NOSTR_ACCOUNT_PUBKEY variable."
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-07-27 16:38:33 +00:00
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
bash -c ./deployment/stub_nginxconf.sh
|
|
|
|
|
|
|
|
MACHINE_EXISTS=false
|
|
|
|
if [ "$VPS_HOSTING_TARGET" = aws ] && docker-machine ls -q | grep -q "$FQDN"; then
|
|
|
|
MACHINE_EXISTS=true
|
2021-12-25 18:43:01 +00:00
|
|
|
fi
|
2022-05-24 18:19:26 +00:00
|
|
|
|
|
|
|
if [ "$VPS_HOSTING_TARGET" = lxd ] && lxc list --format csv | grep -q "$FQDN"; then
|
|
|
|
MACHINE_EXISTS=true
|
2021-12-25 18:43:01 +00:00
|
|
|
fi
|
|
|
|
|
2022-05-24 18:19:26 +00:00
|
|
|
if [ "$USER_NO_BACKUP" = true ]; then
|
|
|
|
RUN_BACKUP=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$MACHINE_EXISTS" = true ]; then
|
|
|
|
# we delete the machine if the user has directed us to
|
|
|
|
if [ "$MIGRATE_VPS" = true ]; then
|
2022-07-29 22:33:24 +00:00
|
|
|
|
|
|
|
# if the RESTORE_ARCHIVE is not set, then
|
|
|
|
if [ -z "$RESTORE_ARCHIVE" ]; then
|
|
|
|
RESTORE_ARCHIVE="$LOCAL_BACKUP_PATH/$UNIX_BACKUP_TIMESTAMP.tar.gz"
|
|
|
|
fi
|
|
|
|
|
2022-07-27 16:38:33 +00:00
|
|
|
# get a backup of the machine. This is what we restore to the new VPS.
|
|
|
|
echo "INFO: Machine exists. Since we're going to delete it, let's grab a backup. We don't need to restore services since we're deleting it."
|
|
|
|
RESTORE_BTCPAY=false UPDATE_BTCPAY=false RUN_RESTORE=false RUN_BACKUP=true RUN_SERVICES=false ./deployment/domain_init.sh
|
2022-05-24 18:19:26 +00:00
|
|
|
|
|
|
|
# delete the remote VPS.
|
|
|
|
if [ "$VPS_HOSTING_TARGET" = aws ]; then
|
2022-07-27 16:38:33 +00:00
|
|
|
RESPONSE=
|
|
|
|
read -r -p "Do you want to continue with deleting '$FQDN' (y/n)": RESPONSE
|
|
|
|
if [ "$RESPONSE" = y ]; then
|
|
|
|
docker-machine rm -f "$FQDN"
|
|
|
|
else
|
|
|
|
echo "STOPPING the migration. User entered something other than 'y'."
|
|
|
|
exit 1
|
2022-05-24 18:19:26 +00:00
|
|
|
fi
|
|
|
|
elif [ "$VPS_HOSTING_TARGET" = lxd ]; then
|
|
|
|
lxc delete --force "$LXD_VM_NAME"
|
|
|
|
USER_RUN_RESTORE=true
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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-07-29 22:33:24 +00:00
|
|
|
sleep 5
|
|
|
|
RESTORE_BTCPAY=true UPDATE_BTCPAY=false RUN_RESTORE=true RUN_BACKUP=false RUN_SERVICES=true RUN_CERT_RENEWAL=false RESTORE_ARCHIVE="$RESTORE_ARCHIVE" ./deployment/domain_init.sh
|
|
|
|
sleep 5
|
2022-05-24 18:19:26 +00:00
|
|
|
else
|
2022-07-29 22:33:24 +00:00
|
|
|
RESTORE_BTCPAY="$RESTORE_BTCPAY" UPDATE_BTCPAY="$UPDATE_BTCPAY" RUN_RESTORE="$USER_RUN_RESTORE" RUN_BACKUP="$RUN_BACKUP" RUN_SERVICES=true ./deployment/domain_init.sh
|
2022-05-24 18:19:26 +00:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ "$MIGRATE_VPS" = true ]; then
|
|
|
|
echo "INFO: User has indicated to delete the machine, but it doesn't exist. Going to create it anyway."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# The machine does not exist. Let's bring it into existence, restoring from latest backup.
|
|
|
|
echo "Machine does not exist. RUN_RESTORE=$USER_RUN_RESTORE RUN_BACKUP=false"
|
2022-07-27 16:38:33 +00:00
|
|
|
RESTORE_BTCPAY=false UPDATE_BTCPAY="$UPDATE_BTCPAY" RUN_RESTORE="$USER_RUN_RESTORE" RUN_BACKUP=false RUN_SERVICES=true ./deployment/domain_init.sh
|
2022-05-24 18:19:26 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-05-28 03:07:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function stub_site_definition {
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
export SITE_PATH="$SITES_PATH/$DOMAIN_NAME"
|
|
|
|
mkdir -p "$SITE_PATH"
|
2022-05-28 03:07:17 +00:00
|
|
|
|
|
|
|
if [ -f "$SITE_PATH/site_definition" ]; then
|
2022-06-22 17:42:51 +00:00
|
|
|
source ./shared.sh
|
2022-05-28 03:07:17 +00:00
|
|
|
else
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Set the domain name for the identity site.
|
2022-07-27 16:38:33 +00:00
|
|
|
export DOMAIN_NAME="${DOMAIN_NAME}"
|
2022-05-28 03:07:17 +00:00
|
|
|
|
|
|
|
# duplicitiy backup archive password
|
|
|
|
export DUPLICITY_BACKUP_PASSPHRASE="$(new_pass)"
|
|
|
|
|
|
|
|
# AWS only
|
|
|
|
#export DDNS_PASSWORD=
|
|
|
|
|
|
|
|
## WWW
|
|
|
|
export DEPLOY_WWW_SERVER=true
|
|
|
|
|
|
|
|
# Deploy APPS to www
|
|
|
|
export DEPLOY_GHOST=true
|
|
|
|
export DEPLOY_NEXTCLOUD=true
|
|
|
|
export DEPLOY_NOSTR=false
|
|
|
|
|
|
|
|
# set if NOSTR_ACCOUNT_PUBKEY=true
|
|
|
|
export NOSTR_ACCOUNT_PUBKEY="CHANGE_ME"
|
|
|
|
|
|
|
|
export DEPLOY_GITEA=false
|
|
|
|
export DEPLOY_ONION_SITE=false
|
|
|
|
|
|
|
|
# passwords for WWW apps
|
|
|
|
## GHOST
|
|
|
|
export GHOST_MYSQL_PASSWORD="$(new_pass)"
|
|
|
|
export GHOST_MYSQL_ROOT_PASSWORD="$(new_pass)"
|
|
|
|
|
|
|
|
## NEXTCLOUD
|
|
|
|
export NEXTCLOUD_MYSQL_PASSWORD="$(new_pass)"
|
|
|
|
export NEXTCLOUD_MYSQL_ROOT_PASSWORD="$(new_pass)"
|
|
|
|
|
|
|
|
## GITEA
|
|
|
|
export GITEA_MYSQL_PASSWORD="$(new_pass)"
|
|
|
|
export GITEA_MYSQL_ROOT_PASSWORD="$(new_pass)"
|
|
|
|
|
|
|
|
## BTCPAY SERVER; if true, then a BTCPay server is deployed.
|
|
|
|
export DEPLOY_BTCPAY_SERVER=false
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
# CHAIN to DEPLOY; valid are 'regtest', 'testnet', and 'mainnet'
|
2022-05-28 03:07:17 +00:00
|
|
|
export BTC_CHAIN=regtest
|
|
|
|
|
2022-05-30 02:43:42 +00:00
|
|
|
# set to false to disable nginx caching; helps when making website updates.
|
|
|
|
# export ENABLE_NGINX_CACHING=true
|
|
|
|
|
2022-05-28 03:07:17 +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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-06-22 17:42:51 +00:00
|
|
|
# let's iterate over the user-supplied domain list and provision each domain.
|
2022-05-28 03:07:17 +00:00
|
|
|
if [ "$VPS_HOSTING_TARGET" = lxd ]; then
|
|
|
|
# iterate through our site list as provided by operator from cluster_definition
|
|
|
|
for i in ${SITE_LIST//,/ }; do
|
|
|
|
export DOMAIN_NAME="$i"
|
2022-06-22 17:42:51 +00:00
|
|
|
export SITE_PATH=""
|
2022-05-28 03:07:17 +00:00
|
|
|
|
|
|
|
stub_site_definition
|
|
|
|
|
|
|
|
# run the logic for a domain deployment.
|
|
|
|
run_domain
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
elif [ "$VPS_HOSTING_TARGET" = aws ]; then
|
|
|
|
stub_site_definition
|
2022-05-24 18:19:26 +00:00
|
|
|
|
2022-05-28 03:07:17 +00:00
|
|
|
# if we're on AWS, we can just provision each system separately.
|
|
|
|
run_domain
|
|
|
|
fi
|