-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinstall.gitpod.sh
246 lines (204 loc) · 6.45 KB
/
install.gitpod.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
#!/bin/bash
set -e
# Function to check the status of a service in Docker Compose
get_status() {
local service_name="$1"
# ANSI color escape sequences
local green="\033[0;32m"
local red="\033[0;31m"
local reset="\033[0m"
# Check if Docker Compose file exists
if [ ! -f "docker-compose.yml" ]; then
echo -e "${red}Docker Compose file 'docker-compose.yml' not found.${reset}"
return 1
fi
# Check if service is running
local status=$(docker-compose ps -q "$service_name")
if [ -n "$status" ]; then
echo -e "${green}Container '$service_name' is running.${reset}"
else
echo -e "${red}Container '$service_name' is not running.${reset}"
exit 1
fi
}
# Define versions
INSTALL_NODE_VER=16.14.0
INSTALL_NVM_VER=0.39.1
INSTALL_YARN_VER=1.22.17
echo "==> Ensuring .bashrc exists and is writable"
touch ~/.bashrc
echo "==> Installing Node Version Manager (NVM) version $INSTALL_NVM_VER"
# Remove NVM if already installed
rm -rf ~/.nvm
# Unset exported variable
export NVM_DIR=
# Install NVM
curl -o- https://raw.githubusercontent.com/creationix/nvm/v$INSTALL_NVM_VER/install.sh | bash
# Make NVM command available in the terminal
source ~/.nvm/nvm.sh
echo "==> Installing Node.js version $INSTALL_NODE_VER"
nvm install $INSTALL_NODE_VER
echo "==> Setting this version as the system default"
nvm alias default $INSTALL_NODE_VER
nvm use default
echo "==> Installing Yarn package manager version $INSTALL_YARN_VER"
rm -rf ~/.yarn
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version $INSTALL_YARN_VER
echo "==> Adding Yarn to the environment path"
# Yarn configurations
export PATH="$HOME/.yarn/bin:$PATH"
yarn config set prefix ~/.yarn -g
echo "==> Checking versions"
nvm --version
node --version
npm --version
yarn --version
# Print welcome message
echo ""
echo ""
echo ""
echo "****************************************************"
echo "Welcome to the installation script for UCI"
echo "****************************************************"
echo ""
echo ""
echo ""
echo "Let's first start by exporting keys required for installation"
echo ""
echo "Please provide the Encryption Key (If you don't have it, please contact the administrator)"
read -r ENCRYPTION_KEY
if [ -z "$ENCRYPTION_KEY" ]; then
echo "ENCRYPTION_KEY is empty. Please contact the administrator."
exit 0
fi
echo "Please provide the Netcore WhatsApp Auth Token (If you don't have it, press Enter to continue)"
read -r NETCORE_WHATSAPP_AUTH_TOKEN
echo "Please provide the Netcore WhatsApp Source (If you don't have it, press Enter to continue)"
read -r NETCORE_WHATSAPP_SOURCE
echo "Please provide the Netcore WhatsApp URI (If you don't have it, press Enter to continue)"
read -r NETCORE_WHATSAPP_URI
echo ""
# Export environment variables
sed -i "s|NETCORE_WHATSAPP_AUTH_TOKEN=.*|NETCORE_WHATSAPP_AUTH_TOKEN=${NETCORE_WHATSAPP_AUTH_TOKEN}|g" .env
sed -i "s|NETCORE_WHATSAPP_SOURCE=.*|NETCORE_WHATSAPP_SOURCE=${NETCORE_WHATSAPP_SOURCE}|g" .env
sed -i "s|NETCORE_WHATSAPP_URI=.*|NETCORE_WHATSAPP_URI=${NETCORE_WHATSAPP_URI}|g" .env
sed -i "s|ENCRYPTION_KEY=.*|ENCRYPTION_KEY=${ENCRYPTION_KEY}|g" .env
if [ -x "$(command -v docker)" ]; then
echo "Docker is already available"
echo ""
else
echo "Installing Docker"
echo ""
# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
fi
if [ -x "$(command -v docker)" ]; then
echo "Docker Compose is already available"
echo ""
else
echo "Installing docker-compose"
echo ""
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
fi
# Clone repo for ODK
if [[ ! -e odk-aggregate ]]; then
mkdir odk-aggregate
cd odk-aggregate
echo "Cloning project from git odk"
git clone -b release-4.4.0 https://github.com/samagra-comms/odk.git
cd ..
fi
# Clone repo for web-channel
if [[ ! -e uci-web-channel ]]; then
# UCI Web Channel
git clone https://github.com/samagra-comms/uci-web-channel.git
cp .env-uci-web-channel uci-web-channel/.env
cd uci-web-channel
# Replace transport socket URL in .env file
uciWebChannelBaseURL=${GITPOD_WORKSPACE_URL:-default_value}
uciWebChannelBaseURL="REACT_APP_TRANSPORT_SOCKET_URL=wss://3005-${uciWebChannelBaseURL:8}"
sed -i "3s|^.*$|$uciWebChannelBaseURL|" .env
yarn install
yarn build
cd ..
else
cp .env-uci-web-channel uci-web-channel/.env
cd uci-web-channel
# Replace transport socket URL in .env file
uciWebChannelBaseURL=${GITPOD_WORKSPACE_URL:-default_value}
uciWebChannelBaseURL="REACT_APP_TRANSPORT_SOCKET_URL=wss://3005-${uciWebChannelBaseURL:8}"
sed -i "3s|^.*$|$uciWebChannelBaseURL|" .env
yarn install
yarn build
cd ..
fi
# Clone repo for uci-admin
if [[ ! -e uci-admin ]]; then
# UCI Admin
git clone https://github.com/samagra-comms/uci-admin
cp .env-uci-admin uci-admin/.env
cd uci-admin
# Replace UCI API URL in .env file
uciApiBaseURL=${GITPOD_WORKSPACE_URL:-default_value}
uciApiBaseURL="NG_APP_url='http://9999:${uciApiBaseURL:8}'"
sed -i "1s|^.*$|$uciApiBaseURL|" .env
npm i
npm run build --configuration production
cd ..
else
if [[ -e .env-uci-admin ]]; then
cp .env-uci-admin uci-admin/.env
fi
cd uci-admin
# Replace UCI API URL in .env file
uciApiBaseURL=${GITPOD_WORKSPACE_URL:-default_value}
uciApiBaseURL="NG_APP_url='http://9999:${uciApiBaseURL:8}'"
sed -i "1s|^.*$|$uciApiBaseURL|" .env
# Remove existing node modules
rm -rf node_modules
rm -rf build
npm i
npm run build --configuration production
cd ..
fi
# Running Docker-Compose
# FusionAuth components
echo ""
echo ""
echo "Building elastic search and fusionauth container, may take a few minutes"
echo ""
echo ""
docker-compose up -d fa-search fusionauth fa-db
get_status fa-search
get_status fusionauth
get_status fa-db
# Kafka Components
echo ""
echo ""
echo "Setting up Kafka components, may take a few minutes"
echo ""
echo ""
docker-compose up -d cass kafka schema-registry zookeeper connect
get_status cass
get_status kafka
get_status schema-registry
get_status zookeeper
get_status connect
# ODK Components
echo ""
echo ""
echo "Setting up ODK components, may take a few minutes"
echo ""
echo ""
docker-compose up -d aggregate-db wait_for_db aggregate-server
get_status aggregate-db
get_status wait_for_db
get_status aggregate-server
echo ""
echo ""
echo "Resolving dependencies"
echo ""
echo ""
docker-compose up -d
echo "All services are up"