This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
cmake.sh
executable file
·267 lines (251 loc) · 7.79 KB
/
cmake.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
#!/bin/bash
show_help() {
cat << EOF
Usage: ${0##*/} -n=[yes|no] -v
This program build Centreon-broker
-f|--force : force rebuild
-r|--release : Build on release mode
-fcr|--force-conan-rebuild : rebuild conan data
-h|--help : help
EOF
}
BUILD_TYPE=Debug
CONAN_REBUILD="0"
while IFS= read -r filename; do
if [[ $filename =~ / ]] ; then
if [ ! -d ~/.conan/data/"$filename" ] ; then
echo "The package '$filename' is missing"
CONAN_REBUILD=1
break
fi
fi
done < conanfile.txt
for i in "$@" ; do
case $i in
-f|--force)
force=1
shift
;;
-r|--release)
BUILD_TYPE="Release"
shift
;;
-fcr|--force-conan-rebuild)
CONAN_REBUILD="1"
;;
-h|--help)
show_help
exit 2
;;
*)
# unknown option
;;
esac
done
# Am I root?
my_id=$(id -u)
if [ -r /etc/centos-release ] ; then
maj="centos$(awk '{print $4}' /etc/centos-release | cut -f1 -d'.')"
v=$(cmake --version)
if [[ $v =~ "version 3" ]] ; then
cmake='cmake'
else
if rpm -q cmake3 ; then
cmake='cmake3'
elif [ "$maj" = "centos7" ] ; then
yum -y install epel-release cmake3
cmake='cmake3'
else
dnf -y install cmake
cmake='cmake'
fi
fi
if [[ ! -x /usr/bin/python3 ]] ; then
yum -y install python3
else
echo "python3 already installed"
fi
if ! rpm -q python3-pip ; then
yum -y install python3-pip
else
echo "pip3 already installed"
fi
good=$(gcc --version | awk '/gcc/ && ($3+0)>5.0{print 1}')
if [ ! "$good" ] ; then
yum -y install centos-release-scl
yum-config-manager --enable rhel-server-rhscl-7-rpms
yum -y install devtoolset-9
ln -s /usr/bin/cmake3 /usr/bin/cmake
source /opt/rh/devtoolset-9/enable
fi
if [ "$maj" = "centos7" ] ; then
curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos7-amd64/rpms/MariaDB-shared-10.5.8-1.el7.centos.x86_64.rpm --output MariaDB-shared-10.5.8-1.el7.centos.x86_64.rpm
curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos7-amd64/rpms/MariaDB-common-10.5.8-1.el7.centos.x86_64.rpm --output MariaDB-common-10.5.8-1.el7.centos.x86_64.rpm
curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos7-amd64/rpms/MariaDB-compat-10.5.8-1.el7.centos.x86_64.rpm --output MariaDB-compat-10.5.8-1.el7.centos.x86_64.rpm
yum install -y MariaDB*.rpm
else
curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos8-amd64/rpms/MariaDB-shared-10.5.8-1.el8.x86_64.rpm --output MariaDB-shared-10.5.8-1.el8.x86_64.rpm
curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos8-amd64/rpms/MariaDB-common-10.5.8-1.el8.x86_64.rpm --output MariaDB-common-10.5.8-1.el8.x86_64.rpm
curl https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/yum/centos8-amd64/rpms/MariaDB-compat-10.5.8-1.el8.x86_64.rpm --output MariaDB-compat-10.5.8-1.el8.x86_64.rpm
dnf install -y MariaDB-*.rpm
fi
pkgs=(
ninja-build
rrdtool-devel
gnutls-devel
lua-devel
perl-Thread-Queue
)
for i in "${pkgs[@]}"; do
if ! rpm -q "$i" ; then
if [ $maj = 'centos7' ] ; then
yum install -y "$i"
else
dnf -y --enablerepo=PowerTools install "$i"
fi
fi
done
elif [ -r /etc/issue ] ; then
maj=$(awk '{print $1}' /etc/issue)
version=$(awk '{print $3}' /etc/issue)
if [ "$version" = "9" ] ; then
dpkg="dpkg"
else
dpkg='dpkg --no-pager'
fi
v=$(cmake --version)
if [[ "$v" =~ "version 3" ]] ; then
cmake='cmake'
elif [ "$maj" = "Debian" ] || [ "$maj" = "Ubuntu" ]; then
if $dpkg -l cmake ; then
echo "Bad version of cmake..."
exit 1
else
if [ $my_id -eq 0 ] ; then
apt install -y cmake
cmake='cmake'
else
echo -e "cmake is not installed, you could enter, as root:\n\tapt install -y cmake\n\n"
exit 1
fi
fi
elif [ "$maj" = "Raspbian" ] ; then
if $dpkg -l cmake ; then
echo "Bad version of cmake..."
exit 1
else
if [ $my_id -eq 0 ] ; then
apt install -y cmake
cmake='cmake'
else
echo -e "cmake is not installed, you could enter, as root:\n\tapt install -y cmake\n\n"
exit 1
fi
fi
else
echo "Bad version of cmake..."
exit 1
fi
if [ "$maj" = "Debian" ] || [ "$maj" = "Ubuntu" ]; then
pkgs=(
gcc
g++
pkg-config
libmariadb3
librrd-dev
libgnutls28-dev
ninja-build
liblua5.3-dev
python3
python3-pip
)
for i in "${pkgs[@]}"; do
if ! $dpkg -l $i | grep "^ii" ; then
if [ $my_id -eq 0 ] ; then
apt install -y $i
else
echo -e "The package \"$i\" is not installed, you can install it, as root, with the command:\n\tapt install -y $i\n\n"
exit 1
fi
fi
done
elif [ "$maj" = "Raspbian" ] ; then
pkgs=(
gcc
g++
pkg-config
libmariadb3
librrd-dev
libgnutls28-dev
ninja-build
liblua5.3-dev
python3
python3-pip
)
for i in "${pkgs[@]}"; do
if ! $dpkg -l $i | grep "^ii" ; then
if [ $my_id -eq 0 ] ; then
apt install -y $i
else
echo -e "The package \"$i\" is not installed, you can install it, as root, with the command:\n\tapt install -y $i\n\n"
exit 1
fi
fi
done
fi
if [[ ! -x /usr/bin/python3 ]] ; then
if [ $my_id -eq 0 ] ; then
apt install -y python3
else
echo -e "python3 is not installed, you can enter, as root:\n\tapt install -y python3\n\n"
exit 1
fi
else
echo "python3 already installed"
fi
if ! $dpkg -l python3-pip ; then
if [ $my_id -eq 0 ] ; then
apt install -y python3-pip
else
echo -e "python3-pip is not installed, you can enter, as root:\n\tapt install -y python3-pip\n\n"
exit 1
fi
else
echo "pip3 already installed"
fi
fi
pip3 install conan --upgrade
if [ "$my_id" -eq 0 ] ; then
conan='/usr/local/bin/conan'
elif which conan ; then
conan=$(which conan)
else
conan="$HOME/.local/bin/conan"
fi
if [ ! -d build ] ; then
mkdir build
else
echo "'build' directory already there"
fi
if [ "$force" = 1 ] ; then
rm -rf build
mkdir build
fi
cd build
if [ "$maj" = centos7 ] ; then
rm -rf ~/.conan/profiles/default
if [ "$CONAN_REBUILD" = 1 ] ; then
$conan install .. -s compiler.libcxx=libstdc++11 --build="*"
else
$conan install .. -s compiler.libcxx=libstdc++11 --build=missing
fi
else
$conan install .. -s compiler.libcxx=libstdc++11 --build=missing
fi
if [ "$maj" = Raspbian ] ; then
CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER=centreon-broker -DWITH_GROUP=centreon-broker -DWITH_CONFIG_PREFIX=/etc/centreon-broker -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF=/etc/centreon-broker -DWITH_PREFIX_LIB=/usr/lib64/nagios -DWITH_MODULE_SIMU=On $* ..
elif [ "$maj" = "Debian" ] || [ "$maj" = "Ubuntu" ]; then
CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER=centreon-broker -DWITH_GROUP=centreon-broker -DWITH_CONFIG_PREFIX=/etc/centreon-broker -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF=/etc/centreon-broker -DWITH_PREFIX_LIB=/usr/lib64/nagios -DWITH_MODULE_SIMU=On $* ..
else
CXXFLAGS="-Wall -Wextra" $cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DWITH_PREFIX=/usr -DWITH_PREFIX_BIN=/usr/sbin -DWITH_USER=centreon-broker -DWITH_GROUP=centreon-broker -DWITH_CONFIG_PREFIX=/etc/centreon-broker -DWITH_TESTING=On -DWITH_PREFIX_MODULES=/usr/share/centreon/lib/centreon-broker -DWITH_PREFIX_CONF=/etc/centreon-broker -DWITH_PREFIX_LIB=/usr/lib64/nagios -DWITH_MODULE_SIMU=On $* ..
fi