-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
2303 lines (1886 loc) · 63.3 KB
/
install.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
# (c) Copyright Ascensio System Limited 2010-2021
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
# You can contact Ascensio System SIA by email at [email protected]
DISK_REQUIREMENTS=40960;
MEMORY_REQUIREMENTS=5500;
CORE_REQUIREMENTS=2;
PRODUCT="onlyoffice";
BASE_DIR="/app/$PRODUCT";
NETWORK="$PRODUCT";
SWAPFILE="/${PRODUCT}_swapfile";
MACHINEKEY_PARAM=$(echo "${PRODUCT}_CORE_MACHINEKEY" | awk '{print toupper($0)}');
COMMUNITY_CONTAINER_NAME="onlyoffice-community-server";
DOCUMENT_CONTAINER_NAME="onlyoffice-document-server";
MAIL_CONTAINER_NAME="onlyoffice-mail-server";
CONTROLPANEL_CONTAINER_NAME="onlyoffice-control-panel";
ELASTICSEARCH_CONTAINER_NAME="onlyoffice-elasticsearch";
MYSQL_CONTAINER_NAME="onlyoffice-mysql-server";
COMMUNITY_IMAGE_NAME="onlyoffice/communityserver";
DOCUMENT_IMAGE_NAME="onlyoffice/documentserver-ee";
MAIL_IMAGE_NAME="onlyoffice/mailserver";
CONTROLPANEL_IMAGE_NAME="onlyoffice/controlpanel";
ELASTICSEARCH_IMAGE_NAME="onlyoffice/elasticsearch";
MYSQL_IMAGE_NAME="mysql";
COMMUNITY_VERSION="";
DOCUMENT_VERSION="";
MAIL_VERSION="";
CONTROLPANEL_VERSION="";
ELASTICSEARCH_VERSION="7.16.3";
MYSQL_VERSION="5.5";
DOCUMENT_SERVER_HOST="";
ELASTICSEARCH_PORT="9200";
MAIL_SERVER_API_HOST="";
MAIL_SERVER_DB_HOST="";
MAIL_IMAPSYNC_START_DATE="$(date +"%Y-%m-%dT%H:%M:%S")";
MAIL_DOMAIN_NAME="";
DIST="";
REV="";
KERNEL="";
UPDATE="false";
HUB="";
USERNAME="";
PASSWORD="";
INSTALL_COMMUNITY_SERVER="true";
INSTALL_DOCUMENT_SERVER="true";
INSTALL_MAIL_SERVER="true";
INSTALL_ELASTICSEARCH="true";
INSTALL_CONTROLPANEL="true";
USE_AS_EXTERNAL_SERVER="false";
PARTNER_DATA_FILE="";
INSTALLATION_TYPE="WORKSPACE_ENTERPRISE";
MAKESWAP="true";
RESTART_COMMUNITY_SERVER="false";
MOVE_COMMUNITY_SERVER_DATABASE="false";
ACTIVATE_COMMUNITY_SERVER_TRIAL="false";
MYSQL_PORT="3306";
MYSQL_DATABASE="$PRODUCT";
MYSQL_MAIL_DATABASE="${PRODUCT}_mailserver";
MYSQL_MAIL_ROOT_PASSWORD="Isadmin123";
MYSQL_MAIL_USER="mail_admin";
MYSQL_ROOT_USER="root";
MYSQL_ROOT_PASSWORD="my-secret-pw";
MYSQL_USER="${PRODUCT}_user";
MYSQL_PASSWORD="${PRODUCT}_pass";
MYSQL_HOST="";
HELP_TARGET="install.sh";
JWT_SECRET="";
CORE_MACHINEKEY="";
SKIP_HARDWARE_CHECK="false";
SKIP_VERSION_CHECK="false";
SKIP_DOMAIN_CHECK="false";
COMMUNITY_PORT=80;
while [ "$1" != "" ]; do
case $1 in
-ci | --communityimage )
if [ "$2" != "" ]; then
COMMUNITY_IMAGE_NAME=$2
shift
fi
;;
-di | --documentimage )
if [ "$2" != "" ]; then
DOCUMENT_IMAGE_NAME=$2
shift
fi
;;
-mi | --mailimage )
if [ "$2" != "" ]; then
MAIL_IMAGE_NAME=$2
shift
fi
;;
-cpi | --controlpanelimage )
if [ "$2" != "" ]; then
CONTROLPANEL_IMAGE_NAME=$2
shift
fi
;;
-mysqli | --mysqlimage )
if [ "$2" != "" ]; then
MYSQL_IMAGE_NAME=$2
shift
fi
;;
-dip | --documentserverip )
if [ "$2" != "" ]; then
DOCUMENT_SERVER_HOST=$2
shift
fi
;;
-mip | --mailserverip )
if [ "$2" != "" ]; then
MAIL_SERVER_API_HOST=$2
shift
fi
;;
-mdbip | --mailserverdbip )
if [ "$2" != "" ]; then
MAIL_SERVER_DB_HOST=$2
shift
fi
;;
-cv | --communityversion )
if [ "$2" != "" ]; then
COMMUNITY_VERSION=$2
shift
fi
;;
-dv | --documentversion )
if [ "$2" != "" ]; then
DOCUMENT_VERSION=$2
shift
fi
;;
-mv | --mailversion )
if [ "$2" != "" ]; then
MAIL_VERSION=$2
shift
fi
;;
-cpv | --controlpanelversion )
if [ "$2" != "" ]; then
CONTROLPANEL_VERSION=$2
shift
fi
;;
-md | --maildomain )
if [ "$2" != "" ]; then
MAIL_DOMAIN_NAME=$2
shift
fi
;;
-u | --update )
if [ "$2" != "" ]; then
UPDATE=$2
shift
fi
;;
-hub | --hub )
if [ "$2" != "" ]; then
HUB=$2
shift
fi
;;
-un | --username )
if [ "$2" != "" ]; then
USERNAME=$2
shift
fi
;;
-p | --password )
if [ "$2" != "" ]; then
PASSWORD=$2
shift
fi
;;
-ics | --installcommunityserver )
if [ "$2" != "" ]; then
INSTALL_COMMUNITY_SERVER=$2
shift
fi
;;
-ids | --installdocumentserver )
if [ "$2" != "" ]; then
INSTALL_DOCUMENT_SERVER=$2
shift
fi
;;
-ims | --installmailserver )
if [ "$2" != "" ]; then
INSTALL_MAIL_SERVER=$2
shift
fi
;;
-icp | --installcontrolpanel )
if [ "$2" != "" ]; then
INSTALL_CONTROLPANEL=$2
shift
fi
;;
-es | --useasexternalserver )
if [ "$2" != "" ]; then
USE_AS_EXTERNAL_SERVER=$2
shift
fi
;;
-pdf | --partnerdatafile )
if [ "$2" != "" ]; then
PARTNER_DATA_FILE=$2
shift
fi
;;
-it | --installation_type )
if [ "$2" != "" ]; then
INSTALLATION_TYPE=$(echo "$2" | awk '{print toupper($0)}');
shift
fi
;;
-ms | --makeswap )
if [ "$2" != "" ]; then
MAKESWAP=$2
shift
fi
;;
-ht | --helptarget )
if [ "$2" != "" ]; then
HELP_TARGET=$2
shift
fi
;;
-mysqlprt | --mysqlport )
if [ "$2" != "" ]; then
MYSQL_PORT=$2
shift
fi
;;
-mysqld | --mysqldatabase )
if [ "$2" != "" ]; then
MYSQL_DATABASE=$2
shift
fi
;;
-mysqlmd | --mysqlmaildatabase )
if [ "$2" != "" ]; then
MYSQL_MAIL_DATABASE=$2
shift
fi
;;
-mysqlmp | --mysqlmailpassword )
if [ "$2" != "" ]; then
MYSQL_MAIL_ROOT_PASSWORD=$2
shift
fi
;;
-mysqlmu | --mysqlmailuser )
if [ "$2" != "" ]; then
MYSQL_MAIL_USER=$2
shift
fi
;;
-mysqlru | --mysqlrootuser )
if [ "$2" != "" ]; then
MYSQL_ROOT_USER=$2
shift
fi
;;
-mysqlrp | --mysqlrootpassword )
if [ "$2" != "" ]; then
MYSQL_ROOT_PASSWORD=$2
shift
fi
;;
-mysqlu | --mysqluser )
if [ "$2" != "" ]; then
MYSQL_USER=$2
shift
fi
;;
-mysqlp | --mysqlpassword )
if [ "$2" != "" ]; then
MYSQL_PASSWORD=$2
shift
fi
;;
-mysqlh | --mysqlhost )
if [ "$2" != "" ]; then
MYSQL_HOST=$2
shift
fi
;;
-skiphc | --skiphardwarecheck )
if [ "$2" != "" ]; then
SKIP_HARDWARE_CHECK=$2
shift
fi
;;
-skipvc | --skipversioncheck )
if [ "$2" != "" ]; then
SKIP_VERSION_CHECK=$2
shift
fi
;;
-skipdc | --skipdomaincheck )
if [ "$2" != "" ]; then
SKIP_DOMAIN_CHECK=$2
shift
fi
;;
-cp | --communityport )
if [ "$2" != "" ]; then
COMMUNITY_PORT=$2
shift
fi
;;
-mk | --machinekey )
if [ "$2" != "" ]; then
CORE_MACHINEKEY=$2
shift
fi
;;
-esi | --elasticsearchimage )
if [ "$2" != "" ]; then
ELASTICSEARCH_IMAGE_NAME=$2
shift
fi
;;
-esv | --elasticsearchversion )
if [ "$2" != "" ]; then
ELASTICSEARCH_VERSION=$2
shift
fi
;;
-esh | --elasticsearchhost )
if [ "$2" != "" ]; then
ELASTICSEARCH_HOST=$2
shift
fi
;;
-ies | --installelasticsearch )
if [ "$2" != "" ]; then
INSTALL_ELASTICSEARCH=$2
shift
fi
;;
-esp | --elasticsearchport )
if [ "$2" != "" ]; then
ELASTICSEARCH_PORT=$2
shift
fi
;;
-jwt | --jwtsecret )
if [ "$2" != "" ]; then
JWT_SECRET=$2
shift
fi
;;
-? | -h | --help )
echo " Usage: bash $HELP_TARGET [PARAMETER] [[PARAMETER], ...]"
echo
echo " Parameters:"
echo " -ci, --communityimage community image name or .tar.gz file path"
echo " -di, --documentimage document image name or .tar.gz file path"
echo " -mi, --mailimage mail image name or .tar.gz file path"
echo " -esi, --elasticsearchimage elasticsearch image name or .tar.gz file path"
echo " -cpi, --controlpanelimage control panel image name or .tar.gz file path"
echo " -mysqli, --mysqlimage mysql image name or .tar.gz file path"
echo " -cv, --communityversion community version"
echo " -dv, --documentversion document version"
echo " -dip, --documentserverip document server ip"
echo " -esv, --elasticsearchversion elasticsearch version"
echo " -esh, --elasticsearchhost elasticsearch server host"
echo " -msp, --elasticsearchport elasticsearch server port"
echo " -mv, --mailversion mail version"
echo " -mip, --mailserverip mail server ip"
echo " -mdbip, --mailserverdbip mail server db ip"
echo " -cpv, --controlpanelversion control panel version"
echo " -md, --maildomain mail domail name"
echo " -u, --update use to update existing components (true|false)"
echo " -hub, --hub dockerhub name"
echo " -un, --username dockerhub username"
echo " -p, --password dockerhub password"
echo " -ics, --installcommunityserver install or update community server (true|false|pull)"
echo " -ids, --installdocumentserver install or update document server (true|false|pull)"
echo " -ims, --installmailserver install or update mail server (true|false|pull)"
echo " -ies, --installelasticsearch install or update elasticsearch (true|false|pull)"
echo " -icp, --installcontrolpanel install or update control panel (true|false|pull)"
echo " -es, --useasexternalserver use as external server (true|false)"
echo " -pdf, --partnerdatafile partner data file"
echo " -it, --installation_type installation type (GROUPS|WORKSPACE|WORKSPACE_ENTERPRISE)"
echo " -ms, --makeswap make swap file (true|false)"
echo " -mysqlh, --mysqlhost mysql server host"
echo " -mysqlprt, --mysqlport mysql server port"
echo " -mysqlru, --mysqlrootuser mysql server root user"
echo " -mysqlrp, --mysqlrootpassword mysql server root password"
echo " -mysqld, --mysqldatabase community server database name"
echo " -mysqlu, --mysqluser community server database user"
echo " -mysqlp, --mysqlpassword community server database password"
echo " -mysqlmd, --mysqlmaildatabase mail server database name"
echo " -mysqlmu, --mysqlmailuser mail server database user"
echo " -mysqlmp, --mysqlmailpassword mail server database password"
echo " -skiphc, --skiphardwarecheck skip hardware check (true|false)"
echo " -skipvc, --skipversioncheck skip version check while update (true|false)"
echo " -skipdc, --skipdomaincheck skip domain check when installing mail server (true|false)"
echo " -cp, --communityport community port (default value 80)"
echo " -mk, --machinekey setting for core.machinekey"
echo " -jwt, --jwtsecret setting for jwt secret"
echo " -?, -h, --help this help"
echo
echo " Examples"
echo " Install all the solution components:"
echo " bash $HELP_TARGET -md yourdomain.com"
echo
echo " Install all the components without Mail Server:"
echo " bash $HELP_TARGET -ims false"
echo
echo " Install Document Server only. Skip the installation of Mail Server, Community Server and Control Panel:"
echo " bash $HELP_TARGET -ics false -ids true -icp false -ims false -es true"
echo
echo " Install Mail Server only. Skip the installation of Document Server, Community Server and Control Panel:"
echo " bash $HELP_TARGET -ics false -ids false -icp false -ims true -md yourdomain.com -es true"
echo
echo " Install Community Server with Control Panel and connect it with Document Server installed on a different machine which has the 192.168.3.202 IP address:"
echo " bash $HELP_TARGET -ics true -icp true -ids false -ims false -dip 192.168.3.202"
echo
echo " Update all installed components. Stop the containers that need to be updated, remove them and run the latest versions of the corresponding components. The portal data should be picked up automatically:"
echo " bash $HELP_TARGET -u true"
echo
echo " Update Document Server only to version 4.4.2.20 and skip the update for all other components:"
echo " bash $HELP_TARGET -u true -dv 4.4.2.20 -ics false -icp false -ims false"
echo
echo " Update Community Server only to version 9.1.0.393 and skip the update for all other components:"
echo " bash $HELP_TARGET -u true -cv 9.1.0.393 -ids false -icp false -ims false"
echo
echo " Update Mail Server only to version 1.6.27 and skip the update for all other components:"
echo " bash $HELP_TARGET -u true -mv 1.6.27 -ics false -ids false -icp false"
echo
echo " Update Control Panel only to version 2.1.0.93 and skip the update for all other components:"
echo " bash $HELP_TARGET -u true -cpv 2.1.0.93 -ics false -ids false -ims false"
echo
exit 0
;;
* )
echo "Unknown parameter $1" 1>&2
exit 1
;;
esac
shift
done
root_checking () {
if [ ! $( id -u ) -eq 0 ]; then
echo "To perform this action you must be logged in with root rights"
exit 1;
fi
}
command_exists () {
type "$1" &> /dev/null;
}
file_exists () {
if [ -z "$1" ]; then
echo "file path is empty"
exit 1;
fi
if [ -f "$1" ]; then
return 0; #true
else
return 1; #false
fi
}
install_curl () {
if command_exists apt-get; then
apt-get -y update
apt-get -y -q install curl
elif command_exists yum; then
yum -y install curl
fi
if ! command_exists curl; then
echo "command curl not found"
exit 1;
fi
}
install_jq () {
curl -s -o jq http://stedolan.github.io/jq/download/linux64/jq
chmod +x jq
cp jq /usr/bin
rm jq
if ! command_exists jq; then
echo "command jq not found"
exit 1;
fi
}
install_netstat () {
if command_exists apt-get; then
apt-get -y -q install net-tools
elif command_exists yum; then
yum -y install net-tools
fi
if ! command_exists netstat; then
echo "command netstat not found"
exit 1;
fi
}
to_lowercase () {
echo "$1" | awk '{print tolower($0)}'
}
trim () {
echo -e "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
}
get_os_info () {
OS=`to_lowercase \`uname\``
if [ "${OS}" == "windowsnt" ]; then
echo "Not supported OS";
exit 1;
elif [ "${OS}" == "darwin" ]; then
echo "Not supported OS";
exit 1;
else
OS=`uname`
if [ "${OS}" == "SunOS" ] ; then
echo "Not supported OS";
exit 1;
elif [ "${OS}" == "AIX" ] ; then
echo "Not supported OS";
exit 1;
elif [ "${OS}" == "Linux" ] ; then
MACH=`uname -m`
if [ "${MACH}" != "x86_64" ]; then
echo "Currently only supports 64bit OS's";
exit 1;
fi
KERNEL=`uname -r`
if [ -f /etc/redhat-release ] ; then
CONTAINS=$(cat /etc/redhat-release | { grep -sw release || true; });
if [[ -n ${CONTAINS} ]]; then
DIST=`cat /etc/redhat-release |sed s/\ release.*//`
REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
else
DIST=`cat /etc/os-release | grep -sw 'ID' | awk -F= '{ print $2 }' | sed -e 's/^"//' -e 's/"$//'`
REV=`cat /etc/os-release | grep -sw 'VERSION_ID' | awk -F= '{ print $2 }' | sed -e 's/^"//' -e 's/"$//'`
fi
elif [ -f /etc/SuSE-release ] ; then
REV=`cat /etc/os-release | grep '^VERSION_ID' | awk -F= '{ print $2 }' | sed -e 's/^"//' -e 's/"$//'`
DIST='SuSe'
elif [ -f /etc/debian_version ] ; then
REV=`cat /etc/debian_version`
DIST='Debian'
if [ -f /etc/lsb-release ] ; then
DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'`
REV=`cat /etc/lsb-release | grep '^DISTRIB_RELEASE' | awk -F= '{ print $2 }'`
elif [ -f /etc/lsb_release ] || [ -f /usr/bin/lsb_release ] ; then
DIST=`lsb_release -a 2>&1 | grep 'Distributor ID:' | awk -F ":" '{print $2 }'`
REV=`lsb_release -a 2>&1 | grep 'Release:' | awk -F ":" '{print $2 }'`
fi
elif [ -f /etc/os-release ] ; then
DIST=`cat /etc/os-release | grep -sw 'ID' | awk -F= '{ print $2 }' | sed -e 's/^"//' -e 's/"$//'`
REV=`cat /etc/os-release | grep -sw 'VERSION_ID' | awk -F= '{ print $2 }' | sed -e 's/^"//' -e 's/"$//'`
fi
fi
DIST=$(trim $DIST);
REV=$(trim $REV);
fi
}
check_os_info () {
if [[ -z ${KERNEL} || -z ${DIST} || -z ${REV} ]]; then
echo "$KERNEL, $DIST, $REV";
echo "Not supported OS";
exit 1;
fi
}
check_kernel () {
MIN_NUM_ARR=(3 10 0);
CUR_NUM_ARR=();
CUR_STR_ARR=$(echo $KERNEL | grep -Po "[0-9]+\.[0-9]+\.[0-9]+" | tr "." " ");
for CUR_STR_ITEM in $CUR_STR_ARR
do
CUR_NUM_ARR=(${CUR_NUM_ARR[@]} $CUR_STR_ITEM)
done
INDEX=0;
while [[ $INDEX -lt 3 ]]; do
if [ ${CUR_NUM_ARR[INDEX]} -lt ${MIN_NUM_ARR[INDEX]} ]; then
echo "Not supported OS Kernel"
exit 1;
elif [ ${CUR_NUM_ARR[INDEX]} -gt ${MIN_NUM_ARR[INDEX]} ]; then
INDEX=3
fi
(( INDEX++ ))
done
}
check_hardware () {
AVAILABLE_DISK_SPACE=$(df -m / | tail -1 | awk '{ print $4 }');
if [ ${AVAILABLE_DISK_SPACE} -lt ${DISK_REQUIREMENTS} ]; then
echo "Minimal requirements are not met: need at least $DISK_REQUIREMENTS MB of free HDD space"
exit 1;
fi
TOTAL_MEMORY=$(free -m | grep -oP '\d+' | head -n 1);
if [ ${TOTAL_MEMORY} -lt ${MEMORY_REQUIREMENTS} ]; then
echo "Minimal requirements are not met: need at least $MEMORY_REQUIREMENTS MB of RAM"
exit 1;
fi
CPU_CORES_NUMBER=$(cat /proc/cpuinfo | grep processor | wc -l);
if [ ${CPU_CORES_NUMBER} -lt ${CORE_REQUIREMENTS} ]; then
echo "The system does not meet the minimal hardware requirements. CPU with at least $CORE_REQUIREMENTS cores is required"
exit 1;
fi
}
make_swap () {
DISK_REQUIREMENTS=6144; #6Gb free space
MEMORY_REQUIREMENTS=11000; #RAM ~12Gb
AVAILABLE_DISK_SPACE=$(df -m / | tail -1 | awk '{ print $4 }');
TOTAL_MEMORY=$(free -m | grep -oP '\d+' | head -n 1);
EXIST=$(swapon -s | awk '{ print $1 }' | { grep -x ${SWAPFILE} || true; });
if [[ -z $EXIST ]] && [ ${TOTAL_MEMORY} -lt ${MEMORY_REQUIREMENTS} ] && [ ${AVAILABLE_DISK_SPACE} -gt ${DISK_REQUIREMENTS} ]; then
if [ "${DIST}" == "Ubuntu" ] || [ "${DIST}" == "Debian" ]; then
fallocate -l 6G ${SWAPFILE}
else
dd if=/dev/zero of=${SWAPFILE} count=6144 bs=1MiB
fi
chmod 600 ${SWAPFILE}
mkswap ${SWAPFILE}
swapon ${SWAPFILE}
echo "$SWAPFILE none swap sw 0 0" >> /etc/fstab
fi
}
check_ports () {
RESERVED_PORTS=(443 5222 25 143 587 4190 8081 3306);
ARRAY_PORTS=();
USED_PORTS="";
if ! command_exists netstat; then
install_netstat
fi
if [ "${COMMUNITY_PORT//[0-9]}" = "" ]; then
for RESERVED_PORT in "${RESERVED_PORTS[@]}"
do
if [ "$RESERVED_PORT" -eq "$COMMUNITY_PORT" ] ; then
echo "Community port $COMMUNITY_PORT is reserved. Select another port"
exit 1;
fi
done
else
echo "Invalid community port $COMMUNITY_PORT"
exit 1;
fi
if [ "$INSTALL_COMMUNITY_SERVER" == "true" ]; then
ARRAY_PORTS=(${ARRAY_PORTS[@]} "$COMMUNITY_PORT" "443" "5222");
elif [ "$INSTALL_DOCUMENT_SERVER" == "true" ]; then
if [ "${USE_AS_EXTERNAL_SERVER}" == "true" ]; then
ARRAY_PORTS=(${ARRAY_PORTS[@]} "$COMMUNITY_PORT" "443");
fi
fi
if [ "$INSTALL_MAIL_SERVER" == "true" ]; then
ARRAY_PORTS=(${ARRAY_PORTS[@]} "25" "143" "587", "465", "993", "995", "4190");
if [ "${USE_AS_EXTERNAL_SERVER}" == "true" ]; then
ARRAY_PORTS=(${ARRAY_PORTS[@]} "8081");
if [[ -z ${MYSQL_HOST} ]]; then
ARRAY_PORTS=(${ARRAY_PORTS[@]} "3306");
fi
fi
fi
for PORT in "${ARRAY_PORTS[@]}"
do
REGEXP=":$PORT$"
CHECK_RESULT=$(netstat -lnt | awk '{print $4}' | { grep $REGEXP || true; })
if [[ $CHECK_RESULT != "" ]]; then
if [[ $USED_PORTS != "" ]]; then
USED_PORTS="$USED_PORTS, $PORT"
else
USED_PORTS="$PORT"
fi
fi
done
if [[ $USED_PORTS != "" ]]; then
echo "The following TCP Ports must be available: $USED_PORTS"
exit 1;
fi
}
check_docker_version () {
CUR_FULL_VERSION=$(docker -v | cut -d ' ' -f3 | cut -d ',' -f1);
CUR_VERSION=$(echo $CUR_FULL_VERSION | cut -d '-' -f1);
CUR_EDITION=$(echo $CUR_FULL_VERSION | cut -d '-' -f2);
if [ "${CUR_EDITION}" == "ce" ] || [ "${CUR_EDITION}" == "ee" ]; then
return 0;
fi
if [ "${CUR_VERSION}" != "${CUR_EDITION}" ]; then
echo "Unspecific docker version"
exit 1;
fi
MIN_NUM_ARR=(1 10 0);
CUR_NUM_ARR=();
CUR_STR_ARR=$(echo $CUR_VERSION | grep -Po "[0-9]+\.[0-9]+\.[0-9]+" | tr "." " ");
for CUR_STR_ITEM in $CUR_STR_ARR
do
CUR_NUM_ARR=(${CUR_NUM_ARR[@]} $CUR_STR_ITEM)
done
INDEX=0;
while [[ $INDEX -lt 3 ]]; do
if [ ${CUR_NUM_ARR[INDEX]} -lt ${MIN_NUM_ARR[INDEX]} ]; then
echo "The outdated Docker version has been found. Please update to the latest version."
exit 1;
elif [ ${CUR_NUM_ARR[INDEX]} -gt ${MIN_NUM_ARR[INDEX]} ]; then
return 0;
fi
(( INDEX++ ))
done
}
install_docker_using_script () {
if ! command_exists curl ; then
install_curl;
fi
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh
}
install_docker () {
if [ "${DIST}" == "Ubuntu" ] || [ "${DIST}" == "Debian" ] || [[ "${DIST}" == CentOS* ]] || [ "${DIST}" == "Fedora" ]; then
install_docker_using_script
systemctl start docker
systemctl enable docker
elif [ "${DIST}" == "Red Hat Enterprise Linux Server" ]; then
echo ""
echo "Your operating system does not allow Docker CE installation."
echo "You can install Docker EE using the manual here - https://docs.docker.com/engine/installation/linux/rhel/"
echo ""
exit 1;
elif [ "${DIST}" == "SuSe" ]; then
echo ""
echo "Your operating system does not allow Docker CE installation."
echo "You can install Docker EE using the manual here - https://docs.docker.com/engine/installation/linux/suse/"
echo ""
exit 1;
elif [ "${DIST}" == "altlinux" ]; then
apt-get -y install docker-io
chkconfig docker on
service docker start
systemctl enable docker
else
echo ""
echo "Docker could not be installed automatically."
echo "Please use this official instruction https://docs.docker.com/engine/installation/linux/other/ for its manual installation."
echo ""
exit 1;
fi
if ! command_exists docker ; then
echo "error while installing docker"
exit 1;
fi
}
docker_login () {
if [[ -n ${USERNAME} && -n ${PASSWORD} ]]; then
docker login ${HUB} --username ${USERNAME} --password ${PASSWORD}
fi
}
make_directories () {
mkdir -p "$BASE_DIR/setup";
mkdir -p "$BASE_DIR/DocumentServer/data";
mkdir -p "$BASE_DIR/DocumentServer/logs";
mkdir -p "$BASE_DIR/DocumentServer/fonts";
mkdir -p "$BASE_DIR/DocumentServer/forgotten";
mkdir -p "$BASE_DIR/MailServer/data/certs";
mkdir -p "$BASE_DIR/MailServer/logs";
mkdir -p "$BASE_DIR/CommunityServer/data";
mkdir -p "$BASE_DIR/CommunityServer/data/certs";
mkdir -p "$BASE_DIR/CommunityServer/data/certs/tmp";
mkdir -p "$BASE_DIR/CommunityServer/logs";
mkdir -p "$BASE_DIR/ControlPanel/data";
mkdir -p "$BASE_DIR/ControlPanel/logs";
mkdir -p "$BASE_DIR/mysql/conf.d";
mkdir -p "$BASE_DIR/mysql/data";
mkdir -p "$BASE_DIR/mysql/initdb";
mkdir -p "$BASE_DIR/mysql/logs";
mkdir -p "$BASE_DIR/mysql/.private";
}
get_available_version () {
if [[ -z "$1" ]]; then
echo "image name is empty";
exit 1;
fi
if ! command_exists curl ; then
install_curl;
fi
if ! command_exists jq ; then
install_jq
fi
CREDENTIALS="";
AUTH_HEADER="";
TAGS_RESP="";
if [[ -n ${HUB} ]]; then
DOCKER_CONFIG="$HOME/.docker/config.json";
if [[ -f "$DOCKER_CONFIG" ]]; then
CREDENTIALS=$(jq -r '.auths."'$HUB'".auth' < "$DOCKER_CONFIG");
if [ "$CREDENTIALS" == "null" ]; then
CREDENTIALS="";
fi
fi
if [[ -z ${CREDENTIALS} && -n ${USERNAME} && -n ${PASSWORD} ]]; then
CREDENTIALS=$(echo -n "$USERNAME:$PASSWORD" | base64);
fi
if [[ -n ${CREDENTIALS} ]]; then
AUTH_HEADER="Authorization: Basic $CREDENTIALS";
fi
REPO=$(echo $1 | sed "s/$HUB\///g");
TAGS_RESP=$(curl -s -H "$AUTH_HEADER" -X GET https://$HUB/v2/$REPO/tags/list);
TAGS_RESP=$(echo $TAGS_RESP | jq -r '.tags')
else
if [[ -n ${USERNAME} && -n ${PASSWORD} ]]; then
CREDENTIALS="{\"username\":\"$USERNAME\",\"password\":\"$PASSWORD\"}";
fi
if [[ -n ${CREDENTIALS} ]]; then
LOGIN_RESP=$(curl -s -H "Content-Type: application/json" -X POST -d "$CREDENTIALS" https://hub.docker.com/v2/users/login/);
TOKEN=$(echo $LOGIN_RESP | jq -r '.token');
AUTH_HEADER="Authorization: JWT $TOKEN";
sleep 1;
fi
TAGS_RESP=$(curl -s -H "$AUTH_HEADER" -X GET https://hub.docker.com/v2/repositories/$1/tags/);
TAGS_RESP=$(echo $TAGS_RESP | jq -r '.results[].name')
fi
VERSION_REGEX_1="[0-9]+\.[0-9]+\.[0-9]+"
VERSION_REGEX_2="[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+"
TAG_LIST=""
for item in $TAGS_RESP
do
if [[ $item =~ $VERSION_REGEX_1 ]] || [[ $item =~ $VERSION_REGEX_2 ]]; then
TAG_LIST="$item,$TAG_LIST"
fi
done
LATEST_TAG=$(echo $TAG_LIST | tr ',' '\n' | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | awk '/./{line=$0} END{print line}');
echo "$LATEST_TAG" | sed "s/\"//g"
}