diff --git a/create_lxc_base.sh b/create_lxc_base.sh index b76256e..9a11d37 100755 --- a/create_lxc_base.sh +++ b/create_lxc_base.sh @@ -1,9 +1,9 @@ #!/bin/bash -set -eu +set -exu cd "$(dirname "$0")" -./stub_lxc_profile.sh "$BASE_IMAGE_VM_NAME" +bash -c "./stub_lxc_profile.sh --lxd-hostname=$BASE_IMAGE_VM_NAME" # let's download our base image. if ! lxc image list --format csv --columns l | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then diff --git a/deploy.sh b/deploy.sh index b3817dc..030c620 100755 --- a/deploy.sh +++ b/deploy.sh @@ -371,22 +371,19 @@ for VIRTUAL_MACHINE in www btcpayserver; do export VPS_HOSTNAME="$VPS_HOSTNAME" export FQDN="$VPS_HOSTNAME.$DOMAIN_NAME" - DDNS_HOST= - if [ "$VIRTUAL_MACHINE" = www ]; then if [ "$SKIP_WWW" = true ]; then echo "INFO: Skipping WWW due to command line argument." continue fi - + + FQDN="$WWW_HOSTNAME.$DOMAIN_NAME" VPS_HOSTNAME="$WWW_HOSTNAME" MAC_ADDRESS_TO_PROVISION="$WWW_SERVER_MAC_ADDRESS" - DDNS_HOST="$WWW_HOSTNAME" ROOT_DISK_SIZE_GB="$((ROOT_DISK_SIZE_GB + NEXTCLOUD_SPACE_GB))" + elif [ "$VIRTUAL_MACHINE" = btcpayserver ] || [ "$SKIP_BTCPAY" = true ]; then - - - DDNS_HOST="$BTCPAY_HOSTNAME" + FQDN="$BTCPAY_HOSTNAME.$DOMAIN_NAME" VPS_HOSTNAME="$BTCPAY_HOSTNAME" MAC_ADDRESS_TO_PROVISION="$BTCPAYSERVER_MAC_ADDRESS" if [ "$BITCOIN_CHAIN" = mainnet ]; then @@ -396,21 +393,19 @@ for VIRTUAL_MACHINE in www btcpayserver; do fi elif [ "$VIRTUAL_MACHINE" = "$BASE_IMAGE_VM_NAME" ]; then - DDNS_HOST="$BASE_IMAGE_VM_NAME" + export FQDN="$BASE_IMAGE_VM_NAME" ROOT_DISK_SIZE_GB=8 else echo "ERROR: VIRTUAL_MACHINE not within allowable bounds." exit fi - export DDNS_HOST="$DDNS_HOST" - export FQDN="$DDNS_HOST.$DOMAIN_NAME" + export FQDN="$FQDN" export LXD_VM_NAME="${FQDN//./-}" - export VIRTUAL_MACHINE="$VIRTUAL_MACHINE" export REMOTE_CERT_DIR="$REMOTE_CERT_BASE_DIR/$FQDN" export MAC_ADDRESS_TO_PROVISION="$MAC_ADDRESS_TO_PROVISION" - ./deploy_vms.sh + ./deploy_vm.sh if [ "$VIRTUAL_MACHINE" = www ]; then # this tells our local docker client to target the remote endpoint via SSH diff --git a/deploy_vm.sh b/deploy_vm.sh index 40b2e32..3bd4a92 100755 --- a/deploy_vm.sh +++ b/deploy_vm.sh @@ -30,7 +30,7 @@ if ! lxc list --format csv | grep -q "$LXD_VM_NAME"; then exit 1 fi - ./stub_lxc_profile.sh "$LXD_VM_NAME" + bash -c "./stub_lxc_profile.sh --vm=$VIRTUAL_MACHINE --lxd-hostname=$LXD_VM_NAME" # now let's create a new VM to work with. #lxc init --profile="$LXD_VM_NAME" "$BASE_IMAGE_VM_NAME" "$LXD_VM_NAME" --vm @@ -43,7 +43,7 @@ if ! lxc list --format csv | grep -q "$LXD_VM_NAME"; then lxc start "$LXD_VM_NAME" - bash -c "./wait_for_lxc_ip.sh --lxc-name=$LXD_VM_NAME" + bash -c "./wait_for_lxc_ip.sh --lxd-name=$LXD_VM_NAME" fi # scan the remote machine and install it's identity in our SSH known_hosts file. diff --git a/stub_lxc_profile.sh b/stub_lxc_profile.sh index e8956c7..71321a2 100755 --- a/stub_lxc_profile.sh +++ b/stub_lxc_profile.sh @@ -1,9 +1,28 @@ #!/bin/bash -set -eu +set -exu cd "$(dirname "$0")" -LXD_HOSTNAME="${1:-}" +VIRTUAL_MACHINE= +LXD_HOSTNAME= + +# grab any modifications from the command line. +for i in "$@"; do + case $i in + --lxd-hostname=*) + LXD_HOSTNAME="${i#*=}" + shift + ;; + --vm=*) + VIRTUAL_MACHINE="${i#*=}" + shift + ;; + *) + echo "Unexpected option: $1" + exit 1 + ;; + esac +done # generate the custom cloud-init file. Cloud init installs and configures sshd SSH_AUTHORIZED_KEY=$(<"$SSH_PUBKEY_PATH") @@ -37,7 +56,8 @@ EOF fi -if [ "$LXD_HOSTNAME" = "$BASE_IMAGE_VM_NAME" ]; then +# if VIRTUAL_MACHINE is undefined, then we doing the base image. +if [ -z "$VIRTUAL_MACHINE" ]; then # this is for the base image only... cat >> "$YAML_PATH" <> "$YAML_PATH" <> "$YAML_PATH" <> "$YAML_PATH" <> "$YAML_PATH" <> "$YAML_PATH" <> "$YAML_PATH" <>"$NGINX_CONF_PATH" <