-
Notifications
You must be signed in to change notification settings - Fork 42
/
run-me-first.sh
executable file
·268 lines (214 loc) · 9.52 KB
/
run-me-first.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/bash
RED='\033[1;31m'
GREEN='\033[0;32m'
NOCOLOR='\033[0m'
# Check curl is installed
if ! [ -x "$(command -v curl)" ]; then
echo -e "${RED}Error: curl is not installed." >&2
exit 1
fi
# Check docker is installed
if ! [ -x "$(command -v docker)" ]; then
echo -e "${RED}Error: docker is not installed." >&2
exit 1
fi
# Check jq is installed
if ! [ -x "$(command -v jq)" ]; then
echo -e "${RED}Error: jq is not installed." >&2
exit 1
fi
source .env
echo -e "
${GREEN}Step 1.${NOCOLOR}
Updating configuration example files can be done from https://github.com/edumeet components repository."
# Update example configurations
# edumeet-client
#curl -s "https://raw.githubusercontent.com/${REPOSITORY}/${EDUMEET_CLIENT}/${BRANCH_CLIENT}/public/config/config.example.js" -o "configs/app/config.example.js"
#echo -e "Updating configuration example files from upstream ${EDUMEET_CLIENT}/${BRANCH_CLIENT} repository.
#"
## edumeet-room-server
#curl -s "https://raw.githubusercontent.com/${REPOSITORY}/${EDUMEET_SERVER}/${BRANCH_SERVER}/config/config.example.json" -o "configs/server/config.example.json"
for confDir in {app,nginx,server,mgmt,mgmt-client}
do
for exConfFile in $(echo ./configs/${confDir}/*example*)
do
confFile=${exConfFile/.example/}
if [ -f ${confFile} ]
then
echo -e "Config ${confFile} exist, ${RED}skipping...${NOCOLOR}"
rm ${exConfFile} &>/dev/null
elif [ -f ${exConfFile} ]
then
echo -e "Creating ${confFile} from ${exConfFile}. ${RED}Please check configuration parameters!${NOCOLOR}"
mv ${exConfFile} ${confFile} &>/dev/null
fi
done
done
# Update TAG version
# VERSION=$(curl -s "https://raw.githubusercontent.com/edumeet/${EDUMEET_SERVER}/${BRANCH_SERVER}/package.json" | grep version | sed -e 's/^.*:\ \"\(.*\)\",/\1/')
while [ -z "$MAIN_DOMAIN" ] || [ $MAIN_DOMAIN == "edumeet.example.com" ]; do
read -e -p "
UPDATE DOMAIN NAME (edumeet.example.com): " MAIN_DOMAIN
done
sed -i "s/^.*MAIN_DOMAIN=.*$/MAIN_DOMAIN=${MAIN_DOMAIN}/" .env
while [ -z "$MEDIA_DOMAIN" ] || [ $MEDIA_DOMAIN == "edumeet.example.com" ]; do
read -e -p "
UPDATE MEDIA_DOMAIN (media.edumeet.example.com): " MEDIA_DOMAIN
done
sed -i "s/^.*MEDIA_DOMAIN=.*$/MEDIA_DOMAIN=${MEDIA_DOMAIN}/" .env
while [ -z "$MANAGEMENT_USERNAME" ] || [ $MANAGEMENT_USERNAME == "edumeet-admin@localhost" ]; do
read -e -p "
UPDATE management-server admin user in mail format (edumeet-admin@localhost): " MANAGEMENT_USERNAME
done
while [ -z $MANAGEMENT_PASSWORD ] || [ $MANAGEMENT_PASSWORD == "supersecret" ]; do
RECOMMENDED_PW=`tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo ''`
read -e -p "
UPDATE management-server admin user (supersecret ->reccommended: ${RECOMMENDED_PW}): " MANAGEMENT_PASSWORD
if [ -z $MANAGEMENT_PASSWORD ]
then
MANAGEMENT_PASSWORD=$RECOMMENDED_PW
fi
done
sed -i -e "s/edumeet-admin@localhost/${MANAGEMENT_USERNAME}/g" configs/_mgmt_pwchange/202310300000000_migrate.ts
sed -i -e "s/supersecret2/${MANAGEMENT_PASSWORD}/g" configs/_mgmt_pwchange/202310300000000_migrate.ts
sed -i "s/^.*MANAGEMENT_USERNAME=.*$/MANAGEMENT_USERNAME=${MANAGEMENT_USERNAME}/" .env
sed -i "s/^.*MANAGEMENT_PASSWORD=.*$/MANAGEMENT_PASSWORD=${MANAGEMENT_PASSWORD}/" .env
while [ -z "$KEYCLOAK_ADMIN" ] || [ $KEYCLOAK_ADMIN == "edumeet" ]; do
read -e -p "
UPDATE KEYCLOAK_ADMIN user: " KEYCLOAK_ADMIN
done
while [ -z $KEYCLOAK_ADMIN_PASSWORD ] || [ $KEYCLOAK_ADMIN_PASSWORD == "edumeet" ]; do
RECOMMENDED_PW=`tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo ''`
read -e -p "
UPDATE KEYCLOAK_ADMIN_PASSWORD (edumeet ->reccommended: ${RECOMMENDED_PW}): " KEYCLOAK_ADMIN_PASSWORD
if [ -z $KEYCLOAK_ADMIN_PASSWORD ]
then
KEYCLOAK_ADMIN_PASSWORD=$RECOMMENDED_PW
fi
done
sed -i "s/^.*KEYCLOAK_ADMIN=.*$/KEYCLOAK_ADMIN=${KEYCLOAK_ADMIN}/" .env
sed -i "s/^.*KEYCLOAK_ADMIN_PASSWORD=.*$/KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_ADMIN_PASSWORD}/" .env
regex="^(([-a-zA-Z0-9\!#\$%\&\'*+/=?^_\`{\|}~]+|(\"([][,:;<>\&@a-zA-Z0-9\!#\$%\&\'*+/=?^_\`{\|}~-]|(\\\\[\\ \"]))+\"))\.)*([-a-zA-Z0-9\!#\$%\&\'*+/=?^_\`{\|}~]+|(\"([][,:;<>\&@a-zA-Z0-9\!#\$%\&\'*+/=?^_\`{\|}~-]|(\\\\[\\ \"]))+\"))@\w((-|\w)*\w)*\.(\w((-|\w)*\w)*\.)*\w{2,4}$"
#while [ -z "$PGADMIN_DEFAULT_EMAIL" ] || [ $PGADMIN_DEFAULT_EMAIL == "[email protected]" ] || [[ ! "$PGADMIN_DEFAULT_EMAIL" =~ $regex ]]; do
# read -e -p "
#UPDATE PGADMIN_DEFAULT_EMAIL user: " PGADMIN_DEFAULT_EMAIL
#done
#while [ -z $PGADMIN_DEFAULT_PASSWORD ] || [ $PGADMIN_DEFAULT_PASSWORD == "edumeet" ]; do
# RECOMMENDED_PW=`tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo ''`
# read -e -p "
#UPDATE PGADMIN_DEFAULT_PASSWORD (supersecret ->reccommended: ${RECOMMENDED_PW}): " PGADMIN_DEFAULT_PASSWORD
# if [ -z $PGADMIN_DEFAULT_PASSWORD ]
# then
# PGADMIN_DEFAULT_PASSWORD=$RECOMMENDED_PW
# fi
#done
#sed -i "s/^.*PGADMIN_DEFAULT_EMAIL=.*$/PGADMIN_DEFAULT_EMAIL=${PGADMIN_DEFAULT_EMAIL}/" .env
#sed -i "s/^.*PGADMIN_DEFAULT_PASSWORD=.*$/PGADMIN_DEFAULT_PASSWORD=${PGADMIN_DEFAULT_PASSWORD}/" .env
echo -e "
${GREEN}Step 2.${NOCOLOR}
Updating TAG version in .env file extracted from edumeet version"
#VERSION=4.x-$(date '+%Y%m%d')-nightly
VERSION=$(curl -L --fail -s "https://hub.docker.com/v2/repositories/${REPOSITORY}/${EDUMEET_CLIENT}/tags/?page_size=1000&name=stable" | jq '.results | .[] | .name' -r | sed 's/latest//' | sort --version-sort | tail -n 1 | grep 4)
sed -i "s/^.*TAG.*$/TAG=${VERSION}/" .env
LISTEN_IP=$(hostname -I | awk '{print $1}')
sed -i "s/^.*LISTEN_IP.*$/LISTEN_IP=${LISTEN_IP}/" .env
EXTERNAL_IP=$(hostname -I | awk '{print $1}')
sed -i "s/^.*EXTERNAL_IP.*$/EXTERNAL_IP=${EXTERNAL_IP}/" .env
echo -e "Current tag: ${RED}${VERSION}${NOCOLOR}
IP set to : ${RED}${LISTEN_IP}${NOCOLOR}
External IP set to : ${RED}${EXTERNAL_IP}${NOCOLOR}
${GREEN}Step 3.${NOCOLOR}
To get latest images run the following or build it with running \"docker-compose up\":
${RED}
docker pull edumeet/${EDUMEET_MN_SERVER}:${VERSION}
docker pull edumeet/${EDUMEET_CLIENT}:${VERSION}
docker pull edumeet/${EDUMEET_SERVER}:${VERSION}
docker pull edumeet/${EDUMEET_MGMT_SERVER}:${VERSION}
docker pull edumeet/${EDUMEET_MGMT_CLIENT}:${VERSION}
"
ACK=$(ack edumeet.example.com --ignore-file=is:README.md --ignore-file=is:run-me-first.sh --ignore-file=is:gen_cert.sh)
ACK_LOCALHOST=$(ack localhost --ignore-file=is:README.md --ignore-file=is:run-me-first.sh --ignore-file=is:.env --ignore-file=is:mgmt.sh --ignore-file=is:gen_cert.sh)
echo -e "
${GREEN}Step 4.${NOCOLOR}
Change configs to your desired configuration.
By default (single domain setup):
- configs/server/config.json
'tls' options shoud be removed when running behind proxy
'host' shoud be 'http://mgmt:3030',
'hostname' shoud be your IP: '${LISTEN_IP}',
- configs/app/config.js
managementUrl shoud be domain name 'https://${MAIN_DOMAIN}/mgmt'
Change domain in the following files:
${ACK}
${ACK_LOCALHOST}
${GREEN}Step 5.${NOCOLOR}
DONE!
*Dont forget to update cert files.
${RED}Please see README file for further configuration instructions.${NOCOLOR}
"
# APP/ CLIENT
if grep -Fq 'localhost' configs/app/config.js
then
read -e -p "
Do you want to set managementUrl to https://${MAIN_DOMAIN}/mgmt from .env file in app/config.js (recommended)? [Y/n] " YN
if [[ $YN == "y" || $YN == "Y" || $YN == "" ]]
then
sed -i "/"managementUrl"/c managementUrl: \"https://${MAIN_DOMAIN}/mgmt\"," configs/app/config.js
echo "done"
fi
else
echo "room-client OK"
fi
if grep -Fq 'edumeet.example.com' configs/app/config.js
then
read -e -p "
Do you want to set managementUrl to https://${MAIN_DOMAIN}/mgmt from .env file in app/config.js (recommended)? [Y/n] " YN
if [[ $YN == "y" || $YN == "Y" || $YN == "" ]]
then
sed -i "/"managementUrl"/c managementUrl: \"https://${MAIN_DOMAIN}/mgmt\"," configs/app/config.js
echo "done"
fi
else
echo "room-client OK"
fi
# MGMT-SERVER
if grep -Fq 'edumeet.example.com' configs/mgmt/default.json
then
read -e -p "
Do you want to replace edumeet.example.com domain in management-server config files to ${MAIN_DOMAIN} in mgmt/default.json (recommended)?[Y/n] " YN
if [[ $YN == "y" || $YN == "Y" || $YN == "" ]]
then
sed -i -e "s/edumeet.example.com/${MAIN_DOMAIN}/g" configs/mgmt/default.json
echo "done"
fi
fi
# KEYCLOAK( auth )
if grep -Fq 'edumeet.example.com' configs/kc/dev.json
then
read -e -p "
Do you want to update Keycloak dev realm to your domain : ${MAIN_DOMAIN} from .env file in kc/dev.json (recommended)? [Y/n] " YN
if [[ $YN == "y" || $YN == "Y" || $YN == "" ]]
then
sed -i "/"adminUrl"/c \"adminUrl\": \"https://${MAIN_DOMAIN}/mgmt/*\"," configs/kc/dev.json
sed -i "/"edumeet.example.com"/c \"rootUrl\": \"https://${MAIN_DOMAIN}/\"," configs/kc/dev.json
echo "done"
fi
else
echo "keycloak dev realm OK"
fi
# MGMT-CLIENT
if grep -Fq 'edumeet.example.com' configs/mgmt-client/config.js
then
read -e -p "
Do you want to set up edumeet-management-client to https://${MAIN_DOMAIN}/cli from .env file in mgmt-client/config.js (recommended)? [Y/n] " YN
if [[ $YN == "y" || $YN == "Y" || $YN == "" ]]
then
sed -i "/"serverApiUrl"/c serverApiUrl: \"https://${MAIN_DOMAIN}/mgmt\"," configs/mgmt-client/config.js
sed -i "/"hostname"/c hostname: \"https://${MAIN_DOMAIN}\"," configs/mgmt-client/config.js
echo "done"
fi
else
echo "management-client OK"
fi
echo "If you want to generate cert(s) with Let's Encrypt run gen-cert.sh"
echo "You can start the application with gen-cert.sh or docker compose up"