This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetYmlVars.sh
executable file
·166 lines (155 loc) · 6.23 KB
/
setYmlVars.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/bash
# Check if ~/docker-compose.yml exists
if [[ -z $(cat ~/docker-compose.yml 2>/dev/null) ]]; then
echo "You need to have the docker-compose.yml in your home folder"
exit 1
fi
echo "This script asks for all login credentials one by one."
echo "Please do not enter an empty string"
echo "SPO URL:"
read surl
if [[ -z "$surl" ]]; then
echo "No input detected! Please re-run this script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
surl="$(echo -e "${surl}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
echo "SPO Tenant:"
read stenant
if [[ -z "$stenant" ]]; then
echo "No input detected! Please re-run the script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
stenant="$(echo -e "${stenant}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
echo "SPO User:"
read suser
if [[ -z "$suser" ]]; then
echo "No input detected! Please re-run the script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
suser="$(echo -e "${suser}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
echo "SPO Password:"
read spwd
if [[ -z "$spwd" ]]; then
echo "No input detected! Please re-run the script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
spwd="$(echo -e "${spwd}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
echo "SPO Workspace ID:"
read swsid
if [[ -z "$swsid" ]]; then
echo "No input detected! Please re-run the script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
swsid="$(echo -e "${swsid}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
#echo "SPO Integration Name:"
#read sin
#if [[ -z "$sin" ]]; then
# echo "No input detected! Please re-run the script and do not enter an empty string."
# exit 1
#else
# # remove both leading and trailing spaces
# sin="$(echo -e "${sin}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
#fi
#echo "SPO Integration Location:"
#read sil
#if [[ -z "$sil" ]]; then
# echo "No input detected! Please re-run the script and do not enter an empty string."
# exit 1
#else
# # remove both leading and trailing spaces
# sil="$(echo -e "${sil}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
#fi
echo "Site Code:"
read sitecode
if [[ -z "$sitecode" ]]; then
echo "No input detected! Please re-run the script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
sitecode="$(echo -e "${sitecode}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
echo "Profile:"
read profile
if [[ -z "$profile" ]]; then
echo "No input detected! Please re-run the script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
profile="$(echo -e "${profile}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
echo "ElasticSearch User:"
read euser
if [[ -z "$euser" ]]; then
echo "No input detected! Please re-run the script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
euser="$(echo -e "${euser}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
echo "ElasticSearch Password:"
read epwd
if [[ -z "$epwd" ]]; then
echo "No input detected! Please re-run the script and do not enter an empty string."
exit 1
else
# remove both leading and trailing spaces
epwd="$(echo -e "${epwd}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
fi
echo ""
echo ""
echo "You entered the following credentials:"
echo -n "SPO URL: "
echo $surl
echo -n "SPO Tenant: "
echo $stenant
echo -n "SPO User: "
echo $suser
echo -n "SPO Password: "
echo $spwd
echo -n "SPO Workspace ID: "
echo $swsid
#echo -n "SPO Integration Name: "
#echo $sin
#echo -n "SPO Integration Location: "
#echo $sil
echo -n "Site Code: "
echo $sitecode
echo -n "Profile: "
echo $profile
echo -n "ElasticSearch User: "
echo $euser
echo -n "ElasticSearch Password: "
echo $epwd
echo ""
echo "If there is anything incorrect, please re-run this script."
echo ""
# Create new edit yml file
newymlfile=~/docker-compose-edit.yml
rm -f $newymlfile
cp ~/docker-compose.yml $newymlfile || { echo "Failed to create new YAML file!" ; exit 1; }
echo "A new YAML file was created"
# Put variables in place
sed -i 's,SPO_URL=<REPLACE>,SPO_URL='"$surl"',g' ~/docker-compose-edit.yml || { echo 'Failed to set SPO_URL variable in new YAML file!' ; exit 1; }
sed -i 's,SPO_TENANT=<REPLACE>,SPO_TENANT='"$stenant"',g' ~/docker-compose-edit.yml || { echo 'Failed to set SPO_TENANT variable in new YAML file!' ; exit 1; }
sed -i 's,SPO_USER=<REPLACE>,SPO_USER='"$suser"',g' ~/docker-compose-edit.yml || { echo 'Failed to set SPO_USER variable in new YAML file!' ; exit 1; }
sed -i 's,SPO_PASSWORD=<REPLACE>,SPO_PASSWORD='"$spwd"',g' ~/docker-compose-edit.yml || { echo 'Failed to set SPO_PASSWORD variable in new YAML file!' ; exit 1; }
sed -i 's,SPO_WORKSPACE_ID=<REPLACE>,SPO_WORKSPACE_ID='"$swsid"',g' ~/docker-compose-edit.yml || { echo 'Failed to set SPO_WORKSPACE_ID variable in new YAML file!' ; exit 1; }
#sed -i 's,INTEGRATION_NAME=<REPLACE>,INTEGRATION_NAME='"$sin"',g' ~/docker-compose-edit.yml || { echo 'Failed to set INTEGRATION_NAME variable in new YAML file!' ; exit 1; }
#sed -i 's,INTEGRATION_LOCATION=<REPLACE>,INTEGRATION_LOCATION='"$sil"',g' ~/docker-compose-edit.yml || { echo 'Failed to set INTEGRATION_LOCATION variable in new YAML file!' ; exit 1; }
sed -i 's,SITE_CODE=<REPLACE>,SITE_CODE='"$sitecode"',g' ~/docker-compose-edit.yml || { echo 'Failed to set SITE_CODE variable in new YAML file!' ; exit 1; }
sed -i 's,PROFILE=<REPLACE>,PROFILE='"$profile"',g' ~/docker-compose-edit.yml || { echo 'Failed to set PROFILE variable in new YAML file!' ; exit 1; }
sed -i 's,ELASTIC_SEARCH_USER=<REPLACE>,ELASTIC_SEARCH_USER='"$euser"',g' ~/docker-compose-edit.yml || { echo 'Failed to set ELASTIC_SEARCH_USER variable in new YAML file!' ; exit 1; }
sed -i 's,ELASTIC_SEARCH_PWD=<REPLACE>,ELASTIC_SEARCH_PWD='"$epwd"',g' ~/docker-compose-edit.yml || { echo 'Failed to set ELASTIC_SEARCH_PWD variable in new YAML file!' ; exit 1; }
echo "Variables were successfully changed in new YAML file"
echo "The new YAML file was written to $newymlfile"
echo "Done!"