Quellcode durchsuchen

Beginning of movim

Bob Mottram vor 8 Jahren
Ursprung
Commit
adc20c9e0c
1 geänderte Dateien mit 526 neuen und 0 gelöschten Zeilen
  1. 526
    0
      src/freedombone-app-movim

+ 526
- 0
src/freedombone-app-movim Datei anzeigen

@@ -0,0 +1,526 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# movim 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 chat'
32
+
33
+IN_DEFAULT_INSTALL=0
34
+SHOW_ON_ABOUT=1
35
+
36
+MOVIM_DOMAIN_NAME=
37
+MOVIM_CODE=
38
+MOVIM_ONION_PORT=8117
39
+MOVIM_REPO="https://github.com/movim/movim"
40
+MOVIM_COMMIT='add1a247804eb0e34fc28a74c2eeea16792ffa8e'
41
+MOVIM_ADMIN_PASSWORD=
42
+MOVIM_DAEMON_PORT=8081
43
+
44
+movim_variables=(ONION_ONLY
45
+                 MOVIM_DOMAIN_NAME
46
+                 MOVIM_CODE
47
+                 DDNS_PROVIDER
48
+                 MY_USERNAME)
49
+
50
+function remove_user_movim {
51
+    remove_username="$1"
52
+
53
+    ${PROJECT_NAME}-pass -u $remove_username --rmapp movim
54
+}
55
+
56
+function add_user_movim {
57
+    new_username="$1"
58
+    new_user_password="$2"
59
+
60
+    ${PROJECT_NAME}-pass -u $new_username -a movim -p "$new_user_password"
61
+    echo '0'
62
+}
63
+
64
+function install_interactive_movim {
65
+    if [ ! $ONION_ONLY ]; then
66
+        ONION_ONLY='no'
67
+    fi
68
+
69
+    if [[ $ONION_ONLY != "no" ]]; then
70
+        MOVIM_DOMAIN_NAME='movim.local'
71
+    else
72
+        MOVIM_DETAILS_COMPLETE=
73
+        while [ ! $MOVIM_DETAILS_COMPLETE ]
74
+        do
75
+            data=$(tempfile 2>/dev/null)
76
+            trap "rm -f $data" 0 1 2 5 15
77
+            if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
78
+                dialog --backtitle $"Freedombone Configuration" \
79
+                       --title $"Movim Configuration" \
80
+                       --form $"\nPlease enter your Movim details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
81
+                       $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
82
+                       $"Code:" 2 1 "$(grep 'MOVIM_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
83
+                       2> $data
84
+            else
85
+                dialog --backtitle $"Freedombone Configuration" \
86
+                       --title $"Movim Configuration" \
87
+                       --form $"\nPlease enter your Movim details.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 12 65 2 \
88
+                       $"Domain:" 1 1 "$(grep 'MOVIM_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
89
+                       2> $data
90
+            fi
91
+            sel=$?
92
+            case $sel in
93
+                1) exit 1;;
94
+                255) exit 1;;
95
+            esac
96
+            MOVIM_DOMAIN_NAME=$(cat $data | sed -n 1p)
97
+            if [ $MOVIM_DOMAIN_NAME ]; then
98
+                TEST_DOMAIN_NAME=$MOVIM_DOMAIN_NAME
99
+                validate_domain_name
100
+                if [[ $TEST_DOMAIN_NAME != $MOVIM_DOMAIN_NAME ]]; then
101
+                    MOVIM_DOMAIN_NAME=
102
+                    dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
103
+                else
104
+                    if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
105
+                        MOVIM_CODE=$(cat $data | sed -n 2p)
106
+                        validate_freedns_code "$MOVIM_CODE"
107
+                        if [ ! $VALID_CODE ]; then
108
+                            MOVIM_DOMAIN_NAME=
109
+                        fi
110
+                    fi
111
+                fi
112
+            fi
113
+            if [ $MOVIM_DOMAIN_NAME ]; then
114
+                MOVIM_DETAILS_COMPLETE="yes"
115
+            fi
116
+        done
117
+
118
+        # save the results in the config file
119
+        write_config_param "MOVIM_CODE" "$MOVIM_CODE"
120
+    fi
121
+    write_config_param "MOVIM_DOMAIN_NAME" "$MOVIM_DOMAIN_NAME"
122
+    APP_INSTALLED=1
123
+}
124
+
125
+function change_password_movim {
126
+    curr_username="$1"
127
+    new_user_password="$2"
128
+
129
+    read_config_param ${MOVIM_DOMAIN_NAME}
130
+
131
+    ${PROJECT_NAME}-pass -u "$curr_username" -a movim -p "$new_user_password"
132
+}
133
+
134
+function movim_create_database {
135
+    if [ -f $IMAGE_PASSWORD_FILE ]; then
136
+        MOVIM_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
137
+    else
138
+        if [ ! $MOVIM_ADMIN_PASSWORD ]; then
139
+            MOVIM_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
140
+        fi
141
+    fi
142
+    if [ ! $MOVIM_ADMIN_PASSWORD ]; then
143
+        return
144
+    fi
145
+
146
+    function_check create_database
147
+    create_database movim "$MOVIM_ADMIN_PASSWORD" $MY_USERNAME
148
+}
149
+
150
+function reconfigure_movim {
151
+    echo -n ''
152
+}
153
+
154
+function upgrade_movim {
155
+    if grep -q "movim domain" $COMPLETION_FILE; then
156
+        MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
157
+    fi
158
+
159
+    # update to the next commit
160
+    function_check set_repo_commit
161
+    set_repo_commit /var/www/$MOVIM_DOMAIN_NAME/htdocs "movim commit" "$MOVIM_COMMIT" $MOVIM_REPO
162
+
163
+    cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
164
+    php composer.phar install
165
+    chown -R www-data:www-data /var/www/${MOVIM_DOMAIN_NAME}/htdocs
166
+}
167
+
168
+
169
+function backup_local_movim {
170
+    MOVIM_DOMAIN_NAME='movim'
171
+    if grep -q "movim domain" $COMPLETION_FILE; then
172
+        MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
173
+    fi
174
+
175
+    source_directory=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
176
+    if [ -d $source_directory ]; then
177
+        dest_directory=movim
178
+        function_check suspend_site
179
+        suspend_site ${MOVIM_DOMAIN_NAME}
180
+
181
+        function_check backup_directory_to_usb
182
+        backup_directory_to_usb $source_directory $dest_directory
183
+
184
+        function_check backup_database_to_usb
185
+        backup_database_to_usb movim
186
+
187
+        function_check restart_site
188
+        restart_site
189
+    fi
190
+}
191
+
192
+function restore_local_movim {
193
+    if ! grep -q "movim domain" $COMPLETION_FILE; then
194
+        return
195
+    fi
196
+    MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
197
+    if [ $MOVIM_DOMAIN_NAME ]; then
198
+        echo $"Restoring movim"
199
+        temp_restore_dir=/root/tempmovim
200
+        movim_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
201
+        # stop the daemons
202
+        cd $movim_dir
203
+        su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
204
+
205
+        function_check movim_create_database
206
+        movim_create_database
207
+
208
+        restore_database movim ${MOVIM_DOMAIN_NAME}
209
+        if [ -d $temp_restore_dir ]; then
210
+            rm -rf $temp_restore_dir
211
+        fi
212
+
213
+        echo $"Restore of movim complete"
214
+    fi
215
+}
216
+
217
+function backup_remote_movim {
218
+    if grep -q "movim domain" $COMPLETION_FILE; then
219
+        MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
220
+        temp_backup_dir=/var/www/${MOVIM_DOMAIN_NAME}/htdocs
221
+        if [ -d $temp_backup_dir ]; then
222
+            function_check suspend_site
223
+            suspend_site ${MOVIM_DOMAIN_NAME}
224
+
225
+            function_check backup_database_to_friend
226
+            backup_database_to_friend movim
227
+
228
+            echo $"Backing up GNU social installation"
229
+
230
+            function_check backup_directory_to_friend
231
+            backup_directory_to_friend $temp_backup_dir movim
232
+
233
+            function_check restart_site
234
+            restart_site
235
+        else
236
+            echo $"movim domain specified but not found in ${temp_backup_dir}"
237
+        fi
238
+    fi
239
+}
240
+
241
+function restore_remote_movim {
242
+    if grep -q "movim domain" $COMPLETION_FILE; then
243
+        echo $"Restoring movim"
244
+        MOVIM_DOMAIN_NAME=$(get_completion_param "movim domain")
245
+
246
+        # stop the daemons
247
+        cd /var/www/${MOVIM_DOMAIN_NAME}/htdocs
248
+        su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
249
+
250
+        function_check movim_create_database
251
+        movim_create_database
252
+
253
+        function_check restore_database_from_friend
254
+        restore_database_from_friend movim ${MOVIM_DOMAIN_NAME}
255
+        if [ -d /root/tempmovim ]; then
256
+            rm -rf /root/tempmovim
257
+        fi
258
+        echo $"Restore of movim complete"
259
+    fi
260
+}
261
+
262
+function remove_movim {
263
+    read_config_param "MOVIM_DOMAIN_NAME"
264
+    if [ ${#MOVIM_DOMAIN_NAME} -eq 0 ]; then
265
+        return
266
+    fi
267
+
268
+    read_config_param "MY_USERNAME"
269
+    echo "Removing $MOVIM_DOMAIN_NAME"
270
+    nginx_dissite $MOVIM_DOMAIN_NAME
271
+    remove_certs $MOVIM_DOMAIN_NAME
272
+
273
+    if [ -d /var/www/$MOVIM_DOMAIN_NAME ]; then
274
+        rm -rf /var/www/$MOVIM_DOMAIN_NAME
275
+    fi
276
+    if [ -f /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME ]; then
277
+        rm /etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
278
+    fi
279
+    function_check drop_database
280
+    drop_database movim
281
+    function_check remove_onion_service
282
+    remove_onion_service movim ${MOVIM_ONION_PORT}
283
+    if grep -q "movim" /etc/crontab; then
284
+        sed -i "/movim/d" /etc/crontab
285
+    fi
286
+    remove_app movim
287
+    remove_completion_param install_movim
288
+    sed -i '/movim/d' $COMPLETION_FILE
289
+    remove_backup_database_local movim
290
+
291
+    function_check remove_ddns_domain
292
+    remove_ddns_domain $MOVIM_DOMAIN_NAME
293
+}
294
+
295
+function install_movim {
296
+    if [ ! $MOVIM_DOMAIN_NAME ]; then
297
+        echo $'No domain name was given for movim'
298
+        exit 72572
299
+    fi
300
+
301
+    movim_hourly_script movim $MOVIM_DOMAIN_NAME
302
+
303
+    function_check install_mariadb
304
+    install_mariadb
305
+
306
+    function_check get_mariadb_password
307
+    get_mariadb_password
308
+
309
+    function_check repair_databases_script
310
+    repair_databases_script
311
+
312
+    apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
313
+    apt-get -yq install php5-memcached php5-intl exiftool
314
+
315
+    if [ ! -d /var/www/$MOVIM_DOMAIN_NAME ]; then
316
+        mkdir /var/www/$MOVIM_DOMAIN_NAME
317
+    fi
318
+    if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
319
+        function_check git_clone
320
+        git_clone $MOVIM_REPO /var/www/$MOVIM_DOMAIN_NAME/htdocs
321
+        if [ ! -d /var/www/$MOVIM_DOMAIN_NAME/htdocs ]; then
322
+            echo $'Unable to clone movim repo'
323
+            exit 76285
324
+        fi
325
+    fi
326
+
327
+    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs
328
+    git checkout $MOVIM_COMMIT -b $MOVIM_COMMIT
329
+    set_completion_param "movim commit" "$MOVIM_COMMIT"
330
+
331
+    curl -sS https://getcomposer.org/installer | php
332
+    php composer.phar install
333
+
334
+    cd /var/www/$MOVIM_DOMAIN_NAME/htdocs/config
335
+    cp db.example.inc.php db.inc.php
336
+    sed -i "s|'username'.*|'username'    => 'root',|g" db.inc.php
337
+    sed -i "s|'password'.*|'password'    => '$MARIADB_PASSWORD',|g" db.inc.php
338
+    sed -i "s|'database'.*|'database'    => 'movim'|g" db.inc.php
339
+
340
+    chmod u+rwx /var/www/$MOVIM_DOMAIN_NAME/htdocs
341
+    chown -R www-data:www-data /var/www/$MOVIM_DOMAIN_NAME/htdocs
342
+
343
+    function_check movim_create_database
344
+    movim_create_database
345
+
346
+    function_check add_ddns_domain
347
+    add_ddns_domain $MOVIM_DOMAIN_NAME
348
+
349
+    MOVIM_ONION_HOSTNAME=$(add_onion_service movim 80 ${MOVIM_ONION_PORT})
350
+
351
+    echo '[Unit]' > /etc/systemd/system/movim.service
352
+    echo 'Description=Movim daemon' >> /etc/systemd/system/movim.service
353
+    echo 'After=network.target nginx.target' >> /etc/systemd/system/movim.service
354
+    echo '' >> /etc/systemd/system/movim.service
355
+    echo '[Service]' >> /etc/systemd/system/movim.service
356
+    echo 'Type=simple' >> /etc/systemd/system/movim.service
357
+    echo 'User=www-data' >> /etc/systemd/system/movim.service
358
+    echo "WorkingDirectory=/var/www/$MOVIM_DOMAIN_NAME/htdocs" >> /etc/systemd/system/movim.service
359
+    if [[ $ONION_ONLY == 'no' ]]; then
360
+        echo "ExecStart=/usr/bin/php /var/www/$MOVIM_DOMAIN_NAME/htdocs/daemon.php start --url=https://$MOVIM_DOMAIN_NAME --port=$MOVIM_DAEMON_PORT" >> /etc/systemd/system/movim.service
361
+    else
362
+        echo "ExecStart=/usr/bin/php /var/www/$MOVIM_DOMAIN_NAME/htdocs/daemon.php start --url=http://$MOVIM_ONION_HOSTNAME --port=$MOVIM_DAEMON_PORT" >> /etc/systemd/system/movim.service
363
+    fi
364
+    echo 'Restart=on-failure' >> /etc/systemd/system/movim.service
365
+    echo 'RestartSec=10' >> /etc/systemd/system/movim.service
366
+    echo '' >> /etc/systemd/system/movim.service
367
+    echo '[Install]' >> /etc/systemd/system/movim.service
368
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/movim.service
369
+    systemctl enable movim
370
+    systemctl daemon-reload
371
+
372
+    movim_nginx_site=/etc/nginx/sites-available/$MOVIM_DOMAIN_NAME
373
+    if [[ $ONION_ONLY == "no" ]]; then
374
+        function_check nginx_http_redirect
375
+        nginx_http_redirect $MOVIM_DOMAIN_NAME "index index.php"
376
+        echo 'server {' >> $movim_nginx_site
377
+        echo '  listen 443 ssl;' >> $movim_nginx_site
378
+        echo '  listen [::]:443 ssl;' >> $movim_nginx_site
379
+        echo "  server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
380
+        echo '' >> $movim_nginx_site
381
+        function_check nginx_compress
382
+        nginx_compress $MOVIM_DOMAIN_NAME
383
+        echo '' >> $movim_nginx_site
384
+        echo '  # Security' >> $movim_nginx_site
385
+        function_check nginx_ssl
386
+        nginx_ssl $MOVIM_DOMAIN_NAME
387
+
388
+        function_check nginx_disable_sniffing
389
+        nginx_disable_sniffing $MOVIM_DOMAIN_NAME
390
+
391
+        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $movim_nginx_site
392
+        echo '' >> $movim_nginx_site
393
+        echo '  # Logs' >> $movim_nginx_site
394
+        echo '  access_log /dev/null;' >> $movim_nginx_site
395
+        echo '  error_log /dev/null;' >> $movim_nginx_site
396
+        echo '' >> $movim_nginx_site
397
+        echo '  # Root' >> $movim_nginx_site
398
+        echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
399
+        echo '' >> $movim_nginx_site
400
+        echo '  # Index' >> $movim_nginx_site
401
+        echo '  index index.php;' >> $movim_nginx_site
402
+        echo '' >> $movim_nginx_site
403
+        echo '  # PHP' >> $movim_nginx_site
404
+        echo '  location ~ \.php {' >> $movim_nginx_site
405
+        echo '    include snippets/fastcgi-php.conf;' >> $movim_nginx_site
406
+        echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $movim_nginx_site
407
+        echo '  }' >> $movim_nginx_site
408
+        echo '' >> $movim_nginx_site
409
+        echo '  # Location' >> $movim_nginx_site
410
+        echo '  location / {' >> $movim_nginx_site
411
+        function_check nginx_limits
412
+        nginx_limits $MOVIM_DOMAIN_NAME '15m'
413
+        echo '    try_files $uri $uri/ @movim;' >> $movim_nginx_site
414
+        echo '  }' >> $movim_nginx_site
415
+        echo '' >> $movim_nginx_site
416
+        echo '  location /ws/ {' >> $movim_nginx_site
417
+        echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
418
+        echo '    proxy_http_version 1.1;' >> $movim_nginx_site
419
+        echo '    proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
420
+        echo '    proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
421
+        echo '    proxy_set_header Host $host;' >> $movim_nginx_site
422
+        echo '    proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
423
+        echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
424
+        echo '    proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
425
+        echo '    proxy_redirect off;' >> $movim_nginx_site
426
+        echo '  }' >> $movim_nginx_site
427
+        echo '' >> $movim_nginx_site
428
+        echo '  # Fancy URLs' >> $movim_nginx_site
429
+        echo '  location @movim {' >> $movim_nginx_site
430
+        echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
431
+        echo '  }' >> $movim_nginx_site
432
+        echo '' >> $movim_nginx_site
433
+        echo '  # Restrict access that is unnecessary anyway' >> $movim_nginx_site
434
+        echo '  location ~ /\.(ht|git) {' >> $movim_nginx_site
435
+        echo '    deny all;' >> $movim_nginx_site
436
+        echo '  }' >> $movim_nginx_site
437
+        echo '' >> $movim_nginx_site
438
+        echo '}' >> $movim_nginx_site
439
+    else
440
+        echo -n '' > $movim_nginx_site
441
+    fi
442
+    echo 'server {' >> $movim_nginx_site
443
+    echo "    listen 127.0.0.1:$MOVIM_ONION_PORT default_server;" >> $movim_nginx_site
444
+    echo "    server_name $MOVIM_DOMAIN_NAME;" >> $movim_nginx_site
445
+    echo '' >> $movim_nginx_site
446
+    function_check nginx_compress
447
+    nginx_compress $MOVIM_DOMAIN_NAME
448
+    echo '' >> $movim_nginx_site
449
+    function_check nginx_disable_sniffing
450
+    nginx_disable_sniffing $MOVIM_DOMAIN_NAME
451
+    echo '' >> $movim_nginx_site
452
+    echo '  # Logs' >> $movim_nginx_site
453
+    echo '  access_log /dev/null;' >> $movim_nginx_site
454
+    echo '  error_log /dev/null;' >> $movim_nginx_site
455
+    echo '' >> $movim_nginx_site
456
+    echo '  # Root' >> $movim_nginx_site
457
+    echo "  root /var/www/$MOVIM_DOMAIN_NAME/htdocs;" >> $movim_nginx_site
458
+    echo '' >> $movim_nginx_site
459
+    echo '  # Index' >> $movim_nginx_site
460
+    echo '  index index.php;' >> $movim_nginx_site
461
+    echo '' >> $movim_nginx_site
462
+    echo '  # PHP' >> $movim_nginx_site
463
+    echo '  location ~ \.php {' >> $movim_nginx_site
464
+    echo '    include snippets/fastcgi-php.conf;' >> $movim_nginx_site
465
+    echo '    fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $movim_nginx_site
466
+    echo '  }' >> $movim_nginx_site
467
+    echo '' >> $movim_nginx_site
468
+    echo '  # Location' >> $movim_nginx_site
469
+    echo '  location / {' >> $movim_nginx_site
470
+    function_check nginx_limits
471
+    nginx_limits $MOVIM_DOMAIN_NAME '15m'
472
+    echo '    try_files $uri $uri/ @movim;' >> $movim_nginx_site
473
+    echo '  }' >> $movim_nginx_site
474
+    echo '' >> $movim_nginx_site
475
+    echo '  location /ws/ {' >> $movim_nginx_site
476
+    echo "    proxy_pass http://localhost:${MOVIM_DAEMON_PORT}/;" >> $movim_nginx_site
477
+    echo '    proxy_http_version 1.1;' >> $movim_nginx_site
478
+    echo '    proxy_set_header Upgrade $http_upgrade;' >> $movim_nginx_site
479
+    echo '    proxy_set_header Connection "Upgrade";' >> $movim_nginx_site
480
+    echo '    proxy_set_header Host $host;' >> $movim_nginx_site
481
+    echo '    proxy_set_header X-Real-IP $remote_addr;' >> $movim_nginx_site
482
+    echo '    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;' >> $movim_nginx_site
483
+    echo '    proxy_set_header X-Forwarded-Proto https;' >> $movim_nginx_site
484
+    echo '    proxy_redirect off;' >> $movim_nginx_site
485
+    echo '  }' >> $movim_nginx_site
486
+    echo '' >> $movim_nginx_site
487
+    echo '  # Fancy URLs' >> $movim_nginx_site
488
+    echo '  location @movim {' >> $movim_nginx_site
489
+    echo '    rewrite ^(.*)$ /index.php?p=$1 last;' >> $movim_nginx_site
490
+    echo '  }' >> $movim_nginx_site
491
+    echo '' >> $movim_nginx_site
492
+    echo '  # Restrict access that is unnecessary anyway' >> $movim_nginx_site
493
+    echo '  location ~ /\.(ht|git) {' >> $movim_nginx_site
494
+    echo '    deny all;' >> $movim_nginx_site
495
+    echo '  }' >> $movim_nginx_site
496
+    echo '' >> $movim_nginx_site
497
+    echo '}' >> $movim_nginx_site
498
+
499
+    function_check configure_php
500
+    configure_php
501
+
502
+    function_check create_site_certificate
503
+    create_site_certificate $MOVIM_DOMAIN_NAME 'yes'
504
+
505
+    # Ensure that the database gets backed up locally, if remote
506
+    # backups are not being used
507
+    function_check backup_databases_script_header
508
+    backup_databases_script_header
509
+
510
+    function_check backup_database_local
511
+    backup_database_local movim
512
+
513
+    function_check nginx_ensite
514
+    nginx_ensite $MOVIM_DOMAIN_NAME
515
+
516
+    ${PROJECT_NAME}-pass -u $MY_USERNAME -a movim -p "$MOVIM_ADMIN_PASSWORD"
517
+
518
+    set_completion_param "movim domain" "$MOVIM_DOMAIN_NAME"
519
+
520
+    systemctl start movim
521
+    systemctl restart php5-fpm
522
+    systemctl restart nginx
523
+    APP_INSTALLED=1
524
+}
525
+
526
+# NOTE: deliberately there is no "exit 0"