[POLICY-15] Push Policy and ELK config updated

Change-Id: I58abfc97512366dea5b8aae80e42b39d1fa888de
Signed-off-by: Ravindra Bakkamanthala <rb7147@att.com>
diff --git a/policy-pe/docker-install.sh b/policy-pe/docker-install.sh
index 57c26bf..fa9472f 100644
--- a/policy-pe/docker-install.sh
+++ b/policy-pe/docker-install.sh
@@ -9,8 +9,8 @@
 function usage() {
 	echo -n "syntax: $(basename $0) "
 	echo -n "--debug ("
-	echo -n "[--install base|pap|pdp|console|mysql|brmsgw|paplp|pdplp] | "
-	echo -n "[--configure base|pap|pdp|console|mysql|brmsgw|paplp|pdplp] | "
+	echo -n "[--install base|pap|pdp|console|mysql|elk|brmsgw|paplp|pdplp] | "
+	echo -n "[--configure base|pap|pdp|console|mysql|elk|brmsgw|paplp|pdplp] | "
 }
 
 function check_java() {
@@ -432,6 +432,71 @@
 	# nothing to do
 }
 
+# This function installs elk related shell scripts and sql files in the proper locations
+# under $POLICY_HOME. It also adds the Elk to the PATH based on configuration.
+#
+function configure_elk() {
+	if [[ $DEBUG == y ]]; then
+		echo "-- ${FUNCNAME[0]} $@ --"
+		set -x
+	fi
+	
+	# nothing to do
+}
+
+function install_elk() {
+	if [[ $DEBUG == y ]]; then
+		echo "-- ${FUNCNAME[0]} $@ --"
+		set -x
+	fi
+	
+	if [[ -f "${HOME}/.bash_profile" ]]; then
+		source "${HOME}/.bash_profile"
+	fi
+	
+	if [[ -f "${HOME}/.profile" ]]; then
+		source "${HOME}/.profile"
+	fi
+	
+	ELK_TARGET_INSTALL_DIR=${POLICY_HOME}/elk
+	
+	if [[ -d ${ELK_TARGET_INSTALL_DIR} ]]; then
+		echo "WARNING: ${ELK_TARGET_INSTALL_DIR} exists."
+		return 1
+	fi
+	
+	/bin/mkdir -p "${ELK_TARGET_INSTALL_DIR}" > /dev/null 2>&1
+	
+	if [[ ! -d ${ELK_TARGET_INSTALL_DIR} ]]; then
+		echo "WARNING: ${ELK_TARGET_INSTALL_DIR} doesn't exist."
+		return 1
+	fi
+	
+	cd ${ELK_TARGET_INSTALL_DIR}
+	curl -L -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.0.tar.gz
+	
+	tar xvzf elasticsearch-5.4.0.tar.gz -C .
+	/bin/rm -fr elasticsearch-5.4.0.tar.gz
+	/bin/mv  ${ELK_TARGET_INSTALL_DIR}/elasticsearch-5.4.0/* .
+	/bin/rm -fr ${ELK_TARGET_INSTALL_DIR}/elasticsearch-5.4.0
+	
+	/bin/cp "${POLICY_HOME}"/install/elk/bin/* "${POLICY_HOME}/bin"	
+	/bin/cp -f "${POLICY_HOME}"/install/elk/config/* "${ELK_TARGET_INSTALL_DIR}/config"
+	/bin/cp -f "${POLICY_HOME}/install/elk/init.d/elkd" "${POLICY_HOME}/etc/init.d/elk"
+	
+	install_prereqs "${COMPONENT_TYPE}.conf"
+	
+	/bin/sed -i -e "s!\${{POLICY_HOME}}!${POLICY_HOME}!g" \
+		-e "s!\${{FQDN}}!${FQDN}!g" \
+		-e "s!\${{ELK_JMX_PORT}}!${ELK_JMX_PORT}!g" \
+		"${ELK_TARGET_INSTALL_DIR}"/config/* "${POLICY_HOME}/etc/init.d/elk" > /dev/null 2>&1
+		
+
+	list_unexpanded_files ${POLICY_HOME}
+		
+	return $?
+}
+
 # This function installs brmsgw related shell scripts and config files in the proper
 # locations under $POLICY_HOME. 
 #
@@ -546,11 +611,12 @@
 	pap)	;;
 	console)	;;
 	mysql)	;;
+	elk)    ;;
 	brmsgw)	;;
 	paplp)	;;
 	pdplp)	;;
 	skip)	;;
-	*)		echo "invalid component type (${COMPONENT_TYPE}): must be in {base|pdp|pap|console|mysql|brmsgw|paplp|pdplp}";
+	*)		echo "invalid component type (${COMPONENT_TYPE}): must be in {base|pdp|pap|console|mysql|elk|brmsgw|paplp|pdplp}";
 			usage
 			exit 1
 			;;
@@ -615,6 +681,9 @@
 		mysql)
 			install_mysql
 			;;
+		elk)
+			install_elk
+			;;		
 		brmsgw)
 			install_brmsgw
 			;;
@@ -622,7 +691,7 @@
 			install_logparser
 			;;
 		*)		
-			echo "invalid component type (${COMPONENT_TYPE}): must be in {base|pdp|pap|console|mysql|brmsgw|paplp|pdplp}";
+			echo "invalid component type (${COMPONENT_TYPE}): must be in {base|pdp|pap|console|mysql|elk|brmsgw|paplp|pdplp}";
 			usage
 			exit 1
 			;;
@@ -649,6 +718,9 @@
 		mysql)
 			configure_mysql
 			;;
+		elk)
+			configure_elk
+			;;	
 		brmsgw)
 			configure_component "${COMPONENT_TYPE}.conf" "${POLICY_HOME}/servers/${COMPONENT_TYPE}/"
 			;;
@@ -656,7 +728,7 @@
 			configure_component "${COMPONENT_TYPE}.conf" "${POLICY_HOME}/servers/${COMPONENT_TYPE}/"
 			;;
 		*)		
-			echo "invalid component type (${COMPONENT_TYPE}): must be in {base|pdp|pap|console|mysql|brmsgw|paplp|pdplp}";
+			echo "invalid component type (${COMPONENT_TYPE}): must be in {base|pdp|pap|console|mysql|elk|brmsgw|paplp|pdplp}";
 			usage
 			exit 1
 			;;