-
-
Notifications
You must be signed in to change notification settings - Fork 443
/
start
executable file
·356 lines (324 loc) · 11.3 KB
/
start
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#!/usr/bin/env bash
generic_version_regex="^[0-9]{1,2}\.[0-9]{1,2}.[0-9]{1,2}$"
version_regex="^[3-9]\.[0-9]{1,2}.[0-9]{1,2}$"
pycti_default_version="5.10.0"
# little trick for exact matching in arrays
declare -A env_arguments=(["prod"]=1 ["test"]=1 ["ci"]=1)
declare -A test_mode=(["test"]=1 ["ci"]=1)
declare -A cmd_arguments=(["build"]=1 ["up"]=1 ["start"]=1 ["restart"]=1 ["down"]=1 ["stop"]=1 ["kill"]=1 ["logs"]=1 ["ps"]=1)
declare -A path_mapping=(["default"]="docker/default.yml" ["postgres"]="docker/postgres.override.yml" ["rabbitmq"]="docker/rabbitmq.override.yml" ["test"]="docker/test.override.yml" ["ci"]="docker/ci.override.yml" ["custom"]="docker/custom.override.yml" ["traefik"]="docker/traefik.yml" ["traefik_prod"]="docker/traefik_prod.yml" ["traefik_local"]="docker/traefik_local.yml" ["multi_queue"]="docker/multi-queue.override.yml" ["test_multi_queue"]="docker/test.multi-queue.override.yml" ["flower"]="docker/flower.override.yml" ["test_flower"]="docker/test.flower.override.yml" ["elastic"]="docker/elasticsearch.override.yml" ["https"]="docker/https.override.yml" ["nfs"]="docker/nfs.override.yml" ["redis"]="docker/redis.override.yml" ["nginx_default"]="docker/nginx.override.yml")
print_synopsis () {
echo "SYNOPSIS"
echo -e " start <env> <command> [OPTIONS]"
echo -e " start -h|--help\n"
}
print_help () {
print_synopsis
echo "ARGUMENTS"
echo " <env> Environment for execution"
echo -e " <command> Command for docker compose\n"
echo "OPTIONS"
echo " --project_name <name> Specify project name."
echo " --version <value> Choose the version you would like to install"
echo " (>=3.0.0). Works only in 'prod' mode. Default"
echo " version is the most recently released."
echo " --all_analyzers Uses every integration."
echo " --tor_analyzers Uses the integrations/tor_analyzers/compose.yml"
echo " file."
echo " --malware_tools_analyzers Uses the integrations/malware_tools_analyzers/"
echo " compose.yml file."
echo " --cyberchef Uses the integrations/cyberchef/compose.yml"
echo " file."
echo " --pcap_analyzers Uses the integrations/pcap_analyzers/compose.yml"
echo " file."
echo " --multi_queue Uses the multiqueue.override.yml compose file."
echo " --nfs Uses the nfs.override.yml compose file."
echo " --traefik_prod Uses the traefik.yml and traefik_prod.yml compose file."
echo " --traefik_local Uses the traefik.yml and traefik_local.yml compose file."
echo " --use-external-database Do NOT use postgres.override.yml compose file."
echo " --use-external-redis Do NOT use redis.override.yml compose file."
echo " --rabbitmq Uses the rabbitmq.override.yml compose file."
echo " --flower Uses the flower.override.yml compose file."
echo " --custom Uses custom.override.yml to leverage your"
echo " customized configuration."
echo " --debug-build See more verbose output from the build."
echo " --elastic This spins up Elasticsearch and Kibana on your"
echo " machine (might need >=16GB of RAM)."
echo " --https This leverage the https.override.yml file that"
echo " can be used to host IntelOwl with HTTPS and your"
echo " own certificate."
echo " --pycti-version <value> The pycti version to choose. This must match the"
echo " OpenCTI server version you are connecting to."
echo " Default is ${pycti_default_version}."
}
check_parameters () {
if [[ $# == 1 && ( $1 == "--help" || $1 == "-h" ) ]]; then
print_help
exit 0
fi
if [[ $# -lt 2 ]]; then
echo "Error! Provide at least the environment and a command." >&2
print_synopsis
exit 2
fi
if ! [[ ${env_arguments["${1}"]} ]]; then
echo "Error! Illegal environment specified." >&2
exit 2
fi
if ! [[ ${cmd_arguments["${2}"]} ]]; then
echo "Error! Illegal command specified." >&2
exit 2
fi
env_argument=$1
cmd_argument=$2
}
set_defaults_values () {
project_name="intel_owl"
version=$current_version
export PYCTI_VERSION=$pycti_default_version
}
load_env () {
export "$(grep -v '^#' "$1")"
}
if ! docker compose version > /dev/null 2>&1; then
echo "Run ./initialize.sh to install Docker Compose 2"
fi
check_parameters "$@" && shift 2
load_env "docker/.env"
current_version=${REACT_APP_INTELOWL_VERSION/"v"/""}
docker_analyzers=("pcap_analyzers" "tor_analyzers" "malware_tools_analyzers" "cyberchef" "phoneinfoga")
for value in "${docker_analyzers[@]}"; do
path_mapping["${value}"]+="integrations/${value}/compose.yml"
path_mapping["${value}.test"]+="integrations/${value}/compose-tests.yml"
# cannot use a list as value of associative array. we have to use a string and convert dynamically
path_mapping["all_analyzers"]+="${path_mapping[${value}]} "
path_mapping["all_analyzers.test"]+="${path_mapping["${value}.test"]} "
done
if [[ ${test_mode["${env_argument}"]} ]]; then
is_test=true
test_appendix=".test"
# load relevant .env file
load_env "docker/.env.start.test"
else
is_test=false
test_appendix=""
fi
# parse arguments and put them in an associative array to better use them later
declare -A params
declare -A analyzers
project_name=""
set_defaults_values
while [[ $# -gt 0 ]]; do
case $1 in
--project_name)
project_name=$2
shift 2
;;
-v | --version)
if ! [[ $2 =~ $version_regex ]]; then
echo "Error! Wrong version format." >&2
exit 1
fi
version=$2
shift 2
;;
--all_analyzers)
analyzers["all_analyzers"]=true
shift 1
;;
--tor_analyzers)
analyzers["tor_analyzers"]=true
shift 1
;;
--malware_tools_analyzers)
analyzers["malware_tools_analyzers"]=true
shift 1
;;
--cyberchef)
analyzers["cyberchef"]=true
shift 1
;;
--pcap_analyzers)
analyzers["pcap_analyzers"]=true
shift 1
;;
--phoneinfoga)
analyzers["phoneinfoga"]=true
shift 1
;;
--multi_queue)
params["multi_queue"]=true
shift 1
;;
--nfs)
params["nfs"]=true
shift 1
;;
--use-external-database)
params["use_external_database"]=true
shift 1
;;
--use-external-redis)
params["use_external_redis"]=true
shift 1
;;
--rabbitmq)
params["rabbitmq"]=true
shift 1
;;
--sqs)
params["sqs"]=true
shift 1
;;
--flower)
params["flower"]=true
shift 1
;;
--custom)
params["custom"]=true
shift 1
;;
--debug-build)
debug_build=true
shift 1
;;
--elastic)
params["elastic"]=true
shift 1
;;
--pycti-version)
if ! [[ $2 =~ $generic_version_regex ]]; then
echo "Error! Wrong pycti version format." >&2
exit 1
fi
export PYCTI_VERSION=$2
shift 2
;;
--https)
params["https"]=true
shift 1
;;
--traefik_prod)
params["traefik_prod"]=true
shift 1
;;
--traefik_local)
params["traefik_local"]=true
shift 1
;;
-h | --help)
print_help
exit 0
;;
--) shift 1; break;; # explicit end of arguments
*)
echo "Error! Invalid option $1."
exit 1
;;
esac
done
# here all variables should be parsed and ready for use
cmd_py_version=("up" "build")
if [[ ( ! $env_argument == "test" || ! ${cmd_py_version[*]} =~ $cmd_argument ) && \
( $PYCTI_VERSION != "$pycti_default_version" ) ]]; then
echo "pycti_version options are valid only while running in" >&2
echo "'test' mode and while building a new image. This is because they can change" >&2
echo "the version of those library only during the build of a new Docker Image." >&2
exit 11
fi
# check if all_analyzers and other flags have been used
for value in "${docker_analyzers[@]}"; do
if [ "${analyzers["$value"]}" ]; then
docker_flags+=("${value}")
fi
done
if [ "${analyzers["all_analyzers"]}" ] && [ ${#docker_flags[@]} -ne 0 ]; then
echo "It is not possible to select both --all_analyzers and another docker container."
exit 1
fi
# default file
compose_files=("${path_mapping["default"]}")
if ! [ "${params["use_external_database"]}" ]; then
compose_files+=("${path_mapping["postgres"]}")
fi
if ! [ "${params["use_external_redis"]}" ]; then
compose_files+=("${path_mapping["redis"]}")
fi
if [ "${params["rabbitmq"]}" ]; then
compose_files+=("${path_mapping["rabbitmq"]}")
elif [ "${params["sqs"]}" ]; then
compose_files+=("${path_mapping["sqs"]}")
fi
if [ "$is_test" = true ]; then
compose_files+=("${path_mapping["$env_argument"]}")
fi
# Check for the traefik_prod or traefik_local argument and include traefik base compose
traefik_enabled=false
if [ "${params["traefik_prod"]}" ] || [ "${params["traefik_local"]}" ]; then
compose_files+=("${path_mapping["traefik"]}")
traefik_enabled=true
fi
# Add the default nginx configuration if traefik is not used
if [ "$traefik_enabled" = false ]; then
compose_files+=("${path_mapping["nginx_default"]}")
fi
# add all the other ones
for value in "${!params[@]}"; do
if [ "${params[$value]}" ]; then
compose_files+=("${path_mapping["$value"]}")
fi
done
# add all the test files
if [[ $env_argument == "test" ]]; then
test_values=("multi_queue" "flower")
for value in "${test_values[@]}"; do
if [ "${params["$value"]}" ]; then
compose_files+=("${path_mapping["test_$value"]}")
fi
done
fi
# add and parse analyzers
if [ "${analyzers["all_analyzers"]}" ]; then
IFS=', ' read -r -a all_analyzers_array <<< "${path_mapping["all_analyzers"]}"
for analyzer in "${all_analyzers_array[@]}" ; do
compose_files+=("${analyzer}")
done
if [ "$is_test" = true ]; then
IFS=', ' read -r -a all_analyzers_array_test <<< "${path_mapping["all_analyzers${test_appendix}"]}"
for analyzer in "${all_analyzers_array_test[@]}" ; do
compose_files+=("${analyzer}")
done
fi
else
# add the single analyzers compose files
if [ ${#docker_flags[@]} -ne 0 ]; then
for analyzer in "${docker_flags[@]}"; do
compose_files+=("${path_mapping["$analyzer"]}")
if [ "$is_test" = true ]; then
compose_files+=("${path_mapping["$analyzer$test_appendix"]}")
fi
done
fi
fi
if [[ $env_argument == "prod" && $version != "${current_version}" ]]; then
echo "Requested version ${version} is different from current version ${current_version}"
directory=$(git config --global --get safe.directory)
if ! [ $? ] || ! [[ "${directory}" == $(pwd) ]]; then
git config --global --add safe.directory "$(pwd)"
fi
git checkout "v${version}"
fi
if [ $debug_build ]; then
export BUILDKIT_PROGRESS="plain"
fi
export DOCKER_BUILDKIT=1
for value in "${compose_files[@]}" ; do
if [ -n "${value}" ]; then
to_run+=" -f $value"
fi
done
if grep "docker" <<< "$(groups)" > /dev/null 2>&1; then
docker compose --project-directory docker ${to_run[@]} -p "$project_name" "$cmd_argument" "$@"
else
sudo docker compose --project-directory docker ${to_run[@]} -p "$project_name" "$cmd_argument" "$@"
fi