From bbfa6d353f401ead6a1d101eb46f1b9b9d827f8a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 23 Apr 2017 17:25:10 +0100 Subject: [PATCH] Also expire files uploaded to gnusocial/postactiv --- src/freedombone-utils-gnusocialtools | 80 +++++++++++++++------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/src/freedombone-utils-gnusocialtools b/src/freedombone-utils-gnusocialtools index 940064f7..9be4af5a 100755 --- a/src/freedombone-utils-gnusocialtools +++ b/src/freedombone-utils-gnusocialtools @@ -503,53 +503,61 @@ function expire_gnusocial_posts { expire_months=3 fi + expire_days=$((expire_months * 30)) + # To prevent the database size from growing endlessly this script expires posts # after a number of months if [ ! -d /var/www/${domain_name}/htdocs ]; then return fi - gnusocial_expire_script=/usr/bin/${gnusocial_type}-expire + gnusocial_expire_posts_script=/usr/bin/${gnusocial_type}-expire-posts - echo ' $gnusocial_expire_script - echo '' >> $gnusocial_expire_script - echo "// ${gnusocial_type} post expiry script, based on StatExpire by Tony Baldwin" >> $gnusocial_expire_script - echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_script - echo '' >> $gnusocial_expire_script - echo "\$oldate=date((\"Y-m-d\"), strtotime(\"-${expire_months} months\"));" >> $gnusocial_expire_script - echo '$username="root";' >> $gnusocial_expire_script - echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');" >> $gnusocial_expire_script - echo "\$database=\"${gnusocial_type}\";" >> $gnusocial_expire_script - echo '' >> $gnusocial_expire_script - echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_script - echo ' echo "Could not connect to mariadb";' >> $gnusocial_expire_script - echo ' exit;' >> $gnusocial_expire_script - echo '}' >> $gnusocial_expire_script - echo '' >> $gnusocial_expire_script - echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_script - echo " echo \"Could not select ${gnusocial_type} database\";" >> $gnusocial_expire_script - echo ' exit;' >> $gnusocial_expire_script - echo '}' >> $gnusocial_expire_script - echo '' >> $gnusocial_expire_script - echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script - echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_script - echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_script - echo '' >> $gnusocial_expire_script - echo 'mysql_query($notice_query);' >> $gnusocial_expire_script - echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_script - echo 'mysql_query($conversation_query);' >> $gnusocial_expire_script - echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_script - echo 'mysql_query($reply_query);' >> $gnusocial_expire_script - echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_script - echo 'mysql_close();' >> $gnusocial_expire_script - echo '' >> $gnusocial_expire_script - echo -n "echo \"Expire ${gnusocial_type} posts: " >> $gnusocial_expire_script - echo '$rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_script + echo ' $gnusocial_expire_posts_script + echo '' >> $gnusocial_expire_posts_script + echo "// ${gnusocial_type} post expiry script, based on StatExpire by Tony Baldwin" >> $gnusocial_expire_posts_script + echo '// https://github.com/tonybaldwin/statexpire' >> $gnusocial_expire_posts_script + echo '' >> $gnusocial_expire_posts_script + echo "\$oldate=date((\"Y-m-d\"), strtotime(\"-${expire_months} months\"));" >> $gnusocial_expire_posts_script + echo '$username="root";' >> $gnusocial_expire_posts_script + echo "\$password=shell_exec('${PROJECT_NAME}-pass -u root -a mariadb');" >> $gnusocial_expire_posts_script + echo "\$database=\"${gnusocial_type}\";" >> $gnusocial_expire_posts_script + echo '' >> $gnusocial_expire_posts_script + echo 'if (!$link = mysql_connect("localhost", $username, $password)) {' >> $gnusocial_expire_posts_script + echo ' echo "Could not connect to mariadb";' >> $gnusocial_expire_posts_script + echo ' exit;' >> $gnusocial_expire_posts_script + echo '}' >> $gnusocial_expire_posts_script + echo '' >> $gnusocial_expire_posts_script + echo 'if (!mysql_select_db($database, $link)) {' >> $gnusocial_expire_posts_script + echo " echo \"Could not select ${gnusocial_type} database\";" >> $gnusocial_expire_posts_script + echo ' exit;' >> $gnusocial_expire_posts_script + echo '}' >> $gnusocial_expire_posts_script + echo '' >> $gnusocial_expire_posts_script + echo "\$notice_query=\"DELETE FROM notice WHERE created <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_posts_script + echo "\$conversation_query=\"DELETE FROM conversation WHERE created <= '$oldate 01:01:01'\";" >> $gnusocial_expire_posts_script + echo "\$reply_query=\"DELETE FROM reply WHERE modified <= '\$oldate 01:01:01'\";" >> $gnusocial_expire_posts_script + echo '' >> $gnusocial_expire_posts_script + echo 'mysql_query($notice_query);' >> $gnusocial_expire_posts_script + echo '$rowaff1=mysql_affected_rows();' >> $gnusocial_expire_posts_script + echo 'mysql_query($conversation_query);' >> $gnusocial_expire_posts_script + echo '$rowaff2=mysql_affected_rows();' >> $gnusocial_expire_posts_script + echo 'mysql_query($reply_query);' >> $gnusocial_expire_posts_script + echo '$rowaff3=mysql_affected_rows();' >> $gnusocial_expire_posts_script + echo 'mysql_close();' >> $gnusocial_expire_posts_script + echo '' >> $gnusocial_expire_posts_script + echo -n "echo \"Expire ${gnusocial_type} posts: " >> $gnusocial_expire_posts_script + echo '$rowaff1 notices, $rowaff2 conversations, and $rowaff3 replies deleted from database.\n";' >> $gnusocial_expire_posts_script + chmod +x $gnusocial_expire_posts_script + + gnusocial_expire_script=/usr/bin/${gnusocial_type}-expire + echo '#!/bin/bash' > $gnusocial_expire_script + echo "/usr/bin/php $gnusocial_expire_posts_script" > $gnusocial_expire_script + echo "find /var/www/${domain_name}/htdocs/file/* -mtime +${expire_days} -exec rm {} +" > $gnusocial_expire_script chmod +x $gnusocial_expire_script # Add a cron job if ! grep -q "${gnusocial_type}_expire_script" /etc/crontab; then - echo "10 3 5 * * root /usr/bin/timeout 500 /usr/bin/php ${gnusocial_expire_script}" >> /etc/crontab + echo "10 3 5 * * root /usr/bin/timeout 500 ${gnusocial_expire_script}" >> /etc/crontab fi # remove old expire script