Parcourir la source

Move gnusocial web UI to pleroma

Note that qvitter is still needed, but may be deprecated later
Bob Mottram il y a 8 ans
Parent
révision
094151d82e
2 fichiers modifiés avec 255 ajouts et 160 suppressions
  1. 40
    160
      src/freedombone-app-gnusocial
  2. 215
    0
      src/freedombone-utils-gnusocialtools

+ 40
- 160
src/freedombone-app-gnusocial Voir le fichier

@@ -39,9 +39,7 @@ GNUSOCIAL_ONION_PORT=8087
39 39
 GNUSOCIAL_REPO="https://git.gnu.io/gnu/gnu-social.git"
40 40
 GNUSOCIAL_COMMIT='7d67eefdf501f492e29f59971ac288e0414dc5b0'
41 41
 GNUSOCIAL_ADMIN_PASSWORD=
42
-GNUSOCIAL_THEME_REPO="https://git.gnu.io/h2p/Qvitter.git"
43
-GNUSOCIAL_THEME_COMMIT='a7f82628402db3a7579bb9b2877da3c5737da77b'
44
-GNUSOCIAL_WELCOME_MESSAGE=$'<h1>Welcome to GNU Social – a federated social metwork</h1><p>Another Freedombone site</p>'
42
+
45 43
 GNUSOCIAL_BACKGROUND_IMAGE_URL=
46 44
 GNUSOCIAL_MARKDOWN_REPO="https://git.gnu.io/chimo/markdown.git"
47 45
 GNUSOCIAL_MARKDOWN_COMMIT='03c53942f94b3376f0946e6e1fe566cc21ccf232'
@@ -59,6 +57,8 @@ GNUSOCIAL_NSFW_COMMIT='a096bbe0cfae9a9b177682920ffb58d32a48e136'
59 57
 # script which causes old posts to expire
60 58
 gnusocial_expire_script=/usr/bin/gnusocial-expire
61 59
 
