forked from Restream/reindexer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependencies.sh
executable file
·244 lines (224 loc) · 7.83 KB
/
dependencies.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
#!/bin/sh
# NO COLOR
NC='\033[0m'
# COLORS
RED='\033[0;31m'
GREEN='\033[0;32m'
LBLUE='\033[01;34m'
# BOLD COLORS
RED_BOLD='\033[0;31;1m'
GREEN_BOLD='\033[0;32;1m'
LBLUE_BOLD='\033[01;34;1m'
YELLOW_BOLD='\033[0;33;1m'
success_msg() {
printf "${GREEN_BOLD}[ OK ] ${NC}$1\n"
}
info_msg() {
printf "${LBLUE_BOLD}[ INFO ] ${NC}$1\n"
}
warning_msg() {
printf "${YELLOW_BOLD}[ WARNING ] ${NC}$1\n"
}
error_msg() {
printf "${RED_BOLD}[ ERROR ] ${NC}$1\n"
}
# declare dependencies arrays for systems
osx_deps="gperftools leveldb snappy cmake git"
centos8_debs="gcc-c++ make snappy-devel leveldb-devel gperftools-devel findutils curl tar unzip rpm-build rpmdevtools git"
centos7_debs="gcc-c++ make snappy-devel leveldb-devel gperftools-devel findutils curl tar unzip rpm-build rpmdevtools git"
centos6_debs="centos-release-scl devtoolset-7-gcc devtoolset-7-gcc-c++ make snappy-devel leveldb-devel gperftools-devel findutils curl tar unzip rpm-build git"
debian_debs="build-essential g++ libgoogle-perftools-dev libsnappy-dev libleveldb-dev make curl unzip git"
alpine_apks="g++ snappy-dev leveldb-dev libexecinfo-dev make curl cmake unzip git"
cmake_installed () {
info_msg "Check for installed cmake ..... "
cmake_version=$(cmake --version 2>/dev/null | grep -oE '3\.[0-9]+\.[0-9]+')
if [ -n "$cmake_version" ]; then
info_msg "Cmake with comaptable version $cmake_version found"
return
fi
return 1
}
install_cmake_linux () {
info_msg "Installing 'cmake' package ....."
case `uname -m` in
x86_64)
curl -L https://github.com/Kitware/CMake/releases/download/v3.11.3/cmake-3.11.3-Linux-x86_64.tar.gz 2>/dev/null | tar xzv --strip-components=1 -C /usr/local/ >/dev/null 2>&1
;;
i386)
curl -L https://github.com/Kitware/CMake/releases/download/v3.6.3/cmake-3.6.3-Linux-i386.tar.gz 2>/dev/null | tar xzv --strip-components=1 -C /usr/local/ >/dev/null 2>&1
;;
*)
warning_msg "Fallback to system 'cmake' package. Be sure, cmake version must be at least 3.0....."
apt-get -y install cmake >/dev/null 2>&1
;;
esac
if [ $? -ne 0 ]; then
error_msg "Error install 'cmake'" && return 1
fi
success_msg "Package 'cmake' was installed successfully." && return
}
install_osx() {
for pkg in $osx_deps
do
if brew list -1 | grep -q "^${pkg}\$"; then
info_msg "Package $pkg already installed. Skip ....."
else
info_msg "Installing $pkg package ....."
brew install ${pkg} 2>&1 | grep -i -E "error|warning" | tr '[:upper:]' '[:lower:]' >/tmp/.status
IFS=":" read STATUS MESSAGE < /tmp/.status
if [ -n "$STATUS" ]; then
print_result="${STATUS}_msg \"$MESSAGE\""
eval "${print_result}"
return 1
else
success_msg "Package '$pkg' was installed successfully."
fi
fi
done
return
}
install_centos8() {
yum install -y epel-release >/dev/null 2>&1 || true
yum install -y http://rpms.remirepo.net/enterprise/remi-release-8.rpm >/dev/null 2>&1 || true
yum install -y dnf-plugins-core 2>&1 || true
yum config-manager --set-enabled PowerTools 2>&1 || true
for pkg in ${centos8_debs}
do
if rpm -qa | grep -qw ${pkg} ; then
info_msg "Package '$pkg' already installed. Skip ....."
else
info_msg "Installing '$pkg' package ....."
yum install -y ${pkg} > /dev/null 2>&1
if [ $? -eq 0 ]; then
success_msg "Package '$pkg' was installed successfully."
else
error_msg "Could not install '$pkg' package. Try 'yum update && yum install $pkg'" && return 1
fi
fi
done
cmake_installed || install_cmake_linux
return $?
}
install_centos7() {
yum install -y epel-release >/dev/null 2>&1 || true
for pkg in ${centos7_debs}
do
if rpm -qa | grep -qw ${pkg} ; then
info_msg "Package '$pkg' already installed. Skip ....."
else
info_msg "Installing '$pkg' package ....."
yum install -y ${pkg} > /dev/null 2>&1
if [ $? -eq 0 ]; then
success_msg "Package '$pkg' was installed successfully."
else
error_msg "Could not install '$pkg' package. Try 'yum update && yum install $pkg'" && return 1
fi
fi
done
cmake_installed || install_cmake_linux
return $?
}
install_centos6() {
yum install -y epel-release >/dev/null 2>&1 || true
for pkg in ${centos6_debs}
do
if rpm -qa | grep -qw ${pkg}; then
info_msg "Package '$pkg' already installed. Skip ....."
else
info_msg "Installing '$pkg' package ....."
yum install -y ${pkg} >/dev/null 2>&1
if [ $? -eq 0 ]; then
success_msg "Package '$pkg' was installed successfully."
else
error_msg "Could not install '$pkg' package. Try 'yum update && yum install $pkg'" && return 1
fi
fi
done
source scl_source enable devtoolset-7
cmake_installed || install_cmake_linux
return $?
}
install_debian() {
info_msg "Updating packages....."
apt-get -y update >/dev/null 2>&1
for pkg in ${debian_debs}
do
dpkg -s ${pkg} >/dev/null 2>&1
if [ $? -eq 0 ]; then
info_msg "Package '$pkg' already installed. Skip ....."
else
info_msg "Installing '$pkg' package ....."
apt-get install -y ${pkg} >/dev/null 2>&1
if [ $? -eq 0 ]; then
success_msg "Package '$pkg' was installed successfully."
else
error_msg "Could not install '$pkg' package. Try 'apt-get update && apt-get install $pkg'" && return 1
fi
fi
done
cmake_installed || install_cmake_linux
return $?
}
install_alpine() {
info_msg "Updating packages....."
apk update >/dev/null 2>&1
for pkg in ${alpine_apks}
do
local info=`apk info | grep ${pkg}`
if [ _"$info" != _"" ]; then
info_msg "Package '$pkg' already installed. Skip ....."
else
info_msg "Installing '$pkg' package ....."
apk add ${pkg} >/dev/null 2>&1
if [ $? -eq 0 ]; then
success_msg "Package '$pkg' was installed successfully."
else
error_msg "Could not install '$pkg' package. Try 'apt-get update && apt-get install $pkg'" && return 1
fi
fi
done
return $?
}
detect_installer() {
if [ -f /etc/os-release ]; then
. /etc/os-release
# It is "ubuntu/debian" ?
local OS=$(echo ${ID} | tr '[:upper:]' '[:lower:]')
if [ "$OS" = "ubuntu" -o "$OS" = "debian" -o "$OS" = "linuxmint" ]; then
OS_TYPE="debian" && return
elif [ "$OS" = "centos" -o "$OS" = "fedora" -o "$OS" = "rhel" ]; then
if [ "$VERSION_ID" = "8" ]; then
OS_TYPE="centos8"
else
OS_TYPE="centos7"
fi
return
elif [ "$OS" = "alpine" ]; then
OS_TYPE="alpine" && return
else
return 1
fi
elif [ -f /etc/centos-release ]; then
if [ $(cat /etc/centos-release | cut -d" " -f3 | cut -d "." -f1) -eq 6 ]; then
OS_TYPE="centos6" && return
else
return 1
fi
elif [ "$(uname)" == "Darwin" ]; then
OS_TYPE="osx" && return
else
return 1
fi
}
detect_installer
if [ $? -eq 0 ]; then
INSTALL="install_${OS_TYPE}"
eval "$INSTALL"
if [ $? -eq 0 ]; then
success_msg "All dependencies installed."; exit 0
else
error_msg "Dependencies installation was failed."; exit 1
fi
else
error_msg "Unsupported OS type."
fi