#!/bin/bash set -eux 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= RESTORE_ARCHIVE= VPS_HOSTING_TARGET=lxd RUN_CERT_RENEWAL=true RESTORE_WWW=false BACKUP_WWW=true RESTORE_BTCPAY=false BACKUP_BTCPAY=true MIGRATE_WWW=false MIGRATE_BTCPAY=false USER_SKIP_WWW=false USER_SKIP_BTCPAY=false UPDATE_BTCPAY=false RECONFIGURE_BTCPAY_SERVER=false DEPLOY_BTCPAY_SERVER=false CLUSTER_NAME="$(lxc remote get-default)" # 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_WWW=false RUN_CERT_RENEWAL=false shift ;; --restore-btcpay) RESTORE_BTCPAY=true BACKUP_BTCPAY=false shift ;; --archive=*) RESTORE_ARCHIVE="${i#*=}" shift ;; --domain=*) DOMAIN_NAME="${i#*=}" shift ;; --update-btcpay) UPDATE_BTCPAY=true shift ;; --skip-www) USER_SKIP_WWW=true shift ;; --skip-btcpay) USER_SKIP_BTCPAY=true shift ;; --no-backup-www) BACKUP_WWW=false shift ;; --no-backup-btcpay) BACKUP_BTCPAY=false shift ;; --migrate-www) MIGRATE_WWW=true RUN_CERT_RENEWAL=false shift ;; --migrate-btcpay) MIGRATE_BTCPAY=true RUN_CERT_RENEWAL=false shift ;; --no-cert-renew) RUN_CERT_RENEWAL=false shift ;; --reconfigure-btcpay) RECONFIGURE_BTCPAY_SERVER=true shift ;; *) echo "Unexpected option: $1" exit 1 ;; esac done # set up our default paths. source ./defaults.sh export CACHES_DIR="$HOME/ss-cache" export SSH_HOME="$HOME/.ssh" export DOMAIN_NAME="$DOMAIN_NAME" export REGISTRY_DOCKER_IMAGE="registry:2" export RESTORE_ARCHIVE="$RESTORE_ARCHIVE" export RESTORE_WWW="$RESTORE_WWW" export BACKUP_WWW="$BACKUP_WWW" export RESTORE_BTCPAY="$RESTORE_BTCPAY" export BACKUP_BTCPAY="$RESTORE_BTCPAY" export MIGRATE_WWW="$MIGRATE_WWW" export MIGRATE_BTCPAY="$MIGRATE_BTCPAY" 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. 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 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" <