-
Notifications
You must be signed in to change notification settings - Fork 2
/
centos-postinstall
executable file
·1839 lines (1666 loc) · 62.2 KB
/
centos-postinstall
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
# centos-postinstall
# This script takes care of all post install work
# Copyright (C) 2014-2015 Alexander Swen <alex@swen.nu>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 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, see <http://www.gnu.org/licenses/>.
# Alexander Swen
# Private contact: alex@swen.nu
# CHANGELOG:
# 29-11-2006 A.Swen created.
# 17-07-2007 A.Swen updated for different OS levels
# TODO
# Off course this script is obsoleted by the powers of puppet. I moved it in
# this repo just because it has some neat tricks that might be usefull for
# others or as a reference for myself.
# SETTINGS
export date=$(date +%Y%m%d)
export me=$(basename $0)
export mydir=$(dirname $0)
tmp_dir=${mydir}
[ -f ${tmp_dir}/serverprofile ] && . ${tmp_dir}/serverprofile
is_vmware_guest=$([ "$(dmidecode|grep -A 1 "System Information"|tail -1|grep VMware)" ] && echo 1 || echo 0)
is_kvm_guest=$([ "$(dmidecode|grep -A 1 "BIOS Information"|tail -1|grep QEMU)" ] && echo 1 || echo 0)
if [ ${is_vmware_guest} -eq 1 -o ${is_kvm_guest} -eq 1 ];then
services_to_stop="qemu lm_sensors iscsi iscsid libvirtd firstboot bluetooth pcscd gpm exim sendmail mdmonitor microcode.ctl restorecond yum-updatesd sendmail isdn pcmcia cups smartd"
else
cpubrand=cat /proc/cpuinfo |awk '/vendor_id/ {print $3}'|tail -1
services_to_stop="$([ "${cpubrand}" = "GenuineIntel" ] || echo "microcode.ctl") pcscd restorecond yum-updatesd sendmail isdn pcmcia cups"
fi
# FUNCTIONS
die () {
rc=$1
shift
echo "==========================">&2
echo "==== FATAL ERROR ====" >&2
echo "==========================">&2
echo "" >&2
echo $@ >&2
exit $rc
}
check_lvm () {
echo "========================== Configure LVM ========================="
for lv in /dev/mapper/vg_*;do
lvname=$(echo ${lv}|awk -F - '{print $2}')
vgname=$(echo ${lv}|awk -F - '{print $1}'|sed -e 's/.*vg_/vg_/g')
lvmountpoint=/$([ "${type}" = "db" ] && echo data/)$(echo ${lvname}|sed -e 's/lv_//g')
[ "$(mount|egrep "${lvmountpoint}|${lvname}")" ] && continue
[ "$(egrep "${lv}|${lvname}|${lvmountpoint}" /etc/fstab)" ] && continue
[ -z "${lvname}" -o -z "${lv}" -o -z "${vgname}" -o -z "${lvmountpoint}" ] && continue
[ ! -d "${lvmountpoint}" ] && mkdir -p "${lvmountpoint}" || continue
echo -e "Adding /dev/${vgname}/${lvname}\t${lvmountpoint}\text3\tdefaults\t0\t0 to fstab"
echo -e "/dev/${vgname}/${lvname}\t${lvmountpoint}\text3\tdefaults\t0\t0" >> /etc/fstab
mount ${lvmountpoint}
done
}
mk_filesystems () {
echo "===================== configure filesystems ======================"
for x in ${datadir}/{backup,software,scripts};do [ ! -d "${x}" ] && install -dm 770 -o root -g staff "${x}";done
lvs|awk '/lv_/ && ! /data/ && ! /swap/ {print $1" "$2}'|while read lvname vgname;do
export lvname vgname
tune2fs -L ${lvname} -r 1 -c 30 /dev/${vgname}/${lvname}
perl -pi -e 's?/dev/$ENV{vgname}/$ENV{lvname}?LABEL=$ENV{lvname} ?g' /etc/fstab
done
lvs|awk '/swap/ {print $1" "$2}'|while read lv_swap vg_swap;do
export lv_swap vg_swap
if [ -n "${lv_swap}" -a -n "${vg_swap}" ];then
mkswap -L ${lv_swap} /dev/${vg_swap}/${lv_swap}
perl -pi -e 's?/dev/$ENV{vg_swap}/$ENV{lv_swap}?LABEL=$ENV{lv_swap} ?g' /etc/fstab
fi
done
awk '/boot/ && ! /tftpboot/ {print $1}' /etc/fstab|while read boot;do
export boot
tune2fs -L boot ${boot}
perl -pi -e 's?$ENV{boot}?LABEL=boot ?g' /etc/fstab
done
mount -o remount,acl /data
chcon -t var_t /data
groupadd data_ro
groupadd data_rw
setfacl -m g:data_ro:rx /data
setfacl -m d:g:data_ro:rx /data
setfacl -m g:data_rw:rwx /data
setfacl -m d:g:data_rw:rwx /data
setfacl -m g:staff:rwx /data
setfacl -m d:g:staff:rwx /data
}
create_staff_user() {
unset shell
[ -e /bin/bash3 ] && shell="-s /bin/bash3"
[ "$(grep "$2" /etc/passwd)" = "" ] && ${addcmd} -u "$1" -G staff,wheel -p "$4" -c "$3" $shell "$2"
if [ ${#5} -gt 0 ]; then
h="/home/$2"
[ ! -d $h/.ssh ] && mkdir -p $h/.ssh
chmod 700 $h
chmod 700 $h/.ssh
echo "$5" >> $h/.ssh/authorized_keys
chmod 600 $h/.ssh/authorized_keys
chown -R $2:staff $h
fi
echo "Created staff user $2 ${3}"
}
getfile () {
[ -z "${dirowner}" ] && dirowner=${owner}
echo "Getting file ${getfile} from ${inst_server} and saving as ${tgtpath}/${tgtfile}"
[ ! -d "${tgtpath}" ] && mkdir -p ${tgtpath}
wget -q $([ ! "${os_version}" = "4.0-32" ] && echo "--no-cache ")http://${inst_server}/inst/cfgfiles/${getfile} -O ${tgtpath}/${tgtfile}
[ ! "${tgtpath}" = "/etc" ] && chown ${dirowner}:${owngrp} "${tgtpath}"
chmod ${dirperm} "${tgtpath}"
chown ${owner}:${owngrp} ${tgtpath}/${tgtfile}
chmod ${perm} ${tgtpath}/${tgtfile}
unset dirowner
}
enableservice () {
if [ -f /etc/init.d/${1} ];then
echo Starting service ${1}
/sbin/chkconfig --add ${1}
/sbin/chkconfig ${1} on
fi
}
conf_logrotate_small_disk () {
echo "============= Configure logrotate for small disks ================"
perl -pi -e '
s/week/dai/g ;
s/^#compress/compress/g ;
s/^rotate 4/rotate 2/g '\
/etc/logrotate.conf
}
mk-dns-server () {
echo "========================== Configure DNS ========================="
export nameddir=/var/named/chroot
# perl -pi -e ' s?CHROOT_PREFIX="/var/lib/named"?CHROOT_PREFIX="$ENV{nameddir}"? ' /etc/init.d/named
# perl -pi -e ' s?^NAMED_RUN_CHROOTED=.*?NAMED_RUN_CHROOTED=yes? ' /etc/sysconfig/named
# mknod ${nameddir}/dev/null c 1 3
# mknod ${nameddir}/dev/random c 1 8
# chmod 666 ${nameddir}/dev/{null,random}
# cp /etc/localtime ${nameddir}/etc
# perl -pi -e 's?SYSLOGD_ADDITIONAL_SOCKET_NAMED=.*?SYSLOGD_ADDITIONAL_SOCKET_NAMED="$ENV{nameddir}/dev/log"? ' /etc/sysconfig/syslog
# find ${nameddir} -type d -exec chmod 700 {} \;
# find ${nameddir} -type f -exec chmod 600 {} \;
# # configure logrotate for named
cat << EOFLGOROTATE > /etc/logrotate.d/named
/var/named/chroot/var/log/*.log {
missingok
notifempty
compress
daily
rotate 7
create 0644 named named
postrotate
/sbin/service named reload 2> /dev/null > /dev/null || true
endscript
}
EOFLGOROTATE
# conf_logrotate_small_disk
# enableservice named
setsebool -P named_write_master_zones 1
rmdir ${nameddir}/var/named/{data,slaves}
install -dm 770 -o named -g named ${nameddir}/var/named/{internal,external}
chcon system_u:object_r:named_zone_t ${nameddir}/var/named/*
install -dm 770 -o named -g named ${nameddir}/var/log/named
chcon system_u:object_r:named_cache_t ${nameddir}/var/log/named
tgtpath=${nameddir}/etc
owner=named
owngrp=named
dirperm=750
perm=640
tgtfile=named_logging.conf
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
tgtpath=${nameddir}/var/named/external
owner=root
owngrp=root
dirperm=770
perm=644
tgtfile=db.bind
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
tgtpath=${nameddir}/var/named/internal
tgtfile=db.0.0.127.in-addr.arpa
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
tgtfile=db.localhost
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
tgtfile=root.hints
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
[ -d /etc/cron.d ] || install -dm 700 -o root -g root /etc/cron.d
echo "*/1 * * * * root /usr/sbin/rndc stats" > /etc/cron.d/dnsstat.cron
[ -d /data ] || install -dm 770 -o root -g root /data
ln -s ${nameddir} /data/named
ln -s ${nameddir} /etc/named
ln -s ${nameddir}/var/log /var/log/named
ln -s ${nameddir}/var/run/named.pid /var/run
service named start
useradd -c "syncuser voor stats" -mp 'pass' syncuser
install -dm 700 -o syncuser -g syncuser ~syncuser/.ssh
cat << EOF > ~syncuser/.ssh/known_hosts
### You can add known hosts here
EOF
chown syncuser:syncuser ~syncuser/.ssh/known_hosts
chmod 644 ~syncuser/.ssh/known_hosts
tgtpath=/data/scripts
owner=root
owngrp=root
dirperm=755
perm=770
tgtfile=sync_stats
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
tgtpath=/etc/cron.d
tgtfile=sync_stats.cron
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
cat << EOF
========================= Configure syncuser ========================
LETOP: je moet nog de id_rsa file plaatsen in ~syncuser/.ssh!
Deze kun je vinden op de managementserver in de homedir van syncuser
of op een andere dns server waarop dit al geregeld is.
gebruik bijvoorbeeld
scp syncuser@hostname:.ssh/id_rsa ~syncuser/.ssh/
chown -R syncuser:syncuser ~syncuser/.ssh
chmod 644 ~syncuser/.ssh/id_rsa
========================= Configure syncuser ========================
EOF
}
mk-dhcp-server () {
echo "========================= Configure DHCPD ========================"
network=$(echo ${internal_ip}|awk -F . '{print $3}')
cat << EOFDHCPD > /etc/dhcpd.conf
# Global options
ddns-update-style interim;
ddns-domainname "swen.nu";
option netbios-name-servers 10.107.119.3;
option domain-name-servers 10.107.119.6;
option domain-name "swen.nu";
option ntp-servers 10.107.119.1;
next-server 10.107.119.6;
filename "pxelinux.0";
option tftp-server-name malibu;
option smtp-server 10.107.119.6;
default-lease-time 3600;
max-lease-time 7200;
log-facility local7;
option option-128 code 128 = string;
option option-129 code 129 = text;
option option-221 code 221 = text;
#key "rndc-key" {
# algorithm hmac-md5;
# secret "c+SMaMiXNSMUxaFTM5Xqql6e1Pj27LUX4jzOSEQANPa96L/eJzQrcQklsY8QmKfMHy14SDZUsvwlDMvck90UMg==";
#}
subnet 10.107.119.0 netmask 255.255.255.0 {
range dynamic-bootp 10.107.119.201 10.107.119.240;
option subnet-mask 255.255.255.0;
option routers 10.107.119.1;
echo allow unknown-clients;
echo allow client-updates;
ddns-updates on;
authoritative;
echo allow bootp;
}
EOFDHCPD
# Configure syslog
perl -pi -e ' s?cron.none.*/log/messages?cron.none;local6.none /var/log/messages?g ' /etc/syslog.conf
cat << EOFSYSLOG >> /etc/syslog.conf
# DHCPD
local6.* /var/log/dhcpd.log
EOFSYSLOG
# configure logrotate for dhcpd
cat << EOFLGOROTATE >> /etc/logrotate.d/dhcpd
/var/log/dhcpd.log {
missingok
notifempty
compress
daily
rotate 7
create 0600 root root
postrotate
/sbin/service dhcpd restart 2>&1 /dev/null || true
endscript
}
EOFLGOROTATE
enableservice dhcpd
}
mk-install-server () {
echo "===================== Configure installserver ===================="
mkdir -p /data/tftpboot /data/www
cd /data/tftpboot
mkdir -p pxelinux.cfg msgs cfgfiles post-scripts
perl -pi -e '
s?/tftpboot?/data/tftpboot?g ;
s?disable.*?disable = no?g '\
/etc/xinetd.d/tftp
[ -f /usr/lib/syslinux/pxelinux.0 ] && cp /usr/lib/syslinux/pxelinux.0 /data/tftpboot
echo "options loop max_loop=64" >> /etc/modprobe.conf
}
mk-xrdp-server () {
echo "======================= Configure RDPserver ======================"
enableservice xrdpd
}
mk-zimbra-server () {
echo "======================= Configure Zimbraserver ======================"
}
mk-puppetmaster () {
echo "======================= Configure Puppetmaster ======================"
# http://www.tomhayman.co.uk/linux/install-puppet-modpassenger-mysql-stored-procs-centos-6-rhel6/
cat << EOF >> /etc/yum.repos.d/puppet.repo
[puppetlabs]
name=Puppet Labs Packages
baseurl=http://yum.puppetlabs.com/el/6/products/x86_64/
enabled=1
gpgcheck=0
[puppetlabs2]
name=Puppet Labs Packages Deps
baseurl=http://yum.puppetlabs.com/el/6/dependencies/x86_64/
enabled=1
gpgcheck=0
EOF
# yum -y install epel-release
rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/i386/epel-release-6-5.noarch.rpm
# rpm --import file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
yum -y install facter puppet puppet-server rubygem-rake
enableservice puppetmaster
/etc/init.d/puppetmaster start
gem install rspec-puppet
}
mk-kvm-server () {
enableservice libvirtd
cat << EOF-cfg-kvmserver > ${tmp_dir}/cfg-kvmserver
#!/bin/bash
echo "======================= Configure kvmserver ======================"
echo "remove the startup of this script from /etc/rc.d/rc.local"
perl -ni -e 'print unless /'cfg-kvmserver'/' /etc/rc.d/rc.local
[ -f ${tmp_dir}/serverprofile ] && . ${tmp_dir}/serverprofile
/sbin/service network stop
perl -ni -e 'print unless /'eth'/' /etc/modprobe.conf
modprobe -r r8169 e1000
rmmod r8169
rmmod e1000
echo -e "alias eth0 r8169\nalias eth1 e1000\nalias eth2 e1000" >> /etc/modprobe.conf
cd /etc/sysconfig/network-scripts
for x in 4 3 2 1 0;do [ -f ifcfg-eth$x ] && mv ifcfg-eth$x ifcfg-eth$((x+1));done
[ -f ifcfg-eth5 ] && mv ifcfg-eth5 ifcfg-eth0
[ -f ifcfg-eth3 -a ! -f ifcfg-eth0 ] && mv ifcfg-eth3 ifcfg-eth0
case ${me} in
cider)
echo -e "alias eth3 e1000\nalias eth4 e1000" >> /etc/modprobe.conf
bridge=br0
br_ip=${internal_ip}
ifs="${internal_if}"
brctl addbr \${bridge}
for if in \${ifs};do
brctl addif \${bridge} \${if}
mac=\$(awk -F = '/HWADDR/ {print \$2}' ifcfg-\${if})
line1=\$(head -1 ifcfg-\${if})
cat << EOF > ifcfg-\${if}
\${line1}
DEVICE=\${if}
HWADDR=\${mac}
ONBOOT=yes
BRIDGE=\${bridge}
TYPE=Ethernet
EOF
done
cat << EOF > ifcfg-\${bridge}
DEVICE=\${bridge}
BOOTPROTO=static
IPADDR=\${br_ip}
GATEWAY=10.107.119.1
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Bridge
EOF
bridge=br3
br_ip=${br3_ip}
ifs="eth3"
brctl addbr \${bridge}
for if in \${ifs};do
brctl addif \${bridge} \${if}
mac=\$(awk -F = '/HWADDR/ {print \$2}' ifcfg-\${if})
line1=\$(head -1 ifcfg-\${if})
cat << EOF > ifcfg-\${if}
\${line1}
DEVICE=\${if}
HWADDR=\${mac}
ONBOOT=yes
BRIDGE=\${bridge}
TYPE=Ethernet
EOF
done
cat << EOF > ifcfg-\${bridge}
DEVICE=\${bridge}
BOOTPROTO=static
IPADDR=\${br_ip}
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Bridge
EOF
bridge=br4
br_ip=${br4_ip}
ifs="eth4"
brctl addbr \${bridge}
for if in \${ifs};do
brctl addif \${bridge} \${if}
mac=\$(awk -F = '/HWADDR/ {print \$2}' ifcfg-\${if})
line1=\$(head -1 ifcfg-\${if})
cat << EOF > ifcfg-\${if}
\${line1}
DEVICE=\${if}
HWADDR=\${mac}
ONBOOT=yes
BRIDGE=\${bridge}
TYPE=Ethernet
EOF
done
cat << EOF > ifcfg-\${bridge}
DEVICE=\${bridge}
BOOTPROTO=static
IPADDR=\${br_ip}
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Bridge
EOF
;;
bigpeat|benriach)
bridge=br0
br_ip=${internal_ip}
ifs="${internal_if}"
brctl addbr \${bridge}
for if in \${ifs};do
brctl addif \${bridge} \${if}
mac=\$(awk -F = '/HWADDR/ {print \$2}' ifcfg-\${if})
line1=\$(head -1 ifcfg-\${if})
cat << EOF > ifcfg-\${if}
\${line1}
DEVICE=\${if}
HWADDR=\${mac}
ONBOOT=yes
BRIDGE=\${bridge}
TYPE=Ethernet
EOF
done
cat << EOF > ifcfg-\${bridge}
DEVICE=\${bridge}
BOOTPROTO=static
IPADDR=\${br_ip}
GATEWAY=10.107.119.1
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Bridge
EOF
bridge=br3
br_ip=${br3_ip}
ifs="eth1"
brctl addbr \${bridge}
for if in \${ifs};do
brctl addif \${bridge} \${if}
mac=\$(awk -F = '/HWADDR/ {print \$2}' ifcfg-\${if})
line1=\$(head -1 ifcfg-\${if})
cat << EOF > ifcfg-\${if}
\${line1}
DEVICE=\${if}
HWADDR=\${mac}
ONBOOT=yes
BRIDGE=\${bridge}
TYPE=Ethernet
EOF
done
cat << EOF > ifcfg-\${bridge}
DEVICE=\${bridge}
BOOTPROTO=static
IPADDR=\${br_ip}
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Bridge
EOF
bridge=br4
br_ip=${br4_ip}
ifs="eth2"
brctl addbr \${bridge}
for if in \${ifs};do
brctl addif \${bridge} \${if}
mac=\$(awk -F = '/HWADDR/ {print \$2}' ifcfg-\${if})
line1=\$(head -1 ifcfg-\${if})
cat << EOF > ifcfg-\${if}
\${line1}
DEVICE=\${if}
HWADDR=\${mac}
ONBOOT=yes
BRIDGE=\${bridge}
TYPE=Ethernet
EOF
done
cat << EOF > ifcfg-\${bridge}
DEVICE=\${bridge}
BOOTPROTO=static
IPADDR=\${br_ip}
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Bridge
EOF
;;
esac
/sbin/service network start
EOF-cfg-kvmserver
chmod +x ${tmp_dir}/cfg-kvmserver
echo "${tmp_dir}/cfg-kvmserver >>${logfile} 2>&1" >>/etc/rc.d/rc.local
}
mk-web-server () {
cat << EOF-cfg-webserver > ${tmp_dir}/cfg-webserver
#!/bin/bash
echo "======================= Configure webserver ======================"
echo "remove the startup of this script from /etc/rc.d/rc.local"
perl -ni -e 'print unless /'cfg-webserver'/' /etc/rc.d/rc.local
[ -f ${tmp_dir}/serverprofile ] && . ${tmp_dir}/serverprofile
export me=${me}
export domain=${domain}
export datadir=/data
export wwwroot=\${datadir}/www
export def_web_svr=\${wwwroot}/default-web-server
export klant=${klant}
[ -d \${wwwroot} ] || mkdir -p \${wwwroot}
chown -R root:staff \${wwwroot}
chmod 755 \${wwwroot}
groupadd www_ro
groupadd www_rw
usermod -aG www_ro apache
usermod -aG data_ro apache
chcon -R -u system_u -t home_root_t \${wwwroot}
setsebool httpd_can_network_connect_db on
install -dm 755 -o apache -g apache \${def_web_svr}/{error,html,icons,manual}
chcon -R -t httpd_sys_content_t \${def_web_svr}/{,error,html,icons,manual}
install -dm 755 -o apache -g apache -Z system_u:object_r:httpd_sys_script_exec_t \${def_web_svr}/cgi-bin
chcon -R -t httpd_sys_script_exec_t \${def_web_svr}/cgi-bin
setfacl -R -m g:www_ro:rx \${wwwroot}
setfacl -R -m d:g:www_ro:rx \${wwwroot}
setfacl -R -m g:www_rw:rwx \${wwwroot}
setfacl -R -m d:g:www_rw:rwx \${wwwroot}
setfacl -R -m g:staff:rwx \${wwwroot}
setfacl -R -m d:g:staff:rwx \${wwwroot}
for dir in error icons manual;do cp -r /var/www/\${dir}/* \${def_web_svr}/\${dir}/;done
chown -R apache:apache \${def_web_svr}
perl -pi -e '
s?^KeepAlive Off?KeepAlive On? ;
s?^Alias /error/.*?Alias /error/ "\$ENV{def_web_svr}/error"? ;
s?<Directory "/var/www/error"?<Directory "\$ENV{def_web_svr}/error"? ;
s?^Alias /icons/.*?Alias /icons/ "\$ENV{def_web_svr}/icons"? ;
s?^<Directory "/var/www/icons"?<Directory "\$ENV{def_web_svr}/icons"? ;
s?^ScriptAlias /cgi-bin/.*?ScriptAlias /cgi-bin/ "\$ENV{def_web_svr}/cgi-bin"? ;
s?^<Directory "/var/www/cgi-bin"?<Directory "\$ENV{def_web_svr}/cgi-bin"? ;
s?^DocumentRoot.*?DocumentRoot \$ENV{def_web_svr}/html? ;
s?^#NameVirtualHost.*?NameVirtualHost *:80? ;
s?^#ServerName.*?ServerName \$ENV{me}.\$ENV{domain}:80? ;
s?^DirectoryIndex.*?DirectoryIndex index.php index.html index.htm default.htm? ;
s?^<Directory "/var/www/html"?<Directory "\$ENV{def_web_svr}/html"? ' /etc/httpd/conf/httpd.conf
[ -d /etc/httpd/vhosts.d ] || mkdir -p /etc/httpd/vhosts.d
cat << EOF-http >> /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin alex@swen.nu
ServerName www.swen.nu
ErrorLog /var/log/httpd/shared-web.error.log
CustomLog /var/log/httpd/shared-web.access.log combined
DocumentRoot \${def_web_svr}/html
<Directory "\${def_web_svr}/html">
Options -Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /icons/ "\${def_web_svr}/icons/"
<Directory "\${def_web_svr}/icons">
Options -Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
ScriptAlias /cgi-bin/ "\${def_web_svr}/cgi-bin/"
<Directory "\${def_web_svr}/cgi-bin">
AllowOverride None
Options -Indexes
Order allow,deny
Allow from all
</Directory>
Alias /error/ "\${def_web_svr}/error/"
<IfModule mod_negotiation.c>
<IfModule mod_include.c>
<Directory "\${def_web_svr}/error">
AllowOverride None
Options -Indexes IncludesNoExec
AddOutputFilter Includes html
AddHandler type-map var
Order allow,deny
Allow from all
LanguagePriority en es de fr
ForceLanguagePriority Prefer Fallback
</Directory>
# ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
# ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
# ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
# ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
# ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
# ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
# ErrorDocument 410 /error/HTTP_GONE.html.var
# ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
# ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
# ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
# ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
# ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
# ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
# ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
# ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
# ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
# ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
</IfModule>
</IfModule>
</VirtualHost>
include /etc/httpd/vhosts.d/*.conf
EOF-http
echo "<?php header(\\"Location: http://www.swen.nu/\\"); exit; ?>" > \${def_web_svr}/html/index.php
echo "<?php phpinfo(); ?>" > \${def_web_svr}/html/t.php
perl -pi -e 's?^register_globals.*?register_globals = On?; s?^error_reporting.*?error_reporting = E_ALL & ~E_NOTICE? ' /etc/php.ini
EOF-cfg-webserver
enableservice httpd
chmod +x ${tmp_dir}/cfg-webserver
echo "${tmp_dir}/cfg-webserver >>${logfile} 2>&1" >>/etc/rc.d/rc.local
tgtpath=/data/scripts
owner=root
owngrp=root
dirperm=770
perm=770
tgtfile=nieuwewebsite
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
tgtfile=crypt.php
getfile=crypt.php.tmpl
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
echo "configure php"
perl -pi -e 's/memory_limit = 8M/memory_limit = 32M/ ' /etc/php.ini
mk-db-server
}
mk-web2-server () {
echo "======================= Configure webserver ======================"
# below you find the steps as lined at http://www.howtoforge.com/perfect-server-centos-5.5-x86_64-ispconfig-3-p4
# that said, I removed and changed some steps ( E.G.: I had already installed the rpm txt key of Dag Wieers and added rpmforge repo during normal postinall)
# 6 Securitylevel
echo ""
echo "ISPCONFIG step 6 reduce securitylevel"
/sbin/chkconfig iptables off
/sbin/service iptables stop
# 7 install some software
echo ""
echo "ISPCONFIG step 7 install some software"
tgtpath=/etc/yum.repos.d
owner=root
owngrp=root
dirperm=755
perm=755
tgtfile=CentOS-Base.repo
getfile=${tgtfile}-for-ISPConfig-server
getfile
yum -y update
yum -y groupinstall development-libs development-tools
# 8 Quota
echo ""
echo "ISPCONFIG step 8 quota"
perl -pi -e 's?LABEL=lv_root / ext3 defaults 1 1?LABEL=lv_root / ext3 defaults,usrquota,grpquota 1 1?' /etc/fstab
for x in user group;do install -m 600 -o root -g root /dev/null /aquota.${x};done
mount -o remount /
quotacheck -avugm
quotaon -avug
# 9 Install apache mysql phpmydamin
echo ""
echo "ISPCONFIG step 9 Install apache mysql phpmydamin"
yum -y install ntp httpd mysql-server php php-mysql php-mbstring php-mcrypt phpmyadmin
# 10 install Dovecot
echo ""
echo "ISPCONFIG step 10 install Dovecot"
yum -y remove dovecot
rpm -Uvh http://dl.atrpms.net/all/dovecot-1.2.15-1_113.el5.x86_64.rpm http://dl.atrpms.net/all/dovecot-sieve-0.1.18-6.el5.x86_64.rpm
[ -d /usr/lib/dovecot ] && rm -rf /usr/lib/dovecot
ln -s /usr/lib64/dovecot /usr/lib
enableservice dovecot
/sbin/service dovecot start
# 11 install postfix with mysql + # 12 install getmail
echo ""
echo "ISPCONFIG step 11 install postfix with mysql + # 12 install getmail"
yum -y erase postfix
[ -f /etc/postfix/main.cf ] && rm -f /etc/postfix/main.cf
yum -y install postfix getmail
/sbin/chkconfig sendmail off
enableservice postfix
/sbin/service postfix start
# 13 conf MYSQL and run secureserver jobs are done at end of this function
echo ""
echo "ISPCONFIG step 13 conf MYSQL and run secureserver jobs are done at end of this function"
tgtpath=/etc/httpd/conf.d
owner=root
owngrp=root
dirperm=755
perm=644
tgtfile=phpmyadmin.conf
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
tgtpath=/usr/share/phpmyadmin
owner=root
owngrp=root
dirperm=755
perm=740
tgtfile=config.inc.php
getfile=phpmyadmin-config.inc.txt
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
chgrp apache ${tgtpath}/${tgtfile}
enableservice httpd
/sbin/service httpd start
# 14 install amavisd-new spamassassin and clamav
echo ""
echo "ISPCONFIG step 14 install amavisd-new spamassassin and clamav "
yum -y install amavisd-new spamassassin unrar unzip bzip2 perl-DBD-mysql phpmyadmin
echo "CONFIG_FILE=\\\"/etc/amavisd/amavisd.conf\\\" " >> /etc/sysconfig/amavisd
sa-update
enableservice amavisd
enableservice clamd
/usr/bin/freshclam
/sbin/service amavisd start
/sbin/service clamd start
install -d -o amavis /var/run/amavisd /var/spool/amavisd /var/spool/amavisd/tmp /var/spool/amavisd/db
ln -s /var/run/clamav/clamd.sock /var/spool/amavisd/clamd.sock
# 15 Installing Apache2 With mod_php, mod_fcgi/PHP5, And suPHP
echo ""
echo "ISPCONFIG step 15 apache With mod_php, mod_fcgi/PHP5, And suPHP"
tgtpath=/etc/yum.repos.d
owner=root
owngrp=root
dirperm=755
perm=755
tgtfile=kbsingh-CentOS-Extras.repo
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
yum -y install php php-devel php-gd php-imap php-ldap php-mysql php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-mbstring php-mcrypt php-mhash php-mssql php-snmp php-soap php-tidy curl curl-devel perl-libwww-perl ImageMagick libxml2 libxml2-devel mod_fcgid php-cli httpd-devel bind-chroot webalizer perl-DateTime-Format-HTTP perl-DateTime-Format-Builder rkhunter squirrelmail pure-ftpd fail2ban munin munin-common munin-node
perl -pi -e 's?^register_globals.*?register_globals = On?; s?^error_reporting.*?error_reporting = E_ALL & ~E_NOTICE?; s?memory_limit = 8M?memory_limit = 32M? ' /etc/php.ini
echo "cgi.fix_pathinfo = 1" >> /etc/php.ini
wget -q --no-cache http://suphp.org/download/suphp-0.7.1.tar.gz -O -|tar zxvf - -C /tmp
cd /tmp/suphp-0.7.1/
./configure --prefix=/usr --sysconfdir=/etc --with-apr=/usr/bin/apr-1-config --with-apxs=/usr/sbin/apxs --with-apache-user=apache --with-setid-mode=owner --with-php=/usr/bin/php-cgi --with-logfile=/var/log/httpd/suphp_log --enable-SUPHP_USE_USERGROUP=yes
make
make install
cat << EOFSUPHP > /etc/httpd/conf.d/suphp.conf
LoadModule suphp_module modules/mod_suphp.so
EOFSUPHP
cd /tmp
rm -rf /tmp/suphp*
tgtpath=/etc
owner=root
owngrp=root
dirperm=755
perm=755
tgtfile=suphp.conf
getfile=${tgtfile}
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
/sbin/service httpd restart
# 16 install pruftpd
echo ""
echo "ISPCONFIG step 16 install pureftpd"
enableservice pure-ftpd
/sbin/service pure-ftpd start
# 17 install chrooted dns server
echo ""
echo "ISPCONFIG step 17 dns server"
install -dm 755 -o named -g named /var/named/
install -dm 775 -o named -g named /var/named/chroot/ /var/named/chroot/var/ /var/named/chroot/var/named/ /var/named/chroot/var/run/
install -dm 777 -o named -g named /var/named/chroot/var/run/named/
cd /var/named/chroot/var/named/
ln -s ../../ chroot
install -m 655 -o named -g named /usr/share/doc/bind-9.3.6/sample/var/named/named.local /var/named/chroot/var/named/named.local
install -m 655 -o named -g named /usr/share/doc/bind-9.3.6/sample/var/named/named.root /var/named/chroot/var/named/named.root
install -m 655 -o named -g named /dev/null /var/named/chroot/etc/named.conf.local
install -m 655 -o named -g named /dev/null /var/named/chroot/var/log/named.log
ln -s /var/named/chroot/var/log/named.log /var/log/
tgtpath=/var/named/chroot/etc
owner=root
owngrp=root
dirperm=755
perm=755
tgtfile=named.conf
getfile=named-duvel.conf
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
enableservice named
/sbin/service named start
# 18 install vlogger and webalizer
echo ""
echo "ISPCONFIG step 18 install vlogger and webalizer"
wget -q --no-cache http://n0rp.chemlab.org/vlogger/vlogger-1.3.tar.gz -O -|tar zxvf - -C /tmp
mv /tmp/vlogger-1.3/vlogger /usr/sbin/
cd /tmp
rm -rf /tmp/vlogger*
# 19 install jailkit
echo ""
echo "ISPCONFIG step 19 install jailkit"
wget -q --no-cache http://olivier.sessink.nl/jailkit/jailkit-2.11.tar.gz -O -|tar zxvf - -C /tmp
cd /tmp/jailkit-2.11
./configure
make
make install
cd /tmp
rm -rf /tmp/jailkit-2.11*
# 20 install fail2ban
echo ""
echo "ISPCONFIG step 20 fail2ban setup"
enableservice fail2ban
/sbin/service fail2ban start
# 21 install rkhunter done at step 15
echo ""
echo "ISPCONFIG step 21 install rkhunter already done"
# 22 install squirrelmail
echo ""
echo "ISPCONFIG step 22 squirrelmail"
tgtpath=/etc/squirrelmail
owner=root
owngrp=root
dirperm=755
perm=755
tgtfile=config_local.php
getfile=squirrel-config.txt
[ ! -f ${tgtpath}/${tgtfile} ] && getfile
# 23 install ISPconfig 3
echo ""
echo "ISPCONFIG step 23 download and extract ispconfig"
wget -q --no-cache http://downloads.sourceforge.net/ispconfig/ISPConfig-3.0.3.tar.gz?use_mirror= -O -|tar zxvf - -C /tmp
# 13 conf MYSQL and run secureserver jobs
echo ""
echo "ISPCONFIG step 13 again: configure DB server"
mk-db-server
}
mk-db-server () {
export datadir=/data
export mydir=${datadir}/mysql
cat << EOF-cfg-sqlserver > ${tmp_dir}/cfg-sqlserver
#!/bin/bash
echo "====================== Configure MySQLserver ====================="
echo "remove the startup of this script from /etc/rc.d/rc.local"
perl -ni -e 'print unless /'cfg-sqlserver'/' /etc/rc.d/rc.local
[ -f ${tmp_dir}/serverprofile ] && . ${tmp_dir}/serverprofile
export datadir=${datadir}
export mydir=${mydir}
[ -f /etc/my.cnf ] && cp /etc/my.cnf /etc/my.cnf.bck
[ -s /etc/my-huge.cnf ] && cp /etc/my-huge.cnf /etc/my.cnf
[ -s /etc/my-default.cnf ] && cp /etc/my-default.cnf /etc/my.cnf
setsebool allow_user_mysql_connect on
install -dm 775 -o mysql -g mysql \${mydir}
chcon -R -t mysqld_db_t \${mydir}
install -dm 770 -o mysql -g mysql -Z system_u:object_r:mysqld_db_t /data/mysql-backup
install -m 640 -o mysql -g mysql -Z system_u:object_r:mysqld_log_t /dev/null /var/log/mysqld.log
ln -sf /var/log/mysqld.log /var/lib/mysql
ln -sf /var/log/mysqld.log \${mydir}
groupadd mysql_ro
groupadd mysql_rw
usermod -aG data_ro mysql
usermod -aG mysql_rw mysql
chmod 770 \${mydir}
setfacl -R -m g:mysql_ro:rx \${mydir}
setfacl -R -m d:g:mysql_ro:rx \${mydir}
setfacl -R -m g:mysql_rw:rwx \${mydir}
setfacl -R -m d:g:mysql_rw:rwx \${mydir}
setfacl -R -m g:staff:rwx \${mydir}
setfacl -R -m d:g:staff:rwx \${mydir}
if [ -f /etc/init.d/mysqld ];then
echo Starting service mysqld...
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on
/sbin/service mysqld start
fi
newmysqlpw="\$(head -c 200 /dev/urandom | tr -cd '[:alnum:]' | head -c 10;echo "")"
/usr/bin/mysqladmin -u root password "\${newmysqlpw}"
cat << EOF > ~root/.my.cnf
[client]
password = "\${newmysqlpw}"
EOF
chown root:root ~root/.my.cnf
chmod 600 ~root/.my.cnf
/usr/bin/mysqladmin --defaults-file=~root/.my.cnf -h localhost.localdomain password "\${newmysqlpw}"
mysql --defaults-file=~root/.my.cnf <<EOF
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.user WHERE User='root' AND Host!='localhost';
DROP DATABASE test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\\\%';
FLUSH PRIVILEGES;
EOF
EOF-cfg-sqlserver
chmod +x ${tmp_dir}/cfg-sqlserver
echo "${tmp_dir}/cfg-sqlserver >>${logfile} 2>&1" >>/etc/rc.d/rc.local
owner=root
owngrp=root
tgtpath=/etc
dirperm=755
perm=644
[ "${type}" = "db" ] && tgtfile=my-huge.cnf || tgtfile=my-default.cnf
getfile=${tgtfile}
getfile
perl -pi -e 's?datadir=.*?datadir=$ENV{mydir}? ' /etc/my.cnf
tgtpath=/etc/cron.d
tgtfile=mysqlbackup.cron
getfile=${tgtfile}
dirperm=755