-
Notifications
You must be signed in to change notification settings - Fork 139
/
setup.sh
executable file
·1705 lines (1568 loc) · 67.9 KB
/
setup.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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
################################################################################
#
# OCS Inventory NG Management Server Setup
#
# Copyleft 2006 Didier LIROULET
# Web: http://www.ocsinventory-ng.org
#
# This code is open source and may be copied and modified as long as the source
# code is always made freely available.
# Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################
#
if [[ -e setup.answers ]]; then
source setup.answers
fi
# Which host run database server
DB_SERVER_HOST="${DB_SERVER_HOST:-localhost}"
# On which port run database server
DB_SERVER_PORT="${DB_SERVER_PORT:-3306}"
# Database server credentials
DB_SERVER_USER="${DB_SERVER_USER:-ocs}"
DB_SERVER_PWD="${DB_SERVER_PWD:-ocs}"
# Where is Apache daemon binary (if empty, will try to find it)
APACHE_BIN="${APACHE_BIN:-}"
# Where is Apache configuration file (if empty, will try to find it)
APACHE_CONFIG_FILE="${APACHE_CONFIG_FILE:-}"
# Where is Apache includes configuration directory (if emty, will try to find it)
APACHE_CONFIG_DIRECTORY="${APACHE_CONFIG_DIRECTORY:-}"
# Which user is running Apache web server (if empty, will try to find it)
APACHE_USER="${APACHE_USER:-}"
# Which group is running Apache web server (if empty, will try to find it)
APACHE_GROUP="${APACHE_GROUP:-}"
# Where is Apache document root directory (if empty, will try to find it)
APACHE_ROOT_DOCUMENT="${APACHE_ROOT_DOCUMENT:-}"
# Which version of mod_perl is apache using, 1 for <= 1.999_21 and 2 for >= 1.999_22 (if empty, user will be asked for)
APACHE_MOD_PERL_VERSION="${APACHE_MOD_PERL_VERSION:-}"
# Where are located OCS Communication server log files
OCS_COM_SRV_LOG="${OCS_COM_SRV_LOG:-/var/log/ocsinventory-server}"
# Where are located OCS Communication server plugins configuration files
OCS_COM_SRV_PLUGINS_CONFIG_DIR="${OCS_COM_SRV_PLUGINS_CONFIG_DIR:-/etc/ocsinventory-server/plugins}"
# Where are located OCS Communication server plugins perl files
OCS_COM_SRV_PLUGINS_PERL_DIR="${OCS_COM_SRV_PLUGINS_PERL_DIR:-/etc/ocsinventory-server/perl}"
# Where is located perl interpreter
PERL_BIN=${PERL_BIN:-$(which perl 2>/dev/null)}
# Where is located make utility
MAKE=${MAKE:-$(which make 2>/dev/null)}
# Where is located logrotate configuration directory
LOGROTATE_CONF_DIR="${LOGROTATE_CONF_DIR:-/etc/logrotate.d}"
# Where is located newsyslog.conf
NEWSYSLOG_CONF_FILE="${NEWSYSLOG_CONF_FILE:-/etc/newsyslog.conf}"
# Where to store setup logs
SETUP_LOG=${SETUP_LOG:-$(pwd)/ocs_server_setup.log}
# Communication Server Apache configuration file
COM_SERVER_APACHE_CONF_FILE="${COM_SERVER_APACHE_CONF_FILE:-ocsinventory-server.conf}"
# Rest API configuration file
API_REST_APACHE_CONF_FILE="${API_REST_APACHE_CONF_FILE:-ocsinventory-restapi.conf}"
# Communication Server logrotate configuration file
COM_SERVER_LOGROTATE_CONF_FILE="${COM_SERVER_LOGROTATE_CONF_FILE:-ocsinventory-server}"
# Administration Console Apache configuration file
ADM_SERVER_APACHE_CONF_FILE="${ADM_SERVER_APACHE_CONF_FILE:-ocsinventory-reports.conf}"
# Administration console read only files directory
ADM_SERVER_STATIC_DIR="${ADM_SERVER_STATIC_DIR:-/usr/share/ocsinventory-reports}"
ADM_SERVER_STATIC_REPORTS_DIR="${ADM_SERVER_STATIC_REPORTS_DIR:-ocsreports}"
ADM_SERVER_REPORTS_ALIAS="${ADM_SERVER_REPORTS_ALIAS:-/ocsreports}"
# Administration console read/write files dir
ADM_SERVER_VAR_DIR="${ADM_SERVER_VAR_DIR:-/var/lib/ocsinventory-reports}"
# Administration default packages directory and Apache alias
ADM_SERVER_VAR_PACKAGES_DIR="${ADM_SERVER_VAR_PACKAGES_DIR:-download}"
ADM_SERVER_PACKAGES_ALIAS="${ADM_SERVER_PACKAGES_ALIAS:-/download}"
# Administration default snmp directory and Apache alias
ADM_SERVER_VAR_SNMP_DIR="${ADM_SERVER_VAR_SNMP_DIR:-snmp}"
ADM_SERVER_SNMP_ALIAS="${ADM_SERVER_SNMP_ALIAS:-/snmp}"
# Administration console tmp files dir
ADM_SERVER_VAR_TMP_DIR="${ADM_SERVER_VAR_TMP_DIR:-tmp_dir}"
# Administration console log files dir
ADM_SERVER_VAR_LOGS_DIR="${ADM_SERVER_VAR_LOGS_DIR:-logs}"
# Administration console scripts log files dir
ADM_SERVER_VAR_SCRIPTS_LOGS_DIR="${ADM_SERVER_VAR_SCRIPTS_LOGS_DIR:-scripts}"
# Administration console default ipdsicover-util.pl cache dir
ADM_SERVER_VAR_IPD_DIR="${ADM_SERVER_VAR_IPD_DIR:-ipd}"
# OS or linux distribution from automatic detection
UNIX_DISTRIBUTION="${UNIX_DISTRIBUTION:-}"
# Default install directory for rest api
REST_API_DIRECTORY="${REST_API_DIRECTORY:-}"
###################### DO NOT MODIFY BELOW #######################
# Check for Apache web server binaries
echo
echo "+----------------------------------------------------------+"
echo "| |"
echo "| Welcome to OCS Inventory NG Management server setup ! |"
echo "| |"
echo "+----------------------------------------------------------+"
echo
# Check for OS or linux distribution
echo "Trying to determine which OS or Linux distribution you use"
if [ -f /etc/redhat-release ]; then
UNIX_DISTRIBUTION="redhat"
elif [ -f /etc/debian_version ]; then
UNIX_DISTRIBUTION="debian"
elif [ -f /etc/SuSE-release ]; then
UNIX_DISTRIBUTION="suse"
fi
# Check for Apache web server binaries
echo "+----------------------------------------------------------+"
echo "| Checking for Apache web server binaries ! |"
echo "+----------------------------------------------------------+"
echo
echo "CAUTION: If upgrading Communication server from OCS Inventory NG 1.0 RC2 and"
echo "previous, please remove any Apache configuration for Communication Server!"
echo
echo -n "Do you wish to continue ([y]/n)?"
read ligne
if [ -z "$ligne" ] || [ "$ligne" = "y" ] || [ "$ligne" = "Y" ]; then
echo "Assuming Communication server 1.0 RC2 or previous is not installed"
echo "on this computer."
echo
else
echo "Installation aborted !"
echo
exit 1
fi
echo >$SETUP_LOG
OCS_LOCAL_DATE=$(date +%Y-%m-%d-%H-%M-%S)
echo "Starting OCS Inventory NG Management server setup on $OCS_LOCAL_DATE" >>$SETUP_LOG
echo -n "from folder " >>$SETUP_LOG
pwd >>$SETUP_LOG
echo -n "Starting OCS Inventory NG Management server setup from folder "
pwd
echo "Storing log in file $SETUP_LOG" >>$SETUP_LOG
echo "Storing log in file $SETUP_LOG"
echo >>$SETUP_LOG
echo "============================================================" >>$SETUP_LOG
echo "Checking OCS Inventory NG Management Server requirements..." >>$SETUP_LOG
echo "============================================================" >>$SETUP_LOG
echo
echo "+----------------------------------------------------------+"
echo "| Checking for database server properties... |"
echo "+----------------------------------------------------------+"
echo
# Check mysql client distribution version
echo "Checking for database server properties" >>$SETUP_LOG
DB_CLIENT_MAJOR_VERSION=$(eval mysql -V | cut -d' ' -f6 | cut -d'.' -f1) >>$SETUP_LOG 2>&1
DB_CLIENT_MINOR_VERSION=$(eval mysql -V | cut -d' ' -f6 | cut -d'.' -f2) >>$SETUP_LOG 2>&1
if [ "$DB_CLIENT_MAJOR_VERSION" = "Linux" ]; then
DB_CLIENT_MAJOR_VERSION=$(eval mysql -V | cut -d' ' -f4 | cut -d'.' -f1) >>$SETUP_LOG 2>&1
DB_CLIENT_MINOR_VERSION=$(eval mysql -V | cut -d' ' -f4 | cut -d'.' -f2) >>$SETUP_LOG 2>&1
fi
echo "Your MySQL client seems to be part of MySQL version $DB_CLIENT_MAJOR_VERSION.$DB_CLIENT_MINOR_VERSION."
echo "MySQL client distribution version $DB_CLIENT_MAJOR_VERSION.$DB_CLIENT_MINOR_VERSION." >>$SETUP_LOG
# Ensure mysql distribution is 4.1 or higher
if [ $DB_CLIENT_MAJOR_VERSION -gt 4 ]; then
res=1
else
if [ $DB_CLIENT_MAJOR_VERSION -eq 4 ]; then
if [ $DB_CLIENT_MINOR_VERSION -eq 1 ]; then
res=1
else
res=0
fi
else
res=0
fi
fi
if [ $res -eq 0 ]; then
# Not 4.1 or higher, ask user to contnue ?
echo "Your computer does not seem to be compliant with MySQL 4.1 or higher."
echo -n "Do you wish to continue (y/[n])?"
read ligne
if [ "$ligne" = "y" ]; then
echo "Ensure your database server is running MySQL 4.1 or higher !"
echo "Ensure also this computer is able to connect to your MySQL server !"
else
echo "Installation aborted !"
exit 1
fi
else
echo "Your computer seems to be running MySQL 4.1 or higher, good ;-)"
echo "Computer seems to be running MySQL 4.1 or higher" >>$SETUP_LOG
fi
echo
# Ask user for database server host
res=0
while [ $res -eq 0 ]; do
echo -n "Which host is running database server [$DB_SERVER_HOST] ?"
read ligne
if [ -z "$ligne" ]; then
res=1
else
DB_SERVER_HOST="$ligne"
res=1
fi
done
echo "OK, database server is running on host $DB_SERVER_HOST ;-)"
echo "Database server is running on host $DB_SERVER_HOST" >>$SETUP_LOG
echo
# Ask user for database server port
res=0
while [ $res -eq 0 ]; do
echo -n "On which port is running database server [$DB_SERVER_PORT] ?"
read ligne
if [ -z "$ligne" ]; then
res=1
else
DB_SERVER_PORT="$ligne"
res=1
fi
done
echo "OK, database server is running on port $DB_SERVER_PORT ;-)"
echo "Database server is running on port $DB_SERVER_PORT" >>$SETUP_LOG
echo
echo
echo "+----------------------------------------------------------+"
echo "| Checking for Apache web server daemon... |"
echo "+----------------------------------------------------------+"
echo
echo "Checking for Apache web server daemon" >>$SETUP_LOG
# Try to find Apache daemon
if [ -z "$APACHE_BIN" ]; then
APACHE_BIN_FOUND=$(which httpd 2>/dev/null)
if [ -z "$APACHE_BIN_FOUND" ]; then
APACHE_BIN_FOUND=$(which apache2ctl 2>/dev/null)
if [ -z "$APACHE_BIN_FOUND" ]; then
APACHE_BIN_FOUND=$(which apachectl 2>/dev/null)
if [ -z "$APACHE_BIN_FOUND" ]; then
APACHE_BIN_FOUND=$(which httpd2 2>/dev/null)
fi
fi
fi
fi
echo "Found Apache daemon $APACHE_BIN_FOUND" >>$SETUP_LOG
# Ask user's confirmation
res=0
while [ $res -eq 0 ]; do
echo -n "Where is Apache daemon binary [$APACHE_BIN_FOUND] ?"
read ligne
if [ -z "$ligne" ]; then
APACHE_BIN=$APACHE_BIN_FOUND
else
APACHE_BIN="$ligne"
fi
# Ensure file exists and is executable
if [ -x $APACHE_BIN ]; then
res=1
else
echo "*** ERROR: $APACHE_BIN is not executable !"
res=0
fi
# Ensure file is not a directory
if [ -d $APACHE_BIN ]; then
echo "*** ERROR: $APACHE_BIN is a directory !"
res=0
fi
done
echo "OK, using Apache daemon $APACHE_BIN ;-)"
echo "Using Apache daemon $APACHE_BIN" >>$SETUP_LOG
echo
echo
echo "+----------------------------------------------------------+"
echo "| Checking for Apache main configuration file... |"
echo "+----------------------------------------------------------+"
echo
# Try to find Apache main configuration file
echo "Checking for Apache main configuration file" >>$SETUP_LOG
if [ -z "$APACHE_CONFIG_FILE" ]; then
APACHE_ROOT=$(eval $APACHE_BIN -V | grep "HTTPD_ROOT" | cut -d'=' -f2 | tr -d '"')
echo "Found Apache HTTPD_ROOT $APACHE_ROOT" >>$SETUP_LOG
APACHE_CONFIG=$(eval $APACHE_BIN -V | grep "SERVER_CONFIG_FILE" | cut -d'=' -f2 | tr -d '"')
echo "Found Apache SERVER_CONFIG_FILE $APACHE_CONFIG" >>$SETUP_LOG
if [ -e $APACHE_CONFIG ]; then
APACHE_CONFIG_FILE_FOUND="$APACHE_CONFIG"
else
APACHE_CONFIG_FILE_FOUND="$APACHE_ROOT/$APACHE_CONFIG"
fi
fi
echo "Found Apache main configuration file $APACHE_CONFIG_FILE_FOUND" >>$SETUP_LOG
# Ask user's confirmation
res=0
while [ $res -eq 0 ]; do
echo -n "Where is Apache main configuration file [$APACHE_CONFIG_FILE_FOUND] ?"
read ligne
if [ -z "$ligne" ]; then
APACHE_CONFIG_FILE=$APACHE_CONFIG_FILE_FOUND
else
APACHE_CONFIG_FILE="$ligne"
fi
# Ensure file is not a directory
if [ -d $APACHE_CONFIG_FILE ]; then
echo "*** ERROR: $APACHE_CONFIG_FILE is a directory !"
res=0
fi
# Ensure file exists and is readable
if [ -r $APACHE_CONFIG_FILE ]; then
res=1
else
echo "*** ERROR: $APACHE_CONFIG_FILE is not readable !"
res=0
fi
done
echo "OK, using Apache main configuration file $APACHE_CONFIG_FILE ;-)"
echo "Using Apache main configuration file $APACHE_CONFIG_FILE" >>$SETUP_LOG
echo
echo
echo "+----------------------------------------------------------+"
echo "| Checking for Apache user account... |"
echo "+----------------------------------------------------------+"
echo
# Try to find Apache main configuration file
echo "Checking for Apache user account" >>$SETUP_LOG
if [ -z "$APACHE_USER" ]; then
case $UNIX_DISTRIBUTION in
"debian")
if [ -f /etc/apache2/envvars ]; then
. /etc/apache2/envvars
fi
APACHE_USER_FOUND=$APACHE_RUN_USER
;;
"suse")
if [ -f /etc/apache2/uid.conf ]; then
APACHE_USER_FOUND=$(cat /etc/apache2/uid.conf | grep "User" | tail -1 | cut -d' ' -f2)
fi
;;
"redhat")
APACHE_USER_FOUND=$(cat $APACHE_CONFIG_FILE | grep "User " | tail -1 | cut -d' ' -f2)
;;
esac
fi
echo "Found Apache user account $APACHE_USER_FOUND" >>$SETUP_LOG
# Ask user's confirmation
res=0
while [ $res -eq 0 ]; do
echo -n "Which user account is running Apache web server [$APACHE_USER_FOUND] ?"
read ligne
if [ -z "$ligne" ]; then
APACHE_USER=$APACHE_USER_FOUND
else
APACHE_USER="$ligne"
fi
# Ensure group exist in /etc/passwd
if [ $(cat /etc/passwd | grep $APACHE_USER | wc -l) -eq 0 ]; then
echo "*** ERROR: account $APACHE_USER not found in system table /etc/passwd !"
else
res=1
fi
done
echo "OK, Apache is running under user account $APACHE_USER ;-)"
echo "Using Apache user account $APACHE_USER" >>$SETUP_LOG
echo
echo
echo "+----------------------------------------------------------+"
echo "| Checking for Apache group... |"
echo "+----------------------------------------------------------+"
echo
# Try to find Apache main configuration file
echo "Checking for Apache group" >>$SETUP_LOG
if [ -z "$APACHE_GROUP" ]; then
case $UNIX_DISTRIBUTION in
"debian")
if [ -f /etc/apache2/envvars ]; then
. /etc/apache2/envvars
fi
APACHE_GROUP_FOUND=$APACHE_RUN_USER
;;
"suse")
if [ -f /etc/apache2/uid.conf ]; then
APACHE_GROUP_FOUND=$(cat /etc/apache2/uid.conf | grep "Group" | tail -1 | cut -d' ' -f2)
fi
;;
"redhat")
APACHE_GROUP_FOUND=$(cat $APACHE_CONFIG_FILE | grep "Group " | tail -1 | cut -d' ' -f2)
;;
esac
if [ -z "$APACHE_GROUP_FOUND" ]; then
# No group found, assume group name is the same as account
echo "No Apache user group found, assuming group name is the same as user account" >>$SETUP_LOG
APACHE_GROUP_FOUND=$APACHE_USER
fi
fi
echo "Found Apache user group $APACHE_GROUP_FOUND" >>$SETUP_LOG
# Ask user's confirmation
res=0
while [ $res -eq 0 ]; do
echo -n "Which user group is running Apache web server [$APACHE_GROUP_FOUND] ?"
read ligne
if [ -z "$ligne" ]; then
APACHE_GROUP=$APACHE_GROUP_FOUND
else
APACHE_GROUP="$ligne"
fi
# Ensure group exist in /etc/group
if [ $(cat /etc/group | grep $APACHE_GROUP | wc -l) -eq 0 ]; then
echo "*** ERROR: group $APACHE_GROUP not found in system table /etc/group !"
else
res=1
fi
done
echo "OK, Apache is running under users group $APACHE_GROUP ;-)"
echo "Using Apache user group $APACHE_GROUP" >>$SETUP_LOG
echo
echo
echo "+----------------------------------------------------------+"
echo "| Checking for Apache Include configuration directory... |"
echo "+----------------------------------------------------------+"
echo
# Try to find Apache includes configuration directory
echo "Checking for Apache Include configuration directory" >>$SETUP_LOG
if [ -z "$APACHE_CONFIG_DIRECTORY" ]; then
if [ -d "$APACHE_ROOT/conf.d" ]; then
APACHE_CONFIG_DIRECTORY_FOUND="$APACHE_ROOT/conf.d"
elif [ -d "$APACHE_ROOT/conf-available" ]; then
APACHE_CONFIG_DIRECTORY_FOUND="$APACHE_ROOT/conf-available"
else
APACHE_CONFIG_DIRECTORY_FOUND=""
fi
if [ -d "$APACHE_CONFIG_DIRECTORY_FOUND" ]; then
echo "Found Apache Include configuration directory $APACHE_CONFIG_DIRECTORY_FOUND" >>$SETUP_LOG
fi
fi
# Ask user's confirmation
echo "Setup found Apache Include configuration directory in"
echo "$APACHE_CONFIG_DIRECTORY_FOUND."
echo "Setup will put OCS Inventory NG Apache configuration in this directory."
res=0
while [ $res -eq 0 ]; do
echo -n "Where is Apache Include configuration directory [$APACHE_CONFIG_DIRECTORY_FOUND] ?"
read ligne
if [ -z "$ligne" ]; then
APACHE_CONFIG_DIRECTORY=$APACHE_CONFIG_DIRECTORY_FOUND
else
APACHE_CONFIG_DIRECTORY="$ligne"
fi
# Ensure file is a directory
if [ -d $APACHE_CONFIG_DIRECTORY ]; then
res=1
else
echo "*** ERROR: $APACHE_CONFIG_DIRECTORY is not a directory !"
res=0
fi
# Ensure directory exists and is writable
if [ -w $APACHE_CONFIG_DIRECTORY ]; then
res=1
else
echo "*** ERROR: $APACHE_CONFIG_DIRECTORY is not writable !"
res=0
fi
done
echo "OK, Apache Include configuration directory $APACHE_CONFIG_DIRECTORY found ;-)"
echo "Using Apache Include configuration directory $APACHE_CONFIG_DIRECTORY" >>$SETUP_LOG
echo
echo
echo "+----------------------------------------------------------+"
echo "| Checking for PERL Interpreter... |"
echo "+----------------------------------------------------------+"
echo
echo "Checking for PERL Interpreter" >>$SETUP_LOG
if [ -z "$PERL_BIN" ]; then
echo "PERL Interpreter not found !"
echo "PERL Interpreter not found" >>$SETUP_LOG
echo "OCS Inventory NG is not able to work without PERL Interpreter."
echo "Setup manually PERL first."
echo "Installation aborted !"
echo "installation aborted" >>$SETUP_LOG
exit 1
else
echo "Found PERL interpreter at <$PERL_BIN> ;-)"
echo "Found PERL interpreter at <$PERL_BIN>" >>$SETUP_LOG
fi
# Ask user's confirmation
res=0
while [ $res -eq 0 ]; do
echo -n "Where is PERL interpreter binary [$PERL_BIN] ?"
read ligne
if [ -n "$ligne" ]; then
PERL_BIN="$ligne"
fi
# Ensure file exists and is executable
if [ -x $PERL_BIN ]; then
res=1
else
echo "*** ERROR: $PERL_BIN is not executable !"
res=0
fi
# Ensure file is not a directory
if [ -d $PERL_BIN ]; then
echo "*** ERROR: $PERL_BIN is a directory !"
res=0
fi
done
echo "OK, using PERL interpreter $PERL_BIN ;-)"
echo "Using PERL interpreter $PERL_BIN" >>$SETUP_LOG
echo
echo
echo -n "Do you wish to setup Communication server on this computer ([y]/n)?"
read ligne
if [ -z "$ligne" ] || [ "$ligne" = "y" ] || [ "$ligne" = "Y" ]; then
# Setting up Communication server
echo >>$SETUP_LOG
echo "============================================================" >>$SETUP_LOG
echo "Installing Communication server" >>$SETUP_LOG
echo "============================================================" >>$SETUP_LOG
echo
echo
echo "+----------------------------------------------------------+"
echo "| Checking for Make utility... |"
echo "+----------------------------------------------------------+"
echo
echo "Checking for Make utility" >>$SETUP_LOG
if [ -z "$MAKE" ]; then
echo "Make utility not found !"
echo "Make utility not found" >>$SETUP_LOG
echo "Setup is not able to build OCS Inventory NG Perl module."
echo "Unable to build OCS Inventory NG Perl module !" >>$SETUP_LOG
exit 1
else
echo "OK, Make utility found at <$MAKE> ;-)"
echo "Make utility found at <$MAKE>" >>$SETUP_LOG
fi
echo
echo "+----------------------------------------------------------+"
echo "| Checking for Apache mod_perl version... |"
echo "+----------------------------------------------------------+"
echo
echo "Checking for Apache mod_perl version 1.99_22 or higher"
echo "Checking for Apache mod_perl version 1.99_22 or higher" >>$SETUP_LOG
$PERL_BIN -mmod_perl2 -e 'print "mod_perl 1.99_22 or higher is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
# mod_perl 2 not found !
echo "Checking for Apache mod_perl version 1.99_21 or previous"
echo "Checking for Apache mod_perl version 1.99_21 or previous" >>$SETUP_LOG
$PERL_BIN -mmod_perl -e 'print "mod_perl 1.99_21 or previous is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
# mod_perl 1 not found => Ask user
res=0
while [ $res -eq 0 ]; do
echo "Setup is unable to determine your Apache mod_perl version."
echo "Apache must have module mod_perl enabled. As configuration differs from"
echo "mod_perl 1.99_21 or previous AND mod_perl 1.99_22 or higher, Setup must"
echo "know which release Apache is using."
echo "You can find which release you are using by running the following command"
echo " - On RPM enabled OS, rpm -q mod_perl"
echo " - On DPKG enabled OS, dpkg -l libapache*-mod-perl*"
echo "Enter 1 for mod_perl 1.99_21 or previous."
echo "Enter 2 for mod_perl 1.99_22 and higher."
echo -n "Which version of Apache mod_perl the computer is running ([1]/2) ?"
read ligne
if [ -z "$ligne" ]; then
APACHE_MOD_PERL_VERSION=1
else
APACHE_MOD_PERL_VERSION=$ligne
fi
res=1
done
else
echo "Found that mod_perl version 1.99_21 or previous is available."
APACHE_MOD_PERL_VERSION=1
fi
else
echo "Found that mod_perl version 1.99_22 or higher is available."
APACHE_MOD_PERL_VERSION=2
fi
if [ $APACHE_MOD_PERL_VERSION -eq 1 ]; then
echo "OK, Apache is using mod_perl version 1.99_21 or previous ;-)"
echo "Using mod_perl version 1.99_21 or previous" >>$SETUP_LOG
else
echo "OK, Apache is using mod_perl version 1.99_22 or higher ;-)"
echo "Using mod_perl version 1.99_22 or higher" >>$SETUP_LOG
fi
echo
echo "+----------------------------------------------------------+"
echo "| Checking for Communication server log directory... |"
echo "+----------------------------------------------------------+"
echo
echo "Checking for Communication server log directory" >>$SETUP_LOG
# Ask user
res=0
while [ $res -eq 0 ]; do
echo "Communication server can create detailed logs. This logs can be enabled"
echo "by setting integer value of LOGLEVEL to 1 in Administration console"
echo "menu Configuration."
echo -n "Where to put Communication server log directory [$OCS_COM_SRV_LOG] ?"
read ligne
if [ -n "$ligne" ]; then
OCS_COM_SRV_LOG=$ligne
fi
res=1
done
echo "OK, Communication server will put logs into directory $OCS_COM_SRV_LOG ;-)"
echo "Using $OCS_COM_SRV_LOG as Communication server log directory" >>$SETUP_LOG
echo
echo "+----------------------------------------------------------------------------+"
echo "| Checking for Communication server plugins configuration directory... |"
echo "+----------------------------------------------------------------------------+"
echo
echo "Checking for Communication server plugins configuration directory" >>$SETUP_LOG
# Ask user
res=0
while [ $res -eq 0 ]; do
echo "Communication server need a directory for plugins configuration files. "
echo -n "Where to put Communication server plugins configuration files [$OCS_COM_SRV_PLUGINS_CONFIG_DIR] ?"
read ligne
if [ -n "$ligne" ]; then
OCS_COM_SRV_PLUGINS_CONFIG_DIR=$ligne
fi
res=1
done
echo "OK, Communication server will put plugins configuration files into directory $OCS_COM_SRV_PLUGINS_CONFIG_DIR ;-)"
echo "Using $OCS_COM_SRV_PLUGINS_CONFIG_DIR as Communication server plugins configuration directory" >>$SETUP_LOG
echo
echo "+-------------------------------------------------------------------+"
echo "| Checking for Communication server plugins perl directory... |"
echo "+-------------------------------------------------------------------+"
echo
echo "Checking for Communication server perl directory" >>$SETUP_LOG
# Ask user
res=0
while [ $res -eq 0 ]; do
echo "Communication server need a directory for plugins Perl modules files."
echo -n "Where to put Communication server plugins Perl modules files [$OCS_COM_SRV_PLUGINS_PERL_DIR] ?"
read ligne
if [ -n "$ligne" ]; then
OCS_COM_SRV_PLUGINS_PERL_DIR=$ligne
fi
res=1
done
echo "OK, Communication server will put plugins Perl modules files into directory $OCS_COM_SRV_PLUGINS_PERL_DIR ;-)"
echo "Using $OCS_COM_SRV_PLUGINS_PERL_DIR as Communication server plugins perl directory" >>$SETUP_LOG
echo
# jump to communication server directory
echo "Entering Apache sub directory" >>$SETUP_LOG
# Check for required Perl Modules (if missing, please install before)
# - DBI 1.40 or higher
# - Apache::DBI 0.93 or higher
# - DBD::mysql 2.9004 or higher
# - Compress::Zlib 1.33 or higher
# - XML::Simple 2.12 or higher
# - Net::IP 1.21 or higher
# - Archive::Zip
echo
echo "+----------------------------------------------------------+"
echo "| Checking for required Perl Modules... |"
echo "+----------------------------------------------------------+"
echo
REQUIRED_PERL_MODULE_MISSING=0
DBI=0
APACHE_DBI=0
DBD_MYSQL=0
COMPRESS_ZLIB=0
XML_SIMPLE=0
NET_IP=0
ARCHIVE_ZIP=0
echo "Checking for DBI PERL module..."
echo "Checking for DBI PERL module" >>$SETUP_LOG
$PERL_BIN -mDBI -e 'print "PERL module DBI is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module DBI is not installed !"
REQUIRED_PERL_MODULE_MISSING=1
DBI=1
else
echo "Found that PERL module DBI is available."
fi
echo "Checking for Apache::DBI PERL module..."
echo "Checking for Apache::DBI PERL module" >>$SETUP_LOG
$PERL_BIN -mApache::DBI -e 'print "PERL module Apache::DBI is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module Apache::DBI is not installed !"
REQUIRED_PERL_MODULE_MISSING=1
APACHE_DBI=1
else
echo "Found that PERL module Apache::DBI is available."
fi
echo "Checking for DBD::mysql PERL module..."
echo "Checking for DBD::mysql PERL module" >>$SETUP_LOG
$PERL_BIN -mDBD::mysql -e 'print "PERL module DBD::mysql is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module DBD::mysql is not installed !"
REQUIRED_PERL_MODULE_MISSING=1
DBD_MYSQL=1
else
echo "Found that PERL module DBD::mysql is available."
fi
echo "Checking for Compress::Zlib PERL module..."
echo "Checking for Compress::Zlib PERL module" >>$SETUP_LOG
$PERL_BIN -mCompress::Zlib -e 'print "PERL module Compress::Zlib is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module Compress::Zlib is not installed !"
REQUIRED_PERL_MODULE_MISSING=1
COMPRESS_ZLIB=1
else
echo "Found that PERL module Compress::Zlib is available."
fi
echo "Checking for XML::Simple PERL module..."
echo "Checking for XML::Simple PERL module" >>$SETUP_LOG
$PERL_BIN -mXML::Simple -e 'print "PERL module XML::Simple is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module XML::Simple is not installed !"
REQUIRED_PERL_MODULE_MISSING=1
XML_SIMPLE=1
else
echo "Found that PERL module XML::Simple is available."
fi
echo "Checking for Net::IP PERL module..."
echo "Checking for Net::IP PERL module" >>$SETUP_LOG
$PERL_BIN -mNet::IP -e 'print "PERL module Net::IP is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module Net::IP is not installed !"
REQUIRED_PERL_MODULE_MISSING=1
NET_IP=1
else
echo "Found that PERL module Net::IP is available."
fi
# Check for Zip::Archive
echo "Checking for Archive::Zip Perl module..."
echo "Checking for Archive::Zip Perl module" >>$SETUP_LOG
$PERL_BIN -mArchive::Zip -e 'print "PERL module Archive::Zip is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module Archive::Zip is not installed !"
REQUIRED_PERL_MODULE_MISSING=1
ARCHIVE_ZIP=1
else
echo "Found that PERL module Archive::Zip is available."
fi
if [ $REQUIRED_PERL_MODULE_MISSING -ne 0 ]; then
echo "*** ERROR: There is one or more required PERL modules missing on your computer !"
echo "Please, install missing PERL modules first."
echo " "
echo "OCS setup.sh can install perl module from packages for you"
echo "The script will use the native package from your operating system like apt or rpm"
echo -n "Do you wish to continue (y/[n])?"
read ligne
if [ "$ligne" = "y" ] || [ "$ligne" = "Y" ]; then
case $UNIX_DISTRIBUTION in
"redhat")
echo "RedHat based automatic installation"
if [ $DBI -eq 1 ]; then
PACKAGE="$PACKAGE perl-DBI"
fi
if [ $APACHE_DBI -eq 1 ]; then
PACKAGE="$PACKAGE perl-Apache-DBI"
fi
if [ $DBD_MYSQL -eq 1 ]; then
PACKAGE="$PACKAGE perl-DBD-MySQL"
fi
if [ $COMPRESS_ZLIB -eq 1 ]; then
PACKAGE="$PACKAGE perl-Compress-Zlib"
fi
if [ $XML_SIMPLE -eq 1 ]; then
PACKAGE="$PACKAGE perl-XML-Simple"
fi
if [ $NET_IP -eq 1 ]; then
PACKAGE="$PACKAGE perl-Net-IP"
fi
if [ $ARCHIVE_ZIP -eq 1 ]; then
PACKAGE="$PACKAGE perl-Archive-Zip"
fi
yum install $PACKAGE
if [ $? != 0 ]; then
echo "Installation aborted !"
echo "Installation script encounter problems to install packages !"
echo "One or more required PERL modules missing !" >>$SETUP_LOG
echo "Installation aborted" >>$SETUP_LOG
exit 1
fi
echo "All packages have been installed on this computer"
;;
"debian")
echo "Debian based automatic installation"
if [ $DBI -eq 1 ]; then
PACKAGE="$PACKAGE libdbi-perl"
fi
if [ $APACHE_DBI -eq 1 ]; then
PACKAGE="$PACKAGE libapache-dbi-perl"
fi
if [ $DBD_MYSQL -eq 1 ]; then
PACKAGE="$PACKAGE libdbd-mysql-perl"
fi
if [ $COMPRESS_ZLIB -eq 1 ]; then
PACKAGE="$PACKAGE libcompress-zlib-perl"
fi
if [ $XML_SIMPLE -eq 1 ]; then
PACKAGE="$PACKAGE libxml-simple-perl"
fi
if [ $NET_IP -eq 1 ]; then
PACKAGE="$PACKAGE libnet-ip-perl"
fi
if [ $ARCHIVE_ZIP -eq 1 ]; then
PACKAGE="$PACKAGE libarchive-zip-perl"
fi
apt-get update
apt-get install $PACKAGE
if [ $? -ne 0 ]; then
echo "Installation aborted !"
echo "Installation script encounter problems to install packages !"
echo "One or more required PERL modules missing !" >>$SETUP_LOG
echo "Installation aborted" >>$SETUP_LOG
exit 1
fi
echo "All packages have been installed on this computer"
;;
*)
echo "Installation aborted !"
echo "Installation script cannot find missing packages for your distribution"
echo "One or more required PERL modules missing !" >>$SETUP_LOG
echo "Installation aborted" >>$SETUP_LOG
exit 1
;;
esac
else
echo "Installation aborted !"
echo "Please, install missing PERL modules first."
echo "One or more required PERL modules missing !" >>$SETUP_LOG
echo "Installation aborted" >>$SETUP_LOG
exit 1
fi
fi
echo
echo
echo -n "Do you wish to setup Rest API server on this computer ([y]/n)?"
read ligne
if [ -z "$ligne" ] || [ "$ligne" = "y" ] || [ "$ligne" = "Y" ]; then
echo
echo "+----------------------------------------------------------+"
echo "| Checking for REST API Dependencies ... |"
echo "+----------------------------------------------------------+"
echo
# Dependencies :
# => Mojolicious::Lite
# => Plack
# => Switch
$PERL_BIN -mMojolicious::Lite -e 'print "PERL module Mojolicious::Lite is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module Mojolicious::Lite is not installed !"
echo -n "Do you wish to continue (y/[n])?"
read ligne
if [ "$ligne" = "y" ] || [ "$ligne" = "Y" ]; then
echo "User choose to continue setup without PERL module Mojolicious::Lite" >>$SETUP_LOG
else
echo
echo "Installation aborted !"
echo "User choose to abort installation !" >>$SETUP_LOG
exit 1
fi
else
echo "Found that PERL module Mojolicious::Lite is available."
fi
$PERL_BIN -mSwitch -e 'print "PERL module Switch is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module Switch is not installed !"
echo -n "Do you wish to continue (y/[n])?"
read ligne
if [ "$ligne" = "y" ] || [ "$ligne" = "Y" ]; then
echo "User choose to continue setup without PERL module Switch" >>$SETUP_LOG
else
echo
echo "Installation aborted !"
echo "User choose to abort installation !" >>$SETUP_LOG
exit 1
fi
else
echo "Found that PERL module Switch is available."
fi
$PERL_BIN -mPlack::Handler -e 'print "PERL module Plack::Handler is available\n"' >>$SETUP_LOG 2>&1
if [ $? -ne 0 ]; then
echo "*** ERROR: PERL module Plack::Handler is not installed !"
echo -n "Do you wish to continue (y/[n])?"
read ligne
if [ "$ligne" = "y" ] || [ "$ligne" = "Y" ]; then
echo "User choose to continue setup without PERL module Plack::Handler" >>$SETUP_LOG
else
echo
echo "Installation aborted !"
echo "User choose to abort installation !" >>$SETUP_LOG
exit 1
fi
else
echo "Found that PERL module Plack::Handler is available."
fi
echo
echo "+----------------------------------------------------------+"
echo "| Configuring REST API Server files ... |"
echo "+----------------------------------------------------------+"
echo
# Get first INC path to determine a valid path
REST_API_DIRECTORY=$($PERL_BIN -e "print \"@INC[2]\"")
echo -n "Where do you want the API code to be store [$REST_API_DIRECTORY] ?"
read ligne
if [ -z "$ligne" ]; then
REST_API_DIRECTORY=$REST_API_DIRECTORY
else
REST_API_DIRECTORY="$ligne"
fi
echo "Copying files to $REST_API_DIRECTORY"
echo "Copying files to $REST_API_DIRECTORY" >>$SETUP_LOG
echo
echo "+----------------------------------------------------------+"
echo "| Configuring REST API Server configuration files ... |"
echo "+----------------------------------------------------------+"
echo
echo "Configuring Rest API server (file $API_REST_APACHE_CONF_FILE)" >>$SETUP_LOG
cp etc/ocsinventory/$API_REST_APACHE_CONF_FILE $API_REST_APACHE_CONF_FILE.local
$PERL_BIN -pi -e "s#'REST_API_PATH'#'$REST_API_DIRECTORY'#g" $API_REST_APACHE_CONF_FILE.local
$PERL_BIN -pi -e "s#'REST_API_LOADER_PATH'#'$REST_API_DIRECTORY/Api/Ocsinventory/Restapi/Loader.pm'#g" $API_REST_APACHE_CONF_FILE.local
echo "Writing Rest API configuration to file $APACHE_CONFIG_DIRECTORY/$API_REST_APACHE_CONF_FILE" >>$SETUP_LOG
cp -f $API_REST_APACHE_CONF_FILE.local $APACHE_CONFIG_DIRECTORY/zz-$API_REST_APACHE_CONF_FILE >>$SETUP_LOG 2>&1
cp -r Api/ $REST_API_DIRECTORY
fi
echo
echo "+----------------------------------------------------------+"
echo "| OK, looks good ;-) |"
echo "| |"
echo "| Configuring Communication server Perl modules... |"
echo "+----------------------------------------------------------+"
echo
echo "Configuring Communication server (perl Makefile.PL)" >>$SETUP_LOG
cd "Apache"
$PERL_BIN Makefile.PL
if [ $? -ne 0 ]; then
echo -n "Warning: Prerequisites too old ! Do you wish to continue (y/[n])?"
read ligne