#!/bin/bash set -eu cd "$(dirname "$0")" check_dependencies () { for cmd in "$@"; do if ! command -v "$cmd" >/dev/null 2>&1; then echo "This script requires \"${cmd}\" to be installed. Please run 'install.sh'." exit 1 fi done } # Check system's dependencies check_dependencies wait-for-it dig rsync sshfs lxc docker-machine # TODO remove dependency on Docker-machine. That's what we use to provision VM on 3rd party vendors. Looking for LXD endpoint. # let's check to ensure the management machine is on the Baseline ubuntu 21.04 if ! lsb_release -d | grep -q "Ubuntu 22.04"; then echo "ERROR: Your machine is not running the Ubuntu 22.04 LTS baseline OS on your management machine." exit 1 fi DOMAIN_NAME= VPS_HOSTING_TARGET=lxd RUN_CERT_RENEWAL=false SKIP_WWW=false RESTORE_WWW=false BACKUP_CERTS=true BACKUP_APPS=true BACKUP_BTCPAY=true RESTORE_BTCPAY=false BTCPAY_RESTORE_ARCHIVE_PATH= BTCPAY_LOCAL_BACKUP_PATH= MIGRATE_WWW=false MIGRATE_BTCPAY=false SKIP_BTCPAY=false UPDATE_BTCPAY=false RECONFIGURE_BTCPAY_SERVER=false CLUSTER_NAME="$(lxc remote get-default)" STOP_SERVICES=false # grab any modifications from the command line. for i in "$@"; do case $i in --aws) VPS_HOSTING_TARGET=aws shift ;; --restore-www) RESTORE_WWW=true BACKUP_APPS=false RUN_CERT_RENEWAL=false shift ;; --restore-btcpay) RESTORE_BTCPAY=true BACKUP_BTCPAY=false RUN_CERT_RENEWAL=false shift ;; --backup-certs) BACKUP_CERTS=true shift ;; --stop) STOP_SERVICES=true shift ;; --domain=*) DOMAIN_NAME="${i#*=}" shift ;; --update-btcpay) UPDATE_BTCPAY=true shift ;; --skip-www) SKIP_WWW=true shift ;; --skip-btcpay) SKIP_BTCPAY=true shift ;; --backup-ghost) BACKUP_APPS=true shift ;; --backup-btcpay) BACKUP_BTCPAY=true shift ;; --restore-archive=*) BTCPAY_RESTORE_ARCHIVE_PATH="${i#*=}" shift ;; --migrate-www) MIGRATE_WWW=true RUN_CERT_RENEWAL=false shift ;; --migrate-btcpay) MIGRATE_BTCPAY=true BACKUP_BTCPAY=true RUN_CERT_RENEWAL=false shift ;; --renew-certs) RUN_CERT_RENEWAL=true shift ;; --reconfigure-btcpay) RECONFIGURE_BTCPAY_SERVER=true shift ;; *) echo "Unexpected option: $1" exit 1 ;; esac done # 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 # set up our default paths. source ./defaults.sh export CACHES_DIR="$HOME/ss-cache" export DOMAIN_NAME="$DOMAIN_NAME" export REGISTRY_DOCKER_IMAGE="registry:2" export BTCPAY_RESTORE_ARCHIVE_PATH="$BTCPAY_RESTORE_ARCHIVE_PATH" export RESTORE_WWW="$RESTORE_WWW" export STOP_SERVICES="$STOP_SERVICES" export BACKUP_CERTS="$BACKUP_CERTS" export BACKUP_APPS="$BACKUP_APPS" export RESTORE_BTCPAY="$RESTORE_BTCPAY" export BACKUP_BTCPAY="$BACKUP_BTCPAY" export MIGRATE_WWW="$MIGRATE_WWW" export MIGRATE_BTCPAY="$MIGRATE_BTCPAY" export RUN_CERT_RENEWAL="$RUN_CERT_RENEWAL" if [ "$VPS_HOSTING_TARGET" = aws ]; then if [ -z "$DOMAIN_NAME" ]; then echo "ERROR: Please specify a domain name with --domain= when using --aws." exit 1 fi CLUSTER_NAME="docker-machine" fi export CLUSTER_NAME="$CLUSTER_NAME" export CLUSTER_PATH="$CLUSTERS_DIR/$CLUSTER_NAME" # ensure our cluster path is created. mkdir -p "$CLUSTER_PATH" # 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. 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." echo " Add ssh pubkeys for your various management machines, if any." echo " By default we added your main ssh pubkey: '$SSH_HOME/id_rsa.pub'." exit 1 fi if [ "$VPS_HOSTING_TARGET" = lxd ]; then 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" ###########################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. if [ -n "$REGISTRY_URL" ]; then cat > "$CLUSTER_PATH/registry.yml" <"$SITE_DEFINITION_PATH" <"$PROJECT_DEFINITION_PATH" <