forked from i-doit/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idoit-install
executable file
·1864 lines (1568 loc) · 64.4 KB
/
idoit-install
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 i-doit on a GNU/Linux operating system
##
##
## Copyright (C) 2017-19 synetics GmbH, <https://i-doit.com/>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
## the Free Software Foundation, either version 3 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 Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##
set -euo pipefail
IFS=$'\n\t'
##
## Configuration
##
## You **should not** edit these settings.
## You will be asked for your preferred settings.
## To overwrite these settings export them before running this script.
## For example:
## export MARIADB_INNODB_BUFFER_POOL_SIZE=2G
## ./idoit-install
##
: "${MARIADB_HOSTNAME:="localhost"}"
: "${MARIADB_SUPERUSER_USERNAME:="root"}"
: "${MARIADB_SUPERUSER_PASSWORD:="idoit"}"
: "${MARIADB_INNODB_BUFFER_POOL_SIZE:="1G"}"
: "${IDOIT_ADMIN_CENTER_PASSWORD:="admin"}"
: "${MARIADB_IDOIT_USERNAME:="idoit"}"
: "${MARIADB_IDOIT_PASSWORD:="idoit"}"
: "${IDOIT_DEFAULT_TENANT:="CMDB"}"
: "${INSTALL_DIR:="/var/www/html"}"
: "${UPDATE_FILE_PRO:="https://i-doit.com/updates.xml"}"
: "${UPDATE_FILE_OPEN:="https://i-doit.org/updates.xml"}"
: "${SCRIPT_SETTINGS:="/etc/i-doit/i-doit.sh"}"
: "${CONSOLE_BIN:="/usr/local/bin/idoit"}"
: "${JOBS_BIN:="/usr/local/bin/idoit-jobs"}"
: "${CRON_FILE:="/etc/cron.d/i-doit"}"
: "${BACKUP_DIR:="/var/backups/i-doit"}"
: "${RECOMMENDED_PHP_VERSION:="7.3"}"
##
## Runtime settings
##
## DO NOT EDIT THESE SETTINGS.
##
OS=""
DATE="$(date +%Y-%m-%d)"
TMP_DIR="/tmp/i-doit_${DATE}"
APACHE_USER="www-data"
APACHE_GROUP="www-data"
MIN_CPU_CORES=2
## Be tolerant, use 1000 instead of 1024:
MIN_RAM=$((1000*1000*1000*2))
APACHE_UNIT=""
MARIADB_UNIT=""
MEMCACHED_UNIT=""
PHP_FPM_UNIT=""
APACHE_CONFIG_FILE=""
MARIADB_CONFIG_FILE=""
PHP_CONFIG_FILE=""
MARIADB_SOCKET=""
PHP_FPM_SOCKET=""
APACHE_HTACCESS_SUBSTITUTION="## Insert content from .htaccess file"
BASENAME=$(basename "$0")
PROJECT_VERSION="0.14-dev"
MARIADB_BIN=""
SUDO_BIN=""
UNZIP_BIN=""
WGET_BIN=""
PHP_BIN=""
## /etc/os-release comes with these variables:
## NAME, VERSION, VERSION_ID, PRETTY_NAME and some more…
NAME=""
VERSION=""
VERSION_ID=""
PRETTY_NAME=""
##--------------------------------------------------------------------------------------------------
function execute {
local status=0
local ip_address=""
log "Install i-doit on a GNU/Linux operating system"
log ""
log "Attention:"
log "This script alters your OS. It will install new packages and will change configuration settings."
log "Only use it on a fresh installation of a GNU/Linux OS."
log "It comes with absolutely no warranty."
log "Read the documentation carefully before you continue:"
log ""
log " https://github.com/bheisig/i-doit-scripts"
log ""
log "This script will automatically…"
log ""
log " 1) install additional distribution packages,"
log " 2) alter configuration of your PHP environment,"
log " 3) alter configuration of your Apache Web server,"
log " 4) alter configuration of your MariaDB DBMS, and"
log " 5) download and install the latest version of i-doit pro or open"
log " 6) deploy cron jobs and an easy-to-use CLI tool for your i-doit instance"
log " 7) deploy scripts to backup and restore your i-doit instance"
log ""
log "You may skip any step if you like."
log ""
askYesNo "Do you really want to continue?" || cancel
log "\\n--------------------------------------------------------------------------------\\n"
identifyOS
log "\\n--------------------------------------------------------------------------------\\n"
checkHardwareRequirements
log "\\n--------------------------------------------------------------------------------\\n"
log "This script needs Web access (HTTP/HTTPS on ports 80/443)."
askNoYes "Do you want to configure a proxy server?" || configureProxy
log "\\n--------------------------------------------------------------------------------\\n"
askYesNo "Do you want to configure the operating system?" && configureOS
log "\\n--------------------------------------------------------------------------------\\n"
checkSoftwareRequirements
log "\\n--------------------------------------------------------------------------------\\n"
askYesNo "Do you want to configure the PHP environment?" && configurePHP && configurePHPFPM
log "\\n--------------------------------------------------------------------------------\\n"
askYesNo "Do you want to configure the Apache Web server?" && configureApache
log "\\n--------------------------------------------------------------------------------\\n"
askYesNo "Do you want to configure MariaDB?" && configureMariaDB
log "\\n--------------------------------------------------------------------------------\\n"
if askYesNo "Do you want to download and install i-doit automatically?"; then
prepareIDoit
updateApacheConfig
installIDoit
ip_address=$(ip route get 1 | sed 's/^.*src \([^ ]*\).*$/\1/;q')
log "Your setup is ready. Navigate to"
log ""
log " http://${ip_address}/"
log ""
log "with your Web browser and login with username/password 'admin'"
status=1
else
log "Your operating system is prepared for the installation of i-doit."
log "To complete the setup please follow the instructions as described in the i-doit Knowledge Base:"
log ""
log " https://kb.i-doit.com/display/en/Setup"
fi
if [[ "$status" = 1 ]]; then
log "\\n--------------------------------------------------------------------------------\\n"
if askYesNo "Do you want to configure i-doit cron jobs?"; then
deployScriptSettings
deployConsole
deployJobScript
deployCronJobs
log "Cron jobs are successfully activated. To change e-mail address, execution date and time please edit this file:"
log ""
log " $CRON_FILE"
log ""
log "There is also a script available for all system users to execute the i-doit console command line tool:"
log ""
log " idoit"
log ""
log "The needed cron jobs are defined here:"
log ""
log " $JOBS_BIN"
log ""
log "If needed you can change the settings of both the i-doit console and the cron jobs:"
log ""
log " $SCRIPT_SETTINGS"
status=2
fi
fi
if [[ "$status" = 2 ]]; then
log "\\n--------------------------------------------------------------------------------\\n"
if askYesNo "Do you want to backup i-doit automatically?"; then
deployBackupAndRestore
log "Backups are successfully activated. Each night a backup will be created."
log "Backups will be kept for 30 days:"
log ""
log " $BACKUP_DIR"
log ""
log "You may create a backup manually:"
log ""
log " idoit-backup"
log ""
log "Of course, you are able to restore i-doit from the lastest backup:"
log ""
log " idoit-restore"
log ""
log "Settings may be changed here:"
log ""
log " $SCRIPT_SETTINGS"
fi
fi
log "\\n--------------------------------------------------------------------------------\\n"
case "$OS" in
"ubuntu1604")
log "To garantee that all your changes take effect you should restart your system."
;;
esac
}
function identifyOS {
if [[ ! -f "/etc/os-release" ]]; then
log "File /etc/os-release is missing"
abort "Unable to identify operating system"
fi
# shellcheck source=/dev/null
source "/etc/os-release"
log "Operating system identified as ${PRETTY_NAME}"
if [[ "$NAME" == "CentOS Linux" && "$VERSION_ID" == "7" ]]; then
log "Warning: This OS is not officially supported by i-doit"
log "Warning: CentOS 7 is out-dated. Please consider to upgrade your OS."
askYesNo "Do you really want to continue?" || cancel
OS="centos7"
APACHE_USER="apache"
APACHE_GROUP="apache"
APACHE_CONFIG_FILE="/etc/httpd/conf.d/i-doit.conf"
MARIADB_CONFIG_FILE="/etc/my.cnf.d/99-i-doit.cnf"
PHP_CONFIG_FILE="/etc/php.d/i-doit.ini"
MARIADB_SOCKET="/var/lib/mysql/mysql.sock"
PHP_FPM_SOCKET="/var/run/php-fpm/php-fpm.sock"
APACHE_UNIT="httpd"
MARIADB_UNIT="mariadb"
MEMCACHED_UNIT="memcached"
PHP_FPM_UNIT="php-fpm"
elif [[ "$NAME" == "CentOS Linux" && "$VERSION_ID" == "8" ]]; then
log "Warning: This OS is not officially supported by i-doit"
askYesNo "Do you really want to continue?" || cancel
OS="centos8"
APACHE_USER="apache"
APACHE_GROUP="apache"
APACHE_CONFIG_FILE="/etc/httpd/conf.d/i-doit.conf"
MARIADB_CONFIG_FILE="/etc/my.cnf.d/99-i-doit.cnf"
PHP_CONFIG_FILE="/etc/php.d/i-doit.ini"
MARIADB_SOCKET="/var/lib/mysql/mysql.sock"
PHP_FPM_SOCKET="/var/run/php-fpm/php-fpm.sock"
APACHE_UNIT="httpd"
MARIADB_UNIT="mariadb"
MEMCACHED_UNIT="memcached"
PHP_FPM_UNIT="php-fpm"
elif [[ "$NAME" == "Debian GNU/Linux" && "$VERSION" == "10 (buster)" ]]; then
export DEBIAN_FRONTEND="noninteractive"
OS="debian10"
APACHE_USER="www-data"
APACHE_GROUP="www-data"
APACHE_CONFIG_FILE="/etc/apache2/sites-available/i-doit.conf"
MARIADB_CONFIG_FILE="/etc/mysql/mariadb.conf.d/99-i-doit.cnf"
PHP_CONFIG_FILE="/etc/php/7.3/mods-available/i-doit.ini"
MARIADB_SOCKET="/var/run/mysqld/mysqld.sock"
PHP_FPM_SOCKET="/var/run/php/php7.3-fpm.sock"
APACHE_UNIT="apache2"
MARIADB_UNIT="mysql"
MEMCACHED_UNIT="memcached"
PHP_FPM_UNIT="php7.3-fpm"
elif [[ "$NAME" == "Debian GNU/Linux" && "$VERSION" == "9 (stretch)" ]]; then
abort "Error: This is the oldstable version of Debian GNU/Linux. It's not supported anymore. Please upgrade."
elif [[ "$NAME" == "Debian GNU/Linux" && "$VERSION" == "8 (jessie)" ]]; then
abort "Error: This is the oldoldstable version of Debian GNU/Linux. It's not supported anymore. Please upgrade."
elif [[ "$NAME" == "Red Hat Enterprise Linux" && "$VERSION_ID" == 8* ]]; then
OS="rhel8"
APACHE_USER="apache"
APACHE_GROUP="apache"
APACHE_CONFIG_FILE="/etc/httpd/conf.d/i-doit.conf"
MARIADB_CONFIG_FILE="/etc/my.cnf.d/99-i-doit.cnf"
PHP_CONFIG_FILE="/etc/php.d/i-doit.ini"
MARIADB_SOCKET="/var/lib/mysql/mysql.sock"
PHP_FPM_SOCKET="/var/run/php-fpm/php-fpm.sock"
APACHE_UNIT="httpd"
MARIADB_UNIT="mariadb"
MEMCACHED_UNIT="memcached"
PHP_FPM_UNIT="php-fpm"
elif [[ "$NAME" == "Red Hat Enterprise Linux Server" && "$VERSION_ID" == 7* ]]; then
log "Warning: RHEL 7 is out-dated. Please consider to upgrade your OS."
askYesNo "Do you really want to continue?" || cancel
OS="rhel7"
APACHE_USER="apache"
APACHE_GROUP="apache"
APACHE_CONFIG_FILE="/etc/httpd/conf.d/i-doit.conf"
MARIADB_CONFIG_FILE="/etc/my.cnf.d/99-i-doit.cnf"
PHP_CONFIG_FILE="/etc/php.d/i-doit.ini"
MARIADB_SOCKET="/var/lib/mysql/mysql.sock"
PHP_FPM_SOCKET="/var/run/php-fpm/php-fpm.sock"
APACHE_UNIT="httpd"
MARIADB_UNIT="mariadb"
MEMCACHED_UNIT="memcached"
PHP_FPM_UNIT="php-fpm"
elif [[ "$NAME" == "SLES" && "$VERSION" == 15* ]]; then
OS="sles15"
INSTALL_DIR="/srv/www/htdocs"
APACHE_USER="wwwrun"
APACHE_GROUP="www"
APACHE_CONFIG_FILE="/etc/apache2/vhosts.d/i-doit.conf"
MARIADB_CONFIG_FILE="/etc/my.cnf.d/99-i-doit.cnf"
PHP_CONFIG_FILE="/etc/php7/conf.d/i-doit.ini"
MARIADB_SOCKET="/var/run/mysql/mysql.sock"
PHP_FPM_SOCKET="/var/run/php-fpm.sock"
APACHE_UNIT="apache2"
MARIADB_UNIT="mysql"
MEMCACHED_UNIT="memcached"
PHP_FPM_UNIT="php-fpm"
elif [[ "$NAME" = "SLES" && "$VERSION_ID" == 12* ]]; then
abort "Error: SLES 12 is out-dated. It's not supported anymore. Please upgrade."
elif [[ "$NAME" == "Ubuntu" && "$VERSION_ID" == "20.04" ]]; then
export DEBIAN_FRONTEND="noninteractive"
OS="ubuntu2004"
APACHE_USER="www-data"
APACHE_GROUP="www-data"
APACHE_CONFIG_FILE="/etc/apache2/sites-available/i-doit.conf"
MARIADB_CONFIG_FILE="/etc/mysql/mariadb.conf.d/99-i-doit.cnf"
PHP_CONFIG_FILE="/etc/php/7.4/mods-available/i-doit.ini"
MARIADB_SOCKET="/var/run/mysqld/mysqld.sock"
PHP_FPM_SOCKET="/var/run/php/php7.4-fpm.sock"
APACHE_UNIT="apache2"
MARIADB_UNIT="mysql"
MEMCACHED_UNIT="memcached"
PHP_FPM_UNIT="php7.4-fpm"
elif [[ "$NAME" == "Ubuntu" && "$VERSION_ID" == "18.04" ]]; then
export DEBIAN_FRONTEND="noninteractive"
OS="ubuntu1804"
APACHE_USER="www-data"
APACHE_GROUP="www-data"
APACHE_CONFIG_FILE="/etc/apache2/sites-available/i-doit.conf"
MARIADB_CONFIG_FILE="/etc/mysql/mariadb.conf.d/99-i-doit.cnf"
PHP_CONFIG_FILE="/etc/php/7.2/mods-available/i-doit.ini"
MARIADB_SOCKET="/var/run/mysqld/mysqld.sock"
PHP_FPM_SOCKET="/var/run/php/php7.2-fpm.sock"
APACHE_UNIT="apache2"
MARIADB_UNIT="mysql"
MEMCACHED_UNIT="memcached"
PHP_FPM_UNIT="php7.2-fpm"
elif [[ "$NAME" == "Ubuntu" && "$VERSION_ID" == "16.04" ]]; then
abort "Error: Ubuntu 16.04 is out-dated. It's not supported anymore. Please upgrade."
else
abort "Operating system ${PRETTY_NAME} is not supported"
fi
}
function checkHardwareRequirements {
local cores=0
local ram=0
local arch=""
log "Check hardware requirements…"
arch=$(uname -m)
if [[ "$arch" != "x86_64" ]]; then
log "Attention! The system architecture is not x86 64 bit, but ${arch}. This could cause unwanted behaviour."
askYesNo "Do you really want to continue?" || cancel
fi
cores=$(nproc)
if [[ "$cores" -ge "$MIN_CPU_CORES" ]]; then
log "$cores CPU cores detected; $MIN_CPU_CORES is required minimum"
else
log "Less than $MIN_CPU_CORES CPU cores detected"
log "Found only $cores CPU core(s)."
log "Your system does not meet the requirements. See:"
log ""
log " <https://kb.i-doit.com/display/en/System+Requirements>"
log ""
askYesNo "Do you really want to continue?" && cancel
fi
ram=$(vmstat --stats --unit b | grep -i "total memory" | awk '{print $1}')
if [[ "$ram" -ge "$MIN_RAM" ]]; then
log "$ram bytes of total memory detected; $MIN_RAM is required minimum"
else
log "Less than $MIN_RAM bytes of total memory detected"
log "Found only $ram bytes."
log "Your system does not meet the requirements. See:"
log ""
log " <https://kb.i-doit.com/display/en/System+Requirements>"
log ""
askYesNo "Do you really want to continue?" && cancel
fi
}
function checkSoftwareRequirements {
local failed=0
log "Check for installed applications and services…"
MARIADB_BIN=$(command -v mysql)
SUDO_BIN=$(command -v sudo)
UNZIP_BIN=$(command -v unzip)
WGET_BIN=$(command -v wget)
PHP_BIN=$(command -v php)
declare -A binaries
binaries["mariabdb"]="$MARIADB_BIN"
binaries["sudo"]="$SUDO_BIN"
binaries["unzip"]="$UNZIP_BIN"
binaries["wget"]="$WGET_BIN"
binaries["php"]="$PHP_BIN"
binaries["systemctl"]=$(command -v systemctl)
binaries["chronic"]=$(command -v chronic)
binaries["memcached"]=$(command -v memcached)
case "$OS" in
"rhel7"|"rhel8"|"centos7"|"centos8")
binaries["httpd"]=$(command -v httpd)
;;
*)
binaries["apachectl"]=$(command -v apachectl)
;;
esac
for bin in "${!binaries[@]}"; do
if [[ -x "${binaries[$bin]}" ]]; then
log "$bin: found"
else
log "$bin: missing"
((failed++))
fi
done
if [[ -x "$PHP_BIN" ]]; then
log "Check for installed PHP extensions…"
case "$OS" in
## TODO There is no php-memcached on RHEL 8:
"rhel8"|"centos8")
local phpExtensions=(bcmath ctype curl fileinfo gd json ldap \
mbstring mysqli mysqlnd pgsql session soap xml zip)
;;
*)
local phpExtensions=(bcmath ctype curl fileinfo gd json ldap \
mbstring memcached mysqli mysqlnd pgsql session soap xml zip)
;;
esac
for phpExtension in "${phpExtensions[@]}"; do
if "$PHP_BIN" -m | grep "$phpExtension" > /dev/null; then
log "PHP extension $phpExtension: found"
else
log "PHP extension $phpExtension: missing"
((failed++))
fi
done
fi
case "$failed" in
0)
log "All software requirements met. Excellent."
;;
1)
abort "Important software requirement is missing. Please install and configure it."
;;
*)
abort "Important software requirements are missing. Please install and configure them."
;;
esac
}
function configureOS {
case "$OS" in
"debian10")
configureDebian10
;;
"ubuntu2004")
configureUbuntu2004
;;
"ubuntu1804")
configureUbuntu1804
;;
"rhel7")
configureRHEL7
;;
"rhel8")
configureRHEL8
;;
"centos7")
configureCentOS7
;;
"centos8")
configureCentOS8
;;
"sles15")
configureSLES15
;;
*)
abort "Unkown operating system '${OS}'!?!"
esac
}
function configureDebian10 {
log "Keep your Debian packages up-to-date"
apt-get -qq --yes update || abort "Unable to update Debian package repositories"
apt-get -qq --yes full-upgrade || abort "Unable to perform update of Debian packages"
apt-get -qq --yes clean || abort "Unable to cleanup Debian packages"
apt-get -qq --yes autoremove || abort "Unable to remove unnecessary Debian packages"
log "Install required Debian packages"
apt-get -qq --yes install --no-install-recommends \
apache2 libapache2-mod-fcgid \
mariadb-client mariadb-server \
php7.3-bcmath php7.3-cli php7.3-common php7.3-curl php7.3-fpm php7.3-gd php7.3-json \
php7.3-ldap php7.3-mbstring php7.3-mysql php7.3-opcache php7.3-pgsql \
php7.3-soap php7.3-xml php7.3-zip \
php-memcached \
memcached unzip sudo moreutils || abort "Unable to install required Debian packages"
}
function configureUbuntu1804 {
log "Keep your Ubuntu packages up-to-date"
apt-get -qq --yes update || abort "Unable to update Ubuntu package repositories"
apt-get -qq --yes full-upgrade || abort "Unable to perform update of Ubuntu packages"
apt-get -qq --yes clean || abort "Unable to cleanup Ubuntu packages"
apt-get -qq --yes autoremove || abort "Unable to remove unnecessary Ubuntu packages"
log "Install required Ubuntu packages"
apt-get -qq --yes install --no-install-recommends \
apache2 libapache2-mod-fcgid \
mariadb-client mariadb-server \
php7.2-bcmath php7.2-cli php7.2-common php7.2-curl php7.2-fpm php7.2-gd php7.2-json \
php7.2-ldap php7.2-mbstring php7.2-mysql php7.2-opcache php7.2-pgsql \
php7.2-soap php7.2-xml php7.2-zip \
php-memcached \
memcached unzip moreutils || abort "Unable to install required Ubuntu packages"
}
function configureUbuntu2004 {
log "Keep your Ubuntu packages up-to-date"
apt-get -qq --yes update || abort "Unable to update Ubuntu package repositories"
apt-get -qq --yes full-upgrade || abort "Unable to perform update of Ubuntu packages"
apt-get -qq --yes clean || abort "Unable to cleanup Ubuntu packages"
apt-get -qq --yes autoremove || abort "Unable to remove unnecessary Ubuntu packages"
log "Install required Ubuntu packages"
apt-get -qq --yes install --no-install-recommends \
apache2 libapache2-mod-fcgid \
mariadb-client mariadb-server \
php7.4-bcmath php7.4-cli php7.4-common php7.4-curl php7.4-fpm php7.4-gd php7.4-json \
php7.4-ldap php7.4-mbstring php7.4-mysql php7.4-opcache php7.4-pgsql \
php7.4-soap php7.4-xml php7.4-zip \
php-memcached \
memcached unzip moreutils || abort "Unable to install required Ubuntu packages"
}
function configureCentOS7 {
log "Keep your yum packages up-to-date"
yum --assumeyes --quiet update || abort "Unable to update yum packages"
yum --assumeyes --quiet autoremove || abort "Unable to remove out-dated yum packages"
yum --assumeyes --quiet clean all || abort "Unable to clean yum caches"
rm -rf /var/cache/yum || abort "Unable to remove orphaned yum caches"
log "Install some important packages, for example Apache Web server"
yum --assumeyes --quiet install httpd memcached unzip wget zip || \
abort "Unable to install packages"
log "RHEL 7 has out-dated packages for PHP and MariaDB."
log "This script will fix this issue by enabling these 3rd party repositories:"
log ""
log " Webtatic.com for PHP 7.2"
log " Official MariaDB repository for MariaDB 10.3"
log ""
if askYesNo "Do you agree with it?"; then
if ! rpm -qa | grep "epel-release" > /dev/null; then
log "Import EPEL public GPG key"
rpm --import --quiet https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7 || \
abort "Unable to import public GPG key from EPEL"
log "Add EPEL releases"
rpm -Uvh --quiet https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || \
abort "Unable to install epel-releases via yum"
fi
if ! rpm -qa | grep "webtatic-release" > /dev/null; then
log "Import Webtatic public GPG key"
rpm --import --quiet https://mirror.webtatic.com/yum/RPM-GPG-KEY-webtatic-el7 || \
abort "Unable to import GPG key from Webtatic"
log "Add Webtatic releases"
rpm -Uvh --quiet https://mirror.webtatic.com/yum/el7/webtatic-release.rpm || \
abort "Unable to add Webtatic"
fi
log "Install PHP packages"
yum --assumeyes --quiet install \
php72w-bcmath php72w-cli php72w-common php72w-fpm php72w-gd php72w-ldap \
php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo \
php72w-pecl-memcached php72w-pgsql php72w-soap php72w-xml || \
abort "Unable to install PHP packages"
log "Enable MariaDB repository"
cat << EOF > /etc/yum.repos.d/MariaDB.repo || \
abort "Unable to create and edit file '/etc/yum.repos.d/MariaDB.repo'"
# MariaDB 10.3 repository list
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
log "Install MariaDB packages"
rpm --import --quiet https://yum.mariadb.org/RPM-GPG-KEY-MariaDB || \
abort "Unable to import GPG key from MariaDB"
## Suppress unnecessary notices which could confuse the user:
yum --assumeyes --quiet install MariaDB-server MariaDB-client &> /dev/null || \
abort "Unable to install MariaDB"
fi
log "Install 'moreutils'"
yum --assumeyes --quiet install moreutils || \
abort "Unable to install packages"
for unit in $APACHE_UNIT $MARIADB_UNIT $MEMCACHED_UNIT $PHP_FPM_UNIT; do
unitctl "enable" "$unit"
unitctl "start" "$unit"
done
log "Allow incoming HTTP traffic"
systemctl -q is-active firewalld.service || (
log "Firewall is inactive."
unitctl "start" "firewalld"
)
firewall-cmd --permanent --add-service=http || abort "Unable to configure firewall"
unitctl "restart" "firewalld"
}
function configureCentOS8 {
log "Keep your yum packages up-to-date"
yum --assumeyes --quiet update || abort "Unable to update yum packages"
yum --assumeyes --quiet autoremove || abort "Unable to remove out-dated yum packages"
yum --assumeyes --quiet clean all || abort "Unable to clean yum caches"
rm -rf /var/cache/yum || abort "Unable to remove orphaned yum caches"
for appStream in httpd:2.4 mariadb:10.3 php:7.2; do
log "Install AppStream $appStream"
yum --assumeyes --quiet module install "$appStream"
done
log "Install some important packages"
yum --assumeyes --quiet install \
memcached unzip wget zip \
php-bcmath php-gd php-ldap php-mysqli php-mysqlnd \
php-pgsql php-soap php-zip || \
abort "Unable to install packages"
if [[ ! -x "$(command -v chronic)" ]]; then
log "Install 'chronic'"
## TODO: I know, this seems to be pretty ugly, but:
## Why the hack is moreutils not included in the standard repositories?!?
wget --quiet -O "${TMP_DIR}/chronic" \
https://git.joeyh.name/index.cgi/moreutils.git/plain/chronic || \
abort "Unable to download 'chronic'"
chmod +x "${TMP_DIR}/chronic" || \
abort "Unable to set executable bit"
mv "${TMP_DIR}/chronic" /usr/local/bin || \
abort "Unable to move 'chronic' to '/usr/local/bin'"
yum --assumeyes --quiet module install perl-App-cpanminus || \
abort "Unable to install cpanm"
cpanm --quiet --notest --install IPC::Run || \
abort "Unable to install Perl module IPC::Run"
fi
for unit in $APACHE_UNIT $MARIADB_UNIT $MEMCACHED_UNIT $PHP_FPM_UNIT; do
unitctl "enable" "$unit"
unitctl "start" "$unit"
done
log "Allow incoming HTTP traffic"
systemctl -q is-active firewalld.service || (
log "Firewall is inactive."
unitctl "start" "firewalld"
)
firewall-cmd --permanent --add-service=http || abort "Unable to configure firewall"
unitctl "restart" "firewalld"
}
function configureRHEL8 {
log "Keep your yum packages up-to-date"
yum --assumeyes --quiet update || abort "Unable to update yum packages"
yum --assumeyes --quiet autoremove || abort "Unable to remove out-dated yum packages"
yum --assumeyes --quiet clean all || abort "Unable to clean yum caches"
rm -rf /var/cache/yum || abort "Unable to remove orphaned yum caches"
for appStream in httpd:2.4 mariadb:10.3 php:7.2; do
log "Install AppStream $appStream"
yum --assumeyes --quiet module install "$appStream"
done
log "Install some important packages"
yum --assumeyes --quiet install \
memcached unzip wget zip \
php-bcmath php-gd php-ldap php-mysqli php-mysqlnd \
php-pgsql php-soap php-zip || \
abort "Unable to install packages"
if [[ ! -x "$(command -v chronic)" ]]; then
log "Install 'chronic'"
## TODO: I know, this seems to be pretty ugly, but:
## Why the hack is moreutils not included in the standard repositories?!?
wget --quiet -O "${TMP_DIR}/chronic" \
https://git.joeyh.name/index.cgi/moreutils.git/plain/chronic || \
abort "Unable to download 'chronic'"
chmod +x "${TMP_DIR}/chronic" || \
abort "Unable to set executable bit"
mv "${TMP_DIR}/chronic" /usr/local/bin || \
abort "Unable to move 'chronic' to '/usr/local/bin'"
yum --assumeyes --quiet module install perl-App-cpanminus || \
abort "Unable to install cpanm"
cpanm --quiet --notest --install IPC::Run || \
abort "Unable to install Perl module IPC::Run"
fi
for unit in $APACHE_UNIT $MARIADB_UNIT $MEMCACHED_UNIT $PHP_FPM_UNIT; do
unitctl "enable" "$unit"
unitctl "start" "$unit"
done
log "Allow incoming HTTP traffic"
systemctl -q is-active firewalld.service || (
log "Firewall is inactive."
unitctl "start" "firewalld"
)
firewall-cmd --permanent --add-service=http || abort "Unable to configure firewall"
unitctl "restart" "firewalld"
}
function configureRHEL7 {
log "Keep your yum packages up-to-date"
yum --assumeyes --quiet update || abort "Unable to update yum packages"
yum --assumeyes --quiet autoremove || abort "Unable to remove out-dated yum packages"
yum --assumeyes --quiet clean all || abort "Unable to clean yum caches"
rm -rf /var/cache/yum || abort "Unable to remove orphaned yum caches"
log "Install some important packages, for example Apache Web server"
yum --assumeyes --quiet install httpd memcached unzip wget zip || \
abort "Unable to install packages"
log "RHEL 7 has out-dated packages for PHP and MariaDB."
log "This script will fix this issue by enabling these 3rd party repositories:"
log ""
log " Webtatic.com for PHP 7.2"
log " Official MariaDB repository for MariaDB 10.3"
log ""
if askYesNo "Do you agree with it?"; then
if ! rpm -qa | grep "epel-release" > /dev/null; then
log "Import EPEL public GPG key"
rpm --import --quiet https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7 || \
abort "Unable to import public GPG key from EPEL"
log "Add EPEL releases"
rpm -Uvh --quiet https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || \
abort "Unable to install epel-releases via yum"
fi
if ! rpm -qa | grep "webtatic-release" > /dev/null; then
log "Import Webtatic public GPG key"
rpm --import --quiet https://mirror.webtatic.com/yum/RPM-GPG-KEY-webtatic-el7 || \
abort "Unable to import GPG key from Webtatic"
log "Add Webtatic releases"
rpm -Uvh --quiet https://mirror.webtatic.com/yum/el7/webtatic-release.rpm || \
abort "Unable to add Webtatic"
fi
log "Install PHP packages"
yum --assumeyes --quiet install \
php72w-bcmath php72w-cli php72w-common php72w-fpm php72w-gd php72w-ldap \
php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo \
php72w-pecl-memcached php72w-pgsql php72w-soap php72w-xml || \
abort "Unable to install PHP packages"
log "Enable MariaDB repository"
cat << EOF > /etc/yum.repos.d/MariaDB.repo || \
abort "Unable to create and edit file '/etc/yum.repos.d/MariaDB.repo'"
# MariaDB 10.3 RedHat repository list
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/rhel7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
log "Install MariaDB packages"
rpm --import --quiet https://yum.mariadb.org/RPM-GPG-KEY-MariaDB || \
abort "Unable to import GPG key from MariaDB"
## Suppress unnecessary notices which could confuse the user:
yum --assumeyes --quiet install MariaDB-server MariaDB-client &> /dev/null || \
abort "Unable to install MariaDB"
fi
log "Enable required repository 'rhel-7-server-eus-optional-rpms'"
subscription-manager repos --enable=rhel-7-server-eus-optional-rpms || \
abort "Repository cannot be enabled"
## Install moreutils *after* EPEL *and* rhel-7-server-eus-optional-rpms have been
## enabled!
log "Install 'moreutils'"
yum --assumeyes --quiet install moreutils || \
abort "Unable to install packages"
for unit in $APACHE_UNIT $MARIADB_UNIT $MEMCACHED_UNIT $PHP_FPM_UNIT; do
unitctl "enable" "$unit"
unitctl "start" "$unit"
done
log "Allow incoming HTTP traffic"
systemctl -q is-active firewalld.service || (
log "Firewall is inactive."
unitctl "start" "firewalld"
)
firewall-cmd --permanent --add-service=http || abort "Unable to configure firewall"
unitctl "restart" "firewalld"
}
function configureSLES15 {
local web_repos=""
local openSuseRepo=""
local webScriptingModuleAlias="Web_and_Scripting_Module_${VERSION_ID}_x86_64"
local webScriptingModuleProduct="sle-module-web-scripting/${VERSION_ID}/x86_64"
log "Keep your packages up-to-date"
zypper --quiet --non-interactive refresh || abort "Unable to refresh software repositories"
zypper --quiet --non-interactive update || abort "Unable to update software packages"
web_repos=$(zypper repos -E | grep -c "$webScriptingModuleAlias")
if [[ "$web_repos" -lt 2 ]]; then
log "The following module is required:"
log ""
log " Web and Scripting"
log ""
log "This script will activate it."
if askYesNo "Do you agree with it?"; then
SUSEConnect -p "$webScriptingModuleProduct" || \
abort "Unable to active module"
else
abort "Essential software repositories are missing"
fi
fi
log "Install software packages"
zypper --quiet --non-interactive install --no-recommends \
apache2 \
mariadb mariadb-client \
memcached \
make sudo unzip \
php7 php7-bcmath php7-bz2 php7-ctype php7-curl php7-fpm php7-gd php7-gettext php7-fileinfo \
php7-json php7-ldap php7-mbstring php7-mysql php7-opcache php7-openssl php7-pdo php7-pgsql \
php7-phar php7-posix php7-soap php7-sockets php7-sqlite php7-xsl php7-zip php7-zlib || \
abort "Unable to install required software packages"
openSuseRepo=$(zypper repos -E | grep -c "server_php_extensions_php7")
if [[ "$openSuseRepo" -lt 1 ]]; then
log "i-doit requires PHP module for memcached"
log "But this PHP module is not available in SLE standard repositories"
log "It will be installed from a 3rd-party repository from openSUSE:"
log ""
log " server:php:extensions:php7"
log ""
log "Details:"
log ""
log " https://software.opensuse.org/download.html?project=server%3Aphp%3Aextensions%3Aphp7&package=php7-memcached"
zypper --quiet --non-interactive addrepo \
--gpgcheck --refresh \
https://download.opensuse.org/repositories/server:php:extensions:php7/SLE_15/server:php:extensions:php7.repo || \
abort "Unable to add repository"
zypper --quiet --non-interactive --gpg-auto-import-keys refresh || \
abort "Unable to refresh software repositories"
fi
zypper --quiet --non-interactive install --no-recommends php7-memcached || \
abort "Unable to install required software package"
zypper --quiet --non-interactive clean || abort "Unable to clean up cached software packages"
for unit in $APACHE_UNIT $MARIADB_UNIT $MEMCACHED_UNIT; do
unitctl "enable" "$unit"
unitctl "start" "$unit"
done
log "Allow incoming HTTP traffic"
systemctl -q is-active firewalld.service || (
log "Firewall is inactive."
unitctl "start" "firewalld"
)
firewall-cmd --permanent --add-service=http || abort "Unable to configure firewall"
unitctl "restart" "firewalld"
if [[ ! -x "$(command -v chronic)" ]]; then
log "Install 'chronic'"
## TODO: I know, this seems to be pretty ugly, but:
## Why the hack is moreutils not included in the standard repositories?!?
wget --quiet -O "${TMP_DIR}/chronic" \
https://git.joeyh.name/index.cgi/moreutils.git/plain/chronic || \
abort "Unable to download 'chronic'"
chmod +x "${TMP_DIR}/chronic" || \
abort "Unable to set executable bit"
mv "${TMP_DIR}/chronic" /usr/bin || \
abort "Unable to move 'chronic' to '/usr/bin'"
wget --quiet -O - https://cpanmin.us | perl - App::cpanminus || \
abort "Unable to install cpanminus"
cpanm --quiet --notest --install IPC::Run || \
abort "Unable to install Perl module IPC::Run"
fi
}
function configureProxy {
if [[ -n "${https_proxy+x}" ]]; then
log "Found proxy settings in environment variable 'https_proxy': $https_proxy"
askYesNo "Do you want to use this setting?" && return 0
fi
echo -n -e "Provide proxy settings [schema: https://username:password@proxy:port]: "
read -r answer
if [[ -n "$answer" ]]; then
log "Set environment variable 'https_proxy' to '${answer}'"
export https_proxy="$answer"
else
log "No settings found. Skip it."
fi
}
function configurePHP {
local php_en_mod=""
local php_version=""
log "Configure PHP"
php_version=$(php --version | head -n1 -c7 | tail -c3)
case "$php_version" in
"5.4"|"5.5"|"5.6"|"7.0")
abort "PHP ${php_version} is way too old. Please upgrade. We recommend version ${RECOMMENDED_PHP_VERSION}."
;;
"7.1")
log "PHP ${php_version} is installed, but this version is deprecated. Please consider to upgrade. We recommend version ${RECOMMENDED_PHP_VERSION}."
php_en_mod=$(command -v phpenmod)
;;
"7.2"|"7.3"|"7.4")
php_en_mod=$(command -v phpenmod)
;;
"8.0")
abort "PHP ${php_version} is installed, but this version is not suitable in a productive environment. Please consider to downgrade. We recommend version ${RECOMMENDED_PHP_VERSION}."