Skip to content

Commit 73b7f2d

Browse files
committed
cleanup(cmake.sh): sonarqube advices added.
1 parent 7d54811 commit 73b7f2d

File tree

1 file changed

+29
-36
lines changed

1 file changed

+29
-36
lines changed

cmake.sh

+29-36
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ This program build Centreon-engine
1212
-h|--help : help
1313
EOF
1414
}
15-
BUILD_TYPE="Debug"
15+
BUILD_TYPE=Debug
1616
CONAN_REBUILD="0"
17-
for i in $(cat conanfile.txt) ; do
18-
if [[ $i =~ / ]] ; then
19-
if [ ! -d ~/.conan/data/$i ] ; then
20-
echo "The package '$i' is missing"
21-
CONAN_REBUILD="1"
17+
while IFS= read -r filename; do
18+
if [[ $filename =~ / ]] ; then
19+
if [ ! -d ~/.conan/data/"$filename" ] ; then
20+
echo "The package '$filename' is missing"
21+
CONAN_REBUILD=1
2222
break
2323
fi
2424
fi
25-
done
25+
done < conanfile.txt
2626

27-
for i in "$@"
28-
do
27+
for i in "$@" ; do
2928
case $i in
3029
-f|--force)
3130
force=1
@@ -52,20 +51,16 @@ done
5251
my_id=$(id -u)
5352

5453
if [ -r /etc/centos-release ] ; then
55-
maj="centos$(cat /etc/centos-release | awk '{print $4}' | cut -f1 -d'.')"
54+
maj="centos$(awk '{print $4}' /etc/centos-release | cut -f1 -d'.')"
5655
v=$(cmake --version)
5756
if [[ $v =~ "version 3" ]] ; then
5857
cmake='cmake'
5958
else
6059
if rpm -q cmake3 ; then
61-
rm -f /usr/bin/cmake
62-
ln -s /usr/bin/cmake3 /usr/bin/cmake
63-
cmake='cmake'
64-
elif [ $maj = "centos7" ] ; then
60+
cmake='cmake3'
61+
elif [ "$maj" = "centos7" ] ; then
6562
yum -y install epel-release cmake3
66-
mv /usr/bin/cmake /usr/bin/cmake2
67-
ln -s /usr/bin/cmake3 /usr/bin/cmake
68-
cmake='cmake'
63+
cmake='cmake3'
6964
else
7065
dnf -y install cmake
7166
cmake='cmake'
@@ -84,8 +79,7 @@ if [ -r /etc/centos-release ] ; then
8479

8580
good=$(gcc --version | awk '/gcc/ && ($3+0)>5.0{print 1}')
8681

87-
if [ ! $good ] ; then
88-
echo "Your compiler is too old. Trying to used devtoolset-9."
82+
if [ ! "$good" ] ; then
8983
yum -y install centos-release-scl
9084
yum-config-manager --enable rhel-server-rhscl-7-rpms
9185
yum -y install devtoolset-9
@@ -97,26 +91,26 @@ if [ -r /etc/centos-release ] ; then
9791
perl-Thread-Queue
9892
)
9993
for i in "${pkgs[@]}"; do
100-
if ! rpm -q $i ; then
94+
if ! rpm -q "$i" ; then
10195
if [ $maj = 'centos7' ] ; then
102-
yum install -y $i
96+
yum install -y "$i"
10397
else
104-
dnf -y --enablerepo=PowerTools install $i
98+
dnf -y --enablerepo=PowerTools install "$i"
10599
fi
106100
fi
107101
done
108102
elif [ -r /etc/issue ] ; then
109-
maj=$(cat /etc/issue | awk '{print $1}')
110-
version=$(cat /etc/issue | awk '{print $3}')
111-
if [ $version = "9" ] ; then
112-
dpkg='dpkg'
103+
maj=$(awk '{print $1}' /etc/issue)
104+
version=$(awk '{print $3}' /etc/issue)
105+
if [ "$version" = "9" ] ; then
106+
dpkg="dpkg"
113107
else
114108
dpkg='dpkg --no-pager'
115109
fi
116110
v=$(cmake --version)
117-
if [[ $v =~ "version 3" ]] ; then
111+
if [[ "$v" =~ "version 3" ]] ; then
118112
cmake='cmake'
119-
elif [ $maj = "Debian" ] || [ $maj = "Ubuntu" ] ; then
113+
elif [ "$maj" = "Debian" ] || [ "$maj" = "Ubuntu" ] ; then
120114
if $dpkg -l cmake ; then
121115
echo "Bad version of cmake..."
122116
exit 1
@@ -129,7 +123,7 @@ elif [ -r /etc/issue ] ; then
129123
exit 1
130124
fi
131125
fi
132-
elif [ $maj = "Raspbian" ] ; then
126+
elif [ "$maj" = "Raspbian" ] ; then
133127
if $dpkg -l cmake ; then
134128
echo "Bad version of cmake..."
135129
exit 1
@@ -146,7 +140,7 @@ elif [ -r /etc/issue ] ; then
146140
echo "Bad version of cmake..."
147141
exit 1
148142
fi
149-
if [ $maj = "Debian" ] || [ $maj = "Ubuntu" ]; then
143+
if [ "$maj" = "Debian" ] || [ "$maj" = "Ubuntu" ]; then
150144
pkgs=(
151145
gcc
152146
g++
@@ -165,8 +159,7 @@ elif [ -r /etc/issue ] ; then
165159
fi
166160
fi
167161
done
168-
fi
169-
if [ $maj = "Raspbian" ] ; then
162+
elif [ "$maj" = "Raspbian" ] ; then
170163
pkgs=(
171164
gcc
172165
g++
@@ -190,7 +183,7 @@ fi
190183

191184
pip3 install conan --upgrade
192185

193-
if [ $my_id -eq 0 ] ; then
186+
if [ "$my_id" -eq 0 ] ; then
194187
conan='/usr/local/bin/conan'
195188
elif which conan ; then
196189
conan=$(which conan)
@@ -204,15 +197,15 @@ else
204197
echo "'build' directory already there"
205198
fi
206199

207-
if [ "$force" = "1" ] ; then
200+
if [ "$force" = 1 ] ; then
208201
rm -rf build
209202
mkdir build
210203
fi
211204
cd build
212205

213-
if [ $maj = "centos7" ] ; then
206+
if [ "$maj" = centos7 ] ; then
214207
rm -rf ~/.conan/profiles/default
215-
if [ "$CONAN_REBUILD" = "1" ] ; then
208+
if [ "$CONAN_REBUILD" = 1 ] ; then
216209
$conan install .. -s compiler.libcxx=libstdc++11 --build="*"
217210
else
218211
$conan install .. -s compiler.libcxx=libstdc++11 --build=missing

0 commit comments

Comments
 (0)