blob: 88ad22f272b7f2f733c96cc54e5c2df3a606a4ef [file] [log] [blame]
ktimoney82e51362023-08-28 13:41:45 +01001#!/bin/bash
2
3# ============LICENSE_START===============================================
4# Copyright (C) 2023 Nordix Foundation. All rights reserved.
5# ========================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=================================================
18#
19
20. scripts/get_influxdb2_token.sh
21. scripts/populate_keycloak.sh
22
23print_usage() {
24 echo "Usage: pmrapp-setup.sh"
25 exit 1
26}
27
28check_error() {
29 if [ $1 -ne 0 ]; then
30 echo "Failed $2"
31 echo "Exiting..."
32 exit 1
33 fi
34}
35
36setup_init() {
37echo "Cleaning previously started containers..."
38./pmrapp-tear-down.sh
39}
40
41check_images(){
42export PMRAPP_IMAGE="pm-rapp:latest"
43}
44
45create_topic() {
46TOPIC="rapp-topic"
47retcode=1
48rt=43200000
49echo "Creating topic $TOPIC with retention $(($rt/1000)) seconds"
50while [ $retcode -ne 0 ]; do
51 cmd_output=$(docker exec -it common-kafka-1-1 ./bin/kafka-topics.sh \
52 --create --topic $TOPIC --config retention.ms=$rt --bootstrap-server kafka-1:9092)
53 retcode=$?
54 test_string="Topic 'rapp-topic' already exists"
55 if [[ $cmd_output == *${test_string}* ]]; then
56 echo $test_string
57 retcode=0
58 fi
59done
60}
61
62setup_pmrapp() {
63create_topic
64
65cid="pm-rapp"
66create_clients nonrtric-realm $cid
67check_error $?
68generate_client_secrets nonrtric-realm $cid
69check_error $?
70
71export PMRAPP_CLIENT_SECRET=$(< .sec_nonrtric-realm_$cid)
72envsubst < docker-compose-pmrapp.yaml > docker-compose-pmrapp_gen.yaml
73docker-compose -p pmrapp -f docker-compose-pmrapp_gen.yaml up -d
74}
75## Main ##
76setup_init
77
78check_images
79
80setup_pmrapp
81check_error $?