forked from intelowlproject/IntelOwl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize.sh
executable file
·150 lines (134 loc) · 4.97 KB
/
initialize.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
#!/bin/bash
set -e
MINIMUM_DOCKER_VERSION=1.13.0
MINIMUM_DOCKER_COMPOSE_VERSION=1.23.2
MINIMUM_PYTHON_VERSION=3.6
# Function to compare 2 semver version
semantic_version_comp () {
if [[ $1 == $2 ]]; then
echo "equalTo"
return
fi
# Remove "v" prefix if present
ver1=$(echo $1 | sed 's/^v//')
ver2=$(echo $2 | sed 's/^v//')
# Convert version numbers to arrays
local IFS=.
local i ver1=($ver1) ver2=($ver2)
# Fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
ver1[i]=0
done
# Compare version numbers
for ((i=0; i<${#ver1[@]}; i++)); do
if [[ -z ${ver2[i]} ]]; then
# Fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]})); then
echo "greaterThan"
return
fi
if ((10#${ver1[i]} < 10#${ver2[i]})); then
echo "lessThan"
return
fi
done
# If we reach this point, the versions are equal
echo "equalTo"
}
echo "This script will check (and possibly guide you through) the installation of dependencies for IntelOwl!"
echo "CARE! This script is delivered AS IS and could not work correctly in every possible environment. It has been tested on Ubuntu 20.04. In the case you face any error, you should just follow the official documentation and do all the required operation manually."
# Check if docker is installed
if ! [ -x "$(command -v docker)" ]; then
echo 'Error: docker is not installed.' >&2
# Ask if user wants to install docker
read -p "Do you want to install docker? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
# Check if docker is installed
if ! [ -x "$(command -v docker)" ]; then
echo 'Error: Could not install docker.' >&2
exit 1
fi
else
echo 'You chose to do not install Docker. Exiting'
exit 1
fi
else
docker_version=$(docker version --format '{{.Server.Version}}')
if [[ $(semantic_version_comp "$docker_version" "$MINIMUM_DOCKER_VERSION") == "lessThan" ]]; then
echo "Error: Docker version is too old. Please upgrade to at least $MINIMUM_DOCKER_VERSION." >&2
exit 1
else
echo "Docker version $docker_version detected"
fi
fi
if [ "$(docker --help | grep -q 'compose')" == 0 ] && ! [ -x "$(command -v docker-compose)" ]; then
echo 'Error: docker-compose is not installed.' >&2
# Ask if user wants to install docker-compose
read -p "Do you want to install docker-compose? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Install docker-compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# Check if docker-compose is installed
if ! [ -x "$(command -v docker-compose)" ]; then
echo 'Error: Could not install docker-compose.' >&2
exit 1
fi
else
exit 1
fi
else
if docker --help | grep -q 'compose'; then
docker_compose_version="$(docker compose version | cut -d 'v' -f3)"
else
IFS=',' read -ra temp <<< "$(docker-compose --version)"
docker_compose_version=$(echo "${temp[0]}"| awk '{print $NF}')
fi
if [[ $(semantic_version_comp "$docker_compose_version" "$MINIMUM_DOCKER_COMPOSE_VERSION") == "lessThan" ]]; then
echo "Error: Docker-compose version is too old. Please upgrade to at least $MINIMUM_DOCKER_COMPOSE_VERSION." >&2
exit 1
else
echo "Docker-compose version $docker_compose_version detected"
fi
fi
# Check if python is installed
if ! [ -x "$(command -v python3)" ]; then
echo 'Error: Python3 is not installed. Please install it.' >&2
exit 1
else
python_version=$(python3 --version| awk '{print $NF}')
if [[ $(semantic_version_comp "$python_version" "$MINIMUM_PYTHON_VERSION") == "lessThan" ]]; then
echo "Error: Python3 version is too old. Please upgrade to at least $MINIMUM_PYTHON_VERSION." >&2
exit 1
else
echo "Python3 version $python_version detected"
fi
fi
if [ -d "venv" ]; then
echo "Found virtual environment \`venv\`"
else
echo "Creating virtual environment \`venv\`"
python3 -m venv venv
fi
echo "Activating virtual environment \`venv\`"
source venv/bin/activate
echo "Installing python dependencies using pip..."
#pip requires --user flag for gentoo
pip3 install -r requirements/pre-requirements.txt
echo "Python dependencies installed!"
echo "Adding Logrotate configuration to Systems logrotate"
cd ./docker/scripts
./install_logrotate.sh
echo "Added Logrotate configuration to Systems logrotate"
echo "Moving to root of the project"
cd -
echo "Looks like you're ready to go!"
echo "Now you can start IntelOwl by activating the virtual env with \`source venv/bin/activate\` running the start.py file (eg: \`sudo python3 start.py prod up\` for production environment)"