This repository was archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_script.sh
executable file
·273 lines (213 loc) · 6.55 KB
/
install_script.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
265
266
267
268
269
270
271
272
273
#!/bin/bash
checkOSVersion () {
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) machine=Linux;;
Darwin*) machine=Mac;;
CYGWIN*) machine=Cygwin;;
MINGW*) machine=MinGw;;
*) machine="UNKNOWN:${unameOut}"
esac
OSVersion=${machine}
echo -e "Setting OS version as ${OSVersion}...\n"
return
}
checkSystemDependency () {
local dependency=$1
if [[ -n $($dependency --version) ]]
then
echo -e "`$dependency --version`"
else
echo "Cannot locate $dependency version. $dependency is required, exiting..."
exit 1
fi
return
}
checkVersionCompatibiity () {
local currentver="$($1 --version)"
local requiredver="$2"
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]
then
echo "$currentver is greater than or equal to $requiredver"
else
echo "Less than $requiredver"
echo "updgrade your docker-compose to at least $requiredver"
exit 1
fi
return
}
dockerBuildContainer () {
local projectLoc=$1
cd $projectLoc && docker-compose build
return
}
dockerRaiseContainer () {
local projectLoc=$1
cd $projectLoc && docker-compose up -d
return
}
cloneInRepo () {
local dir=$1
local repoURL=$2
$(cd $dir && git clone $repoURL)
return
}
checkoutBranch () {
local dir=$1
local branch=$2
cd $dir && git checkout $branch
return
}
npmInstall () {
local dir=$1
npm i --prefix $dir
return
}
meteorReset () {
local dir=$1
cd $dir && meteor reset
}
# install dir
installDirectory=$1
# system dependencies
dependencies=(
"docker"
"git"
"meteor"
"node"
"npm"
)
# dir loc of install script
scriptDirectory=$(dirname $0)
# running os version check
checkOSVersion
# TODO: create a verbose mode
if [[ "$2" == "verbose" ]]
then
echo -e "Running Verbose \n"
fi
# check for install directory specification
if [ -z "$1" ]
then
echo "You did not set an installtion directory"
read -p "Please set a location or use the default provided: " -ei "$HOME/developerlevel" installDirectory
echo "install directory: $installDirectory"
fi
# if there is no directory, make one
if [ -d $installDirectory ]
then
echo "Your installation directory is set to: $installDirectory"
else
echo "creating directory: $installDirectory"
$(mkdir $installDirectory)
echo "Your installation directory is set to: $installDirectory"
fi
# run dependency checks
echo -e "2. Running checks for dependencies...\n"
# checks for each dependency by checking its version
for DEP in "${dependencies[@]}"; do
echo -e "checking for $DEP..."
checkSystemDependency $DEP
done
echo -e "checking docker-compose version for compatibility..."
checkVersionCompatibiity "docker-compose" "1.18.0"
# TODO: create working checks for mac
if [ $OSVersion == "Linux" ]
then
if [[ $(systemctl is-active docker) == "inactive" ]]
then
echo "starting docker... "
$(sudo systemctl start docker)
echo -e "Docker Status: $(systemctl is-active docker)\n"
else
echo -e "Docker Status: $(systemctl is-active docker)\n"
fi
elif [ $OSVersion == "Mac" ]
then
if (! docker stats --no-stream ); then
# On Mac OS this would be the terminal command to launch Docker
open /Applications/Docker.app
#Wait until Docker daemon is running and has completed initialisation
while (! docker stats --no-stream ); do
# Docker takes a few seconds to initialize
echo "Waiting for Docker to launch..."
sleep 1
done
fi
else
echo "OS not supported for this script, exiting..."
exit 1
fi
# check if aarc directory exists
if [ -d "$installDirectory/aarc" ]
then
echo -e "aarc already exists...\n"
checkoutBranch "$installDirectory/aarc/" "feature/DevDocker"
AARC_DIR="$installDirectory/aarc"
else
echo "aarc is not in the specified installation directory. cloning into $installDirectory..."
cloneInRepo $installDirectory "https://github.com/paladinarcher/aarc.git"
checkoutBranch "$installDirectory/aarc/" "feature/DevDocker"
echo "adding variable.env file..."
$(cp "$(pwd)/variables.env" "$installDirectory/aarc/api/")
AARC_DIR="$installDirectory/aarc"
fi
# check if tsq directory exists
if [ -d "$installDirectory/TSQ-Microservice" ]
then
echo -e "tsq exists, skipping...\n"
TSQ_DIR="$installDirectory/TSQ-Microservice/"
else
echo "tsq is not in the specified work directory. cloning into $installDirectory..."
cloneInRepo $installDirectory "https://github.com/paladinarcher/TSQ-Microservice.git"
TSQ_DIR="$installDirectory/TSQ-Microservice/"
fi
# check if the padawan directory exists
if [ -d "$installDirectory/padawan" ]
then
echo -e "padawan already exists...\n"
checkoutBranch "$installDirectory/padawan/" "staging"
echo -e "installing padawan npm dependencies...\n"
meteor npm install --prefix "$installDirectory/padawan/"
PADAWAN_DIR="$installDirectory/padawan"
meteorReset $PADAWAN_DIR
echo ""
else
echo "padawan is not in the specified work directory. cloning into $installDirectory..."
cloneInRepo $installDirectory "https://github.com/paladinarcher/padawan.git"
checkoutBranch "$installDirectory/padawan/" "staging"
echo -e "installing padawan npm dependencies...\n"
meteor npm install --prefix "$installDirectory/padawan/"
PADAWAN_DIR="$installDirectory/padawan"
meteorReset $PADAWAN_DIR
echo ""
fi
echo ""
NPM_INSTALLS=( "$installDirectory/aarc/frontend" "$installDirectory/aarc/api" "$installDirectory/TSQ-Microservice")
echo -e "installing dependencies via npm...\n"
for install_dir in "${NPM_INSTALLS[@]}"; do
npmInstall $install_dir
echo ""
done
echo -e "starting TSQ...\n"
dockerRaiseContainer $TSQ_DIR
echo -e "\nbuilding aarc...\n"
dockerBuildContainer "$AARC_DIR/docker/aarc_dev"
echo -e "raising aarc...\n"
dockerRaiseContainer "$AARC_DIR/docker/aarc_dev"
echo -e "\nbuilding padawan app container...\n"
dockerBuildContainer "$PADAWAN_DIR/docker/dev/"
echo -e "\nraising padawan app container...\n"
dockerRaiseContainer "$PADAWAN_DIR/docker/dev/"
echo -e "\ninstalling meteor and starting padawan in the app container... \n\n"
printf "\nstarting up application container, this may take awhile..."
while [ $(docker logs dev_app_1 2>&1 | grep "App running at: http://localhost" -c -i) -lt 1 ];
do
printf "."
sleep 1s
done
echo -e "\n"
echo "application container started! navigate to http://localhost:3000"
echo "if you want to see what's going on in a container look at the logs with docker logs <container name>"
echo "you can follow a container with docker logs -f <container name>"
exit 0