60
+GNUSOCIAL_TITLE='Pleroma FE'
61
+
62 62
 gnusocial_variables=(ONION_ONLY
63 63
                      GNUSOCIAL_DOMAIN_NAME
64 64
                      GNUSOCIAL_CODE
@@ -71,6 +71,7 @@ gnusocial_variables=(ONION_ONLY
71 71
                      SHARINGS_COMMIT
72 72
                      SHARINGS_THEME_REPO
73 73
                      SHARINGS_THEME_COMMIT
74
+                     GNUSOCIAL_TITLE
74 75
                      MY_USERNAME)
75 76
 
76 77
 function gnusocial_fix_endless_reloads {
@@ -125,18 +126,18 @@ function install_interactive_gnusocial {
125 126
             if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
126 127
                 dialog --backtitle $"Freedombone Configuration" \
127 128
                        --title $"GNU Social Configuration" \
128
-                       --form $"\nPlease enter your GNU Social details. Welcome message and 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 \
129
+                       --form $"\nPlease enter your GNU Social 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 \
129 130
                        $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
130
-                       $"Welcome Message:" 2 1 "$(grep '$GNUSOCIAL_WELCOME_MESSAGE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
131
+                       $"Totle:" 2 1 "$(grep '$GNUSOCIAL_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
131 132
                        $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
132 133
                        $"Code:" 4 1 "$(grep 'GNUSOCIAL_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
133 134
                        2> $data
134 135
             else
135 136
                 dialog --backtitle $"Freedombone Configuration" \
136 137
                        --title $"GNU Social Configuration" \
137
-                       --form $"\nPlease enter your GNU Social details. Welcome message and 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 \
138
+                       --form $"\nPlease enter your GNU Social 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 \
138 139
                        $"Domain:" 1 1 "$(grep 'GNUSOCIAL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
139
-                       $"Welcome Message:" 2 1 "$(grep '$GNUSOCIAL_WELCOME_MESSAGE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
140
+                       $"Title:" 2 1 "$(grep '$GNUSOCIAL_TITLE' temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
140 141
                        $"Background image URL:" 3 1 "$(grep '$GNUSOCIAL_BACKGROUND_IMAGE_URL' temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
141 142
                        2> $data
142 143
             fi
@@ -146,9 +147,9 @@ function install_interactive_gnusocial {
146 147
                 255) exit 1;;
147 148
             esac
148 149
             GNUSOCIAL_DOMAIN_NAME=$(cat $data | sed -n 1p)
149
-            welcome_msg=$(cat $data | sed -n 2p)
150
-            if [ ${#welcome_msg} -gt 1 ]; then
151
-                GNUSOCIAL_WELCOME_MESSAGE=$welcome_msg
150
+            title=$(cat $data | sed -n 2p)
151
+            if [ ${#title} -gt 1 ]; then
152
+                GNUSOCIAL_TITLE=$welcome_msg
152 153
             fi
153 154
             img_url=$(cat $data | sed -n 3p)
154 155
             if [ ${#img_url} -gt 1 ]; then
@@ -179,14 +180,14 @@ function install_interactive_gnusocial {
179 180
         done
180 181
 
181 182
         # remove any invalid characters
182
-        if [ ${#GNUSOCIAL_WELCOME_MESSAGE} -gt 0 ]; then
183
-            new_welcome=$(echo "$GNUSOCIAL_WELCOME_MESSAGE" | sed "s|'||g")
184
-            GNUSOCIAL_WELCOME_MESSAGE="$new_welcome"
183
+        if [ ${#GNUSOCIAL_TITLE} -gt 0 ]; then
184
+            new_title=$(echo "$GNUSOCIAL_TITLE" | sed "s|'||g")
185
+            GNUSOCIAL_TITLE="$new_title"
185 186
         fi
186 187
 
187 188
         # save the results in the config file
188 189
         write_config_param "GNUSOCIAL_CODE" "$GNUSOCIAL_CODE"
189
-        write_config_param "GNUSOCIAL_WELCOME_MESSAGE" "$GNUSOCIAL_WELCOME_MESSAGE"
190
+        write_config_param "GNUSOCIAL_TITLE" "$GNUSOCIAL_TITLE"
190 191
         write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
191 192
     fi
192 193
     write_config_param "GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_DOMAIN_NAME"
@@ -240,42 +241,6 @@ function reconfigure_gnusocial {
240 241
     echo -n ''
241 242
 }
242 243
 
243
-function gnusocial_set_background_image_from_url {
244
-    GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT=
245
-    if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
246
-        if [[ $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".jpeg" || $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".jpg" ]]; then
247
-            GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="jpg"
248
-        fi
249
-        if [[ $GNUSOCIAL_BACKGROUND_IMAGE_URL == *".png" ]]; then
250
-            GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="png"
251
-        fi
252
-        if [[ $$GNUSOCIAL_BACKGROUND_IMAGE_URL == *".gif" ]]; then
253
-            GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="gif"
254
-        fi
255
-    fi
256
-
257
-    if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT ]; then
258
-        read_config_param GNUSOCIAL_DOMAIN_NAME
259
-        gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
260
-
261
-        cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter
262
-
263
-        wget $GNUSOCIAL_BACKGROUND_IMAGE_URL -O img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}
264
-        if [ ! -f img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT} ]; then
265
-            echo "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
266
-            echo $'Custom background image for gnusocial could not be downloaded'
267
-            echo "1"
268
-            return
269
-        fi
270
-
271
-        if grep -q "'img/custom" $gnusocial_config_file; then
272
-            sed -i "s|'img/custom.*|'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';|g" $gnusocial_config_file
273
-        fi
274
-    fi
275
-    echo "0"
276
-}
277
-
278
-
279 244
 function gnusocial_set_background_image {
280 245
     data=$(tempfile 2>/dev/null)
281 246
     trap "rm -f $data" 0 1 2 5 15
@@ -289,7 +254,7 @@ function gnusocial_set_background_image {
289 254
             if [ ${#temp_background} -gt 0 ]; then
290 255
                 GNUSOCIAL_BACKGROUND_IMAGE_URL="$temp_background"
291 256
                 write_config_param "GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_BACKGROUND_IMAGE_URL"
292
-                if [[ $(gnusocial_set_background_image_from_url) == "0" ]]; then
257
+                if [[ $(pleroma_set_background_image_from_url "$domain_name" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE") == "0" ]]; then
293 258
                     dialog --title $"Set GNU Social login background" \
294 259
                            --msgbox $"The background image has been set" 6 60
295 260
                 fi
@@ -298,26 +263,23 @@ function gnusocial_set_background_image {
298 263
     esac
299 264
 }
300 265
 
301
-function gnusocial_set_welcome_message {
266
+function gnusocial_set_title {
302 267
     data=$(tempfile 2>/dev/null)
303 268
     trap "rm -f $data" 0 1 2 5 15
304 269
     dialog --title $"GNU Social" \
305 270
            --backtitle $"Freedombone Control Panel" \
306
-           --inputbox $'Set a welcome message, which can include html formatting' 10 60 2>$data
271
+           --inputbox $'Set a title' 10 60 2>$data
307 272
     sel=$?
308 273
     case $sel in
309 274
         0)
310
-            temp_welcome=$(<$data)
311
-            if [ ${#temp_welcome} -gt 0 ]; then
312
-                GNUSOCIAL_WELCOME_MESSAGE="$temp_welcome"
313
-                gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
314
-                if grep -q "customwelcometext" $gnusocial_config_file; then
315
-                    write_config_param "GNUSOCIAL_WELCOME_MESSAGE" "$GNUSOCIAL_WELCOME_MESSAGE"
316
-                    sed -i "s|customwelcometext.*|customwelcometext']['en'] = '${GNUSOCIAL_WELCOME_MESSAGE}';|g" $gnusocial_config_file
317
-
318
-                    dialog --title $"Set GNU Social welcome message" \
319
-                           --msgbox $"Welcome message has been set" 6 60
320
-                fi
275
+            new_title=$(<$data)
276
+            if [ ${#new_title} -gt 0 ]; then
277
+                GNUSOCIAL_TITLE="$new_title"
278
+                write_config_param "GNUSOCIAL_TITLE" "$GNUSOCIAL_TITLE"
279
+                cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/static
280
+                sed -i "s|\"name\":.*|\"name\": \"${GNUSOCIAL_TITLE}\",|g" config.json
281
+                dialog --title $"Set GNU Social title" \
282
+                       --msgbox $"The title has been set" 6 60
321 283
             fi
322 284
            ;;
323 285
     esac
@@ -332,7 +294,7 @@ function configure_interactive_gnusocial {
332 294
                --title $"GNU Social" \
333 295
                --radiolist $"Choose an operation:" 12 70 3 \
334 296
                1 $"Set a login screen background image" off \
335
-               2 $"Set a welcome message" off \
297
+               2 $"Set the title" off \
336 298
                3 $"Exit" on 2> $data
337 299
         sel=$?
338 300
         case $sel in
@@ -341,7 +303,7 @@ function configure_interactive_gnusocial {
341 303
         esac
342 304
         case $(cat $data) in
343 305
             1) gnusocial_set_background_image;;
344
-            2) gnusocial_set_welcome_message;;
306
+            2) gnusocial_set_title;;
345 307
             3) break;;
346 308
         esac
347 309
     done
@@ -365,6 +327,8 @@ function upgrade_gnusocial {
365 327
 
366 328
     function_check gnusocial_running_script
367 329
     gnusocial_running_script
330
+
331
+    upgrade_pleroma "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
368 332
 }
369 333
 
370 334
 
@@ -472,6 +436,9 @@ function remove_gnusocial {
472 436
     if [ ${#GNUSOCIAL_DOMAIN_NAME} -eq 0 ]; then
473 437
         return
474 438
     fi
439
+    function_check remove_nodejs
440
+    remove_nodejs pleroma-gnusocial
441
+
475 442
     read_config_param "GNUSOCIAL_DOMAIN_NAME"
476 443
     read_config_param "MY_USERNAME"
477 444
     echo "Removing $GNUSOCIAL_DOMAIN_NAME"
@@ -933,97 +900,6 @@ function expire_gnusocial_posts {
933 900
     fi
934 901
 }
935 902
 
936
-function install_gnusocial_theme {
937
-    # update to the next commit
938
-    function_check set_repo_commit
939
-    set_repo_commit /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter "gnusocial theme commit" "$GNUSOCIAL_THEME_COMMIT" $GNUSOCIAL_THEME_REPO
940
-
941
-    # customise with project logo
942
-    if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
943
-        if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
944
-            cp ~/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
945
-        else
946
-            if [ -f /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png ]; then
947
-                cp /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
948
-            fi
949
-        fi
950
-    fi
951
-
952
-    if [[ $(app_is_installed gnusocial_theme) == "1" ]]; then
953
-        return
954
-    fi
955
-
956
-    apt-get -yq install wget
957
-
958
-    if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins ]; then
959
-        mkdir -p /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
960
-    fi
961
-
962
-    cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins
963
-    function_check git_clone
964
-    git_clone $GNUSOCIAL_THEME_REPO Qvitter
965
-    cd /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter
966
-    git checkout $GNUSOCIAL_THEME_COMMIT -b $GNUSOCIAL_THEME_COMMIT
967
-
968
-    # download a custom background image
969
-    if [[ $(gnusocial_set_background_image_from_url) != "0" ]]; then
970
-        exit 356723
971
-    fi
972
-
973
-    if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
974
-        filename=$(basename "$GNUSOCIAL_BACKGROUND_IMAGE_URL")
975
-        GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT="${filename##*.}"
976
-    fi
977
-
978
-    gnusocial_config_file=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/config.php
979
-    if ! grep -q "addPlugin('Qvitter')" $gnusocial_config_file; then
980
-        GNUSOCIAL_WELCOME_MESSAGE=$(echo $GNUSOCIAL_WELCOME_MESSAGE | sed "s|\$GNUSOCIAL_DOMAIN_NAME|$GNUSOCIAL_DOMAIN_NAME|g")
981
-        echo "" >> $gnusocial_config_file
982
-        echo "// Qvitter settings" >> $gnusocial_config_file
983
-        echo "addPlugin('Qvitter');" >> $gnusocial_config_file
984
-        echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $gnusocial_config_file
985
-        echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $gnusocial_config_file
986
-        echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $gnusocial_config_file
987
-        echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $gnusocial_config_file
988
-        if [[ $ONION_ONLY != 'no' ]]; then
989
-            echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $gnusocial_config_file
990
-            echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $gnusocial_config_file
991
-        fi
992
-        if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL ]; then
993
-            echo "\$config['site']['qvitter']['sitebackground'] = 'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';" >> $gnusocial_config_file
994
-        else
995
-            echo "\$config['site']['qvitter']['sitebackground'] = 'img/vagnsmossen.jpg';" >> $gnusocial_config_file
996
-        fi
997
-        echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $gnusocial_config_file
998
-        echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $gnusocial_config_file
999
-        echo "\$config['site']['qvitter']['enablewelcometext'] = true;" >> $gnusocial_config_file
1000
-        echo "\$config['site']['qvitter']['customwelcometext']['en'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
1001
-        echo "\$config['site']['qvitter']['customwelcometext']['de'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
1002
-        echo "\$config['site']['qvitter']['customwelcometext']['fr'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
1003
-        echo "\$config['site']['qvitter']['customwelcometext']['es'] = '$GNUSOCIAL_WELCOME_MESSAGE';" >> $gnusocial_config_file
1004
-        echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $gnusocial_config_file
1005
-    else
1006
-        if [ $GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT ]; then
1007
-            if [ -f img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT} ]; then
1008
-                sed -i "s|\$config['site']['qvitter']['sitebackground'].*|\$config['site']['qvitter']['sitebackground'] = 'img/custom.${GNUSOCIAL_BACKGROUND_IMAGE_URL_EXT}';|g" $gnusocial_config_file
1009
-            fi
1010
-        fi
1011
-    fi
1012
-
1013
-    # customise with project logo
1014
-    if [ -f /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
1015
-        if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
1016
-            cp ~/freedombone/img/gnusocial_sprite.png /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs/local/plugins/Qvitter/img/sprite.png
1017
-        fi
1018
-    fi
1019
-
1020
-    set_completion_param "gnusocial theme commit" "$GNUSOCIAL_THEME_COMMIT"
1021
-
1022
-    chown -R www-data:www-data /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
1023
-
1024
-    install_completed gnusocial_theme
1025
-}
1026
-
1027 903
 function install_gnusocial_markdown {
1028 904
     GNUSOCIAL_PATH=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
1029 905
 
@@ -1112,12 +988,16 @@ function install_gnusocial {
1112 988
 
1113 989
     install_gnusocial_main
1114 990
     expire_gnusocial_posts
1115
-    install_gnusocial_theme
991
+    install_qvitter "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
1116 992
     install_gnusocial_markdown
1117
-    install_gnusocial_plugin_sharings
1118
-    install_gnusocial_plugin_sharings_theme
993
+    #install_gnusocial_plugin_sharings
994
+    #install_gnusocial_plugin_sharings_theme
1119 995
     install_gnusocial_plugin_nsfw
1120 996
 
997
+    function_check install_nodejs
998
+    install_nodejs pleroma-gnusocial
999
+    install_pleroma "gnusocial" "$GNUSOCIAL_DOMAIN_NAME" "$GNUSOCIAL_BACKGROUND_IMAGE_URL" "$GNUSOCIAL_TITLE"
1000
+
1121 1001
     # unleash the daemons!
1122 1002
     /etc/cron.hourly/gnusocial-daemons
1123 1003
 

+ 215
- 0
src/freedombone-utils-gnusocialtools Voir le fichier

@@ -0,0 +1,215 @@
1
+#!/bin/bash
2
+#
3
+# .---.                  .              .
4
+# |                      |              |
5
+# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
6
+# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
7
+# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
8
+#
9
+#                    Freedom in the Cloud
10
+#
11
+# functions common to GNU Social server varieties
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
+QVITTER_THEME_REPO="https://git.gnu.io/h2p/Qvitter.git"
32
+QVITTER_THEME_COMMIT='a7f82628402db3a7579bb9b2877da3c5737da77b'
33
+
34
+PLEROMA_REPO="https://gitgud.io/lambadalambda/pleroma-fe.git"
35
+PLEROMA_COMMIT='935c0e09'
36
+
37
+function pleroma_set_background_image_from_url {
38
+    domain_name="$1"
39
+    url="$2"
40
+    title="$3"
41
+
42
+    ext=
43
+    if [ ${#url} -gt 0 ]; then
44
+        if [[ $url == *".jpeg" || $url == *".jpg" ]]; then
45
+            ext="jpg"
46
+        fi
47
+        if [[ $url == *".png" ]]; then
48
+            ext="png"
49
+        fi
50
+        if [[ $url == *".gif" ]]; then
51
+            ext="gif"
52
+        fi
53
+    fi
54
+
55
+    if [ ${#ext} -gt 0 ]; then
56
+        if [ -d /var/www/${domain_name}/htdocs/static ]; then
57
+            cd /var/www/${domain_name}/htdocs/static
58
+
59
+            wget $url -O bg_custom.${ext}
60
+            if [ ! -f bg_custom.${ext} ]; then
61
+                echo "$url"
62
+                echo $'Custom background image for pleroma could not be downloaded'
63
+                echo "1"
64
+                return
65
+            fi
66
+
67
+            sed -i "s|\"background\":.*|\"background\": \"bg_custom.${ext}\",|g" config.json
68
+        fi
69
+    fi
70
+
71
+    # customise the logo
72
+    if [ -f /var/www/${domain_name}/htdocs/static/logo.png ]; then
73
+        if [ -f ~/freedombone/img/logo_white.png ]; then
74
+            cp ~/freedombone/img/logo_white.png /var/www/${domain_name}/htdocs/static/logo.png
75
+        else
76
+            if [ -f /home/$MY_USERNAME/freedombone/img/logo_white.png ]; then
77
+                cp /home/$MY_USERNAME/freedombone/img/logo_white.png /var/www/${domain_name}/htdocs/static/logo.png
78
+            fi
79
+        fi
80
+    fi
81
+
82
+    # customise the title
83
+    if [ -f /var/www/${domain_name}/htdocs/static/config.json ]; then
84
+        sed -i "s|\"name\":.*|\"name\": \"${title}\",|g" config.json
85
+    fi
86
+
87
+    echo "0"
88
+}
89
+
90
+function install_qvitter {
91
+    domain_name=$1
92
+    app_name=$2
93
+
94
+    # update to the next commit
95
+    function_check set_repo_commit
96
+    set_repo_commit /var/www/${domain_name}/htdocs/local/plugins/Qvitter "${app_name} theme commit" "$QVITTER_THEME_COMMIT" $QVITTER_THEME_REPO
97
+
98
+    # customise with project logo
99
+    if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
100
+        if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
101
+            cp ~/freedombone/img/gnusocial_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
102
+        else
103
+            if [ -f /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png ]; then
104
+                cp /home/$MY_USERNAME/freedombone/img/gnusocial_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
105
+            fi
106
+        fi
107
+    fi
108
+
109
+    if [[ $(app_is_installed "${app_name}_theme") == "1" ]]; then
110
+        return
111
+    fi
112
+
113
+    apt-get -yq install wget
114
+
115
+    if [ ! -d /var/www/${domain_name}/htdocs/local/plugins ]; then
116
+        mkdir -p /var/www/${domain_name}/htdocs/local/plugins
117
+    fi
118
+
119
+    cd /var/www/${domain_name}/htdocs/local/plugins
120
+    function_check git_clone
121
+    git_clone $QVITTER_THEME_REPO Qvitter
122
+    cd /var/www/${domain_name}/htdocs/local/plugins/Qvitter
123
+    git checkout $QVITTER_THEME_COMMIT -b $QVITTER_THEME_COMMIT
124
+
125
+    config_file=/var/www/${domain_name}/htdocs/config.php
126
+    if ! grep -q "addPlugin('Qvitter')" $config_file; then
127
+        echo "" >> $config_file
128
+        echo "// Qvitter settings" >> $config_file
129
+        echo "addPlugin('Qvitter');" >> $config_file
130
+        echo "\$config['site']['qvitter']['enabledbydefault'] = true;" >> $config_file
131
+        echo "\$config['site']['qvitter']['defaultbackgroundcolor'] = '#f4f4f4';" >> $config_file
132
+        echo "\$config['site']['qvitter']['defaultlinkcolor'] = '#0084B4';" >> $config_file
133
+        echo "\$config['site']['qvitter']['timebetweenpolling'] = 30000; // 30 secs" >> $config_file
134
+        if [[ $ONION_ONLY != 'no' ]]; then
135
+            echo "\$config['site']['qvitter']['urlshortenerapiurl'] = 'http://qttr.at/shortener.php';" >> $config_file
136
+            echo "\$config['site']['qvitter']['urlshortenersignature'] = 'b6afeec983';" >> $config_file
137
+        fi
138
+        echo "\$config['site']['qvitter']['favicon'] = 'img/favicon.ico?v=4';" >> $config_file
139
+        echo "\$config['site']['qvitter']['sprite'] = Plugin::staticPath('Qvitter', '').'img/sprite.png?v=40';" >> $config_file
140
+        echo "\$config['site']['qvitter']['enablewelcometext'] = false;" >> $config_file
141
+        echo "\$config['site']['qvitter']['blocked_ips'] = array();" >> $config_file
142
+    fi
143
+
144
+    # customise with project logo
145
+    if [ -f /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png ]; then
146
+        if [ -f ~/freedombone/img/gnusocial_sprite.png ]; then
147
+            cp ~/freedombone/img/gnusocial_sprite.png /var/www/${domain_name}/htdocs/local/plugins/Qvitter/img/sprite.png
148
+        fi
149
+    fi
150
+
151
+    chown -R www-data:www-data /var/www/${domain_name}/htdocs
152
+
153
+    set_completion_param "${app_name} theme commit" "$QVITTER_THEME_COMMIT"
154
+
155
+    install_completed ${app_name}_theme
156
+}
157
+
158
+function install_pleroma {
159
+    app_name="$1"
160
+    pleroma_domain="$1"
161
+    background_url="$2"
162
+    title="$3"
163
+
164
+    if [ ! -d ~/build/pleroma ]; then
165
+        function_check git_clone
166
+        git_clone $PLEROMA_REPO ~/build/pleroma
167
+        if [ ! -d ~/build/pleroma ]; then
168
+            echo $'Unable to clone pleroma repo'
169
+            exit 682252
170
+        fi
171
+    fi
172
+
173
+    cd ~/build/pleroma
174
+    git checkout $PLEROMA_COMMIT -b $PLEROMA_COMMIT
175
+    set_completion_param "${app_name} pleroma commit" "$PLEROMA_COMMIT"
176
+
177
+    npm install -g yarn
178
+    yarn
179
+    npm run build
180
+    if [ ! -d ~/build/pleroma/dist ]; then
181
+        echo 'Unable to build pleroma'
182
+        exit 7629352
183
+    fi
184
+    mv ~/build/pleroma/dist/index.html ~/build/pleroma/dist/pleroma.html
185
+    cp -r ~/build/pleroma/dist/* /var/www/$pleroma_domain/htdocs/
186
+
187
+    gnusocial_set_background_image_from_url "$pleroma_domain" "$background_url" "$title"
188
+
189
+    nginx_site=/etc/nginx/sites-available/$pleroma_domain
190
+    sed -i 's|index index.php;|index pleroma.html;|g' $nginx_site
191
+}
192
+
193
+function upgrade_pleroma {
194
+    domain_name="$1"
195
+    app_name="$2"
196
+    background_url="$3"
197
+    title="$4"
198
+
199
+    if [ -d ~/build/pleroma ]; then
200
+        set_repo_commit ~/build/pleroma "${app_name} pleroma commit" "$PLEROMA_COMMIT" $PLEROMA_REPO
201
+        cd ~/build/pleroma
202
+        npm run build
203
+        if [ ! -d ~/build/pleroma/dist ]; then
204
+            echo 'Unable to build pleroma'
205
+            exit 268362
206
+        fi
207
+        mv ~/build/pleroma/dist/index.html ~/build/pleroma/dist/pleroma.html
208
+        cp -r ~/build/pleroma/dist/* /var/www/${domain_name}/htdocs/
209
+        pleroma_set_background_image_from_url "$domain_name" "$background_url" "$title"
210
+    else
211
+        install_pleroma "${app_name}" "${domain_name}" "${background_url}" "${title}"
212
+    fi
213
+}
214
+
215
+# NOTE: deliberately there is no "exit 0"