#!/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 duplicity # TODO remove dependency on Docker-machine. That's what we use to provision VM on 3rd party vendors. Looking for LXD endpoint. MIGRATE_VPS=false DOMAIN_NAME= VPS_HOSTING_TARGET=lxd RUN_CERT_RENEWAL=true USER_NO_BACKUP=false USER_RUN_RESTORE=false BTC_CHAIN=regtest UPDATE_BTCPAY=false RECONFIGURE_BTCPAY_SERVER=false DEPLOY_BTCPAY_SERVER=false MACVLAN_INTERFACE= LXD_DISK_TO_USE= # grab any modifications from the command line. for i in "$@"; do case $i in --aws) VPS_HOSTING_TARGET=aws shift ;; --restore) USER_RUN_RESTORE=true RUN_CERT_RENEWAL=false USER_NO_BACKUP=true shift ;; --domain=*) DOMAIN_NAME="${i#*=}" shift ;; --update-btcpay) UPDATE_BTCPAY=true shift ;; --no-backup) USER_NO_BACKUP=true shift ;; --migrate) MIGRATE_VPS=true shift ;; --no-cert-renew) RUN_CERT_RENEWAL=false shift ;; --mainnet) BTC_CHAIN=mainnet shift ;; --testnet) BTC_CHAIN=testnet shift ;; --regtest) BTC_CHAIN=regtest shift ;; --reconfigure-btcpay) RECONFIGURE_BTCPAY_SERVER=true shift ;; *) # unknown option ;; esac done # set up our default paths. export CLUSTERS_DIR="$HOME/ss-clusters" export CACHES_DIR="$HOME/ss-cache" export SSH_HOME="$HOME/.ssh" export DOMAIN_NAME="$DOMAIN_NAME" export REGISTRY_DOCKER_IMAGE="registry:2" if [ "$VPS_HOSTING_TARGET" = lxd ]; then CURRENT_REMOTE="$(lxc remote get-default)" elif [ "$VPS_HOSTING_TARGET" = aws ]; then CURRENT_REMOTE="docker-machine" fi export LXD_REMOTE_PATH="$CLUSTERS_DIR/$CURRENT_REMOTE" export CURRENT_REMOTE="$CURRENT_REMOTE" # 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 "$LXD_REMOTE_PATH/authorized_keys" ]; then mkdir -p "u" cat "$SSH_HOME/id_rsa.pub" >> "$LXD_REMOTE_PATH/authorized_keys" echo "INFO: Sovereign Stack just stubbed out '$LXD_REMOTE_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 mkdir -p "$CACHES_DIR" "$LXD_REMOTE_PATH" CLUSTER_DEFINTION="$LXD_REMOTE_PATH/cluster_definition" export CLUSTER_DEFINTION="$CLUSTER_DEFINTION" if [ ! -f "$CLUSTER_DEFINTION" ]; then # stub out a cluster_definition. cat >"$CLUSTER_DEFINTION" < export REGISTRY_PASSWORD= export MACVLAN_INTERFACE="\$MACVLAN_INTERFACE" export LXD_DISK_TO_USE="\$LXD_DISK_TO_USE" export SITE_LIST="\$SITE_LIST" EOL chmod 0744 "$CLUSTER_DEFINTION" echo "We stubbed out a '$CLUSTER_DEFINTION' file for you." echo "Use this file to customize your cluster deployment;" echo "Check out 'https://www.sovereign-stack.org/cluster-definition' for an example." exit 1 fi ######################################### if [ ! -f "$CLUSTER_DEFINTION" ]; then echo "ERROR: CLUSTER DEFINITION NOT PRESENT." exit 1 fi source "$CLUSTER_DEFINTION" ###########################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 > "$LXD_REMOTE_PATH/registry.yml" <"$SITE_DEFINITION_PATH" <