+#!/bin/bash
+################################################################################
+# Copyright (c) 2020 Nordix Foundation. #
+# #
+# Licensed under the Apache License, Version 2.0 (the "License"); #
+# you may not use this file except in compliance with the License. #
+# You may obtain a copy of the License at #
+# #
+# http://www.apache.org/licenses/LICENSE-2.0 #
+# #
+# Unless required by applicable law or agreed to in writing, software #
+# distributed under the License is distributed on an "AS IS" BASIS, #
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
+# See the License for the specific language governing permissions and #
+# limitations under the License. #
+################################################################################
+
+
+while [ -n "$1" ]; do # while loop starts
+
+ case "$1" in
+
+ -f) OVERRIDEYAML=$2
+ shift
+ ;;
+ -c) LIST_OF_COMPONENTS=$2
+ shift
+ ;;
+ *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
+
+ esac
+
+ shift
+
+done
+
+
+if [ -z "$OVERRIDEYAML" ];then
+ echo "****************************************************************************************************************"
+ echo " ERROR "
+ echo "****************************************************************************************************************"
+ echo "RIC deployment without deployment recipe is currently disabled. Please specify an recipe with the -f option."
+ echo "****************************************************************************************************************"
+ exit 1
+fi
+
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
+
+COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
+NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^ namespace:/{getline; while ($0 ~ /^ .*|^ *$/) {print $0; if (getline == 0) {break}}}')
+NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
+RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
+SIMULATOR_BLOCK=$(cat $OVERRIDEYAML | awk '/^ simulatorinstance:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
+SIMULATOR_COUNT=$(echo "$SIMULATOR_BLOCK" | awk '/^ *count:/{print $2}')
+COMPONENTS=${LIST_OF_COMPONENTS:-"a1simulator policymanagementservice"}
+echo "SIMULATOR_COUNT [$SIMULATOR_COUNT]"
+
+if ! kubectl get ns ${NONRTRIC_NAMESPACE:-nonrtric}> /dev/null 2>&1; then
+ kubectl create ns ${NONRTRIC_NAMESPACE:-nonrtric}
+fi
+if ! kubectl get ns onap > /dev/null 2>&1; then
+ kubectl create ns onap
+fi
+
+kubectl create configmap -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe --from-file=recipe=$OVERRIDEYAML
+
+echo "Deploying NONRTRIC components [$COMPONENTS]"
+
+for component in $COMPONENTS; do
+ helm dep up $DIR/../helm/$component
+ case "$component" in
+ a1simulator)
+ for((i=1;i<=$SIMULATOR_COUNT;i++)) ; do
+ echo "CREATING SIMUALATOR INSTANCE $i"
+ helm install -f $OVERRIDEYAML --namespace "${NONRTRIC_NAMESPACE:-nonrtric}" --name "${RELEASE_PREFIX}-$component-$i" --set a1simulator.instanceName=a1-sim-$i $DIR/../helm/$component
+ done
+ ;;
+ *)
+ helm install -f $OVERRIDEYAML --namespace "${NONRTRIC_NAMESPACE:-nonrtric}" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
+
+ esac
+
+done