This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheasycheck.sh
executable file
·487 lines (429 loc) · 10.4 KB
/
easycheck.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
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
#!/bin/bash
#Author: Vítezslav Dvořák 2017
DISTRO="UNKNOWN"
VERSION="UNKNOWN"
MEMORYSIZE=""
DISKFREE=0
SCORE=0
MYSQLDEV="n/a"
function WhiteColor() {
echo -en '\E[37m'"\033[1m$1\033[0m" # Blue
}
function BlueColor() {
echo -en '\E[34m'"\033[1m$1\033[0m" # Blue
}
function RedColor() {
echo -en '\E[31m'"\033[1m$1\033[0m" # Red
}
function GreenColor() {
echo -en '\E[32m'"\033[1m$1\033[0m" # Green
}
function YellowColor() {
echo -en '\E[33m'"\033[1m$1\033[0m" # Yellow
}
function MagentaColor() {
echo -en '\E[35m'"\033[1m$1\033[0m" # Magenta
}
function OkMark() {
echo -en '\E[1;32m'"\033[1m✔\033[0m"
}
function BadMark() {
echo -en '\E[0;91m'"\033[1m✘\033[0m"
}
function WarningMark() {
echo -en '\E[1;35m'"\033[1m⚠\033[0m"
}
function commandExists()
{
if [ `which $1 2>&1 | grep -v ":" | wc -l` == "1" ]; then
echo true
else
echo false
fi
}
function InstallCurl(){
if [ $(commandExists curl) == "false" ]; then
YellowColor "\n Curl not found! Installing: "
bash -c "sudo $INSTALLER install curl"
echo
fi
}
function AdaptToDistro() {
case "$DISTRO" in
"Debian" )
INSTALLER="apt-get -y"
MINVER="8"
MYSQLDEV="libmysqlclient-dev"
INSTQCMD="dpkg -l"
DEPS="g++ libmagickcore-6.q16-dev libmagickwand-6-headers"
;;
"Ubuntu" )
INSTALLER="apt-get -y"
MYSQLDEV="libmysqlclient-dev"
;;
"Rhel" | "Centos" | "centos")
INSTALLER="yum -y"
MINVER="7"
MYSQLDEV="mysql-devel"
;;
*)
RedColor "Unknown $DISTRO"
;;
esac
}
function CheckRootAccess(){
WhiteColor "Root access: "
if [[ $EUID -ne 0 ]]; then
if type "sudo" &> /dev/null; then
BlueColor "with sudo "
if sudo -S -p '' echo -n < /dev/null 2> /dev/null ;
then
GreenColor "allowed " ; OkMark
else
RedColor "denied " ; BadMark
fi
else
MagentaColor "unprivileged "
WarningMark
fi
else
OkMark
fi
echo
}
function CheckVersion(){
WhiteColor "Distro Version: "
if (( $(echo "${VERSION} ${MINVER}" | awk '{print ($1 >= $2)}') ))
then
YellowColor "${VERSION} "; OkMark
else
RedColor "${VERSION} "; BadMark
fi
echo
}
function CheckDistro() {
WhiteColor "Distribution: "
if [ $(commandExists lsb_release) == "true" ]; then
DISTRO=`lsb_release -i | awk '{print $3}'`
VERSION=`lsb_release -r | awk '{print $2}'`
else # LSB Not present
if [ -f "/etc/os-release" ] #Debian/OLD Ubuntu
then
source /etc/os-release
VERSION=$VERSION_ID
DISTRO=$ID
else #Other Distro
if [ -f "/etc/debian_version" ] #Debian/OLD Ubuntu
then
VERSION=`cat /etc/debian_version`
else #Other Distro
RedColor "Unrecognized distro version\n"
fi
fi
fi
case "$DISTRO" in
"Ubuntu" | "Debian" | "Redhat" | "Centos" | "centos" )
YellowColor " ${DISTRO} "; OkMark; echo
;;
*) RedColor "${DISTRO} "; BadMark; echo
;;
esac
AdaptToDistro
CheckVersion
}
bytesToHuman() {
b=${1:-0}; d=''; s=0; S=(Bytes {K,M,G,T,E,P,Y,Z}iB)
while ((b > 1024)); do
d="$(printf ".%02d" $((b % 1024 * 100 / 1024)))"
b=$((b / 1024))
let s++
done
echo "$b$d ${S[$s]}"
}
function CheckMemory() {
WhiteColor "Memory: "
OKMEM=4294967296
BIGMEM=8589934592
MEMORY=`free -b | sed -n 2p | awk '{ print $2 }'`
HUMEM=`bytesToHuman $MEMORY`
YellowColor $HUMEM
if [ "$MEMORY" -ge "$BIGMEM" ]
then
GreenColor " - for large installation "; OkMark
else
if [ "$MEMORY" -ge "$OKMEM" ]
then
BlueColor " - for small installation"; OkMark
else
RedColor " is lower than required "; BadMark
fi
fi
echo
}
function CheckDiskSpace() {
WhiteColor "Disk space: "
OKDISK=10737418240
BIGDISK=42949672960
DISKFREE=`df --output=avail | tail -n +2 | sort -n | tail -n1`
HUDISK=`bytesToHuman $DISKFREE`
YellowColor $HUDISK
if [ "$DISKFREE" -ge "$BIGDISK" ]
then
GreenColor " - for large installation "; OkMark
else
if [ "$DISKFREE" -le "$OKDISK" ]
then
BlueColor " - for small installation "; OkMark
else
RedColor " is lower than required "; BadMark
fi
fi
echo
}
function CheckPing() {
if ping -c 3 $1 &> /dev/null
then
OkMark
else
BadMark
fi
echo
}
function CheckCurl() {
CURL_MAX_CONNECTION_TIMEOUT="-m 100"
CURL_RETURN_CODE=0
CURL_OUTPUT=`curl ${CURL_MAX_CONNECTION_TIMEOUT} $1 2> /dev/null` || CURL_RETURN_CODE=$?
if [ ${CURL_RETURN_CODE} -ne 0 ]; then
RedColor "Curl connection failed with return code - ${CURL_RETURN_CODE}"; BadMark
else
OkMark
fi
echo
}
function CheckGemsConnectivity(){
RUBYGEMSIP="151.101.194.2" #In 7/2017
RUBYGEMSHOSTNAME="api.rubygems.org"
WhiteColor "Ping rubygems.org (IP): "
CheckPing $RUBYGEMSIP
WhiteColor "Ping rubygems.org (DNS): "
CheckPing $RUBYGEMSHOSTNAME
WhiteColor "HTTP rubygems.org: "
CheckCurl "http://${RUBYGEMSHOSTNAME}"
WhiteColor "HTTPS rubygems.org: "
CheckCurl "https://${RUBYGEMSHOSTNAME}"
}
function CheckRubyVersion(){
MINRUBYVER="2.6"
OKRUBYVER="2.6.7"
if [ -f "/etc/profile.d/rvm.sh" ]; then
source /etc/profile.d/rvm.sh
if type "rvm" &> /dev/null; then
OkMark
YellowColor " RVM Detected\n"
rvm list
else
WarningMark
MagentaColor " RVM Coruppted! Consider reinstall by:"
WhiteColor " curl -sSL https://get.rvm.io | bash -s stable "
echo
fi
fi
if [ $(commandExists ruby) == "true" ]; then
RUBYVER=`echo 'puts RUBY_VERSION' | ruby`
WhiteColor "Ruby Installed: "
YellowColor "$RUBYVER "
which ruby | awk '{ printf "%s", $0 }'
if (( $(echo "${RUBYVER} ${MINRUBYVER}" | awk '{print ($1 >= $2)}') ))
then
if (( $(echo "${RUBYVER} ${OKRUBYVER}" | awk '{print ($1 >= $2)}') ))
then
GreenColor " Fresh enough "
else
BlueColor " Consider upgrade "
fi
OkMark
else
RedColor " obsolete "
BadMark
fi
else
RedColor "Ruby not found "
BadMark
fi
echo
}
function CheckMySQL(){
WhiteColor "MySQL: "
if [ $(commandExists mysql) == "true" ]; then
YellowColor "MySQL "
BlueColor "client "
MYSQLSO=`/sbin/ldconfig -p | grep "mysqlclient.so " | awk '{print $4}'`;
MYSQLH=`find /usr/ -name 'mysql.h'`
if [ `echo $MYSQLSO | wc -l` == "0" ] || [ `echo $MYSQLH | wc -l` == "0" ]
then
MagentaColor "Install MySQL Dev by:"
echo " $INSTALLER $MYSQLDEV "
WarningMark
else
GreenColor "$MYSQLSO $MYSQLH "
OkMark
fi
else
WarningMark
fi
echo
}
function CheckPostgreSQL(){
WhiteColor "Postgresql: "
if [ $(commandExists psql) == "true" ]; then
YellowColor "PostgreSQL "
BlueColor "client "
RedColor "PostgreSQl is not supported any more. Please consider switching to MySQL."
if type "pg_config" &> /dev/null;
then
if [ `find /usr/ -name 'pg_config.h'|wc -l` == "0" ];
then
YellowColor " pg_config.h not found "
WarningMark
else
OkMark
fi
else
YellowColor " pg_config not found "
WarningMark
fi
else
WarningMark
fi
echo
}
function CheckDatabase(){
CheckMySQL
CheckPostgreSQL
}
function CheckCompiler(){
WhiteColor "C Compiler: "
if [ $(commandExists cc) == "true" ]; then
CCVER=`cc --version | head -n 1 | awk '{ printf "%s", $0 }'`
YellowColor "${CCVER} "
OkMark
else
bash -c "sudo $INSTALLER install gcc"
if [ $(commandExists cc) == "true" ]; then
CCVER=`cc --version | head -n 1 | awk '{ printf "%s", $0 }'`
YellowColor "Installed ${CCVER} "
OkMark
else
RedColor "not found "
BadMark
fi
fi
echo
}
function CheckBundler(){
CheckCompiler
WhiteColor "Bundler: "
if [ $(commandExists gem) == "true" ]; then
if [ `gem list -i bundler` == "true" ]
then
BlueColor " gem installed "
if [ $(commandExists bundle) == "true" ]; then
GreenColor `bundle --version | awk '{print $3 }'`" "
which bundle | awk '{ printf "%s", $0 }'
else
RedColor "bundle command not found! "
WarningMark
fi
else
YellowColor "\n gem command found! Installing: "
gem install bundler
if [ `gem list -i bundler` == "true" ]
then
if [ $(commandExists bundle) == "true" ]; then
GreenColor `bundle --version | awk '{print $3 }'`" "
which bundle | awk '{ printf "%s", $0 }'
else
RedColor "bundle command not found! "
WarningMark
fi
else
MagentaColor "gem not installed "
WarningMark
fi
fi
else
RedColor "gem command not found! "
WarningMark
fi
echo
}
function CheckImagick(){
WhiteColor "Imagick development files: "
if [ $(commandExists Magick-config) == "true" ]; then
GreenColor `which Magick-config | awk '{ printf "%s", $0 }'`" "
if [ `find /usr/ -name 'MagickCore.pc'|wc -l` == "0" ];
then
YellowColor " MagickCore.pc not found "
WarningMark
else
if [ `find /usr/ -name 'MagickWand.h'|wc -l` == "0" ];
then
YellowColor " MagickWand.h not found "
WarningMark
else
OkMark
fi
fi
else
YellowColor "Magick-config not found"
WarningMark
fi
echo
}
function CheckRedmineInstaller(){
WhiteColor "Redmine installer: "
if [ $(commandExists redmine) == "true" ]; then
GreenColor `redmine --version | tail -n 1 | awk '{print $3 }'`" "
which redmine
else
YellowColor "Install it: "
WhiteColor "gem install redmine-installer --pre"
fi
echo
}
function CheckNodejs(){
WhiteColor "Redmine installer: "
if [ $(commandExists node) == "true" ]; then
GreenColor `node -v | tail -n 1`" "
which node
else
YellowColor "Install it: "
WhiteColor "sudo apt install nodejs"
fi
echo
}
function CheckRedisServer(){
WhiteColor "Redmine installer: "
if [ $(commandExists redis-server) == "true" ]; then
GreenColor `redis-server -v | tail -n 1 | awk '{print $3 }'`" "
which redis-server
else
YellowColor "Install it: "
WhiteColor "sudo apt install redis-server"
fi
echo
}
MagentaColor "\nEasyRedmine requirements Check\n\n"
CheckRootAccess
CheckDistro
InstallCurl
CheckMemory
CheckDiskSpace
CheckRubyVersion
CheckGemsConnectivity
CheckBundler
CheckDatabase
CheckImagick
CheckRedmineInstaller
CheckNodejs
CheckRedisServer