forked from eclipse-sdv-blueprints/fleet-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-config-functions.sh
104 lines (98 loc) · 3.29 KB
/
create-config-functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# 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.
#
# SPDX-License-Identifier: Apache-2.0
#
# Utility methods for creating property files to be used with the Docker Compose
# files in this directory.
#
# create file with environment variables that the FMS Forwarder running in the vehicle
# will use to configure its connection to Hono's MQTT adapter
create_common_mqtt_client_env() {
ENV_FILE_PATH=$1
URI=$2
TRUST_STORE=$3
ENABLE_HOSTNAME_VALIDATION=$4
echo "Creating MQTT client properties file ${ENV_FILE_PATH} ..."
cat <<EOF > "${ENV_FILE_PATH}"
MQTT_URI=${URI}
TRUST_STORE_PATH=${TRUST_STORE}
ENABLE_HOSTNAME_VALIDATION=${ENABLE_HOSTNAME_VALIDATION}
EOF
}
# create file with environment variables that the FMS Forwarder running in the vehicle
# will use to configure its connection to Hono's MQTT adapter
create_mqtt_client_env() {
ENV_FILE_PATH=$1
URI=$2
USERNAME=$3
PASSWORD=$4
TRUST_STORE=$5
ENABLE_HOSTNAME_VALIDATION=$6
create_common_mqtt_client_env \
"${ENV_FILE_PATH}" \
"${URI}" \
"${TRUST_STORE}" \
"${ENABLE_HOSTNAME_VALIDATION}"
cat <<EOF >> "${ENV_FILE_PATH}"
MQTT_USERNAME=${USERNAME}
MQTT_PASSWORD=${PASSWORD}
EOF
}
# create file with environment variables that the FMS Forwarder running in the vehicle
# will use to configure its connection to Hono's MQTT adapter
create_mqtt_client_env_with_cert() {
ENV_FILE_PATH=$1
URI=$2
CLIENT_CERT_PATH=$3
CLIENT_KEY_PATH=$4
TRUST_STORE=$5
ENABLE_HOSTNAME_VALIDATION=$6
create_common_mqtt_client_env \
"${ENV_FILE_PATH}" \
"${URI}" \
"${TRUST_STORE}" \
"${ENABLE_HOSTNAME_VALIDATION}"
CONFIG_DIR_FMS_FORWARDER="${ENV_FILE_PATH%/*}/fms-forwarder"
cp "${CLIENT_CERT_PATH}" "${CLIENT_KEY_PATH}" "${CONFIG_DIR_FMS_FORWARDER}"
cat <<EOF >> "${ENV_FILE_PATH}"
DEVICE_CERT=/app/config/$(basename "$CLIENT_CERT_PATH")
DEVICE_KEY=/app/config/$(basename "$CLIENT_KEY_PATH")
EOF
}
# create file with environment variables to be used with Docker Compose when
# starting the services:
#
# docker compose --env-file hono.env ...
#
create_docker_compose_env() {
ENV_FILE_PATH=$1
CONSUMER_CONFIG_FOLDER=$2
CONSUMER_KAFKA_PROPERTIES_FILE_NAME=$3
CONSUMER_KAFKA_TOPIC_NAME=$4
FORWARDER_CONFIG_FOLDER=$5
FORWARDER_MQTT_ENV_FILE_PATH=$6
echo "Creating Docker Compose env file ${ENV_FILE_PATH} ..."
cat <<EOF > "${ENV_FILE_PATH}"
FMS_CONSUMER_CONFIG_FOLDER=${CONSUMER_CONFIG_FOLDER}
FMS_CONSUMER_KAFKA_PROPERTIES_FILE=${CONSUMER_KAFKA_PROPERTIES_FILE_NAME}
FMS_CONSUMER_KAFKA_TOPIC_NAME=${CONSUMER_KAFKA_TOPIC_NAME}
FMS_FORWARDER_CONFIG_FOLDER=${FORWARDER_CONFIG_FOLDER}
FMS_FORWARDER_MQTT_ENV_FILE=${FORWARDER_MQTT_ENV_FILE_PATH}
EOF
}