Parcourir la source

Consolidate gnusocial post expiry script

Bob Mottram il y a 8 ans
Parent
révision
7d0f470389

+ 6
- 58
src/freedombone-app-gnusocial Voir le fichier

@@ -13,7 +13,7 @@
13 13
 # License
14 14
 # =======
15 15
 #
16
-# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
16
+# Copyright (C) 2014-2017 Bob Mottram <bob@freedombone.net>
17 17
 #
18 18
 # This program is free software: you can redistribute it and/or modify
19 19
 # it under the terms of the GNU Affero General Public License as published by
@@ -54,11 +54,11 @@ SHARINGS_THEME_COMMIT='7106c7ef03'
54 54
 GNUSOCIAL_NSFW_REPO="https://gitgud.io/ShitposterClub/SensitiveContent"
55 55
 GNUSOCIAL_NSFW_COMMIT='a096bbe0cfae9a9b177682920ffb58d32a48e136'
56 56
 
57
-# script which causes old posts to expire
58
-gnusocial_expire_script=/usr/bin/gnusocial-expire
59
-
60 57
 GNUSOCIAL_TITLE='Pleroma FE'
61 58
 
59
+# Number of months after which posts expire
60
+GNUSOCIAL_EXPIRE_MONTHS=3
61
+
62 62
 gnusocial_variables=(ONION_ONLY
63 63
                      GNUSOCIAL_DOMAIN_NAME
64 64
                      GNUSOCIAL_CODE
@@ -72,6 +72,7 @@ gnusocial_variables=(ONION_ONLY
72 72
                      SHARINGS_THEME_REPO
73 73
                      SHARINGS_THEME_COMMIT
74 74
                      GNUSOCIAL_TITLE
75
+                     GNUSOCIAL_EXPIRE_MONTHS
75 76
                      MY_USERNAME)
76 77
 
77 78
 function gnusocial_fix_endless_reloads {
@@ -843,59 +844,6 @@ function install_gnusocial_plugin_sharings_theme {
843 844
     install_completed gnusocial_plugin_sharings_theme
844 845
 }
845 846
 
846
-function expire_gnusocial_posts {
847
-    # To prevent the database size from growing endlessly this script expires posts
848
-    # after a number of months
849
-    if [ ! -d /var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs ]; then
850
-        return
851
-    fi
852
-
853
-    echo '<?php' > $gnusocial_expire_script
854
-    echo '' >> $gnusocial_expire_script
855
-    echo '// gnusocial post expiry script, based on StatExpire by Tony Baldwin' >> $gnusocial_expire_script
856
-    echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_script
857
-    echo '' >> $gnusocial_expire_script
858
-    echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $gnusocial_expire_script
859
-    echo '$username="root";' >> $gnusocial_expire_script
860
-    echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');" >> $gnusocial_expire_script
861
-    echo '$database="gnusocial";' >> $gnusocial_expire_script
862
-    echo '' >> $gnusocial_expire_script
863
-    echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_script
864
-    echo '    echo "Could not connect to mariadb";' >> $gnusocial_expire_script
865
-    echo '    exit;' >> $gnusocial_expire_script
866
-    echo '}' >> $gnusocial_expire_script
867
-    echo '' >> $gnusocial_expire_script
868
-    echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_script
869
-    echo '    echo "Could not select gnusocial database";' >> $gnusocial_expire_script
870
-    echo '    exit;' >> $gnusocial_expire_script
871
-    echo '}' >> $gnusocial_expire_script
872
-    echo '' >> $gnusocial_expire_script
873
-    echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
874
-    echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_script
875
-    echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
876
-    echo '' >> $gnusocial_expire_script
877
-    echo 'mysql_query($notice_query);' >> $gnusocial_expire_script
878
-    echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_script
879
-    echo 'mysql_query($conversation_query);' >> $gnusocial_expire_script
880
-    echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_script
881
-    echo 'mysql_query($reply_query);' >> $gnusocial_expire_script
882
-    echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_script
883
-    echo 'mysql_close();' >> $gnusocial_expire_script
884
-    echo '' >> $gnusocial_expire_script
885
-    echo 'echo "Expire gnusocial posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_script
886
-    chmod +x $gnusocial_expire_script
887
-
888
-    # Add a cron job
889
-    if ! grep -q "$gnusocial_expire_script" /etc/crontab; then
890
-        echo "10 3 5   *   *   root /usr/bin/timeout 500 /usr/bin/php $gnusocial_expire_script" >> /etc/crontab
891
-    fi
892
-
893
-    # remove old expire script
894
-    if [ -f /etc/cron.weekly/clear-gnusocial-database ]; then
895
-        rm /etc/cron.weekly/clear-gnusocial-database
896
-    fi
897
-}
898
-
899 847
 function install_gnusocial_markdown {
900 848
     GNUSOCIAL_PATH=/var/www/$GNUSOCIAL_DOMAIN_NAME/htdocs
901 849
 
@@ -983,7 +931,7 @@ function install_gnusocial {
983 931
     fi
984 932
 
985 933
     install_gnusocial_main
986
-    expire_gnusocial_posts
934
+    expire_gnusocial_posts "$GNUSOCIAL_DOMAIN_NAME" "gnusocial" "$GNUSOCIAL_EXPIRE_MONTHS"
987 935
     install_qvitter "$GNUSOCIAL_DOMAIN_NAME" "gnusocial"
988 936
     install_gnusocial_markdown
989 937
     #install_gnusocial_plugin_sharings

+ 5
- 57
src/freedombone-app-postactiv Voir le fichier

@@ -13,7 +13,7 @@
13 13
 # License
14 14
 # =======
15 15
 #
16
-# Copyright (C) 2016 Bob Mottram <bob@freedombone.net>
16
+# Copyright (C) 2016-2017 Bob Mottram <bob@freedombone.net>
17 17
 #
18 18
 # This program is free software: you can redistribute it and/or modify
19 19
 # it under the terms of the GNU Affero General Public License as published by
@@ -43,8 +43,8 @@ POSTACTIV_ADMIN_PASSWORD=
43 43
 POSTACTIV_BACKGROUND_IMAGE_URL=
44 44
 POSTACTIV_TITLE='PostActiv'
45 45
 
46
-# script which causes old posts to expire
47
-postactiv_expire_script=/usr/bin/postactiv-expire
46
+# Number of months after which posts expire
47
+POSTACTIV_EXPIRE_MONTHS=3
48 48
 
49 49
 postactiv_variables=(ONION_ONLY
50 50
                      POSTACTIV_DOMAIN_NAME
@@ -52,6 +52,7 @@ postactiv_variables=(ONION_ONLY
52 52
                      DDNS_PROVIDER
53 53
                      MY_USERNAME
54 54
                      POSTACTIV_BACKGROUND_IMAGE_URL
55
+                     POSTACTIV_EXPIRE_MONTHS
55 56
                      POSTACTIV_TITLE)
56 57
 
57 58
 function remove_user_postactiv {
@@ -710,59 +711,6 @@ function install_postactiv_main {
710 711
     install_completed postactiv_main
711 712
 }
712 713
 
713
-function expire_postactiv_posts {
714
-    # To prevent the database size from growing endlessly this script expires posts
715
-    # after a number of months
716
-    if [ ! -d /var/www/$POSTACTIV_DOMAIN_NAME/htdocs ]; then
717
-        return
718
-    fi
719
-
720
-    echo '<?php' > $postactiv_expire_script
721
-    echo '' >> $postactiv_expire_script
722
-    echo '// postactiv post expiry script, based on StatExpire by Tony Baldwin' >> $postactiv_expire_script
723
-    echo '// https://github.com/tonybaldwin/statexpire' >> $postactiv_expire_script
724
-    echo '' >> $postactiv_expire_script
725
-    echo '$oldate=date(("Y-m-d"), strtotime("-3 months"));' >> $postactiv_expire_script
726
-    echo '$username="root";' >> $postactiv_expire_script
727
-    echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');" >> $postactiv_expire_script
728
-    echo '$database="postactiv";' >> $postactiv_expire_script
729
-    echo '' >> $postactiv_expire_script
730
-    echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $postactiv_expire_script
731
-    echo '    echo "Could not connect to mariadb";' >> $postactiv_expire_script
732
-    echo '    exit;' >> $postactiv_expire_script
733
-    echo '}' >> $postactiv_expire_script
734
-    echo '' >> $postactiv_expire_script
735
-    echo 'if (!mysql_select_db($database, $link)) {' >> $postactiv_expire_script
736
-    echo '    echo "Could not select postactiv database";' >> $postactiv_expire_script
737
-    echo '    exit;' >> $postactiv_expire_script
738
-    echo '}' >> $postactiv_expire_script
739
-    echo '' >> $postactiv_expire_script
740
-    echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $postactiv_expire_script
741
-    echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $postactiv_expire_script
742
-    echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $postactiv_expire_script
743
-    echo '' >> $postactiv_expire_script
744
-    echo 'mysql_query($notice_query);' >> $postactiv_expire_script
745
-    echo '$rowaff1=mysql_affected_rows();' >> $postactiv_expire_script
746
-    echo 'mysql_query($conversation_query);' >> $postactiv_expire_script
747
-    echo '$rowaff2=mysql_affected_rows();' >> $postactiv_expire_script
748
-    echo 'mysql_query($reply_query);' >> $postactiv_expire_script
749
-    echo '$rowaff3=mysql_affected_rows();' >> $postactiv_expire_script
750
-    echo 'mysql_close();' >> $postactiv_expire_script
751
-    echo '' >> $postactiv_expire_script
752
-    echo 'echo "Expire postactiv posts: $rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $postactiv_expire_script
753
-    chmod +x $postactiv_expire_script
754
-
755
-    # Add a cron job
756
-    if ! grep -q "$postactiv_expire_script" /etc/crontab; then
757
-        echo "10 3 5   *   *   root /usr/bin/timeout 500 /usr/bin/php $postactiv_expire_script" >> /etc/crontab
758
-    fi
759
-
760
-    # remove old expire script
761
-    if [ -f /etc/cron.weekly/clear-postactiv-database ]; then
762
-        rm /etc/cron.weekly/clear-postactiv-database
763
-    fi
764
-}
765
-
766 714
 function install_postactiv {
767 715
     if [ ! $ONION_ONLY ]; then
768 716
         ONION_ONLY='no'
@@ -785,7 +733,7 @@ function install_postactiv {
785 733
         install_pleroma "postactiv" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
786 734
     fi
787 735
 
788
-    expire_postactiv_posts
736
+    expire_gnusocial_posts "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_EXPIRE_MONTHS"
789 737
 
790 738
     # unleash the daemons!
791 739
     /etc/cron.hourly/postactiv-daemons

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

@@ -273,5 +273,68 @@ function gnusocial_hourly_script {
273 273
     chmod +x /etc/cron.hourly/${gnusocial_type}-daemons
274 274
 }
275 275
 
276
+function expire_gnusocial_posts {
277
+    domain_name=$1
278
+    gnusocial_type=$2
279
+    expire_months=$3
280
+
281
+    if [ ! $expire_months ]; then
282
+        expire_months=3
283
+    fi
284
+
285
+    # To prevent the database size from growing endlessly this script expires posts
286
+    # after a number of months
287
+    if [ ! -d /var/www/${domain_name}/htdocs ]; then
288
+        return
289
+    fi
290
+
291
+    gnusocial_expire_script=/usr/bin/${gnusocial_type}-expire
292
+
293
+    echo '<?php' > $gnusocial_expire_script
294
+    echo '' >> $gnusocial_expire_script
295
+    echo "// ${gnusocial_type} post expiry script, based on StatExpire by Tony Baldwin" >> $gnusocial_expire_script
296
+    echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_script
297
+    echo '' >> $gnusocial_expire_script
298
+    echo "\$oldate=date((\"Y-m-d\"), strtotime(\"-${expire_months} months\"));" >> $gnusocial_expire_script
299
+    echo '$username="root";' >> $gnusocial_expire_script
300
+    echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');" >> $gnusocial_expire_script
301
+    echo "\$database=\"${gnusocial_type}\";" >> $gnusocial_expire_script
302
+    echo '' >> $gnusocial_expire_script
303
+    echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_script
304
+    echo '    echo "Could not connect to mariadb";' >> $gnusocial_expire_script
305
+    echo '    exit;' >> $gnusocial_expire_script
306
+    echo '}' >> $gnusocial_expire_script
307
+    echo '' >> $gnusocial_expire_script
308
+    echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_script
309
+    echo "    echo \"Could not select ${gnusocial_type} database\";" >> $gnusocial_expire_script
310
+    echo '    exit;' >> $gnusocial_expire_script
311
+    echo '}' >> $gnusocial_expire_script
312
+    echo '' >> $gnusocial_expire_script
313
+    echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
314
+    echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_script
315
+    echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script
316
+    echo '' >> $gnusocial_expire_script
317
+    echo 'mysql_query($notice_query);' >> $gnusocial_expire_script
318
+    echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_script
319
+    echo 'mysql_query($conversation_query);' >> $gnusocial_expire_script
320
+    echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_script
321
+    echo 'mysql_query($reply_query);' >> $gnusocial_expire_script
322
+    echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_script
323
+    echo 'mysql_close();' >> $gnusocial_expire_script
324
+    echo '' >> $gnusocial_expire_script
325
+    echo -n "echo \"Expire ${gnusocial_type} posts: " >> $gnusocial_expire_script
326
+    echo '$rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_script
327
+    chmod +x $gnusocial_expire_script
328
+
329
+    # Add a cron job
330
+    if ! grep -q "${gnusocial_type}_expire_script" /etc/crontab; then
331
+        echo "10 3 5   *   *   root /usr/bin/timeout 500 /usr/bin/php ${gnusocial_type}_expire_script" >> /etc/crontab
332
+    fi
333
+
334
+    # remove old expire script
335
+    if [ -f /etc/cron.weekly/clear-${gnusocial_type}-database ]; then
336
+        rm /etc/cron.weekly/clear-${gnusocial_type}-database
337
+    fi
338
+}
276 339
 
277 340
 # NOTE: deliberately there is no "exit 0"