From f68f8a1b4c506d1f21c5a43ee6f2ace6e238d9d4 Mon Sep 17 00:00:00 2001 From: afeiszli Date: Tue, 21 Feb 2023 18:36:37 -0500 Subject: [PATCH] upgrade script functional --- scripts/nm-upgrade.sh | 235 +++++++++++++++++++++++++++++------------- 1 file changed, 161 insertions(+), 74 deletions(-) diff --git a/scripts/nm-upgrade.sh b/scripts/nm-upgrade.sh index 83a8e843..d09d721e 100644 --- a/scripts/nm-upgrade.sh +++ b/scripts/nm-upgrade.sh @@ -103,6 +103,21 @@ install_dependencies() { echo "-----------------------------------------------------" } +get_email() { + + unset GET_EMAIL + unset RAND_EMAIL + RAND_EMAIL="$(echo $RANDOM | md5sum | head -c 16)@email.com" + read -p "Email Address for Domain Registration (click 'enter' to use $RAND_EMAIL): " GET_EMAIL + if [ -z "$GET_EMAIL" ]; then + echo "using rand email" + EMAIL="$RAND_EMAIL" + else + EMAIL="$GET_EMAIL" + fi + +} + # collect_server_settings - retrieve server settings from existing compose file collect_server_settings() { MASTER_KEY=$(yq -r .services.netmaker.environment.MASTER_KEY docker-compose.yml) @@ -199,6 +214,7 @@ collect_node_settings() { curl -s -H "Authorization: Bearer $MASTER_KEY" -H 'Content-Type: application/json' https://$SERVER_HTTP_HOST/api/nodes | jq -c '[ .[] | select(.isserver=="yes") ]' > nodejson.tmp NODE_LEN=$(jq length nodejson.tmp) HAS_INGRESS="no" + HAS_RELAY="no" if [ "$NODE_LEN" -gt 0 ]; then echo "===SERVER NODES===" for i in $(seq 1 $NODE_LEN); do @@ -236,37 +252,107 @@ collect_node_settings() { echo "WARNING: Your server contains an Ingress Gateway. After upgrading, existing Ext Clients will be lost and must be recreated. Please confirm that you would like to continue." confirm fi + if [[ $HAS_RELAY == "yes" ]]; then + echo "WARNING: Your server contains a Relay. After upgrading, relay will be unset. Relay functionality has been moved to the 'host' level, and must be reconfigured once all machines are upgraded." + confirm + fi + +} + +setup_caddy() { + + echo "backing up Caddyfile to /root/Caddyfile.backup" + cp /root/Caddyfile /root/Caddyfile.backup + + if grep -wq "acme.zerossl.com/v2/DV90" Caddyfile; then + echo "zerossl already set, continuing" + else + echo "editing Caddyfile" + sed -i '0,/email/{s~email~acme_ca https://acme.zerossl.com/v2/DV90\n\t&~}' /root/Caddyfile + fi + +cat <> /root/Caddyfile + +# STUN +https://$STUN_DOMAIN { + reverse_proxy netmaker:3478 +} +EOT + +} + +set_mq_credentials() { + + unset GET_MQ_USERNAME + unset GET_MQ_PASSWORD + unset CONFIRM_MQ_PASSWORD + echo "Enter Credentials For MQ..." + read -p "MQ Username (click 'enter' to use 'netmaker'): " GET_MQ_USERNAME + if [ -z "$GET_MQ_USERNAME" ]; then + echo "using default username for mq" + MQ_USERNAME="netmaker" + else + MQ_USERNAME="$GET_MQ_USERNAME" + fi + + select domain_option in "Auto Generated Password" "Input Your Own Password"; do + case $REPLY in + 1) + echo "generating random password for mq" + MQ_PASSWORD=$(tr -dc A-Za-z0-9