forked from DIKSHA-NCTE/Ops-Tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
188 lines (173 loc) · 5.72 KB
/
setup.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
#!/bin/bash
home=$(pwd)
echo "Please enter the environment (development/production)"
read ENV
# Reading variables provided by the user
if [[ $ENV == 'development' ]] || [[ $ENV == 'production' ]]; then
echo "Starting environment configuration...\n\n"
echo "Enter host for the instance. eg: https://diksha.gov.in"
read BASE
echo "Enter API key for Ops Tool"
read API_KEY
echo "Enter KeyCloak Client ID for Ops Tool"
read RESOURCE
echo "Enter KeyCloak Client Secret for Ops Tool"
read SECRET
echo "Enter Course Exhaust Report api end point. eg: https://diksha.gov.in/api/exhaust-report"
read DATAEXHAUSTKONGAPIURL
echo "Enter Blob storage account client"
read BLOB_ACCOUNT
echo "Enter SAS token for Exhaust Reports folder"
read EXHAUSTREPORTSAS
echo "Enter SAS token for Broadcast Contents folder"
read BROADCASTCONTENTSAS
echo "Enter Custodian Organisation name for the instance"
read CUSTODIAN_ORG
echo "Enter Database User"
read DB_USER
echo "Enter Database Password"
read DB_PASSWORD
if [[ $ENV == 'production' ]]; then
echo "Enter host for Ops Tool Instance. eg: https://ops.diksha.gov.in"
read OPS_HOST
fi
# Configuring .env file
if [[ -z $BASE ]]; then
empty='true'
echo BASE="<Host for adopters instance>" > .env
echo KEYCLOCKBASE="<base url of keycloak server>" >> .env
else
echo BASE=$BASE'/' > .env
echo KEYCLOCKBASE=$BASE'/' >> .env
fi
if [[ -z $API_KEY ]]; then
empty='true'
echo API_KEY="Bearer <api key>" >> .env
else
echo API_KEY=Bearer $API_KEY >> .env
fi
if [[ -z $RESOURCE ]]; then
empty='true'
echo RESOURCE="<Ops Tool Keycloak Client ID>" >> .env
else
echo RESOURCE=$RESOURCE >> .env
fi
if [[ -z $SECRET ]]; then
empty='true'
echo SECRET="<Ops Tool Keycloak Client Secret>" >> .env
else
echo SECRET=$SECRET >> .env
fi
if [[ -z $DATAEXHAUSTKONGAPIURL ]]; then
empty='true'
echo DATAEXHAUSTKONGAPIURL="<Exhaust Report api url>" >> .env
else
echo DATAEXHAUSTKONGAPIURL=$DATAEXHAUSTKONGAPIURL >> .env
fi
if [[ -z $BLOB_ACCOUNT ]]; then
empty='true'
echo BLOB_ACCOUNT="<Blob Account Client>" >> .env
else
echo BLOB_ACCOUNT=$BLOB_ACCOUNT >> .env
fi
if [[ -z $EXHAUSTREPORTSAS ]]; then
empty='true'
echo EXHAUSTREPORTSAS="<SAS token for Exhaust Reports blob folder>" >> .env
else
echo EXHAUSTREPORTSAS=$EXHAUSTREPORTSAS >> .env
fi
if [[ -z $BROADCASTCONTENTSAS ]]; then
empty='true'
echo BROADCASTCONTENTSAS="<SAS token for Broadcast Contents blob folder>" >> .env
else
echo BROADCASTCONTENTSAS=$BROADCASTCONTENTSAS >> .env
fi
# Configuring client and server environment files
if [[ $ENV == 'development' ]]; then
echo 'export const environment = {
production: false,
PLAY_URL: "'${BASE}/play/content/'",
base : "'${BASE}/api/'",
key_base : "'${BASE}/'",
LOCALHOST :"http://localhost:3000/api/",
RESOURCE: "'${RESOURCE}'",
CUSTODIAN_ORG: "'${CUSTODIAN_ORG}'"
};' > Ops-Tool-Client/src/environments/environment.ts
echo '{
"database": {
"connectionLimit": 10,
"host": "localhost",
"user": "'${DB_USER}'",
"password": "'${DB_PASSWORD}'",
"database": "ETBPROCESS"
},
"server": {
"port": 3000
},
"keycloak": {
"auth_server_url": "'${BASE}/auth'",
"resource": "'${RESOURCE}'"
}
}' > Ops-Tool-Server/config/config.development.json
fi
if [[ $ENV == 'production' ]]; then
echo 'export const environment = {
production: true,
PLAY_URL: "'${BASE}/play/content/'",
base : "'${BASE}/api/'",
key_base : "'${BASE}/'",
LOCALHOST :"'${OPS_HOST}/api/'",
RESOURCE: "'${RESOURCE}'",
CUSTODIAN_ORG: "'${CUSTODIAN_ORG}'"
};' > Ops-Tool-Client/src/environments/environment.prod.ts
echo '{
"database": {
"connectionLimit": 10,
"host": "localhost",
"user": "'${DB_USER}'",
"password": "'${DB_PASSWORD}'",
"database": "ETBPROCESS"
},
"server": {
"port": 3000
},
"keycloak": {
"auth_server_url": "'${BASE}/auth'",
"resource": "'${RESOURCE}'"
}
}' > Ops-Tool-Server/config/config.production.json
fi
# Installing Dependencies
echo "Installing dependencies...\n\n"
cd $home/Ops-Tool-Client
npm install
cd $home/Ops-Tool-Server
npm install
# Creating Static Folders
echo "Creating static folders...\n\n"
cd $home/Ops-Tool-Server
mkdir -p uploads logs
cd uploads
mkdir -p course-reports csvOutput input self-signup-user-reports streamedOutput
cd $home
# Setting up Database with all the required tables and data
echo "Setting up database...\n\n"
mysqladmin create ETBPROCESS -u root -p$DB_PASSWORD;
mysql ETBPROCESS < $home/Ops-Tool-Server/db-scripts/ETBPROCESS.sql -u root -p$DB_PASSWORD;
mysql ETBPROCESS < $home/Ops-Tool-Server/db-scripts/constants.sql -u root -p$DB_PASSWORD;
mysql ETBPROCESS < $home/Ops-Tool-Server/db-scripts/modules.sql -u root -p$DB_PASSWORD;
# Configuring forms
if [[ -z $BASE ]] && [[ -z $API_KEY ]]; then
for file in $home/Ops-Tool-Server/config/forms/*
do
curl --location --request POST "'${BASE}'" \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer '${API_KEY}'' \
--data-raw "'$(<$file)'"
done
fi
echo "Ops Tool setup completed successfully!"
else
echo "Couldn't complete the setup as no/wrong environment was selected. Please, try again.\n\n"
sh ./setup.sh
fi