-
Notifications
You must be signed in to change notification settings - Fork 0
/
zero.sh
1271 lines (1196 loc) · 45.3 KB
/
zero.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
##########################################################################################
# Ubuntu 20.04+ / 22.04+ LTS x86_64
# Nextcloud 23+ and 24+ (if released!)
# Carsten Rieger IT-Services (www.c-rieger.de)
# Vielen Dank an / many thanks to:
# https://github.com/MrEddX
# https://github.com/DasCanard
# https://codeberg.org/DecaTec
##########################################################################################
##############################
# D: Konfigurationsvariablen #
# E: Configuration variables #
##############################
# D: Datenverzeichnis: wo sollen die Nextcloud Daten gespeichert werden
# absoluter Pfad, bspw.: "/var/nc_data"
# E: Data directory: where to store Nextclud data
# absolute path, e.g.: "/var/nc_data"
NEXTCLOUDDATAPATH="/data"
# D: Lokaler Nextcloud Administrator
# beliebiger Name, bspw.: "nc_admin"
# E: local Nextcloud administrator
# any name, e.g.: "nc_admin"
NEXTCLOUDADMINUSER="nc_admin"
# D: Passwort des lokalen Nextcloud Administrators
# NEXTCLOUDADMINUSERPASSWORD="NeXtCLoUd-PwD"
# oder automatisch generieren lassen
# E: Password for the local Nextcloud administrator
# NEXTCLOUDADMINUSERPASSWORD="NeXtCLoUd-PwD"
# or it will be generated by the script
NEXTCLOUDADMINUSERPASSWORD=$(openssl rand -hex 16)
# Nextcloud Release (https://nextcloud.com/changelog/)
# D: bspw. NCRELEASE="nextcloud-23.0.4.tar.bz2"
# oder das aktuelle/letzte (latest.tar.bz2) Release:
# E: e.g. NCRELEASE="nextcloud-23.0.4.tar.bz2"
# or the current/latest (latest.tar.bz2) release:
NCRELEASE="latest.tar.bz2"
# D: Ihre Nextcloud Domain ohne(!) https
# Wird der Parameter LETSENCRYPT="y" gesetzt
# so werden TLS Zertifikate von dieser Domain
# von Let's Encrypt automatisch eingebunden
# E: Your Nextcloud daomain without (!) https
# If the parameter LETSENCRYPT="y" is set
# ssl/tls certificates will be requested
# and embedded from Let's Encrypt
NEXTCLOUDDNS="ihre.domain.de"
# Let'sEncrypt-SSL/TLS: [y|n]
# D: Sollen Zertifikate von LetsEncrypt eingerichtet werden?
# LETSENCRYPT="y" <- inkl. automat. Erneuerungen
# E: Should the script configure Let's Encrypt certificates?
# LETSENCRYPT="y" <- incl. automat. renewals
LETSENCRYPT="n"
# D: Nextcloud Externe IP(v4)
# bspw. NEXTCLOUDEXTIP="123.124.125.120"
# oder vom System ausgelesen
# E: Nextcloud external ip (v4)
# e.g. NEXTCLOUDEXTIP="123.124.125.120"
# or read from the system
NEXTCLOUDEXTIP=$(dig +short txt ch whoami.cloudflare @1.0.0.1)
# D: MariaDB-Root-Passwort setzen,
# bspw.: MARIADBROOTPASSWORD="MaRiAdB-RooT-PwD"
# oder automatisch vom Skript generieren lassen
# E: Set MariaDB-Root-Password,
# e.g.: MARIADBROOTPASSWORD="MaRiAdB-RooT-PwD"
# or it wil be gerated by the script
MARIADBROOTPASSWORD=$(openssl rand -hex 16)
# D: Datenbank auswählen:
# MariaDB "m" oder postgreSQL "p"
# E: Choose database:
# MariaDB "m" or postgreSQL "p"
DATABASE="m"
# D: Datenbankbenutzer:
# E: Database user:
NCDBUSER="ncdbuser"
# D: Passwort des Datenbankbenutzers:
# NCDBPASSWORD="YouR#P@ssworT" oder vom Skript generiert
# E: Password for database user:
# NCDBPASSWORD="YouR#P@ssworT" or generated by script
NCDBPASSWORD=$(openssl rand -hex 16)
# D: Welche Zeitzone soll verwendet werden?
# E: Which timezone is to be set?
CURRENTTIMEZONE='Europe/Berlin'
# D: Welche Region (Sprache) soll für die Nextcloud Phone Region gesetzt werden?
# E: Which region is to be se for the "Nextcloud Phone Region"
PHONEREGION='DE'
#########################################################################
### ! DO NOT CHANGE ANYTHING FROM HERE! // KEINE ÄNDERUNGEN AB HIER ! ###
#########################################################################
###########################
# Start/Begin #
###########################
# D: Linuxbenutzer ermitteln
# E: identify the current user
BENUTZERNAME=$(logname)
# D: Ausführung als ROOT überprüfen
# E: Operating as root?
if [ "$(id -u)" != "0" ]
then
clear
echo ""
echo "*****************************"
echo "* BITTE ALS ROOT AUSFÜHREN! *"
echo "* *"
echo "* PLEASE OPERATE AS ROOT! *"
echo "*****************************"
echo ""
exit 1
fi
if [ "$(lsb_release -r | awk '{ print $2 }')" = "20.04" ] || [ "$(lsb_release -r | awk '{ print $2 }')" = "22.04" ]
then
clear
echo "*************************************************"
echo "* Pre-Installationschecks werden durchgefuehrt *"
echo "* Pre-Installationschecks are initiated *"
echo "*************************************************"
echo ""
echo "* Test: Root ...............:::::::::::::::: OK *"
echo ""
echo "* Test: Ubuntu 2X.04 LTS .........:::::::::: OK *"
echo ""
else
clear
echo ""
echo "****************************************"
echo "* Sie verwenden kein Ubuntu 20/22 *"
echo "* You aren't operating on Ubuntu 20/22 *"
echo "****************************************"
echo ""
exit 1
fi
##########################
# Re-Install. verhindern #
# Prevent Second Run #
##########################
if [ -e "/var/www/nextcloud/config/config.php" ] || [ -e /etc/nginx/conf.d/nextcloud.conf ]; then
clear
echo "*************************************************"
echo "* Test: Bestehende Insatllation ....:::::FAILED *"
echo "* Test: Previous installation ......:::::FAILED *"
echo "*************************************************"
echo ""
echo "* Nextcloud ist auf diesem System bereits installiert!"
echo "* Nextcloud has already been installed on this system!"
echo ""
echo "* Bitte entfernen Sie alles komplett, bevor Sie mit einer Installation fortfahren."
echo "* Please remove it completely before proceeding to a new installation."
echo ""
echo "* Das Uninstall-Skript finden Sie hier // Please find the uninstall script here:"
echo "* /home/$BENUTZERNAME/Nextcloud-Installationsskript/uninstall.sh"
echo ""
exit 1
else
echo "*************************************************"
echo "* Keine Bestehende Installation ......:::::: OK *"
echo "* No previous installation ..........::::::: OK *"
echo "*************************************************"
echo ""
fi
###########################
# Prüfe Homeverzeichnis #
# Verify homedirectory #
###########################
if [ ! -d "/home/$BENUTZERNAME/" ]; then
echo "* Erstelle: Benutzerverzeichnis .....:::::: OK *"
echo "* Creating: Home Directory ..........:::::: OK *"
echo ""
mkdir /home/"$BENUTZERNAME"/
echo "* Test: Benutzerverzeichnis ........:::::::: OK *"
echo "* Test: Home directory ..........::::::::::: OK *"
echo ""
else
echo "* Test: Benutzerverzeichnis ........:::::::: OK *"
echo "* Test: Home directory ..........::::::::::: OK *"
echo ""
fi
if [ ! -d "/home/$BENUTZERNAME/Nextcloud-Installationsskript/" ]; then
echo "* Erstelle: Installationsskript-Verzeichnis: OK *"
echo "* Creating: Install directory .......::::::: OK *"
echo ""
mkdir /home/"$BENUTZERNAME"/Nextcloud-Installationsskript/
echo "* Test: Installationsskript-Verzeichnis ..:: OK *"
echo "* Test: Installscript directory .....::::::: OK *"
echo ""
else
echo "* Test: Installationsskript-Verzeichnis ..:: OK *"
echo "* Test: Installscript directory .....::::::: OK *"
echo ""
fi
echo "*************************************************"
echo "* Pre-Installationschecks erfolgreich! *"
echo "* Pre-Installation checks successfull! *"
echo "*************************************************"
echo ""
sleep 3
###########################
# D: Resolver ermitteln #
# E: Identify the resolver#
###########################
RESOLVER=$(grep "nameserver" /etc/resolv.conf| awk '{ print $2 }')
###########################
# D: Lokale IP ermitteln #
# E: Identify local ip #
###########################
IPA=$(hostname -I | awk '{print $1}')
###########################
# D: Systempfade auslesen #
# E: System patches #
###########################
addaptrepository=$(command -v add-apt-repository)
adduser=$(command -v adduser)
apt=$(command -v apt-get)
aptkey=$(command -v apt-key)
aptmark=$(command -v apt-mark)
cat=$(command -v cat)
chmod=$(command -v chmod)
chown=$(command -v chown)
clear=$(command -v clear)
cp=$(command -v cp)
curl=$(command -v curl)
echo=$(command -v echo)
ip=$(command -v ip)
ln=$(command -v ln)
mysql_secure_installation=$(command -v mysql_secure_installation)
mkdir=$(command -v mkdir)
mv=$(command -v mv)
rm=$(command -v rm)
sed=$(command -v sed)
service=$(command -v service)
sudo=$(command -v sudo)
su=$(command -v su)
systemctl=$(command -v systemctl)
tar=$(command -v tar)
touch=$(command -v touch)
usermod=$(command -v usermod)
wget=$(command -v wget)
###########################
# Uninstall-Skript #
###########################
${touch} /home/"$BENUTZERNAME"/Nextcloud-Installationsskript/uninstall.sh
${cat} <<EOF >/home/"$BENUTZERNAME"/Nextcloud-Installationsskript/uninstall.sh
#!/bin/bash
if [ "\$(id -u)" != "0" ]
then
${clear}
${echo} ""
${echo} "*****************************"
${echo} "* BITTE ALS ROOT AUSFÜHREN! *"
${echo} "* *"
${echo} "* PLEASE OPERATE AS ROOT! *"
${echo} "*****************************"
${echo} ""
exit 1
fi
${clear}
${echo} "*************************************************************************************"
${echo} "* ACHTUNG! WARNING! ACHTUNG! WARNING! *"
${echo} "* *"
${echo} "* Nextcloud und ALLE Benutzer-Daten und -Dateien werden unwiderruflich gelöscht! *"
${echo} "* Nextcloud as well as ALL user files will be IRREVERSIBLY REMOVED from the system! *"
${echo} "* *"
${echo} "*************************************************************************************"
${echo}
${echo} "Press Ctrl+C To Abort // Drücke STRG+C um abzubrechen"
${echo}
seconds=$((10))
while [ \$seconds -gt 0 ]; do
${echo} -ne "Removal begins after: \$seconds\033[0K\r"
sleep 1
: \$((seconds--))
done
${rm} -Rf $NEXTCLOUDDATAPATH
${mv} /etc/hosts.bak /etc/hosts
${apt} remove --purge --allow-change-held-packages -y nginx* php* mariadb-* mysql-common libdbd-mariadb-perl galera-* postgresql-* redis* fail2ban ufw
${rm} -Rf /etc/ufw /etc/fail2ban /var/www /etc/mysql /etc/postgresql /etc/postgresql-common /var/lib/mysql /var/lib/postgresql /etc/letsencrypt /var/log/nextcloud /home/$BENUTZERNAME/Nextcloud-Installationsskript/install.log /home/$BENUTZERNAME/Nextcloud-Installationsskript/update.sh
${rm} -Rf /etc/nginx /usr/share/keyrings/nginx-archive-keyring.gpg
${addaptrepository} ppa:ondrej/php -ry
${rm} -f /etc/ssl/certs/dhparam.pem /etc/apt/sources.list.d/* /etc/motd /root/.bash_aliases
deluser --remove-all-files acmeuser
crontab -u www-data -r
${rm} -f /etc/sudoers.d/acmeuser
${apt} autoremove -y
${apt} autoclean -y
${sed} -i '/vm.overcommit_memory = 1/d' /etc/sysctl.conf
echo ""
echo "Done!"
exit 0
EOF
${chmod} +x /home/"$BENUTZERNAME"/Nextcloud-Installationsskript/uninstall.sh
###########################
# D: Hostdatei anpassen #
# E: Мodify host file #
###########################
${cp} /etc/hosts /etc/hosts.bak
${sed} -i '/127.0.1.1/d' /etc/hosts
${cat} <<EOF >> /etc/hosts
127.0.1.1 $(hostname) $NEXTCLOUDDNS
$NEXTCLOUDEXTIP $NEXTCLOUDDNS
EOF
###########################
# D: Systemeinstellungen #
# E: System settings #
###########################
${apt} install -y figlet
figlet=$(command -v figlet)
${touch} /etc/motd
${figlet} Nextcloud > /etc/motd
${cat} <<EOF >> /etc/motd
(c) Carsten Rieger IT-Services
https://www.c-rieger.de
EOF
###########################
# Logdatei / Logfile #
# install.log #
###########################
exec > >(tee -i "/home/$BENUTZERNAME/Nextcloud-Installationsskript/install.log")
exec 2>&1
###########################
# D: Update-Funktion #
# E: Update-function #
###########################
function update_and_clean() {
${apt} update
${apt} upgrade -y
${apt} autoclean -y
${apt} autoremove -y
}
###########################
# D: Kosmetische Funktion #
# E: Cosmetical function #
###########################
CrI() {
while ps "$!" > /dev/null; do
echo -n '.'
sleep '0.5'
done
${echo} ''
}
###########################
# D: Relevante Software #
# wird f. apt geblockt #
# E: Relevant software #
# will be blocked for #
# apt #
###########################
function setHOLD() {
${aptmark} hold nginx*
${aptmark} hold redis*
${aptmark} hold mariadb*
${aptmark} hold mysql*
${aptmark} hold php*
}
###########################
# D: Services neu starten #
# E: Restart services #
###########################
function restart_all_services() {
${service} nginx restart
if [ $DATABASE == "m" ]
then
${service} mysql restart
else
${service} postgresql restart
fi
${service} redis-server restart
${service} php8.0-fpm restart
}
###########################
# D: NC Daten indizieren #
# E: NC data index #
###########################
function nextcloud_scan_data() {
${sudo} -u www-data /usr/bin/php /var/www/nextcloud/occ files:scan --all
${sudo} -u www-data /usr/bin/php /var/www/nextcloud/occ files:scan-app-data
${service} fail2ban restart
}
###########################
# D: Verwende IPv4 f. apt #
# E: Use IPv4 for apt #
###########################
${echo} 'Acquire::ForceIPv4 "true";' >> /etc/apt/apt.conf.d/99force-ipv4
###########################
# D: Basissoftware #
# E: Required software #
###########################
${clear}
${echo} "Systemaktualisierungen u. Rerepositories"
${echo} "System updates and software repositories"
${echo} ""
sleep 3
${apt} upgrade -y
${apt} install -y \
apt-transport-https bash-completion bzip2 ca-certificates cron curl dialog dirmngr ffmpeg ghostscript git gpg gnupg gnupg2 htop \
libfile-fcntllock-perl libfontconfig1 libfuse2 locate lsb-release net-tools screen smbclient socat software-properties-common \
ssl-cert tree ubuntu-keyring unzip wget zip
###########################
# D: Energiesparmodus: aus#
# E: Energy mode: off #
###########################
${systemctl} mask sleep.target suspend.target hibernate.target hybrid-sleep.target
###########################
# PHP 8 Repositories #
###########################
${addaptrepository} ppa:ondrej/php -y
# ${echo} "deb https://ppa.launchpadcontent.net/ondrej/php/ubuntu $(lsb_release -cs) main" | /usr/bin/tee /etc/apt/sources.list.d/php.list
# ${aptkey} adv --keyserver keyserver.ubuntu.com --recv-keys 4f4ea0aae5267a6c
###########################
# NGINX Repositories #
###########################
${curl} https://nginx.org/keys/nginx_signing.key | gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
${echo} "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
###########################
# DB Repositories #
###########################
if [ $DATABASE == "m" ]
then
${echo} "MariaDB aus dem PPA"
# ${echo} "deb [arch=amd64] https://mirror.kumi.systems/mariadb/repo/10.7/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/mariadb.list
# ${aptkey} adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
else
${echo} "postgreSQL aus dem PPA"
# ${echo} "deb [arch=amd64] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list
# ${wget} --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
fi
###########################
# D: Entfernen Autoupdates#
# E: Remove unatt.upgrades#
###########################
${apt} purge -y unattended-upgrades
###########################
# D: Systemaktualisierung #
# E: System update #
###########################
update_and_clean
###########################
# D: Bereinigung #
# E: Clean Up #
###########################
${apt} remove -y apache2 nginx nginx-common nginx-full --allow-change-held-packages
${rm} -Rf /etc/apache2 /etc/nginx
###########################
# Installation NGINX #
###########################
${clear}
${echo} "NGINX-Installation"
${echo} ""
sleep 3
${apt} install -y nginx --allow-change-held-packages
${systemctl} enable nginx.service
${mv} /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
${touch} /etc/nginx/nginx.conf
${cat} <<EOF >/etc/nginx/nginx.conf
user www-data;
worker_processes auto;
pid /var/run/nginx.pid;
events {
worker_connections 2048;
multi_accept on; use epoll;
}
http {
server_names_hash_bucket_size 64;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
#set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
send_timeout 3600;
tcp_nopush on;
tcp_nodelay on;
open_file_cache max=500 inactive=10m;
open_file_cache_errors on;
keepalive_timeout 65;
reset_timedout_connection on;
server_tokens off;
resolver $RESOLVER valid=30s;
resolver_timeout 5s;
include /etc/nginx/conf.d/*.conf;
}
EOF
###########################
# Neustart/Restart NGINX #
###########################
${service} nginx restart
###########################
# D: Verzeichnisse anlegen#
# E: Create directories #
###########################
${mkdir} -p /var/log/nextcloud /var/www/letsencrypt/.well-known/acme-challenge /etc/letsencrypt/rsa-certs /etc/letsencrypt/ecc-certs
${chmod} -R 775 /var/www/letsencrypt
${chmod} -R 770 /etc/letsencrypt
${chown} -R www-data:www-data /var/log/nextcloud /var/www/ /etc/letsencrypt
###########################
# D: Hinzufügen ACME-User #
# E: Create ACME-user #
###########################
${adduser} --disabled-login --gecos "" acmeuser
${usermod} -aG www-data acmeuser
${touch} /etc/sudoers.d/acmeuser
${cat} <<EOF >/etc/sudoers.d/acmeuser
acmeuser ALL=NOPASSWD: /bin/systemctl reload nginx.service
EOF
${su} - acmeuser -c "/usr/bin/curl https://get.acme.sh | sh"
${su} - acmeuser -c ".acme.sh/acme.sh --set-default-ca --server letsencrypt"
###########################
# Installation PHP8 #
###########################
${clear}
${echo} "PHP-Installation"
${echo} ""
sleep 3
${apt} install -y php-common php8.0-{fpm,gd,curl,xml,zip,intl,mbstring,bz2,ldap,apcu,bcmath,gmp,imagick,igbinary,redis,smbclient,cli,common,opcache,readline} imagemagick ldap-utils nfs-common cifs-utils --allow-change-held-packages
AvailableRAM=$(/usr/bin/awk '/MemAvailable/ {printf "%d", $2/1024}' /proc/meminfo)
AverageFPM=$(/usr/bin/ps --no-headers -o 'rss,cmd' -C php-fpm8.0 | /usr/bin/awk '{ sum+=$1 } END { printf ("%d\n", sum/NR/1024,"M") }')
FPMS=$((AvailableRAM/AverageFPM))
PMaxSS=$((FPMS*2/3))
PMinSS=$((PMaxSS/2))
PStartS=$(((PMaxSS+PMinSS)/2))
${cp} /etc/php/8.0/fpm/pool.d/www.conf /etc/php/8.0/fpm/pool.d/www.conf.bak
${cp} /etc/php/8.0/fpm/php-fpm.conf /etc/php/8.0/fpm/php-fpm.conf.bak
${cp} /etc/php/8.0/cli/php.ini /etc/php/8.0/cli/php.ini.bak
${cp} /etc/php/8.0/fpm/php.ini /etc/php/8.0/fpm/php.ini.bak
${cp} /etc/php/8.0/fpm/php-fpm.conf /etc/php/8.0/fpm/php-fpm.conf.bak
${cp} /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.bak
${sed} -i 's/;env\[HOSTNAME\] = /env[HOSTNAME] = /' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/;env\[TMP\] = /env[TMP] = /' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/;env\[TMPDIR\] = /env[TMPDIR] = /' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/;env\[TEMP\] = /env[TEMP] = /' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/;env\[PATH\] = /env[PATH] = /' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/pm.max_children =.*/pm.max_children = '$FPMS'/' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/pm.start_servers =.*/pm.start_servers = '$PStartS'/' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/pm.min_spare_servers =.*/pm.min_spare_servers = '$PMinSS'/' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/pm.max_spare_servers =.*/pm.max_spare_servers = '$PMaxSS'/' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/;pm.max_requests =.*/pm.max_requests = 2000/' /etc/php/8.0/fpm/pool.d/www.conf
${sed} -i 's/output_buffering =.*/output_buffering = 'Off'/' /etc/php/8.0/cli/php.ini
${sed} -i 's/max_execution_time =.*/max_execution_time = 3600/' /etc/php/8.0/cli/php.ini
${sed} -i 's/max_input_time =.*/max_input_time = 3600/' /etc/php/8.0/cli/php.ini
${sed} -i 's/post_max_size =.*/post_max_size = 10240M/' /etc/php/8.0/cli/php.ini
${sed} -i 's/upload_max_filesize =.*/upload_max_filesize = 10240M/' /etc/php/8.0/cli/php.ini
${sed} -i "s|;date.timezone.*|date.timezone = $CURRENTTIMEZONE|" /etc/php/8.0/cli/php.ini
${sed} -i 's/memory_limit = 128M/memory_limit = 2G/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/output_buffering =.*/output_buffering = 'Off'/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/max_execution_time =.*/max_execution_time = 3600/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/max_input_time =.*/max_input_time = 3600/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/post_max_size =.*/post_max_size = 10240M/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/upload_max_filesize =.*/upload_max_filesize = 10240M/' /etc/php/8.0/fpm/php.ini
${sed} -i "s|;date.timezone.*|date.timezone = $CURRENTTIMEZONE|" /etc/php/8.0/fpm/php.ini
${sed} -i 's/;session.cookie_secure.*/session.cookie_secure = True/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/;opcache.enable=.*/opcache.enable=1/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/;opcache.enable_cli=.*/opcache.enable_cli=1/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/;opcache.memory_consumption=.*/opcache.memory_consumption=128/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/;opcache.interned_strings_buffer=.*/opcache.interned_strings_buffer=16/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/;opcache.max_accelerated_files=.*/opcache.max_accelerated_files=10000/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/;opcache.revalidate_freq=.*/opcache.revalidate_freq=1/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/;opcache.save_comments=.*/opcache.save_comments=1/' /etc/php/8.0/fpm/php.ini
${sed} -i 's/allow_url_fopen =.*/allow_url_fopen = 1/' /etc/php/8.0/fpm/php.ini
${sed} -i '$aapc.enable_cli=1' /etc/php/8.0/mods-available/apcu.ini
${sed} -i "s|;emergency_restart_threshold.*|emergency_restart_threshold = 10|g" /etc/php/8.0/fpm/php-fpm.conf
${sed} -i "s|;emergency_restart_interval.*|emergency_restart_interval = 1m|g" /etc/php/8.0/fpm/php-fpm.conf
${sed} -i "s|;process_control_timeout.*|process_control_timeout = 10|g" /etc/php/8.0/fpm/php-fpm.conf
${sed} -i 's/rights=\"none\" pattern=\"PS\"/rights=\"read|write\" pattern=\"PS\"/' /etc/ImageMagick-6/policy.xml
${sed} -i 's/rights=\"none\" pattern=\"EPS\"/rights=\"read|write\" pattern=\"EPS\"/' /etc/ImageMagick-6/policy.xml
${sed} -i 's/rights=\"none\" pattern=\"PDF\"/rights=\"read|write\" pattern=\"PDF\"/' /etc/ImageMagick-6/policy.xml
${sed} -i 's/rights=\"none\" pattern=\"XPS\"/rights=\"read|write\" pattern=\"XPS\"/' /etc/ImageMagick-6/policy.xml
${ln} -s /usr/local/bin/gs /usr/bin/gs
###########################
# Neustart/Restart PHP #
###########################
${service} php8.0-fpm restart
${service} nginx restart
###########################
# Installation DB #
###########################
${clear}
${echo} "DB-Installation"
${echo} ""
sleep 3
if [ $DATABASE == "m" ]
then
${apt} install -y php8.0-mysql mariadb-server --allow-change-held-packages
${service} mysql stop
${mv} /etc/mysql/my.cnf /etc/mysql/my.cnf.bak
${cat} <<EOF >/etc/mysql/my.cnf
[client]
default-character-set = utf8mb4
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
log_error=/var/log/mysql/mysql_error.log
nice = 0
socket = /var/run/mysqld/mysqld.sock
[mysqld]
basedir = /usr
bind-address = 127.0.0.1
binlog_format = ROW
bulk_insert_buffer_size = 16M
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
concurrent_insert = 2
connect_timeout = 5
datadir = /var/lib/mysql
default_storage_engine = InnoDB
expire_logs_days = 2
general_log_file = /var/log/mysql/mysql.log
general_log = 0
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
innodb_file_per_table = 1
innodb_open_files = 400
innodb_io_capacity = 4000
innodb_flush_method = O_DIRECT
innodb_read_only_compressed=OFF
key_buffer_size = 128M
lc_messages_dir = /usr/share/mysql
lc_messages = en_US
log_bin = /var/log/mysql/mariadb-bin
log_bin_index = /var/log/mysql/mariadb-bin.index
log_error = /var/log/mysql/mysql_error.log
log_slow_verbosity = query_plan
log_warnings = 2
long_query_time = 1
max_allowed_packet = 16M
max_binlog_size = 100M
max_connections = 200
max_heap_table_size = 64M
myisam_recover_options = BACKUP
myisam_sort_buffer_size = 512M
port = 3306
pid-file = /var/run/mysqld/mysqld.pid
query_cache_limit = 2M
query_cache_size = 64M
query_cache_type = 1
query_cache_min_res_unit = 2k
read_buffer_size = 2M
read_rnd_buffer_size = 1M
skip-log-bin
skip-external-locking
skip-name-resolve
slow_query_log_file = /var/log/mysql/mariadb-slow.log
slow-query-log = 1
socket = /var/run/mysqld/mysqld.sock
sort_buffer_size = 4M
table_open_cache = 400
thread_cache_size = 128
tmp_table_size = 64M
tmpdir = /tmp
transaction_isolation = READ-COMMITTED
#unix_socket=OFF
user = mysql
wait_timeout = 600
[mysqldump]
max_allowed_packet = 16M
quick
quote-names
[isamchk]
key_buffer = 16M
EOF
if [ "$(lsb_release -r | awk '{ print $2 }')" = "20.04" ]
then
sed -i '/innodb_read_only_compressed=OFF/d' /etc/mysql/my.cnf
fi
${service} mysql restart
mysql=$(command -v mysql)
${mysql} -e "CREATE DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
${mysql} -e "CREATE USER ${NCDBUSER}@localhost IDENTIFIED BY '${NCDBPASSWORD}';"
${mysql} -e "GRANT ALL PRIVILEGES ON nextcloud.* TO '${NCDBUSER}'@'localhost';"
${mysql} -e "FLUSH PRIVILEGES;"
cat <<EOF | ${mysql_secure_installation}
\n
n
y
y
y
y
EOF
mysql -u root -e "SET PASSWORD FOR root@'localhost' = PASSWORD('$MARIADBROOTPASSWORD'); FLUSH PRIVILEGES;"
else
if [ "$(lsb_release -r | awk '{ print $2 }')" = "20.04" ]
then
${apt} install -y php8.0-pgsql postgresql-12 --allow-change-held-packages
else
${apt} install -y php8.0-pgsql postgresql-14 --allow-change-held-packages
fi
sudo -u postgres psql <<EOF
CREATE USER ${NCDBUSER} WITH PASSWORD '${NCDBPASSWORD}';
CREATE DATABASE nextcloud TEMPLATE template0 ENCODING 'UNICODE';
ALTER DATABASE nextcloud OWNER TO ${NCDBUSER};
GRANT ALL PRIVILEGES ON DATABASE nextcloud TO ${NCDBUSER};
EOF
${service} postgresql restart
fi
###########################
# Installation Redis #
###########################
${clear}
${echo} "REDIS-Installation"
${echo} ""
sleep 3
${apt} install -y redis-server --allow-change-held-packages
${cp} /etc/redis/redis.conf /etc/redis/redis.conf.bak
${sed} -i 's/port 6379/port 0/' /etc/redis/redis.conf
${sed} -i s/\#\ unixsocket/\unixsocket/g /etc/redis/redis.conf
${sed} -i 's/unixsocketperm 700/unixsocketperm 770/' /etc/redis/redis.conf
${sed} -i 's/# maxclients 10000/maxclients 10240/' /etc/redis/redis.conf
${cp} /etc/sysctl.conf /etc/sysctl.conf.bak
${sed} -i '$avm.overcommit_memory = 1' /etc/sysctl.conf
${usermod} -a -G redis www-data
###########################
# Self-Signed-SSL #
###########################
${apt} install -y ssl-cert
###########################
# NGINX TLS #
###########################
[ -f /etc/nginx/conf.d/default.conf ] && ${mv} /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
${touch} /etc/nginx/conf.d/default.conf
${touch} /etc/nginx/conf.d/http.conf
${cat} <<EOF >/etc/nginx/conf.d/http.conf
upstream php-handler {
server unix:/run/php/php8.0-fpm.sock;
}
map \$arg_v \$asset_immutable {
"" "";
default "immutable";
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name cloud.server.io;
root /var/www;
location ^~ /.well-known/acme-challenge {
default_type text/plain;
root /var/www/letsencrypt;
}
location / {
return 301 https://\$host\$request_uri;
}
}
EOF
${cat} <<EOF >/etc/nginx/conf.d/nextcloud.conf
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name cloud.server.io;
ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
ssl_trusted_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
#ssl_certificate /etc/letsencrypt/rsa-certs/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/rsa-certs/privkey.pem;
#ssl_certificate /etc/letsencrypt/ecc-certs/fullchain.pem;
#ssl_certificate_key /etc/letsencrypt/ecc-certs/privkey.pem;
#ssl_trusted_certificate /etc/letsencrypt/ecc-certs/chain.pem;
ssl_dhparam /etc/ssl/certs/dhparam.pem;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_protocols TLSv1.3 TLSv1.2;
ssl_ciphers 'TLS-CHACHA20-POLY1305-SHA256:TLS-AES-256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384';
ssl_ecdh_curve X448:secp521r1:secp384r1;
ssl_prefer_server_ciphers on;
ssl_stapling on;
ssl_stapling_verify on;
client_max_body_size 10G;
client_body_timeout 3600s;
fastcgi_buffers 64 4K;
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/wasm application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;
add_header Permissions-Policy "interest-cohort=()";
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Download-Options "noopen" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
add_header X-XSS-Protection "1; mode=block" always;
fastcgi_hide_header X-Powered-By;
root /var/www/nextcloud;
index index.php index.html /index.php\$request_uri;
location = / {
if ( \$http_user_agent ~ ^DavClnt ) {
return 302 /remote.php/webdav/\$is_args\$args;
}
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ^~ /apps/rainloop/app/data {
deny all;
}
location ^~ /.well-known {
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
location /.well-known/acme-challenge { try_files \$uri \$uri/ =404; }
location /.well-known/pki-validation { try_files \$uri \$uri/ =404; }
return 301 /index.php\$request_uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:\$|/) { return 404; }
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { return 404; }
location ~ \.php(?:\$|/) {
rewrite ^/(?!index|test|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php\$request_uri;
fastcgi_split_path_info ^(.+?\.php)(/.*)\$;
set \$path_info \$fastcgi_path_info;
try_files \$fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
fastcgi_param PATH_INFO \$path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
fastcgi_read_timeout 3600;
fastcgi_send_timeout 3600;
fastcgi_connect_timeout 3600;
}
location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)\$ {
try_files \$uri /index.php\$request_uri;
add_header Cache-Control "public, max-age=15778463, \$asset_immutable";
expires 6M;
access_log off;
location ~ \.wasm\$ {
default_type application/wasm;
}
}
location ~ \.woff2?\$ {
try_files \$uri /index.php\$request_uri;
expires 7d;
access_log off;
}
location /remote {
return 301 /remote.php\$request_uri;
}
location / {
try_files \$uri \$uri/ /index.php\$request_uri;
}
}
EOF
${clear}
${echo} "Diffie-Hellman key:"
${echo} ""
/usr/bin/openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
${echo} ""
sleep 3
###########################
# Hostname #
###########################
${sed} -i "s/server_name cloud.server.io;/server_name $(hostname) $NEXTCLOUDDNS;/" /etc/nginx/conf.d/http.conf
${sed} -i "s/server_name cloud.server.io;/server_name $(hostname) $NEXTCLOUDDNS;/" /etc/nginx/conf.d/nextcloud.conf
###########################
# Nextcloud-CRON #
###########################
(/usr/bin/crontab -u www-data -l ; echo "*/5 * * * * /usr/bin/php -f /var/www/nextcloud/cron.php > /dev/null 2>&1") | /usr/bin/crontab -u www-data -
###########################
# Neustart/Restart NGINX #
###########################
${service} nginx restart
${clear}
###########################
# Herunterladen/Download #
# Nextcloud #
###########################
${echo} "Downloading:" $NCRELEASE
${wget} -q https://download.nextcloud.com/server/releases/$NCRELEASE & CrI
${wget} -q https://download.nextcloud.com/server/releases/$NCRELEASE.md5
${echo} ""
${echo} "Verify Checksum (MD5):"
if [ "$(md5sum -c $NCRELEASE.md5 < $NCRELEASE | awk '{ print $2 }')" = "OK" ]
then
md5sum -c $NCRELEASE.md5 < $NCRELEASE
${echo} ""
else
${clear}
${echo} ""
${echo} "CHECKSUM ERROR => SECURITY ALERT => ABBRUCH!"
exit 1
fi
${echo} "Extracting:" $NCRELEASE
${tar} -xjf $NCRELEASE -C /var/www & CrI
${chown} -R www-data:www-data /var/www/
${rm} -f $NCRELEASE $NCRELEASE.md5
restart_all_services
###########################
# Nextcloud Installation #
###########################
${clear}
${echo} "Nextcloud Installation"
${echo} ""
if [[ ! -e $NEXTCLOUDDATAPATH ]];
then
${mkdir} -p $NEXTCLOUDDATAPATH
fi
${chown} -R www-data:www-data $NEXTCLOUDDATAPATH
${echo} "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
${echo} ""
${echo} "Die Nextcloud wird jetzt 'silent' installiert - bitte haben Sie Geduld!"
${echo} "Your Nextcloud will now be installed silently - please be patient!"
${echo} ""
if [ $DATABASE == "m" ]
then
sudo -u www-data php /var/www/nextcloud/occ maintenance:install --database "mysql" --database-name "nextcloud" --database-user "${NCDBUSER}" --database-pass "${NCDBPASSWORD}" --admin-user "${NEXTCLOUDADMINUSER}" --admin-pass "${NEXTCLOUDADMINUSERPASSWORD}" --data-dir "${NEXTCLOUDDATAPATH}"
else
sudo -u www-data php /var/www/nextcloud/occ maintenance:install --database "pgsql" --database-name "nextcloud" --database-user "${NCDBUSER}" --database-pass "${NCDBPASSWORD}" --admin-user "${NEXTCLOUDADMINUSER}" --admin-pass "${NEXTCLOUDADMINUSERPASSWORD}" --data-dir "${NEXTCLOUDDATAPATH}"
fi
${echo} ""
sleep 5
declare -l YOURSERVERNAME
YOURSERVERNAME=$(hostname)
###########################
# Optimieren/Optimizing #
# Nextcloud config.php #
###########################
${sudo} -u www-data ${cp} /var/www/nextcloud/config/config.php /var/www/nextcloud/config/config.php.bak
${sudo} -u www-data /usr/bin/php /var/www/nextcloud/occ config:system:set trusted_domains 0 --value="$YOURSERVERNAME"
${sudo} -u www-data /usr/bin/php /var/www/nextcloud/occ config:system:set trusted_domains 1 --value="$NEXTCLOUDDNS"
${sudo} -u www-data /usr/bin/php /var/www/nextcloud/occ config:system:set trusted_domains 2 --value="$IPA"
${sudo} -u www-data /usr/bin/php /var/www/nextcloud/occ config:system:set overwrite.cli.url --value=https://"$NEXTCLOUDDNS"
${echo} ""
${echo} "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
${cp} /var/www/nextcloud/.user.ini /usr/local/src/.user.ini.bak
${sudo} -u www-data ${sed} -i 's/output_buffering=.*/output_buffering=0/' /var/www/nextcloud/.user.ini
${sudo} -u www-data /usr/bin/php /var/www/nextcloud/occ background:cron
${sed} -i '/);/d' /var/www/nextcloud/config/config.php
${cat} <<EOF >>/var/www/nextcloud/config/config.php
'activity_expire_days' => 14,
'allow_local_remote_servers' => true,