Browse Source

cryptpad app

Bob Mottram 7 years ago
parent
commit
2ce3937be4
2 changed files with 518 additions and 7 deletions
  1. 502
    0
      src/freedombone-app-cryptpad
  2. 16
    7
      src/freedombone-app-koel

+ 502
- 0
src/freedombone-app-cryptpad View File

@@ -0,0 +1,502 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# cryptpad application
12
+#
13
+# License
14
+# =======
15
+#
16
+# Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
17
+#
18
+# This program is free software: you can redistribute it and/or modify
19
+# it under the terms of the GNU Affero General Public License as published by
20
+# the Free Software Foundation, either version 3 of the License, or
21
+# (at your option) any later version.
22
+#
23
+# This program is distributed in the hope that it will be useful,
24
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26
+# GNU Affero General Public License for more details.
27
+#
28
+# You should have received a copy of the GNU Affero General Public License
29
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
30
+
31
+VARIANTS='full full-vim writer'
32
+
33
+IN_DEFAULT_INSTALL=0
34
+SHOW_ON_ABOUT=1
35
+
36
+CRYPTPAD_DOMAIN_NAME=
37
+CRYPTPAD_CODE=
38
+CRYPTPAD_ONION_PORT=8119
39
+CRYPTPAD_PORT=9003
40
+CRYPTPAD_REPO=""
41
+CRYPTPAD_COMMIT=''
42
+CRYPTPAD_ADMIN_PASSWORD=
43
+CRYPTPAD_DIR=/etc/cryptpad
44
+
45
+cryptpad_variables=(ONION_ONLY
46
+                    CRYPTPAD_DOMAIN_NAME
47
+                    CRYPTPAD_CODE
48
+                    DDNS_PROVIDER
49
+                    MY_EMAIL_ADDRESS
50
+                    MY_USERNAME)
51
+
52
+function remove_user_cryptpad {
53
+    remove_username="$1"
54
+
55
+    ${PROJECT_NAME}-pass -u $remove_username --rmapp cryptpad
56
+}
57
+
58
+function add_user_cryptpad {
59
+    new_username="$1"
60
+    new_user_password="$2"
61
+
62
+    ${PROJECT_NAME}-pass -u $new_username -a cryptpad -p "$new_user_password"
63
+    echo '0'
64
+}
65
+
66
+function install_interactive_cryptpad {
67
+    if [ ! $ONION_ONLY ]; then
68
+        ONION_ONLY='no'
69
+    fi
70
+
71
+    if [[ $ONION_ONLY != "no" ]]; then
72
+        CRYPTPAD_DOMAIN_NAME='cryptpad.local'
73
+    else
74
+        CRYPTPAD_DETAILS_COMPLETE=
75
+        while [ ! $CRYPTPAD_DETAILS_COMPLETE ]
76
+        do
77
+            data=$(tempfile 2>/dev/null)
78
+            trap "rm -f $data" 0 1 2 5 15
79
+            if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
80
+                dialog --backtitle $"Freedombone Configuration" \
81
+                       --title $"Cryptpad Configuration" \
82
+                       --form $"\nPlease enter your Cryptpad details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
83
+                       $"Domain:" 1 1 "$(grep 'CRYPTPAD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
84
+                       $"Code:" 2 1 "$(grep 'CRYPTPAD_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
85
+                       2> $data
86
+            else
87
+                dialog --backtitle $"Freedombone Configuration" \
88
+                       --title $"Cryptpad Configuration" \
89
+                       --form $"\nPlease enter your Cryptpad details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
90
+                       $"Domain:" 1 1 "$(grep 'CRYPTPAD_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
91
+                       2> $data
92
+            fi
93
+            sel=$?
94
+            case $sel in
95
+                1) exit 1;;
96
+                255) exit 1;;
97
+            esac
98
+            CRYPTPAD_DOMAIN_NAME=$(cat $data | sed -n 1p)
99
+            if [ $CRYPTPAD_DOMAIN_NAME ]; then
100
+                if [[ $CRYPTPAD_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
101
+                    CRYPTPAD_DOMAIN_NAME=""
102
+                fi
103
+                TEST_DOMAIN_NAME=$CRYPTPAD_DOMAIN_NAME
104
+                validate_domain_name
105
+                if [[ $TEST_DOMAIN_NAME != $CRYPTPAD_DOMAIN_NAME ]]; then
106
+                    CRYPTPAD_DOMAIN_NAME=
107
+                    dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
108
+                else
109
+                    if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
110
+                        CRYPTPAD_CODE=$(cat $data | sed -n 2p)
111
+                        validate_freedns_code "$CRYPTPAD_CODE"
112
+                        if [ ! $VALID_CODE ]; then
113
+                            CRYPTPAD_DOMAIN_NAME=
114
+                        fi
115
+                    fi
116
+                fi
117
+            fi
118
+            if [ $CRYPTPAD_DOMAIN_NAME ]; then
119
+                CRYPTPAD_DETAILS_COMPLETE="yes"
120
+            fi
121
+        done
122
+
123
+        # save the results in the config file
124
+        write_config_param "CRYPTPAD_CODE" "$CRYPTPAD_CODE"
125
+    fi
126
+    write_config_param "CRYPTPAD_DOMAIN_NAME" "$CRYPTPAD_DOMAIN_NAME"
127
+    APP_INSTALLED=1
128
+}
129
+
130
+function change_password_cryptpad {
131
+    curr_username="$1"
132
+    new_user_password="$2"
133
+
134
+    read_config_param 'CRYPTPAD_DOMAIN_NAME'
135
+
136
+    ${PROJECT_NAME}-pass -u "$curr_username" -a cryptpad -p "$new_user_password"
137
+}
138
+
139
+function reconfigure_cryptpad {
140
+    if [ -d $CRYPTPAD_DIR/datastore ]; then
141
+        rm -rf $CRYPTPAD_DIR/datastore
142
+    fi
143
+}
144
+
145
+function upgrade_cryptpad {
146
+    if grep -q "cryptpad domain" $COMPLETION_FILE; then
147
+        CRYPTPAD_DOMAIN_NAME=$(get_completion_param "cryptpad domain")
148
+    fi
149
+
150
+    CURR_CRYPTPAD_COMMIT=$(get_completion_param "cryptpad commit")
151
+    if [[ "$CURR_CRYPTPAD_COMMIT" == "$CRYPTPAD_COMMIT" ]]; then
152
+        return
153
+    fi
154
+
155
+    systemctl stop cryptpad
156
+
157
+    # update to the next commit
158
+    function_check set_repo_commit
159
+    set_repo_commit $CRYPTPAD_DIR "cryptpad commit" "$CRYPTPAD_COMMIT" $CRYPTPAD_REPO
160
+
161
+    cd $CRYPTPAD_DIR
162
+    chown -R cryptpad:cryptpad *
163
+
164
+    systemctl start cryptpad
165
+}
166
+
167
+
168
+function backup_local_cryptpad {
169
+    CRYPTPAD_DOMAIN_NAME='cryptpad'
170
+    if grep -q "cryptpad domain" $COMPLETION_FILE; then
171
+        CRYPTPAD_DOMAIN_NAME=$(get_completion_param "cryptpad domain")
172
+    fi
173
+
174
+    source_directory=$CRYPTPAD_DIR/datastore
175
+    if [ -d $source_directory ]; then
176
+        systemctl stop cryptpad
177
+
178
+        dest_directory=cryptpad
179
+        function_check suspend_site
180
+        suspend_site ${CRYPTPAD_DOMAIN_NAME}
181
+
182
+        function_check backup_directory_to_usb
183
+        backup_directory_to_usb $source_directory $dest_directory
184
+
185
+        function_check restart_site
186
+        restart_site
187
+
188
+        systemctl start cryptpad
189
+    fi
190
+}
191
+
192
+function restore_local_cryptpad {
193
+    if [ -d $CRYPTPAD_DIR ]; then
194
+        systemctl stop cryptpad
195
+        temp_restore_dir=/root/tempcryptpad
196
+        function_check restore_directory_from_usb
197
+        restore_directory_from_usb $temp_restore_dir cryptpad
198
+        cp -r $temp_restore_dir$CRYPTPAD_DIR/datastore/* $CRYPTPAD_DIR/datastore/
199
+        systemctl start cryptpad
200
+    fi
201
+}
202
+
203
+function backup_remote_cryptpad {
204
+    if grep -q "cryptpad domain" $COMPLETION_FILE; then
205
+        CRYPTPAD_DOMAIN_NAME=$(get_completion_param "cryptpad domain")
206
+        temp_backup_dir=$CRYPTPAD_DIR/datastore
207
+        if [ -d $temp_backup_dir ]; then
208
+            systemctl stop cryptpad
209
+
210
+            function_check suspend_site
211
+            suspend_site ${CRYPTPAD_DOMAIN_NAME}
212
+
213
+            echo $"Backing up Cryptpad installation"
214
+
215
+            function_check backup_directory_to_friend
216
+            backup_directory_to_friend $temp_backup_dir cryptpad
217
+
218
+            function_check restart_site
219
+            restart_site
220
+
221
+            systemctl start cryptpad
222
+        else
223
+            echo $"cryptpad domain specified but not found in ${temp_backup_dir}"
224
+        fi
225
+    fi
226
+}
227
+
228
+function restore_remote_cryptpad {
229
+    if [ -d $CRYPTPAD_DIR ]; then
230
+        systemctl stop cryptpad
231
+        temp_restore_dir=/root/tempcryptpad
232
+        function_check restore_directory_from_usb
233
+        restore_directory_from_friend $temp_restore_dir cryptpad
234
+        cp -r $temp_restore_dir$CRYPTPAD_DIR/datastore/* $CRYPTPAD_DIR/datastore/
235
+        systemctl start cryptpad
236
+    fi
237
+}
238
+
239
+function remove_cryptpad {
240
+    if [ ${#CRYPTPAD_DOMAIN_NAME} -eq 0 ]; then
241
+        return
242
+    fi
243
+
244
+    systemctl stop cryptpad
245
+    systemctl disable cryptpad
246
+    if [ -f /etc/systemd/system/cryptpad.service ]; then
247
+        rm /etc/systemd/system/cryptpad.service
248
+    fi
249
+
250
+    function_check remove_nodejs
251
+    remove_nodejs cryptpad
252
+
253
+    read_config_param "CRYPTPAD_DOMAIN_NAME"
254
+    read_config_param "MY_USERNAME"
255
+    echo "Removing $CRYPTPAD_DOMAIN_NAME"
256
+    nginx_dissite $CRYPTPAD_DOMAIN_NAME
257
+    remove_certs $CRYPTPAD_DOMAIN_NAME
258
+
259
+    if [ -d $CRYPTPAD_DIR ]; then
260
+        rm -rf $CRYPTPAD_DIR
261
+    fi
262
+    if [ -f /etc/nginx/sites-available/$CRYPTPAD_DOMAIN_NAME ]; then
263
+        rm /etc/nginx/sites-available/$CRYPTPAD_DOMAIN_NAME
264
+    fi
265
+    function_check remove_onion_service
266
+    remove_onion_service cryptpad ${CRYPTPAD_ONION_PORT}
267
+    remove_app cryptpad
268
+    remove_completion_param install_cryptpad
269
+    sed -i '/cryptpad/d' $COMPLETION_FILE
270
+
271
+    userdel -r cryptpad
272
+
273
+    function_check remove_ddns_domain
274
+    remove_ddns_domain $CRYPTPAD_DOMAIN_NAME
275
+}
276
+
277
+function install_cryptpad_main {
278
+    if [ ! $CRYPTPAD_DOMAIN_NAME ]; then
279
+        echo $'No domain name was given for cryptpad'
280
+        exit 7359
281
+    fi
282
+
283
+    if [[ $(app_is_installed cryptpad_main) == "1" ]]; then
284
+        return
285
+    fi
286
+
287
+    if [ ! -d /var/www/$CRYPTPAD_DOMAIN_NAME ]; then
288
+        mkdir /var/www/$CRYPTPAD_DOMAIN_NAME
289
+    fi
290
+    if [ ! -d $CRYPTPAD_DIR ]; then
291
+        mkdir -p $CRYPTPAD_DIR
292
+
293
+        function_check git_clone
294
+        git_clone $CRYPTPAD_REPO $CRYPTPAD_DIR
295
+        if [ ! -d $CRYPTPAD_DIR ]; then
296
+            echo $'Unable to clone cryptpad repo'
297
+            exit 783251
298
+        fi
299
+    fi
300
+
301
+    # an unprivileged user to run as
302
+    useradd -d $CRYPTPAD_DIR/ cryptpad
303
+
304
+    cd $CRYPTPAD_DIR
305
+    git checkout $CRYPTPAD_COMMIT -b $CRYPTPAD_COMMIT
306
+    set_completion_param "cryptpad commit" "$CRYPTPAD_COMMIT"
307
+
308
+    chown -R cryptpad:cryptpad $CRYPTPAD_COMMIT
309
+
310
+    function_check add_ddns_domain
311
+    add_ddns_domain $CRYPTPAD_DOMAIN_NAME
312
+
313
+    CRYPTPAD_ONION_HOSTNAME=$(add_onion_service cryptpad 80 ${CRYPTPAD_ONION_PORT})
314
+
315
+    cryptpad_nginx_site=/etc/nginx/sites-available/$CRYPTPAD_DOMAIN_NAME
316
+    if [[ $ONION_ONLY == "no" ]]; then
317
+        function_check nginx_http_redirect
318
+        nginx_http_redirect $CRYPTPAD_DOMAIN_NAME "index index.html"
319
+        echo 'server {' >> $cryptpad_nginx_site
320
+        echo '  listen 443 ssl;' >> $cryptpad_nginx_site
321
+        echo '  listen [::]:443 ssl;' >> $cryptpad_nginx_site
322
+        echo "  server_name $CRYPTPAD_DOMAIN_NAME;" >> $cryptpad_nginx_site
323
+        echo '' >> $cryptpad_nginx_site
324
+        echo '  # Security' >> $cryptpad_nginx_site
325
+        function_check nginx_ssl mobile
326
+        nginx_ssl $CRYPTPAD_DOMAIN_NAME
327
+
328
+        function_check nginx_disable_sniffing
329
+        nginx_disable_sniffing $CRYPTPAD_DOMAIN_NAME
330
+
331
+        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $cryptpad_nginx_site
332
+        echo '' >> $cryptpad_nginx_site
333
+        echo '  # Logs' >> $cryptpad_nginx_site
334
+        echo '  access_log /dev/null;' >> $cryptpad_nginx_site
335
+        echo '  error_log /dev/null;' >> $cryptpad_nginx_site
336
+        echo '' >> $cryptpad_nginx_site
337
+        echo '  # Root' >> $cryptpad_nginx_site
338
+        echo "  root $CRYPTPAD_DIR;" >> $cryptpad_nginx_site
339
+        echo '' >> $cryptpad_nginx_site
340
+        echo '  index index.html;' >> $cryptpad_nginx_site
341
+        echo '' >> $cryptpad_nginx_site
342
+        echo '  location = / {' >> $cryptpad_nginx_site
343
+        echo "    proxy_pass http://localhost:$CRYPTPAD_PORT;" >> $cryptpad_nginx_site
344
+        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $cryptpad_nginx_site
345
+        echo '    proxy_set_header Host $host;' >> $cryptpad_nginx_site
346
+        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $cryptpad_nginx_site
347
+        echo '' >> $cryptpad_nginx_site
348
+        echo '    # WebSocket support (nginx 1.4)' >> $cryptpad_nginx_site
349
+        echo '    proxy_http_version 1.1;' >> $cryptpad_nginx_site
350
+        echo '    proxy_set_header Upgrade $http_upgrade;' >> $cryptpad_nginx_site
351
+        echo '    proxy_set_header Connection upgrade;' >> $cryptpad_nginx_site
352
+        echo '  }' >> $cryptpad_nginx_site
353
+        echo '' >> $cryptpad_nginx_site
354
+
355
+        echo '  location ^~ /customize.dist/ {' >> $cryptpad_nginx_site
356
+        echo '    # This is needed in order to prevent infinite recursion between /customize/ and the root' >> $cryptpad_nginx_site
357
+        echo '  }' >> $cryptpad_nginx_site
358
+        echo '  location ^~ /customize/ {' >> $cryptpad_nginx_site
359
+        echo '    rewrite ^/customize/(.*)$ $1 break;' >> $cryptpad_nginx_site
360
+        echo '    try_files /customize/$uri /customize.dist/$uri;' >> $cryptpad_nginx_site
361
+        echo '  }' >> $cryptpad_nginx_site
362
+        echo '  location = /api/config {' >> $cryptpad_nginx_site
363
+        echo '    default_type text/javascript;' >> $cryptpad_nginx_site
364
+        echo '    rewrite ^.*$ /customize/api/config break;' >> $cryptpad_nginx_site
365
+        echo '  }' >> $cryptpad_nginx_site
366
+        echo '' >> $cryptpad_nginx_site
367
+        echo '  location ^~ /blob/ {' >> $cryptpad_nginx_site
368
+        echo '    try_files $uri =404;' >> $cryptpad_nginx_site
369
+        echo '  }' >> $cryptpad_nginx_site
370
+        echo '' >> $cryptpad_nginx_site
371
+        echo '  location ~ ^/(register|login|settings|user|pad|drive|poll|slide|code|whiteboard|file|media)$ {' >> $cryptpad_nginx_site
372
+        echo '    rewrite ^(.*)$ $1/ redirect;' >> $cryptpad_nginx_site
373
+        echo '  }' >> $cryptpad_nginx_site
374
+        echo '' >> $cryptpad_nginx_site
375
+        echo '  try_files $uri $uri/index.html /customize/$uri;' >> $cryptpad_nginx_site
376
+        echo '}' >> $cryptpad_nginx_site
377
+    else
378
+        echo -n '' > $cryptpad_nginx_site
379
+    fi
380
+    echo 'server {' >> $cryptpad_nginx_site
381
+    echo "    listen 127.0.0.1:$CRYPTPAD_ONION_PORT default_server;" >> $cryptpad_nginx_site
382
+    echo "    server_name $CRYPTPAD_ONION_HOSTNAME;" >> $cryptpad_nginx_site
383
+    echo '' >> $cryptpad_nginx_site
384
+    echo '  # Logs' >> $cryptpad_nginx_site
385
+    echo '  access_log /dev/null;' >> $cryptpad_nginx_site
386
+    echo '  error_log /dev/null;' >> $cryptpad_nginx_site
387
+    echo '' >> $cryptpad_nginx_site
388
+    echo '  # Root' >> $cryptpad_nginx_site
389
+    echo "  root $CRYPTPAD_DIR;" >> $cryptpad_nginx_site
390
+    echo '' >> $cryptpad_nginx_site
391
+    echo '  index index.html;' >> $cryptpad_nginx_site
392
+    echo '' >> $cryptpad_nginx_site
393
+    echo '  location = / {' >> $cryptpad_nginx_site
394
+    echo "    proxy_pass http://localhost:$CRYPTPAD_PORT;" >> $cryptpad_nginx_site
395
+    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $cryptpad_nginx_site
396
+    echo '    proxy_set_header Host $host;' >> $cryptpad_nginx_site
397
+    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $cryptpad_nginx_site
398
+    echo '' >> $cryptpad_nginx_site
399
+    echo '    # WebSocket support (nginx 1.4)' >> $cryptpad_nginx_site
400
+    echo '    proxy_http_version 1.1;' >> $cryptpad_nginx_site
401
+    echo '    proxy_set_header Upgrade $http_upgrade;' >> $cryptpad_nginx_site
402
+    echo '    proxy_set_header Connection upgrade;' >> $cryptpad_nginx_site
403
+    echo '  }' >> $cryptpad_nginx_site
404
+    echo '' >> $cryptpad_nginx_site
405
+
406
+    echo '  location ^~ /customize.dist/ {' >> $cryptpad_nginx_site
407
+    echo '    # This is needed in order to prevent infinite recursion between /customize/ and the root' >> $cryptpad_nginx_site
408
+    echo '  }' >> $cryptpad_nginx_site
409
+    echo '  location ^~ /customize/ {' >> $cryptpad_nginx_site
410
+    echo '    rewrite ^/customize/(.*)$ $1 break;' >> $cryptpad_nginx_site
411
+    echo '    try_files /customize/$uri /customize.dist/$uri;' >> $cryptpad_nginx_site
412
+    echo '  }' >> $cryptpad_nginx_site
413
+    echo '  location = /api/config {' >> $cryptpad_nginx_site
414
+    echo '    default_type text/javascript;' >> $cryptpad_nginx_site
415
+    echo '    rewrite ^.*$ /customize/api/config break;' >> $cryptpad_nginx_site
416
+    echo '  }' >> $cryptpad_nginx_site
417
+    echo '' >> $cryptpad_nginx_site
418
+    echo '  location ^~ /blob/ {' >> $cryptpad_nginx_site
419
+    echo '    try_files $uri =404;' >> $cryptpad_nginx_site
420
+    echo '  }' >> $cryptpad_nginx_site
421
+    echo '' >> $cryptpad_nginx_site
422
+    echo '  location ~ ^/(register|login|settings|user|pad|drive|poll|slide|code|whiteboard|file|media)$ {' >> $cryptpad_nginx_site
423
+    echo '    rewrite ^(.*)$ $1/ redirect;' >> $cryptpad_nginx_site
424
+    echo '  }' >> $cryptpad_nginx_site
425
+    echo '' >> $cryptpad_nginx_site
426
+    echo '  try_files $uri $uri/index.html /customize/$uri;' >> $cryptpad_nginx_site
427
+    echo '}' >> $cryptpad_nginx_site
428
+
429
+    sed -i 's|DENY;|SAMEORIGIN;|g' $cryptpad_nginx_site
430
+
431
+    function_check create_site_certificate
432
+    create_site_certificate $CRYPTPAD_DOMAIN_NAME 'yes'
433
+
434
+    function_check nginx_ensite
435
+    nginx_ensite $CRYPTPAD_DOMAIN_NAME
436
+
437
+    ${PROJECT_NAME}-pass -u $MY_USERNAME -a cryptpad -p "$CRYPTPAD_ADMIN_PASSWORD"
438
+
439
+    set_completion_param "cryptpad domain" "$CRYPTPAD_DOMAIN_NAME"
440
+
441
+    install_completed cryptpad_main
442
+}
443
+
444
+function install_cryptpad {
445
+    if [ ! $ONION_ONLY ]; then
446
+        ONION_ONLY='no'
447
+    fi
448
+
449
+    function_check install_nodejs
450
+    install_nodejs cryptpad
451
+
452
+    install_cryptpad_main
453
+
454
+    cd $CRYPTPAD_DIR
455
+
456
+    npm install
457
+    npm install -g bower
458
+    bower install
459
+    cp config.example.js config.js
460
+    if [ ! -f config.js ]; then
461
+        echo $'Cryptpad config file not found'
462
+        exit 628252
463
+    fi
464
+
465
+    sed -i "s|httpPort:.*|httpPort: $CRYPTPAD_PORT,|g" config.js
466
+    sed -i "s|websocketPath:.*|websocketPath: '/',|g" config.js
467
+    sed -i "s|// domain:|domain:|g" config.js
468
+    sed -i 's|openFileLimit:.*|openFileLimit: 1024,|g' config.js
469
+    if [[ $ONION_ONLY == 'no' ]]; then
470
+        sed -i "s|domain:.*|domain: 'https://$CRYPTPAD_DOMAIN_NAME',|g" config.js
471
+    else
472
+        sed -i "s|domain:.*|domain: 'https://$CRYPTPAD_ONION_HOSTNAME',|g" config.js
473
+    fi
474
+
475
+    chown -R cryptpad:cryptpad $CRYPTPAD_DIR
476
+
477
+    # daemon
478
+    echo '[Unit]' > /etc/systemd/system/cryptpad.service
479
+    echo 'Description=Cryptpad' >> /etc/systemd/system/cryptpad.service
480
+    echo 'After=syslog.target' >> /etc/systemd/system/cryptpad.service
481
+    echo 'After=network.target' >> /etc/systemd/system/cryptpad.service
482
+    echo '' >> /etc/systemd/system/cryptpad.service
483
+    echo '[Service]' >> /etc/systemd/system/cryptpad.service
484
+    echo 'Type=simple' >> /etc/systemd/system/cryptpad.service
485
+    echo 'User=cryptpad' >> /etc/systemd/system/cryptpad.service
486
+    echo 'Group=cryptpad' >> /etc/systemd/system/cryptpad.service
487
+    echo "WorkingDirectory=$CRYPTPAD_DIR" >> /etc/systemd/system/cryptpad.service
488
+    echo "ExecStart=/usr/local/bin/node ./server.js" >> /etc/systemd/system/cryptpad.service
489
+    echo 'Restart=on-failure' >> /etc/systemd/system/cryptpad.service
490
+    echo '' >> /etc/systemd/system/cryptpad.service
491
+    echo '[Install]' >> /etc/systemd/system/cryptpad.service
492
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/cryptpad.service
493
+    systemctl enable cryptpad.service
494
+    systemctl daemon-reload
495
+    systemctl start cryptpad.service
496
+
497
+    systemctl restart nginx
498
+
499
+    APP_INSTALLED=1
500
+}
501
+
502
+# NOTE: deliberately there is no "exit 0"

+ 16
- 7
src/freedombone-app-koel View File

@@ -323,6 +323,8 @@ function backup_local_koel {
323 323
 
324 324
     source_directory=/var/www/${KOEL_DOMAIN_NAME}/htdocs
325 325
     if [ -d $source_directory ]; then
326
+        systemctl stop koal
327
+
326 328
         dest_directory=koel
327 329
         function_check suspend_site
328 330
         suspend_site ${KOEL_DOMAIN_NAME}
@@ -335,6 +337,8 @@ function backup_local_koel {
335 337
 
336 338
         function_check restart_site
337 339
         restart_site
340
+
341
+        systemctl start koal
338 342
     fi
339 343
 }
340 344
 
@@ -345,6 +349,8 @@ function restore_local_koel {
345 349
     KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
346 350
     if [ $KOEL_DOMAIN_NAME ]; then
347 351
         echo $"Restoring koel"
352
+        systemctl stop koal
353
+
348 354
         temp_restore_dir=/root/tempkoel
349 355
         koel_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
350 356
 
@@ -355,6 +361,7 @@ function restore_local_koel {
355 361
         if [ -d $temp_restore_dir ]; then
356 362
             rm -rf $temp_restore_dir
357 363
         fi
364
+        systemctl start koal
358 365
     fi
359 366
 }
360 367
 
@@ -363,6 +370,8 @@ function backup_remote_koel {
363 370
         KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
364 371
         temp_backup_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
365 372
         if [ -d $temp_backup_dir ]; then
373
+            systemctl stop koal
374
+
366 375
             function_check suspend_site
367 376
             suspend_site ${KOEL_DOMAIN_NAME}
368 377
 
@@ -376,6 +385,8 @@ function backup_remote_koel {
376 385
 
377 386
             function_check restart_site
378 387
             restart_site
388
+
389
+            systemctl start koal
379 390
         else
380 391
             echo $"koel domain specified but not found in ${temp_backup_dir}"
381 392
         fi
@@ -385,11 +396,10 @@ function backup_remote_koel {
385 396
 function restore_remote_koel {
386 397
     if grep -q "koel domain" $COMPLETION_FILE; then
387 398
         echo $"Restoring koel"
388
-        KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
389 399
 
390
-        # stop the daemons
391
-        cd /var/www/${KOEL_DOMAIN_NAME}/htdocs
392
-        su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
400
+        systemctl stop koal
401
+
402
+        KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
393 403
 
394 404
         function_check koel_create_database
395 405
         koel_create_database
@@ -400,9 +410,8 @@ function restore_remote_koel {
400 410
             rm -rf /root/tempkoel
401 411
         fi
402 412
 
403
-        # start the daemons
404
-        cd /var/www/${KOEL_DOMAIN_NAME}/htdocs
405
-        su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data
413
+        systemctl start koal
414
+
406 415
         echo $"Restore of koel complete"
407 416
     fi
408 417
 }