forked from RestyaPlatform/board
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restyaboard.sh
executable file
·2009 lines (1933 loc) · 71.2 KB
/
restyaboard.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#
# Install script for Restyaboard
#
# Usage: ./restyaboard.sh
#
# Copyright (c) 2014-2022 Restya.
# Dual License (OSL 3.0 & Commercial License)
{
main() {
if [[ $EUID -ne 0 ]];
then
echo "This script must be run as root"
exit 1
fi
set -x
whoami
#
# Checking the OS name and OS version
#
find_release ()
{
# Checking the Ubuntu OS
if [ -f /etc/lsb-release ]; then
OS_REQUIREMENT="`grep DISTRIB_ID /etc/lsb-release`"
DISTRIB_ID='DISTRIB_ID='
OS_NAME=$OS_REQUIREMENT$DISTRIB_ID
array=();
if ([ "$OS_REQUIREMENT" != "$DISTRIB_ID" ])
then
while [[ $OS_NAME ]]; do
array+=( "${OS_NAME%%"$DISTRIB_ID"*}" );
OS_NAME=${OS_NAME#*"$DISTRIB_ID"};
done;
OS_REQUIREMENT=${array[1]}
fi
OS_VERSION="`grep DISTRIB_RELEASE /etc/lsb-release`"
DISTRIB_RELEASE='DISTRIB_RELEASE='
OS_Ver=$OS_VERSION$DISTRIB_RELEASE
version=();
if ([ "$OS_VERSION" != "$DISTRIB_RELEASE" ])
then
while [[ $OS_Ver ]]; do
version+=( "${OS_Ver%%"$DISTRIB_RELEASE"*}" );
OS_Ver=${OS_Ver#*"$DISTRIB_RELEASE"};
done;
OS_VERSION=${version[1]}
fi
return
fi
# Checking the Redhat, Fedora, and Centos
if [ -f /etc/redhat-release ]; then
OS_REQUIREMENT="`cat /etc/redhat-release | cut -d ' ' -f 1`"
OS_VERSION="`cat /etc/redhat-release | cut -d ' ' -f 4 | cut -d '.' -f 1`"
return
fi
# Checking the Debian OS
if [ -f /etc/issue ]; then
OS_REQUIREMENT="`cat /etc/issue | cut -d ' ' -f 1`"
OS_VERSION="`cat /etc/issue | cut -d ' ' -f 3`"
return
fi
# Checking the OpenBSD
if [ -f /etc/motd ]; then
OS_REQUIREMENT="`cat /etc/motd | head -1 | cut -d ' ' -f 1`"
OS_VERSION="`cat /etc/motd | head -1 | cut -d ' ' -f 2`"
return
fi
}
findbin ()
{
ret=0
newpath=`echo $PATH | tr : ' '`
for i in ${newpath}; do
if [ -x $i/$1 ]; then
ret=1
break
fi
done
echo $ret
return
}
checkdeps()
{
pkginfo="dpkg rpm ipkg pkg_info"
for i in $pkginfo; do
ret=`findbin $i`
if [ $ret -eq 1 ]; then
pkginfo=$i
echo "Yes, found $i, so we'll use that for listing packages"
break
fi
done
if [ ${pkginfo} = "pkg_info" ]; then
# BSD needs PKG_PATH set to load anything over the net.
if [ x${PKG_PATH} = x ]; then
echo "Please set the environment variable PKG_PATH and try again."
exit 1
fi
fi
pkg_name="yum apt-get ipkg pkg_add"
for i in ${pkg_name}; do
ret=`findbin $i`
if [ $ret -eq 1 ]; then
pkg_name=$i
echo "Yes, found $i, so we'll use that to install packages"
break
fi
done
for i in ${genericdeps} ${gtkdeps} ${kdedeps}; do
case $pkginfo in
dpkg)
deps="`dpkg -l "*$i*" | grep -- "^ii" | cut -d ' ' -f 3`"
;;
rpm)
deps="`rpm -q $i`"
;;
pkg_info)
deps="`pkg_info | grep "$i" | sed -e 's: .*$::'`"
;;
ipkg)
deps="todo"
;;
*)
echo "ERROR: No package manager found!"
exit 1
;;
esac
found=`echo ${deps} | grep -v 'not installed' | grep -c "${i}" 2>&1`
if [ $found -gt 0 ]; then
echo "Yes, found $i"
else
echo "Nope, $i appears to not be installed"
missing="${missing} $i"
fi
done
if [ -n "${missing}" ]; then
echo "package(s)\"${missing}\" are missing!"
echo "You will need sudo priviledges to install the packages"
if [ x$yes = xno ]; then
$debug sudo ${pkgnet} install ${missing}
else
$debug sudo ${pkgnet} -y install ${missing}
fi
fi
}
install_nginx()
{
if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "LinuxMint" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
then
APACHE_ENABLED=$(service apache2 status | grep 'running' | wc -l)
if [ ${APACHE_ENABLED} -eq 1 ]
then
set +x
echo "It looks like Apache is running in your server. If you've configured and using any other application in Apache then continue in Apache. Otherwise Restyaboard is recommending to use nginx. So script will stop the apache and install nginx in your server. Do you want to continue as Apache provide "y" or to continue with nginx provide "n" (Y/n)?"
read -r answer
set -x
case "${answer}" in
[Nn])
echo "Stopping apache..."
service apache2 stop
APACHE_ENABLED=$(service apache2 status | grep 'running' | wc -l)
echo "Checking nginx..."
if ! which nginx > /dev/null 2>&1; then
echo "nginx not installed!"
set +x
echo "Do you want to install nginx (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
echo "Installing nginx..."
apt install -y cron nginx
error_code=$?
if [ ${error_code} != 0 ]
then
echo "nginx installation failed with error code ${error_code} (nginx installation failed with error code 2)"
return 2
fi
if [ -f "/etc/nginx/conf.d/default" ]; then
rm -rf /etc/nginx/conf.d/default
fi
if [ -f "/etc/nginx/sites-enabled/default" ]; then
rm -rf /etc/nginx/sites-enabled/default
fi
if [ -f "/etc/nginx/sites-available/default" ]; then
rm -rf /etc/nginx/sites-available/default
fi
UFW_ENABLED=$(ufw status | grep 'active' | wc -l)
if [ ${UFW_ENABLED} -eq 1 ]
then
ufw allow 'Nginx HTTP'
ufw allow 'Nginx HTTPS'
fi
service nginx start
esac
fi
esac
else
echo "Checking nginx..."
if ! which nginx > /dev/null 2>&1; then
echo "nginx not installed!"
set +x
echo "Do you want to install nginx (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
echo "Installing nginx..."
apt install -y cron nginx
error_code=$?
if [ ${error_code} != 0 ]
then
echo "nginx installation failed with error code ${error_code} (nginx installation failed with error code 2)"
return 2
fi
if [ -f "/etc/nginx/conf.d/default" ]; then
rm -rf /etc/nginx/conf.d/default
fi
if [ -f "/etc/nginx/sites-enabled/default" ]; then
rm -rf /etc/nginx/sites-enabled/default
fi
if [ -f "/etc/nginx/sites-available/default" ]; then
rm -rf /etc/nginx/sites-available/default
fi
UFW_ENABLED=$(ufw status | grep 'active' | wc -l)
if [ ${UFW_ENABLED} -eq 1 ]
then
ufw allow 'Nginx HTTP'
ufw allow 'Nginx HTTPS'
fi
service nginx start
esac
fi
fi
else
APACHE_ENABLED=$(service httpd status | grep 'running' | wc -l)
if [ ${APACHE_ENABLED} -eq 1 ]
then
set +x
echo "It looks like Apache is running in your server. If you've configured and using any other application in Apache then continue in Apache. Otherwise Restyaboard is recommending to use nginx. So script will stop the apache and install nginx in your server. Do you want to continue as Apache provide "y" or to continue with nginx provide "n" (Y/n)?"
read -r answer
set -x
case "${answer}" in
[Nn])
echo "Stopping apache..."
service httpd stop
APACHE_ENABLED=$(service httpd status | grep 'running' | wc -l)
echo "Checking nginx..."
if ! which nginx > /dev/null 2>&1; then
echo "nginx not installed!"
set +x
echo "Do you want to install nginx (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
echo "Installing nginx..."
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install nginx
else
rpm -Uvh "http://nginx.org/packages/centos/${OS_VERSION}/noarch/RPMS/nginx-release-centos-${OS_VERSION}-0.el${OS_VERSION}.ngx.noarch.rpm"
yum install -y zip cronie nginx
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "cron nginx installation failed with error code ${error_code} cron nginx installation failed with error code 18"
return 18
fi
if [ -f "/etc/nginx/conf.d/default.conf" ]; then
rm -rf /etc/nginx/conf.d/default.conf
fi
if [ -f "/etc/nginx/sites-enabled/default.conf" ]; then
rm -rf /etc/nginx/sites-enabled/default.conf
fi
if [ -f "/etc/nginx/sites-available/default.conf" ]; then
rm -rf /etc/nginx/sites-available/default.conf
fi
FIREWALL_ENABLED=$(firewall-cmd --state | grep 'running' | wc -l)
if [ ${FIREWALL_ENABLED} -eq 1 ]
then
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
fi
service nginx start
chkconfig --levels 35 nginx on
esac
fi
esac
else
echo "Checking nginx..."
if ! which nginx > /dev/null 2>&1; then
echo "nginx not installed!"
set +x
echo "Do you want to install nginx (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
echo "Installing nginx..."
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install nginx
else
rpm -Uvh "http://nginx.org/packages/centos/${OS_VERSION}/noarch/RPMS/nginx-release-centos-${OS_VERSION}-0.el${OS_VERSION}.ngx.noarch.rpm"
yum install -y zip cronie nginx
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "cron nginx installation failed with error code ${error_code} cron nginx installation failed with error code 18"
return 18
fi
if [ -f "/etc/nginx/conf.d/default.conf" ]; then
rm -rf /etc/nginx/conf.d/default.conf
fi
if [ -f "/etc/nginx/sites-enabled/default.conf" ]; then
rm -rf /etc/nginx/sites-enabled/default.conf
fi
if [ -f "/etc/nginx/sites-available/default.conf" ]; then
rm -rf /etc/nginx/sites-available/default.conf
fi
FIREWALL_ENABLED=$(firewall-cmd --state | grep 'running' | wc -l)
if [ ${FIREWALL_ENABLED} -eq 1 ]
then
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
fi
service nginx start
chkconfig --levels 35 nginx on
esac
fi
fi
fi
}
install_php()
{
if ! hash php 2>&-; then
echo "PHP is not installed!"
set +x
echo "Do you want to install PHP (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
if ([ "$pkg_name" = "apt-get" ])
then
echo "Installing PHP..."
apt install -y php7.4 php7.4-common --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "PHP installation failed with error code ${error_code} (PHP installation failed with error code 3)"
return 3
fi
else
if ([ "$pkg_name" = "yum" ])
then
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
echo "Note: For the latest version of PHP, we're going to download https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm and https://rpms.remirepo.net/enterprise/remi-release-8.rpm."
echo "Installing PHP..."
dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-${OS_VERSION}.noarch.rpm
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-${OS_VERSION}.rpm
dnf module enable php:remi-7.4
dnf -y install php php-cli php-common
else
yum install -y epel-release
echo "Note: For the latest version of PHP, we're going to download http://rpms.famillecollet.com/enterprise/remi-release-${OS_VERSION}.rpm."
echo "Installing PHP..."
rpm -Uvh "http://rpms.famillecollet.com/enterprise/remi-release-${OS_VERSION}.rpm"
yum --enablerepo=remi-php74 install -y php
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php installation failed with error code ${error_code} (php installation failed with error code 20)"
return 20
fi
fi
fi
esac
fi
echo "Installing PHP fpm and cli extension..."
if ([ "$pkg_name" = "apt-get" ])
then
apt install -y php7.4-fpm php7.4-cli --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php7.4-cli installation failed with error code ${error_code} (php7.4-cli installation failed with error code 4)"
fi
service php7.4-fpm start
else
if ([ "$pkg_name" = "yum" ])
then
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install php-fpm php-devel php-opcache
dnf -y install php-json
else
yum --enablerepo=remi-php74 install -y php-fpm php-devel php-cli php-opcache
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php-devel installation failed with error code ${error_code} (php-devel installation failed with error code 21)"
return 21
fi
service php-fpm start
fi
fi
if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "LinuxMint" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
then
echo "...."
else
chkconfig --levels 35 php-fpm on
fi
echo "Checking PHP curl extension..."
php -m | grep curl
if [ "$?" -gt 0 ]; then
echo "Installing php-curl..."
if ([ "$pkg_name" = "apt-get" ])
then
apt install -y php7.4-curl --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php7.4-curl installation failed with error code ${error_code} (php7.4-curl installation failed with error code 5)"
return 5
fi
else
if ([ "$pkg_name" = "yum" ])
then
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install php-curl
else
yum --enablerepo=remi-php74 install -y php-curl
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php-curl installation failed with error code ${error_code} (php-curl installation failed with error code 22)"
return 22
fi
fi
fi
fi
echo "Checking PHP pgsql extension..."
php -m | grep pgsql
if [ "$?" -gt 0 ]; then
echo "Installing php-pgsql..."
if ([ "$pkg_name" = "apt-get" ])
then
apt install libpq5
apt install -y php7.4-pgsql --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php7.4-pgsql installation failed with error code ${error_code} (php7.4-pgsql installation failed with error code 6)"
return 6
fi
else
if ([ "$pkg_name" = "yum" ])
then
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install php-pgsql
else
yum --enablerepo=remi-php74 install -y php-pgsql
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php-pgsql installation failed with error code ${error_code} (php-pgsql installation failed with error code 23)"
return 23
fi
fi
fi
fi
echo "Checking PHP mbstring extension..."
php -m | grep mbstring
if [ "$?" -gt 0 ]; then
echo "Installing php-mbstring..."
if ([ "$pkg_name" = "apt-get" ])
then
apt install -y php7.4-mbstring --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php7.4-mbstring installation failed with error code ${error_code} (php7.4-mbstring installation failed with error code 7)"
return 7
fi
else
if ([ "$pkg_name" = "yum" ])
then
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install php-mbstring
else
yum --enablerepo=remi-php74 install -y php-mbstring
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php-mbstring installation failed with error code ${error_code} (php-mbstring installation failed with error code 24)"
return 24
fi
fi
fi
fi
echo "Checking PHP ldap extension..."
php -m | grep ldap
if [ "$?" -gt 0 ]; then
echo "Installing php-ldap..."
if ([ "$pkg_name" = "apt-get" ])
then
apt install -y php7.4-ldap --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php7.4-ldap installation failed with error code ${error_code} (php7.4-ldap installation failed with error code 8)"
return 8
fi
else
if ([ "$pkg_name" = "yum" ])
then
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install php-ldap
else
yum --enablerepo=remi-php74 install -y php-ldap
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php-ldap installation failed with error code ${error_code} (php-ldap installation failed with error code 25)"
return 25
fi
fi
fi
fi
echo "Checking PHP imagick extension..."
php -m | grep imagick
if [ "$?" -gt 0 ]; then
echo "Installing php-imagick..."
if ([ "$pkg_name" = "apt-get" ])
then
apt install -y gcc
error_code=$?
if [ ${error_code} != 0 ]
then
echo "gcc installation failed with error code ${error_code} (gcc installation failed with error code 9)"
return 9
fi
apt install -y imagemagick
error_code=$?
if [ ${error_code} != 0 ]
then
echo "imagemagick installation failed with error code ${error_code} (imagemagick installation failed with error code 9)"
return 9
fi
apt install -y php7.4-imagick --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php7.4-imagick installation failed with error code ${error_code} (php7.4-imagick installation failed with error code 10)"
return 10
fi
else
if ([ "$pkg_name" = "yum" ])
then
yum install -y ImageM* netpbm gd gd-* libjpeg libexif gcc coreutils make
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install php-pear
dnf -y install php-gd
else
yum --enablerepo=remi-php74 install -y php-pear
yum --enablerepo=remi-php74 install -y php-gd
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "Installing php-imagick failed with error code ${error_code} (Installing php-imagick failed with error code 26)"
return 26
fi
cd /usr/local/src
wget http://pecl.php.net/get/imagick-2.2.2.tgz
tar zxvf ./imagick-2.2.2.tgz
cd imagick-2.2.2
phpize
./configure
make
make test
make install
echo "extension=imagick.so" >> /etc/php.ini
fi
fi
fi
echo "Checking PHP imap extension..."
php -m | grep imap
if [ "$?" -gt 0 ]; then
echo "Installing php7.4-imap..."
if ([ "$pkg_name" = "apt-get" ])
then
apt install -y php7.4-imap --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php7.4-imap installation failed with error code ${error_code} (php7.4-imap installation failed with error code 11)"
return 11
fi
else
if ([ "$pkg_name" = "yum" ])
then
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install php-imap
else
yum --enablerepo=remi-php74 install -y php-imap
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php-imap installation failed with error code ${error_code} (php-imap installation failed with error code 26)"
return 26
fi
fi
fi
fi
echo "Checking xml..."
php -m | grep xml
if [ "$?" -gt 0 ]; then
echo "Installing xml..."
if ([ "$pkg_name" = "apt-get" ])
then
apt install php7.4-xml --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "xml installation failed with error code ${error_code} (xml installation failed with error code 56)"
return 56
fi
else
if ([ "$pkg_name" = "yum" ])
then
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf -y install php-xml
else
yum --enablerepo=remi-php74 install -y php-xml
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "xml installation failed with error code ${error_code} (xml installation failed with error code 57)"
return 57
fi
fi
fi
fi
}
set_timezone()
{
if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "LinuxMint" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
then
timezone=$(cat /etc/timezone)
sed -i -e 's/date.timezone/;date.timezone/g' /etc/php/7.4/fpm/php.ini
echo "date.timezone = $timezone" >> /etc/php/7.4/fpm/php.ini
else
PHP_VERSION=$(php -v | grep "PHP 5" | sed 's/.*PHP \([^-]*\).*/\1/' | cut -c 1-3)
echo "Installed PHP version: '$PHP_VERSION'"
timezone=$(cat /etc/sysconfig/clock | grep ZONE | cut -d"\"" -f2)
sed -i -e 's/date.timezone/;date.timezone/g' /etc/php.ini
echo "date.timezone = $timezone" >> /etc/php.ini
fi
}
install_postgresql()
{
if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "LinuxMint" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
then
id -a postgres
error_code=$?
if [ ${error_code} != 0 ]; then
echo "PostgreSQL not installed!"
set +x
echo "Do you want to install PostgreSQL (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
echo "Installing PostgreSQL..."
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
apt install wget ca-certificates
error_code=$?
if [ ${error_code} != 0 ]
then
echo "ca-certificates installation failed with error code ${error_code} (ca-certificates installation failed with error code 12)"
fi
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc
apt-key add ACCC4CF8.asc
apt update
apt install -y postgresql --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "postgresql installation failed with error code ${error_code} (postgresql installation failed with error code 13)"
return 13
fi
esac
else
PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}' | head -1)
if [[ ${PSQL_VERSION} == "" ]]; then
PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
fi
if [[ ${PSQL_VERSION} =~ ^10\.[0-9]{1,}$ ]]; then
PSQL_VERSION=10
fi
if [[ ${PSQL_VERSION} =~ ^11\.[0-9]{1,}$ ]]; then
PSQL_VERSION=11
fi
if [[ ${PSQL_VERSION} =~ ^12\.[0-9]{1,}$ ]]; then
PSQL_VERSION=12
fi
if [[ ${PSQL_VERSION} =~ ^13\.[0-9]{1,}$ ]]; then
PSQL_VERSION=13
fi
if [[ 1 -eq "$(echo "${PSQL_VERSION} < 9.3" | bc)" ]]; then
set +x
echo "Restyaboard will not work in your PostgreSQL version (i.e. less than 9.3). So script going to update PostgreSQL version 9.6"
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
apt install wget ca-certificates
error_code=$?
if [ ${error_code} != 0 ]
then
echo "ca-certificates installation failed with error code ${error_code} (ca-certificates installation failed with error code 12)"
fi
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc
apt-key add ACCC4CF8.asc
apt update
apt upgrade
apt install -y postgresql --allow-unauthenticated
error_code=$?
if [ ${error_code} != 0 ]
then
echo "postgresql installation failed with error code ${error_code} (postgresql installation failed with error code 13)"
return 13
fi
fi
fi
PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}' | head -1)
if [[ ${PSQL_VERSION} == "" ]]; then
PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
fi
if [[ ${PSQL_VERSION} =~ ^10\.[0-9]{1,}$ ]]; then
PSQL_VERSION=10
fi
if [[ ${PSQL_VERSION} =~ ^11\.[0-9]{1,}$ ]]; then
PSQL_VERSION=11
fi
if [[ ${PSQL_VERSION} =~ ^12\.[0-9]{1,}$ ]]; then
PSQL_VERSION=12
fi
if [[ ${PSQL_VERSION} =~ ^13\.[0-9]{1,}$ ]]; then
PSQL_VERSION=13
fi
sed -e 's/peer/trust/g' -e 's/ident/trust/g' < /etc/postgresql/${PSQL_VERSION}/main/pg_hba.conf > /etc/postgresql/${PSQL_VERSION}/main/pg_hba.conf.1
cd /etc/postgresql/${PSQL_VERSION}/main || exit
mv pg_hba.conf pg_hba.conf_old
mv pg_hba.conf.1 pg_hba.conf
service postgresql restart
else
if ! which psql > /dev/null 2>&1;
then
echo "PostgreSQL not installed!"
set +x
echo "Do you want to install PostgreSQL (y/n)?"
read -r answer
set -x
case "${answer}" in
[Yy])
echo "Installing PostgreSQL..."
if [ $(getconf LONG_BIT) = "64" ]; then
if [[ $OS_REQUIREMENT = "Fedora" ]]; then
dnf install -y "https://download.postgresql.org/pub/repos/yum/reporpms/F-${OS_VERSION}-x86_64/pgdg-fedora-repo-latest.noarch.rpm"
else
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
echo "...."
else
yum install -y "https://download.postgresql.org/pub/repos/yum/reporpms/EL-${OS_VERSION}-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
fi
fi
fi
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf module enable postgresql:13
dnf -y install postgresql-server postgresql-contrib postgresql-libs
else
yum install -y postgresql13 postgresql13-server postgresql13-contrib postgresql13-libs
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "postgresql13 installation failed with error code ${error_code} (postgresql13 installation failed with error code 29)"
return 29
fi
esac
else
PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
if [[ $PSQL_VERSION < 9.3 ]]; then
set +x
echo "Restyaboard will not work in your PostgreSQL version (i.e. less than 9.3). So script going to update PostgreSQL version 9.6"
if [ $(getconf LONG_BIT) = "64" ]; then
if [[ $OS_REQUIREMENT = "Fedora" ]]; then
dnf install -y "https://download.postgresql.org/pub/repos/yum/reporpms/F-${OS_VERSION}-x86_64/pgdg-fedora-repo-latest.noarch.rpm"
else
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" != "8" ])
then
yum install -y "https://download.postgresql.org/pub/repos/yum/reporpms/EL-${OS_VERSION}-x86_64/pgdg-redhat-repo-latest.noarch.rpm"
fi
fi
fi
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
dnf module enable postgresql:13
dnf -y install postgresql-server postgresql-contrib postgresql-libs
else
yum install -y postgresql13 postgresql13-server postgresql13-contrib postgresql13-libs
fi
error_code=$?
if [ ${error_code} != 0 ]
then
echo "postgresql installation failed with error code ${error_code} (postgresql installation failed with error code 29)"
return 29
fi
fi
fi
PSQL_VERSION=$(psql --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
if [[ ${PSQL_VERSION} =~ ^13\.[0-9]{1,}$ ]]; then
PSQL_VERSION=13
fi
PSQL_FOLDER=$(echo ${PSQL_VERSION} | sed 's/\.//')
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
postgresql-setup --initdb
else
"/usr/pgsql-${PSQL_VERSION}/bin/postgresql-${PSQL_VERSION}-setup" initdb
fi
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
systemctl enable postgresql
systemctl start postgresql
else
if [ -f "/bin/systemctl" ]; then
systemctl start "postgresql-${PSQL_VERSION}.service"
systemctl enable "postgresql-${PSQL_VERSION}.service"
else
"/etc/init.d/postgresql-${PSQL_VERSION}" start
chkconfig --levels 35 "postgresql-${PSQL_VERSION}" on
fi
fi
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
sed -e 's/peer/trust/g' -e 's/ident/trust/g' < "/var/lib/pgsql/data/pg_hba.conf" > "/var/lib/pgsql/data/pg_hba.conf.1"
cd "/var/lib/pgsql/data" || exit
else
sed -e 's/peer/trust/g' -e 's/ident/trust/g' < "/var/lib/pgsql/${PSQL_VERSION}/data/pg_hba.conf" > "/var/lib/pgsql/${PSQL_VERSION}/data/pg_hba.conf.1"
cd "/var/lib/pgsql/${PSQL_VERSION}/data" || exit
fi
mv pg_hba.conf pg_hba.conf_old
mv pg_hba.conf.1 pg_hba.conf
if ([ "$OS_REQUIREMENT" = "CentOS" ] && [ "$OS_VERSION" -ge "8" ])
then
systemctl restart postgresql
else
if [ -f "/bin/systemctl" ]; then
systemctl restart "postgresql-${PSQL_VERSION}.service"
else
"/etc/init.d/postgresql-${PSQL_VERSION}" restart
fi
fi
fi
}
install_geoip()
{
if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "LinuxMint" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
then
if ! hash GeoIP-devel 2>&-;
then
apt install -y php7.4-geoip php7.4-dev libgeoip-dev
error_code=$?
if [ ${error_code} != 0 ]
then
echo "php7.4-geoip php7.4-dev libgeoip-dev installation failed with error code ${error_code} (php7.4-geoip php7.4-dev libgeoip-dev installation failed with error code 50)"
fi
fi
if ! hash pecl/geoip 2>&-;
then
pecl install geoip
error_code=$?
if [ ${error_code} != 0 ]
then
echo "pecl geoip installation failed with error code ${error_code} (pecl geoip installation failed with error code 47)"
fi
fi
echo "extension=geoip.so" >> /etc/php.ini
mkdir -v /usr/share/GeoIP
error_code=$?
if [ ${error_code} != 0 ]
then
echo "GeoIP folder creation failed with error code ${error_code} (GeoIP folder creation failed with error code 52)"
fi
get_geoip_data
else
if ! hash pecl/geoip 2>&-;
then
pecl install geoip
error_code=$?
if [ ${error_code} != 0 ]
then
echo "pecl geoip installation failed with error code ${error_code} (pecl geoip installation failed with error code 47)"
return 47
fi
fi
fi
}
configure_restyaboard()
{
if ([ "$OS_REQUIREMENT" = "Ubuntu" ] || [ "$OS_REQUIREMENT" = "Debian" ] || [ "$OS_REQUIREMENT" = "LinuxMint" ] || [ "$OS_REQUIREMENT" = "Raspbian" ])
then
set +x
if [ ${APACHE_ENABLED} -eq 1 ]
then
set +x
echo "To configure apache, enter your domain name (e.g., www.example.com, 192.xxx.xxx.xxx, etc.,):"
read -r webdir
while [[ -z "$webdir" ]]
do
read -r -p "To configure apache, enter your domain name (e.g., www.example.com, 192.xxx.xxx.xxx, etc.,):" webdir
done
set -x
echo "$webdir"
curl -v -L -G -o ${DOWNLOAD_DIR}/.htaccess https://raw.githubusercontent.com/RestyaPlatform/board/master/.htaccess
set +x
echo "Enter your document root (where your Restyaboard to be installed. e.g., /var/www/html/restyaboard):"
read -r dir
while [[ -z "$dir" ]]
do
read -r -p "Enter your document root (where your Restyaboard to be installed. e.g., /var/www/html/restyaboard):" dir
done
set -x
echo "$dir"
mkdir -p "$dir"
echo "Changing root directory in apache configuration..."
cp ${DOWNLOAD_DIR}/.htaccess $dir
set -x
echo "<VirtualHost *:80>
ServerName $webdir
ServerAlias $webdir
DocumentRoot $dir
</VirtualHost>
<Directory $dir>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>" >> /etc/apache2/sites-available/restyaboard.conf
set -x
echo "127.0.0.1 $webdir" >> /etc/hosts
rm -rf ${DOWNLOAD_DIR}/.htaccess
else