Browse Source

Merge branch 'stretch' of https://github.com/bashrc/freedombone

Bob Mottram 7 years ago
parent
commit
988b881ef1

BIN
img/backgrounds/pleroma.jpg View File


+ 3
- 3
src/freedombone-app-gnusocial View File

@@ -232,7 +232,7 @@ function gnusocial_set_background_image {
232 232
             if [ ${#temp_background} -gt 0 ]; then
233 233
                 GNUSOCIAL_BACKGROUND_IMAGE_URL="$temp_background"
234 234
                 write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
235
-                if [[ $(pleroma_set_background_image_from_url "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE" | tail -n 1) == "0" ]]; then
235
+                if [[ $(pleroma_set_background_image_from_url /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE" | tail -n 1) == "0" ]]; then
236 236
                     dialog --title $"Set GNU Social login background" \
237 237
                            --msgbox $"The background image has been set" 6 60
238 238
                 fi
@@ -363,7 +363,7 @@ function upgrade_gnusocial {
363 363
 
364 364
     gnusocial_hourly_script gnusocial $GNUSOCIAL_DOMAIN_NAME
365 365
     if [ -d $INSTALL_DIR/pleroma ]; then
366
-        upgrade_pleroma "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
366
+        upgrade_pleroma_frontend "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
367 367
     fi
368 368
     install_gnusocial_default_background "gnusocial" "$GNUSOCIAL_DOMAIN_NAME"
369 369
     chown -R www-data:www-data /var/www/${GNUSOCIAL_DOMAIN_NAME}/htdocs
@@ -924,7 +924,7 @@ function install_gnusocial {
924 924
     gnusocial_use_qvitter gnusocial
925 925
 
926 926
     if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
927
-        pleroma_set_background_image_from_url "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
927
+        pleroma_set_background_image_from_url /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
928 928
     fi
929 929
 
930 930
     APP_INSTALLED=1

+ 782
- 0
src/freedombone-app-pleroma View File

@@ -0,0 +1,782 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# Pleroma backend application
12
+# https://git.pleroma.social/pleroma/pleroma/wikis/Installing-on-Debian-Based-Distributions
13
+#
14
+# License
15
+# =======
16
+#
17
+# Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
18
+#
19
+# This program is free software: you can redistribute it and/or modify
20
+# it under the terms of the GNU Affero General Public License as published by
21
+# the Free Software Foundation, either version 3 of the License, or
22
+# (at your option) any later version.
23
+#
24
+# This program is distributed in the hope that it will be useful,
25
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
+# GNU Affero General Public License for more details.
28
+#
29
+# You should have received a copy of the GNU Affero General Public License
30
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
31
+
32
+VARIANTS='full full-vim social'
33
+
34
+IN_DEFAULT_INSTALL=0
35
+SHOW_ON_ABOUT=1
36
+
37
+PLEROMA_DOMAIN_NAME=
38
+PLEROMA_CODE=
39
+PLEROMA_PORT=4000
40
+PLEROMA_ONION_PORT=8011
41
+PLEROMA_REPO="https://git.pleroma.social/pleroma/pleroma.git"
42
+PLEROMA_COMMIT='7252f6b054dfdfac1f9bac77c442c5a1ebd898af'
43
+PLEROMA_ADMIN_PASSWORD=
44
+PLEROMA_DIR=/etc/pleroma
45
+PLEROMA_SECRET_KEY=""
46
+
47
+PLEROMA_BACKGROUND_IMAGE_URL=
48
+
49
+PLEROMA_TITLE='Pleroma Server'
50
+
51
+# Number of months after which posts expire
52
+PLEROMA_EXPIRE_MONTHS=3
53
+
54
+pleroma_variables=(ONION_ONLY
55
+                   PLEROMA_DOMAIN_NAME
56
+                   PLEROMA_CODE
57
+                   PLEROMA_WELCOME_MESSAGE
58
+                   PLEROMA_BACKGROUND_IMAGE_URL
59
+                   DDNS_PROVIDER
60
+                   PLEROMA_TITLE
61
+                   PLEROMA_EXPIRE_MONTHS
62
+                   MY_EMAIL_ADDRESS
63
+                   MY_USERNAME)
64
+
65
+function pleroma_recompile {
66
+    # necessary after parameter changes
67
+    sudo -u pleroma mix clean
68
+    sudo -u pleroma mix deps.compile
69
+    sudo -u pleroma mix compile
70
+
71
+    if [ -f /etc/systemd/system/pleroma.service ]; then
72
+        systemctl restart pleroma
73
+    fi
74
+}
75
+
76
+function logging_on_pleroma {
77
+    echo -n ''
78
+}
79
+
80
+function logging_off_pleroma {
81
+    echo -n ''
82
+}
83
+
84
+function remove_user_pleroma {
85
+    remove_username="$1"
86
+
87
+    ${PROJECT_NAME}-pass -u $remove_username --rmapp pleroma
88
+}
89
+
90
+function add_user_pleroma {
91
+    new_username="$1"
92
+    new_user_password="$2"
93
+
94
+    ${PROJECT_NAME}-pass -u $new_username -a pleroma -p "$new_user_password"
95
+
96
+    echo '0'
97
+}
98
+
99
+function install_interactive_pleroma {
100
+    if [ ! $ONION_ONLY ]; then
101
+        ONION_ONLY='no'
102
+    fi
103
+
104
+    if [[ $ONION_ONLY != "no" ]]; then
105
+        PLEROMA_DOMAIN_NAME='pleroma.local'
106
+    else
107
+        PLEROMA_DETAILS_COMPLETE=
108
+        while [ ! $PLEROMA_DETAILS_COMPLETE ]
109
+        do
110
+            data=$(tempfile 2>/dev/null)
111
+            trap "rm -f $data" 0 1 2 5 15
112
+            if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
113
+                dialog --backtitle $"Freedombone Configuration" \
114
+                       --title $"Pleroma Configuration" \
115
+                       --form $"\nPlease enter your Pleroma 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 4 \
116
+                       $"Domain:" 1 1 "$(grep 'PLEROMA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
117
+                       $"Title:" 2 1 "$(grep '$PLEROMA_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
118
+                       $"Background image URL:" 3 1 "$(grep '$PLEROMA_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
119
+                       $"Code:" 4 1 "$(grep 'PLEROMA_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
120
+                       2> $data
121
+            else
122
+                dialog --backtitle $"Freedombone Configuration" \
123
+                       --title $"Pleroma Configuration" \
124
+                       --form $"\nPlease enter your Pleroma 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 4 \
125
+                       $"Domain:" 1 1 "$(grep 'PLEROMA_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
126
+                       $"Title:" 2 1 "$(grep '$PLEROMA_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
127
+                       $"Background image URL:" 3 1 "$(grep '$PLEROMA_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
128
+                       2> $data
129
+            fi
130
+            sel=$?
131
+            case $sel in
132
+                1) exit 1;;
133
+                255) exit 1;;
134
+            esac
135
+            PLEROMA_DOMAIN_NAME=$(cat $data | sed -n 1p)
136
+            title=$(cat $data | sed -n 2p)
137
+            if [ ${#title} -gt 1 ]; then
138
+                PLEROMA_TITLE=$welcome_msg
139
+            fi
140
+            img_url=$(cat $data | sed -n 3p)
141
+            if [ ${#img_url} -gt 1 ]; then
142
+                PLEROMA_BACKGROUND_IMAGE_URL=$img_url
143
+            fi
144
+            if [ $PLEROMA_DOMAIN_NAME ]; then
145
+                if [[ $PLEROMA_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
146
+                    PLEROMA_DOMAIN_NAME=""
147
+                fi
148
+                TEST_DOMAIN_NAME=$PLEROMA_DOMAIN_NAME
149
+                validate_domain_name
150
+                if [[ $TEST_DOMAIN_NAME != $PLEROMA_DOMAIN_NAME ]]; then
151
+                    PLEROMA_DOMAIN_NAME=
152
+                    dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
153
+                else
154
+                    if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
155
+                        PLEROMA_CODE=$(cat $data | sed -n 4p)
156
+                        validate_freedns_code "$PLEROMA_CODE"
157
+                        if [ ! $VALID_CODE ]; then
158
+                            PLEROMA_DOMAIN_NAME=
159
+                        fi
160
+                    fi
161
+                fi
162
+            fi
163
+            if [ $PLEROMA_DOMAIN_NAME ]; then
164
+                PLEROMA_DETAILS_COMPLETE="yes"
165
+            fi
166
+        done
167
+
168
+        # remove any invalid characters
169
+        if [ ${#PLEROMA_TITLE} -gt 0 ]; then
170
+            new_title=$(echo "$PLEROMA_TITLE" | sed "s|'||g")
171
+            PLEROMA_TITLE="$new_title"
172
+        fi
173
+
174
+        # save the results in the config file
175
+        write_config_param "PLEROMA_CODE" "$PLEROMA_CODE"
176
+        write_config_param "PLEROMA_TITLE" "$PLEROMA_TITLE"
177
+        write_config_param "PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_BACKGROUND_IMAGE_URL"
178
+    fi
179
+    write_config_param "PLEROMA_DOMAIN_NAME" "$PLEROMA_DOMAIN_NAME"
180
+    APP_INSTALLED=1
181
+}
182
+
183
+function change_password_pleroma {
184
+    curr_username="$1"
185
+    new_user_password="$2"
186
+
187
+    #${PROJECT_NAME}-pass -u "$curr_username" -a pleroma -p "$new_user_password"
188
+}
189
+
190
+function pleroma_create_database {
191
+    if [ -f $IMAGE_PASSWORD_FILE ]; then
192
+        PLEROMA_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
193
+    else
194
+        if [ ! $PLEROMA_ADMIN_PASSWORD ]; then
195
+            PLEROMA_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
196
+        fi
197
+    fi
198
+    if [ ! $PLEROMA_ADMIN_PASSWORD ]; then
199
+        return
200
+    fi
201
+
202
+    add_postgresql_user pleroma "$PLEROMA_ADMIN_PASSWORD" encrypted
203
+    run_system_query_postgresql "create database pleroma;"
204
+    # temporarily allow the user to create databases
205
+    run_system_query_postgresql "ALTER USER pleroma CREATEDB;"
206
+    run_system_query_postgresql "ALTER USER pleroma SUPERUSER;"
207
+    run_system_query_postgresql "GRANT ALL ON ALL tables IN SCHEMA public TO pleroma;"
208
+    run_system_query_postgresql "GRANT ALL ON ALL sequences IN SCHEMA public TO pleroma;"
209
+    run_system_query_postgresql "CREATE EXTENSION citext;"
210
+
211
+    read_config_param "PLEROMA_SECRET_KEY"
212
+    if [ ${#PLEROMA_SECRET_KEY} -lt 50 ]; then
213
+        PLEROMA_SECRET_KEY="$(create_password 30)$(create_password 30)"
214
+        if [ ${#PLEROMA_SECRET_KEY} -lt 50 ]; then
215
+            run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
216
+            run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
217
+            echo $'Pleroma secret key not created'
218
+            exit 6782352
219
+        fi
220
+        write_config_param "PLEROMA_SECRET_KEY" "$PLEROMA_SECRET_KEY"
221
+    fi
222
+
223
+    pleroma_secret=config/dev.secret.exs
224
+    cp config/dev.exs $pleroma_secret
225
+    sed -i "s|username:.*|username: \"pleroma\",|g" $pleroma_secret
226
+    sed -i "s|password:.*|password: \"$PLEROMA_ADMIN_PASSWORD\",|g" $pleroma_secret
227
+    sed -i "s|database:.*|database: \"pleroma\",|g" $pleroma_secret
228
+    sed -i "/Pleroma.Web.Endpoint/a secret_key_base: \"$PLEROMA_SECRET_KEY\"," $pleroma_secret
229
+    sed -i 's|secret_key_base: |  secret_key_base: |g' $pleroma_secret
230
+    sed -i "/Pleroma.Web.Endpoint/a pubsub: [name: Pleroma.Web.PubSub, adapter: Phoenix.PubSub.PG2]," $pleroma_secret
231
+    sed -i 's|pubsub: |  pubsub: |g' $pleroma_secret
232
+    sed -i 's|watchers: []|watchers: [],|g' $pleroma_secret
233
+    sed -i "/watchers: []/a url: [host: \"$PLEROMA_DOMAIN_NAME\", scheme: \"https\", port: 443]" $pleroma_secret
234
+    sed -i 's|url: |  url: |g' $pleroma_secret
235
+
236
+    cd $PLEROMA_DIR
237
+    chown -R pleroma:pleroma *
238
+    sudo -u pleroma mix local.rebar --force
239
+    if [ ! "$?" = "0" ]; then
240
+        run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
241
+        run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
242
+        echo $'mix local.rebar failed'
243
+        exit 73528562
244
+    fi
245
+    sudo -u pleroma mix local.hex --force
246
+    sudo -u pleroma mix deps.compile mimerl
247
+    sudo -u pleroma mix ecto.create --force
248
+    if [ ! "$?" = "0" ]; then
249
+        run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
250
+        run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
251
+        echo $'mix ecto.create failed'
252
+        exit 83653582
253
+    fi
254
+    sudo -u pleroma mix ecto.migrate --force
255
+    if [ ! "$?" = "0" ]; then
256
+        run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
257
+        run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
258
+        echo $'mix ecto.migrate failed'
259
+        exit 73752573
260
+    fi
261
+
262
+    # revoke the ability to create databases for this user
263
+    run_system_query_postgresql "ALTER USER pleroma NOSUPERUSER;"
264
+    run_system_query_postgresql "ALTER USER pleroma NOCREATEDB;"
265
+}
266
+
267
+function reconfigure_pleroma {
268
+    echo -n ''
269
+}
270
+
271
+function pleroma_set_background_image {
272
+    PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
273
+
274
+    data=$(tempfile 2>/dev/null)
275
+    trap "rm -f $data" 0 1 2 5 15
276
+    dialog --title $"Pleroma" \
277
+           --backtitle $"Freedombone Control Panel" \
278
+           --inputbox $'Set a background image URL' 10 60 2>$data
279
+    sel=$?
280
+    case $sel in
281
+        0)
282
+            temp_background=$(<$data)
283
+            if [ ${#temp_background} -gt 0 ]; then
284
+                PLEROMA_BACKGROUND_IMAGE_URL="$temp_background"
285
+                write_config_param "PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_BACKGROUND_IMAGE_URL"
286
+                if [[ $(pleroma_set_background_image_from_url $PLEROMA_DIR "$PLEROMA_DOMAIN_NAME" "$PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_TITLE" | tail -n 1) == "0" ]]; then
287
+                    pleroma_recompile
288
+                    dialog --title $"Set Pleroma login background" \
289
+                           --msgbox $"The background image has been set" 6 60
290
+                fi
291
+            fi
292
+           ;;
293
+    esac
294
+    rm $data
295
+}
296
+
297
+function pleroma_set_title {
298
+    data=$(tempfile 2>/dev/null)
299
+    trap "rm -f $data" 0 1 2 5 15
300
+    dialog --title $"Pleroma" \
301
+           --backtitle $"Freedombone Control Panel" \
302
+           --inputbox $'Set a title' 10 60 2>$data
303
+    sel=$?
304
+    case $sel in
305
+        0)
306
+            new_title=$(<$data)
307
+            if [ ${#new_title} -gt 0 ]; then
308
+                PLEROMA_TITLE="$new_title"
309
+                PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
310
+                write_config_param "PLEROMA_TITLE" "$PLEROMA_TITLE"
311
+                sed -i "s|\"name\":.*|\"name\": \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/static/config.json
312
+                sed -i "s|\"name\":.*|\"name\": \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/priv/static/static/config.json
313
+                sed -i "s|name: .*|name: \"${PLEROMA_TITLE}\",|g" $PLEROMA_DIR/config/config.exs
314
+                systemctl restart pleroma
315
+                dialog --title $"Set Pleroma title" \
316
+                       --msgbox $"The title has been set" 6 60
317
+            fi
318
+           ;;
319
+    esac
320
+    rm $data
321
+}
322
+
323
+function pleroma_set_expire_months {
324
+    PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
325
+    read_config_param "PLEROMA_EXPIRE_MONTHS"
326
+
327
+    data=$(tempfile 2>/dev/null)
328
+    trap "rm -f $data" 0 1 2 5 15
329
+    dialog --title $"Pleroma" \
330
+           --backtitle $"Freedombone Control Panel" \
331
+           --inputbox $'Set an expiry period for posts in months. Anything older will be deleted. Lower values help to keep the database size small and as fast as possible.' 12 60 "$PLEROMA_EXPIRE_MONTHS" 2>$data
332
+    sel=$?
333
+    case $sel in
334
+        0)
335
+            new_expiry_months=$(<$data)
336
+            if [ ${#new_expiry_months} -gt 0 ]; then
337
+                # should contain no spaces
338
+                if [[ "$new_expiry_months" == *" "* ]]; then
339
+                    return
340
+                fi
341
+                # should be a number
342
+                re='^[0-9]+$'
343
+                if ! [[ $new_expiry_months =~ $re ]] ; then
344
+                    return
345
+                fi
346
+                # set the new value
347
+                PLEROMA_EXPIRE_MONTHS=$new_expiry_months
348
+                write_config_param "PLEROMA_EXPIRE_MONTHS" "$PLEROMA_EXPIRE_MONTHS"
349
+
350
+                # TODO
351
+
352
+                dialog --title $"Set Pleroma post expiry period" \
353
+                       --msgbox $"Expiry period set to $PLEROMA_EXPIRE_MONTHS months" 6 60
354
+            fi
355
+           ;;
356
+    esac
357
+    rm $data
358
+}
359
+
360
+function pleroma_disable_registrations {
361
+    dialog --title $"Disable new Pleroma user registrations" \
362
+           --backtitle $"Freedombone Control Panel" \
363
+           --yesno $"\nDo you wish to disable new registrations?" 10 60
364
+    sel=$?
365
+    case $sel in
366
+        0) sed -i 's|registrations_open:.*|registrations_open: false|g' $PLEROMA_DIR/config/config.exs
367
+           sed -i 's|"registrationOpen":.*|"registrationOpen": false|g' $PLEROMA_DIR/priv/static/static/config.json
368
+           ;;
369
+        1) sed -i 's|registrations_open:.*|registrations_open: true|g' $PLEROMA_DIR/config/config.exs
370
+           sed -i 's|"registrationOpen":.*|"registrationOpen": true|g' $PLEROMA_DIR/priv/static/static/config.json
371
+           ;;
372
+        255) return;;
373
+    esac
374
+    pleroma_recompile
375
+}
376
+
377
+function configure_interactive_pleroma {
378
+    read_config_param PLEROMA_EXPIRE_MONTHS
379
+    while true
380
+    do
381
+        data=$(tempfile 2>/dev/null)
382
+        trap "rm -f $data" 0 1 2 5 15
383
+        dialog --backtitle $"Freedombone Control Panel" \
384
+               --title $"Pleroma" \
385
+               --radiolist $"Choose an operation:" 14 70 5 \
386
+               1 $"Set a background image" off \
387
+               2 $"Set the title" off \
388
+               3 $"Disable new account registrations" off \
389
+               4 $"Set post expiry period (currently $PLEROMA_EXPIRE_MONTHS months)" off \
390
+               5 $"Exit" on 2> $data
391
+        sel=$?
392
+        case $sel in
393
+            1) return;;
394
+            255) return;;
395
+        esac
396
+        case $(cat $data) in
397
+            1) pleroma_set_background_image;;
398
+            2) pleroma_set_title;;
399
+            3) pleroma_disable_registrations;;
400
+            4) pleroma_set_expire_months;;
401
+            5) break;;
402
+        esac
403
+        rm $data
404
+    done
405
+}
406
+
407
+function upgrade_pleroma {
408
+    CURR_PLEROMA_COMMIT=$(get_completion_param "pleroma commit")
409
+    if [[ "$CURR_PLEROMA_COMMIT" == "$PLEROMA_COMMIT" ]]; then
410
+        return
411
+    fi
412
+
413
+    function_check set_repo_commit
414
+    set_repo_commit $PLEROMA_DIR "pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
415
+    chown -R pleroma:pleroma $PLEROMA_DIR
416
+    pleroma_recompile
417
+}
418
+
419
+function backup_local_pleroma {
420
+    PLEROMA_DOMAIN_NAME='pleroma'
421
+    if grep -q "pleroma domain" $COMPLETION_FILE; then
422
+        PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
423
+    fi
424
+
425
+    function_check suspend_site
426
+    suspend_site ${PLEROMA_DOMAIN_NAME}
427
+
428
+    source_directory=$PLEROMA_DIR
429
+    dest_directory=pleroma
430
+    backup_directory_to_usb $source_directory $dest_directory
431
+
432
+    USE_POSTGRESQL=1
433
+    function_check backup_database_to_usb
434
+    backup_database_to_usb pleroma
435
+
436
+    function_check restart_site
437
+    restart_site
438
+}
439
+
440
+function restore_local_pleroma {
441
+    if ! grep -q "pleroma domain" $COMPLETION_FILE; then
442
+        return
443
+    fi
444
+    PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
445
+    if [ $PLEROMA_DOMAIN_NAME ]; then
446
+        echo $"Restoring pleroma"
447
+        temp_restore_dir=/root/temppleroma
448
+        pleroma_dir=$PLEROMA_DIR
449
+
450
+        function_check pleroma_create_database
451
+        pleroma_create_database
452
+
453
+        USE_POSTGRESQL=1
454
+        restore_database pleroma
455
+        if [ -d $temp_restore_dir ]; then
456
+            rm -rf $temp_restore_dir
457
+        fi
458
+
459
+        function_check restore_directory_from_usb
460
+        restore_directory_from_usb $temp_restore_dir pleroma
461
+        if [ -d $temp_restore_dir ]; then
462
+            chown -R pleroma:pleroma $pleroma_dir
463
+            rm -rf $temp_restore_dir
464
+        fi
465
+
466
+        echo $"Restore of pleroma complete"
467
+    fi
468
+}
469
+
470
+function backup_remote_pleroma {
471
+    PLEROMA_DOMAIN_NAME='pleroma'
472
+    if grep -q "pleroma domain" $COMPLETION_FILE; then
473
+        PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
474
+    fi
475
+
476
+    function_check suspend_site
477
+    suspend_site ${PLEROMA_DOMAIN_NAME}
478
+
479
+    source_directory=$PLEROMA_DIR
480
+    dest_directory=pleroma
481
+    backup_directory_to_friend $source_directory $dest_directory
482
+
483
+    USE_POSTGRESQL=1
484
+    function_check backup_database_to_friend
485
+    backup_database_to_friend pleroma
486
+
487
+    function_check restart_site
488
+    restart_site
489
+}
490
+
491
+function restore_remote_pleroma {
492
+    if ! grep -q "pleroma domain" $COMPLETION_FILE; then
493
+        return
494
+    fi
495
+    PLEROMA_DOMAIN_NAME=$(get_completion_param "pleroma domain")
496
+    if [ $PLEROMA_DOMAIN_NAME ]; then
497
+        echo $"Restoring pleroma"
498
+        temp_restore_dir=/root/temppleroma
499
+        pleroma_dir=$PLEROMA_DIR
500
+
501
+        function_check pleroma_create_database
502
+        pleroma_create_database
503
+
504
+        USE_POSTGRESQL=1
505
+        function_check restore_database_from_friend
506
+        restore_database_from_friend pleroma
507
+        if [ -d $temp_restore_dir ]; then
508
+            rm -rf $temp_restore_dir
509
+        fi
510
+
511
+        function_check restore_directory_from_friend
512
+        restore_directory_from_friend $temp_restore_dir pleroma
513
+        if [ -d $temp_restore_dir ]; then
514
+            chown -R pleroma:pleroma $pleroma_dir
515
+            rm -rf $temp_restore_dir
516
+        fi
517
+
518
+        pleroma_update_after_restore pleroma ${PLEROMA_DOMAIN_NAME}
519
+
520
+        echo $"Restore of pleroma complete"
521
+    fi
522
+}
523
+
524
+function remove_pleroma {
525
+    if [ ${#PLEROMA_DOMAIN_NAME} -eq 0 ]; then
526
+        return
527
+    fi
528
+    systemctl stop pleroma
529
+    systemctl disable pleroma
530
+    rm /etc/systemd/system/pleroma.service
531
+
532
+    userdel pleroma
533
+    apt-get -yq remove esl-erlang elixir erlang-xmerl erlang-dev erlang-parsetools
534
+
535
+    function_check remove_nodejs
536
+    remove_nodejs pleroma-backend
537
+
538
+    read_config_param "PLEROMA_DOMAIN_NAME"
539
+    read_config_param "MY_USERNAME"
540
+    echo "Removing $PLEROMA_DOMAIN_NAME"
541
+    nginx_dissite $PLEROMA_DOMAIN_NAME
542
+    remove_certs $PLEROMA_DOMAIN_NAME
543
+
544
+    if [ -d /var/www/$PLEROMA_DOMAIN_NAME ]; then
545
+        rm -rf /var/www/$PLEROMA_DOMAIN_NAME
546
+    fi
547
+    if [ -f /etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME ]; then
548
+        rm /etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME
549
+    fi
550
+    if [ -d $PLEROMA_DIR ]; then
551
+        rm -rf $PLEROMA_DIR
552
+    fi
553
+    function_check drop_database_postgresql
554
+    drop_database_postgresql pleroma
555
+    function_check remove_onion_service
556
+    remove_onion_service pleroma ${PLEROMA_ONION_PORT}
557
+    remove_app pleroma
558
+    remove_completion_param install_pleroma
559
+    sed -i '/pleroma domain/d' $COMPLETION_FILE
560
+    sed -i '/pleroma commit/d' $COMPLETION_FILE
561
+
562
+    function_check remove_ddns_domain
563
+    remove_ddns_domain $PLEROMA_DOMAIN_NAME
564
+}
565
+
566
+function install_elixir {
567
+    apt-get -yq install wget build-essential
568
+
569
+    if [ ! -d $INSTALL_DIR ]; then
570
+        mkdir -p $INSTALL_DIR
571
+    fi
572
+
573
+    cd $INSTALL_DIR
574
+    erlang_package=erlang-solutions_1.0_all.deb
575
+    wget https://packages.erlang-solutions.com/$erlang_package
576
+    if [ ! -f $INSTALL_DIR/$erlang_package ]; then
577
+        exit 72853
578
+    fi
579
+    dpkg -i $erlang_package
580
+    apt-get -yq update
581
+    apt-get -yq install esl-erlang
582
+    apt-get -yq install elixir erlang-xmerl erlang-dev erlang-parsetools
583
+
584
+    if [ ! -f /usr/local/bin/mix ]; then
585
+        echo $'/usr/local/bin/mix not found after elixir installation'
586
+        exit 629352
587
+    fi
588
+}
589
+
590
+function install_pleroma {
591
+    if [ ! $ONION_ONLY ]; then
592
+        ONION_ONLY='no'
593
+    fi
594
+
595
+    # We need elixir 1.4+ here, so the debian repo package won't do
596
+    install_elixir
597
+
598
+    function_check install_nodejs
599
+    install_nodejs pleroma-backend
600
+    install_postgresql
601
+
602
+    if [ ! -d /var/www/${PLEROMA_DOMAIN_NAME}/htdocs ]; then
603
+        mkdir -p /var/www/${PLEROMA_DOMAIN_NAME}/htdocs
604
+    fi
605
+    if [ -d $PLEROMA_DIR ]; then
606
+        rm -rf $PLEROMA_DIR
607
+    fi
608
+
609
+
610
+    # get the repo
611
+    if [ -f /repos/pleroma/index.html ]; then
612
+        mv /repos/pleroma /repos/pleroma-fe
613
+    fi
614
+    if [ -d /repos/pleroma ]; then
615
+        mkdir -p $PLEROMA_DIR
616
+        cp -r -p /repos/pleroma/. $PLEROMA_DIR
617
+        cd $PLEROMA_DIR
618
+        git pull
619
+    else
620
+        function_check git_clone
621
+        git_clone $PLEROMA_REPO $PLEROMA_DIR
622
+    fi
623
+
624
+    if [ ! -d $PLEROMA_DIR ]; then
625
+        echo $'Unable to clone pleroma backend repo'
626
+        exit 783523
627
+    fi
628
+
629
+
630
+    # create user
631
+    useradd -d $PLEROMA_DIR -s /bin/false pleroma
632
+
633
+
634
+    # checkout the commit
635
+    cd $PLEROMA_DIR
636
+    git checkout $PLEROMA_COMMIT -b $PLEROMA_COMMIT
637
+    set_completion_param "pleroma commit" "$PLEROMA_COMMIT"
638
+    chown -R pleroma:pleroma $PLEROMA_DIR
639
+
640
+
641
+    # web config
642
+    function_check add_ddns_domain
643
+    add_ddns_domain $PLEROMA_DOMAIN_NAME
644
+
645
+    PLEROMA_ONION_HOSTNAME=$(add_onion_service pleroma 80 ${PLEROMA_ONION_PORT})
646
+
647
+    pleroma_nginx_site=/etc/nginx/sites-available/$PLEROMA_DOMAIN_NAME
648
+    if [[ $ONION_ONLY == "no" ]]; then
649
+        function_check nginx_http_redirect
650
+        nginx_http_redirect $PLEROMA_DOMAIN_NAME "index index.html"
651
+        echo 'server {' >> $pleroma_nginx_site
652
+        echo '  listen 443 ssl;' >> $pleroma_nginx_site
653
+        echo '  listen [::]:443 ssl;' >> $pleroma_nginx_site
654
+        echo "  server_name $PLEROMA_DOMAIN_NAME;" >> $pleroma_nginx_site
655
+        echo '' >> $pleroma_nginx_site
656
+        function_check nginx_compress
657
+        nginx_compress $PLEROMA_DOMAIN_NAME
658
+        echo '' >> $pleroma_nginx_site
659
+        echo '  # Security' >> $pleroma_nginx_site
660
+        function_check nginx_ssl
661
+        nginx_ssl $PLEROMA_DOMAIN_NAME
662
+
663
+        function_check nginx_disable_sniffing
664
+        nginx_disable_sniffing $PLEROMA_DOMAIN_NAME
665
+
666
+        echo '  add_header Strict-Transport-Security max-age=15768000;' >> $pleroma_nginx_site
667
+        echo '' >> $pleroma_nginx_site
668
+        echo '  # Logs' >> $pleroma_nginx_site
669
+        echo '  access_log /dev/null;' >> $pleroma_nginx_site
670
+        echo '  error_log /dev/null;' >> $pleroma_nginx_site
671
+        echo '' >> $pleroma_nginx_site
672
+        echo "  root $PLEROMA_DIR;" >> $pleroma_nginx_site
673
+        echo '' >> $pleroma_nginx_site
674
+        echo '  index index.html;' >> $pleroma_nginx_site
675
+        echo '  location / {' >> $pleroma_nginx_site
676
+        function_check nginx_limits
677
+        nginx_limits $PLEROMA_DOMAIN_NAME '15m'
678
+        echo "    proxy_pass http://localhost:$PLEROMA_PORT;" >> $pleroma_nginx_site
679
+        echo '  }' >> $pleroma_nginx_site
680
+        echo '  # include snippets/well-known.conf;' >> $pleroma_nginx_site
681
+        echo '}' >> $pleroma_nginx_site
682
+    else
683
+        echo -n '' > $pleroma_nginx_site
684
+    fi
685
+    echo 'server {' >> $pleroma_nginx_site
686
+    echo "    listen 127.0.0.1:$PLEROMA_ONION_PORT default_server;" >> $pleroma_nginx_site
687
+    echo "    server_name $PLEROMA_ONION_HOSTNAME;" >> $pleroma_nginx_site
688
+    echo '' >> $pleroma_nginx_site
689
+    function_check nginx_compress
690
+    nginx_compress $PLEROMA_DOMAIN_NAME
691
+    echo '' >> $pleroma_nginx_site
692
+    function_check nginx_disable_sniffing
693
+    nginx_disable_sniffing $PLEROMA_DOMAIN_NAME
694
+    echo '' >> $pleroma_nginx_site
695
+    echo '  # Logs' >> $pleroma_nginx_site
696
+    echo '  access_log /dev/null;' >> $pleroma_nginx_site
697
+    echo '  error_log /dev/null;' >> $pleroma_nginx_site
698
+    echo '' >> $pleroma_nginx_site
699
+    echo "  root $PLEROMA_DIR;" >> $pleroma_nginx_site
700
+    echo '' >> $pleroma_nginx_site
701
+    echo '  index index.html;' >> $pleroma_nginx_site
702
+    echo '  location / {' >> $pleroma_nginx_site
703
+    function_check nginx_limits
704
+    nginx_limits $PLEROMA_DOMAIN_NAME '15m'
705
+    echo "    proxy_pass http://localhost:$PLEROMA_PORT;" >> $pleroma_nginx_site
706
+    echo '  }' >> $pleroma_nginx_site
707
+    echo '  # include snippets/well-known.conf;' >> $pleroma_nginx_site
708
+    echo '}' >> $pleroma_nginx_site
709
+
710
+
711
+    # back end
712
+    cd $PLEROMA_DIR
713
+    chown -R pleroma:pleroma *
714
+    sudo -u pleroma mix local.hex --force
715
+    if [ ! "$?" = "0" ]; then
716
+        echo $'mix local.hex failed'
717
+        exit 1745673
718
+    fi
719
+    sudo -u pleroma mix deps.get --force
720
+    if [ ! "$?" = "0" ]; then
721
+        echo $'mix deps.get failed'
722
+        exit 7325733
723
+    fi
724
+
725
+    function_check pleroma_create_database
726
+    pleroma_create_database
727
+
728
+    ${PROJECT_NAME}-pass -u $MY_USERNAME -a pleroma -p "$PLEROMA_ADMIN_PASSWORD"
729
+
730
+    # NOTE: we don't need to install the frontend separately,
731
+    # since the backend contains a precompiled version of it
732
+
733
+    install_gnusocial_default_background "pleroma" "$PLEROMA_DOMAIN_NAME"
734
+    if [ ! -f $PLEROMA_DIR/priv/static/static/config.json ]; then
735
+        echo $"$PLEROMA_DIR/priv/static/static/config.json file missing"
736
+        exit 323689
737
+    fi
738
+    sed -i 's|"theme":.*|"theme": "base16-summerfruit-dark.css",|g' $PLEROMA_DIR/priv/static/static/config.json
739
+
740
+    if [ $PLEROMA_BACKGROUND_IMAGE_URL ]; then
741
+        pleroma_set_background_image_from_url $PLEROMA_DIR/priv/static "$PLEROMA_DOMAIN_NAME" "$PLEROMA_BACKGROUND_IMAGE_URL" "$PLEROMA_TITLE"
742
+    fi
743
+
744
+
745
+    # Get certificate
746
+    function_check create_site_certificate
747
+    create_site_certificate $PLEROMA_DOMAIN_NAME 'yes'
748
+
749
+    function_check nginx_ensite
750
+    nginx_ensite $PLEROMA_DOMAIN_NAME
751
+
752
+    systemctl restart postgresql
753
+    systemctl restart nginx
754
+
755
+    set_completion_param "pleroma domain" "$PLEROMA_DOMAIN_NAME"
756
+
757
+
758
+    # daemon
759
+    echo '[Unit]' > /etc/systemd/system/pleroma.service
760
+    echo 'Description=Pleroma social network' >> /etc/systemd/system/pleroma.service
761
+    echo 'After=network.target postgresql.service' >> /etc/systemd/system/pleroma.service
762
+    echo '' >> /etc/systemd/system/pleroma.service
763
+    echo '[Service]' >> /etc/systemd/system/pleroma.service
764
+    echo 'User=pleroma' >> /etc/systemd/system/pleroma.service
765
+    echo "WorkingDirectory=$PLEROMA_DIR" >> /etc/systemd/system/pleroma.service
766
+    echo "Environment=\"HOME=$PLEROMA_DIR\"" >> /etc/systemd/system/pleroma.service
767
+    echo 'ExecStart=/usr/local/bin/mix phx.server' >> /etc/systemd/system/pleroma.service
768
+    echo 'ExecReload=/bin/kill $MAINPID' >> /etc/systemd/system/pleroma.service
769
+    echo 'KillMode=process' >> /etc/systemd/system/pleroma.service
770
+    echo 'Restart=on-failure' >> /etc/systemd/system/pleroma.service
771
+    echo '' >> /etc/systemd/system/pleroma.service
772
+    echo '[Install]' >> /etc/systemd/system/pleroma.service
773
+    echo 'WantedBy=multi-user.target' >> /etc/systemd/system/pleroma.service
774
+    echo 'Alias=pleroma.service' >> /etc/systemd/system/pleroma.service
775
+    systemctl daemon-reload
776
+    systemctl enable pleroma
777
+    systemctl start pleroma
778
+
779
+    APP_INSTALLED=1
780
+}
781
+
782
+# NOTE: deliberately there is no "exit 0"

+ 3
- 3
src/freedombone-app-postactiv View File

@@ -248,7 +248,7 @@ function postactiv_set_background_image {
248 248
                 POSTACTIV_BACKGROUND_IMAGE_URL="$temp_background"
249 249
                 write_config_param "POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_BACKGROUND_IMAGE_URL"
250 250
 
251
-                if [[ $(pleroma_set_background_image_from_url "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE" | tail -n 1) == "0" ]]; then
251
+                if [[ $(pleroma_set_background_image_from_url /var/www/$POSTACTIV_DOMAIN_NAME/htdocs "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE" | tail -n 1) == "0" ]]; then
252 252
                     dialog --title $"Set PostActiv background" \
253 253
                            --msgbox $"The background image has been set" 6 60
254 254
                 fi
@@ -378,7 +378,7 @@ function upgrade_postactiv {
378 378
     gnusocial_block_user_script
379 379
     gnusocial_block_domain_script postactiv "$POSTACTIV_DOMAIN_NAME"
380 380
 
381
-    upgrade_pleroma "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
381
+    upgrade_pleroma_frontend "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
382 382
     postactiv_customise_logo
383 383
     install_gnusocial_default_background "postactiv" "$POSTACTIV_DOMAIN_NAME"
384 384
     chown -R www-data:www-data /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
@@ -945,7 +945,7 @@ function install_postactiv {
945 945
     gnusocial_use_qvitter postactiv
946 946
 
947 947
     if [ $POSTACTIV_BACKGROUND_IMAGE_URL ]; then
948
-        pleroma_set_background_image_from_url "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
948
+        pleroma_set_background_image_from_url /var/www/$POSTACTIV_DOMAIN_NAME/htdocs "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
949 949
     fi
950 950
 
951 951
     APP_INSTALLED=1

+ 6
- 0
src/freedombone-app-vpn View File

@@ -59,11 +59,17 @@ vpn_variables=(MY_EMAIL_ADDRESS
59 59
                VPN_TLS_PORT)
60 60
 
61 61
 function logging_on_vpn {
62
+    if [ ! -f /etc/openvpn/server.conf ]; then
63
+        return
64
+    fi
62 65
     sed -i 's|status .*|status /var/log/openvpn.log|g' /etc/openvpn/server.conf
63 66
     systemctl restart openvpn
64 67
 }
65 68
 
66 69
 function logging_off_vpn {
70
+    if [ ! -f /etc/openvpn/server.conf ]; then
71
+        return
72
+    fi
67 73
     sed -i 's|status .*|status /dev/null|g' /etc/openvpn/server.conf
68 74
     systemctl restart openvpn
69 75
 }

+ 23
- 0
src/freedombone-backup-local View File

@@ -337,6 +337,28 @@ function backup_mariadb {
337 337
     fi
338 338
 }
339 339
 
340
+function backup_postgresql {
341
+    if [ ! -d /etc/postgresql ]; then
342
+        return
343
+    fi
344
+
345
+    temp_backup_dir=/root/temppostgresql
346
+    if [ ! -d $temp_backup_dir ]; then
347
+        mkdir $temp_backup_dir
348
+    fi
349
+    sudo -u postgres pg_dumpall --roles-only > $temp_backup_dir/postgresql.sql
350
+    if [ ! -s $temp_backup_dir/postgresql.sql ]; then
351
+        echo $"Unable to backup postgresql settings"
352
+        rm -rf $temp_backup_dir
353
+        umount $USB_MOUNT
354
+        rm -rf $USB_MOUNT
355
+        exit 684365
356
+    fi
357
+    echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
358
+    chmod 400 $temp_backup_dir/db
359
+    backup_directory_to_usb $temp_backup_dir postgresql
360
+}
361
+
340 362
 # has the remove option been set ?
341 363
 remove_option=$2
342 364
 if [[ $1 == "remove" ]]; then
@@ -355,6 +377,7 @@ backup_configfiles
355 377
 backup_blocklist
356 378
 backup_admin_readme
357 379
 backup_mariadb
380
+backup_postgresql
358 381
 backup_extra_directories local
359 382
 backup_unmount_drive $USB_DRIVE $USB_MOUNT
360 383
 echo $"Backup to USB drive is complete. You can now unplug it."

+ 23
- 0
src/freedombone-backup-remote View File

@@ -336,6 +336,28 @@ function backup_mariadb {
336 336
     fi
337 337
 }
338 338
 
339
+function backup_postgresql {
340
+    if [ ! -d /etc/postgresql ]; then
341
+        return
342
+    fi
343
+
344
+    temp_backup_dir=/root/temppostgresql
345
+    if [ ! -d $temp_backup_dir ]; then
346
+        mkdir $temp_backup_dir
347
+    fi
348
+    sudo -u postgres pg_dumpall --roles-only > $temp_backup_dir/postgresql.sql
349
+    if [ ! -s $temp_backup_dir/postgresql.sql ]; then
350
+        echo $"Unable to backup postgresql settings"
351
+        rm -rf $temp_backup_dir
352
+        umount $USB_MOUNT
353
+        rm -rf $USB_MOUNT
354
+        exit 684365
355
+    fi
356
+    echo "$DATABASE_PASSWORD" > $temp_backup_dir/db
357
+    chmod 400 $temp_backup_dir/db
358
+    backup_directory_to_friend $temp_backup_dir postgresql
359
+}
360
+
339 361
 # Returns the filename of a key share
340 362
 function get_key_share {
341 363
     no_of_shares=$1
@@ -410,6 +432,7 @@ if [[ $TEST_MODE == "no" ]]; then
410 432
     backup_web_server
411 433
     backup_admin_readme
412 434
     backup_mariadb
435
+    backup_postgresql
413 436
     backup_certs
414 437
     backup_mailing_list
415 438
     backup_apps remote

+ 1
- 0
src/freedombone-controlpanel View File

@@ -1084,6 +1084,7 @@ function restore_data_from_storage {
1084 1084
     utils_installed=(configfiles
1085 1085
                      blocklist
1086 1086
                      mariadb
1087
+                     postgresql
1087 1088
                      letsencrypt
1088 1089
                      passwords
1089 1090
                      mutt

+ 11
- 3
src/freedombone-image-customise View File

@@ -1553,18 +1553,25 @@ function image_preinstall_repos {
1553 1553
     git clone $INADYN_REPO $rootdir/repos/inadyn
1554 1554
     git clone $TOMB_REPO $rootdir/repos/tomb
1555 1555
 
1556
+    if [[ $SOCIALINSTANCE == "pleroma" ]]; then
1557
+        git clone $PLEROMA_REPO $rootdir/repos/pleroma
1558
+        #git clone $QVITTER_THEME_REPO $rootdir/repos/qvitter
1559
+        git clone $PLEROMA_FRONTEND_REPO $rootdir/repos/pleroma-fe
1560
+        return
1561
+    fi
1562
+
1556 1563
     if [[ $SOCIALINSTANCE == "gnusocial" ]]; then
1557 1564
         git clone $GNUSOCIAL_REPO $rootdir/repos/gnusocial
1558 1565
         git clone $GNUSOCIAL_MARKDOWN_REPO $rootdir/repos/gnusocial-markdown
1559 1566
         #git clone $QVITTER_THEME_REPO $rootdir/repos/qvitter
1560
-        git clone $PLEROMA_REPO $rootdir/repos/pleroma
1567
+        git clone $PLEROMA_FRONTEND_REPO $rootdir/repos/pleroma-fe
1561 1568
         return
1562 1569
     fi
1563 1570
 
1564 1571
     if [[ $SOCIALINSTANCE == "postactiv" ]]; then
1565 1572
         git clone $GNUSOCIAL_MARKDOWN_REPO $rootdir/repos/gnusocial-markdown
1566 1573
         #git clone $QVITTER_THEME_REPO $rootdir/repos/qvitter
1567
-        git clone $PLEROMA_REPO $rootdir/repos/pleroma
1574
+        git clone $PLEROMA_FRONTEND_REPO $rootdir/repos/pleroma-fe
1568 1575
         #git clone $POSTACTIV_REPO $rootdir/repos/postactiv
1569 1576
         return
1570 1577
     fi
@@ -1574,9 +1581,10 @@ function image_preinstall_repos {
1574 1581
     git clone $ETHERPAD_REPO $rootdir/repos/etherpad
1575 1582
     git clone $FRIENDICA_REPO $rootdir/repos/friendica
1576 1583
     git clone $GNUSOCIAL_REPO $rootdir/repos/gnusocial
1584
+    git clone $PLEROMA_REPO $rootdir/repos/pleroma
1577 1585
     git clone $GNUSOCIAL_MARKDOWN_REPO $rootdir/repos/gnusocial-markdown
1578 1586
     #git clone $QVITTER_THEME_REPO $rootdir/repos/qvitter
1579
-    git clone $PLEROMA_REPO $rootdir/repos/pleroma
1587
+    git clone $PLEROMA_FRONTEND_REPO $rootdir/repos/pleroma-fe
1580 1588
     #git clone $POSTACTIV_REPO $rootdir/repos/postactiv
1581 1589
     git clone $SHARINGS_REPO $rootdir/repos/sharings
1582 1590
     git clone $HTMLY_REPO $rootdir/repos/htmly

+ 54
- 0
src/freedombone-restore-local View File

@@ -289,6 +289,59 @@ function restore_mariadb {
289 289
     fi
290 290
 }
291 291
 
292
+function restore_postgresql {
293
+    if [[ $RESTORE_APP != 'all' ]]; then
294
+        if [[ $RESTORE_APP != 'postgresql' ]]; then
295
+            return
296
+        fi
297
+    fi
298
+
299
+    if [[ $(is_completed install_postgresql) == "0" ]]; then
300
+        function_check install_postgresql
301
+        install_postgresql
302
+    fi
303
+
304
+    if [ -d $USB_MOUNT/backup/postgresql ]; then
305
+        echo $"Restoring postgresql settings"
306
+        temp_restore_dir=/root/temppostgresql
307
+        restore_directory_from_usb $temp_restore_dir postgresql
308
+
309
+        store_original_postgresql_password
310
+
311
+        echo $'Obtaining original postgresql password'
312
+        db_pass=$(cat /root/.postgresqloriginal)
313
+        if [ ${#db_pass} -gt 0 ]; then
314
+            echo $"Restore the postgresql user table"
315
+            if [ -d ${temp_restore_dir}${temp_restore_dir} ]; then
316
+                mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}${temp_restore_dir}/postgresql.sql)
317
+            else
318
+                mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
319
+            fi
320
+            if [ ! "$?" = "0" ]; then
321
+                echo $"Try again using the password obtained from backup"
322
+                db_pass=$(${PROJECT_NAME}-pass -u root -a postgresql)
323
+                if [ -d ${temp_restore_dir}${temp_restore_dir} ]; then
324
+                    mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}${temp_restore_dir}/postgresql.sql)
325
+                else
326
+                    mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
327
+                fi
328
+            fi
329
+            if [ ! "$?" = "0" ]; then
330
+                echo "$mysqlsuccess"
331
+                set_user_permissions
332
+                backup_unmount_drive
333
+                exit 73825
334
+            fi
335
+            echo $"Restarting database"
336
+            systemctl restart postgresql
337
+            echo $"Ensure postgresql handles authentication"
338
+            POSTGRESQL_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
339
+            DATABASE_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
340
+        fi
341
+        rm -rf $temp_restore_dir
342
+    fi
343
+}
344
+
292 345
 function restore_letsencrypt {
293 346
     if [[ $RESTORE_APP != 'all' ]]; then
294 347
         if [[ $RESTORE_APP != 'letsencrypt' ]]; then
@@ -865,6 +918,7 @@ restore_configfiles
865 918
 same_admin_user
866 919
 restore_passwordstore
867 920
 restore_mariadb
921
+restore_postgresql
868 922
 restore_letsencrypt
869 923
 restore_tor
870 924
 restore_mutt_settings

+ 51
- 0
src/freedombone-restore-remote View File

@@ -255,6 +255,56 @@ function restore_mariadb {
255 255
     fi
256 256
 }
257 257
 
258
+function restore_postgresql {
259
+    if [[ $RESTORE_APP != 'all' ]]; then
260
+        if [[ $RESTORE_APP != 'postgresql' ]]; then
261
+            return
262
+        fi
263
+    fi
264
+
265
+    if [[ $(is_completed install_postgresql) == "0" ]]; then
266
+        function_check install_postgresql
267
+        install_postgresql
268
+    fi
269
+
270
+    if [ -d $SERVER_DIRECTORY/backup/postgresql ]; then
271
+        echo $"Restoring Postgresql settings"
272
+        temp_restore_dir=/root/temppostgresql
273
+        restore_directory_from_friend $temp_restore_dir postgresql
274
+
275
+        store_original_postgresql_password
276
+
277
+        echo $'Obtaining Postgresql password'
278
+        db_pass=$(cat /root/.postgresqloriginal)
279
+        if [ ${#db_pass} -gt 0 ]; then
280
+            echo $"Restore the Postgresql user table"
281
+            if [ -d ${temp_restore_dir}${temp_restore_dir} ]; then
282
+                mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}${temp_restore_dir}/postgresql.sql)
283
+            else
284
+                mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
285
+            fi
286
+            if [ ! "$?" = "0" ]; then
287
+                echo $"Try again using the password obtained from backup"
288
+                db_pass=$(${PROJECT_NAME}-pass -u root -a postgresql)
289
+                if [ -d ${temp_restore_dir}${temp_restore_dir} ]; then
290
+                    mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}${temp_restore_dir}/postgresql.sql)
291
+                else
292
+                    mysqlsuccess=$(sudo -u postgres pg_restore ${temp_restore_dir}/postgresql.sql)
293
+                fi
294
+            fi
295
+            if [ ! "$?" = "0" ]; then
296
+                echo "$mysqlsuccess"
297
+                exit 962
298
+            fi
299
+            echo $"Restarting database"
300
+            systemctl restart postgresql
301
+            echo $"Ensure postgresql handles authentication"
302
+            POSTGRESQL_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
303
+        fi
304
+        rm -rf ${temp_restore_dir}
305
+    fi
306
+}
307
+
258 308
 function restore_letsencrypt {
259 309
     if [[ $RESTORE_APP != 'all' ]]; then
260 310
         if [[ $RESTORE_APP != 'letsencrypt' ]]; then
@@ -769,6 +819,7 @@ restore_blocklist
769 819
 restore_configfiles
770 820
 restore_passwordstore
771 821
 restore_mariadb
822
+restore_postgresql
772 823
 restore_letsencrypt
773 824
 restore_mutt_settings
774 825
 restore_gpg

+ 30
- 8
src/freedombone-utils-backup View File

@@ -235,9 +235,14 @@ function backup_database_local_usb {
235 235
     if [ ! -d ${local_database_dir} ]; then
236 236
         mkdir -p ${local_database_dir}
237 237
     fi
238
-    keep_database_running
239 238
     echo $"Obtaining ${1} database backup"
240
-    mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > ${local_database_dir}/${1}.sql
239
+    if [ ! $USE_POSTGRESQL ]; then
240
+        keep_database_running
241
+        mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > ${local_database_dir}/${1}.sql
242
+    else
243
+        USE_POSTGRESQL=
244
+        sudo -u postgres pg_dump ${1} > ${local_database_dir}/${1}.sql
245
+    fi
241 246
     if [ -f ${local_database_dir}/${1}.sql ]; then
242 247
         if [ ! -s ${local_database_dir}/${1}.sql ]; then
243 248
             echo $"${1} database could not be saved"
@@ -545,9 +550,16 @@ function backup_database_remote {
545 550
     if [ ! -d ${local_database_dir} ]; then
546 551
         mkdir -p ${local_database_dir}
547 552
     fi
548
-    keep_database_running
553
+
549 554
     echo "Obtaining ${1} database backup"
550
-    mysqldump --password="$DATABASE_PASSWORD" ${1} > ${local_database_dir}/${1}.sql
555
+    if [ ! $USE_POSTGRESQL ]; then
556
+        keep_database_running
557
+        mysqldump --lock-tables --password="$DATABASE_PASSWORD" ${1} > ${local_database_dir}/${1}.sql
558
+    else
559
+        USE_POSTGRESQL=
560
+        sudo -u postgres pg_dump ${1} > ${local_database_dir}/${1}.sql
561
+    fi
562
+
551 563
     if [ -f ${local_database_dir}/${1}.sql ]; then
552 564
         if [ ! -s ${local_database_dir}/${1}.sql ]; then
553 565
             echo $"${1} database could not be saved"
@@ -642,8 +654,13 @@ function restore_database_from_friend {
642 654
             rm -rf ${local_database_dir}
643 655
             exit 503
644 656
         fi
645
-        keep_database_running
646
-        mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < ${local_database_dir}/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
657
+        if [ ! $USE_POSTGRESQL ]; then
658
+            keep_database_running
659
+            mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${1} -o < ${local_database_dir}/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
660
+        else
661
+            USE_POSTGRESQL=
662
+            mysqlsuccess=$(sudo -u postgres pg_restore ${local_database_dir}/${RESTORE_SUBDIR}/temp${1}data/${1}.sql)
663
+        fi
647 664
         if [ ! "$?" = "0" ]; then
648 665
             echo "$mysqlsuccess"
649 666
             exit 964
@@ -721,8 +738,13 @@ function restore_database {
721 738
             backup_unmount_drive
722 739
             exit 503
723 740
         fi
724
-        keep_database_running
725
-        mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${restore_app_name} -o < $database_file)
741
+        if [ ! $USE_POSTGRESQL ]; then
742
+            keep_database_running
743
+            mysqlsuccess=$(mysql -u root --password="$DATABASE_PASSWORD" ${restore_app_name} -o < $database_file)
744
+        else
745
+            USE_POSTGRESQL=
746
+            mysqlsuccess=$(sudo -u postgres pg_restore $database_file)
747
+        fi
726 748
         if [ ! "$?" = "0" ]; then
727 749
             echo "$mysqlsuccess"
728 750
             function_check set_user_permissions

+ 82
- 46
src/freedombone-utils-gnusocialtools View File

@@ -32,8 +32,8 @@
32 32
 QVITTER_THEME_REPO="https://github.com/bashrc/Qvitter"
33 33
 QVITTER_THEME_COMMIT='c6f09bda4e45be4290cf7409fa5efb4420538032'
34 34
 
35
-PLEROMA_REPO="https://gitgud.io/lambadalambda/pleroma-fe"
36
-PLEROMA_COMMIT='cbe652f2d94d81fa54a37378b7ff014c4391ca5e'
35
+PLEROMA_FRONTEND_REPO="https://gitgud.io/lambadalambda/pleroma-fe"
36
+PLEROMA_FRONTEND_COMMIT='cbe652f2d94d81fa54a37378b7ff014c4391ca5e'
37 37
 
38 38
 SHARINGS_REPO="http://github.com/bashrc/Sharings"
39 39
 SHARINGS_COMMIT='0d30fe7d153c7ab44e8459970b8f2b5dec06e43c'
@@ -88,9 +88,10 @@ function qvitter_update_background {
88 88
 }
89 89
 
90 90
 function pleroma_set_background_image_from_url {
91
-    domain_name="$1"
92
-    url="$2"
93
-    title="$3"
91
+    basedir="$1"
92
+    domain_name="$2"
93
+    url="$3"
94
+    title="$4"
94 95
 
95 96
     if [ ${#domain_name} -eq 0 ]; then
96 97
         echo "1"
@@ -111,7 +112,7 @@ function pleroma_set_background_image_from_url {
111 112
     fi
112 113
 
113 114
     if [ ${#ext} -gt 0 ]; then
114
-        cd /var/www/${domain_name}/htdocs
115
+        cd $basedir
115 116
 
116 117
         # remove any existing image
117 118
         if [ -f bg_custom.${ext} ]; then
@@ -127,13 +128,20 @@ function pleroma_set_background_image_from_url {
127 128
             return
128 129
         fi
129 130
 
130
-        if [ -d /var/www/${domain_name}/htdocs/static ]; then
131
+        if [ -d $basedir/static ]; then
131 132
             cp bg_custom.${ext} static/bg_custom.${ext}
132 133
             chown www-data:www-data static/bg_custom.${ext}
133 134
             sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" static/config.json
134 135
         fi
136
+        if [ -d priv/static/static ]; then
137
+            cp bg_custom.${ext} priv/static/static/bg_custom.${ext}
138
+            chown www-data:www-data priv/static/static/bg_custom.${ext}
139
+            sed -i "s|\"background\":.*|\"background\": \"/static/bg_custom.${ext}\",|g" priv/static/static/config.json
140
+        fi
135 141
 
136
-        qvitter_update_background ${domain_name} ${ext}
142
+        if [[ "$basedir" != $PLEROMA_DIR ]]; then
143
+            qvitter_update_background ${domain_name} ${ext}
144
+        fi
137 145
 
138 146
         rm bg_custom.${ext}
139 147
     else
@@ -142,19 +150,28 @@ function pleroma_set_background_image_from_url {
142 150
     fi
143 151
 
144 152
     # customise the logo
145
-    if [ -f /var/www/${domain_name}/htdocs/static/logo.png ]; then
153
+    if [ -f $basedir/static/logo.png ]; then
146 154
         if [ -f ~/freedombone/img/logo_fbone3.png ]; then
147
-            cp ~/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/static/logo.png
155
+            cp ~/freedombone/img/logo_fbone3.png $basedir/static/logo.png
156
+            if [ -d $basedir/priv/static/static ]; then
157
+                cp ~/freedombone/img/logo_fbone3.png $basedir/priv/static/static/logo.png
158
+            fi
148 159
         else
149 160
             if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then
150
-                cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/static/logo.png
161
+                cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png $basedir/static/logo.png
162
+                if [ -d $basedir/priv/static/static ]; then
163
+                    cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png $basedir/priv/static/static/logo.png
164
+                fi
151 165
             fi
152 166
         fi
153 167
     fi
154 168
 
155 169
     # customise the title
156
-    if [ -f /var/www/${domain_name}/htdocs/static/config.json ]; then
157
-        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" /var/www/${domain_name}/htdocs/static/config.json
170
+    if [ -f $basedir/static/config.json ]; then
171
+        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" $basedir/static/config.json
172
+    fi
173
+    if [ -f $basedir/priv/static/static/config.json ]; then
174
+        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" $basedir/priv/static/static/config.json
158 175
     fi
159 176
 
160 177
     echo "0"
@@ -251,26 +268,31 @@ function install_gnusocial_default_background {
251 268
     gnusocial_type=$1
252 269
     domain_name=$2
253 270
 
271
+    basedir=/var/www/${domain_name}/htdocs
272
+    if [[ "$gnusocial_type" == 'pleroma' ]]; then
273
+        basedir=$PLEROMA_DIR/priv/static
274
+    fi
275
+
254 276
     # customise the logo
255
-    if [ -f /var/www/${domain_name}/htdocs/static/logo.png ]; then
277
+    if [ -f $basedir/static/logo.png ]; then
256 278
         if [ -f ~/freedombone/img/logo_fbone3.png ]; then
257
-            cp ~/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/static/logo.png
279
+            cp ~/freedombone/img/logo_fbone3.png $basedir/static/logo.png
258 280
         else
259 281
             if [ -f /home/$MY_USERNAME/freedombone/img/logo_fbone3.png ]; then
260
-                cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png /var/www/${domain_name}/htdocs/static/logo.png
282
+                cp /home/$MY_USERNAME/freedombone/img/logo_fbone3.png $basedir/static/logo.png
261 283
             fi
262 284
         fi
263 285
     fi
264 286
 
265
-    if [ ! -f /var/www/${domain_name}/htdocs/static/bg.jpg ]; then
287
+    if [ ! -f $basedir/static/bg.jpg ]; then
266 288
         return
267 289
     fi
268 290
 
269 291
     if [ -f ~/freedombone/img/backgrounds/${gnusocial_type}.jpg ]; then
270
-        cp ~/freedombone/img/backgrounds/${gnusocial_type}.jpg /var/www/${domain_name}/htdocs/static/bg.jpg
292
+        cp ~/freedombone/img/backgrounds/${gnusocial_type}.jpg $basedir/static/bg.jpg
271 293
     else
272 294
         if [ -f /home/$MY_USERNAME/freedombone/img/backgrounds/${gnusocial_type}.jpg ]; then
273
-            cp /home/$MY_USERNAME/freedombone/img/backgrounds/${gnusocial_type}.jpg /var/www/${domain_name}/htdocs/static/bg.jpg
295
+            cp /home/$MY_USERNAME/freedombone/img/backgrounds/${gnusocial_type}.jpg $basedir/static/bg.jpg
274 296
         fi
275 297
     fi
276 298
 }
@@ -284,14 +306,14 @@ function install_pleroma_front_end {
284 306
 
285 307
     if [ ! -d $INSTALL_DIR/pleroma ]; then
286 308
 
287
-        if [ -d /repos/pleroma ]; then
309
+        if [ -d /repos/pleroma-fe ]; then
288 310
             mkdir -p $INSTALL_DIR/pleroma
289
-            cp -r -p /repos/pleroma/. $INSTALL_DIR/pleroma
311
+            cp -r -p /repos/pleroma-fe/. $INSTALL_DIR/pleroma
290 312
             cd $INSTALL_DIR/pleroma
291 313
             git pull
292 314
         else
293 315
             function_check git_clone
294
-            git_clone $PLEROMA_REPO $INSTALL_DIR/pleroma
316
+            git_clone $PLEROMA_FRONTEND_REPO $INSTALL_DIR/pleroma
295 317
         fi
296 318
 
297 319
         if [ ! -d $INSTALL_DIR/pleroma ]; then
@@ -301,8 +323,8 @@ function install_pleroma_front_end {
301 323
     fi
302 324
 
303 325
     cd $INSTALL_DIR/pleroma
304
-    git checkout $PLEROMA_COMMIT -b $PLEROMA_COMMIT
305
-    set_completion_param "${app_name} pleroma commit" "$PLEROMA_COMMIT"
326
+    git checkout $PLEROMA_FRONTEND_COMMIT -b $PLEROMA_FRONTEND_COMMIT
327
+    set_completion_param "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT"
306 328
 
307 329
     if [ -d $INSTALL_DIR/pleroma/node_modules ]; then
308 330
         rm -rf $INSTALL_DIR/pleroma/node_modules
@@ -328,9 +350,14 @@ function install_pleroma_front_end {
328 350
         exit 5282682
329 351
     fi
330 352
 
331
-    cp -r $INSTALL_DIR/pleroma/dist/* /var/www/${pleroma_domain}/htdocs/
353
+    if [[ "$app_name" != 'pleroma' ]]; then
354
+        cp -r $INSTALL_DIR/pleroma/dist/* /var/www/${pleroma_domain}/htdocs/
355
+        pleroma_set_background_image_from_url /var/www/${pleroma_domain}/htdocs "$pleroma_domain" "$background_url" "$title"
356
+    else
357
+        cp -r $INSTALL_DIR/pleroma/dist/* $PLEROMA_DIR/priv/static
358
+        pleroma_set_background_image_from_url $PLEROMA_DIR/priv/static "$pleroma_domain" "$background_url" "$title"
359
+    fi
332 360
 
333
-    pleroma_set_background_image_from_url "$pleroma_domain" "$background_url" "$title"
334 361
 
335 362
     nginx_site=/etc/nginx/sites-available/${pleroma_domain}
336 363
     sed -i 's|index index.php;|index index.html;|g' $nginx_site
@@ -345,17 +372,21 @@ function install_pleroma_front_end {
345 372
         rm -rf /root/.cache/yarn
346 373
     fi
347 374
 
348
-    chown -R www-data:www-data /var/www/${pleroma_domain}/htdocs
375
+    if [[ "$app_name" != 'pleroma' ]]; then
376
+        chown -R www-data:www-data /var/www/${pleroma_domain}/htdocs
377
+    else
378
+        chown -R pleroma:pleroma $PLEROMA_DIR
379
+    fi
349 380
 }
350 381
 
351
-function upgrade_pleroma {
382
+function upgrade_pleroma_frontend {
352 383
     domain_name="$1"
353 384
     app_name="$2"
354 385
     background_url="$3"
355 386
     title="$4"
356 387
 
357 388
     if [ -d $INSTALL_DIR/pleroma ]; then
358
-        set_repo_commit $INSTALL_DIR/pleroma "${app_name} pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
389
+        set_repo_commit $INSTALL_DIR/pleroma "${app_name} pleroma commit" "$PLEROMA_FRONTEND_COMMIT" $PLEROMA_FRONTEND_REPO
359 390
         cd $INSTALL_DIR/pleroma
360 391
         yarn
361 392
         npm run build
@@ -363,31 +394,36 @@ function upgrade_pleroma {
363 394
             echo 'Unable to build pleroma'
364 395
             exit 268362
365 396
         fi
366
-        if [ -f /var/www/${domain_name}/htdocs/static/logo.png ]; then
367
-            cp /var/www/${domain_name}/htdocs/static/logo.png /var/www/${domain_name}/htdocs/static/logo.png.old
397
+
398
+        basedir=/var/www/${domain_name}/htdocs
399
+        if [[ "$app_name" == 'pleroma' ]]; then
400
+            basedir=$PLEROMA_DIR/priv/static
401
+        fi
402
+        if [ -f $basedir/static/logo.png ]; then
403
+            cp $basedir/static/logo.png $basedir/static/logo.png.old
368 404
         fi
369
-        if [ -f /var/www/${domain_name}/htdocs/static/bg.jpg ]; then
370
-            cp /var/www/${domain_name}/htdocs/static/bg.jpg /var/www/${domain_name}/htdocs/static/bg.jpg.old
405
+        if [ -f $basedir/static/bg.jpg ]; then
406
+            cp $basedir/static/bg.jpg $basedir/static/bg.jpg.old
371 407
         fi
372
-        if [ -f /var/www/${domain_name}/htdocs/static/config.json ]; then
373
-            cp /var/www/${domain_name}/htdocs/static/config.json /var/www/${domain_name}/htdocs/static/config.json.old
408
+        if [ -f $basedir/static/config.json ]; then
409
+            cp $basedir/static/config.json $basedir/static/config.json.old
374 410
         fi
375
-        cp -r $INSTALL_DIR/pleroma/dist/* /var/www/${domain_name}/htdocs/
376
-        if [ -f /var/www/${domain_name}/htdocs/static/config.json.old ]; then
377
-            mv /var/www/${domain_name}/htdocs/static/config.json.old /var/www/${domain_name}/htdocs/static/config.json
411
+        cp -r $INSTALL_DIR/pleroma/dist/* $basedir/
412
+        if [ -f $basedir/static/config.json.old ]; then
413
+            mv $basedir/static/config.json.old $basedir/static/config.json
378 414
         fi
379
-        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" /var/www/${domain_name}/htdocs/static/config.json
380
-        if [ -f /var/www/${domain_name}/htdocs/static/logo.png.old ]; then
381
-            cp /var/www/${domain_name}/htdocs/static/logo.png.old /var/www/${domain_name}/htdocs/static/logo.png
415
+        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" $basedir/static/config.json
416
+        if [ -f $basedir/static/logo.png.old ]; then
417
+            cp $basedir/static/logo.png.old $basedir/static/logo.png
382 418
         fi
383
-        if [ -f /var/www/${domain_name}/htdocs/static/bg.jpg.old ]; then
384
-            cp /var/www/${domain_name}/htdocs/static/bg.jpg.old /var/www/${domain_name}/htdocs/static/bg.jpg
419
+        if [ -f $basedir/static/bg.jpg.old ]; then
420
+            cp $basedir/static/bg.jpg.old $basedir/static/bg.jpg
385 421
         fi
386 422
 
387
-        if [ -f /var/www/${domain_name}/htdocs/index.php ]; then
388
-            mv /var/www/${domain_name}/htdocs/index.php /var/www/${domain_name}/htdocs/index_qvitter.php
423
+        if [ -f $basedir/index.php ]; then
424
+            mv $basedir/index.php $basedir/index_qvitter.php
389 425
         fi
390
-        chown -R www-data:www-data /var/www/${domain_name}/htdocs
426
+        chown -R www-data:www-data $basedir
391 427
     else
392 428
         install_pleroma_front_end "${app_name}" "${domain_name}" "${background_url}" "${title}"
393 429
     fi

+ 158
- 0
src/freedombone-utils-postgresql View File

@@ -0,0 +1,158 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# postgresql database functions
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
+# Set this when calling backup and restore commands
32
+USE_POSTGRESQL=
33
+
34
+function store_original_postgresql_password {
35
+    if [ ! -f /root/.postgresqloriginal ]; then
36
+        echo $'Storing original postgresql password'
37
+        ORIGINAL_POSTGRESQL_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
38
+        # We can store this in plaintext because it will soon be of historical interest only
39
+        echo -n "$ORIGINAL_POSTGRESQL_PASSWORD" > /root/.postgresqloriginal
40
+    fi
41
+}
42
+
43
+function get_postgresql_password {
44
+    POSTGRESQL_PASSWORD=$(${PROJECT_NAME}-pass -u root -a postgresql)
45
+    if [[ "$POSTGRESQL_PASSWORD" == *'failed'* ]]; then
46
+        echo $'Could not obtain postgresql password'
47
+        exit 7835272
48
+    fi
49
+}
50
+
51
+function install_postgresql {
52
+    if [[ $(is_completed $FUNCNAME) == "1" ]]; then
53
+        return
54
+    fi
55
+
56
+    function_check get_postgresql_password
57
+    get_postgresql_password
58
+    if [ ! $POSTGRESQL_PASSWORD ]; then
59
+        if [ -f $IMAGE_PASSWORD_FILE ]; then
60
+            POSTGRESQL_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
61
+        else
62
+            POSTGRESQL_PASSWORD="$(openssl rand -base64 32 | cut -c1-${MINIMUM_PASSWORD_LENGTH})"
63
+        fi
64
+    fi
65
+    ${PROJECT_NAME}-pass -u root -a postgresql -p "$POSTGRESQL_PASSWORD"
66
+
67
+    apt-get -yq install postgresql postgresql-contrib postgresql-client
68
+    apt-get -yq remove --purge apache2-bin*
69
+    if [ -d /etc/apache2 ]; then
70
+        rm -rf /etc/apache2
71
+        echo $'Removed Apache installation after postgresql install'
72
+    fi
73
+
74
+    if [ ! -d /etc/postgresql ]; then
75
+        echo $"ERROR: postgresql does not appear to have installed. $CHECK_MESSAGE"
76
+        exit 78352
77
+    fi
78
+
79
+    if [ ! -f /usr/bin/psql ]; then
80
+        echo $"ERROR: psql command does not appear to have installed. $CHECK_MESSAGE"
81
+        exit 835290
82
+    fi
83
+
84
+    mark_completed $FUNCNAME
85
+}
86
+
87
+function add_postgresql_user {
88
+    postgresql_username=$1
89
+    postgresql_password=$2
90
+    if [[ "$3" != 'encrypt'* ]]; then
91
+        sudo -u postgres psql -c "create user $postgresql_username password '$postgresql_password';"
92
+    else
93
+        sudo -u postgres psql -c "create user $postgresql_username;"
94
+        sudo -u postgres psql -c "ALTER user $postgresql_username with encrypted password '$postgresql_password';"
95
+    fi
96
+}
97
+
98
+function remove_postgresql_user {
99
+    postgresql_username=$1
100
+    sudo -u postgres psql -c "drop user $postgresql_username"
101
+}
102
+
103
+function drop_database_postgresql {
104
+    database_name="$1"
105
+    sudo -u postgres psql -c "drop database $database_name"
106
+}
107
+
108
+function run_system_query_postgresql {
109
+    query=$1
110
+    sudo -u postgres psql -c "$query"
111
+}
112
+
113
+function run_query_postgresql {
114
+    database_name=$1
115
+    database_query=$2
116
+    sudo -u postgres psql -d $database_name -c "$database_query"
117
+}
118
+
119
+function run_query_postgresql_with_output {
120
+    database_name=$1
121
+    database_query=$2
122
+    output=$(sudo -u postgres psql -d $database_name -c << EOF
123
+use $database_name;
124
+$database_query
125
+EOF
126
+)
127
+    echo "$output"
128
+}
129
+
130
+function initialise_database_postgresql {
131
+    database_name=$1
132
+    database_file=$2
133
+    sudo -u postgres psql $database_name < $database_file
134
+    if [ ! "$?" = "0" ]; then
135
+        exit 7238525
136
+    fi
137
+}
138
+
139
+function create_database_postgresql {
140
+    app_name="$1"
141
+    app_admin_password="$2"
142
+    app_admin_username=$3
143
+    if [ ! -d $INSTALL_DIR ]; then
144
+        mkdir $INSTALL_DIR
145
+    fi
146
+    if [ ! $app_admin_username ]; then
147
+        app_admin_username=${app_name}admin
148
+    fi
149
+
150
+    echo "create database ${app_name};
151
+CREATE USER '$app_admin_username@localhost' IDENTIFIED BY '${app_admin_password}';
152
+GRANT ALL PRIVILEGES ON ${app_name}.* TO '$app_admin_username@localhost';
153
+flush privileges;
154
+quit" > $INSTALL_DIR/batch.sql
155
+    chmod 600 $INSTALL_DIR/batch.sql
156
+    sudo -u postgres psql -d $database_name --file=$INSTALL_DIR/batch.sql
157
+    shred -zu $INSTALL_DIR/batch.sql
158
+}