-
Notifications
You must be signed in to change notification settings - Fork 5
/
nextcloud-ins.sh
2640 lines (2497 loc) · 108 KB
/
nextcloud-ins.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
# Nextcloud Install Script
# Made for freshly installed, server Linux distributions using AMD64(x86_64) architecture:
# Debian (11,12), Enterprise Linux (9), Ubuntu Server (22), Fedora Server (39).
#
# It will update OS, preconfigure everything, install neeeded packages and Nextcloud.
# There is also support for upgrading Nextcloud and OS packages - just download and run latest version of this script again.
# It will create backup of current Nextcloud (but without users files) with it's database,
# and then it will upgrade OS, software packages, and Nextcloud to the newest major version.
#
# This Nextcloud installer allows Nextcloud to work locally and thru Internet:
# - by local IP address with and without SSL (it use self signed SSL certificate for https protocol),
# - or using domain name (local and over Internet), if domain is already configured correctly (it will use free Let's Encrypt service for certificate signing).
# Software packages that are installed are Apache (web server), MariaDB (database server), PHP (programming language with interpreter),
# NTP (time synchronization service), and Redis (cache server) installed and used.
# Some other software is also installed for better preview/thumbnails generation by Nextcloud like LibreOffice, Krita, ImageMagick etc.
# Also new service for Nextcloud "cron" is generated that starts every 5 minutes so Nextcloud can do some work while users are not connected.
#
# To use it just use this command:
# sudo sh -c "wget -q https://github.com/nicrame/Linux-Scripts/raw/master/nextcloud-ins.sh && chmod +x nextcloud-ins.sh && ./nextcloud-ins.sh"
#
# You may also add specific variables (lang, mail, dns) that will be used, by adding them to command above, e.g:
# sudo sh -c "wget -q https://github.com/nicrame/Linux-Scripts/raw/master/nextcloud-ins.sh && chmod +x nextcloud-ins.sh && ./nextcloud-ins.sh -lang=pl [email protected] -dm=domain.com -nv=24 -fdir=/mnt/sdc5/nextcloud-data"
# -lang (for language) variable will install additional packages specific for choosed language and setup Nextcloud default language.
# Currently supported languages are: none (default value is none/empty that will use web browser language), Arabic (ar), Chinese (zh), French (fr), Hindi (hi), Polish (pl), Spanish (es) and Ukrainian (uk),
# -mail variable is for information about Your email address, that will be presented to let's encrypt, so you'll be informed if domain name SSL certificate couldn't be refreshed (default value is empty),
# -dm variable is used when you got (already prepared and configured) domain name, it will be configured for Nextcloud server and Let's encrypt SSL (default value is empty),
# -nv variable allows You to choose older version to install, supported version are: 24-28, empty (it will install newest, currently v28),
# -fdir variable gives possibility to specify where user files and nextcloud.log files are stored, by default this settings will leave default location that is /var/www/nextcloud/data.
# selecting different location will not change Nextcloud configuration, but will bind (using mount) default Nextcloud location, to the specified one,
# so using security mechanism like chroot/jail/SELinux etc. will work correctly without additional configuration for them, web server etc.
# For example if option -fdir=/mnt/sdc5/nextcloud-data will be used, then entering directory /var/www/nextcloud/data will actually show content of /mnt/sdc5/nextcloud-data.
# If you want to use spaces between words in directory name, then put path inside double quotes, eg. -fdir="/mnt/sdx/users data folder"
# To remember data directory settings, and mount them each OS start /etc/fstab file is modified.
# -restore argument is used for recovering older Nextcloud files/database. Since v 1.11 this script generate backup of Nextcloud files (excluding users data) and database,
# when it's started for upgrade process (which is default scenario when script is started another time after first use).
# You may use -restore=list to check the list of previously created backups, or -restore=filename.tar.bz2 to select one of those files, and use them to restore Nextcloud.
# IMPORTSNT: When -restore argument is used with any kind of parameters, then any other is ignored. It means You can't use -restore variable with others.
# - backup argument starts backup process without doing any other tasks. It will just create backup of current Nextcloud install with database, excluding users files.
# Similar to -restore, -backup argument must be used by itself (any other one used with it will be ignored).
#
# After install You may use Your web browser to access Nextcloud using local IP address,
# or domain name, if You have configured it before (DNS settings and router configuration should be done earlier by You).
# Both HTTP and HTTPS protocols are enabled by default. Localhost, self signed certificate is generated by default.
# For additional domain name certificate is made with Let's encrypt service (if You use -dns command variable).
#
# It was tested with many Nextcloud versions since v24.
#
# Updates of Nextcloud after using this script:
# By default this script disable "updatenotification" app that allow You to update Nextcloud using its own administration panel.
# The main reason is that such updates sometimes leave files that shouldn't stay, which brakes their update system at some points (i had many such problems in the past).
# So, to update Your Nextcloud there are two options:
# 1. You may start the script again, so it will upgrade OS with software packages and Nextcloud to the newest version (it will update between major releases too),
# so for example if You have version 28.0.3, it will update it to 29.0.5(that was newest version when this text was edited).
# But if You selected version to install with "-nv" argument (eg. -nv=28) when script was used for the first time, then starting script again will not update anything,
# and leave You with selected version, without updating minor release.
# So if You got 28.0.3 it will not update to 28.0.9 (because when this script is released, i do not know how many minor releases will be in the future).
# 2. You may also enable updatenotification app using Nextcloud GUI - go to Apps -> Disabled apps -> click on Enable button near "Update notification" app.
# Then go to "Administration settings" -> Overview, where will be information about new version available for updating.
#
# In case of problems, LOG output is generated at /var/log/nextcloud-installer.log.
# Attach it if You want to report errors with installation process.
#
# If You want to report errors that You think may be made by the script, please add logs of Apache web server, PHP and Nextcloud.
# This script was never tested, and not reccommended to be used on containerization environment (like Docker, LXC etc.),
# but it was working well on virtual machines under KVM and Virtualbox.
#
# More info:
# [PL/ENG] https://www.marcinwilk.eu/pl/projects/linux-scripts/nextcloud-debian-install/
#
# Feel free to contact me: [email protected]
# www.marcinwilk.eu
# Marcin Wilk
#
# License:
# 1. You use it at your own risk. Author is not responsible for any damage made with that script.
# 2. Any changes of scripts must be shared with author with authorization to implement them and share.
#
# V 1.11.3 - 12.09.2024
# - Nextcloud Hub 9 (v30) is now default/latest
# - updated default versions to newest releases when using -nv parameter
# - add few commands to be sure that PHP 8.3 is used as default version
# - small tweaks and fixes
# V 1.11.2 - 16.05.2024
# - new arguments: -backup (create backup) and -restore (that can be used with "list" argument to show previously created backups, or with filename to be used to restore from it)
# - modify backup file names to show more data (date, time and Nextcloud version that is backed up)
# V 1.11 - 16.05.2024
# - update documentation inside script
# - first attempt to backup/restore feature
# V 1.10 - 19.04.2024
# - Nextcloud Hub 8 (v29) is now default/latest
# - PHP 8.3 is used as default PHP version
# - Fixed error that didn't allow installing older versions of NC (and PHP 7.4)
# V 1.9.2 - 13.03.2024
# - checking if "fdir" parameter is configured for already existing directory and inform if not
# - fix spaces in directory names saved in fstab, configured with -fdir argument (fstab do not support spaces in directory names)
# V 1.9.1 - 12.03.2024
# - some description update, and few code changes that do not affect the way script is working
# - add PHP 8.3 install code (currently disabled) for future NC versions
# V 1.9 - 04.03.2024
# - new argument that allow to configure location of "data" directory, where user files are stored (it use mount/fstab for security mechanisms compatibility)
# V 1.8.1 - 07.02.2024
# - first release with Fedora Server 39, and Ubuntu Server LTS (22) distributions support
# V 1.8 - 04.02.2024
# - first release with Rocky Linux (9), and other Enterprise Linux distributions support
# - a little more code optimizations
# V 1.7.1 - 01.02.2024
# - code cleanup
# - add maintenance window start time configuration (for 28.0.2 released today)
# V 1.7 - 30.01.2024
# - tweaks for thumbnails/preview generation
# - disabe sleep/hibernate modes in OS
# - add HTTP2 protocol support
# - small security fix
# - description improvements
# - packages installer will now wait for background jobs (started by OS) to finish
# V 1.6.4 - 04.01.2024
# - add bz2 module for PHP (for Nextcloud Hub 7)
# - Happy New Year!
# V 1.6.3 - 04.11.2023
# - more tests and fixes
# V 1.6.2 - 04.08.2023
# - few more languages are now supported with -lang= parameter (Arabic (ar), Chinese (zh), French (fr), Hindi (hi), Polish (pl), Spanish (es) and Ukrainian (uk))
# V 1.6.1 - 03.08.2023
# - small tweaks
# V 1.6 - 03.08.2023
# - new variable that allows installing older version of Nextcloud (users reported problems with NC27)
# - the script rename itself after finished work (so installer command always refer to newest version)
# - script is prepared now for few future updates (up to Nextcloud v28)
# V 1.5.5 - 12.07.2023
# - better description of variables use on error
# V 1.5.4 - 07.07.2023
# - fixed some logical problem
# - add support for Debian 12
# - add support for Nextcloud Hub 5 (v27)
# V 1.5.3 - 15.04.2023
# - using older PHP (8.1) version for upgrade process before removing it (Nextcloud do not finish upgrade process on never PHP version)
# - check for currently installed Nextcloud version and update it so many times it needs (till version 26) - when upgrading from script version 1.4 or older
# V 1.5.2 - 05.04.2023
# - twofactor_webauthn app installing and enabling for more security (tested with Yubikey)
# V 1.5.1 - 05.04.2023
# - upgrading from 1.4 and lower added to the script
# V 1.5 - 25.03.2023
# - use Nextcloud Hub 4 (v26)
# - enable opcache again (it looks it's working fine now)
# - use PHP version 8.2
# - install ddclient (dynamic DNS client - https://ddclient.net/)
# - install miniupnpc ans start it for port 80 and 443 to open ports (it should be unncessary)
# - added more variables to use (language, e_mail)
# - installer is now creating file with it's version number for future upgrades
# - installer detects if older versions of script were used, and in the next release it will upgrade everything (nextcloud included)
# V 1.4.3 - 24.02.2023
# - allow self-signed certificate config option in nextcloud (it may be needed sometimes)
# V 1.4.2 - 10.02.2023
# - completely disable opcache because of many segfaults even when JIT is completely disabled
# V 1.4.1 - 08.02.2023
# - opcache jit cache in php has been disabled because of many segfaults reported
# V 1.4 - 31.01.2023
# - fixes thanks to "maybe" user from hejto.pl portal (ufw, redis, chmods etc.) Thank You!
# V 1.3 - 30.01.2023
# - fix PHP 8.1 installing
# - more data stored to log for better error handling
# V 1.2 - 23.01.2023
# - some performance fixes (better support for large files)
# V 1.1 - 04.08.2022
# - added support for adding domain name as command line variable (with let's ecnrypt support)
# - added crontab job for certbot (Let's encrypt) and some more description
# V 1.0 - 20.06.2022
# - initial version based on private install script (for EL)
#
# Future plans:
# - add option to delete very old backups
# - add High Performance Backend (HPB) for Nextcloud (Push Service)
# - make backup of Nextcloud script (excluding users files) and database for recovery before upgrade (done with v1.11)
# - add option to restore previosly created backup (done with v1.11).
export LC_ALL=C
ver=1.11
cpu=$( uname -m )
user=$( whoami )
debvf=/etc/debian_version
ubuvf=/etc/dpkg/origins/ubuntu
if [ -e $debvf ]
then
if [ -e $ubuvf ]
then
ubuv=$( cat /etc/lsb-release | grep "Ubuntu 22" | awk -F '"' '{print $2}' )
unset debv
debv=$ubuv
ubu19=$( cat /etc/lsb-release | grep "Ubuntu 19" )
ubu20=$( cat /etc/lsb-release | grep "Ubuntu 20" )
ubu21=$( cat /etc/lsb-release | grep "Ubuntu 21" )
ubu22=$( cat /etc/lsb-release | grep "Ubuntu 22" )
ubu23=$( cat /etc/lsb-release | grep "Ubuntu 23" )
else
debv=$( cat $debvf )
fi
fi
elvf=/etc/redhat-release
fedvf=/etc/fedora-release
if [ -e $elvf ]
then
elv=$( cat $elvf )
el6=$( cat /etc/redhat-release | grep "release 6" )
el7=$( cat /etc/redhat-release | grep "release 7" )
el8=$( cat /etc/redhat-release | grep "release 8" )
el9=$( cat /etc/redhat-release | grep "release 9" )
el10=$( cat /etc/redhat-release | grep "release 10" )
if [ -e $fedvf ]
then
fed36=$( cat /etc/redhat-release | grep "release 36" )
fed37=$( cat /etc/redhat-release | grep "release 37" )
fed38=$( cat /etc/redhat-release | grep "release 38" )
fed39=$( cat /etc/redhat-release | grep "release 39" )
fi
fi
addr=$( hostname -I )
addr1=$( hostname -I | awk '{print $1}' )
cdir=$( pwd )
if [ -e $debvf ]
then
websrv_usr=www-data
fi
if [ -e $elvf ]
then
websrv_usr=apache
fi
lang=""
mail=""
dm=""
nv=""
fdir=""
restore=""
insl=/var/log/nextcloud-installer.log
rstl=/var/log/nextcloud-ins-rst.log
ver_file=/var/local/nextcloud-installer.ver
nbckd=/var/local/nextcloud-installer-backups
nbckf=nextcloud.tar
scrpt=nextcloud-ins
backup=false
while [ "$#" -gt 0 ]; do
case "$1" in
-lang=*) lang="${1#*=}" ;;
-mail=*) mail="${1#*=}" ;;
-dm=*) dm="${1#*=}" ;;
-nv=*) nv="${1#*=}" ;;
-fdir=*) fdir="${1#*=}" ;;
-restore=*) restore="${1#*=}" ;;
-backup) backup=true ;;
*)
echo "Unknown parameter: $1" >&2;
echo "Remember to add one, or more variables after equals sign:";
echo -e "Eg. \e[1;32m-\e[39;0mmail\e[1;32m=\e[39;[email protected] \e[1;32m-\e[39;0mlang\e[1;32m=\e[39;0mpl \e[1;32m-\e[39;0mdm\e[1;32m=\e[39;0mdomain.com \e[1;32m-\e[39;0mnv\e[1;32m=\e[39;0m24 \e[1;32m-\e[39;0mfdir\e[1;32m=\e[39;0m/mnt/sdc5/nextcloud-data";
echo "or in case of backup and restore argument (used individually):";
echo -e "\e[1;32m-\e[39;0mbackup";
echo -e "\e[1;32m-\e[39;0mrestore\e[1;32m=\e[39;0mlist";
echo -e "\e[1;32m-\e[39;0mrestore\e[1;32m=\e[39;0mfilename-from-list.tar.bz2";
exit 1
;;
esac
shift
done
# More complex tasks are functions now:
function restart_websrv {
if [ -e $debvf ]
then
systemctl stop apache2 >> $insl 2>&1
fi
if [ -e $elvf ]
then
systemctl stop httpd >> $insl 2>&1
if [ -d /etc/opt/remi/php74 ]
then
systemctl stop php74-php-fpm >> $insl 2>&1
rm -rf /var/opt/remi/php74/lib/php/opcache/* >> $insl 2>&1
systemctl start php74-php-fpm >> $insl 2>&1
fi
fi
if [ -d /etc/opt/remi/php81 ]
then
systemctl stop php81-php-fpm >> $insl 2>&1
rm -rf /var/opt/remi/php81/lib/php/opcache/* >> $insl 2>&1
systemctl start php81-php-fpm >> $insl 2>&1
fi
if [ -d /etc/opt/remi/php82 ]
then
systemctl stop php82-php-fpm >> $insl 2>&1
rm -rf /var/opt/remi/php82/lib/php/opcache/* >> $insl 2>&1
systemctl start php82-php-fpm >> $insl 2>&1
fi
if [ -d /etc/opt/remi/php83 ]
then
systemctl stop php83-php-fpm >> $insl 2>&1
rm -rf /var/opt/remi/php83/lib/php/opcache/* >> $insl 2>&1
systemctl start php83-php-fpm >> $insl 2>&1
fi
if [ -d /etc/opt/remi/php84 ]
then
systemctl stop php84-php-fpm >> $insl 2>&1
rm -rf /var/opt/remi/php84/lib/php/opcache/* >> $insl 2>&1
systemctl start php84-php-fpm >> $insl 2>&1
fi
if [ -d /etc/opt/remi/php85 ]
then
systemctl stop php85-php-fpm >> $insl 2>&1
rm -rf /var/opt/remi/php85/lib/php/opcache/* >> $insl 2>&1
systemctl start php85-php-fpm >> $insl 2>&1
fi
if [ -d /etc/opt/remi/php86 ]
then
systemctl stop php86-php-fpm >> $insl 2>&1
rm -rf /var/opt/remi/php86/lib/php/opcache/* >> $insl 2>&1
systemctl start php86-php-fpm >> $insl 2>&1
fi
if [ -e $elvf ]
then
systemctl start httpd >> $insl 2>&1
fi
if [ -e $debvf ]
then
systemctl start apache2 >> $insl 2>&1
fi
}
function maintenance_window_setup {
if grep -q "maintenance_window_start" "/var/www/nextcloud/config/config.php"
then
echo "!!!!!!! Maintenance window time already configured." >> $insl 2>&1
else
echo "!!!!!!! Adding maintenance window time inside NC config." >> $insl 2>&1
sed -i "/installed' => true,/a\ \ 'maintenance_window_start' => '1'," /var/www/nextcloud/config/config.php
fi
}
# Check if Nextcloud was updated with nv variable, and if yes, skip doing anything to not brake it.
# This is version made for newer version of script, so it report that it was running under $ver_file.
function nv_check_upd {
echo "Older version of Nextcloud configured, skipping updates and exit."
echo "Older version of Nextcloud configured, skipping updates and exit." >> $insl 2>&1
echo -e "pver=$ver lang=$lang mail=$mail dm=$dm nv=$nv fdir=$fdir\n$(</var/local/nextcloud-installer.ver)" > $ver_file
echo -e "Version $ver was succesfully installed at $(date +%d-%m-%Y_%H:%M:%S)\n$(</var/local/nextcloud-installer.ver)" > $ver_file
mv $cdir/$scrpt.sh $scrpt-$(date +"%FT%H%M").sh
unset LC_ALL
exit 0
}
function nv_check_upd_cur {
echo "Older version of Nextcloud configured, skipping updates and exit."
echo "Older version of Nextcloud configured, skipping updates and exit." >> $insl 2>&1
mv $cdir/$scrpt.sh $scrpt-$(date +"%FT%H%M").sh
unset LC_ALL
exit 0
}
function nv_upd_simpl {
rm -rf /var/www/nextcloud/composer.lock >> $insl 2>&1
rm -rf /var/www/nextcloud/package-lock.json >> $insl 2>&1
rm -rf /var/www/nextcloud/package.json >> $insl 2>&1
rm -rf /var/www/nextcloud/composer.json >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ db:add-missing-indices >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/updater/updater.phar --no-interaction >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ upgrade >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ maintenance:mode --off >> $insl 2>&1
}
function update_os {
if [ -e $debvf ]
then
apt-get update -o DPkg::Lock::Timeout=-1 >> $insl 2>&1 && apt-get upgrade -y -o DPkg::Lock::Timeout=-1 >> $insl 2>&1 && apt-get autoremove -y >> $insl 2>&1
fi
if [ -e $elvf ]
then
dnf update -y -q >> $insl 2>&1
fi
}
function install_soft {
echo "!!!!!!! Installing all needed standard packages" >> $insl 2>&1
if [ -e $debvf ]
then
DEBIAN_FRONTEND=noninteractive
apt-get install -y -o DPkg::Lock::Timeout=-1 git lbzip2 unzip zip lsb-release locales-all rsync wget curl sed screen gawk mc sudo net-tools ethtool vim nano ufw apt-transport-https ca-certificates software-properties-common miniupnpc jq libfontconfig1 libfuse2 socat tree ffmpeg imagemagick webp libreoffice ghostscript bindfs >> $insl 2>&1
yes | sudo DEBIAN_FRONTEND=noninteractive apt-get -yqq -o DPkg::Lock::Timeout=-1 install ddclient >> $insl 2>&1
fi
if [ -e $elvf ]
then
# Disabling SELinux for testing purposes here. By default just let it run and configure things instead.
# setenforce 0 >> $insl 2>&1
# grubby --update-kernel ALL --args selinux=0 >> $insl 2>&1
# sed --in-place=.bak 's/^SELINUX\=enforcing/SELINUX\=permissive/g' /etc/selinux/config
if [ -e $fedvf ]
then
dnf install -y -q https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm >> $insl 2>&1
dnf config-manager -y --enable fedora-cisco-openh264 >> $insl 2>&1
else
dnf -q config-manager --set-enabled crb && dnf install -y -q epel-release >> $insl 2>&1
dnf install -q --nogpgcheck https://mirrors.rpmfusion.org/free/el/rpmfusion-free-release-$(rpm -E %rhel).noarch.rpm -y >> $insl 2>&1
dnf install -q --nogpgcheck https://mirrors.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-$(rpm -E %rhel).noarch.rpm -y >> $insl 2>&1
fi
dnf install -y -q git lbzip2 unzip zip lsb-release rsync wget curl sed screen gawk mc sudo net-tools ethtool vim nano ca-certificates miniupnpc jq fontconfig-devel socat tree ffmpeg ImageMagick libwebp libreoffice ghostscript ddclient >> $insl 2>&1
fi
}
function install_php81 {
if [ -e $debvf ]
then
curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg >> $insl 2>&1
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' >> $insl 2>&1
apt-get update >> $insl 2>&1
apt-get install -y -o DPkg::Lock::Timeout=-1 php8.1 libapache2-mod-php8.1 libmagickcore-6.q16-6-extra php8.1-mysql php8.1-common php8.1-redis php8.1-dom php8.1-curl php8.1-exif php8.1-fileinfo php8.1-bcmath php8.1-gmp php8.1-imagick php8.1-mbstring php8.1-xml php8.1-zip php8.1-iconv php8.1-intl php8.1-simplexml php8.1-xmlreader php8.1-ftp php8.1-ssh2 php8.1-sockets php8.1-gd php8.1-imap php8.1-soap php8.1-xmlrpc php8.1-apcu php8.1-dev php8.1-cli >> $insl 2>&1
fi
if [ -e $elvf ]
then
if [ -e $fedvf ]
then
dnf install -y -q https://rpms.remirepo.net/fedora/remi-release-39.rpm >> $insl 2>&1
dnf config-manager --set-enabled remi
else
dnf install -y -q https://rpms.remirepo.net/enterprise/remi-release-9.rpm >> $insl 2>&1
fi
dnf install -y -q php81 php81-php-apcu php81-php-opcache php81-php-mysql php81-php-bcmath php81-php-common php81-php-geos php81-php-gmp php81-php-pecl-imagick-im7 php81-php-pecl-lzf php81-php-pecl-mcrypt php81-php-pecl-recode php81-php-process php81-php-zstd php81-php-redis php81-php-dom php81-php-curl php81-php-exif php81-php-fileinfo php81-php-mbstring php81-php-xml php81-php-zip php81-php-iconv php81-php-intl php81-php-simplexml php81-php-xmlreader php81-php-ftp php81-php-ssh2 php81-php-sockets php81-php-gd php81-php-imap php81-php-soap php81-php-xmlrpc php81-php-apcu php81-php-cli php81-php-ast php81-php-brotli php81-php-enchant php81-php-ffi php81-php-lz4 php81-php-phalcon5 php81-php-phpiredis php81-php-smbclient php81-php-tidy php81-php-xz >> $insl 2>&1
dnf install -y -q php81-syspaths php81-mod_php >> $insl 2>&1
ln -s /var/opt/remi/php81/log/php-fpm /var/log/php81-fpm
fi
}
function install_php82 {
if [ -e $debvf ]
then
if [ -e $ubuvf ]
then
add-apt-repository -y ppa:ondrej/php >> $insl 2>&1
DEBIAN_FRONTEND=noninteractive
else
curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg >> $insl 2>&1
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' >> $insl 2>&1
fi
apt-get update >> $insl 2>&1
apt-get install -y -o DPkg::Lock::Timeout=-1 php8.2 libapache2-mod-php8.2 libmagickcore-6.q16-6-extra php8.2-mysql php8.2-common php8.2-bz2 php8.2-redis php8.2-dom php8.2-curl php8.2-exif php8.2-fileinfo php8.2-bcmath php8.2-gmp php8.2-imagick php8.2-mbstring php8.2-xml php8.2-zip php8.2-iconv php8.2-intl php8.2-simplexml php8.2-xmlreader php8.2-ftp php8.2-ssh2 php8.2-sockets php8.2-gd php8.2-imap php8.2-soap php8.2-xmlrpc php8.2-apcu php8.2-dev php8.2-cli >> $insl 2>&1
fi
if [ -e $elvf ]
then
if [ -e $fedvf ]
then
dnf install -y -q https://rpms.remirepo.net/fedora/remi-release-39.rpm >> $insl 2>&1
dnf config-manager --set-enabled remi
else
dnf install -y -q https://rpms.remirepo.net/enterprise/remi-release-9.rpm >> $insl 2>&1
fi
dnf install -y -q php82 php82-php-apcu php82-php-opcache php82-php-mysql php82-php-bcmath php82-php-common php82-php-geos php82-php-gmp php82-php-pecl-imagick-im7 php82-php-pecl-lzf php82-php-pecl-mcrypt php82-php-pecl-recode php82-php-process php82-php-zstd php82-php-redis php82-php-dom php82-php-curl php82-php-exif php82-php-fileinfo php82-php-mbstring php82-php-xml php82-php-zip php82-php-iconv php82-php-intl php82-php-simplexml php82-php-xmlreader php82-php-ftp php82-php-ssh2 php82-php-sockets php82-php-gd php82-php-imap php82-php-soap php82-php-xmlrpc php82-php-apcu php82-php-cli php82-php-ast php82-php-brotli php82-php-enchant php82-php-ffi php82-php-lz4 php82-php-phalcon5 php82-php-phpiredis php82-php-smbclient php82-php-tidy php82-php-xz >> $insl 2>&1
dnf install -y -q php82-syspaths php82-mod_php >> $insl 2>&1
ln -s /var/opt/remi/php82/log/php-fpm /var/log/php82-fpm
fi
}
function install_php83 {
if [ -e $debvf ]
then
if [ -e $ubuvf ]
then
add-apt-repository -y ppa:ondrej/php >> $insl 2>&1
DEBIAN_FRONTEND=noninteractive
else
curl -sSLo /usr/share/keyrings/deb.sury.org-php.gpg https://packages.sury.org/php/apt.gpg >> $insl 2>&1
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' >> $insl 2>&1
fi
apt-get update >> $insl 2>&1
apt-get install -y -o DPkg::Lock::Timeout=-1 php8.3 libapache2-mod-php8.3 libmagickcore-6.q16-6-extra php8.3-mysql php8.3-common php8.3-bz2 php8.3-redis php8.3-dom php8.3-curl php8.3-exif php8.3-fileinfo php8.3-bcmath php8.3-gmp php8.3-imagick php8.3-mbstring php8.3-xml php8.3-zip php8.3-iconv php8.3-intl php8.3-simplexml php8.3-xmlreader php8.3-ftp php8.3-ssh2 php8.3-sockets php8.3-gd php8.3-imap php8.3-soap php8.3-xmlrpc php8.3-apcu php8.3-dev php8.3-cli >> $insl 2>&1
fi
if [ -e $elvf ]
then
if [ -e $fedvf ]
then
dnf install -y -q https://rpms.remirepo.net/fedora/remi-release-39.rpm >> $insl 2>&1
dnf config-manager --set-enabled remi
else
dnf install -y -q https://rpms.remirepo.net/enterprise/remi-release-9.rpm >> $insl 2>&1
fi
dnf install -y -q php83 php83-php-apcu php83-php-opcache php83-php-mysql php83-php-bcmath php83-php-common php83-php-geos php83-php-gmp php83-php-pecl-imagick-im7 php83-php-pecl-lzf php83-php-pecl-mcrypt php83-php-pecl-recode php83-php-process php83-php-zstd php83-php-redis php83-php-dom php83-php-curl php83-php-exif php83-php-fileinfo php83-php-mbstring php83-php-xml php83-php-zip php83-php-iconv php83-php-intl php83-php-simplexml php83-php-xmlreader php83-php-ftp php83-php-ssh2 php83-php-sockets php83-php-gd php83-php-imap php83-php-soap php83-php-xmlrpc php83-php-apcu php83-php-cli php83-php-ast php83-php-brotli php83-php-enchant php83-php-ffi php83-php-lz4 php83-php-phalcon5 php83-php-phpiredis php83-php-smbclient php83-php-tidy php83-php-xz >> $insl 2>&1
dnf install -y -q php83-syspaths php83-mod_php >> $insl 2>&1
ln -s /var/opt/remi/php83/log/php-fpm /var/log/php83-fpm
fi
}
# This is function for installing currently used latest version of PHP.
function install_php {
install_php83
}
# Check and add http2 support to Apache.
function add_http2 {
if [ -e $debvf ]
then
if grep -q "Protocols" "/etc/apache2/sites-available/nextcloud.conf"
then
echo "!!!!!!! HTTP2 already inside vhost config." >> $insl 2>&1
else
echo "!!!!!!! HTTP2 adding to vhost" >> $insl 2>&1
sed -i "/LimitRequestBody 0/a\ \ H2WindowSize 5242880" /etc/apache2/sites-available/nextcloud.conf
sed -i "/LimitRequestBody 0/a\ \ ProtocolsHonorOrder Off" /etc/apache2/sites-available/nextcloud.conf
sed -i "/LimitRequestBody 0/a\ \ Protocols h2 h2c http/1.1" /etc/apache2/sites-available/nextcloud.conf
fi
fi
}
function preview_tweaks {
echo "!!!!!!! Preview thumbnails tweaking in NC" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 0 --value="OC\\Preview\\PNG" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 1 --value="OC\\Preview\\JPEG" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 2 --value="OC\\Preview\\GIF" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 3 --value="OC\\Preview\\BMP" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 4 --value="OC\\Preview\\XBitmap" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 5 --value="OC\\Preview\\MP3" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 6 --value="OC\\Preview\\TXT" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 7 --value="OC\\Preview\\MarkDown" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 8 --value="OC\\Preview\\OpenDocument" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 9 --value="OC\\Preview\\Krita" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 10 --value="OC\\Preview\\Illustrator" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 11 --value="OC\\Preview\\HEIC" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 12 --value="OC\\Preview\\HEIF" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 13 --value="OC\\Preview\\Movie" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 14 --value="OC\\Preview\\MSOffice2003" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 15 --value="OC\\Preview\\MSOffice2007" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 16 --value="OC\\Preview\\MSOfficeDoc" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 17 --value="OC\\Preview\\PDF" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 18 --value="OC\\Preview\\Photoshop" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 19 --value="OC\\Preview\\Postscript" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 20 --value="OC\\Preview\\StarOffice" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 21 --value="OC\\Preview\\SVG" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 22 --value="OC\\Preview\\TIFF" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 23 --value="OC\\Preview\\WEBP" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 24 --value="OC\\Preview\\EMF" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 25 --value="OC\\Preview\\Font" >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:set enabledPreviewProviders 26 --value="OC\\Preview\\Image" >> $insl 2>&1
if [ -e $debvf ]
then
sed -i 's/\(^ *<policy.*rights="\)\([^"]*\)\(".*PS.*\/>\)/\1read|write\3/1' /etc/ImageMagick-6/policy.xml
sed -i 's/\(^ *<policy.*rights="\)\([^"]*\)\(".*PS2.*\/>\)/\1read|write\3/1' /etc/ImageMagick-6/policy.xml
sed -i 's/\(^ *<policy.*rights="\)\([^"]*\)\(".*PS3.*\/>\)/\1read|write\3/1' /etc/ImageMagick-6/policy.xml
sed -i 's/\(^ *<policy.*rights="\)\([^"]*\)\(".*EPS.*\/>\)/\1read|write\3/1' /etc/ImageMagick-6/policy.xml
sed -i 's/\(^ *<policy.*rights="\)\([^"]*\)\(".*PDF.*\/>\)/\1read|write\3/1' /etc/ImageMagick-6/policy.xml
fi
}
function php74_tweaks {
echo "!!!!!!! PHP 7.4 config files modify." >> $insl 2>&1
echo "PHP config files tweaking."
if [ -e $debvf ]
then
php74_in1=/etc/php/7.4/apache2
php74_in2=/etc/php/7.4/apache2/conf.d
fi
if [ -e $elvf ]
then
php74_in1=/etc/opt/remi/php74
php74_in2=/etc/opt/remi/php74/php.d
ln -s /var/opt/remi/php74/log/php-fpm /var/log/php-fpm
fi
if [ -e $debvf ]
then
echo 'apc.enable_cli=1' >> /etc/php/7.4/cli/conf.d/20-apcu.ini
fi
if [ -e $debvf ]
then
echo 'apc.enable_cli=1' >> $php74_in2/40-apcu.ini
fi
sed -i 's/\b128M\b/1024M/g' $php74_in1/php.ini
sed -i 's/\bmax_execution_time = 30\b/max_execution_time = 3600/g' $php74_in1/php.ini
sed -i 's/\boutput_buffering = 4096\b/output_buffering = Off/g' $php74_in1/php.ini
sed -i 's/\bmax_input_vars = 1000\b/max_input_vars = 3000/g' $php74_in1/php.ini
sed -i 's/\bmax_input_time = 60\b/max_input_time = 3600/g' $php74_in1/php.ini
sed -i 's/\bpost_max_size = 8M\b/post_max_size = 16G/g' $php74_in1/php.ini
sed -i 's/\bupload_max_filesize = 2M\b/upload_max_filesize = 16G/g' $php74_in1/php.ini
sed -i 's/\bmax_file_uploads = 20\b/max_file_uploads = 200/g' $php74_in1/php.ini
sed -i 's/\bdefault_socket_timeout = 20\b/default_socket_timeout = 3600/g' $php74_in1/php.ini
sed -i '/MySQLi]/amysqli.cache_size = 2000' $php74_in1/php.ini
if [ -e $debvf ]
then
sed -i 's/\b128M\b/1024M/g' /etc/php/7.4/cli/php.ini
sed -i 's/\bmax_execution_time = 30\b/max_execution_time = 3600/g' /etc/php/7.4/cli/php.ini
sed -i 's/\boutput_buffering = 4096\b/output_buffering = Off/g' /etc/php/7.4/cli/php.ini
sed -i 's/\bmax_input_vars = 1000\b/max_input_vars = 3000/g' /etc/php/7.4/cli/php.ini
sed -i 's/\bmax_input_time = 60\b/max_input_time = 3600/g' /etc/php/7.4/cli/php.ini
sed -i 's/\bpost_max_size = 8M\b/post_max_size = 16G/g' /etc/php/7.4/cli/php.ini
sed -i 's/\bupload_max_filesize = 2M\b/upload_max_filesize = 16G/g' /etc/php/7.4/cli/php.ini
sed -i 's/\bmax_file_uploads = 20\b/max_file_uploads = 200/g' /etc/php/7.4/cli/php.ini
sed -i 's/\bdefault_socket_timeout = 20\b/default_socket_timeout = 3600/g' /etc/php/7.4/cli/php.ini
sed -i '/MySQLi]/amysqli.cache_size = 2000' /etc/php/7.4/cli/php.ini
fi
echo 'opcache.enable_cli=1' >> $php74_in2/10-opcache.ini
echo 'opcache.interned_strings_buffer=64' >> $php74_in2/10-opcache.ini
echo 'opcache.max_accelerated_files=20000' >> $php74_in2/10-opcache.ini
echo 'opcache.memory_consumption=256' >> $php74_in2/10-opcache.ini
echo 'opcache.save_comments=1' >> $php74_in2/10-opcache.ini
echo 'opcache.enable=1' >> $php74_in2/10-opcache.ini
# echo 'opcache.revalidate_freq=1' >> $php74_in2/10-opcache.ini
# echo 'opcache.jit=disable' >> $php74_in2/10-opcache.ini
restart_websrv
}
function php81_tweaks {
echo "!!!!!!! PHP 8.1 config files modify." >> $insl 2>&1
echo "PHP config files tweaking."
if [ -e $debvf ]
then
php81_in1=/etc/php/8.1/apache2
php81_in2=/etc/php/8.1/apache2/conf.d
fi
if [ -e $elvf ]
then
php81_in1=/etc/opt/remi/php81
php81_in2=/etc/opt/remi/php81/php.d
fi
if [ -e $debvf ]
then
echo 'apc.enable_cli=1' >> /etc/php/8.1/cli/conf.d/20-apcu.ini
fi
if [ -e $debvf ]
then
echo 'apc.enable_cli=1' >> $php81_in2/40-apcu.ini
fi
sed -i 's/\b128M\b/1024M/g' $php81_in1/php.ini
sed -i 's/\bmax_execution_time = 30\b/max_execution_time = 3600/g' $php81_in1/php.ini
sed -i 's/\boutput_buffering = 4096\b/output_buffering = Off/g' $php81_in1/php.ini
sed -i 's/\bmax_input_vars = 1000\b/max_input_vars = 3000/g' $php81_in1/php.ini
sed -i 's/\bmax_input_time = 60\b/max_input_time = 3600/g' $php81_in1/php.ini
sed -i 's/\bpost_max_size = 8M\b/post_max_size = 16G/g' $php81_in1/php.ini
sed -i 's/\bupload_max_filesize = 2M\b/upload_max_filesize = 16G/g' $php81_in1/php.ini
sed -i 's/\bmax_file_uploads = 20\b/max_file_uploads = 200/g' $php81_in1/php.ini
sed -i 's/\bdefault_socket_timeout = 20\b/default_socket_timeout = 3600/g' $php81_in1/php.ini
sed -i '/MySQLi]/amysqli.cache_size = 2000' $php81_in1/php.ini
if [ -e $debvf ]
then
sed -i 's/\b128M\b/1024M/g' /etc/php/8.1/cli/php.ini
sed -i 's/\bmax_execution_time = 30\b/max_execution_time = 3600/g' /etc/php/8.1/cli/php.ini
sed -i 's/\boutput_buffering = 4096\b/output_buffering = Off/g' /etc/php/8.1/cli/php.ini
sed -i 's/\bmax_input_vars = 1000\b/max_input_vars = 3000/g' /etc/php/8.1/cli/php.ini
sed -i 's/\bmax_input_time = 60\b/max_input_time = 3600/g' /etc/php/8.1/cli/php.ini
sed -i 's/\bpost_max_size = 8M\b/post_max_size = 16G/g' /etc/php/8.1/cli/php.ini
sed -i 's/\bupload_max_filesize = 2M\b/upload_max_filesize = 16G/g' /etc/php/8.1/cli/php.ini
sed -i 's/\bmax_file_uploads = 20\b/max_file_uploads = 200/g' /etc/php/8.1/cli/php.ini
sed -i 's/\bdefault_socket_timeout = 20\b/default_socket_timeout = 3600/g' /etc/php/8.1/cli/php.ini
sed -i '/MySQLi]/amysqli.cache_size = 2000' /etc/php/8.1/cli/php.ini
fi
echo 'opcache.enable_cli=1' >> $php81_in2/10-opcache.ini
echo 'opcache.interned_strings_buffer=64' >> $php81_in2/10-opcache.ini
echo 'opcache.max_accelerated_files=20000' >> $php81_in2/10-opcache.ini
echo 'opcache.memory_consumption=256' >> $php81_in2/10-opcache.ini
echo 'opcache.save_comments=1' >> $php81_in2/10-opcache.ini
echo 'opcache.enable=1' >> $php81_in2/10-opcache.ini
# echo 'opcache.revalidate_freq=1' >> $php81_in2/10-opcache.ini
# echo 'opcache.jit=disable' >> $php81_in2/10-opcache.ini
restart_websrv
}
function php82_tweaks {
echo "!!!!!!! PHP 8.2 config files modify." >> $insl 2>&1
echo "PHP config files tweaking."
if [ -e $debvf ]
then
php82_in1=/etc/php/8.2/apache2
php82_in2=/etc/php/8.2/apache2/conf.d
fi
if [ -e $elvf ]
then
php82_in1=/etc/opt/remi/php82
php82_in2=/etc/opt/remi/php82/php.d
fi
if [ -e $debvf ]
then
echo 'apc.enable_cli=1' >> /etc/php/8.2/cli/conf.d/20-apcu.ini
fi
if [ -e $elvf ]
then
echo 'apc.enable_cli=1' >> $php82_in2/40-apcu.ini
fi
sed -i 's/\b128M\b/1024M/g' $php82_in1/php.ini
sed -i 's/\bmax_execution_time = 30\b/max_execution_time = 3600/g' $php82_in1/php.ini
sed -i 's/\boutput_buffering = 4096\b/output_buffering = Off/g' $php82_in1/php.ini
sed -i 's/\bmax_input_vars = 1000\b/max_input_vars = 3000/g' $php82_in1/php.ini
sed -i 's/\bmax_input_time = 60\b/max_input_time = 3600/g' $php82_in1/php.ini
sed -i 's/\bpost_max_size = 8M\b/post_max_size = 16G/g' $php82_in1/php.ini
sed -i 's/\bupload_max_filesize = 2M\b/upload_max_filesize = 16G/g' $php82_in1/php.ini
sed -i 's/\bmax_file_uploads = 20\b/max_file_uploads = 200/g' $php82_in1/php.ini
sed -i 's/\bdefault_socket_timeout = 20\b/default_socket_timeout = 3600/g' $php82_in1/php.ini
sed -i '/MySQLi]/amysqli.cache_size = 2000' $php82_in1/php.ini
if [ -e $debvf ]
then
sed -i 's/\b128M\b/1024M/g' /etc/php/8.2/cli/php.ini
sed -i 's/\bmax_execution_time = 30\b/max_execution_time = 3600/g' /etc/php/8.2/cli/php.ini
sed -i 's/\boutput_buffering = 4096\b/output_buffering = Off/g' /etc/php/8.2/cli/php.ini
sed -i 's/\bmax_input_vars = 1000\b/max_input_vars = 3000/g' /etc/php/8.2/cli/php.ini
sed -i 's/\bmax_input_time = 60\b/max_input_time = 3600/g' /etc/php/8.2/cli/php.ini
sed -i 's/\bpost_max_size = 8M\b/post_max_size = 16G/g' /etc/php/8.2/cli/php.ini
sed -i 's/\bupload_max_filesize = 2M\b/upload_max_filesize = 16G/g' /etc/php/8.2/cli/php.ini
sed -i 's/\bmax_file_uploads = 20\b/max_file_uploads = 200/g' /etc/php/8.2/cli/php.ini
sed -i 's/\bdefault_socket_timeout = 20\b/default_socket_timeout = 3600/g' /etc/php/8.2/cli/php.ini
sed -i '/MySQLi]/amysqli.cache_size = 2000' /etc/php/8.2/cli/php.ini
fi
echo 'opcache.enable_cli=1' >> $php82_in2/10-opcache.ini
echo 'opcache.interned_strings_buffer=64' >> $php82_in2/10-opcache.ini
echo 'opcache.max_accelerated_files=20000' >> $php82_in2/10-opcache.ini
echo 'opcache.memory_consumption=256' >> $php82_in2/10-opcache.ini
echo 'opcache.save_comments=1' >> $php82_in2/10-opcache.ini
echo 'opcache.enable=1' >> $php82_in2/10-opcache.ini
# echo 'opcache.revalidate_freq=1' >> $php82_in2/10-opcache.ini
# echo 'opcache.jit=disable' >> $php82_in2/10-opcache.ini
restart_websrv
}
function php83_tweaks {
echo "!!!!!!! PHP 8.3 config files modify." >> $insl 2>&1
echo "PHP config files tweaking."
if [ -e $debvf ]
then
php83_in1=/etc/php/8.3/apache2
php83_in2=/etc/php/8.3/apache2/conf.d
php83_inc=/etc/php/8.3/cli/php.ini
fi
if [ -e $elvf ]
then
php83_in1=/etc/opt/remi/php83
php83_in2=/etc/opt/remi/php83/php.d
fi
if [ -e $debvf ]
then
echo 'apc.enable_cli=1' >> /etc/php/8.3/cli/conf.d/20-apcu.ini
fi
if [ -e $elvf ]
then
echo 'apc.enable_cli=1' >> $php83_in2/40-apcu.ini
fi
sed -i 's/\b128M\b/1024M/g' $php83_in1/php.ini
sed -i 's/\bmax_execution_time = 30\b/max_execution_time = 3600/g' $php83_in1/php.ini
sed -i 's/\boutput_buffering = 4096\b/output_buffering = Off/g' $php83_in1/php.ini
sed -i 's/\bmax_input_vars = 1000\b/max_input_vars = 3000/g' $php83_in1/php.ini
sed -i 's/\bmax_input_time = 60\b/max_input_time = 3600/g' $php83_in1/php.ini
sed -i 's/\bpost_max_size = 8M\b/post_max_size = 16G/g' $php83_in1/php.ini
sed -i 's/\bupload_max_filesize = 2M\b/upload_max_filesize = 16G/g' $php83_in1/php.ini
sed -i 's/\bmax_file_uploads = 20\b/max_file_uploads = 200/g' $php83_in1/php.ini
sed -i 's/\bdefault_socket_timeout = 20\b/default_socket_timeout = 3600/g' $php83_in1/php.ini
sed -i '/MySQLi]/amysqli.cache_size = 2000' $php83_in1/php.ini
if [ -e $debvf ]
then
sed -i 's/\b128M\b/1024M/g' $php83_inc
sed -i 's/\bmax_execution_time = 30\b/max_execution_time = 3600/g' $php83_inc
sed -i 's/\boutput_buffering = 4096\b/output_buffering = Off/g' $php83_inc
sed -i 's/\bmax_input_vars = 1000\b/max_input_vars = 3000/g' $php83_inc
sed -i 's/\bmax_input_time = 60\b/max_input_time = 3600/g' $php83_inc
sed -i 's/\bpost_max_size = 8M\b/post_max_size = 16G/g' $php83_inc
sed -i 's/\bupload_max_filesize = 2M\b/upload_max_filesize = 16G/g' $php83_inc
sed -i 's/\bmax_file_uploads = 20\b/max_file_uploads = 200/g' $php83_inc
sed -i 's/\bdefault_socket_timeout = 20\b/default_socket_timeout = 3600/g' $php83_inc
sed -i '/MySQLi]/amysqli.cache_size = 2000' $php83_inc
fi
echo 'opcache.enable_cli=1' >> $php83_in2/10-opcache.ini
echo 'opcache.interned_strings_buffer=64' >> $php83_in2/10-opcache.ini
echo 'opcache.max_accelerated_files=20000' >> $php83_in2/10-opcache.ini
echo 'opcache.memory_consumption=256' >> $php83_in2/10-opcache.ini
echo 'opcache.save_comments=1' >> $php83_in2/10-opcache.ini
echo 'opcache.enable=1' >> $php83_in2/10-opcache.ini
# echo 'opcache.revalidate_freq=1' >> $php83_in2/10-opcache.ini
# echo 'opcache.jit=disable' >> $php83_in2/10-opcache.ini
a2enmod php8.3 >> $insl 2>&1
a2dismod php8.2 >> $insl 2>&1
restart_websrv
}
# This are tweaks for currently latest verion used.
function php_tweaks {
php83_tweaks
}
function save_version_info {
echo -e "pver=$ver lang=$lang mail=$mail dm=$dm nv=$nv fdir=$fdir\n$(</var/local/nextcloud-installer.ver)" > $ver_file
echo -e "Version $ver was succesfully installed at $(date +%d-%m-%Y_%H:%M:%S)\n$(</var/local/nextcloud-installer.ver)" > $ver_file
}
function save_upg_info {
echo -e "pver=$ver lang=$lang mail=$mail dm=$dm nv=$nv fdir=$fdir\n$(</var/local/nextcloud-installer.ver)" > $ver_file
echo -e "Succesfully upgraded to $ver at $(date +%d-%m-%Y_%H:%M:%S)\n$(</var/local/nextcloud-installer.ver)" > $ver_file
}
function disable_sleep {
echo "!!!!!!! Disabling sleep states." >> $insl 2>&1
echo "Disabling sleep states:"
systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target >> $insl 2>&1
}
# Check if nv option was used for every version, and exit without progress.
function nv_verify {
if [ "$nv" = "24" ]
then
nv_check_upd
fi
if [ "$nv" = "25" ]
then
nv_check_upd
fi
if [ "$nv" = "26" ]
then
nv_check_upd
fi
if [ "$nv" = "27" ]
then
nv_check_upd
fi
if [ "$nv" = "28" ]
then
maintenance_window_setup
nv_check_upd
fi
if [ "$nv" = "29" ]
then
nv_check_upd
fi
if [ "$nv" = "30" ]
then
nv_check_upd
fi
}
# Unset nver variable and read fresh value
function sncver {
unset ncver
ncver=$( sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:get version | awk -F '.' '{print $1}' )
}
function ncverf {
unset ncverf
ncverf=$( sudo -u $websrv_usr php /var/www/nextcloud/occ config:system:get version )
}
# Check for every version and update it one by one.
function nv_update {
sncver
if [ "$ncver" = "26" ]
then
nv_upd_simpl
fi
sncver
if [ "$ncver" = "26" ]
then
nv_upd_simpl
fi
sncver
if [ "$ncver" = "26" ]
then
nv_upd_simpl
fi
sncver
if [ "$ncver" = "27" ]
then
nv_upd_simpl
fi
sncver
if [ "$ncver" = "27" ]
then
nv_upd_simpl
fi
sncver
if [ "$ncver" = "27" ]
then
nv_upd_simpl
fi
sncver
if [ "$ncver" = "28" ]
then
nv_upd_simpl
fi
sncver
if [ "$ncver" = "28" ]
then
nv_upd_simpl
fi
sncver
if [ "$ncver" = "28" ]
then
nv_upd_simpl
fi
if [ "$ncver" = "29" ]
then
nv_upd_simpl
fi
if [ "$ncver" = "29" ]
then
nv_upd_simpl
fi
if [ "$ncver" = "29" ]
then
nv_upd_simpl
fi
if [ "$ncver" = "30" ]
then
nv_upd_simpl
fi
if [ "$ncver" = "30" ]
then
nv_upd_simpl
fi
if [ "$ncver" = "30" ]
then
nv_upd_simpl
fi
}
# Office Package Installing
# Currently disabled since no multiple domains support
function collab_inst {
wget https://collaboraoffice.com/downloads/gpg/collaboraonline-release-keyring.gpg --directory-prefix=/usr/share/keyrings/ >> $insl 2>&1
echo "Types: deb
URIs: https://www.collaboraoffice.com/repos/CollaboraOnline/CODE-deb
Suites: ./
Signed-By: /usr/share/keyrings/collaboraonline-release-keyring.gpg" >> /etc/apt/sources.list.d/collaboraonline.sources
echo "deb http://deb.debian.org/debian bookworm contrib non-free" > /etc/apt/sources.list.d/contrib.list
apt-get update >> $insl 2>&1
apt-get install -y -o DPkg::Lock::Timeout=-1 ttf-mscorefonts-installer coolwsd code-brand collaboraoffice-dict-en collaboraofficebasis-pl collaboraoffice-dict-pl >> $insl 2>&1
systemctl enable coolwsd >> $insl 2>&1
coolconfig set ssl.enable true >> $insl 2>&1
coolconfig set ssl.termination true >> $insl 2>&1
coolconfig set storage.wopi.host $(hostname -I) >> $insl 2>&1
# coolconfig set net.post_allow.host "192\.168\.[0-9]{1,3}\.[0-9]{1,3}"
# coolconfig set-admin-password
coolconfig update-system-template >> $insl 2>&1
systemctl restart coolwsd >> $insl 2>&1
sudo -u $websrv_usr php /var/www/nextcloud/occ app:install richdocuments >> $insl 2>&1
ufw allow 9980/tcp
}
function ooffice_inst {
echo "Docker installation processing." >> $insl 2>&1
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg >> $insl 2>&1; done
install -m 0755 -d /etc/apt/keyrings >> $insl 2>&1
curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
tee /etc/apt/sources.list.d/docker.list >> $insl 2>&1
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin >> $insl 2>&1
echo "Installing OO" >> $insl 2>&1
docker pull ghcr.io/thomisus/onlyoffice-documentserver-unlimited:latest
docker run -i -t -d -p 9880:80 ghcr.io/thomisus/onlyoffice-documentserver-unlimited
sudo -u $websrv_usr php /var/www/nextcloud/occ app:install richdocuments >> $insl 2>&1
ufw allow 9880/tcp
}
# Backup
function ncbackup {
echo "!!!!!!! Creating backup." >> $insl 2>&1
echo "Creating backup - it may take some time, please wait."
echo "Check if directory for backup exist, and create it if not." >> $insl 2>&1
mkdir $nbckd >> $insl 2>&1
ncverf
echo "Backing up database." >> $insl 2>&1
echo "Backing up database."
dbname=$(grep "dbname" "/var/www/nextcloud/config/config.php" | awk -F"'" '{print $4}')
dbpassword=$(grep "dbpassword" "/var/www/nextcloud/config/config.php" | awk -F"'" '{print $4}')
dbuser=$(grep "dbuser" "/var/www/nextcloud/config/config.php" | awk -F"'" '{print $4}')
mysqldump -u $dbuser -p$dbpassword $dbname > /var/www/nextcloud/nextcloud.sql
echo "Backing up Nextcloud directory - excluding files stored by users!" >> $insl 2>&1
echo "Backing up Nextcloud directory - excluding files stored by users!"
rm -rf $nbckd/$nbckf >> $insl 2>&1
tar -pcf $nbckd/$nbckf --exclude="/var/www/nextcloud/data" /var/www/nextcloud >> $insl 2>&1
tar -rpf $nbckd/$nbckf /var/www/nextcloud/data/.h* >> $insl 2>&1
tar -rpf $nbckd/$nbckf /var/www/nextcloud/data/.o* >> $insl 2>&1
tar -rpf $nbckd/$nbckf /var/www/nextcloud/data/audit.log >> $insl 2>&1
tar -rpf $nbckd/$nbckf /var/www/nextcloud/data/index.* >> $insl 2>&1
tar -rpf $nbckd/$nbckf /var/www/nextcloud/data/nextcloud.log >> $insl 2>&1
tar -rpf $nbckd/$nbckf /var/www/nextcloud/data/updater.log >> $insl 2>&1
tar -rpf $nbckd/$nbckf --exclude="preview" /var/www/nextcloud/data/appdata_* >> $insl 2>&1
tar -rpf $nbckd/$nbckf /var/www/nextcloud/data/bridge-bot >> $insl 2>&1
tar -rpf $nbckd/$nbckf /var/www/nextcloud/data/files_external >> $insl 2>&1
tar -rpf $nbckd/$nbckf --exclude="backups" /var/www/nextcloud/data/updater-* >> $insl 2>&1
echo "Compressing backup." >> $insl 2>&1
echo "Compressing backup."
lbzip2 -k -z -9 $nbckd/$nbckf
rm -rf $nbckd/$nbckf
mv $nbckd/nextcloud.tar.bz2 $nbckd/$(date +%Y-%m-%d-at-%H:%M:%S)-nc-v$ncverf.tar.bz2
rm -rf /var/www/nextcloud/nextcloud.sql >> $insl 2>&1
echo "Backup creation finished." >> $insl 2>&1
echo "Backup creation finished."
}
# Restore
function ncrestore {
echo "Nextcloud installer $ver (www.marcinwilk.eu) started. RESTORE MODE." >> $rstl 2>&1
date >> $rstl 2>&1
echo "---------------------------------------------------------------------------" >> $rstl 2>&1
if [ "$restore" = "list" ]; then
echo "Backup files that can be used as argument to do restore (eg. nextcloud-ins.sh -restore=filename.tar.bz2):"