-
Notifications
You must be signed in to change notification settings - Fork 73
/
install.sh
executable file
·1676 lines (1447 loc) · 56.6 KB
/
install.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/bash
###############################################################################
#
# install.sh - Installs/Updates NagVis
#
# Copyright (c) 2004-2016 NagVis Project (Contact: [email protected])
#
# Development:
# Wolfgang Nieder
# Lars Michelsen <[email protected]>
#
# License:
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###############################################################################
# Some initialisations
###############################################################################
# Default action
INSTALLER_ACTION="install"
# Be quiet? (Enable/Disable confirmations)
INSTALLER_QUIET=0
# Should the installer change config options when possible?
INSTALLER_CONFIG_MOD="y"
# files to ignore/delete
IGNORE_DEMO=""
# backends to use
NAGVIS_BACKENDS="mklivestatus,ndo2db,ido2db"
# data source
SOURCE=nagios
# skip checks
RC=0
FORCE=0
UNDO=0
ACONF="y"
REMOVE="n"
LOG=install.log
CALL="$0"
NAGVIS_PATH_PARAM_SET=0
NAGVIS_PATH_OLD_PARAM_SET=0
# Default Path to Graphviz binaries
GRAPHVIZ_PATH="/usr/local/bin"
# Version of NagVis to be installed
NAGVIS_VER=$(cat share/server/core/defines/global.php | grep CONST_VERSION | awk -F"'" '{ print $4 }')
INSTALLER_VERSION=$NAGVIS_VER
# Version of old NagVis (will be detected if update)
NAGVIS_VER_OLD=""
# Relative path to the NagVis configuration file
NAGVIS_CONF="etc/nagvis.ini.php"
# Relative path to the NagVis SQLite auth database
NAGVIS_AUTH_DB="etc/auth.db"
NAGVIS_PERMS_DB="etc/perms.db"
NAGVIS_WORLDMAP_DB="etc/worldmap.db"
# File for saving the old removed map permissions
AUTH_BACKUP="etc/auth-backup"
# Default nagios web conf
HTML_SAMPLE="etc/apache2-nagvis.conf-sample"
# Default nagios web conf
HTML_CONF="nagvis.conf"
# Saving current timestamp for backup when updating
DATE=$(date +%Y-%m-%d_%H:%M:%S)
# Web path to the NagVis base directory
HTML_PATH=""
# Path to webserver conf
WEB_PATH=""
# Default webserver user
WEB_USER=""
# Default webserver group
WEB_GROUP=""
# Version prerequisites
NEED_PHP_VERSION=$(cat share/server/core/defines/global.php | grep CONST_NEEDED_PHP_VERSION | awk -F"'" '{ print $4 }')
[ -z "$NEED_PHP_VERSION" ] && NEED_PHP_VERSION="5.0"
NEED_PHP_MODULES="gd mbstring gettext session xml pdo"
NEED_GV_MOD="dot neato twopi circo fdp"
NEED_GV_VERSION=2.14
NEED_SQLITE_VERSION=3.0
LINE_SIZE=78
GREP_INCOMPLETE=0
# Function definitions
###############################################################################
. install_lib
# format version string
fmt_version() {
V=${1//a/.0.0}
V=${V//b/.0.2}
V=${V//rc/.0.4}
if [ ${#V} -eq 3 ]; then
V=${V}.0.60
fi
NV=""
for S in "${V//./ }"; do
NV="$NV$(printf %02d $S)"
done
while [ ${#NV} -lt 8 ]; do
NV=${NV}0
done
echo $NV
}
# Print usage
usage() {
cat <<EOD
NagVis Installer $INSTALLER_VERSION
Installs or updates NagVis on your system.
Usage: $0 [OPTIONS]
General Parameters:
-s <SOURCE> Data source, defaults to Nagios, may be Icinga
-n <PATH> Path to Nagios/Icinga base directory (\$BASE)
Default value: $NAGIOS_PATH
-b <PATH> Path to graphviz binaries ($NEED_GV_MOD)
Default value: $GRAPHVIZ_PATH
-p <PATH> Path to NagVis base directory to install to
Default value: $NAGVIS_PATH
-O <PATH> Path to the old NagVis base directory to update from.
You only need to set this if it is different than the new NagVis base
directory given in "-p". This may be useful when updating from 1.4
to 1.6 where the paths to NagVis changed.
Default value: $NAGVIS_PATH
-W <PATH> Web path to the NagVis base directory
Default: $HTML_PATH
-u <USER> User who runs the webserver
-g <GROUP> Group who runs the webserver
-w <PATH> Path to the webserver config files
-i <BACKENDs> Comma separated list of backends to use:
Available backends: mklivestatus, ndo2db, ido2db, merlinmy
Backend specific parameters:
ndo2db, ido2db:
-m <BINARY> Full path to the NDO/IDO module
Default value: \$BASE/bin/ndo2db
mklivestatus:
-l <SOCKET> MKLivestatus socket. Has to be in the following format:
TCP Socket: tcp:<ip>:<port>
Unix Socket: unix:<full-path>
Default value: unix:\$BASE/var/rw/live
Flag parameters:
-o Omit demo files
-a [y|n] Install the config file for the web server (y/n)
-r When performing an update of an existing NagVis installation the old
NagVis directory will be saved in a backup directory. When you know
what you are doing you can tell the installer to remove this backup
directory after a successful installation.
-q Quiet mode. The installer won't ask for confirmation of what to do.
The installer will use the hard coded options or the values given
by command line parameters.
This can be useful for automatic or scripted deployment
WARNING: Only use this if you know what you are doing
-F This is the force mode. Specifying this flag will call the installer
skip all validity checks and install NagVis with the given options
WARNING: Only use this if you know what you are doing
-c [y|n] Update configuration files when possible? Parses all existing
configuration files, checks for deprecated and missing options and
fixes known problems. This option has only effects when updating
mechanisms have been added to this installer.
-v Version information
-h This message
EOD
}
# Print version information
version() {
cat <<EOD
NagVis installer, version $INSTALLER_VERSION
Copyright (C) 2004-2011 NagVis Project (Contact: [email protected])
License: GNU General Public License version 2
Development:
- Wolfgang Nieder
- Lars Michelsen <[email protected]>
EOD
}
# Print line
line() {
[ $INSTALLER_QUIET -eq 1 ] && return
DASHES="--------------------------------------------------------------------------------------------------------------"
SIZE2=`expr $LINE_SIZE - 4`
if [ -z "$1" ]; then
OUT=`printf "+%${LINE_SIZE}.${LINE_SIZE}s+\n" $DASHES`
else
if [ -z "$2" ]; then
OUT=`printf "+--- %s\n" "$1"`
else
OUT=`printf "+--- %${SIZE2}.${SIZE2}s+\n" "$1 $DASHES"`
fi
fi
echo "$OUT"
}
# Print text
text() {
[ $INSTALLER_QUIET -eq 1 ] && return
SIZE2=`expr $LINE_SIZE - 3`
if [ -z "$1" ]; then
OUT=`printf "%s%${LINE_SIZE}s%s\n" "|" "" "|"`
else
if [ -z "$2" ]; then
OUT=`printf "%s\n" "$1"`
else
OUT=`printf "%-${LINE_SIZE}.${LINE_SIZE}s %s\n" "$1" "$2"`
fi
fi
echo "$OUT"
}
# Ask user for confirmation
confirm() {
echo -n "| $1 [$2]: "
read ANS
[ -z $ANS ] && ANS=$2
ANS=`echo $ANS | tr "jyos" "YYYY" | cut -c 1,1`
[ "$ANS" != "Y" ]&&ANS="N"
}
# Ask user for confirmation
check_confirm() {
ANS=`echo $ANS | tr "jyos" "yyyy" | cut -c 1,1`
if [ "$ANS" = "y" ]; then
return 0
else
return 0
fi
}
# Check Nagios path
check_nagios_path() {
if [ -d $NAGIOS_PATH ]; then
log " $SOURCE path $NAGIOS_PATH" "found"
return 0
else
log " $SOURCE path $NAGIOS_PATH" ""
return 1
fi
}
check_web_user() {
if [ "`getent passwd $WEB_USER | cut -d':' -f1`" = "$WEB_USER" ]; then
return 0
else
echo "| Error: User $WEB_USER not found."
return 1
fi
}
check_web_group() {
if [ "`getent group $WEB_GROUP | cut -d':' -f1`" = "$WEB_GROUP" ]; then
return 0
else
echo "| Error: Group $WEB_GROUP not found."
exit 1
fi
}
ask_user() {
VAR=$1
DEFAULT=$2
MANDATORY=$3
VERIFY_FUNC=$4
TEXT=$5
RETURN=1
while true; do
if [ $INSTALLER_QUIET -ne 1 ]; then
echo -n "| $TEXT [$DEFAULT]: "
read OPT
if [ ! -z $OPT ]; then
eval "${VAR}=$OPT"
else
eval "${VAR}=$DEFAULT"
fi
fi
if [ $MANDATORY -eq 1 -a "${!VAR}" != "" ] || [ $MANDATORY -eq 0 ]; then
if [ "$VERIFY_FUNC" != "" ]; then
${VERIFY_FUNC}
if [ $? = 0 ]; then
RETURN=0
fi
# In quiet mode break in all cases
if [ $INSTALLER_QUIET -eq 1 -o $RETURN = 0 ]; then
break
fi
else
RETURN=0
break
fi
else
break
fi
done
return $RETURN
}
# Print welcome message
welcome() {
[ $INSTALLER_QUIET -eq 1 ] && return
cat <<EOD
+------------------------------------------------------------------------------+
| $(printf "Welcome to NagVis Installer %-48s" $INSTALLER_VERSION) |
+------------------------------------------------------------------------------+
| This script is built to facilitate the NagVis installation and update |
| procedure for you. The installer has been tested on the following systems: |
| - Debian, since Etch (4.0) |
| - Ubuntu, since Hardy (8.04) |
| - SuSE Linux Enterprise Server 10 and 11 |
| |
| Similar distributions to the ones mentioned above should work as well. |
| That (hopefully) includes RedHat, Fedora, CentOS, OpenSuSE |
| |
| If you experience any problems using these or other distributions, please |
| report that to the NagVis team. |
+------------------------------------------------------------------------------+
EOD
ask_user "ANS" "y" 1 "check_confirm" \
"Do you want to proceed?"
if [ "$ANS" != "y" ]; then
text
text "| Installer aborted, exiting..." "|"
line ""
exit 1
fi
}
# Print module state, exit if necessary
log() {
[ $INSTALLER_QUIET -eq 1 ] && return
SIZE=`expr $LINE_SIZE - 8`
if [ -z "$2" ]; then
OUT=`printf "%-${SIZE}s %s\n" "| $1" "MISSING |"`
elif [ "$2" = "needed" ]; then
OUT="$1 needed"
elif [ "$2" = "warning" ]; then
OUT=`printf "%-${LINE_SIZE}s |\n" "| $1"`
elif [ "$2" = "done" ]; then
OUT=`printf "%-${SIZE}s %s\n" "| $1" " done |"`
elif [ "$2" = "no_ex" ]; then
SIZE=`expr $LINE_SIZE - 16`
OUT=`printf "%-${SIZE}s %s\n" "| $1" " not executable |"`
else
OUT=`printf "%-${SIZE}s %s\n" "| $1" " found |"`
fi
echo "$OUT"
}
# Tries to detect the Nagios path using the running Nagios process
# Will overwrite the NAGIOS_PATH when found some Nagios running
detect_nagios_path() {
IFS=$'\n'
init_id=1
os_type=`uname -s`
case $os_type in
SunOS) # In Solaris Zone, there's no init process (id = 1) but zsched (random id)
init_id=$(ps -ef | grep " zsched$" | grep -v grep | awk '{ print $2 }' | head -1)
;;
esac
for N_PROC in `
case $os_type in
SunOS) /bin/ps -ef -o pid,ppid,user,args ;;
*) ps ax -o pid,ppid,user,command ;;
esac | grep "bin/$SOURCE" | grep -v grep`; do
IFS=" "
# 2138 1 nagios /d/nagvis-dev/nagios/bin/nagios -d /d/nagvis-dev/nagios/etc/nagios.cfg
N_PID=`expr "$N_PROC" : ' *\([0-9]*\)'`
N_PPID=`expr "$N_PROC" : ' *[0-9]* *\([0-9]*\)'`
N_USR=`expr "$N_PROC" : ' *[0-9]* *[0-9]* *\([^ ]*\)'`
N_CMD=`expr "$N_PROC" : ' *[0-9]* *[0-9]* *[^ ]* *\(.*\)'`
echo "$N_CMD" | grep -i " -d" >/dev/null
if [[ $? -eq 0 && $N_PPID -eq $init_id ]]; then
N_BIN=${N_CMD%% *}
NAGIOS_PATH=${N_BIN%%/bin/$SOURCE}
NAGIOS_PATH=${NAGIOS_PATH%/}
fi
done
IFS=" "
}
# Tries to detect the correct path to the livestatus socket locally
detect_livestatus_socket() {
if [ -S "/var/run/nagios/rw/live" ]; then
LIVESTATUS_SOCK="unix:/var/run/nagios/rw/live"
elif [ -S "/var/run/icinga2/cmd/livestatus" ]; then
LIVESTATUS_SOCK="unix:/var/run/icinga2/cmd/livestatus"
else
LIVESTATUS_SOCK="unix:$NAGIOS_PATH/var/rw/live"
fi
}
# Check Backend module prerequisites
check_backend() {
# Do not ask in quiet mode
if [ $INSTALLER_QUIET -eq 0 ]; then
return
fi
# Ask to configure the backends during update
if [ $INSTALLER_ACTION = "update" ]; then
confirm "Do you want to update the backend configuration?" "n"
if [ "$ANS" = "N" ]; then
return
fi
fi
BACKENDS=""
text "| Checking Backends. (Available: $NAGVIS_BACKENDS)" "|"
if [ $INSTALLER_QUIET -ne 1 ]; then
if [ -z "$NAGVIS_BACKEND" ]; then
ASK=`echo $NAGVIS_BACKENDS | sed 's/,/ /g'`
for i in $ASK; do
DEFAULT="n"
if [ "$i" = "mklivestatus" ]; then
DEFAULT="y"
fi
confirm "Do you want to use backend $i?" $DEFAULT
if [ "$ANS" = "Y" ]; then
BACKENDS=$BACKENDS,$i
fi
done
NAGVIS_BACKEND=$BACKENDS
fi
NAGVIS_BACKEND=${NAGVIS_BACKEND#,}
fi
echo $NAGVIS_BACKEND | grep -i "MKLIVESTATUS" >/dev/null
if [ $? -eq 0 ]; then
[ -z "$LIVESTATUS_SOCK" ] && detect_livestatus_socket
# Check if the livestatus socket is available
# when not using a tcp socket
if [[ "$LIVESTATUS_SOCK" =~ unix:* ]]; then
if [ -S ${LIVESTATUS_SOCK#unix:} ]; then
log " Livestatus Socket (${LIVESTATUS_SOCK#unix:})" "found"
elif [ $INSTALLER_QUIET -ne 1 ]; then
# Loop until we got what we want in interactive mode
while [[ ! "$LIVESTATUS_SOCK" =~ tcp:* && ! -S ${LIVESTATUS_SOCK#unix:} ]]; do
log " Livestatus Socket (${LIVESTATUS_SOCK#unix:})" ""
text "| Valid socket formats are: tcp:127.0.0.1:7668 or unix:/path/to/live" "|"
echo -n "| Please enter your MKLivestatus socket: "
read APATH
if [ ! -z $APATH ]; then
LIVESTATUS_SOCK=$APATH
if [[ ! "$LIVESTATUS_SOCK" =~ unix:* && ! "$LIVESTATUS_SOCK" =~ tcp:* ]]; then
text "| Invalid socket format. Take a look above for valid formats." "|"
elif [[ ! "$LIVESTATUS_SOCK" =~ unix:* ]]; then
text "| Unable to check TCP-Sockets, hope you entered the correct socket." "|"
fi
fi
done
else
log " Livestatus Socket (${LIVESTATUS_SOCK#unix:})" ""
fi
CALL="$CALL -l \"$LIVESTATUS_SOCK\""
else
text "| Unable to check TCP-Sockets, hope you entered the correct socket." "|"
fi
# Check if php socket module is available
check_php_modules "sockets" "$NEED_PHP_VERSION"
if [ "$BACKENDS" = "" ]; then
BACKENDS="mklivestatus"
else
BACKENDS="${BACKENDS},mklivestatus"
fi
fi
echo $NAGVIS_BACKEND | grep -i "NDO2DB" >/dev/null
if [ $? -eq 0 ]; then
# Check ndo2db binary with version suffix
[ -z "$NDO_MOD" ]&&NDO_MOD="$NAGIOS_PATH/bin/ndo2db-3x"
NDO=`$NDO_MOD --version 2>/dev/null | grep -i "^NDO2DB"`
# Check ndo2db binary without version suffix
if [ -z "$NDO" ]; then
NDO_MOD="$NAGIOS_PATH/bin/ndo2db"
NDO=`$NDO_MOD --version 2>/dev/null | grep -i "^NDO2DB"`
fi
[ -z "$NDO" ]&&NDO_MOD="NDO Module ndo2db"
log " $NDO_MOD (ndo2db)" $NDO
# Check if php mysql module is available
check_php_modules "mysql" "$NEED_PHP_VERSION"
if [ "$BACKENDS" = "" ]; then
BACKENDS="ndo2db"
else
BACKENDS="${BACKENDS},ndo2db"
fi
fi
echo $NAGVIS_BACKEND | grep -i "IDO2DB" >/dev/null
if [ $? -eq 0 ]; then
# Check IDO
if [ -z "$NDO" ]; then
NDO_MOD="$NAGIOS_PATH/bin/ido2db"
fi
NDO=`$NDO_MOD --version 2>/dev/null | grep -i "^IDO2DB"`
[ -z "$NDO" ]&&NDO_MOD="IDO Module ido2db"
log " $NDO_MOD (ido2db)" $NDO
# Check if php mysql module is available
check_php_modules "mysql" "$NEED_PHP_VERSION"
if [ "$BACKENDS" = "" ]; then
BACKENDS="ido2db"
else
BACKENDS="${BACKENDS},ido2db"
fi
fi
# Check merlin prerequisites if necessary
echo $NAGVIS_BACKEND | grep -i "MERLINMY" >/dev/null
if [ $? -eq 0 ]; then
#text "| *** Sorry, no checks yet for merlin" "|"
# Check if php mysql module is available
check_php_modules "mysql" "$NEED_PHP_VERSION"
if [ "$BACKENDS" = "" ]; then
BACKENDS="merlinmy"
else
BACKENDS="${BACKENDS},merlinmy"
fi
fi
if [ -z "$BACKENDS" ]; then
log "NO (valid) backend(s) specified"
fi
BACKENDS=${BACKENDS#,}
[ ! -z "$BACKENDS" ] && CALL="$CALL -i $BACKENDS"
}
# Check Apache PHP module
check_apache_php() {
DIR=$1
[ ! -d $DIR ] && return
WEB_PATH=${DIR%%/}
if [ -d $DIR/conf-available ]; then
WEB_PATH=$WEB_PATH/conf-available
elif [ -d $DIR/conf.d ]; then
WEB_PATH=$WEB_PATH/conf.d
fi
# The apache user/group are defined by env vars in Ubuntu, set them here
[ -f $DIR/envvars ] && source $DIR/envvars
MODPHP=`find $DIR -type f -exec grep -ie "mod_php.*\.so" -e "libphp.*\.so" {} \; | tr -s " " | cut -d" " -f3 | uniq`
# Only try to detect user when not set or empty
if [ -z "$WEB_USER" ]; then
WEB_USER=`find $DIR -type f -name "*conf" -exec grep -i "^User" {} \; | grep -vi "UserDir" | cut -d" " -f2 | uniq`
VAR=`echo $WEB_USER | grep "$" >/dev/null 2>&1`
[ $? -eq 0 ] && WEB_USER=`eval "echo $WEB_USER"`
fi
# Only try to detect group when not set or empty
if [ -z "$WEB_GROUP" ]; then
WEB_GROUP=`find $DIR -type f -name "*.conf" -exec grep -i "^Group" {} \; | cut -d" " -f2 | uniq`
VAR=`echo $WEB_GROUP | grep "$" >/dev/null 2>&1`
[ $? -eq 0 ] && WEB_GROUP=`eval "echo $WEB_GROUP"`
fi
}
# Check Graphviz version by installed system package
check_graphviz_version() {
if [ "${PKG##/*/}" = "dpkg" ]; then
GRAPHVIZ_VER=`$PKG -l "graphviz" | grep "graphviz" | grep ii | awk -F' ' '{ print $3 }' | sed "s/-.*$//" | cut -d"." -f1,2`
elif [ "${PKG##/*/}" = "rpm" ]; then
GRAPHVIZ_VER=`$PKG -qa "graphviz" | sed "s/graphviz-//g" | sed "s/-.*$//" | cut -d"." -f1,2`
elif [ "${PKG##/*/}" = "pkginfo" ]; then
GRAPHVIZ_VER=`$PKG -l "SMCgviz" | grep VERSION | awk '{print $2}'`
else
GRAPHVIZ_VER=`$PKG list installed "graphviz" | grep "installed" | awk -F' ' '{ print $2 }' | sed "s/-.*$//" | cut -d"." -f1,2`
fi
GRAPHVIZ_FMT=`fmt_version $GRAPHVIZ_VER`
if [ -z "$GRAPHVIZ_VER" ]; then
log "WARNING: The Graphviz package was not found." "warning"
log " This may not be a problem if you installed it from source" "warning"
else
log "Graphviz $GRAPHVIZ_VER" $GRAPHVIZ_VER
if [ $GRAPHVIZ_FMT -lt $GRAPHVIZ_REQ ]; then
log "| Error: Version >= $1" "needed"
fi
fi
}
# Check Graphviz Modules
check_graphviz_modules() {
for MOD in $1
do
TMP=`which $MOD 2>/dev/null`
[ -z "$TMP" ] && TMP=`which $GRAPHVIZ_PATH/$MOD 2>/dev/null`
if [ -s "$TMP" ]; then
GV_MOD_VER=`$MOD -V 2>&1`
GV_MOD_VER=${GV_MOD_VER#*version }
GV_MOD_VER=${GV_MOD_VER% (*}
fi
log " Graphviz Module $MOD $GV_MOD_VER" $TMP
if [ -n "$GV_MOD_VER" ]; then
GV_MOD_FMT=`fmt_version $GV_MOD_VER`
if [ $GV_MOD_FMT -lt $GRAPHVIZ_REQ ]; then
log "| Error: Version >= $2" "needed"
fi
fi
done
}
# Check PHP Version
check_php_version() {
if [ "${PKG##/*/}" = "dpkg" ]; then
PHP_VER=`$PKG -l "php[0-9]" 2>/dev/null | grep "php" | grep ii | awk -F' ' '{ print $3 }' | sed "s/-.*$//" | cut -d"." -f1,2`
elif [ "${PKG##/*/}" = "rpm" ]; then
PHP_VER=`$PKG -qa "php[0-9]" | sed "s/php[0-9]\-//g" | sed "s/-.*$//" | cut -d"." -f1,2`
else
PHP_VER=`$PKG list installed "php[0-9]" 2>/dev/null | grep "installed" | awk -F' ' '{ print $2 }' | sed "s/-.*$//" | cut -d"." -f1,2`
fi
PHP=`which php 2>/dev/null`
if [ -z "$PHP_VER" ]; then
if [ -s "$PHP" -a -x "$PHP" ]; then
PHP_VER=`$PHP -v | head -1 | sed -e "s/PHP \([0-9\]\+\.[0-9\]\+\).*/\1/"`
fi
fi
log "PHP $PHP_VER" $PHP_VER
if [ -n "$PHP_VER" ]; then
PHP_FMT=`fmt_version $PHP_VER`
PHP_REQ=`fmt_version $NEED_PHP_VERSION`
if [ $PHP_FMT -lt $PHP_REQ ]; then
log "| Error: Version >= $1" "needed"
fi
fi
}
# Check PHP modules
check_php_modules() {
for MOD in $1
do
TMP=""
if [ "${PKG##/*/}" = "dpkg" ]; then
MOD_VER=`$PKG -l "php[0-9]-$MOD" 2>/dev/null | grep "php" | grep "ii" | awk -F' ' '{ print $3 }' | sed "s/-.*$//" | cut -d"." -f1,2`
elif [ "${PKG##/*/}" = "rpm" ]; then
MOD_VER=`$PKG -qa "php[0-9]?-$MOD" | sed "s/php[0-9]?\-$MOD-//g" | sed "s/-.*$//" | cut -d"." -f1,2`
else
MOD_VER=`$PKG list installed "php[0-9]-$MOD" 2>/dev/null | grep "php" | grep "installed" | awk -F' ' '{ print $2 }' | sed "s/-.*$//" | cut -d"." -f1,2`
fi
# maybe compiled in module
if [ -s "$PHP" -a -x "$PHP" ]; then
TMP=`$PHP -m 2>&1 | grep -i "^$MOD$"`
[ -z "$MOD_VER" -a -n "$TMP" ]&&MOD_VER="compiled_in"
fi
if [ -z "$TMP" ]; then
TMP=`find /etc/ -type f -name "php?" -exec grep -ie "$MOD" {} \; | cut -d"=" -f2`
fi
# RedHat: /etc/php.d/...
if [ -z "$TMP" -a -d /etc/php.d/ ]; then
TMP=`grep -ie "$MOD" /etc/php.d/* | cut -d"=" -f2`
fi
# Ubuntu: /etc/php5/conf.d
if [ -z "$TMP" -a -d /etc/php5/conf.d ]; then
TMP=`grep -ie "extension=$MOD" /etc/php5/conf.d/* | sed 's/.*=//;s/\.so*//'`
fi
log " PHP Module: $MOD $MOD_VER" $TMP
if [ -n "$MOD_VER" ]; then
if [ `echo "$2 $MOD_VER" | awk '{if ($1 > $2) print $1; else print $2}'` = $2 ]; then
log " WARNING: Module $MOD not found." "warning"
log " This may not be a problem. You can ignore this if your php" "warning"
log " was compiled with the module included" "warning"
fi
fi
done
}
# Check SQLite version
check_sqlite_version() {
if [ "${PKG##/*/}" = "dpkg" ]; then
SQLITE_VER=`$PKG -l "sqlite3" | grep "sqlite" | grep ii | awk -F' ' '{ print $3 }' | sed "s/-.*$//" | cut -d"." -f1,2`
elif [ "${PKG##/*/}" = "rpm" ]; then
SQLITE_VER=`$PKG -qa "sqlite" | sed "s/sqlite-//g" | sed "s/-.*$//" | cut -d"." -f1,2`
else
SQLITE_VER=`$PKG list installed "sqlite" | grep "installed" | awk -F' ' '{ print $2 }' | sed "s/-.*$//" | cut -d"." -f1,2`
fi
SQLITE_FMT=`fmt_version $SQLITE_VER`
if [ -z "$SQLITE_VER" ]; then
log "WARNING: The SQLite package was not found." "warning"
log " This may not be a problem if you installed it from source" "warning"
else
log "SQLite $SQLITE_VER" $SQLITE_VER
if [ $SQLITE_FMT -lt $SQLITE_REQ ]; then
log "| Error: Version >= $1" "needed"
fi
fi
}
# Check return code
chk_rc() {
LRC=$?
if [ $LRC -ne 0 ]; then
echo $* Return Code: $LRC
if [ $UNDO -eq 1 ]; then
ANS="n"
ask_user "ANS" "y" 1 "check_confirm" \
"Do you want to revert to old NagVis version?"
if [ "$ANS" = "y" ]; then
text "| Trying to revert to old NagVis version" "|"
text "| Renaming $NAGVIS_PATH to ${NAGVIS_PATH}_broken" "|"
[ -d $NAGVIS_PATH ]&& mv $NAGVIS_PATH ${NAGVIS_PATH}_broken
text "| Renaming $NAGVIS_PATH_BACKUP to $NAGVIS_PATH_OLD" "|"
[ -d $NAGVIS_PATH_BACKUP ]&& mv $NAGVIS_PATH_BACKUP $NAGVIS_PATH_OLD
fi
fi
exit 1
else
if [ "$2" != "" ]; then
echo "$2"
fi
fi
}
rename_template_files() {
DONE=""
# 1: source directory
SOURCE=$1
# 2: target directory
TARGET=$2
# 3: template type
TYPE=$3
[ -n "$LINE" ] && DONE=`log "$LINE" done`
FILES=`find $NAGVIS_PATH/$SOURCE -type f -printf "%f\n"`
IFS=$'\n'
for FILE in $FILES; do
IFS=" "
FILE_NEW=`echo "$FILE" | sed 's/tmpl\.//g' | sed "s/\.html/\.$TYPE\.html/g" | sed "s/\.css/\.$TYPE\.css/g"`
cp -p "$NAGVIS_PATH/$SOURCE/$FILE" "$NAGVIS_PATH/$TARGET/$FILE_NEW"
chk_rc "| Error renaming $TYPE template file ($SOURCE/$FILE to $TARGET/$FILE_NEW)" "$DONE"
done
IFS=" "
}
copy_dir_xpath() {
DONE=""
# 1: Exclude pattern
# 2: Old dir
# 3: New dir
[ -n "$LINE" ] && DONE=`log "$LINE" done`
# Get files and directories to copy. This takes only the elements in the
# given directory.
# FILES=`find $NAGVIS_PATH_BACKUP/$2 -mindepth 1 -maxdepth 1`
FILES=`find $NAGVIS_PATH_BACKUP/$2/* -prune 2> /dev/null`
# Maybe exclude some files
if [ "$1" != "" ]; then
FILES=`echo "$FILES" | grep -vE $1`
fi
if [ "$FILES" != "" ]; then
cp -pr `echo "$FILES" | xargs` $NAGVIS_PATH/$3
chk_rc "| Error copying dir $2 to $3" "$DONE"
fi
}
restore() {
copy $NAGVIS_PATH_BACKUP/$1 $NAGVIS_PATH/$1 "$2" "$3"
}
copy() {
DONE=""
# DEBUG: [ -n "$LINE" ] && line "$LINE"
[ -n "$LINE" ] && DONE=`log "$LINE" done`
[ -z "$3" ] && WHAT=$1 || WHAT=$3
# When trying to copy a file/dir which does not exist just skip it
if [[ "$1" != */ && ! -e "$1" ]]; then
return
fi
FILTER=
if [ "$4" != "" ]; then
for F in $4; do
FILTER=$FILTER\ --exclude\ $F
done
fi
rsync -aq -f "- .gitignore" $FILTER $1 $2
chk_rc "| Error copying $WHAT" "$DONE"
LINE=""
DONE=""
}
set_perm() {
if [ -d "$2" -o -f "$2" -o "${2#${2%?}}" = "*" ]; then
# Don't do anything when called with globbing and directory is empty
if [[ "${2#${2%?}}" = "*" && "`ls -1 "${2%*\*}"`" = "" ]]; then
return 0
else
DONE=`log "$2" done`
chmod $1 $2
chk_rc "| Error setting permissions for $2" "$DONE"
fi
fi
}
makedir() {
if [ ! -d $1 ]; then
DONE=`log "Creating directory $1..." done`
mkdir -p $1
chk_rc "| Error creating directory $1" "$DONE"
fi
}
# Main program starting
###############################################################################
# More (re)initialisations
# Version info
NAGVIS_TAG=`fmt_version "$NAGVIS_VER"`
[ -z "$NAGVIS_TAG" ]&&NAGVIS_TAG=01000000
if [ $NAGVIS_TAG -lt 01050000 ]; then
echo "Error: This installer version only installs NagVis 1.5x or newer"
exit 1
fi
S=`echo $* | grep -i "\-s icinga"`
[ $? -eq 0 ]&&SOURCE=icinga
# Default hardcoded Nagios path
NAGIOS_PATH="/usr/local/$SOURCE"
# Try to detect the Nagios path with some magic
detect_nagios_path
# Default hardcoded NagVis base
NAGVIS_PATH="${NAGIOS_PATH%%nagios}"
NAGVIS_PATH="${NAGVIS_PATH%/}/nagvis"
NAGVIS_PATH_OLD=$NAGVIS_PATH
# Default nagios share webserver path
HTML_PATH="/nagvis"
# Process command line options
if [ $# -gt 0 ]; then
while getopts "p:n:m:l:w:W:u:b:g:c:i:s:O:a:ohqvFr" options $OPTS; do
case $options in
n)
NAGIOS_PATH=${OPTARG%/}
;;
m)
NDO_MOD=$OPTARG
;;
l)
LIVESTATUS_SOCK=$OPTARG
;;
b)
GRAPHVIZ_PATH=$OPTARG
;;
p)
NAGVIS_PATH=${OPTARG%/}
NAGVIS_PATH_PARAM_SET=1
if [ $NAGVIS_PATH_OLD_PARAM_SET -eq 0 ]; then
NAGVIS_PATH_OLD=$NAGVIS_PATH
fi
;;
O)
NAGVIS_PATH_OLD=${OPTARG%/}
NAGVIS_PATH_OLD_PARAM_SET=1
;;
w)
WEB_PATH=${OPTARG%/}
;;
W)
HTML_PATH=$OPTARG
;;
u)
WEB_USER=$OPTARG
;;
g)
WEB_GROUP=$OPTARG
;;
i)
NAGVIS_BACKEND=$OPTARG
;;
o)
IGNORE_DEMO="demo*cfg demo*png demo*ini.php demo-*.csv"
;;
q)
INSTALLER_QUIET=1
;;
c)
INSTALLER_CONFIG_MOD=$OPTARG
;;
s)
SOURCE=`echo $OPTARG | tr [A-Z] [a-z]`
;;
a)
ACONF="$OPTARG"
;;
F)
FORCE=1
;;
r)
REMOVE="y"
;;
h)
usage
exit 0
;;
v)
version
exit 0
;;
*)
echo "Error: Unknown option."
usage
exit 1
;;
esac
done
fi
if [ $(($#-$OPTIND)) -gt 0 ]; then
echo "ERROR: Unprocessed command line parameter found. Maybe you provided an argument"
echo " (dash missing) instead of the supported parameters."
exit 1
fi
if [ $FORCE -eq 1 ]; then
if [ -z "$WEB_USER" -o -z "$WEB:GROUP" -o -z "$WEB_PATH" ]; then
echo "ERROR: Using '-F' you also have to specify '-u ...', '-g ...' and '-w ...'"
exit 1
fi
fi
find_bin()
{
bin=$1
case `uname -s` in
SunOS) which $bin | grep -v "^no $bin in" ;;
*) which $bin 2> /dev/null ;;
esac
}