-
Notifications
You must be signed in to change notification settings - Fork 103
/
syncwerk_v5_debian
1278 lines (1059 loc) · 37.7 KB
/
syncwerk_v5_debian
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
(
#
# syncwerk-server-installer/syncwerk_v5_debian
#
# Copyright 2015, Alexander Jackson <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Uncomment to run in verbose mode
set -ex
# Determine which Syncwerk version to install
cat <<EOF
Possible options:
1 = Syncwerk Community Edition (CE)
2 = Syncwerk Professional (PRO)
EOF
PS3="Which Syncwerk version would you like to install? "
select SYNCWERK_SERVER_VERSION in CE PRO ABORT
do
case "${SYNCWERK_SERVER_VERSION}" in
ABORT) echo "Aborting" ; break ;;
"") echo "$REPLY: Wrong value. Select 1 or 2." ;;
*)
if [ ${SYNCWERK_SERVER_VERSION} = "CE" ]
then
SYNCWERK_SERVER_PROFESSIONAL=disabled
else
SYNCWERK_SERVER_PROFESSIONAL=enabled
fi
# Vars
SERVER_NAME=$(hostname -s | cut -c -16)
while test "${#SERVER_NAME}" -lt 2; do SERVER_NAME="${SERVER_NAME}_"; done
HOSTNAME=$(hostname -f)
SYNCWERK_SERVER_ADMIN=admin@${HOSTNAME}
SYNCWERK_SERVER_USER=syncwerk
SYNCWERK_SERVER_FILESERVER_PORT=8082
# Without trailing slash
SYNCWERK_SERVER_HOME=/opt/syncwerk
SYNCWERK_SERVER_TIME_ZONE="Europe/Berlin"
# Don't touch the following variable, unless you know what you are doing
export DEBIAN_FRONTEND=noninteractive
# Install installer prerequisites
apt-get update
apt-get install net-tools lsb-release ca-certificates -y
OS=$(lsb_release -c | awk '{ print $2 }')
OS_DESC=$(lsb_release -d | awk -F':' '{ print $2}')
# Get architecture
if [ $(getconf LONG_BIT) = "64" ]
then
ARCH=x86-64
else
ARCH=i386
fi
DEB_ARCH=$(dpkg --print-architecture)
if [ ${SYNCWERK_SERVER_PROFESSIONAL} = "enabled" ]
then
# Syncwerk Professional
SYNCWERK_SERVER_SOURCE=$(find /usr/src/syncwerk/syncwerk-pro-server_*_x86-64.tar.gz | sort -r | head -1)
SYNCWERK_SERVER_VERSION=$(echo ${SYNCWERK_SERVER_SOURCE} | awk -F '_' '{ print $2}')
fi
# Functions
function print-system-infos {
# Log system infos
echo Timestamp
echo -----------------------------------------------------------------
date
echo
echo
echo Hostnames
echo -----------------------------------------------------------------
echo "$(hostname -f),$(hostname -s),$(hostname -d),$(hostname -i)"
echo
echo
echo Content of /etc/hosts
echo -----------------------------------------------------------------
cat /etc/hosts
echo
echo
echo OS
echo -----------------------------------------------------------------
lsb_release -a
echo
echo
echo OS Architecture
echo -----------------------------------------------------------------
echo ${ARCH}
echo
echo
echo Debian Package Architecture
echo -----------------------------------------------------------------
echo ${DEB_ARCH}
echo
echo
echo CPU info
echo -----------------------------------------------------------------
echo cat /proc/cpuinfo
echo
echo
echo Memory info
echo -----------------------------------------------------------------
echo cat /proc/meminfo
echo
echo
echo Active Kernel
echo -----------------------------------------------------------------
uname -a
echo
echo
echo Network Interfaces
echo -----------------------------------------------------------------
ifconfig -a
echo
echo
echo IP Addresses
echo -----------------------------------------------------------------
ip addr show
echo
echo
echo DNS Servers
echo -----------------------------------------------------------------
cat /etc/resolv.conf
echo
echo
echo Routes
echo -----------------------------------------------------------------
route -n
echo
echo
echo Content of /etc/network/interfaces
echo -----------------------------------------------------------------
cat /etc/network/interfaces
echo
echo
echo Debian Version
echo -----------------------------------------------------------------
cat /etc/debian_version
echo
echo
find /etc/apt/ -type f | grep -v gpg | while read line ; do echo ; \
echo Content of $line ; \
echo ----------------------------------------------------------------- ; \
cat $line ; \
echo ;
done
echo
echo
echo Installed packages
echo -----------------------------------------------------------------
dpkg -l
echo
echo
echo Process List
echo -----------------------------------------------------------------
ps axu
echo
echo
echo Local user accounts
echo -----------------------------------------------------------------
cat /etc/passwd
}
function description {
clear
cat <<EOF
Installing Syncwerk Server ${SYNCWERK_SERVER_VERSION} on
${OS_DESC} (${ARCH}).
Features: NGINX, MariaDB, Memcached, WebDAV, logrotate
-----------------------------------------------------------------
This installer is meant to run on a freshly installed machine
only. If you run it on a production server things can and
probably will go terrible wrong and you will loose valuable
data!
For questions or suggestions please contact me at
-----------------------------------------------------------------
Hit return to proceed or CTRL-C to abort.
EOF
read dummy
clear
}
function ensure-we-are-running-the-installer-on-a-supported-operating-system {
if [[ ${OS} != stretch && ${OS} != jessie && ${OS} != wheezy ]] ; then
echo "Aborting because OS not supported" ; exit 1
fi
}
function are-we-root-abort-if-not {
if [[ ${EUID} -ne 0 ]] ; then
echo "Aborting because you are not root" ; exit 1
fi
}
function does-user-exist-and-abort-if-he-does {
if getent passwd ${SYNCWERK_SERVER_USER} > /dev/null 2>&1 ;
then
echo "Aborting because user ${SYNCWERK_SERVER_USER} already exist" ; exit 1
fi
}
function does-directory-exist-abort-if-it-does {
if [[ -d "${SYNCWERK_SERVER_HOME}" ]] ;
then
echo "Aborting because directory ${SYNCWERK_SERVER_HOME} already exist" ; exit 1
fi
}
function abort-if-syncwerk-professional-source-is-missing {
if [ ${SYNCWERK_SERVER_PROFESSIONAL} = "enabled" ]
then
if [[ -f ${SYNCWERK_SERVER_SOURCE} ]] ;
then
echo "Found ${SYNCWERK_SERVER_SOURCE}. Proceeding with installation..."
else
echo "Aborting because ${SYNCWERK_SERVER_SOURCE} is missing" ; exit 1
fi
fi
}
function update-operating-system {
apt-get update
apt-get dist-upgrade -y
}
function install-system-utils {
apt-get install apt-utils dialog mtr nload htop less mc tar -y
}
function setup-ntpd {
apt-get install ntp -y
ntpd -gq
}
function setup-ufw-firewall {
apt-get install ufw -y
for i in ssh http https ; do ufw allow $i ; done
yes | ufw enable
}
function setup-fail2ban {
apt-get install fail2ban -y
}
function setup-postfix {
debconf-set-selections << EOF
postfix postfix/root_address string
postfix postfix/rfc1035_violation boolean false
postfix postfix/mydomain_warning boolean
postfix postfix/mynetworks string 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
postfix postfix/mailname string $(hostname -f)
postfix postfix/tlsmgr_upgrade_warning boolean
postfix postfix/recipient_delim string +
postfix postfix/main_mailer_type select Internet Site
postfix postfix/destinations string $(hostname -f), localhost.$(hostname -d)
postfix postfix/retry_upgrade_warning boolean
# Install postfix despite an unsupported kernel?
postfix postfix/kernel_version_warning boolean
postfix postfix/not_configured error
postfix postfix/sqlite_warning boolean
postfix postfix/mailbox_limit string 0
postfix postfix/relayhost string
postfix postfix/procmail boolean false
postfix postfix/bad_recipient_delimiter error
postfix postfix/protocols select all
postfix postfix/chattr boolean false
EOF
apt-get install postfix -y
dpkg-reconfigure postfix
}
function setup-unattended-upgrades {
debconf-set-selections <<EOF
unattended-upgrades unattended-upgrades/enable_auto_updates boolean true
EOF
apt-get install unattended-upgrades -y
dpkg-reconfigure unattended-upgrades
}
function install-syncwerk-server-requirements {
apt-get install sudo python-setuptools python-simplejson python-imaging python-mysqldb \
memcached python-memcache pwgen curl openssl -y
# Syncwerk Professional requirements
if [ ${SYNCWERK_SERVER_PROFESSIONAL} = "enabled" ]
then
apt-get install libpython2.7 libreoffice libreoffice-script-provider-python \
ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy poppler-utils python-urllib3 -y
if [ ${OS} = "stretch" ]
then
apt-get install openjdk-8-jre python3-uno -y
elif [ ${OS} = "jessie" ]
then
apt-get install openjdk-7-jre python3-uno -y
else
apt-get install openjdk-7-jre python-uno -y
fi
fi
}
function setup-nginx {
apt-get install nginx -y
rm -rf /etc/nginx/conf.d/*
mkdir -p /etc/nginx/conf.d/
cat > /etc/nginx/conf.d/syncwerk.conf <<'EOF'
server {
listen [::]:80 ipv6only=off;
server_name "";
return 301 https://$http_host$request_uri;
}
server {
listen [::]:443 ipv6only=off;
server_name "";
ssl on;
ssl_certificate /etc/nginx/ssl/syncwerk.crt;
ssl_certificate_key /etc/nginx/ssl/syncwerk.key;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_max_temp_file_size 0;
location / {
fastcgi_pass 127.0.0.1:8000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param HTTPS on;
fastcgi_param HTTP_SCHEME https;
access_log /var/log/nginx/syncwerk-webapp.access.log;
error_log /var/log/nginx/syncwerk-webapp.error.log;
}
location /seafhttp {
rewrite ^/seafhttp(.*)$ $1 break;
proxy_pass http://127.0.0.1:8082;
client_max_body_size 0;
proxy_connect_timeout 36000s;
proxy_read_timeout 36000s;
proxy_send_timeout 36000s;
}
location /media {
root /opt/syncwerk/syncwerk-server-latest/seahub;
}
location /webdav {
fastcgi_pass 127.0.0.1:8080;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param HTTPS on;
client_max_body_size 0;
access_log /var/log/nginx/syncwerk-webdav.access.log;
error_log /var/log/nginx/syncwerk-webdav.error.log;
}
}
EOF
# Create optimized nginx.conf
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup
#NGINX_USER=$(cat /etc/nginx/nginx.conf.backup | grep user | cut -d" " -f2 | cut -d";" -f1)
#NGINX_GROUP=$(cat /etc/nginx/nginx.conf.backup | grep user | cut -d" " -f3 | cut -d";" -f1)
#if [ ${#NGINX_GROUP} -lt 2 ]; then
# NGINX_GROUP="${NGINX_USER}";
#fi
cat > /etc/nginx/nginx.conf <<ENDOFFILE
#user $NGINX_USER $NGINX_GROUP;
worker_processes 4;
events {
worker_connections 8096;
multi_accept on;
use epoll;
}
pid /var/run/nginx.pid;
worker_rlimit_nofile 40000;
http {
server_tokens off;
server_names_hash_bucket_size 128;
client_max_body_size 50M;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;
# Fully disabled gzip compression to mitigate Django BREACH attack: https://www.djangoproject.com/weblog/2013/aug/06/breach-and-django/
gzip off;
#gzip_vary on;
#gzip_proxied expired no-cache no-store private auth any;
#gzip_comp_level 9;
#gzip_min_length 10240;
#gzip_buffers 16 8k;
#gzip_http_version 1.1;
#gzip_types text/plain text/css text/xml text/javascript application/javascript application/x-javascript application/xml font/woff2;
#gzip_disable "MSIE [1-6].";
include /etc/nginx/conf.d/*.conf;
map \$scheme \$php_https {
default off;
https on;
}
include perfect-forward-secrecy.conf;
}
ENDOFFILE
# Setup perfect forward secrecy
openssl dhparam -dsaparam -out /etc/nginx/dh4096.pem 4096
cat > /etc/nginx/perfect-forward-secrecy.conf <<'EOF'
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA";
ssl_dhparam dh4096.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
EOF
# Fix NGINX worker_processes to number of CPU cores
CPUS=$(cat /proc/cpuinfo | grep processor | wc | awk '{ print $1 }')
eval "sed -i 's/worker_processes.*/worker_processes $CPUS;/g' /etc/nginx/nginx.conf"
}
function create-self-signed-certificate-for-nginx {
mkdir -p /etc/nginx/ssl
openssl genrsa -out /etc/nginx/ssl/syncwerk.key 4096
cat > /etc/nginx/ssl/syncwerk.cnf << EOF
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca
prompt = no
[req_distinguished_name]
countryName = DE
stateOrProvinceName = Bayern
localityName = Wiesentheid
organizationName = Syncwerk GmbH
organizationalUnitName = Seahub
emailAddress = [email protected]
# Must be last for Syncwerk client to validate...
commonName = $(hostname -f)
[v3_ca]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
basicConstraints = CA:TRUE
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = $(hostname -f)
DNS.3 = $(hostname -s)
IP.1 = 127.0.0.1
IP.2 = $(hostname -i)
EOF
openssl req -new -x509 -key /etc/nginx/ssl/syncwerk.key -out /etc/nginx/ssl/syncwerk.crt -days 10950 -config /etc/nginx/ssl/syncwerk.cnf -sha256
}
function restart-nginx {
if [ ${OS} = "wheezy" ]
then
service nginx restart
else
if [[ $(cat /proc/1/environ) == *container* ]]; then service nginx restart ; else systemctl restart nginx ; fi
fi
}
function setup-mariadb {
if [[ ${OS} == wheezy ]]; then
cat > /etc/apt/sources.list.d/mariadb.list <<EOF
# MariaDB Repository
deb http://mirror.netcologne.de/mariadb/repo/10.0/debian wheezy main
deb-src http://mirror.netcologne.de/mariadb/repo/10.0/debian wheezy main
EOF
apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
apt-get update
apt-get upgrade -y
fi
apt-get install mariadb-server -y
SQLROOTPW=$(pwgen 14 1)
mysqladmin -u root password ${SQLROOTPW}
cat > /root/.my.cnf <<EOF
[client]
user=root
password=${SQLROOTPW}
EOF
chmod 600 /root/.my.cnf
}
function setup-database-backup {
# install package
apt-get install automysqlbackup -y
# change destination directory
SYNCWERK_SERVER_BACKUPDIR="/var/backups/syncwerk-server/database/"
eval "sed -i 's#/var/lib/automysqlbackup#$SYNCWERK_SERVER_BACKUPDIR#' /etc/default/automysqlbackup"
# launch a backup now
/usr/sbin/automysqlbackup
echo "Automatic database backups are in ${SYNCWERK_SERVER_BACKUPDIR}."
}
function sysv-autostart {
cat > /etc/init.d/syncwerk-server <<'EOF'
#!/bin/bash
### BEGIN INIT INFO
# Provides: syncwerk-server
# Required-Start: $remote_fs $syslog mysql
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Syncwerk server
# Description: Start Syncwerk server
### END INIT INFO
# Author: Alexander Jackson <[email protected]>
#
# Change the value of "user" to your linux user name
user=syncwerk
script_path=/opt/syncwerk/syncwerk-server-latest
syncwerk_init_log=/opt/syncwerk/logs/syncwerk.init.log
seahub_init_log=/opt/syncwerk/logs/seahub.init.log
# Change the value of fastcgi to true if fastcgi is to be used
fastcgi=true
# Set the port of fastcgi, default is 8000. Change it if you need different.
fastcgi_port=8000
case "$1" in
start)
sudo -u ${user} ${script_path}/seafile.sh start >> ${syncwerk_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh start >> ${seahub_init_log}
fi
;;
restart)
sudo -u ${user} ${script_path}/seafile.sh restart >> ${syncwerk_init_log}
if [ $fastcgi = true ];
then
sudo -u ${user} ${script_path}/seahub.sh restart-fastcgi ${fastcgi_port} >> ${seahub_init_log}
else
sudo -u ${user} ${script_path}/seahub.sh restart >> ${seahub_init_log}
fi
;;
stop)
sudo -u ${user} ${script_path}/seafile.sh $1 >> ${syncwerk_init_log}
sudo -u ${user} ${script_path}/seahub.sh $1 >> ${seahub_init_log}
;;
*)
echo "Usage: /etc/init.d/syncwerk-server {start|stop|restart}"
exit 1
;;
esac
EOF
chmod +x /etc/init.d/syncwerk-server
update-rc.d syncwerk-server defaults
}
function systemd-autostart {
cat > /etc/systemd/system/syncwerk.service <<'EOF'
[Unit]
Description=Syncwerk Server
After=network.target mysql.service
[Service]
Type=oneshot
ExecStart=/opt/syncwerk/syncwerk-server-latest/seafile.sh start
ExecStop=/opt/syncwerk/syncwerk-server-latest/seafile.sh stop
RemainAfterExit=yes
User=syncwerk
Group=nogroup
[Install]
WantedBy=multi-user.target
EOF
systemctl enable syncwerk
cat > /etc/systemd/system/seahub.service <<'EOF'
[Unit]
Description=Seafile Seahub
After=network.target syncwerk.service
[Service]
ExecStart=/opt/syncwerk/syncwerk-server-latest/seahub.sh start-fastcgi 8000
ExecStop=/opt/syncwerk/syncwerk-server-latest/seahub.sh stop
User=syncwerk
Group=nogroup
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
EOF
systemctl enable seahub
# Syncwerk restart script
cat > /usr/local/sbin/syncwerk-server-restart << 'EOF'
#!/bin/bash
for ACTION in stop start ; do
for SERVICE in syncwerk seahub ; do
systemctl ${ACTION} ${SERVICE}
done
done
EOF
chmod 700 /usr/local/sbin/syncwerk-server-restart
# Syncwerk start script
cat > /usr/local/sbin/syncwerk-server-start << 'EOF'
#!/bin/bash
for ACTION in start ; do
for SERVICE in syncwerk seahub ; do
systemctl ${ACTION} ${SERVICE}
done
done
EOF
chmod 700 /usr/local/sbin/syncwerk-server-start
# Syncwerk stop script
cat > /usr/local/sbin/syncwerk-server-stop << 'EOF'
#!/bin/bash
for ACTION in stop ; do
for SERVICE in syncwerk seahub ; do
systemctl ${ACTION} ${SERVICE}
done
done
EOF
chmod 700 /usr/local/sbin/syncwerk-server-stop
}
function setup-syncwerk-server-autostart {
if [ ${OS} = "wheezy" ]
then
sysv-autostart
else
if [[ $(cat /proc/1/environ) == *container* ]]; then sysv-autostart ; else systemd-autostart ; fi
fi
}
function add-system-user {
adduser --system --gecos "${SYNCWERK_SERVER_USER}" ${SYNCWERK_SERVER_USER} --home ${SYNCWERK_SERVER_HOME}
}
function create-syncwerk-server-directory {
mkdir -p ${SYNCWERK_SERVER_HOME}/installed
}
function get-syncwerk-sources {
cd ${SYNCWERK_SERVER_HOME}
if [ ${SYNCWERK_SERVER_PROFESSIONAL} = "enabled" ]
then
cp ${SYNCWERK_SERVER_SOURCE} ${SYNCWERK_SERVER_HOME}/syncwerk-pro-server_${SYNCWERK_SERVER_VERSION}_x86-64.tar.gz
tar xzf ${SYNCWERK_SERVER_HOME}/syncwerk-pro-server_${SYNCWERK_SERVER_VERSION}_x86-64.tar.gz
mv ${SYNCWERK_SERVER_HOME}/syncwerk-pro-server_${SYNCWERK_SERVER_VERSION}_x86-64.tar.gz ${SYNCWERK_SERVER_HOME}/installed/syncwerk-pro-server_${SYNCWERK_SERVER_VERSION}_x86-64.tar.gz
SYNCWERK_SERVER_INSTALL_PATH=${SYNCWERK_SERVER_HOME}/syncwerk-pro-server-${SYNCWERK_SERVER_VERSION}
else
# Disabled on 2015-11-13 due to issues with the Bintray repository. x86-64 is broke, i386 seems to be ok.
#curl -OL https://download.syncwerk.com/syncwerk-server_latest_${ARCH}.tar.gz
if [ $(getconf LONG_BIT) = "64" ]
then
wget https://download.syncwerk.com/server/community/linux/syncwerk-server_5.1.4_x86-64.tar.gz -O syncwerk-server_latest_x86-64.tar.gz
tountar="syncwerk-server_latest_x86-64.tar.gz"
else
curl -OL https://download.syncwerk.com/syncwerk-server_latest_${ARCH}.tar.gz
tountar="syncwerk-server_latest_${ARCH}.tar.gz"
fi
tar xzf $tountar
SYNCWERK_SERVER_VERSION=$(basename ${SYNCWERK_SERVER_HOME}/syncwerk-server-* | awk -F'-' ' { print $3 }')
mv $tountar installed/syncwerk-server_${SYNCWERK_SERVER_VERSION}_${ARCH}.tar.gz
SYNCWERK_SERVER_INSTALL_PATH=${SYNCWERK_SERVER_HOME}/syncwerk-server-${SYNCWERK_SERVER_VERSION}
fi
}
function create-syncwerk-database {
SYNCWERK_DB_PW=$(pwgen 14 1)
cat > ${SYNCWERK_SERVER_HOME}/.my.cnf <<EOF
[client]
user=syncwerk
password=${SYNCWERK_DB_PW}
EOF
chmod 600 ${SYNCWERK_SERVER_HOME}/.my.cnf
chown -R ${SYNCWERK_SERVER_USER}.nogroup ${SYNCWERK_SERVER_HOME}
mysql -e "CREATE DATABASE IF NOT EXISTS \`ccnet-db\` character set = 'utf8';"
mysql -e "CREATE DATABASE IF NOT EXISTS \`syncwerk-db\` character set = 'utf8';"
mysql -e "CREATE DATABASE IF NOT EXISTS \`webapp-db\` character set = 'utf8';"
mysql -e "CREATE USER 'syncwerk'@'localhost' IDENTIFIED BY '${SYNCWERK_DB_PW}';"
mysql -e "GRANT ALL PRIVILEGES ON \`ccnet-db\` . * TO 'syncwerk'@'localhost';"
mysql -e "GRANT ALL PRIVILEGES ON \`syncwerk-db\` . * TO 'syncwerk'@'localhost';"
mysql -e "GRANT ALL PRIVILEGES ON \`webapp-db\` . * TO 'syncwerk'@'localhost';"
}
function import-seahub-database-structure {
mysql webapp-db < ${SYNCWERK_SERVER_INSTALL_PATH}/seahub/sql/mysql.sql
}
function setup-syncwerk-server {
cd ${SYNCWERK_SERVER_INSTALL_PATH}
# Vars - Don't touch these unless you really know what you are doing!
SRC_DOCS_DIR=${SYNCWERK_SERVER_INSTALL_PATH}/seafile/docs/
SEAHUB_SECRET_KEYGEN=${SYNCWERK_SERVER_INSTALL_PATH}/seahub/tools/secret_key_generator.py
DEFAULT_CCNET_CONF_DIR=${SYNCWERK_SERVER_HOME}/ccnet
DEFAULT_CONF_DIR=${SYNCWERK_SERVER_HOME}/conf
SYNCWERK_SERVER_DATA_DIR=${SYNCWERK_SERVER_HOME}/syncwerk-data
LIBRARY_TEMPLATE_DIR=${SYNCWERK_SERVER_DATA_DIR}/library-template
DEST_SETTINGS_PY=${SYNCWERK_SERVER_HOME}/conf/seahub_settings.py
CCNET_INIT=${SYNCWERK_SERVER_INSTALL_PATH}/seafile/bin/ccnet-init
SEAF_SERVER_INIT=${SYNCWERK_SERVER_INSTALL_PATH}/seafile/bin/seaf-server-init
MEDIA_DIR=${SYNCWERK_SERVER_INSTALL_PATH}/seahub/media
ORIG_AVATAR_DIR=${SYNCWERK_SERVER_INSTALL_PATH}/seahub/media/avatars
DEST_AVATAR_DIR=${SYNCWERK_SERVER_HOME}/seahub-data/avatars
SYNCWERK_SERVER_SYMLINK=${SYNCWERK_SERVER_HOME}/syncwerk-server-latest
# Create ccnet conf
export SYNCWERK_LD_LIBRARY_PATH=${SYNCWERK_SERVER_INSTALL_PATH}/seafile/lib/:${SYNCWERK_SERVER_INSTALL_PATH}/seafile/lib64:${LD_LIBRARY_PATH}
LD_LIBRARY_PATH=$SYNCWERK_LD_LIBRARY_PATH "${CCNET_INIT}" -c "${DEFAULT_CCNET_CONF_DIR}" \
--name "${SERVER_NAME}" --host "${HOSTNAME}" -F "${DEFAULT_CONF_DIR}"
# Fix service url
eval "sed -i 's/^SERVICE_URL.*/SERVICE_URL = https:\/\/${HOSTNAME}/' ${DEFAULT_CONF_DIR}/ccnet.conf"
# Create syncwerk conf
LD_LIBRARY_PATH=$SYNCWERK_LD_LIBRARY_PATH ${SEAF_SERVER_INIT} --seafile-dir "${SYNCWERK_SERVER_DATA_DIR}" \
--fileserver-port ${SYNCWERK_SERVER_FILESERVER_PORT} -F "${DEFAULT_CONF_DIR}"
# Write seafile.ini
echo "${SYNCWERK_SERVER_DATA_DIR}" > "${DEFAULT_CCNET_CONF_DIR}/seafile.ini"
# Configure Syncwerk WebDAV Server
mkdir -p ${DEFAULT_CONF_DIR}
cat > ${DEFAULT_CONF_DIR}/seafdav.conf <<EOF
[WEBDAV]
enabled = true
port = 8080
fastcgi = true
share_name = /webdav
EOF
# generate seahub_settings.py
key=$(python "${SEAHUB_SECRET_KEYGEN}")
echo "SECRET_KEY = \"${key}\"" > "${DEST_SETTINGS_PY}"
# prepare avatar directory
mkdir -p "${SYNCWERK_SERVER_HOME}/seahub-data"
mv "${ORIG_AVATAR_DIR}" "${DEST_AVATAR_DIR}"
ln -s ../../../seahub-data/avatars ${MEDIA_DIR}
# create logs directory
mkdir -p "${SYNCWERK_SERVER_HOME}/logs"
# Create symlink for current server version
ln -s $(basename ${SYNCWERK_SERVER_INSTALL_PATH}) ${SYNCWERK_SERVER_SYMLINK}
# Fix permissions
chmod 0600 ${DEST_SETTINGS_PY}
chmod 0700 ${DEFAULT_CCNET_CONF_DIR} ${SYNCWERK_SERVER_DATA_DIR} ${DEFAULT_CONF_DIR}
# copy user manuals to library template
#mkdir -p ${LIBRARY_TEMPLATE_DIR}
#cp -f ${SRC_DOCS_DIR}/*.doc ${LIBRARY_TEMPLATE_DIR}
# Setup professional features
if [ ${SYNCWERK_SERVER_PROFESSIONAL} = "enabled" ]
then
PRO_PY=${SYNCWERK_SERVER_INSTALL_PATH}/pro/pro.py
$PYTHON ${PRO_PY} setup --mysql --mysql_host=127.0.0.1 --mysql_port=3306 --mysql_user=syncwerk --mysql_password=${SYNCWERK_DB_PW} --mysql_db=webapp-db
fi
# Configuring ccnet.conf
cat >> ${DEFAULT_CONF_DIR}/ccnet.conf <<EOF
[Database]
ENGINE = mysql
HOST = 127.0.0.1
PORT = 3306
USER = syncwerk
PASSWD = ${SYNCWERK_DB_PW}
DB = ccnet-db
CONNECTION_CHARSET = utf8
EOF
# Configuring seafile.conf
cat >> ${DEFAULT_CONF_DIR}/seafile.conf <<EOF
[database]
type = mysql
host = 127.0.0.1
port = 3306
user = syncwerk
password = ${SYNCWERK_DB_PW}
db_name = syncwerk-db
connection_charset = utf8
EOF
# Configuring seahub_settings.py
cat >> ${DEST_SETTINGS_PY} <<EOF
#ADMINS = (
# ('admin1', '[email protected]'),
# ('admin2', '[email protected]'),
# ('admin3', '[email protected]'),
#)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'webapp-db',
'USER': 'syncwerk',
'PASSWORD': '${SYNCWERK_DB_PW}',
'HOST': '127.0.0.1',
'PORT': '3306',
'OPTIONS': {
'init_command': 'SET storage_engine=INNODB',
}
}
}
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
# 'LOCATION': '127.0.0.2:11211',
# 'LOCATION': '127.0.0.3:11211',
}
}
#AVATAR_FILE_STORAGE = 'seahub.base.database_storage.DatabaseStorage'
#COMPRESS_CACHE_BACKEND = 'django.core.cache.backends.locmem.LocMemCache'
ACTIVATE_AFTER_REGISTRATION = False
ADD_REPLY_TO_HEADER = False
#BRANDING_CSS = 'custom/custom.css'
CLOUD_MODE = False
DEFAULT_FROM_EMAIL = 'noreply@${HOSTNAME}'
EMAIL_HOST = 'localhost'
EMAIL_HOST_PASSWORD = ''
EMAIL_HOST_USER = ''
EMAIL_PORT = '25'
EMAIL_USE_TLS = False
ENABLE_GLOBAL_ADDRESSBOOK = True
ENABLE_MAKE_GROUP_PUBLIC = False
ENABLE_REPO_HISTORY_SETTING = True
ENABLE_SETTINGS_VIA_WEB = False
ENABLE_SIGNUP = False
ENABLE_SYS_ADMIN_VIEW_REPO = True
ENABLE_THUMBNAIL = True
ENABLE_UPLOAD_FOLDER = True
FILE_ENCODING_LIST = ['auto', 'utf-8', 'gbk', 'ISO-8859-1', 'ISO-8859-5', 'Shift_JIS']
FILE_PREVIEW_MAX_SIZE = 30 * 1024 * 1024
FILE_SERVER_ROOT = 'https://${HOSTNAME}/seafhttp'
#LOGO_HEIGHT = 32
#LOGO_WIDTH = 149
#OFFICE_CONVERTOR_ROOT = 'http://127.0.0.1'
REPLACE_FROM_EMAIL = False
#REPO_PASSWORD_MIN_LENGTH = 8
SEND_EMAIL_ON_ADDING_SYSTEM_MEMBER = True
SEND_EMAIL_ON_RESETTING_USER_PASSWD = True
SERVER_EMAIL = 'EMAIL_HOST_USER'
SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
SESSION_SAVE_EVERY_REQUEST = False
SITE_BASE = 'https://${HOSTNAME}'
SITE_NAME = 'Syncwerk Server'
SITE_TITLE = 'Syncwerk Server'
THUMBNAIL_ROOT = '${SYNCWERK_SERVER_HOME}/seahub-data/thumbnail/thumb/'
TIME_ZONE = '${SYNCWERK_SERVER_TIME_ZONE}'
#USER_PASSWORD_MIN_LENGTH = 8
#USER_PASSWORD_STRENGTH_LEVEL = 3
#USER_STRONG_PASSWORD_REQUIRED = True
EOF
# Backup check_init_admin.py befor applying changes
cp ${SYNCWERK_SERVER_INSTALL_PATH}/check_init_admin.py ${SYNCWERK_SERVER_INSTALL_PATH}/check_init_admin.py.backup
# Set admin credentials in check_init_admin.py
SYNCWERK_SERVER_ADMIN_PASSWORD=$(pwgen 14 1)
eval "sed -i 's/= ask_admin_email()/= \"${SYNCWERK_SERVER_ADMIN}\"/' ${SYNCWERK_SERVER_INSTALL_PATH}/check_init_admin.py"
eval "sed -i 's/= ask_admin_password()/= \"${SYNCWERK_SERVER_ADMIN_PASSWORD}\"/' ${SYNCWERK_SERVER_INSTALL_PATH}/check_init_admin.py"
# Start and stop Syncwerk eco system. This generates the initial admin user.
${SYNCWERK_SERVER_INSTALL_PATH}/seafile.sh start
${SYNCWERK_SERVER_INSTALL_PATH}/seahub.sh start
${SYNCWERK_SERVER_INSTALL_PATH}/seahub.sh stop
${SYNCWERK_SERVER_INSTALL_PATH}/seafile.sh stop
# Restore original check_init_admin.py
mv ${SYNCWERK_SERVER_INSTALL_PATH}/check_init_admin.py.backup ${SYNCWERK_SERVER_INSTALL_PATH}/check_init_admin.py
# Fix permissions
chown ${SYNCWERK_SERVER_USER}.nogroup -R ${SYNCWERK_SERVER_HOME}
# Enable office preview in Seahub
if [ ${SYNCWERK_SERVER_PROFESSIONAL} = "enabled" ]
then
sed -i 's/enabled = false/enabled = true/' ${DEFAULT_CONF_DIR}/seafevents.conf
fi
}
function setup-syncwerk-server-logrotate {
apt-get install logrotate -y
cat > /etc/logrotate.d/syncwerk <<EOF