Browse Source

NET-1574: Pro install arg, handle enrollment key exists error (#3109)

* generalise smtp config

* copy over smtp vars

* env new line

* fix master key api access

* comment user tests

* fix network and user invite for master key access

* remove email sender type

* user mgmt commands

* check user role on CE

* user role nmtcl cmds

* user groups commands

* fix role and groups command

* fix user create cmd

* add usage info

* rm user role check

* fix user update cmd

* fix static check

* add backwards comptability support for extclient api for mobile

* rm debug logs

* set frontend url from base domain if empty

* add flag to install pro

* collect tenant id and license on pro install

* collect tenant id and license on pro install

* add install log

* add pro arg to usage

* add pro arg

* get token if exists already

* trim double quotes from netmaker tag

* trim double quotes from netmaker token

* use jq -r

* copy license and tenant id from previous config

* rename used tenant id var in script
Abhishek K 1 year ago
parent
commit
bb8e4e53e9
1 changed files with 38 additions and 16 deletions
  1. 38 16
      scripts/nm-quick.sh

+ 38 - 16
scripts/nm-quick.sh

@@ -19,11 +19,13 @@ unset BUILD_TAG
 unset IMAGE_TAG
 unset NETMAKER_BASE_DOMAIN
 unset UPGRADE_FLAG
+unset COLLECT_PRO_VARS
 # usage - displays usage instructions
 usage() {
 	echo "nm-quick.sh v$NM_QUICK_VERSION"
 	echo "usage: ./nm-quick.sh [-c]"
 	echo " -c  if specified, will install netmaker community version"
+	echo " -p  if specified, will install netmaker pro version"
 	echo " -u  if specified, will upgrade netmaker to pro version"
 	echo " -d if specified, will downgrade netmaker to community version"
 	exit 1
@@ -236,7 +238,7 @@ save_config() { (
 	save_config_item UI_IMAGE_TAG "$IMAGE_TAG"
 	# version-specific entries
 	if [ "$INSTALL_TYPE" = "pro" ]; then
-		save_config_item NETMAKER_TENANT_ID "$TENANT_ID"
+		save_config_item NETMAKER_TENANT_ID "$NETMAKER_TENANT_ID"
 		save_config_item LICENSE_KEY "$LICENSE_KEY"
 		if [ "$UPGRADE_FLAG" = "yes" ];then
 			save_config_item METRICS_EXPORTER "on"
@@ -249,7 +251,7 @@ save_config() { (
 		save_config_item SERVER_IMAGE_TAG "$IMAGE_TAG"
 	fi
 	# copy entries from the previous config
-	local toCopy=("SERVER_HOST" "MASTER_KEY" "MQ_USERNAME" "MQ_PASSWORD"
+	local toCopy=("SERVER_HOST" "MASTER_KEY" "MQ_USERNAME" "MQ_PASSWORD" "LICENSE_KEY" "NETMAKER_TENANT_ID"
 		"INSTALL_TYPE" "NODE_ID" "DNS_MODE" "NETCLIENT_AUTO_UPDATE" "API_PORT"
 		"CORS_ALLOWED_ORIGIN" "DISPLAY_KEYS" "DATABASE" "SERVER_BROKER_ENDPOINT" "VERBOSITY"
 		"DEBUG_MODE"  "REST_BACKEND" "DISABLE_REMOTE_IP_CHECK" "TELEMETRY" "ALLOWED_EMAIL_DOMAINS" "AUTH_PROVIDER" "CLIENT_ID" "CLIENT_SECRET"
@@ -568,7 +570,17 @@ set_install_vars() {
 	EMAIL="$GET_EMAIL"
 
 	wait_seconds 1
-
+	if [ "$COLLECT_PRO_VARS" = "true" ]; then
+		unset LICENSE_KEY
+		while [ -z "$LICENSE_KEY" ]; do
+			read -p "License Key: " LICENSE_KEY
+		done
+		unset NETMAKER_TENANT_ID
+		while [ -z ${NETMAKER_TENANT_ID} ]; do
+			read -p "Tenant ID: " NETMAKER_TENANT_ID
+		done
+	fi
+	wait_seconds 1
 	unset GET_MQ_USERNAME
 	unset GET_MQ_PASSWORD
 	unset CONFIRM_MQ_PASSWORD
@@ -729,22 +741,27 @@ setup_mesh() {
 		echo "Creating netmaker network (10.101.0.0/16)"
 
 		# TODO causes "Error Status: 400 Response: {"Code":400,"Message":"could not find any records"}"
-		nmctl network create --name netmaker --ipv4_addr 10.101.0.0/16
+		nmctl network create --name netmaker --ipv4_addr 100.172.188.0/24
 
 		wait_seconds 5
 	fi
 
 	echo "Obtaining a netmaker enrollment key..."
-
-	local tokenJson=$(nmctl enrollment_key create --tags netmaker --unlimited --networks netmaker)
-	TOKEN=$(jq -r '.token' <<<${tokenJson})
-	if test -z "$TOKEN"; then
-		echo "Error creating an enrollment key"
-		exit 1
+	local netmakerTag=$(nmctl enrollment_key list | jq -r '.[] | .tags[0]')
+	if [ ${netmakerTag} = "netmaker" ]; then
+		# key exists already, fetch token
+		TOKEN=$(nmctl enrollment_key list | jq -r '.[] | select(.tags[0]=="netmaker") | .token')
 	else
-		echo "Enrollment key ready"
+		local tokenJson=$(nmctl enrollment_key create --tags netmaker --unlimited --networks netmaker)
+		TOKEN=$(jq -r '.token' <<<${tokenJson})
+		if test -z "$TOKEN"; then
+			echo "Error creating an enrollment key"
+			exit 1
+		else
+			echo "Enrollment key ready"
+		fi
 	fi
-
+	
 	wait_seconds 3
 
 }
@@ -813,9 +830,9 @@ upgrade() {
 	while [ -z "$LICENSE_KEY" ]; do
 		read -p "License Key: " LICENSE_KEY
 	done
-	unset TENANT_ID
-	while [ -z ${TENANT_ID} ]; do
-		read -p "Tenant ID: " TENANT_ID
+	unset NETMAKER_TENANT_ID
+	while [ -z ${NETMAKER_TENANT_ID} ]; do
+		read -p "Tenant ID: " NETMAKER_TENANT_ID
 	done
 	save_config
 	# start docker and rebuild containers / networks
@@ -871,7 +888,7 @@ main (){
 	fi
 
 	INSTALL_TYPE="pro"
-	while getopts :cudv flag; do
+	while getopts :cudpv flag; do
 	case "${flag}" in
 	c)
 		INSTALL_TYPE="ce"
@@ -889,6 +906,11 @@ main (){
 		downgrade
 		exit 0
 		;;
+	p)
+		echo "installing pro version..."
+		INSTALL_TYPE="pro"
+		COLLECT_PRO_VARS="true"
+		;;
 	v)
 		usage
 		exit 0