From 9faf44556598faf587c01b2d050c37269193042a Mon Sep 17 00:00:00 2001
From: root <root@srv8.soctools.grena.ge>
Date: Fri, 11 Mar 2022 12:08:04 +0400
Subject: [PATCH] create script to ask variables interactively

---
 configure.sh                      | 80 +++++++++++++++++++++++++++++++
 group_vars/all/main.yml           |  8 +++-
 group_vars/all/variables.template | 28 +++++++++++
 3 files changed, 114 insertions(+), 2 deletions(-)
 create mode 100755 configure.sh
 create mode 100644 group_vars/all/variables.template

diff --git a/configure.sh b/configure.sh
new file mode 100755
index 0000000..26650a7
--- /dev/null
+++ b/configure.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+set -e
+if [ -f group_vars/all/variables.yml ]; then 
+	echo "Variables file (group_vars/all/variables.yml) is configure manually. please take a look if everything is correct and move to next step"
+	cat group_vars/all/variables.yml
+else 
+	echo "set FQDN which will be used to access the soctools services. (the DNS record should already be in place.)"
+	read -p 'soctoolsproxy: ' soctoolsproxy
+	if [ -z $soctoolsproxy ]; then
+		echo "Error: Empty string for soctoolsproxy! exiting..."
+		exit 1
+	fi
+	echo
+	echo "Organization's top level domain (will be used as organization name and organization domain in different services)"
+	read -p 'domain: ' domain
+        if [ -z $domain ]; then
+                echo "Error: Empty string for domain! exiting..."
+                exit 1
+        fi
+	echo
+	echo
+	echo
+	echo "Please provide following parameters for first socctolls user which will be created during the initialization with organization admin privileges:"
+	echo "firstname - First name of the user"
+	echo "lastname 	- Last name of the user"
+	echo "username 	- Username of the user"
+	echo "DN 	- Distinguished Name of the user, for user certificate"
+	echo "CN 	- Common Name of the user, for user certificate"
+	echo "Email will be generated automatically in Username@Domain format becouse of format restrictions in some services"
+	sleep 10
+	for i in firstname lastname username DN CN; do
+		read -p "${i}: " $i
+	      	if [ -z $i ]; then
+                	echo "Error: Empty string for ${i}! exiting..."
+                	exit 1
+        	fi
+	done
+	echo
+	echo
+	echo
+	sleep 2
+	echo "Please check the gethered variables and type 'yes' if everything is correct: "
+	echo "soctoolsproxy: 	$soctoolsproxy"
+	echo "domain: 		$domain"
+	echo "firstname: 	$firstname"
+	echo "lastname: 	$lastname"
+	echo "username: 	$username"
+	echo "DN: 		$DN"
+	echo "CN:		$CN"
+	echo
+	echo
+	sleep 10
+	read -p "Correct? type 'yes' or 'no': " ANSWER
+	if [ $ANSWER = "yes" ]; then
+		if ! [ -f group_vars/all/variables.template ]; then
+			echo "template file(group_vars/all/variables.template) does not exists! exiting ..."
+			exit 1
+		else
+			cp -f group_vars/all/variables.template group_vars/all/variables.yml
+			sed -i "s/CHANGE_ME_TO_FQDN/${soctoolsproxy}/g" group_vars/all/variables.yml
+			sed -i "s/soctools.test/${domain}/g" group_vars/all/variables.yml
+			sed -i "11s/soc_admin/${firstname}/" group_vars/all/variables.yml
+			sed -i "12s/SOC/${lastname}/" group_vars/all/variables.yml
+			sed -i "13s/soc_admin/${username}/" group_vars/all/variables.yml
+			sed -i "14s/soc_admin/${username}/" group_vars/all/variables.yml
+			sed -i "15s/SOC_Admin/${DN}/" group_vars/all/variables.yml
+			sed -i "16s/SOC_Admin/${CN}/" group_vars/all/variables.yml
+			sed -i "26s/soc_admin/${username}/" group_vars/all/variables.yml
+			echo
+			echo
+			echo "variables file generated (group_vars/all/variables.yml)"
+			sleep 2
+			echo "move to next command to deploy the soctools cluster."
+			echo 'Thank You!'
+		fi
+	else
+		echo "Exiting based of user input ..."
+		exit 0
+	fi
+fi
diff --git a/group_vars/all/main.yml b/group_vars/all/main.yml
index 3405aa9..66f8bab 100644
--- a/group_vars/all/main.yml
+++ b/group_vars/all/main.yml
@@ -1,7 +1,5 @@
 ---
 
-soctoolsproxy: "CHANGE_ME_TO_FQDN"
-
 maxmind_key: ""
 
 docker_build_dir: "{{playbook_dir}}/build"
@@ -15,6 +13,12 @@ suffix: a20201004
 
 kibana_plugins_version: "v0.7"
 
+THEHIVE_KIBANA_USER:
+  username: "kibana"
+  name: "Kibana"
+  surname: "User"
+  roles: '["read", "write"]'
+
 haproxy_name: "soctools-haproxy"
 haproxy_version: "2.2"
 haproxy_img: "{{repo}}/haproxy:{{version}}{{suffix}}"
diff --git a/group_vars/all/variables.template b/group_vars/all/variables.template
new file mode 100644
index 0000000..ed0178a
--- /dev/null
+++ b/group_vars/all/variables.template
@@ -0,0 +1,28 @@
+---
+
+# set FQDN which will be used to access the soctools services. (the DNS record should already be in place.)
+soctoolsproxy: "CHANGE_ME_TO_FQDN"
+
+# Organization's top level domain (will be used as organization name and organization domain in different services)
+domain: "soctools.test"
+
+#List of users which will be created during the initialization with organization admin privileges
+soctools_users:
+  - firstname: "soc_admin"
+    lastname: "SOC"
+    username: "soc_admin"
+    email: "soc_admin@{{domain}}"
+    DN: "CN=SOC_Admin"
+    CN: "SOC_Admin"
+#  - firstname: "soc_admin_2"
+#    lastname: "SOC"
+#    username: "soc_admin_2"
+#    email: "soc_admin_2@{{domain}}"
+#    DN: "CN=SOC_Admin_2"
+#    CN: "SOC_Admin_2"
+    
+# list of users(username) from previous step which will recive admin roles in ODFE. (Minimum one user is required)
+ODFE_ADMIN_USERS:
+  - soc_admin
+#  -   soc_admin_2
+
-- 
GitLab