#!/bin/bash #function test { echo "param1 $1"; } function join { local IFS="$1"; shift; echo "$*"; } function join_by { local d=${1-} f=${2-}; if shift 2; then printf %s "$f" "${@/#/$d}"; fi; } joinByString() { local separator="$1" shift local first="$1" shift printf "%s" "$first" "${@/#/$separator}" } # Help command if [ "$1" == "-h" ]; then echo "Usage: `basename $0` " exit 0 fi # Creates root folder for configuration of the application if [ ! -d "$(pwd)/BMW-Dynatrace-config/$1" ]; then echo "$1 project folder doesn't exist, creating one..." mkdir BMW-Dynatrace-config/$1 else echo "$1 project folder already exists" fi # Configuration array declare -a config_arr=( "management-zone" "dashboard" "alerting-profile" "notification" "custom-service-java" "synthetic-monitor" "calculated-metrics-service" "conditional-naming-processgroup" "conditional-naming-service" #"anomaly-detection-metrics" ) IFS=',' read -a compassIDs <<< $2 delimeterZ=',' result=$(joinByString , ${compassIDs[@]}) echo Result: $result; joinByString , ${compassIDs[@]} #echo join_by , "${compassIDs[@]}" #result=$(join , ${compassIDs[@]}) #echo "Result" + $result for i in "${config_arr[@]}" do if [ ! -d "BMW-Dynatrace-config/$1/$i" ]; then echo "--> Creating [$i]" cp -R onboarding/CD_managementZone/$i BMW-Dynatrace-config/$1/ if [ -f "BMW-Dynatrace-config/$1/$i/$i.yaml" ]; then sed -i "s/CD_managementZone/$1/g" BMW-Dynatrace-config/$1/$i/$i.yaml #compassIds=$2.split(',').join(',') sed -i "s/newCompassIds/$compassIds/g" BMW-Dynatrace-config/$1/$i/$i.yaml #sed -i "s/newComponentTag/$2/g" BMW-Dynatrace-config/$1/$i/$i.yaml fi else echo "[$i] already exist, no changes applied" fi done