-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_config.sh
executable file
·76 lines (65 loc) · 2.8 KB
/
setup_config.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
#!/bin/bash
GREEN="\e[32m"
YELLOW="\e[93m"
NOCOLOR="\e[0m"
DIM_COLOR="\e[2m"
RED_COLOR="\e[31m"
config_key=mstream-config.toml
if [ -f ${config_key} ]
then
read -p "$(printf "Configuration file ${YELLOW}${config_key}${NOCOLOR} already exists! Overwrite config? [y/N]${NOCOLOR}") " overwrite_config
case ${overwrite_config} in
[yY])
echo -e $(printf "${GREEN}Overwriting ${YELLOW}${config_key}${NOCOLOR}")
cp ${config_key} ${config_key}.bak
;;
*)
echo -e $(printf "${GREEN}Exiting interactive config${NOCOLOR}")
exit 0;
;;
esac
fi
# Configure GCP project
read -p "$(printf "\n> ${YELLOW}Enter GCP Service Account Key Path${NOCOLOR}:") " gc_key_path
echo "gcp_service_account_key_path = \"${gc_key_path}\"" > ${config_key}
# Configure change stream connectors
stream_count=0
echo -e "\n"$(printf "${DIM_COLOR}Entering Interactive config${NOCOLOR}")
while :
do
if [ ! ${stream_count} -eq 0 ]
then
read -p "$(printf "> ${YELLOW}Add another stream configuration? [y/n]${NOCOLOR}") " default_config
else
default_config=y
fi
case ${default_config} in
[nN])
echo -e $(printf "${GREEN}Exiting interactive config${NOCOLOR}")
break
;;
*)
read -p "$(printf "> ${YELLOW}Enter stream name":${NOCOLOR}) " connector_name
read -p "$(printf "> ${YELLOW}Enter db connection string":${NOCOLOR}) " db_connection
read -p "$(printf "> ${YELLOW}Enter db name":${NOCOLOR}) " db_name
read -p "$(printf "> ${YELLOW}Enter db collection":${NOCOLOR}) " db_collection
read -p "$(printf "> ${YELLOW}Enter pubsub schema provider (gcp, mongodb)":${NOCOLOR}) " schema_provider_name
read -p "$(printf "> ${YELLOW}Enter pubsub schema id":${NOCOLOR}) " schema_id
read -p "$(printf "> ${YELLOW}Enter pubsub topic":${NOCOLOR}) " pubsub_topic
echo -e $(printf "${GREEN}Adding ${YELLOW}${connector_name}${GREEN} to ${YELLOW}${config_key}${GREEN}${NOCOLOR}")
echo -e "\n[[connectors]]" >> ${config_key}
echo "name = \"${connector_name}\"" >> ${config_key}
echo "db_connection = \"${db_connection}\"" >> ${config_key}
echo "db_name = \"${db_name}\"" >> ${config_key}
echo "db_collection = \"${db_collection}\"" >> ${config_key}
echo "schema = { provider = \"${schema_provider_name}\", id = \"${schema_id}\" }" >> ${config_key}
echo "topic = \"${pubsub_topic}\"" >> ${config_key}
stream_count=$((stream_count+1))
esac
done
if [ ! -f ${config_key} ]
then
echo -e $(printf "${RED_COLOR}Error: configuration file ${YELLOW}${config_key}${RED_COLOR} does not exist!${NOCOLOR}")
exit 1;
fi
# rm ${config_key}.bak