aboutsummaryrefslogtreecommitdiffstats
path: root/epsdk-app-onap/src/main/swm/common/localize_asdc.sh
blob: 5774e5a0cf2cd5ff65fea9ac6d963ff4431f0d4a (plain)
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
#!/bin/bash

FINAL_CONFIG_FILE=${ROOT_DIR}/war/WEB-INF/conf/asdc.properties
TEMPLATE_CONFIG_FILE=${ROOT_DIR}/war/WEB-INF/conf/asdc_template.properties
BACKUP1_CONFIG_FILE=${ROOT_DIR}/war/WEB-INF/conf/asdc.properties.bk.1
BACKUP2_CONFIG_FILE=${ROOT_DIR}/war/WEB-INF/conf/asdc.properties.bk.2

echo "Localizing the SDC client configuration"

if [ -z "${ASDC_CLIENT_TYPE}" ]; then
	ASDC_CLIENT_TYPE=REST
fi

if [ "${ASDC_CLIENT_TYPE}" = "REST" ]; then
	if [ -z "${ASDC_CLIENT_REST_HOST}" ]; then
		echo 'ASDC_CLIENT_REST_HOST must be provided when ASDC_CLIENT_TYPE=REST'
		exit 1
	fi

	if [ -z "${ASDC_CLIENT_REST_AUTH}" ]; then
		echo 'ASDC_CLIENT_REST_AUTH must be provided when ASDC_CLIENT_TYPE=REST'
		exit 2
	fi

	if [ -z "${ASDC_CLIENT_REST_PROTOCOL}" ]; then
		ASDC_CLIENT_REST_PROTOCOL=http
	fi

	if [ -z "${ASDC_CLIENT_REST_PORT}" ]; then
		ASDC_CLIENT_REST_PORT=8080
	fi
else
	ASDC_CLIENT_REST_HOST=""
	ASDC_CLIENT_REST_AUTH=""
	ASDC_CLIENT_REST_PROTOCOL="http"
	ASDC_CLIENT_REST_PORT="8080"
fi

#------------------------------------------------------------------------
#- MAKE A BACKUP OF PREVIOUS BACKUP FILE, IF EXISTS
#------------------------------------------------------------------------
if [ -f ${BACKUP1_CONFIG_FILE} ]; then
    cp -f ${BACKUP1_CONFIG_FILE} ${BACKUP2_CONFIG_FILE} || {
        echo "ERROR: Could not copy ${BACKUP1_CONFIG_FILE} to ${BACKUP2_CONFIG_FILE}"
        exit 2
    }
fi
 
#------------------------------------------------------------------------
#- MAKE A BACKUP OF CURRENT FILE, IF EXISTS
#------------------------------------------------------------------------
if [ -f ${FINAL_CONFIG_FILE} ]; then
    cp -f ${FINAL_CONFIG_FILE} ${BACKUP1_CONFIG_FILE} || {
        echo "ERROR: Could not copy ${FINAL_CONFIG_FILE} to ${BACKUP1_CONFIG_FILE}"
        exit 3
    }
fi

sed -e 's ${ASDC_CLIENT_TYPE} '${ASDC_CLIENT_TYPE}' g' \
	-e 's ${ASDC_CLIENT_REST_HOST} '${ASDC_CLIENT_REST_HOST}' g' \
	-e 's ${ASDC_CLIENT_REST_PORT} '${ASDC_CLIENT_REST_PORT}' g' \
	-e 's ${ASDC_CLIENT_REST_PROTOCOL} '${ASDC_CLIENT_REST_PROTOCOL}' g' \
	-e 's/${ASDC_CLIENT_REST_AUTH}/'"${ASDC_CLIENT_REST_AUTH}"'/g' ${TEMPLATE_CONFIG_FILE} > ${FINAL_CONFIG_FILE} || {
		echo "ERROR: Could not process template file ${TEMPLATE_CONFIG_FILE} into ${FINAL_CONFIG_FILE}"
		exit 4
	}

echo "Localized ${FINAL_CONFIG_FILE} successfully."