-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvalidate_config.sh
More file actions
executable file
·471 lines (412 loc) · 8.4 KB
/
validate_config.sh
File metadata and controls
executable file
·471 lines (412 loc) · 8.4 KB
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
#!/bin/bash
# vim: ts=4:sw=4
. ~/plescripts/plelib.sh
. ~/plescripts/networklib.sh
. ~/plescripts/global.cfg
EXEC_CMD_ACTION=EXEC
typeset test_iso_ol7=yes
typeset -r ME=$0
typeset -r PARAMS="$*"
typeset -r str_usage=\
"Usage : $ME [-skip_test_iso_ol7]
Ce script vérifie que le virtual-host remplie les conditions nécessaires au bon
fonctionnement de la démo."
while [ $# -ne 0 ]
do
case $1 in
-emul)
EXEC_CMD_ACTION=NOP
shift
;;
-skip_test_iso_ol7)
test_iso_ol7=no
shift
;;
-h|-help|help)
info "$str_usage"
LN
exit 1
;;
*)
error "Arg '$1' invalid."
LN
info "$str_usage"
exit 1
;;
esac
done
typeset -i nr_errors=0
function test_if_scripts_exists
{
line_separator
info -n "Directory exists \$HOME/plescripts "
if [ ! -d "$HOME/plescripts" ]
then
info -f "[$KO]"
error " must contains all scripts."
((++nr_errors))
else
info -f "[$OK]"
fi
LN
}
# $1 zip name
# Don't work with 12.1
function _test_if_grip_zip_exists
{
typeset -r zip_name="$1"
info "Grid zip $orarel :"
info -n "Exist \$HOME/$oracle_install/grid/$zip_name "
if [ ! -f "$HOME/$oracle_install/grid/$zip_name" ]
then
info -f "[$KO]"
error " \$HOME/$oracle_install/grid must contains $zip_name"
LN
((++nr_errors))
else
info -f "[$OK]"
LN
fi
}
function test_oracle_binaries_or_zip
{
line_separator
if [[ $orarel =~ 18 ]]
then
info "Oracle zip $orarel :"
info -n "Exist \$HOME/$oracle_install/database/LINUX.X64_180000_db_home.zip "
if [ ! -f "$HOME/$oracle_install/database/LINUX.X64_180000_db_home.zip" ]
then
info -f "[$KO]"
error " \$HOME/$oracle_install/database/LINUX.X64_180000_db_home.zip."
LN
((++nr_errors))
else
info -f "[$OK]"
LN
fi
elif [[ $orarel =~ 12 ]]
then
info "Oracle $orarel extracted :"
info -n "Exist \$HOME/$oracle_install/database/runInstaller "
if [ ! -f "$HOME/$oracle_install/database/runInstaller" ]
then
info -f "[$KO]"
error " \$HOME/$oracle_install/database must contains Oracle installer."
LN
((++nr_errors))
else
info -f "[$OK]"
LN
fi
else
error "Release '$orarel' invalid."
exit 1
fi
}
function test_grid_binaries_or_zip
{
line_separator
case "$orarel" in
12.2|18.0)
_test_if_grip_zip_exists $grid_zip_name
;;
12.1)
info "Grid $orarel extracted :"
info -n "Exist \$HOME/$oracle_install/grid/runInstaller "
if [ ! -f "$HOME/$oracle_install/grid/runInstaller" ]
then
info -f "[$KO]"
error " \$HOME/$oracle_install/grid must contains Grid installer."
LN
((++nr_errors))
else
info -f "[$OK]"
LN
fi
;;
*)
error "Release '$orarel' invalid."
exit 1
;;
esac
}
function _is_exported
{
typeset -r directory=$1
info -n " - $(replace_paths_by_shell_vars $directory) "
typeset -r network=$(right_pad_ip $infra_network)
if grep -qE "${directory}\s*${network}.*" /etc/exports 2>/dev/null
then
info -f "[$OK]"
return 0
else
((++nr_errors))
info -f "[$KO]"
return 1
fi
}
function validate_NFS_exports
{
line_separator
typeset -r network=$(right_pad_ip $infra_network)
info "Validate NFS exports from $client_hostname on network ${network} :"
if ! _is_exported $HOME/plescripts
then
info " add to /etc/exports : $HOME/plescripts $network/$if_pub_prefix(rw,sync,subtree_check,no_root_squash)"
fi
if ! _is_exported $HOME/$oracle_install
then
info " add to /etc/exports : $HOME/oracle_install/$orarel $network/$if_pub_prefix(ro,subtree_check)"
fi
LN
}
function ISO_OLinux7_exists
{
line_separator
info -n "ISO Oracle Linux $OL7_LABEL exists $(replace_paths_by_shell_vars $full_linux_iso_name) "
if [ ! -f "$full_linux_iso_name" ]
then
info -f "[$KO]"
((++nr_errors))
else
info -f "[$OK]"
fi
LN
}
function validate_gateway
{
line_separator
info -n "Validate gateway $gateway "
if ping -c 1 $gateway >/dev/null 2>&1
then
info -f "[$OK]"
else
info -f "[$KO]"
((++nr_errors))
fi
LN
}
function validate_master_time_server
{
[ "$master_time_server" == internet ] && return || true
line_separator
info -n "Time synchronization server : ping of $master_time_server "
if ping -c 1 $master_time_server >/dev/null 2>&1
then
info -f "[$OK]"
else
info -f "[$KO]"
((++nr_errors))
fi
LN
}
function validate_nic
{
line_separator
info -n "Validate NIC $if_net_bridgeadapter "
if [ "$if_net_bridgeadapter" == "undef" ]
then
info -f "[$KO]"
((++nr_errors))
else
info -f "[$OK]"
fi
LN
}
function validate_resolv_conf
{
line_separator
info "Validate resolv.conf "
info -n " - Test : search $infra_domain "
if grep search /etc/resolv.conf | grep -q $infra_domain
then
info -f "[$OK]"
else
info -f "[$KO]"
((++nr_errors))
fi
info -n " - Test : nameserver $infra_ip "
if grep -q ${infra_ip} /etc/resolv.conf
then
info -f "[$OK]"
else
info -f "[$KO]"
((++nr_errors))
fi
LN
}
function _shell_in_path
{
line_separator
info -n "\$PATH contains \$HOME/plescripts/shell "
if command_exists stop_vm
then
info -f "[$OK]"
else
info -f "[$KO]"
((++nr_errors))
fi
LN
}
function _in_path
{
typeset option=no
if [ "$1" == "-o" ]
then
option=yes
shift
fi
typeset -r cmd=$1
typeset -r cmd_msg=$2
typeset -r msg=$(printf "%-10s " $cmd)
info -n " $msg"
if command_exists $cmd
then
info -f "[$OK]"
else
if [ $option == yes ]
then
info -f -n "[${BLUE}optional${NORM}]"
else
((++nr_errors))
info -f -n "[$KO]"
fi
info -f " $cmd_msg"
typeset -r distrib=$(grep ^NAME /etc/os-release | cut -d= -f2)
if [[ $option == no && $distrib =~ openSUSE ]]
then
exec_cmd -ci cnf $cmd
LN
fi
fi
}
function test_tools
{
_shell_in_path
info "Installed :"
_in_path VBoxManage "Install VirtualVox"
_in_path nc "Install nc"
_in_path ssh "Install ssh"
_in_path -o git "Install git"
_in_path -o tmux "Install tmux"
LN
if command_exists VBoxManage
then
info -n "$USER in group vboxusers "
gid_vboxusers=$(cat /etc/group|grep vboxusers|cut -d: -f3)
if id|grep -q $gid_vboxusers
then
info -f "[$OK]"
LN
else
((++nr_errors))
if cat /etc/group|grep -qE "^vboxusers.*$USER*"
then
info -f "[$KO] : disconnect user $USER and connect again."
LN
else
info -f "[$KO] execute : sudo usermod -a -G vboxusers $USER"
warning "Take effect on a new connection."
LN
fi
fi
fi
}
function test_if_configure_global_cfg_executed
{
line_separator
info -n "~/plescripts/configure_global.cfg.sh executed "
typeset errors_msg
typeset -i exec_global=0
typeset hn=$(hostname -s)
if [ "$hn" != "$client_hostname" ]
then
((++nr_errors))
exec_global=1
errors_msg="\n\tclient_hostname=$client_hostname expected $hn"
fi
if [ "$USER" != "$common_user_name" ]
then
((++nr_errors))
exec_global=1
errors_msg="$errors_msg\n\tcommon_user_name=$common_user_name expected $USER"
fi
if [ x"$vm_path" == x ]
then
((++nr_errors))
exec_global=1
errors_msg="$errors_msg\n\tvm_path not set."
fi
if [ $exec_global -eq 1 ]
then
info -f "[$KO]"
info "Execute : ./configure_global.cfg.sh"
error "Errors :$errors_msg"
info "vm_path = $vm_path"
else
info -f "[$OK]"
fi
LN
}
function test_timer_hpet
{
if [ ! -f /sys/devices/system/clocksource/clocksource0/current_clocksource ]
then
return
fi
line_separator
typeset -r timer_name=$(cat /sys/devices/system/clocksource/clocksource0/current_clocksource)
case "$timer_name" in
"hpet")
info "Current timer ${GREEN}$timer_name${NORM}."
LN
;;
kvm-clock)
error "Timer ${RED}kvm-clock${NORM} invalid."
error "$(hostname -s) must be a physical machine."
LN
((++nr_errors))
;;
*)
info "Current timer ${RED}$timer_name${NORM}?"
if grep -q hpet /sys/devices/system/clocksource/clocksource0/available_clocksource
then
info " ==> Enable hpet timer for better performances."
LN
else
info " hpet timer not available."
LN
fi
;;
esac
}
typeset -r orarel=${oracle_release%.*.*}
test_if_scripts_exists
test_oracle_binaries_or_zip
test_grid_binaries_or_zip
validate_NFS_exports
[ $test_iso_ol7 == yes ] && ISO_OLinux7_exists || true
validate_gateway
validate_nic
validate_master_time_server
validate_resolv_conf
test_tools
test_if_configure_global_cfg_executed
if [ "$common_user_name" != "no_user_defined" ]
then
line_separator
exec_cmd -c "~/plescripts/shell/set_plescripts_acl.sh"
fi
test_timer_hpet
line_separator
if [ $nr_errors -ne 0 ]
then
error "Configuration failed : $nr_errors errors."
LN
exit 1
else
info "Configuration [$OK]"
LN
exit 0
fi