forked from PatchDashboard/patchdashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·1950 lines (1796 loc) · 76.5 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
################################################################################
##
## Title: Patch Management Dashboard Installer
##
## Authors: jonsjava <[email protected]>
## metalcated <[email protected]>
##
## Date: 11/22/2014
##
## Version: 1.0 RC1
##
## Changelog: 0.1 - Initial Release
## 0.2 - Improved base installer for OS detection
## 0.3 - Script rework/overhaul. Added sql insert secion
## - Cleaned up and organized into functions
## 0.4 - Added crontab function rather than manual proc
## - Lots of logic added to read the existing db users
## - Check connections to the provided db info
## - Added virtualhost file to apache/httpd
## 0.5 - Fixed relative_path in rewrite check
## - Added SQL fixes for existing table data
## 0.6 - Added automated Debian flavor apache/php/mysql
## - Added automated Red Hat flavor apache/php/mysql
## - Added PHP Version check and cleaned up some output
## 0.7 - Added installation key for agent authentication
## - Added more logic for mysql root passwords
## - Added php install for unsupported versions
## - Fixed issue with mysql root password being setup on el5
## - Fixed some more issues with install apache/mysql/php on el5
## 0.8 - Added more logic for handling CentOS version installs
## 0.9 - Added a staged path and fixed how its copied to the web_dir
## 1.0 - Fixed password generation issues, default passwords now work
## - This is a release ready version :)
##
## RC1 - Updated the installer to handle new changes for RC1
##. 1.1 - Added EnableSSL function to setup SSL and certificates
##
#################################################################################
install_opts="db_host db_root_id db_root_pass db_user db_pass db_name new_web_admin new_web_admin_email new_web_admin_passwd new_web_duser new_web_duser_email new_web_duser_passwd your_company installation_key relative_path new_web_dir web_user"
upgrade_opts="web_dir relative_path";
function show_help {
cat <<EOF
Installer for PatchDashboard.
Options:
-ui|--unattended-install run installation without user interaction
required options are:
EOF
for var in $install_opts; do
echo " --$(echo $var | sed 's,_,-,g')"
done
cat <<EOF
-uu|--unattended-upgrade run upgrade without user interaction
required options are:
EOF
for var in $upgrade_opts; do
echo " --$(echo $var | sed 's,_,-,g')"
done
cat <<EOF
-g|--guided Interactive mode.
Beware: interactive mode makes changes to your system, like installing packages and changing iptables. This is fine on a clean system, but on a multi-purpose system you might want to go the --unattended-install route.
EOF
}
# parse command line parameters
GUIDED=""
UNATTENDED=""
FORCE="no"
while [[ $# -gt 0 ]]; do
key="$1"
shift
case $key in
-ui|--unattended-install)
UNATTENDED="YES"
ACTION="INSTALL"
;;
-uu|--unattended-upgrade)
UNATTENDED="YES"
ACTION="UPGRADE"
;;
--force)
FORCE="yes"
;;
-g|--guided)
GUIDED="YES"
;;
-h)
show_help
exit
;;
*)
found=""
for var in $install_opts $upgrade_opts; do
if [[ "--$(echo $var | sed 's,_,-,g')" == "$key" ]]; then
eval $var=\"$1\"
shift
found=1
break
fi
done
if [ -z "$found" ]; then
echo -e "Unknown option $key.\n"
show_help
exit 1
fi
;;
esac
done
# get hostname into var
export host_node=`hostname`
# generate random passwords
SERVER_IP=$(ip addr|grep inet|grep eth0|awk '{print $2}'|cut -d'/' -f1)
MY_PATH="`dirname \"$0\"`"
hash_pass_script="$MY_PATH/hash_pass.php"
password_salt=$(dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev)
function hash_password()
{
export password="$1"
$hash_pass_script "$password" "$password_salt"
}
function genPasswd()
{
local p=$1
[ "$p" == "" ] && p=12
export randomPass=$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${p} | xargs)
echo $randomPass
}
function genInstallKey()
{
export installation_key=$(< /dev/urandom tr -dc 'a-zA-Z0-9~!@#$%^&*_-' | head -c${1:-32}|sha256sum)
}
# get user running installer
user=`whoami`
# if user is not root, exit
if [ "$user" != "root" ]; then
echo -e "\e[31Error\e[0m: You must be root to install this!"
exit 0
fi
# get OS information and run applicable function
if [[ -f /etc/lsb-release && -f /etc/debian_version ]]; then
export os=$(lsb_release -s -d|head -1|awk {'print $1'})
export os_ver=$(lsb_release -s -d|head -1|awk {'print $2'}|cut -d "." -f 1)
elif [[ -f /etc/debian_version ]]; then
export os="$(cat /etc/issue|head -n 1|awk {'print $1'})"
export os_ver="$(cat /etc/debian_version|head -1|awk {'print $1'}|cut -d "." -f 1)"
elif [[ -f /etc/redhat-release ]]; then
if [[ "$os" = "Red" && $(grep -i enterprise /etc/redhat-release) != "" ]]; then
export os="Red Hat Enterprise"
export os_ver=$(cat /etc/redhat-release|head -1|awk {'print $7'}|cut -d "." -f 1)
elif [[ "$os" = "Red" ]]; then
export os="Red Hat"
export os_ver=$(cat /etc/redhat-release|head -1|awk {'print $6'}|cut -d "." -f 1)
else
export os=$(cat /etc/redhat-release|head -1|awk {'print $1'})
export os_ver=$(cat /etc/redhat-release|head -1|awk {'print $3'}|cut -d "." -f 1)
fi
else
export os=$(uname -s -r|head -1|awk {'print $1'})
export os_ver=$(uname -s -r|head -1|awk {'print $2'}|cut -d "." -f 1)
fi
# get DocumentRoot for error checking (not checked on all distros yet)
if [[ "$os" = "Ubuntu" ]] || [[ "$os" = "Debian" ]] || [[ "$os" = "Linux" ]]; then
export doc_root=$(grep -s DocumentRoot /etc/apache2/sites-enabled/*|head -n 1|awk {'print $3'})
elif [[ "$os" = "CentOS" ]] || [[ "$os" = "Fedora" ]] || [[ "$os" = "Red Hat" ]] || [[ "$os" = "Red Hat Enterprise" ]]; then
export doc_root=$(grep -s DocumentRoot /etc/httpd/conf/*|grep -v "#"|head -n 1|awk -F\" {'print $2'})
fi
## begin main functions of installer
function OSInstall()
{
echo -e "Running install for: \e[32m$os $os_ver\e[0m\n"
if [[ "$os" = "Ubuntu" ]] || [[ "$os" = "Debian" ]] || [[ "$os" = "Linux" ]]; then
apache_exists=$(which apache2)
php5_exists=$(which php)
mysqld_exists=$(which mysqld)
rsync_exists=$(which rsync)
if [[ "$os" = "Linux" ]] && [[ "$apache_exists" = "" ]]; then
echo -e "\n\e[31mNotice\e[0m: Please install the full LAMP stack before trying to install this application.\n\n\e[31mNotice\e[0m: https://community.rackspace.com/products/f/25/t/49\n"
exit 0
fi
if [[ "$rsync_exists" = "" ]]; then
echo -e "\e[31mNotice\e[0m: Rsync does not seem to be installed."
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
echo -e "\e[31mNotice\e[0m: Please wait while prerequisites are installed...\n\n\e[31mNotice\e[0m: Installing Rsync..."
while true;
do echo -n .;sleep 1;done &
apt-get install -y rsync >/dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
echo -e "\n\n\e[32mNotice\e[0m: Rsync Installation Complete\n"
fi
if [[ "$apache_exists" = "" ]]; then
echo -e "\e[31mNotice\e[0m: Apache/PHP does not seem to be installed."
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
echo -e "\e[31mNotice\e[0m: Please wait while prerequisites are installed...\n\n\e[31mNotice\e[0m: Installing Apache and PHP5..."
while true;
do echo -n .;sleep 1;done &
apt-get install -y apache2 apache2-threaded-dev apache2-utils curl > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
echo "ServerName localhost" >> /etc/apache2/httpd.conf
echo -e "\n\e[32mNotice\e[0m: Apache/PHP Installation Complete\n"
fi
if [[ "$php5_exists" = "" ]]; then
echo -e "\e[31mNotice\e[0m: PHP does not seem to be installed."
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
echo -e "\e[31mNotice\e[0m: Installing PHP5..."
while true;
do echo -n .;sleep 1;done &
apt-get install -y php5 libapache2-mod-php5 php5-mcrypt php5-common php5-gd php5-cgi php5-cli php5-fpm php5-dev php5-xmlrpc php5-mysql php5-sybase > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
echo -e "\n\n\e[32mNotice\e[0m: PHP Installation Complete\n"
fi
if [[ "$mysqld_exists" = "" ]]; then
echo -e "\e[31mNotice\e[0m: MySQL does not seem to be installed."
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
mysqlPasswd
if [[ "$mysql_passwd" != "$mysql_passwd_again" ]]; then
echo -e "\n\n\e[31mNotice\e[0m: Passwords do not match, please try again.\n"
mysqlPasswd
fi
debconf-set-selections <<< "mysql-server mysql-server/root_password password $mysql_passwd"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $mysql_passwd_again"
echo -e "\n\n\e[31mNotice\e[0m: Installing MySQL Client and Server..."
while true;
do echo -n .;sleep 1;done &
apt-get install -y mysql-client mysql-server php5-mysql php5-sybase libapache2-mod-auth-mysql libmysqlclient-dev > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
mysql_install_db > /dev/null 2>&1
echo -e "\nInstalling MySQL system tables...\nOK"
echo -e "Filling help tables...\nOK"
echo -e "\n\e[36mNotice\e[0m: You may run /usr/bin/mysql_secure_installation to secure the MySQL installation once this application setup has been completed."
echo -e "\n\e[32mNotice\e[0m: MySQL Installation Complete\n"
fi
web_dir="/var/www/patch_manager/"
web_user="www-data"
web_service="apache2"
echo -e "\e[32mChecking apache2 rewrite module\n\e[0m"
if [[ -z $(apache2ctl -M|grep rewrite) ]]; then
# enable rewrite modules
echo -e "\n\e[32mApache Module\e[0m: rewrite status = \e[31mdisabled\e[0m"
a2enmod rewrite > /dev/null 2>&1
echo -e "\n\e[32mApache Module\e[0m: rewrite enabled\n"
else
echo -e "\n\e[32mApache Module\e[0m: rewrite status = enabled\n"
fi
echo -e "\e[32mChecking if services are started\n\e[0m"
if [[ -n $(service mysql status|grep "stop/waiting") ]]; then
# enable mysqld
echo -e "\e[32mService\e[0m: mysql status = \e[31mstop/waiting\n\e[0m"
service mysql start
echo
else
echo -e "\e[32mService\e[0m: mysql status = started\n"
fi
# sanity checks
phpverCheck
PackageCheck
checkIPtables
elif [[ "$os" = "CentOS" ]] || [[ "$os" = "Fedora" ]] || [[ "$os" = "Red Hat" ]] || [[ "$os" = "Red Hat Enterprise" ]]; then
httpd_exists=$(rpm -qa | grep "httpd")
php_exists=$(rpm -qa | grep "php")
mysqld_exists=$(rpm -qa | grep "mysql-server")
rsync_exists=$(rpm -qa | grep "rsync")
if [[ "$rsync_exists" = "" ]]; then
echo -e "\e[31mNotice\e[0m: Rsync does not seem to be installed."
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
echo -e "\e[31mNotice\e[0m: Please wait while prerequisites are installed...\n\n\e[31mNotice\e[0m: Installing Rsync..."
while true;
do echo -n .;sleep 1;done &
yum install -y rsync >/dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
echo -e "\n\n\e[32mNotice\e[0m: Rsync Installation Complete\n"
fi
if [[ "$httpd_exists" = "" ]]; then
echo -e "\e[31mNotice\e[0m: Apache does not seem to be installed."
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
echo -e "\e[31mNotice\e[0m: Please wait while prerequisites are installed...\n\n\e[31mNotice\e[0m: Installing Apache..."
if [[ "$os_ver" = "5" ]]; then
while true;
do echo -n .;sleep 1;done &
yum install --disablerepo=webtatic -y httpd httpd-devel httpd-tools curl > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
else
while true;
do echo -n .;sleep 1;done &
yum install -y httpd httpd-devel httpd-tools curl > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
fi
echo -e "\n\e[32mNotice\e[0m: Apache Installation Complete\n"
echo -e "\e[32mChecking httpd start up config\n\e[0m"
if [[ -z $(chkconfig --list httpd|grep "2:on\|3:on\|5:on") ]]; then
# enable httpd at startup 235
echo -e "\e[32mChkConfig\e[0m: httpd status = \e[31mdisabled\e[0m"
chkconfig --level 235 httpd on
echo -e "\e[32mChkConfig\e[0m: httpd enabled\n"
else
echo -e "\e[32mChkConfig\e[0m: httpd status = enabled\n"
fi
fi
if [[ "$php_exists" = "" ]]; then
echo -e "\e[31mNotice\e[0m: PHP does not seem to be installed."
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
echo -e "\e[31mNotice\e[0m: Installing PHP5..."
while true;
do echo -n .;sleep 1;done &
yum install -y php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-cli php-pdo php-mssql > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
echo -e "\n\n\e[32mNotice\e[0m: PHP Installation Complete\n"
fi
if [[ "$mysqld_exists" = "" ]]; then
echo -e "\e[31mNotice\e[0m: MySQL does not seem to be installed."
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
mysqlPasswd
echo -e "\n\n\e[32m\e[4mMySQL Database Install and Setup\n\e[0m"
if [[ "$mysql_passwd" != "$mysql_passwd_again" ]]; then
echo -e "\e[31mNotice\e[0m: Passwords do not match, please try again.\n"
mysqlPasswd
fi
echo -e "\e[31mNotice\e[0m: Installing MySQL Client and Server..."
while true;
do echo -n .;sleep 1;done &
yum install -y mysql mysql-server mysql-devel > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
service mysqld restart > /dev/null 2>&1
mysql_install_db > /dev/null 2>&1
echo -e "\nInstalling MySQL system tables...\nOK"
echo -e "Filling help tables...\nOK"
echo -e "\n\e[36mNotice\e[0m: You may run /usr/bin/mysql_secure_installation to secure the MySQL installation once this application setup has been completed."
echo -e "\n\e[32mNotice\e[0m: MySQL Installation Complete\n"
echo -e "\e[32mChecking mysqld start up config\n\e[0m"
if [[ -z $(chkconfig --list mysqld|grep "2:on\|3:on\|5:on") ]]; then
# enable mysqld at startup 235
echo -e "\e[32mChkConfig\e[0m: mysqld status = \e[31mdisabled\e[0m"
chkconfig --level 235 mysqld on
echo -e "\e[32mChkConfig\e[0m: mysqld enabled\n"
else
echo -e "\e[32mChkConfig\e[0m: mysqld status = enabled\n"
fi
fi
web_dir="/var/www/patch_manager/"
web_user="apache"
web_service="httpd"
echo -e "\e[32mChecking if services are started\n\e[0m"
if [[ -n $(service mysqld status|grep "stopped") ]]; then
# enable mysqld
echo -e "\e[32mService\e[0m: mysqld status = \e[31mstopped\n\e[0m"
service mysqld restart
echo
else
echo -e "\e[32mService\e[0m: mysqld status = started\n"
fi
# set initial mysql root password
mysqlRootPwd
# sanity checks
phpverCheck
PackageCheck
checkIPtables
localhostChk
fi
}
function PackageCheck()
{
echo -e "\e[32mChecking for dependencies and missing packages\n\e[0m"
if [[ "$os" = "Ubuntu" ]] || [[ "$os" = "Debian" ]] || [[ "$os" = "Linux" ]]; then
pkgList="apache2 apache2-threaded-dev apache2-utils php5 libapache2-mod-php5 php5-mcrypt php5-common php5-gd php5-cgi php5-cli php5-fpm php5-dev php5-xmlrpc mysql-client mysql-server php5-mysql php5-sybase libapache2-mod-auth-mysql libmysqlclient-dev curl rsync"
echo -e "\e[31mWARNING\e[0m: Please keep in mind this is not a fool proof process, if you have 3rd party repo's, the automated package installer may fail.\n"
for package in $pkgList; do
dpkg-query -l $package > /dev/null 2>&1
if [[ "$?" = "1" ]]; then
echo -e "\e[32mPackage\e[0m: \e[36m$package\e[0m not installed, installing missing package"
while true;
do echo -n .;sleep 1;done &
apt-get install -y $package > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
echo -e "\n\e[32mPackage\e[0m: \e[36m$package\e[0m install complete\n"
fi
done
elif [[ "$os" = "CentOS" ]] || [[ "$os" = "Fedora" ]] || [[ "$os" = "Red Hat" ]] || [[ "$os" = "Red Hat Enterprise" ]]; then
ls /etc/yum/pluginconf.d/fastestmirror.conf > /dev/null 2>&1
if [[ "$?" = 0 ]]; then
if [[ $(grep "exclude=.at" /etc/yum/pluginconf.d/fastestmirror.conf) = "" ]]; then
echo "exclude=.at" >> /etc/yum/pluginconf.d/fastestmirror.conf
fi
fi
# check for extra repos
extraRepo=$(ls /etc/yum.repos.d/|grep 'remi\|webtatic')
if [[ "$?" = 0 ]]; then
if [[ $(yum list installed|grep -i "56") != "" ]]; then
pVer="56"
elif [[ $(yum list installed|grep -i "55") != "" ]]; then
pVer="55"
elif [[ $(yum list installed|grep -i "54") != "" ]]; then
pVer="54"
else
pVer=""
fi
pkgList="php php${pVer}-php-mysqlnd php${pVer}-php-common php${pVer}-php-gd php${pVer}-php-mbstring php${pVer}-php-mcrypt php${pVer}-php-devel php${pVer}-php-xml php${pVer}-php-cli php${pVer}-php-pdo php${pVer}-php-mssql mysql mysql-server mysql-devel httpd httpd-devel httpd-tools curl rsync"
else
pkgList="php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-cli php-pdo php-mssql mysql mysql-server mysql-devel httpd httpd-devel httpd-tools curl rsync"
fi
for package in $pkgList; do
if [[ $(yum list installed|grep "$package[.]") = "" ]]; then
repoName=$(echo $extraRepo|cut -d'.' -f 1|sed -e 's/ /,/g')
echo -e "\e[32mPackage\e[0m: \e[36m$package\e[0m not installed, installing missing package"
echo -e "\e[31mWARNING\e[0m: Detected 3rd party repos> $repoName - Please keep in mind this is not a fool proof process... but we try :)\n"
if [[ $? = 0 ]]; then
echo -e "\n\e[32m3rd Party Repos Exist\e[0m: $repoName, attempting to enable the specific repos before installing dependancies.\n"
while true;
do echo -n .;sleep 1;done &
yum install -y --enablerepo=$repoName $package > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
echo -e "\n\e[32mPackage\e[0m: \e[36m$package\e[0m install complete\n"
else
while true;
do echo -n .;sleep 1;done &
yum install -y --skip-broken $package > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM;
echo -e "\n\e[32mPackage\e[0m: \e[36m$package\e[0m install complete\n"
fi
fi
done
fi
}
function EnableSSL()
{
echo -e "\e[32mEnableSSL\e[0m: Preparing to setup SSL for the Patch Management Dashboard web interface."
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
if [[ "$os" = "Ubuntu" ]] || [[ "$os" = "Debian" ]] || [[ "$os" = "Linux" ]]; then
# set ssl key path
ssl_path="/etc/ssl"
# install SSL
a2enmod ssl
a2ensite default-ssl
echo
elif [[ "$os" = "CentOS" ]] || [[ "$os" = "Fedora" ]] || [[ "$os" = "Red Hat" ]] || [[ "$os" = "Red Hat Enterprise" ]]; then
# set ssl key path
ssl_path="/etc/pki/tls"
# install SSL
yum install mod_ssl openssl -y > /dev/null 2>&1
fi
# check existing keys, if not setup new
if [[ -f $ssl_path/private/ca.key ]]; then
echo -e "\e[31mSSL\e[0m: Keys already exist in $ssl_path/certs and $ssl_path/private.\n"
unset yn
read -p "Do you want to create a new keys? (yes/no): " yn
while [[ $yn = "" ]]; do
read -p "Do you want to create a new keys? (yes/no): " yn
done
echo
if [[ "$yn" = "yes" || "$yn" = "y" ]]; then
# ask questions for key generation
echo -e "\e[32mSSL\e[0m: Generating SSL Keys for $web_service"
echo -e "\e[32mSSL\e[0m: please answer the following questions for the the location of the hosted environment.\n"
read -p "Country: " country
while [[ $country = "" ]]; do
read -p "Country: " country
done
read -p "State: " state
while [[ $state = "" ]]; do
read -p "State: " state
done
read -p "City: " city
while [[ $city = "" ]]; do
read -p "City: " city
done
read -p "Orginization: " org
while [[ $org = "" ]]; do
read -p "Orginization: " org
done
read -p "Orginizational Unit: " orgu
while [[ $orgu = "" ]]; do
read -p "Orginizational Unit: " orgu
done
# generate private key
rm -rf $ssl_path/private/ca.key
openssl genrsa -out $ssl_path/private/ca.key 4096 > /dev/null 2>&1
# generate CSR
rm -rf $ssl_path/private/ca.csr
openssl req -new -subj "/C=$country/ST=$state/L=$city/O=$org/OU=$orgu/CN=$host_node" -key $ssl_path/private/ca.key -out $ssl_path/private/ca.csr
# generate Self Signed Key
rm -rf $ssl_path/private/ca.crt
openssl x509 -req -days 1095 -in $ssl_path/private/ca.csr -signkey $ssl_path/private/ca.key -out $ssl_path/certs/ca.crt
fi
else
# ask questions for key generation
echo -e "\e[32mSSL\e[0m: Generating SSL Keys for $web_service"
echo -e "\e[32mSSL\e[0m: please answer the following questions for the the location of the hosted environment.\n"
read -p "Country: " country
while [[ $country = "" ]]; do
read -p "Country: " country
done
read -p "State: " state
while [[ $state = "" ]]; do
read -p "State: " state
done
read -p "City: " city
while [[ $city = "" ]]; do
read -p "City: " city
done
read -p "Orginization: " org
while [[ $org = "" ]]; do
read -p "Orginization: " org
done
read -p "Orginizational Unit: " orgu
while [[ $orgu = "" ]]; do
read -p "Orginizational Unit: " orgu
done
# generate private key
rm -rf $ssl_path/private/ca.key
openssl genrsa -out $ssl_path/private/ca.key 4096 > /dev/null 2>&1
# generate CSR
rm -rf $ssl_path/private/ca.csr
openssl req -new -subj "/C=$country/ST=$state/L=$city/O=$org/OU=$orgu/CN=$host_node" -key $ssl_path/private/ca.key -out $ssl_path/private/ca.csr
# generate Self Signed Key
rm -rf $ssl_path/private/ca.crt
openssl x509 -req -days 1095 -in $ssl_path/private/ca.csr -signkey $ssl_path/private/ca.key -out $ssl_path/certs/ca.crt
echo
fi
echo -e "\e[32m\e[4mWebpage Location Setup\e[0m\n"
unset new_web_dir
read -p "Please enter location for web interface [Default: $web_dir]: " new_web_dir
while [[ "$new_web_dir" = "" ]]; do
echo -e "\e[32mNotice\e[0m: Default Location Used: $web_dir"
new_web_dir=$web_dir
done
echo $new_web_dir|grep --word-regexp "${doc_root%%/html}" > /dev/null 2>&1
if [[ "$?" = 1 ]]; then
echo -e "\n\e[31mNotice\e[0m: $new_web_dir is not within the DocumentRoot: $doc_root\n\e[31mNotice\e[0m: Please try again.\n"
WebUIInfo
fi
echo
unset new_relative_path
read -p "Please enter the relative path [Default: $relative_path]: " new_relative_path
while [[ "$new_relative_path" = "" ]]; do
echo -e "\e[32mNotice\e[0m: Default Location Used: $relative_path"
new_relative_path=$relative_path
relpath=$(echo $new_relative_path|cut -d '/' -f 2)
done
echo
if [ "$new_relative_path" != "$relative_path" ] && [ "$new_relative_path" != "" ]; then
relative_path="$new_relative_path"
fi
if [ "${new_relative_path: -1}" != "/" ]; then
new_relative_path=$new_relative_path"/"
fi
if [ "$new_web_dir" != "$web_dir" ] && [ "$new_web_dir" != "" ]; then
web_dir="$new_web_dir"
fi
if [ "${web_dir: -1}" != "/" ]; then
web_dir=$web_dir"/"
fi
if [[ $(grep "$ssl_path/certs/ca.crt" /etc/$web_service/conf.d/patch_manager.conf) = "" ]]; then
targetdir=$(echo $new_web_dir|sed 's=/[^/]*$==;s/\.$//')
echo -e "\e[32mSSL\e[0m: Adding SSL configuration to /etc/$web_service/conf.d/patch_manager.conf\n"
cat <<EOA >> /etc/$web_service/conf.d/patch_manager.conf
NameVirtualHost *:443
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile $ssl_path/certs/ca.crt
SSLCertificateKeyFile $ssl_path/private/ca.key
<Directory $targetdir>
AllowOverride All
</Directory>
DocumentRoot $targetdir
ServerName localhost
</VirtualHost>
EOA
else
echo -e "\e[31mSSL\e[0m: SSL configuration already exists in /etc/$web_service/conf.d/patch_manager.conf\n"
fi
# process web service restart
service $web_service restart
rewrite_check=`curl -s localhost${relative_path}rewrite_check|grep 404|wc -l`
if [ "$rewrite_check" = "1" ]; then
echo -e "\n\e[31mError\e[0m: Apache Mod_rewrite or .htaccess is not working. Please ensure you have mod_rewrite installed and enabled. If it is, please make sure you change 'AllowOverride None' to 'AllowOverride All'"
echo -e "\e[31mError\e[0m: If you don't, this site won't work. \e[31mYou've been warned\e[0m."
fi
echo -e "\n\e[32mNotice\e[0m: SSL installation is now complete. You can now go to https://${host_node}${relative_path}\n"
exit 0
}
function phpversion()
{
echo "$@" | awk -F. '{ printf("%d.%d.%d\n", $1,$2,$3); }';
}
function phpverCheck()
{
phpver=$(php --version|grep "PHP 5"|awk {'print $2'})
if [[ $(phpversion $phpver) < $(phpversion 5.2.0) ]]; then
echo -e "\e[0mYou are running PHP Version: \e[031m$phpver\e[0m which is incompatible with this application.\n"
phpExtraInst
fi
}
function phpExtraInst()
{
#export CentOSVer="5"
echo -e "\e[32mPHP Install\e[0m: Installing PHP 5.3/5.4 depending on your distro\n"
echo -e "\e[32mPHP Install\e[0m: Adding EPEL and WebTatic Repos"
rpm -Uvh "http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm" > /dev/null 2>&1
rpm -Uvh "http://repo.webtatic.com/yum/centos/5/latest.rpm" > /dev/null 2>&1
sed -i 's/enabled=0/enabled=1/g' /etc/yum.repos.d/webtatic.repo
unset wait
echo -e "\e[32m";read -p "Press enter to continue install" wait;echo -e "\e[0m"
echo -e "\e[32mPHP Install\e[0m: Installing PHP5.3 or greater..."
while true;
do echo -n .;sleep 1;done &
yum install -y php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml php-cli php-pdo php-php-gettext php-tidy > /dev/null 2>&1
kill $!; trap 'kill $!' SIGTERM
echo -e "\n\e[32mPHP Install\e[0m: PHP Installation Complete\n"
echo -e "Running OS Check and Dependacies check again, please wait...\n"
sleep 3
$0
exit 0
}
function checkIPtables()
{
if [[ $(iptables -L|grep "dpt:http\|dpt:https") = "" ]]; then
echo -e "\e[32mIptables\e[0m: Enabling port 80 and 443 on iptables\n"
# detect which OS
if [[ "$os" = "Ubuntu" ]] || [[ "$os" = "Debian" ]] || [[ "$os" = "Linux" ]]; then
if [[ $(dpkg -s iptables-persistent|grep "Status:"|cut -d " " -f2-4) != "install ok installed" ]]; then
# install iptables-persistent
echo -e "\n\e[32mIptables\e[0m: $os detected, installing iptables-persistent\n"
debconf-set-selections <<< "iptables-persistent iptables-persistent/autosave_v4 boolean true"
debconf-set-selections <<< "iptables-persistent iptables-persistent/autosave_v6 boolean true"
apt-get install -y iptables-persistent > /dev/null 2>&1
fi
# add rules and save
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
service iptables-persistent save
echo
elif [[ "$os" = "CentOS" ]] || [[ "$os" = "Fedora" ]] || [[ "$os" = "Red Hat" ]] || [[ "$os" = "Red Hat Enterprise" ]]; then
# add rules and save
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
service iptables save
echo
fi
fi
}
function localhostChk()
{
servername=$(grep "ServerName" /etc/httpd/conf/httpd.conf|grep -v "#"|awk {'print $2'})
if [[ "$servername" != "localhost" ]]; then
if [[ "$servername" = "" ]]; then
echo "ServerName localhost" >> /etc/httpd/conf/httpd.conf
else
unset yn
echo -e "\e[32mServerName\e[0m: Current Apache ServerName = $servername\n"
read -p "Is the ServerName correct? [Enter 'yes' to skip and 'no' to enter localhost as ServerName] (y/n): " yn
while [[ "$yn" != "yes" && "$yn" != "no" && "$yn" != "y" && "$yn" != "n" ]]; do
read -p "Is this ServerName correct? [Enter 'yes' to skip and 'no' to enter localhost as ServerName] (y/n): " yn
echo
done
if [[ "$yn" = "yes" ]] || [[ "$yn" = "y" ]]; then
echo -e "\n\e[32mServerName\e[0m: Skipping"
else
echo
sed -i 's/'$servername'/localhost/g' /etc/httpd/conf/httpd.conf
fi
fi
fi
}
function mysqlPasswd()
{
echo -e "Create a new password for the root MySQL account\n"
unset mysql_passwd
read -s -p "Enter MySQL $db_root_id password: " mysql_passwd
while [[ "$mysql_passwd" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide the MySQL $db_root_id password, please try again.\n"
read -p "Enter MySQL $db_root_id password: " mysql_passwd
done
echo
unset mysql_passwd_again
read -s -p "Enter MySQL $db_root_id password again: " mysql_passwd_again
while [[ "$mysql_passwd_again" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide the MySQL $db_root_id password again, please try again.\n"
read -p "Enter MySQL $db_root_id password again: " mysql_passwd_again
export mysql_passwd_again
done
}
function mysqlRootPwd()
{
if [[ $(mysqladmin -s status) != "" ]]; then
if [[ "$mysql_passwd_again" = "" ]] && [[ "$mysqld_exists" != "" ]]; then
echo -e "\e[32mMySQL\e[0m: Your root password is blank, this will cause an issue during setup.\n"
mysqlPasswd
mysqladmin password "$mysql_passwd_again"
echo -e "\n"
else
mysqladmin password "$mysql_passwd_again"
fi
else
echo -e "\e[32mMySQL\e[0m: Root password already setup, skipping.\n"
fi
}
function dbAskHost()
{
echo -e "\e[4m\e[32mDatabase Setup\e[0m\n\nThis step will create the user, set the password and create the database.\n"
unset db_host
read -p "Database Host: " db_host
while [[ "$db_host" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide a Database Host, please try again.\n"
read -p "Database Host: " db_host
done
if [[ "$db_host" != "localhost" ]]; then
echo -e "\n\e[31mNotice\e[0m: You have provided a host other than the localhost, please ensure you have correctly setup remote"
echo -e "\e[31mNotice\e[0m: access for the MySQL root account or provide an elevated ID with permissions to create new accounts.\n"
unset yn
read -p "Are you using a MySQL account other than root? (yes/no): " yn
while [[ "$yn" = "" ]]; do
read -p "Are you using a MySQL account other than root? (yes/no): " yn
done
if [[ "$yn" = "yes" || "$yn" = "y" ]]; then
dbAskElevatedUser
fi
fi
ping -c 1 $db_host > /dev/null 2>&1
if [ $? -gt 0 ]; then
echo -e "\n\e[31mNotice\e[0m: Inactive host: \e[36m$db_host\e[0m, please try again.\n"
dbAskHost
fi
}
function dbAskUser()
{
echo -e "\n\nEnter the database username and password you want to use for the application.\n"
unset db_user
read -p "Database User: " db_user
while [[ "$db_user" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide a Database User, please try again.\n"
read -p "Database User: " db_user
done
}
function dbAskElevatedUser()
{
echo -e "\nEnter the MySQL Elevated username and password your using to create the database user with.\n"
unset db_root_id
read -p "Elevated Database ID: " db_root_id
while [[ "$db_root_id" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide a MySQL Elevated User, please try again.\n"
read -p "Elevated Database ID: " db_root_id
done
}
function dbAskPass()
{
unset db_pass
read -s -p "Database Pass: " db_pass
echo
while [[ "$db_pass" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide a Database Password, please try again.\n"
read -s -p "Database Pass: " db_pass
echo
done
unset db_pass_again
read -s -p "Database Pass again: " db_pass_again
echo
while [[ "$db_pass_again" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide a Database Passwordi again, please try again.\n"
read -s -p "Database Pass again: " db_pass_again
echo
done
if [[ "$db_pass" != "$db_pass_again" ]]; then
echo -e "\n\n\e[36mNotice\e[0m: Database User passwords do not match, please try again.\n"
dbAskPass
fi
}
function dbAskName()
{
unset db_name
read -p "Database Name: " db_name
while [[ "$db_name" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide a Database Name, please try again.\n"
read -p "Database Name: " db_name
done
export db_name
}
function dbCheck()
{
# check if database exists
db_exists=$(mysql --batch -u $db_root_id -p$db_root_pass -h $db_host --skip-column-names -e "show databases like '"$db_name"';" | grep "$db_name" > /dev/null; echo "$?")
if [ $db_exists -eq 0 ];then
dbExists=yes
else
dbExists=no
fi
}
function dbConnTest()
{
# check connection to db
if [[ ${#} -gt 0 && "$1" == "root" ]]; then
db_connx=$(mysql --batch -u $db_root_id -p"$db_root_pass" -h $db_host -e ";" > /dev/null; echo "$?")
else
db_connx=$(mysql --batch -u $db_user -p"$db_pass" -h $db_host -e ";" > /dev/null; echo "$?")
fi
if [ $db_connx -eq 0 ];then
dbConnx=yes
else
dbConnx=no
fi
}
function dbRootPasswd()
{
# set db_host if not set
if [[ "$db_host" = "" ]]; then
export db_host="localhost"
fi
unset db_root_pass
echo
read -s -p "Enter the MySQL $db_root_id password: " db_root_pass
while [[ "$db_root_pass" = "" ]]; do
echo -e "\n\e[36mNotice\e[0m: Please provide the $db_root_id password, please try again.\n"
read -s -p "Enter the MySQL $db_root_id password: " db_root_pass
echo
done
if [[ "$db_host" != "localhost" ]]; then
echo -e "\n"
fi
db_root_connx=$(mysql --batch -u $db_root_id -h $db_host -p"$db_root_pass" -e ";" > /dev/null; echo "$?"; echo)
while [[ "$db_root_connx" -eq 1 ]]; do
echo -e "\n\e[31mNotice\e[0m: Unable to connect to mysql, please try again."
echo -e "\n\e[36mNotice\e[0m: You may run /usr/bin/mysql_secure_installation to secure the MySQL installation and set the $db_root_id password.\n"
unset yn
read -p "Do you want to try again or exit? [yes to continue, no to exit] (y/n): " yn
while [[ "$yn" != "yes" && "$yn" != "no" && "$yn" != "y" && "$yn" != "n" ]]; do
read -p "Do you want to try again or exit? [yes to continue, no to exit] (y/n): " yn
echo
done
if [[ "$yn" = "no" ]] || [[ "$yn" = "n" ]]; then
echo -e "\n\e[32mExiting Installation as per your response.\n\e[0m"
sleep 2
exit 0
else
echo
read -s -p "Enter the MySQL $db_root_id password: " db_root_pass
db_root_connx=$(mysql --batch -u $db_root_id -h $db_host -p"$db_root_pass" -e ";" > /dev/null; echo "$?"; echo)
fi
done
}
function dbUserDBCreate()
{
while read user; do
if [[ "$db_user" == "$user" ]]; then
echo -e "\n\e[31mNotice\e[0m: $user already exists. Skipping."
break
fi
done < <(mysql --batch --skip-column-names -u $db_root_id -h $db_host -p"$db_root_pass" -e 'use mysql; SELECT `user` FROM `user`;')
if [[ "$db_user" != "$user" ]]; then
echo -e "\n\e[32mNotice\e[0m: Creating \e[32m$db_user\e[0m and granting all privileges on \e[36m$db_name\e[0m"
mysql -u $db_root_id -h $db_host -p"$db_root_pass" -e "CREATE USER '$db_user'@'$db_host' IDENTIFIED BY '$db_pass';"
mysql -u $db_root_id -h $db_host -p"$db_root_pass" -e "GRANT ALL PRIVILEGES ON $db_name.* TO '$db_user'@'$db_host';"
mysql -u $db_root_id -h $db_host -p"$db_root_pass" -e "FLUSH PRIVILEGES;"
fi
unset user
}
function dbCreate()
{
if [[ "$db_user" = "" ]]; then
mysql -u $db_root_id -h $db_host -p"$db_pass" -e "create database $db_name;"
mysql -u $db_root_id -h $db_host -p"$db_pass" -D $db_name < database/db_create.sql
mysql -u $db_root_id -h $db_host -p"$db_pass" -D $db_name < database/centos_data.sql
else
mysql -u $db_user -h $db_host -p"$db_pass" -e "create database $db_name;"
mysql -u $db_user -h $db_host -p"$db_pass" -D $db_name < database/db_create.sql
mysql -u $db_user -h $db_host -p"$db_pass" -D $db_name < database/centos_data.sql
fi
}
function dbUpdate()
{
if [[ "$db_user" = "" ]]; then
mysql -u $db_root_id -h $db_host -p"$db_pass" -s -D $db_name < database/db_update.sql
mysql -u $db_root_id -h $db_host -p"$db_pass" -D $db_name < database/centos_data.sql
else
mysql -u $db_user -h $db_host -p"$db_pass" -s -D $db_name < database/db_update.sql
mysql -u $db_user -h $db_host -p"$db_pass" -D $db_name < database/centos_data.sql
fi
}
function WebDaemonUser()
{
unset new_web_user
read -p "Please enter the web user [Default: $web_user]: " new_web_user
echo $new_web_user|grep -P '[^\w\xC0-\xFF]' > /dev/null 2>&1
if [[ "$?" = 0 ]]; then
echo -e "\n\e[31mError:\e[0m Invalid name, non-alphanumeric characters are not allowed.\n"
WebDaemonUser
fi
while [[ "$new_web_user" = "" ]]; do
echo -e "\e[32mNotice\e[0m: Using Default WebUser $web_user"
new_web_user=$web_user
done
echo
if [ "$new_web_user" != "$web_user" ] && [ "$new_web_user" != "" ]; then
web_user="$new_web_user"
fi
}
function WebiUIAdmin()
{
# Web-UI admin username
unset new_web_admin
read -p "Web Interface Admin [Default: $web_admin]: " new_web_admin
echo $new_web_admin|grep -P '[^\w\xC0-\xFF]' > /dev/null 2>&1
if [[ "$?" = 0 ]]; then
echo -e "\n\e[31mError:\e[0m Invalid name, non-alphanumeric characters are not allowed.\n"
WebiUIAdmin
fi
while [[ "$new_web_admin" = "" ]]; do
echo -e "\e[32mNotice\e[0m: Default Web Admin used: $web_admin"
new_web_admin=$web_admin
done
echo
}
function WebUIDUser()
{
unset new_web_duser
read -p "Web Interface User [Default: $web_duser]: " new_web_duser
echo $new_web_duser|grep -P '[^\w\xC0-\xFF]' > /dev/null 2>&1
if [[ "$?" = 0 ]]; then
echo -e "\n\e[31mError:\e[0m Invalid name, non-alphanumeric characters are not allowed.\n"
WebUIDUser
fi
while [[ "$new_web_duser" = "" ]]; do
echo -e "\e[32mNotice\e[0m: Default User used: $web_duser."
new_web_duser=$web_duser
done
echo
}
function WebUIAPWConfirm()
{
if [[ "$new_web_admin_passwd" = "" ]]; then
read -s -p "Web Admin Password [Default: $web_admin_passwd]: " new_web_admin_passwd
echo
read -s -p "Web Admin Password Confirm: " new_web_admin_passwd_confirm
echo
else
echo
read -s -p "Web Admin Password Confirm: " new_web_admin_passwd_confirm